TheForces Round #40 (Maths-Forces)
A. Submission Bait II
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an integer $$$n$$$, and you need to construct an array $$$a$$$ of size $$$n$$$ satisfying:

  • $$$1 \le a_i \le 2n$$$ for all $$$1 \le i \le n$$$.
  • There are not two distinct indices $$$i$$$ and $$$j$$$ $$$(1 \le i,j \le n,$$$ $$$i \neq j)$$$ such that $$$a_i$$$ can be divided by $$$a_j$$$.
Input

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

The only line of each test case contains an integer $$$n$$$ ($$$1\le n\le 10^5$$$).

It is guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$10^5$$$.

Output

For each test case, output $$$n$$$ integers  — the array you construct.

If there are multiple solutions, print any of them.

Example
Input
3
2
3
4
Output
2 3
5 3 2
2 3 5 7

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

The Fibonacci sequence, where each number is the sum of the two preceding ones, is well-known in mathematics. Consider a sequence $$$a$$$ that follows a similar pattern but with subtraction instead of addition.

Given three integers $$$n$$$, $$$a_1$$$, and $$$a_2$$$. For $$$i \geq 3$$$, $$$a_i = a_{i-1} - a_{i-2}$$$.

Your task is to find

$$$$$$\sum_{i = 1}^{n} a_i \mod (10^9 + 7)$$$$$$

Input

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

Each of the next $$$t$$$ lines contains three integers $$$n$$$, $$$a_1$$$, and $$$a_2$$$ $$$(1 \leq n, a_1, a_2 \leq 10^9)$$$.

Output

For each test case, output the answer.

Example
Input
6
3 2 5
4 1 2
1 1 1
3 10 3
799843967 796619138 446173607
1000000000 1000000000 1000000000
Output
10
3
1
6
649554476
1000000000

C. Kaosar loves Polynomials
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two integers $$$k$$$, $$$n$$$ and a polynomial $$$P(x) = a_0+a_1x+a_2x^2+....+a_nx^n$$$.

Note

  • $$$P^{1}(x) = P(x)$$$

  • $$$P^{2}(x) = P(x)\cdot P(x)$$$

  • $$$P^{3}(x)=P(x) \cdot P(x) \cdot P(x)$$$
  • ...

  • $$$P^i(x) = \underbrace{P(x) \cdot P(x) \cdot \dots \cdot P(x)}_{\text{i times}}$$$

Your task is to find the value of total sum of the coefficients of $$$P^k(x)$$$ modulo $$$(10^9 + 7)$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 2 \cdot 10^4)$$$. The description of the test cases follows.

The first line of each test case contains $$$2$$$ integers $$$k$$$ $$$(1 \leq k \leq 2 \cdot 10^5)$$$ and $$$n$$$ $$$(0 \leq n \leq 2 \cdot 10^5)$$$.

The next line will contain $$$n+1$$$ integers $$$a_0,a_1,...,a_n$$$ $$$(-10^{9} \leq a_i \leq 10^{9})$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$2 \cdot 10^5$$$. However, there is no limit to the sum of $$$k$$$.

Output

For each test case, print the sum modulo $$$(10^9 + 7)$$$.

Example
Input
4
1 1
1 1
2 1
5 3
2 1
-2 -2
2003 3
-1 4 -2 1
Output
2
64
16
993748093
Note

In the first test, $$$P(x) = 1+x$$$. The sum of its coefficients is $$$1+1 = 2.$$$

In the second test, $$$P(x) = 5+3x$$$. We can get $$$P^{2}(x) = P(x) \cdot P(x) = 25+30x+9x^2$$$. The sum of its coefficients is $$$25+30+9 = 64$$$.

D. Array Forge
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is an array $$$a$$$. Initially, $$$a = [0]$$$.

Assume that you can perform several operations. In the $$$i$$$-th operation, you can do exactly one of the following two operations:

  • Set $$$a_1 := a_1 + 1$$$;
  • Choose an index $$$j$$$ ($$$1 \leq j \leq |a|$$$), and insert the value $$$i$$$ after $$$a_j$$$.

You are given $$$q$$$ independent queries. For each query, you are given three integers $$$x$$$, $$$l$$$, and $$$r$$$ ($$$1 \leq$$$ $$$\boldsymbol{x \leq l}$$$ $$$\leq r$$$). Your task is to count the number of distinct arrays $$$a$$$ that satisfy the following conditions:

  • $$$a_1 \leq x$$$;
  • The number of operations performed is in the range $$$[l, r]$$$.

