2024 ICPC ShaanXi Provincial Contest
A. chmod
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

chmod is a command used to change file or directory permissions. It is one of the commonly used commands in Linux and other Unix-like operating systems. The chmod command allows users to set different permissions for files or directories to control who can read, write, or execute these files.

In a Linux system, each file or directory has permissions associated with it, and these permissions determine who can perform what operations on the file. Users are divided into three categories: owner, group, and others. Each type of user has three permissions: read (r), write (w) and execute (x). These $$$9$$$ permissions can be specified separately. We call 'permission string' a string of length $$$9$$$, which corresponds to the $$$9$$$ permissions mentioned above in order. If you have this permission, it is the corresponding one in r, w, x, otherwise -.

For example, 'permission string' rwxr-x--x indicates that the file has full permissions for the owner, only read and execute permissions for users in the group to which it belongs, and only execution permissions for others.

When using the chmod command, you can provide a pattern string to modify permissions. In this question, we only consider a pattern string with a length of $$$3$$$ consisting of numbers no greater than $$$7$$$. The three numbers represent the owner, the group and others from left to right. For each number, the lowest three binary bits from high to low indicate whether the user has read (r), write (w) and execute (x) permissions.

For example: After executing chmod 760 file.txt, the 'permission string' of the file is rwxrw----.

Given a number of legal pattern strings, each time you read in a pattern string, you need to output the 'permission string' of the modified file.

Input

The first line contains a positive integer $$$T$$$ ($$$1 \le T \le 100$$$), representing the number of data groups.

The next $$$T$$$ lines contain one chmod pattern string per line.

Output

There are $$$T$$$ lines in total, representing the 'permission string' corresponding to the pattern string.

Example
Input
3
356
114
514
Output
-wxr-xrw-
--x--xr--
r-x--xr--

B. Expression Matrix
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A $$$n \times m$$$ character matrix $$$a_{ij}$$$ is called a legal expression matrix if and only if it satisfies the following conditions:

  • The matrix only contains the characters '1', '+', and '*'.
  • For each line, the string formed by reading the matrix from left to right is a legal expression.
  • For each column, the string formed by reading the matrix from top to bottom is a legal expression.

The weight of a legal expression matrix is defined as the sum of the values obtained by evaluating the $$$n + m$$$ expressions formed by reading each row from left to right and each column from top to bottom.

Find the legal expression matrix of size $$$n \times m$$$ with the smallest weight. If there are multiple answers, you can output any of them.

We define a string $$$s$$$ as a legal expression as follows:

  • If $$$s = \overbrace{111\dots111}^{\text{at least one } 1}$$$, then $$$s$$$ is a legal expression.
  • If both $$$s$$$ and $$$t$$$ are legal expressions, then $$$s$$$ * $$$t$$$ is also a legal expression.
  • If both $$$s$$$ and $$$t$$$ are legal expressions, then $$$s$$$ + $$$t$$$ is also a legal expression.
Input

The input consists of a single line with two integers $$$n, m$$$ ($$$3 \leq n, m \leq 9$$$), separated by space, representing the number of rows and columns of the matrix.

Output

Output $$$n$$$ lines, each containing $$$m$$$ characters. The $$$j$$$-th character of the $$$i$$$-th line, $$$a_{ij}$$$, represents the matrix with the smallest weight.

If there are multiple answers, you can output any one of them.

Example
Input
4 4
Output
1111
1*11
11*1
1111
Note

For the given example, the weight of the matrix is $$$4488$$$, and it can be proven that there is no matrix with a smaller weight.

C. Seats
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Kingdom of Tree is preparing to hold a grand celebration!

As the celebration designer of the Kingdom of Tree, Shirost is preparing to invite $$$n$$$ guests to attend the celebration. There are a total of $$$2n$$$ seats prepared for the celebration, each seat can only accommodate one person and each person sits in exactly one seat. Shirost initially plans to arrange the $$$i$$$-th guest in the $$$i$$$-th seat. However, the president has surveyed the wishes of these $$$n$$$ guests, and the desired seat for the $$$i$$$-th guest is the $$$a_i$$$-th seat. But unless they can sit in their desired seat, they would only sit in their original seat. The president hopes that Shirost can modify the plan to maximize the number of guests sitting in their desired seats.

