meetforever/GRPO_CL huggingface dataset:
user: This is the hard version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved.

First, Aoi came up with the following idea for the competitive programming problem:

Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies.

Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array).

After that, she will do $n$ duels with the enemies with the following rules:

  If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing.  The candy which Yuzu gets will be used in the next duels. 

Yuzu wants to win all duels. How many valid permutations $P$ exist?

This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea:

Let's define $f(x)$ as the number of valid permutations for the integer $x$.

You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$.

Your task is to solve this problem made by Akari.


-----Input-----

The first line contains two integers $n$, $p$ $(2 \le p \le n \le 10^5)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 10^9)$.


-----Output-----

In the first line, print the number of good integers $x$.

In the second line, output all good integers $x$ in the ascending order.

It is guaranteed that the number of good integers $x$ does not exceed $10^5$.


-----Examples-----
Input
3 2
3 4 5

Output
1
3

Input
4 3
2 3 5 6

Output
2
3 4

Input
4 3
9 1 1 1

Output
0


Input
3 2
1000000000 1 999999999

Output
1
999999998



-----Note-----

In the first test, $p=2$.

  If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good.  If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good.  If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good.  If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. 

So, the only good number is $3$.

In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
user: You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right. 

Obviously, there is not enough sand on the beach, so you brought n packs of sand with you. Let height h_{i} of the sand pillar on some spot i be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with H sand packs to the left of the first spot and you should prevent sand from going over it. 

Finally you ended up with the following conditions to building the castle:  h_1 ≤ H: no sand from the leftmost spot should go over the fence;  For any $i \in [ 1 ; \infty)$ |h_{i} - h_{i} + 1| ≤ 1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen;  $\sum_{i = 1}^{\infty} h_{i} = n$: you want to spend all the sand you brought with you. 

As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible. 

Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold.


-----Input-----

The only line contains two integer numbers n and H (1 ≤ n, H ≤ 10^18) — the number of sand packs you have and the height of the fence, respectively.


-----Output-----

Print the minimum number of spots you can occupy so the all the castle building conditions hold.


-----Examples-----
Input
5 2

Output
3

Input
6 8

Output
3



-----Note-----

Here are the heights of some valid castles:   n = 5, H = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...]  n = 6, H = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied) 

The first list for both cases is the optimal answer, 3 spots are occupied in them.

And here are some invalid ones:  n = 5, H = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...]  n = 6, H = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...]
user: The Patisserie AtCoder sells cakes with number-shaped candles.
There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.
Each cake has an integer value called deliciousness, as follows:
 - The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
 - The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
 - The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.

There are X \times Y \times Z such ways to choose three cakes.

We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.

Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

-----Constraints-----
 - 1 \leq X \leq 1 \ 000
 - 1 \leq Y \leq 1 \ 000
 - 1 \leq Z \leq 1 \ 000
 - 1 \leq K \leq \min(3 \ 000, X \times Y \times Z)
 - 1 \leq A_i \leq 10 \ 000 \ 000 \ 000
 - 1 \leq B_i \leq 10 \ 000 \ 000 \ 000
 - 1 \leq C_i \leq 10 \ 000 \ 000 \ 000
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z

-----Output-----
Print K lines. The i-th line should contain the i-th value stated in the problem statement.

-----Sample Input-----
2 2 2 8
4 6
1 5
3 8

-----Sample Output-----
19
17
15
14
13
12
10
8

There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:
 - (A_2, B_2, C_2): 6 + 5 + 8 = 19
 - (A_1, B_2, C_2): 4 + 5 + 8 = 17
 - (A_2, B_1, C_2): 6 + 1 + 8 = 15
 - (A_2, B_2, C_1): 6 + 5 + 3 = 14
 - (A_1, B_1, C_2): 4 + 1 + 8 = 13
 - (A_1, B_2, C_1): 4 + 5 + 3 = 12
 - (A_2, B_1, C_1): 6 + 1 + 3 = 10
 - (A_1, B_1, C_1): 4 + 1 + 3 = 8
