2018-2019 Summer Petrozavodsk Camp, Oleksandr Kulkov Contest 2
A. Square Root Partitioning
time limit per test
3 seconds
memory limit per test
256 mebibytes
input
standard input
output
standard output

Consider the following expression: $$$$$$\sqrt{a_1} \pm \sqrt{a_2} \pm \dots \pm \sqrt{a_n} = 0\text{.}$$$$$$ Calculate the number of ways to replace each $$$\pm$$$ with $$$+$$$ or $$$-$$$ so that it holds true.

Input

The first line of input contains a single integer $$$n$$$ ($$$2 \leq n \leq 36$$$).

Second line of input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^{10^5}$$$).

Output

Output a single integer: the answer to the problem.

Examples
Input
3
2 2 8
Output
1
Input
4
4 9 25 49
Output
0
B. Yet Another Convolution
time limit per test
6 seconds
memory limit per test
256 mebibytes
input
standard input
output
standard output

You are given an integer array $$$a_1, \dots, a_n$$$ and an integer array $$$b_1, \dots, b_n$$$.

You have to calculate the array $$$c_1, \dots, c_{n}$$$ defined as follows:

$$$$$$c_k = \max\limits_{\gcd(i,j) = k} |a_i - b_j|\text{.}$$$$$$

Input

The first line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$).

The second line of input contains $$$n$$$ integers $$$a_1, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$).

The third line of input contains $$$n$$$ integers $$$b_1, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$).

Output

Output $$$n$$$ integers $$$c_1, \dots, c_n$$$.

Example
Input
8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
Output
7 5 3 3 1 3 5 7
C. Money Sharing
time limit per test
1 second
memory limit per test
256 mebibytes
input
standard input
output
standard output

It becomes more and more popular to share something instead of buying it.

One of the promising sharing systems is money sharing. There are numerous approaches to it, but we will deal with the one when there is a public entry point where money may be borrowed or returned free of charge. No need to say that the system quickly rose to be extremely popular.

Due to such popularity, it is hard to keep the system stable, so one has to request borrowing some money several days in advance. You are to develop an automatic managing system for money sharing. Consider a single day: during the day, you have $$$n$$$ requests for money lending, and there are also $$$m$$$ resupplies scheduled. They both may be described by non-zero integer $$$x$$$. Initially, the entry point has no money. On event described by $$$x$$$:

  • If $$$x \gt 0$$$, then it is a resupply, so the amount of money in the entry point is increased by $$$x$$$.
  • If $$$x \lt 0$$$, then it is a request to borrow the amount of money equal to $$$|x|$$$. If the request is approved, then the amount of money in the entry point is decreased by $$$|x|$$$. Otherwise, it does not change.

Unfortunately, it is not always possible to satisfy all requests, because the entry point may eventually end up not having enough money to lend, so some requests may have to be declined. Your task is, given the description of all requests and resupplies, to choose for each request whether to accept or decline it, so that the entry point always has enough money to satisfy the accepted requests. If there are multiple possible answers, you should choose the one having the minimum possible number of requests declined. If there are still multiple possible answers, find any one of them.

Input

The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$).

Each of the next $$$n+m$$$ lines contains a single integer $$$x$$$ ($$$1 \leq |x| \leq 10^9$$$) and describe the events.

Events are described in the order they occur, no two events occur at the same moment of time.

Output

Output your answer in $$$n+m$$$ lines.

For each resupply event, simply output "resupplied".

For each request, output "approved" or "declined" depending on your decision.

Example
Input
4 1
+5
-3
-2
-1
-1
Output
resupplied
declined
approved
approved
approved
D. Magic Strings
time limit per test
4 seconds
memory limit per test
256 mebibytes
input
standard input
output
standard output

Consider the sequence of strings $$$F_1, F_2, \dots$$$, defined as:

$$$$$$ F_1 = ab\text{,} $$$$$$ $$$$$$ F_{k+1} = F_kF_kb\text{.} $$$$$$

Calculate the number of distinct subsequences of the string $$$F_{n}$$$ modulo $$$10^9+7$$$.

Input

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10$$$), which is the number of test cases.

The second line of input contains $$$t$$$ integers $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$), one for each test case.

Output

For each test case, output the single integer which is the answer to the problem. Separate consecutive answers by single spaces.