Formally, you need to find an array $$$b_i$$$ of length $$$n$$$ ($$$1 \leq i \leq n, 1 \leq b_i \leq 2n$$$) satisfying $$$\forall i \neq j,b_i \neq b_j$$$ and $$$\forall i, b_i=i$$$ or $$$b_i=a_i$$$. Morever, you should maximize the number of $$$b_i = a_i$$$.

You only need to output the maximum number.

Input

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^{5}$$$), representing the total number of guests.

The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \leq a_i \leq 2n$$$), separated by spaces, representing the desired seats of each guest.

Output

Output a single integer on a single line, representing the maximum number of guests sitting in their desired seats.

Example
Input
5
2 6 4 5 3
Output
5
Note

Example explanation:

All guests can move to their desired seats.

D. Double Subsequence
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Little L has a hard time seeing strings he doesn't like! Seeing them appear as subsequences is too!

Given a long string $$$S$$$ denoting the text that Little L wants to read, and exactly two short strings $$$s_1$$$, $$$s_2$$$ denoting the strings that Little L doesn't want to see, all three strings consist of lowercase letters.

Little L is disgusted by the fact that two strings appear as subsequences within the text at the same time, and he believes that a string $$$T$$$'s antisense value is the product of the number of occurrences of $$$s_1$$$ as a subsequence of $$$T$$$, and the number of occurrences of $$$s_2$$$ as a subsequence of $$$T$$$.

Since he's going to read each subsegment of $$$S$$$, he now needs you to find the sum of the antisense value of all the subsegments of $$$S$$$. Since the answer may be too large, you only need to output the result of modeling $$$998244353$$$.

A sequence $$$H$$$ is a subsequence of a sequence $$$T$$$ if $$$H$$$ can be obtained from $$$T$$$ by the deletion of several (possibly zero or all) elements.

A sequence $$$H$$$ is a subsegment of a sequence $$$T$$$ if $$$H$$$ can be obtained from $$$T$$$ by the deletion of several (possibly zero or all) elements from the beginning and several (possibly zero or all) elements from the end.

Input

The input consists of three lines, each line a string consisting only of lowercase letters.

The string in the first line represents $$$S$$$, the second line represents $$$s_1$$$, and the third line represents $$$s_2$$$, where $$$1\le |S|\le 1\times 10^5$$$, $$$1\le |s_1|$$$, $$$|s_2|\le 20$$$.

Output

Outputs an integer representing the answer solved.

Example
Input
iccpcicpc
icpc
ccpc
Output
133
Note

The example is explained as follows:

begin positionend positionicpc numbersccpc numbers
1521
1621
1742
1842
19119
2501
2601
2702
2802
2919
3913
4911
5911
6910

In the remaining subsegments, both strings appear as subsequences $$$0$$$ times.

The answer is $$$(2\times 1) \times 2 + (4\times 2) \times 2 + 11\times 9 + (0\times 1)\times 2 + (0\times 2)\times 2 + 1\times 9 + 1\times 3+ (1\times 1)\times 2 + 1\times 0=133$$$.

E. Trade Road
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A circle is divided into $$$K$$$ points which are numbered clockwise as $$$1, 2, \cdots, K$$$. Among them, markets $$$M_1, M_2, \cdots, M_n$$$ are built at points $$$a_1, a_2, \cdots, a_n$$$ respectively.

A trade route from market $$$i$$$ to market $$$j$$$ is a directed line segment $$$M_i M_j$$$ ($$$i \neq j$$$) and must satisfy the following conditions:

  • Market $$$j$$$ must be the farthest market from market $$$i$$$ (if there are multiple markets at the same farthest distance, any one of them is acceptable).
  • The route segment $$$M_i M_j$$$ cannot intersect or overlap with other route segments at points other than the starting or ending points.