user: Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides both x and y.Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.Definition of dividing
An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq A, B \leq 10^{12}

-----Input-----
Input is given from Standard Input in the following format:
A B

-----Output-----
Print the maximum number of divisors that can be chosen to satisfy the condition.

-----Sample Input-----
12 18

-----Sample Output-----
3

12 and 18 have the following positive common divisors: 1, 2, 3, and 6.
1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.
user: To decide which is the strongest among Rock, Paper, and Scissors, we will hold an RPS tournament.
There are 2^k players in this tournament, numbered 0 through 2^k-1. Each player has his/her favorite hand, which he/she will use in every match.
A string s of length n consisting of R, P, and S represents the players' favorite hands.
Specifically, the favorite hand of Player i is represented by the ((i\text{ mod } n) + 1)-th character of s; R, P, and S stand for Rock, Paper, and Scissors, respectively.
For l and r such that r-l is a power of 2, the winner of the tournament held among Players l through r-1 will be determined as follows:
 - If r-l=1 (that is, there is just one player), the winner is Player l.
 - If r-l\geq 2, let m=(l+r)/2, and we hold two tournaments, one among Players l through m-1 and the other among Players m through r-1. Let a and b be the respective winners of these tournaments. a and b then play a match of rock paper scissors, and the winner of this match - or a if the match is drawn - is the winner of the tournament held among Players l through r-1.
Find the favorite hand of the winner of the tournament held among Players 0 through 2^k-1.

-----Notes-----
 - a\text{ mod } b denotes the remainder when a is divided by b.
 - The outcome of a match of rock paper scissors is determined as follows:
 - If both players choose the same hand, the match is drawn;
 - R beats S;
 - P beats R;
 - S beats P.

-----Constraints-----
 - 1 \leq n,k \leq 100
 - s is a string of length n consisting of R, P, and S.

-----Input-----
Input is given from Standard Input in the following format:
n k
s

-----Output-----
Print the favorite hand of the winner of the tournament held among Players 0 through 2^k-1, as R, P, or S.

-----Sample Input-----
3 2
RPS

-----Sample Output-----
P

 - The favorite hand of the winner of the tournament held among Players 0 through 1 is P.
 - The favorite hand of the winner of the tournament held among Players 2 through 3 is R.
 - The favorite hand of the winner of the tournament held among Players 0 through 3 is P.
Thus, the answer is P.
   P
 ┌─┴─┐
 P   R
┌┴┐ ┌┴┐
R P S R
 ```
       S
   ┌───┴───┐
   P       S
 ┌─┴─┐   ┌─┴─┐
 P   R   S   P
┌┴┐ ┌┴┐ ┌┴┐ ┌┴┐
R P S R P S R P
```
user: There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.
You can rearrange these children just one time in any order you like.
When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points.
Find the maximum total happiness points the children can earn.

-----Constraints-----
 - 2 \leq N \leq 2000
 - 1 \leq A_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N

-----Output-----
Print the maximum total happiness points the children can earn.

-----Sample Input-----
4
1 3 4 2

-----Sample Output-----
20

If we move the 1-st child from the left to the 3-rd position from the left, the 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and the 4-th child to the 2-nd position, the children earns 1 \times |1-3|+3 \times |2-4|+4 \times |3-1|+2 \times |4-2|=20 happiness points in total.
user: Let f(A, B) be the exclusive OR of A, A+1, ..., B. Find f(A, B).
What is exclusive OR?
The bitwise exclusive OR of integers c_1, c_2, ..., c_n (let us call it y) is defined as follows:
 - When y is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if, the number of integers among c_1, c_2, ...c_m whose binary representations have 1 in the 2^k's place, is odd, and 0 if that count is even.
For example, the exclusive OR of 3 and 5 is 6. (When written in base two: the exclusive OR of 011 and 101 is 110.)

