CSP-Junior 2022
A. Power
time limit per test
1 s
memory limit per test
512 MB
input
pow.in
output
pow.out

You're given integers $$$a$$$ and $$$b$$$,calculate $$$a^b$$$。

But if $$$a^b$$$ exceeds $$$10^9$$$, print '-1'. Otherwise, print the correct value.

Input

Read from file "pow.in"

Single line contains integers $$$a, b$$$.

Output

Output to file "pow.out"

Single line,if $$$a^b$$$ doesn't exceeds $$$10^9$$$, print $$$a^b$$$, otherwise print '-1'.

Examples
Input
10 9
Output
1000000000
Input
23333 66666
Output
-1
Note

$$$$$$1 \le a, b \le 10^9$$$$$$

B. Decode
time limit per test
1 s
memory limit per test
512 MB
input
decode.in
output
decode.out

Mutitestcases.

You're given three positive integers $$$n_i, e_i, d_i$$$, print two positive integers $$$p_i, q_i$$$, meet $$$n_i = p_i \times q_i$$$ and $$$e_i \times d_i = (p_i - 1)(q_i - 1) + 1$$$.

Input

Read from file "decode.in"

First line an integer $$$t$$$ — number of testcases.

Following $$$t$$$ lines, $$$i$$$th contains three integers $$$n_i, d_i, e_i$$$.

Output

Output to file "decode.out"

Output $$$t$$$ lines, two integers $$$p_i, q_i$$$ as your answer. Note $$$p_i\leq q_i$$$ should hold.

If there are no solutions, pring 'NO'.

Example
Input
10
770 77 5
633 1 211
545 1 499
683 3 227
858 3 257
723 37 13
572 26 11
867 17 17
829 3 263
528 4 109
Output
2 385
NO
NO
NO
11 78
3 241
2 286
NO
NO
6 88
Note

$$$$$$1\leq t\leq 10^5,1\leq n_i\leq 10^{18},1\leq d_i\times e_i\leq 10^{18},1\leq n_i−e_i\times d_i+2\leq 10^9$$$$$$

C. Expr
time limit per test
1 s
memory limit per test
512 MB
input
expr.in
output
expr.out

逻辑表达式是计算机科学中的重要概念和工具,包含逻辑值、逻辑运算、逻辑运算优先级等内容。

在一个逻辑表达式中,元素的值只有两种可能:$$$0$$$(表示假)和 $$$1$$$(表示真)。元素之间有多种可能的逻辑运算,本题中只需考虑如下两种:"与"(符号为 '&')和"或"(符号为 '|')。其运算规则如下:

$$$0 \mathbin{\&} 0 = 0 \mathbin{\&} 1 = 1 \mathbin{\&} 0 = 0$$$,$$$1 \mathbin{\&} 1 = 1$$$; $$$0 \mathbin{|} 0 = 0$$$,$$$0 \mathbin{|} 1 = 1 \mathbin{|} 0 = 1 \mathbin{|} 1 = 1$$$。

在一个逻辑表达式中还可能有括号。规定在运算时,括号内的部分先运算;两种运算并列时,'&' 运算优先于 '|' 运算;同种运算并列时,从左向右运算。

比如,表达式 '0|1&0' 的运算顺序等同于 '0|(1&0)';表达式 '0&1&0|1' 的运算顺序等同于 '((0&1)&0)|1'。

此外,在 C++ 等语言的有些编译器中,对逻辑表达式的计算会采用一种"短路"的策略:在形如 'a&b' 的逻辑表达式中,会先计算 'a' 部分的值,如果 $$$a = 0$$$,那么整个逻辑表达式的值就一定为 $$$0$$$,故无需再计算 'b' 部分的值;同理,在形如 'a|b' 的逻辑表达式中,会先计算 'a' 部分的值,如果 $$$a = 1$$$,那么整个逻辑表达式的值就一定为 $$$1$$$,无需再计算 'b' 部分的值。