What is the maximum number of trade routes that can exist?

Input

The first line contains two integers $$$K$$$, $$$n$$$ ($$$3 \leq K \leq 10^9, 3\leq n \leq \min(K,10^5) $$$), separated by a space, representing that there are $$$n$$$ markets distributed at the $$$K$$$ equally spaced points on the circle.

The second line contains $$$n$$$ integers $$$a_1, a_2, \cdots, a_n$$$ ($$$1\leq a_1 \lt a_2 \lt \cdots \lt a_{n-1} \lt a_n \leq K$$$), correspond to points at which a market is built.

Output

Output an integer representing the maximum number of trade routes that can exist.

Examples
Input
10 5
1 2 5 6 8
Output
2
Input
3 3
1 2 3
Output
3
Note

For the first example, the two possible answers are shown in the following figures:

F. Try a try, AC is OK
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

MCPlayer542 is working on a problem.

Since the problem is so difficult, he can't just write the correct solution, but instead writes $$$n$$$ different codes, where the $$$i$$$-th code can get $$$g_i$$$ points.

With time running out, MCPlayer542 was going to just hand the code in haphazardly. However, he realizes that due to the special rules of the contest, he must submit twice, and the total score he gets will be the bitwise AND operation of the scores of the two submissions.

Formally, if he submits the $$$i$$$-th and $$$j$$$-th code in the two submissions, the score is $$$g_i\& g_j$$$, where $$$\&$$$ denotes a bitwise AND operation.

He wants to know the highest score he can get.

Input

Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$($$$1\le t\le 2\times 10^5$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$($$$1\le n \le 2\times 10^5$$$) — the number of codes.

The next line contains $$$n$$$ integers $$$g_1,\ g_2,\ \ldots,\ g_n$$$($$$0 \le g_i \lt 2^{30}$$$), separated by single spaces.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\times 10^5$$$.

Output

For each test case, output a single integer in a line, denoting the answer.

Example
Input
2
3
10 4 15
4
10 10 5 4
Output
15
10
Note

In the first test case, you can submit the third code twice.

In the second test case, you can submit the first and the second codes.

G. Disappearing Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

uuku is learning digital dynamic programming.

But one day, he found that the $$$x$$$ in the nine digits of $$$1,2,\ldots,9$$$ had disappeared, which means that all numbers containing the digit $$$x$$$ had disappeared.

This made him very panicked because it had a significant impact on the number of statistics.

Now, he hopes you can help him find out where the number $$$n$$$ ranks among the natural numbers that have not disappeared in this situation.

Input

There are multiple test cases. The first line of the input contains an integer $$$T$$$ ($$$1 \leq T \leq 10^5$$$), indicating the number of test cases.

For each test case:

The first line contains two positive integers $$$n$$$ and $$$x$$$ ($$$0 \leq n \leq 10^{18}$$$, $$$1 \leq x \leq 9$$$).

It's guaranteed that $$$n$$$ doesn't include $$$x$$$.

Output

For each test case, output a number indicating the ranking of $$$n$$$.

Example
Input
5
9 4
99 7
12345678 9
9475632111234123 8
998244353114514 7
Output
9
81
6053445
1758041005111510
205404686678741
Note

For the first example, the natural sequence becomes $$$0,1,2,3,5,6,7,8,9$$$, where the number $$$9$$$ is the $$$9$$$ th.

H. Maximum Flow
time limit per test
15 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given a directed acyclic graph with $$$n$$$ vertices and $$$m$$$ edges with $$$1$$$ capacity. For every vertex $$$i$$$ except vertex $$$1$$$, if the maximum flow from vertex $$$1$$$ to vertex $$$i$$$ is $$$f_i$$$, please output $$$\min\{f_i,\ k\}$$$.

For a graph with edge capacity $$$1$$$, a flow from vertex $$$1$$$ to vertex $$$i$$$ is a path from vertex $$$1$$$ to vertex $$$i$$$. If there can be at most $$$f_i$$$ disjoint paths from vertex $$$1$$$ to vertex $$$i$$$(i.e. each pair of flows do not share edges), we consider the maximum flow from vertex $$$1$$$ to vertex $$$i$$$ to be $$$f_i$$$.

Input

The first line of input contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$2 \leq n \leq 10^5, 1 \leq m \leq 2 \times 10^5, 1 \leq k \leq 50$$$), separated by spaces, representing the number of vertices , the number of edges, and the parameter.