Since the answers may be large, you need to output them modulo $$$998\,244\,353$$$.

Input

The first line contains an integer $$$q$$$ ($$$1 \le q \le 10^5$$$)  — the number of queries.

Next, there are $$$q$$$ lines, each containing three space-separated integers $$$x$$$, $$$l$$$, and $$$r$$$ ($$$1 \leq \boldsymbol{x \leq l}$$$ $$$\leq r\le 10^6$$$).

Output

For each query, output the answer modulo $$$998\,244\,353$$$ on a new line.

Example
Input
6
1 1 1
1 1 2
2 2 3
3 4 5
800000 900000 1000000
1000000 1000000 1000000
Output
2
6
20
384
146046122
463285462
Note

In the first test case, all the $$$2$$$ possible arrays are:

  • $$$[1]$$$
  • $$$[0,1]$$$

In the second test case, all the $$$6$$$ possible arrays are:

  • $$$[1]$$$
  • $$$[0,1]$$$
  • $$$[1,1]$$$
  • $$$[1,2]$$$
  • $$$[0,1,2]$$$
  • $$$[0,2,1]$$$

E. GCD and LCM in Perfect Sync
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given $$$a_1$$$ and $$$n$$$, find the number of sequences of positive integers $$$a_2, a_3, \dots, a_n$$$ that satisfy the following condition:

$$$$$$ \frac{\operatorname{lcm}(a_1, a_2, \ldots, a_n)}{\gcd(a_1, a_2, \ldots, a_n)} = a_1 $$$$$$

Here, $$$\gcd(a_1, a_2, \dots, a_n)$$$ denotes the greatest common divisor, which is the largest positive integer that divides each number in the sequence, and $$$\operatorname{lcm}(a_1, a_2, \dots, a_n)$$$ denotes the least common multiple, which is the smallest positive integer that is divisible by each number in the sequence.

Since the answer can be large, output it modulo $$$998\,244\,353$$$. It can be proven that the answer is finite.

Input

The first line contains a single integer $$$t$$$ $$$(1\le t\le 1000)$$$ — the number of test cases.

The only line of each test case consists of two integers $$$a_1$$$ and $$$n$$$ ($$$2 \le a_1,n \le 10^9$$$).

Output

For each test case, output the number of sequences satisfying the condition above modulo $$$998\,244\,353$$$.

Example
Input
4
2 3
4 3
666 999
1000000000 1000000000
Output
6
12
15861573
208999360
Note

In the first test case, all the $$$6$$$ valid sequences are $$$[2,1,1],[2,1,2],$$$ $$$[2,2,1],[2,2,4],[2,4,2],$$$ and $$$[2,4,4]$$$.

F. Mega Polynomial
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two polynomials $$$f(x) = Ax + B$$$ and $$$g(x) = Cx^n + Dx^{n-1}$$$. Your task is to find the minimum integer $$$k$$$, such that $$$g^{(k)}(x)$$$ is divisible by $$$f(x)$$$.

Here, $$$g^{(k)}(x)$$$ represents taking the derivative of $$$g(x)$$$ exactly $$$k$$$ times.

Formally,

  • $$$g^{(0)}(x) = g(x)$$$,
  • $$$g^{(k)}(x) = \frac{d}{dx} \left( g^{(k-1)}(x) \right)$$$ for $$$k \geq 1$$$,

and

  • $$$\frac{d}{dx} \left( Ex^m + Fx^{m-1} \right) = mEx^{m-1} + (m-1)Fx^{m-2}$$$ for $$$m \gt 1$$$,
  • $$$\frac{d}{dx} \left( Gx \right) = G$$$,
  • $$$\frac{d}{dx} \left( G \right) = 0$$$,

where $$$E$$$, $$$F$$$, and $$$G$$$ are constants.

For example, for $$$g(x) = x^3 + 3x^2$$$, we can find that:

  • $$$g^{(1)}(x) = 3x^2 + 6x$$$,
  • $$$g^{(2)}(x) = 6x + 6$$$,
  • $$$g^{(3)}(x) = 6$$$,
  • $$$g^{(4)}(x) = 0$$$.