-----Constraints-----
 - All values in input are integers.
 - 0 \leq A \leq B \leq 10^{12}

-----Input-----
Input is given from Standard Input in the following format:
A B

-----Output-----
Compute f(A, B) and print it.

-----Sample Input-----
2 4

-----Sample Output-----
5

2, 3, 4 are 010, 011, 100 in base two, respectively.
The exclusive OR of these is 101, which is 5 in base ten.
user: You are given a tree with N vertices.

Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices.

The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i.
You are also given Q queries and an integer K. In the j-th query (1≤j≤Q):
 - find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.

-----Constraints-----
 - 3≤N≤10^5 
 - 1≤a_i,b_i≤N (1≤i≤N-1) 
 - 1≤c_i≤10^9 (1≤i≤N-1) 
 - The given graph is a tree.
 - 1≤Q≤10^5 
 - 1≤K≤N 
 - 1≤x_j,y_j≤N (1≤j≤Q) 
 - x_j≠y_j (1≤j≤Q) 
 - x_j≠K,y_j≠K (1≤j≤Q) 

-----Input-----
Input is given from Standard Input in the following format:  
N  
a_1 b_1 c_1  
:  
a_{N-1} b_{N-1} c_{N-1}
Q K
x_1 y_1
:  
x_{Q} y_{Q}

-----Output-----
Print the responses to the queries in Q lines.

In the j-th line j(1≤j≤Q), print the response to the j-th query.

-----Sample Input-----
5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5

-----Sample Output-----
3
2
4

The shortest paths for the three queries are as follows:
 - Query 1: Vertex 2 → Vertex 1 → Vertex 2 → Vertex 4 : Length 1+1+1=3 
 - Query 2: Vertex 2 → Vertex 1 → Vertex 3 : Length 1+1=2 
 - Query 3: Vertex 4 → Vertex 2 → Vertex 1 → Vertex 3 → Vertex 5 : Length 1+1+1+1=4
user: Given is a string S of length N consisting of lowercase English letters.
Snuke can do this operation any number of times: remove fox occurring as a substring from s and concatenate the remaining parts of s.
What is the minimum possible length of s after some number of operations by Snuke?

-----Constraints-----
 - 1 \leq N \leq 2 \times 10^{5}
 - s is a string of length N consisting of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
N
s

-----Print-----
Print the minimum possible length of s after some number of operations by Snuke.

-----Sample Input-----
6
icefox

-----Sample Output-----
3

 - By removing the fox at the end of icefox, we can turn s into ice.
user: n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by k or decrease all numbers at points in the set by k. You would like to eventually end up with all numbers equal to 0. Is it possible?

A set of 2 points is considered evenly spaced if they are diametrically opposed, and a set of 3 or more points is considered evenly spaced if they form a regular polygon.


-----Input-----

The first line of input contains an integer n (3 ≤ n ≤ 100000), the number of points along the circle.

The following line contains a string s with exactly n digits, indicating the numbers initially present at each of the points, in clockwise order.


-----Output-----

Print "YES" (without quotes) if there is some sequence of operations that results in all numbers being 0, otherwise "NO" (without quotes).

You can print each letter in any case (upper or lower).


-----Examples-----
Input
30
000100000100000110000000001100

Output
YES

Input
6
314159

Output
NO



-----Note-----

If we label the points from 1 to n, then for the first test case we can set k = 1. Then we increase the numbers at points 7 and 22 by 1, then decrease the numbers at points 7, 17, and 27 by 1, then decrease the numbers at points 4, 10, 16, 22, and 28 by 1.
user: Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7.

gcd here means the greatest common divisor.


-----Input-----

The only line contains two positive integers x and y (1 ≤ x, y ≤ 10^9).


-----Output-----

Print the number of such sequences modulo 10^9 + 7.


-----Examples-----
Input
3 9

Output
3

Input
5 8