Example
Input
3
1 2 3
Output
4 17 226 
Note

The first three strings are: $$$F_1 = \texttt{ab}$$$, $$$F_2 = \texttt{ababb}$$$, and $$$F_3 = \texttt{ababbababbb}$$$.

E. Decimal Expansion
time limit per test
1 second
memory limit per test
256 mebibytes
input
standard input
output
standard output

Consider the following constant: $$$$$$\varphi = \dfrac{9}{10} \cdot \dfrac{99}{100} \cdot \dfrac{999}{1000} \cdot \dfrac{9999}{10000}\cdot \dots$$$$$$

You have to find the $$$n$$$-th digit after the decimal separator in the decimal representation of $$$\varphi$$$.

Input

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) which is the number of test cases.

The next line contains $$$t$$$ integers $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$), one for each test case.

Output

For each test case, output a single digit which is the answer to that test case. Separate consecutive answers by single spaces.

Example
Input
15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Output
8 9 0 0 1 0 0 9 9 9 9 8 9 9 9 
Note

The constant evaluates as $$$\varphi = 0.890010099998999\dots$$$

F. Cosmic Crossroads
time limit per test
4 seconds
memory limit per test
256 mebibytes
input
standard input
output
standard output

Consider two sets of $$$n$$$ lines passing through the point $$$(0;0;0)$$$ in Euclidean three-dimensional space. Instead of actual lines, you are given two sets, $$$2n$$$ points in each set: $$$r_i=(x_i;y_i;z_i)$$$ and $$$r_j'=(x_j';y_j';z_j')$$$. These are the points where the lines intersect the unit sphere (two opposite points for each line).

It is known that the second set was obtained from the first one by some rotation around the origin and shuffling the order of the points. You have to find a permutation $$$\pi_1, \dots, \pi_{2n}$$$ and the rotation $$$\varphi$$$ of three-dimensional space such that, for all $$$i$$$, $$$$$$|r_{\pi_i} - \varphi(r'_i)| \leq 10^{-6}\text{.}$$$$$$ The rotation $$$\varphi$$$ should be described by point $$$e=(x;y;z)$$$ and angle $$$\theta$$$. It means we rotate the space around the axis from the origin to point $$$e$$$ by angle $$$\theta$$$ following the right-hand rule (see notes).

It is guaranteed that the directions of the first set of lines were chosen uniformly at random, independently from each other.

Input

The first line of input contains a single integer $$$n$$$ ($$$2 \leq n \leq 4 \cdot 10^4$$$).

Each of the next $$$2n$$$ lines contains three real numbers $$$x_i$$$, $$$y_i$$$ and $$$z_i$$$ describing points from the first set.

Each of the next $$$2n$$$ lines contains three real numbers $$$x'_i$$$, $$$y'_i$$$ and $$$z'_i$$$ describing points from the second set.

All real numbers are given with the precision of up to $$$12$$$ digits after decimal point.

It also holds that if point $$$r_i=(x_i;y_i;z_i)$$$ lies in one of sets then the point $$$-r_i$$$ lies in that set as well.

It is guaranteed that solution exists and would still exist even with precision of $$$10^{-9}$$$ instead of $$$10^{-6}$$$.

Output

On the first line, print a single real number $$$\theta$$$ ($$$-\pi \leq \theta \leq \pi$$$) describing the rotation angle.

On the second line, print three real numbers $$$x$$$, $$$y$$$, $$$z$$$ ($$$10^{-3} \leq |x|+|y|+|z| \leq 10^3$$$) describing the point $$$e$$$ on the rotation axis.

On the third line, print $$$2n$$$ integers $$$\pi_1, \dots, \pi_{2n}$$$.

Assume that rotation occurs in the sense prescribed by the right-hand rule (see notes).

Example
Input
2
0.923879533 0.382683432 0
0.923879533 -0.382683432 0
-0.923879533 -0.382683432 0
-0.923879533 0.382683432 0
0.382683432 0.923879533 0
0.382683432 -0.923879533 0
-0.382683432 -0.923879533 0
-0.382683432 0.923879533 0
Output
-1.570796327
0.000000000 0.000000000 1.000000000
2 3 4 1
Note

Just so you remember, rotation is done as follows:

Example test case looks like this:

The first set of points is $$$\{1,2,3,4\}$$$, and the second set of points is $$$\{1',2',3',4'\}$$$. After the rotation of the second set of lines by $$$-\tfrac{\pi}{2}$$$ around axis $$$(0;0;1)$$$, we obtain the following matching: $$$\{(1';2),(2';3),(3';4),(4',1)\}$$$.

H. Defying Gravity
time limit per test
2 seconds
memory limit per test
256 mebibytes
input
standard input
output
standard output

Planet Oz is located in the origin of two-dimensional euclidean space. Elphaba wants to show everyone that her powers lie far beyond the laws of physics. To do this, she wants to take off from Oz and fly away along some straight line to infinity and beyond.

The task is complicated by the fact that Oz has $$$n$$$ satellites revolving around it. For each satellite, its polar coordinates $$$(\rho_i; \varphi_i)$$$ and mass $$$m_i$$$ are known. Here, the planet and satellites are considered points, $$$\rho_i$$$ is the radial distance from Oz to the $$$i$$$-th satellite, and $$$\varphi_i$$$ is the polar angle between the satellite and some fixed reference direction measured in arc seconds.

Assume that Elphaba is located in the point denoted by vector $$$\vec r$$$ and has mass $$$m$$$, while $$$i$$$-th satellite is located in the point denoted by vector $$$\vec r_i$$$. The satellite attracts Elphaba with the force directed from Elphaba to the satellite. This force is proportional to Elphaba's mass $$$m$$$ and satellite's mass $$$m_i$$$, and inversely proportional to the squared distance between them, $$$|\vec r - \vec r_i|^2$$$. Thus, exact value of force $$$\vec F_i$$$ applied to Elphaba by $$$i$$$-th satellite is as follows:

$$$$$$\vec F_i = -\dfrac{Gmm_i(\vec r - \vec r_i)}{|\vec r - \vec r_i|^3}$$$$$$

Here, $$$G$$$ is the universal gravitational constant, the value of which does not concern us in this problem.

Forces applied from different satellites sum up directly. Therefore, the overall force $$$\vec F$$$ applied to Elphaba by all satellites is equal to $$$\vec F = \vec F_1 + \dots + \vec F_n$$$.

Elphaba wants to choose the direction of her flight in such a way that it doesn't pass through any of the satellites, and its direction is not affected by satellites at any moment of time. In other words, the force $$$\vec F$$$ must be collinear to $$$\vec r$$$ for all points $$$\vec r$$$ on Elphaba's trajectory.

Your task is to find all possible directions for Elphaba's flight.

Input

The first line of input contains a single even integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$), the number of satellites.