We say that a polynomial $$$P_1(x)$$$ is divisible by $$$P_2(x)$$$ if and only if there exists a polynomial $$$Q(x)$$$ such that $$$P_1(x) = Q(x)P_2(x)$$$, where the coefficients of $$$Q$$$ are integers.

Input

The first line contains one positive integer $$$t$$$ ($$$1\leq t \leq 10^5$$$) — the number of test cases.

Each test case consists of one line which contains $$$5$$$ integers $$$A,B,C,D,n$$$ ($$$1\leq A,B,C,D,n\leq 2\cdot 10^5$$$).

Output

For each test case, output the minimum integer $$$k$$$, such that $$$g^{(k)}(x)$$$ is divisible by $$$f(x)$$$.

Example
Input
6
1 2 2 4 1
4 2 3 3 4
2 4 1 3 3
2 1 5 2 4
131296 123463 91609 133724 142208
172458 127836 190471 141192 190476
Output
0
2
4
5
50599
190477
Note

In the first test case, $$$f(x)=x+2$$$ and $$$g(x)=2x+4$$$. We can see that $$$g^{(0)}(x)$$$ is divisible by $$$f(x)$$$ because $$$g^{(0)}(x)=g(x)=2x+4=2 \cdot f(x)$$$. So, the answer is $$$0$$$.

In the second test case, $$$f(x)=4x+2$$$ and $$$g(x)=3x^4+3x^3$$$. We can see that $$$k=2$$$ is the minimum integer such that $$$g^{(k)}(x)$$$ is divisible by $$$f(x)$$$ because $$$g^{(2)}(x)=36x^2+18x=9x \cdot f(x)$$$.

In the third test case, $$$f(x)=2x+4$$$ and $$$g(x)=x^3+3x^2$$$. We can see that $$$k=4$$$ is the minimum integer such that $$$g^{(k)}(x)$$$ is divisible by $$$f(x)$$$ because $$$g^{(4)}(x)=0=0 \cdot f(x)$$$.

Note that although $$$g^{(1)}(x)=3x^2+6x=\frac{2}{3}x \cdot f(x)$$$, $$$g^{(1)}(x)$$$ is not divisible by $$$f(x)$$$ since $$$\frac{2}{3}$$$ is not an integer.

G. Max-Min Madness
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array $$$a$$$ of length $$$n$$$. You can perform the following two operations any number of times, in any order:

  1. Choose an index $$$i$$$ such that $$$a_i \gt 0$$$, and decrement $$$a_i$$$ by $$$1$$$. In other words, assign $$$a_i := a_i - 1$$$.
  2. Select $$$k \geq 2$$$ distinct indices $$$i_1, i_2, \dots, i_k$$$ such that there exists at least one pair of indices $$$i_x$$$ and $$$i_y$$$ satisfying $$$a_{i_x} \neq a_{i_y}$$$. In other words, not all the values in the picked indices are the same. Then simultaneously set the values of all of $$$a_{i_1},a_{i_2},\dots,a_{i_k}$$$ to $$$(\max(a_{i_1}, a_{i_2}, \dots, a_{i_k})$$$ $$$- \min(a_{i_1}, a_{i_2}, \dots, a_{i_k}) - 1)$$$.

    For example, given $$$a = [1,0,1,9,1]$$$, choosing $$$a_1, a_3, a_4$$$ for operation $$$2$$$ results in $$$a=[7,0,7,7,1]$$$. However, choosing $$$a_1, a_3, a_5$$$ for operation $$$2$$$ is invalid, as their values are the same.

You want to choose a sequence of operations that maximizes the total number of operations. Find the maximum number of operations possible. Since the answer can be large, output it modulo $$$998\,244\,353$$$.

Input

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.

For each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the size of the array $$$a$$$.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^6$$$).

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

Output

For each test case, output a single integer in a new line — the maximum number of operations possible modulo $$$998\,244\,353$$$.

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

In the first test case, you can only choose $$$a_1$$$ for operation $$$1$$$ five times.

In the second test case, the optimal strategy is the following:

  1. Choose $$$a_1$$$ and $$$a_2$$$ for operation $$$2$$$. After that, $$$a=[1,1]$$$.
  2. Choose $$$a_1$$$ for operation $$$1$$$. After that, $$$a=[0,1]$$$.
  3. Choose $$$a_2$$$ for operation $$$1$$$. After that, $$$a=[0,0]$$$.

After this, we can no longer perform any of the two operations on the array.