The next $$$m$$$ lines each contain two integers $$$x_i$$$, $$$y_i$$$ ($$$1 \leq x_i, y_i \leq n, x_i \neq y_i$$$), separated by spaces, describing a directed edge.

It is guaranteed that the graph has no self-loops, but may contain multiple edges. It is also guaranteed that the given graph is a directed acyclic graph.

Output

Output a single line containing $$$n-1$$$ integers separated by spaces. For the $$$i$$$-th integer, if the maximum flow from vertex $$$1$$$ to vertex $$$i+1$$$ does not exceed $$$k$$$, then output the value of the maximum flow; otherwise, output $$$k$$$.

Examples
Input
7 12 3
1 2
1 3
3 2
3 4
2 4
1 5
5 6
3 6
1 7
5 7
6 7
4 7
Output
2 1 2 1 2 3 
Input
5 8 50
1 2
1 2
1 2
3 2
2 4
2 4
2 4
2 4
Output
3 0 3 0 
Note

The graph described in the first example is as follows:

We can find $$$4$$$ disjoint paths from vertex $$$1$$$ to vertex $$$7$$$:

1->7

1->5->7

1->3->6->7

1->2->4->7

We can not find more disjoint paths from vertex $$$1$$$ to vertex $$$7$$$.

So the maximum flow from vertex $$$1$$$ to vertex $$$7$$$ is $$$f_7=4$$$, but since $$$k=3$$$, the sixth integer in the answer is $$$3$$$.

I. Prime Guess I
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

MCPlayer542 has a mysterious odd prime number $$$p$$$, but he doesn't want to let you know its value.

He plans to encrypt the number with a function $$$f(x)$$$ whose value is the sum of digits of $$$x$$$ in decimal, e.g.$$$f(5)=5$$$, $$$f(542)=5+4+2=11$$$, $$$f(1024)=1+0+2+4=7$$$.

However, considering you're so smart, he decides to change the function to the following one after a moment's thought: $$$$$$g(x)=f(f(f(f(f(f(f(f(f(f(x))))))))))$$$$$$ That is, apply $$$10$$$ times $$$f(x)$$$ in a row. To make the matter worse, he replaces $$$p$$$ with $$$q=p^k$$$ as well.

Now he is going to give you $$$n$$$ integers $$$g(q^{a_1}),\ g(q^{a_2}),\ \ldots,\ g(q^{a_n})$$$ and he requires the value of $$$$$$q^{a_1}\bmod (m\cdot a_1),\ q^{a_2}\bmod (m\cdot a_2),\ \ldots,\ q^{a_n}\bmod (m\cdot a_n)$$$$$$ respectively.

He's sure that you'll never make a successful guess, so he doesn't mind if you choose $$$m$$$ and $$$a_1,\ a_2,\ \ldots,\ a_n$$$ yourself. Can you accomplish this task?

Please note that there are restrictions on the range of $$$m$$$.

Input

Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$($$$1\le t\le 500$$$) — the number of test cases. The description of the test cases follows.

Interaction

The first line of each test case contains two integers $$$n$$$ and $$$k$$$($$$1\le n\le 50,\ 1\le k\le 10^9$$$), separated by a single space.

For each interaction following, output a single integer $$$a_i$$$($$$1\le a_i\le 10^{18}$$$, $$$a_i$$$ should be pairwise distinct) — the power of $$$q$$$ in a query.

After each query, you should read a single integer, $$$g(q^{a_i})$$$.

