Two players play following game. Initially they have number $$$ n $$$. Players make alternating turns. If the current number written on the board is more than $$$ 0 $$$ during his move the player can divide the current number by $$$2$$$ with rounding down or substract $$$ 1$$$ from the current number, but such a move can be made only when the current number is odd. (that is, $$$ 4 $$$ per move can be turned into $$$ 2 $$$, and $$$ 7 $$$ into $$$ 3 $$$ or $$$ 6 $$$). The game continues until number $$$ 0 $$$ appears on the board. The player who cannot make a move loses (that is, the player who is forced to move when the number $$$ 0 $$$ is written on the board). Determine who wins if both players play optimally – the one who moved first or the one who moved second. You need to answer $$$ t $$$ independent queries. For each of them print $$$ 1 $$$ if for the given $$$ n $$$ the first player wins, and $$$ 0 $$$ otherwise. Print the answers to the queries in the order in which they appear in the input data.
In first line ypu are given number $$$1 \le t \le 10^3$$$ - number of queries. In following $$$t$$$ lines you are given $$$t$$$ numbers, in each line – number $$$1 \le n \le 10^{18}$$$.
For every query output $$$1$$$ if first player wins and $$$0$$$ otherwise.
3 1 2 3
1 0 1
Let's define function $$$f$$$ from array of non-negative numbers $$$A$$$ of $$$n$$$ elements in the following way: $$$f(A, 0) = $$$ $$$\sum\limits_{i=1}^n a_i$$$;
$$$f(A, i) = $$$$$$\sum\limits_{l=1}^n \sum\limits_{r=l}^n$$$ $$$f(A[l, r], i - 1)$$$, $$$i \gt 0$$$, where $$$A[l, r]$$$ - subarray of array $$$A$$$ with indexes from $$$l$$$ to $$$r$$$. You are given $$$n$$$, $$$k$$$ and array $$$A$$$ of $$$n$$$ elements. Compute $$$f(A, k)$$$ modulo $$$10^9+7$$$.
In first line you are given two numbers: $$$1 \le n \le 2 * 10^5$$$ and $$$0 \le k \le 2 * 10^5$$$. In the second line you are given array of $$$n$$$ integers $$$0 \le a_i \le 10^9$$$.
Output answer modulo $$$10^9+7$$$.
5 0 1 2 3 4 5
15
5 1 1 2 3 4 5
105
3 2 1 2 3
42
Krosh has a graph of $$$n$$$ vertexes. For any vertex $$$1 \le i \le n - 2$$$ there are oriented edges $$$(i, i + 1)$$$ and $$$(i, i + 2)$$$, for vertex $$$n - 1$$$ there is oriented edge $$$(n - 1, n)$$$. Every vertex has it's value - $$$a_i$$$. Krosh considers paths from vertex $$$1$$$ to vertex $$$n$$$. Cost of the path is the maximum among all the values of the vertexes Krosh has visited. Help Krosh to calculate sum of costs over all the paths from $$$1$$$ to $$$n$$$. Output answer modulo $$$m$$$ where $$$m$$$ is given(can be non-prime).
In first line you are given two numbers $$$1 \le n \le 2 * 10^5$$$ and $$$10 \le m \le 10^9$$$ - number of vertexes and modulo.In next line you are given $$$n$$$ positive integres $$$1 \le a_i \le 10^9$$$ values of vertexes.
Output answer modulo m.
4 1000 2 3 5 3
13
1 1000000000 1000000000
0
5 583723 1000000000 1000000000 1000000000 1000000000 1000000000
412505
Krosh calls positive integer interesting if it can be represented as a sum of two powers of number two, in other words $$$x$$$ is interesting if there exists two non-negative numbers $$$i \ge 0$$$, $$$j \ge 0$$$, $$$i \neq j$$$ such that $$$x = 2^i + 2^j$$$. Krosh has big number $$$m$$$ in binary number system. Length of this number does not exceed $$$2*10^5$$$. Help Krosh to calculate how many interesting numbers there are from $$$1$$$ to $$$m$$$.
In first line you are given number $$$1 \le n \le 2 * 10^5$$$ the length of the number. In second line there is number $$$m$$$ of $$$n$$$ digits in binary system. Every digit is $$$0$$$ or $$$1$$$ and first digit is $$$1$$$.
4 1010
5
2 11
1
You are given number $$$n$$$. Find number of ways to decompose number $$$n$$$ on summands where each next summand is at least twice more than the previous. So for each $$$1 \le i \lt k$$$ where $$$k$$$ is number of summands $$$a_{i + 1} \ge 2 * a_i$$$.
You are given number $$$1 \le n \le 3 * 10^5$$$.
Output answer modulo $$$10^9+7$$$.
10
6
6
3
Krosh has given a new math homework: find the sum of the following series: $$$\sum\limits_{n = 1}^{\infty} \frac{(C_n^k) ^ 2}{2^n}$$$, where $$$k$$$ is given. Help him to find it for given $$$k$$$. It's guaranteed that answer is integer. Print it modulo prime number $$$10^9+7$$$.
You are given integer $$$0 \le k \le 10^6$$$.
Print the series sum modulo $$$10^9+7$$$.
2
26
$$$C_n^k$$$ – number of ways to choose $$$k$$$ objects from $$$n$$$ objects.
You are given number $$$n$$$. Consider permutation $$$p$$$ of integers from $$$1$$$ to $$$n$$$. Define $$$f(l, r) = (((p(l)$$$ $$$mod$$$ $$$p(l + 1))$$$ $$$mod$$$ $$$p(l + 2))$$$ $$$mod$$$ ... $$$mod$$$ $$$p(r)$$$. Let's beauty of permutation $$$B(p)$$$be the sum $$$f(l, r)$$$ over all the subsegments of permutation $$$B(p) = \sum_{l = 1}^n \sum_{r = l}^n f(l, r)$$$. Find expectation of the beauty of randomly chosen permutation of $$$n$$$ integers over given prime modulo $$$m$$$. It can be shown that answer can be represented as fraction $$$\frac{P}{Q}$$$, where $$$P$$$, $$$Q$$$ are integers and $$$Q \neq 0$$$ $$$(mod$$$ $$$m)$$$.
You are given numbers $$$1 \le n \le 300$$$ and $$$10^8 \le m \le 10^9$$$ where m is prime.
Output answer.
2 998244353
499122180
1 998244353
1
3 700000001
8
Krosh is going to celebrate his birthday soon. He thinks that friends will present him some permutation $$$p$$$ of $$$n$$$ numbers from $$$1$$$ to $$$n$$$. Krosh may dislike permutation because he likes fixed points. These are such positions $$$i$$$ where $$$p_i = i$$$. He wants permutation to contatin at least one fixed point. So he can do following moves with the presented permutation: swap any two adjacent elements in it. Krosh knows how to make minimum number of moves to obtain his goal but there is a new question for him: what is the maximum number of such moves he can do in worst scenario?
You are given $$$1 \le n \le 10^5$$$ – size of permutation.
In first line output maximum number of moves Krosh can make in worst case. In second line output the permutation on which this number of moves is obtained. If there are more than one answer output any of them.
2
1 2 1
Krosh has three numbers $$$ a $$$, $$$ b $$$, $$$ c $$$. Help him count the number of arrays of length $$$ n $$$, whose $$$ AND $$$ of elements is equal to $$$ a $$$, $$$ OR $$$ of elements is equal to $$$ b $$$, and $$$ XOR $$$ of elements is equal to $$$ c $$$. Two arrays are considered different if there is a position such that different arrays have different numbers at this position. Since the answer can get big, print its remainder after division by $$$ 10 ^ 9 + 7 $$$.
The first line contains the number of elements in the array $$$ 1 \le n \le 10 ^ {18} $$$. The second line contains the number $$$ a $$$. The third line contains the number $$$ b $$$. The fourth line contains the number $$$ c $$$. These numbers are written in binary notation, their lengths are equal and do not exceed $$$ 10 ^ 5 $$$. It is guaranteed that the number $$$ b $$$ denoting $$$ OR $$$ starts with $$$ 1 $$$. The numbers $$$ a $$$ and $$$ c $$$ may contain leading zeros.
Output answer modulo $$$10^9+7$$$.
4 001 101 100
8
Consider some number without leading zeroes(but 0 is allowed). We neee to obtain new number which is divisible by three. In one move we can take any digit of this number and decrease it(if it is not 0) or increase it by 1(if it is not 9). Resulting number should not contain leading zeroes(but 0 is allowed). What is the minimum number of such moves to get a number which is divisible by three?
You are given number n (0 ≤ n ≤ 1018).
Output answer to the problem.
12
0
124
1
0
0
123456788
1