现在给你一个逻辑表达式,你需要计算出它的值,并且统计出在计算过程中,两种类型的"短路"各出现了多少次。需要注意的是,如果某处"短路"包含在更外层被"短路"的部分内则不被统计,如表达式 '1|(0&1)' 中,尽管 '0&1' 是一处"短路",但由于外层的 '1|(0&1)' 本身就是一处"短路",无需再计算 '0&1' 部分的值,因此不应当把这里的 '0&1' 计入一处"短路"。

Input

从文件 "expr.in" 读入

输入共一行,一个非空字符串 $$$s$$$ 表示待计算的逻辑表达式。

Output

输出至文件 "expr.out"

输出共两行,第一行输出一个字符 '0' 或 '1',表示这个逻辑表达式的值;第二行输出两个非负整数,分别表示计算上述逻辑表达式的过程中,形如 'a&b' 和 'a|b' 的"短路"各出现了多少次。

Examples
Input
0&(1|0)|(1|1|1&0)
Output
1
1 2
Input
(0|1&0|1|1|(1|1))&(0&1&(1|0)|0|1|0)&0
Output
0
2 3
Note

【样例解释 #1】

该逻辑表达式的计算过程如下,每一行的注释表示上一行计算的过程:

0&(1|0)|(1|1|1&0)

=(0&(1|0))|((1|1)|(1&0)) //用括号标明计算顺序

=0|((1|1)|(1&0)) //先计算最左侧的 &,是一次形如 a&b 的"短路"

=0|(1|(1&0)) //再计算中间的 |,是一次形如 a|b 的"短路"

=0|1 //再计算中间的 |,是一次形如 a|b 的"短路"

=1

【数据范围】

设 $$$\lvert s \rvert$$$ 为字符串 $$$s$$$ 的长度。

对于所有数据,$$$1 \le \lvert s \rvert \le 10^6$$$。保证 $$$s$$$ 中仅含有字符 '0'、'1'、'&'、'|'、'('、')' 且是一个符合规范的逻辑表达式。保证输入字符串的开头、中间和结尾均无额外的空格。保证 $$$s$$$ 中没有重复的括号嵌套(即没有形如 '((a))' 形式的子串,其中 'a' 是符合规范的逻辑表 达式)。

【提示】

以下给出一个"符合规范的逻辑表达式"的形式化定义:

  • 字符串 '0' 和 '1' 是符合规范的;
  • 如果字符串 's' 是符合规范的,且 's' 不是形如 '(t)' 的字符串(其中 't' 是符合规范的),那么字符串 '(s)' 也是符合规范的;
  • 如果字符串 'a' 和 'b' 均是符合规范的,那么字符串 'a&b'、'a|b' 均是符合规范的;
  • 所有符合规范的逻辑表达式均可由以上方法生成。

D. Point
time limit per test
1 s
memory limit per test
512 MB
input
point.in
output
point.out

In a plane, you are given $$$n$$$ points $$$(x_i, y_i)$$$. In addition, you can add $$$k$$$ points freely.

After adding $$$k$$$ points, you need to choose some points from $$$n + k$$$ points and form a sequence, meet either $$$x_{i+1} - x_i = 1, y_{i+1} = y_i$$$ or $$$y_{i+1} - y_i = 1, x_{i+1} = x_i$$$. Print the maximum length of the sequence.

Input

Read from file "point.in"

First line contains two integers $$$n, k$$$ — the number of given points and the number of points that you can add freely.

Following $$$n$$$ lines, $$$i$$$th contains two integers $$$x_i, y_i$$$ — $$$i$$$th given point.

Output

Output to file "point.out"

Print one integer — the maximum length of the sequence.

Examples
Input
8 2
3 1
3 2
3 3
3 6
1 2
2 2
5 5
5 3
Output
8
Input
4 100
10 10
15 25
20 20
30 30
Output
103
Note

$$$$$$1 \leq n \leq 500,0 \leq k \leq 100,1 \leq x_i, y_i \leq {10}^9$$$$$$

All the given points are pairwise different.

There are no other constraints on added points except the count.