After $$$n$$$ rounds of interaction, you are required to output a single integer $$$m$$$($$$m\ge 35$$$, $$$1\le m\cdot a_i\le 10^{18}$$$) in a line, and $$$n$$$ integers separated by single spaces in the following line — $$$q^{a_1}\bmod (m\cdot a_1),\ q^{a_2}\bmod (m\cdot a_2),\ \ldots,\ q^{a_n}\bmod (m\cdot a_n)$$$.

You must make exactly $$$n$$$ queries, then output the answer and terminate your program, otherwise you may get unpredictable verdicts.

Please note that after each round of your output(i.e. after outputting $$$a_i$$$ in each query and after outputting $$$m$$$ and answers finally) it is required to output the end of line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:

  • fflush(stdout) in C;
  • cout.flush() in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python.

It is guaranteed that the odd prime number $$$p$$$($$$2 \lt p\le 10^{18}$$$) is fixed and does not change during the interaction.

Scoring

If the answer in your final output is correct, you will get the verdict Accepted;

If $$$m$$$ or $$$a_i$$$ in your output does not meet the restrictions, or your answer is incorrect, you will get the verdict Wrong Answer.

You may also get other verdicts if their usual cases occur.

Example
Input
2
3 1

3

9

9


3 2

4

4

4


Output


1

2

3

100
3 9 27

1

7

49

49
0 0 0
Note

In the first test case, $$$p=3$$$, so we have $$$q=p^k=3$$$.

We may choose $$$a=\{1,\ 2,\ 3\}$$$, then we receive $$$g(3^1)=3,\ g(3^2)=9,\ g(3^3)=9$$$, respectively.

Then we find that $$$p=3$$$. By choosing $$$m=100$$$, we should output $$$3^1\bmod (100\times 1)=3,\ 3^2\bmod (100\times 2)=9,\ 3^3\bmod (100\times 3)=27$$$.

In the second test case, $$$p=7$$$, so we have $$$q=p^k=49$$$.

We may choose $$$a=\{1,\ 7,\ 49\}$$$, then we receive $$$g(49^1)=4,\ g(49^7)=4,\ g(49^{49})=4$$$, respectively.

Then we may guess $$$p=7$$$. By choosing $$$m=49$$$, we should output $$$49^1\bmod (49\times 1)=0,\ 49^7\bmod (49\times 7)=0,\ 49^{49}\bmod (49\times 49)=0$$$.

Please note that the explanation of the second test case is only intended to be an example of the interaction, it is not guaranteed that the interaction above will determine $$$p=7$$$.

J. Prime Guess II
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

MCPlayer542 had a hard time trying to prepare a mysterious prime number.

He then invented a geniusstupid way to do it, and named it "prime score".

He prepared $$$n$$$ different numbers $$$a_1,\ a_2,\ \ldots,\ a_n$$$ as tests, and defined the "prime score" $$$score(x,l,r)$$$ as follows:

$$$$$$score(x,l,r)=\sum_{i=l}^r{f(x,a_i)}$$$$$$ where $$$$$$f(x,y)=\left\{\begin{array}{rcl}u-y, & x=1 \\ u, & 1 \lt x\le y,\ \gcd(x,y)=1 \\ -x\cdot y, & x\neq 1,\ \gcd(x,y)=x \\ 0, & \text{otherwise}. \end{array}\right.$$$$$$

It can be seen that the "prime score" of a prime number is usually higher but it still doesn't help.

So MCPlayer542 is angry, now his only plan is to run a brute-force on the test and get a sum of score $$$\sum_{i=1}^{10^6}{score(i,l,r)}$$$. He will test $$$q$$$ times, given $$$u$$$ and $$$l$$$ for each test, where $$$u$$$ is an argument to the function $$$f(x,y)$$$.

For each query, he wants to know the maximum sum of score that can be obtained and the minimum $$$r$$$ to get the maximum sum of score.

Input

The first line contains two integers $$$n,\ q$$$ ($$$1\le n,\ q\le 5\times 10^5$$$) — the number of tests and the number of queries, separated by a single space.

The second line contains $$$n$$$ integers $$$a_1,\ a_2,\ \ldots,\ a_n$$$ ($$$1\le a_i\le 10^6$$$) — the value of each test, separated by single spaces.

Each of the following $$$q$$$ lines contains two integers $$$u_i,\ l_i$$$ ($$$1\le u_i \le 1.8\times 10^7,\ 1\le l_i\le n$$$), separated by a single space, denotes a query.

Output

For every query, output two integers separated by a single space — the maximum sum of score and the minimum $$$r_i$$$ ($$$l_i\le r_i\le n$$$) to get the maximum sum of score.

Examples
Input
10 7
10 9 2 1 5 3 10 10 1 8
14 4
17 5
13 10
16 1
12 4
16 6
16 3
Output
55 6
60 6
-68 10
-58 6
41 6
20 6
79 6
Input
6 8
3 7 7 10 8 9
21 1
20 4
21 3
21 5
21 1
21 2
21 2
21 5
Output
170 3
-100 4
70 3
-27 6
170 3
140 3
140 3
-27 6
Note

In the first query of Sample 1, $$$u_1=14,\ l_1=4$$$. If we choose $$$r_1=6$$$, the final sum of score is $$$\sum_{i=1}^{10^6}{score(i,4,6)}$$$. We can see that:

  • $$$score(1,4,6)=13+9+11=33$$$;
  • $$$score(2,4,6)=0+14+14=28$$$;
  • $$$score(3,4,6)=0+14-9=5$$$;
  • $$$score(4,4,6)=0+14+0=14$$$;
  • $$$score(5,4,6)=0-25+0=-25$$$;
  • for any other $$$i$$$, we have $$$score(i,4,6)=0+0+0=0$$$.
Therefore, the sum of scores for $$$r_1=6$$$ is $$$33+28+5+14-25=55$$$.

It can be shown that a larger sum of scores cannot be obtained for any other value of $$$r_1$$$, so the answer is $$$55$$$ and the minimum $$$r_1$$$ to get the sum is $$$6$$$.

K. Lethal Company
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, Shirost has been addicted to a game called Lethal Company.

In the game, players will act as contract workers for the company, collecting valuable waste from abandoned industrial planets. In the process of exploration, Shirost will encounter a monster called Coil-Head, which will move extremely rapidly when nobody is watching it, but will remain stationary when someone is watching it. As soon as approached by Coil-Head, workers will be killed immediately .

Now Shirost is standing at the intersection of $$$n$$$ infinitely long passages. He knows there will be $$$m$$$ Coil-Heads, appearing in the $$$x_i$$$ th passage at the $$$t_i$$$ th moment, $$$y_i$$$ meters away from him.

For each moment $$$j$$$, the following three events will occur in order:

  1. When the moment start, the Coil-Heads that satisfy $$$t_i = j$$$ will appear in the $$$x_i$$$-th passage, $$$y_i$$$ meters away from Shirost.
  2. Shirost chooses to watch exactly one passage.
  3. The Coil-Heads in this passage will be unable to move, but Coil-Heads which have appeared in other passages will move $$$k$$$ meters towards him. If any Coil-Head arrives at his position, he will die at the $$$j$$$ th moment.

Shirost wants to know the latest moment that he is alive. In other word, If Shirost is dead at the latest at the $$$j$$$ th moment, then you should output $$$j-1$$$. If he won't die, please output $$$-1$$$.

Input

The first line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \leq n \leq 5 \times 10^5, 1 \leq m \leq 5 \times 10^5, 1 \leq k \leq 10^{18}$$$), separated by spaces, representing the number of passages, the number of Coil-Heads, the distance that the Coil-Heads moves at each moment.

The next $$$m$$$ lines each contain three integers $$$t_i$$$, $$$x_i$$$, $$$y_i$$$ ($$$1 \leq t_i \leq 10^{18}, 1 \leq x_i \leq n, 1 \leq y_i \leq 10^{18}$$$), separated by spaces, representing the moment, the passage and the distance from Shirost when Coil-Head appears.

Output

Output a single integer on a single line, representing the latest moment of Shirost that he is alive. If he won't die, please output $$$-1$$$.