Output
0



-----Note-----

There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).

There are no suitable sequences in the second test.
user: You are organizing a boxing tournament, where $n$ boxers will participate ($n$ is a power of $2$), and your friend is one of them. All boxers have different strength from $1$ to $n$, and boxer $i$ wins in the match against boxer $j$ if and only if $i$ is stronger than $j$.

The tournament will be organized as follows: $n$ boxers will be divided into pairs; the loser in each pair leaves the tournament, and $\frac{n}{2}$ winners advance to the next stage, where they are divided into pairs again, and the winners in all pairs advance to the next stage, and so on, until only one boxer remains (who is declared the winner).

Your friend really wants to win the tournament, but he may be not the strongest boxer. To help your friend win the tournament, you may bribe his opponents: if your friend is fighting with a boxer you have bribed, your friend wins even if his strength is lower.

Furthermore, during each stage you distribute the boxers into pairs as you wish.

The boxer with strength $i$ can be bribed if you pay him $a_i$ dollars. What is the minimum number of dollars you have to spend to make your friend win the tournament, provided that you arrange the boxers into pairs during each stage as you wish?


-----Input-----

The first line contains one integer $n$ ($2 \le n \le 2^{18}$) — the number of boxers. $n$ is a power of $2$.

The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$, where $a_i$ is the number of dollars you have to pay if you want to bribe the boxer with strength $i$. Exactly one of $a_i$ is equal to $-1$ — it means that the boxer with strength $i$ is your friend. All other values are in the range $[1, 10^9]$.


-----Output-----

Print one integer — the minimum number of dollars you have to pay so your friend wins.


-----Examples-----
Input
4
3 9 1 -1

Output
0
Input
8
11 -1 13 19 24 7 17 5

Output
12


-----Note-----

In the first test case no matter how you will distribute boxers into pairs, your friend is the strongest boxer and anyway wins the tournament.

In the second test case you can distribute boxers as follows (your friend is number $2$):

$1 : 2, 8 : 5, 7 : 3, 6 : 4$ (boxers $2, 8, 7$ and $6$ advance to the next stage);

$2 : 6, 8 : 7$ (boxers $2$ and $8$ advance to the next stage, you have to bribe the boxer with strength $6$);

$2 : 8$ (you have to bribe the boxer with strength $8$);
user: Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.

Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^4) — the number of cubes given to Vanya.


-----Output-----

Print the maximum possible height of the pyramid in the single line.


-----Examples-----
Input
1

Output
1

Input
25

Output
4



-----Note-----

Illustration to the second sample:  [Image]
user: Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.

One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.

Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.

Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^3) — the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id_1, id_2, ..., id_{n} (0 ≤ id_{i} ≤ 10^9). Number id_{i} equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise.

Consider the secretaries indexed from 1 to n in some way.


-----Output-----

Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.


-----Examples-----
Input
6
0 1 7 1 7 10

Output
2

Input
3
1 1 1

Output
-1

Input
1
0

Output
0



-----Note-----

In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.

In the second test sample the described situation is impossible as conferences aren't allowed.
user: A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.

You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 10^6).


-----Output-----

In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.

In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.


-----Examples-----
Input
9

Output
9
1 1 1 1 1 1 1 1 1 

Input
32

Output
3
10 11 11
user: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform:  U — move from the cell (x, y) to (x, y + 1);  D — move from (x, y) to (x, y - 1);  L — move from (x, y) to (x - 1, y);  R — move from (x, y) to (x + 1, y). 

Ivan entered a sequence of n commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0, 0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!


-----Input-----

The first line contains one number n — the length of sequence of commands entered by Ivan (1 ≤ n ≤ 100).

The second line contains the sequence itself — a string consisting of n characters. Each character can be U, D, L or R.


-----Output-----

Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.


-----Examples-----
Input
4
LDUR

Output
4

Input
5
RRRUU

Output
0

Input
6
LLRRRR

Output
4