Each of the following $$$n$$$ lines contains three integers $$$\rho_i$$$, $$$\varphi_i$$$, and $$$m_i$$$ ($$$1 \leq \rho_i \leq 10^{18}$$$, $$$0 \leq \varphi_i \lt 129\,600$$$, $$$1 \leq m_i \leq 10^9$$$) representing polar coordinates and mass of the $$$i$$$-th satellite.

It is guaranteed that no two satellites have the same polar angle $$$\varphi$$$.

Output

Output a sorted list of real numbers $$$\alpha$$$ ($$$0 \leq \alpha \lt 129\,600$$$) denoting polar angles in arc seconds of all possible flight directions. Your answer would be considered correct if absolute or relative error of every number in the list is at most $$$10^{-6}$$$. It is guaranteed that the answer always contains at most $$$2 \cdot 10^{5}$$$ directions.

Example
Input
2
1 0 1
1 64800 1
Output
2
32400.0000000
97200.0000000
Note

One arc second (denoted as $$$1"$$$) is equal to one sixtieth of one arc minute (denoted as $$$1'$$$), which in turn is equal to one sixtieth of one arc degree (denoted as $$$1^\circ$$$). Therefore, $$$60" = 1'$$$, $$$60'=1^\circ$$$, and $$$129\,600"=360^\circ$$$, which means that $$$129\,600$$$ arc seconds constitute the full arc.

In the first example, the first satellite is located at point $$$A(1;0)$$$, and the second one is located at point $$$B(-1;0)$$$. The only possible flight directions on the picture are denoted by $$$\vec r_1$$$ and $$$\vec r_2$$$ having polar angles $$$90^\circ=32\,400"$$$ and $$$270^\circ=97\,200"$$$ correspondingly.

I. From Modular to Rational
time limit per test
6 seconds
memory limit per test
256 mebibytes
input
standard input
output
standard output

This is an interactive problem.

Someone picked a positive rational number $$$x=p/q$$$ where $$$1 \leq p, q \leq 10^9$$$. You may ask at most $$$10$$$ queries of the kind "? $$$m$$$", where $$$10^9 \lt m \lt 10^{12}$$$ and $$$m$$$ is a prime number. For each query, you will get the number $$$y$$$ such that $$$y \equiv pq^{-1} \pmod{m}$$$. You have to guess the number $$$x$$$.

Interaction

The first line of input contains a single integer $$$t$$$, the number of test cases ($$$1 \leq t \leq 10^5$$$).

For each test case, you may ask at most $$$10$$$ queries. Each query should be one of two types:

  1. "? $$$m$$$", where $$$10^9 \lt m \lt 10^{12}$$$ and $$$m$$$ is a prime number,
  2. "! $$$p$$$ $$$q$$$", where $$$1 \leq p, q \leq 10^9$$$, meaning that the answer is equal to $$$p/q$$$.
It is guaranteed that the number $$$x$$$ in each test case does not change during testing.
Example
Input
3

1


500000004


2
Output
 
? 1000000007

! 1 1
? 1000000007

! 2 4
? 1000000007

! 2 1
Note

In the example, you deal with $$$x=1/1$$$, $$$x=1/2$$$, and $$$x=2/1$$$, while always taking $$$m=10^9+7$$$.

As you may see, it is not necessary to have $$$\gcd(p,q)=1$$$ as long as $$$1\leq p,q\leq 10^9$$$ and $$$x=p/q$$$.

J. Tree Automorphisms
time limit per test
1 second
memory limit per test
256 mebibytes
input
standard input
output
standard output

Let $$$T$$$ be a tree on $$$n$$$ vertices. We call permutation $$$\pi = \pi_1, \pi_2, \dots, \pi_n$$$ an automorphism of $$$T$$$ if, for any pair of vertices $$$(u, v)$$$, there is an edge between them if and only if there is an edge between $$$\pi_u$$$ and $$$\pi_v$$$.

Let $$$\alpha=\alpha_1, \alpha_2, \dots, \alpha_n$$$ and $$$\beta=\beta_1,\beta_2,\dots,\beta_n$$$ be two permutations. Then their composition $$$\gamma = \alpha \circ \beta$$$ is defined as $$$\gamma = \alpha_{\beta_1}, \alpha_{\beta_2}, \dots, \alpha_{\beta_n}$$$, that is, $$$\gamma_i = \alpha_{\beta_i}$$$. Automorphisms of $$$T$$$ are closed under composition, so if $$$\alpha$$$ and $$$\beta$$$ are two automorphisms of $$$T$$$, then $$$\alpha \circ \beta$$$ is its automorphism as well. Indeed, it may be conceived as if we firstly applied automorphism $$$\beta$$$ and then automorphism $$$\alpha$$$.

You have to find a set of automorphisms $$$P=\{\pi^{(1)}, \pi^{(2)}, \dots, \pi^{(k)}\}$$$ such that $$$k \lt n$$$ and any automorphism of $$$T$$$ may be represented as finite composition of permutations from $$$P$$$.

Input

The first line of input contains a single integer $$$n$$$ ($$$2 \leq n \leq 50$$$), which is the number of vertices in the tree.

Each of the following $$$n-1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$) meaning that there is an edge between vertices $$$u_i$$$ and $$$v_i$$$ in the tree.

Output

On the first line, output a single integer $$$k$$$ ($$$1 \leq k \lt n$$$), which is the number of permutations in the set $$$P$$$.

Each of the following $$$k$$$ lines should contain $$$n$$$ integers each, denoting $$$i$$$-th permutation $$$\pi^{(i)}_1, \pi^{(i)}_2, \dots, \pi^{(i)}_n$$$.

If there are several possible sets $$$P$$$, output any one of them. It is guaranteed that the answer always exists.

Examples
Input
2
1 2
Output
1
2 1
Input
3
1 2
1 3
Output
1
1 3 2
Input
4
1 2
1 3
1 4
Output
2
1 3 2 4
1 4 3 2