Examples
Input
2 3 2
1 1 6
2 2 7
3 1 8
Output
6
Input
114514 6 1919810
1 1 1
1 1 9
1 4 1
1 5 9
1 1 8
1 4 10
Output
0
Note

Shirost can act as follows:

momentpassage watched$$$1$$$st Coil-Head distance$$$2$$$nd Coil-Head distance$$$3$$$rd Coil-Head distance
116
2165
32456
41436
52234
61214

At the $$$7$$$ th moment, no matter which passage Shirost watches, he will be killed by Coil-Head at this moment. So the answer is $$$6$$$.

L. Chess
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

LNC likes numbers the product of whose digits is a factor of itself under the base of $$$k$$$. He calls these special numbers LNC-number. For example:

When $$$k = 10$$$, $$$y = (36)_{10}$$$ is a LNC-number because $$$(3 \times 6) \mid 36$$$.

When $$$k = 4$$$, $$$y = (12)_4$$$ is a LNC-number because $$$(12)_4 = (6)_{10}$$$ while $$$(1 \times 2) \mid 6$$$.

When $$$k = 2$$$, $$$y = (1101)_2$$$ is not a LNC-number because $$$(1101)_2 = (13)_{10}$$$ while $$$0$$$ is not the factor of $$$13$$$.

LNC is playing a game with LJJ in which LJJ gives $$$x$$$ pieces and then LNC chooses an integer $$$k$$$ ($$$k \geq 2$$$). They then alternately take away a number of pieces, requiring that the number of pieces taken should be a LNC-number under the base of $$$k$$$. LNC takes the first move, and the first one who cannot take pieces loses. Both LNC and LJJ are smart enough to choose the optimal strategy.

LJJ feels that this game is unfair. They play $$$T$$$ games. For each $$$x$$$ he gives, he wants to know the smallest $$$k$$$ such that LNC wins first.

Input

The first line gives a positive integer $$$T$$$ ($$$1 \le T \le 1 \times 10^2$$$), indicating the number of data cases.

One positive integer $$$x$$$ ($$$3 \le x \le 10^{18}$$$) per line for each of the next $$$T$$$ lines, representing the number $$$x$$$ given by LJJ.

Output

Output $$$T$$$ lines, each containing a positive integer $$$k$$$, representing the smallest $$$k$$$ for each query that ensures LNC will win.

Example
Input
3
9
5
10
Output
2
2
3
Note

When $$$x=5$$$, LNC can choose $$$k=2$$$. $$$x=(5)_{10}=(101)_2$$$.

LNC takes away $$$(11)_2$$$ first, then $$$x=(10)_2$$$, and LJJ can only take away $$$(1)_2$$$. LNC takes the last $$$(1)_2$$$ and wins.

Since $$$k=2$$$ cannot be smaller, the final answer is $$$k=2$$$.

M. Window Decoration
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a window with dimensions $$$100 \text{cm} \times 100 \text{cm}$$$ and $$$n$$$ square window decorations, each with a diagonal length of $$$2 \text{cm}$$$. Establish a coordinate system with the origin at the bottom left corner of the window $$$(0,0)$$$ and the top right corner at $$$(100,100)$$$. The center of the $$$i$$$-th window decoration is placed at a non-edge integer coordinate point $$$(x_i,y_i)$$$ $$$(1 \leq x_i,y_i \leq 99)$$$, and the diagonals of the window decorations are parallel to the coordinate axes.

Find out the total area of the window covered by at least one window decoration.

Input

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10000$$$).

Following are $$$n$$$ lines, each containing two integers $$$x_i,y_i$$$ ($$$1 \leq x_i,y_i \leq 99$$$), as described above.

Output

Output a single line with a single real number: area of the window covered by at least one window decoration.

Your answer is considered correct if its absolute or relative error does not exceed $$$10^{−4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a−b|}{\max (1,|b|)} \leq 10^{−4}$$$.

Example
Input
5
1 1
2 1
3 2
5 5
5 5
Output
7.5
Note

Explanation for the first example is shown as follows: