Takahashi is initially at his house and is about to visit Aoki's house.
There are N bus stops numbered 1 to N between the two houses, and Takahashi can move between them in the following ways:

- He can walk from his house to bus stop 1 in X units of time.
- For each i = 1, 2, \ldots, N-1, a bus departs from bus stop i at each time that is a multiple of P_i, and by taking this bus, he can get to bus stop (i+1) in T_i units of time. Here, the constraints guarantee that 1 \leq P_i \leq 8.
- Takahashi can walk from bus stop N to Aoki's house in Y units of time.

For each i = 1, 2, \ldots, Q, process the following query.

Find the earliest time that Takahashi can arrive at Aoki's house when he leaves his house at time q_i.

Note that if he arrives at a bus stop exactly at the departure time of a bus, he can take that bus.

Input

The input is given from Standard Input in the following format:
N X Y
P_1 T_1
P_2 T_2
\vdots
P_{N-1} T_{N-1}
Q
q_1
q_2
\vdots
q_Q

Output

Print Q lines.
For each i = 1, 2, \ldots, Q, the i-th line should contain the answer to the i-th query.

Constraints

- 2 \leq N \leq 10^5
- 1 \leq X, Y \leq 10^9
- 1 \leq P_i \leq 8
- 1 \leq T_i \leq 10^9
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq q_i \leq 10^9
- All input values are integers.

Sample Input 1

4 2 3
5 4
6 6
3 1
7
13
0
710511029
136397527
763027379
644706927
447672230

Sample Output 1

34
22
710511052
136397548
763027402
644706946
447672250

For the first query, Takahashi can move as follows to arrive at Aoki's house at time 34.

- Leave his house at time 13.
- Walk from his house and arrive at bus stop 1 at time 15.
- Take the bus departing from bus stop 1 at time 15 and arrive at bus stop 2 at time 19.
- Take the bus departing from bus stop 2 at time 24 and arrive at bus stop 3 at time 30.
- Take the bus departing from bus stop 3 at time 30 and arrive at bus stop 4 at time 31.
- Walk from bus stop 4 and arrive at Aoki's house at time 34.

For the second query, Takahashi can move as follows and arrive at Aoki's house at time 22.

- Leave his house at time 0.
- Walk from his house and arrive at bus stop 1 at time 2.
- Take the bus departing from bus stop 1 at time 5 and arrive at bus stop 2 at time 9.
- Take the bus departing from bus stop 2 at time 12 and arrive at bus stop 3 at time 18.
- Take the bus departing from bus stop 3 at time 18 and arrive at bus stop 4 at time 19.
- Walk from bus stop 4 and arrive at Aoki's house at time 22.


You are given positive integers A and B.
Print the value A^B+B^A.

Input

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

Output

Print the answer as an integer.

Constraints

- 2 \leq A \leq B \leq 9
- All input values are integers.

Sample Input 1

2 8

Sample Output 1

320

For A = 2, B = 8, we have A^B = 256, B^A = 64, so A^B + B^A = 320.

Sample Input 2

9 9

Sample Output 2

774840978

Sample Input 3

5 6

Sample Output 3

23401


You are given a string S.
Find the maximum length of a contiguous substring of S that is a palindrome.
Note that there is always a contiguous substring of S that is a palindrome.

Input

The input is given from Standard Input in the following format:
S

Output

Print the answer.

Constraints

- S is a string of length between 2 and 100, inclusive, consisting of uppercase English letters.

Sample Input 1

TOYOTA

Sample Output 1

5

TOYOT, a contiguous substring of TOYOTA, is a palindrome of length 5.
TOYOTA, the only length-6 contiguous substring of TOYOTA, is not a palindrome, so print 5.

Sample Input 2

ABCDEFG

Sample Output 2

1

Every contiguous substring of length 1 is a palindrome.

Sample Input 3

AAAAAAAAAA

Sample Output 3

10


This problem is an easier version of Problem G.

There is a slot machine with three reels.
The arrangement of symbols on the i-th reel is represented by the string S_i. Here, S_i is a string of length M consisting of digits.
Each reel has a corresponding button. For each non-negative integer t, Takahashi can either choose and press one button or do nothing exactly t seconds after the reels start spinning.
If he presses the button corresponding to the i-th reel exactly t seconds after the reels start spinning, the i-th reel will stop and display the ((t \bmod M)+1)-th character of S_i.
Here, t \bmod M denotes the remainder when t is divided by M.
Takahashi wants to stop all the reels so that all the displayed characters are the same.
Find the minimum possible number of seconds from the start of the spin until all the reels are stopped so that his goal is achieved.
If this is impossible, report that fact.

Input

The input is given from Standard Input in the following format:
M
S_1
S_2
S_3

Output

If it is impossible to stop all the reels so that all the displayed characters are the same, print -1.
Otherwise, print the minimum possible number of seconds from the start of the spin until such a state is achieved.

Constraints

- 1 \leq M \leq 100
- M is an integer.
- S_i is a string of length M consisting of digits.

Sample Input 1

10
1937458062
8124690357
2385760149

Sample Output 1

6

Takahashi can stop each reel as follows so that 6 seconds after the reels start spinning, all the reels display 8.

- Press the button corresponding to the second reel 0 seconds after the reels start spinning. The second reel stops and displays 8, the ((0 \bmod 10)+1=1)-st character of S_2.
- Press the button corresponding to the third reel 2 seconds after the reels start spinning. The third reel stops and displays 8, the ((2 \bmod 10)+1=3)-rd character of S_3.
- Press the button corresponding to the first reel 6 seconds after the reels start spinning. The first reel stops and displays 8, the ((6 \bmod 10)+1=7)-th character of S_1.

There is no way to make the reels display the same character in 5 or fewer seconds, so print 6.

Sample Input 2

20
01234567890123456789
01234567890123456789
01234567890123456789

Sample Output 2

20

Note that he must stop all the reels and make them display the same character.

Sample Input 3

5
11111
22222
33333

Sample Output 3

-1

It is impossible to stop the reels so that all the displayed characters are the same.
In this case, print -1.


There are N people numbered 1 to N on a coordinate plane.
Person 1 is at the origin.
You are given M pieces of information in the following form:

- From person A_i's perspective, person B_i is X_i units away in the positive x-direction and Y_i units away in the positive y-direction.

Determine the coordinates of each person. If the coordinates of a person cannot be uniquely determined, report that fact.

Input

The input is given from Standard Input in the following format:
N M
A_1 B_1 X_1 Y_1
\vdots
A_M B_M X_M Y_M

Output

Print N lines.
If the coordinates of person i cannot be uniquely determined, the i-th line should contain undecidable.
If they can be uniquely determined as (s_i,t_i), the i-th line should contain s_i and t_i in this order, separated by a space.

Constraints

- 1 \leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1\leq A_i,  B_i \leq N
- A_i \neq B_i
- -10^9 \leq X_i,Y_i \leq 10^9
- All input values are integers.
- The given information is consistent.

Sample Input 1

3 2
1 2 2 1
1 3 -1 -2

Sample Output 1

0 0
2 1
-1 -2

The figure below shows the positional relationship of the three people.

Sample Input 2

3 2
2 1 -2 -1
2 3 -3 -3

Sample Output 2

0 0
2 1
-1 -2

The figure below shows the positional relationship of the three people.

Sample Input 3

5 7
1 2 0 0
1 2 0 0
2 3 0 0
3 1 0 0
2 1 0 0
3 2 0 0
4 5 0 0

Sample Output 3

0 0
0 0
0 0
undecidable
undecidable

The same piece of information may be given multiple times, and multiple people may be at the same coordinates.


There are N people gathered for an event called Flowing Noodles. The people are lined up in a row, numbered 1 to N in order from front to back.
During the event, the following occurrence happens M times:

- At time T_i, a quantity W_i of noodles is flown down. The person at the front of the row gets all of it (if no one is in the row, no one gets it). That person then steps out of the row and returns to their original position in the row at time T_i+S_i.

A person who returns to the row at time X is considered to be in the row at time X.
After all the M occurrences, report the total amount of noodles each person has got.

Input

The input is given from Standard Input in the following format:
N M
T_1 W_1 S_1
\vdots
T_M W_M S_M

Output

Print N lines.
The i-th line should contain the amount of noodles person i has got.

Constraints

- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 0 <T_1 <\ldots < T_M \leq 10^9
- 1 \leq S_i \leq 10^9
- 1 \leq W_i \leq 10^9
- All input values are integers.

Sample Input 1

3 5
1 1 3
2 10 100
4 100 10000
10 1000 1000000000
100 1000000000 1

Sample Output 1

101
10
1000

The event proceeds as follows:

- At time 1, a quantity 1 of noodles is flown down. People 1, 2, and 3 are in the row, and the person at the front, person 1, gets the noodles and steps out of the row.
- At time 2, a quantity 10 of noodles is flown down. People 2 and 3 are in the row, and the person at the front, person 2, gets the noodles and steps out of the row.
- At time 4, person 1 returns to the row.
- At time 4, a quantity 100 of noodles is flown down. People 1 and 3 are in the row, and the person at the front, person 1, gets the noodles and steps out of the row.
- At time 10, a quantity 1000 of noodles is flown down. Only person 3 is in the row, and the person at the front, person 3, gets the noodles and steps out of the row.
- At time 100, a quantity 1000000000 of noodles is flown down. No one is in the row, so no one gets these noodles.
- At time 102, person 2 returns to the row.
- At time 10004, person 1 returns to the row.
- At time 1000000010, person 3 returns to the row.

The total amounts of noodles people 1, 2, and 3 have got are 101, 10, and 1000, respectively.

Sample Input 2

3 1
1 1 1

Sample Output 2

1
0
0

Sample Input 3

1 8
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8

Sample Output 3

15


A positive integer x is called a 321-like Number when it satisfies the following condition.

- The digits of x are strictly decreasing from top to bottom.
- In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le i < d:
- (the i-th digit from the top of x) > (the (i+1)-th digit from the top of x).

Note that all one-digit positive integers are 321-like Numbers.
For example, 321, 96410, and 1 are 321-like Numbers, but 123, 2109, and 86411 are not.
You are given N as input. Print Yes if N is a 321-like Number, and No otherwise.

Input

The input is given from Standard Input in the following format:
N

Output

Print Yes if N is a 321-like Number, and No otherwise.

Constraints

- All input values are integers.
- 1 \le N \le 99999

Sample Input 1

321

Sample Output 1

Yes

For N=321, the following holds:

- The first digit from the top, 3, is greater than the second digit from the top, 2.
- The second digit from the top, 2, is greater than the third digit from the top, 1.

Thus, 321 is a 321-like Number.

Sample Input 2

123

Sample Output 2

No

For N=123, the following holds:

- The first digit from the top, 1, is not greater than the second digit from the top, 2.

Thus, 123 is not a 321-like Number.

Sample Input 3

1

Sample Output 3

Yes

Sample Input 4

86411

Sample Output 4

No


There is an exam structured as follows.

- The exam consists of N rounds called round 1 to N.
- In each round, you are given an integer score between 0 and 100, inclusive.
- Your final grade is the sum of the N-2 of the scores earned in the rounds excluding the highest and lowest.
- Formally, let S=(S_1,S_2,\dots,S_N) be the sequence of the scores earned in the rounds sorted in ascending order, then the final grade is S_2+S_3+\dots+S_{N-1}.

Now, N-1 rounds of the exam have ended, and your score in round i was A_i.
Print the minimum score you must earn in round N for a final grade of X or higher.
If your final grade will never be X or higher no matter what score you earn in round N, print -1 instead.
Note that your score in round N can only be an integer between 0 and 100.

Input

The input is given from Standard Input in the following format:
N X
A_1 A_2 \dots A_{N-1}

Output

Print the answer.

Constraints

- All input values are integers.
- 3 \le N \le 100
- 0 \le X \le 100 \times (N-2)
- 0 \le A_i \le 100

Sample Input 1

5 180
40 60 80 50

Sample Output 1

70

Your scores in the first four rounds were 40, 60, 80, and 50.
If you earn a score of 70 in round 5, the sequence of the scores sorted in ascending order will be S=(40,50,60,70,80), for a final grade of 50+60+70=180.
It can be shown that 70 is the minimum score you must earn for a final grade of 180 or higher.

Sample Input 2

3 100
100 100

Sample Output 2

0

Your scores in the first two rounds were 100 and 100.
If you earn a score of 0 in round 3, the sequence of the scores sorted in ascending order will be S=(0,100,100), for a final grade of 100.
Note that the highest score, 100, is earned multiple times, and only one of them is excluded. (The same goes for the lowest score.)
It can be shown that 0 is the minimum score you must earn for a final grade of 100 or higher.

Sample Input 3

5 200
0 0 99 99

Sample Output 3

-1

Your scores in the first four rounds were 0, 0, 99, and 99.
It can be shown that your final grade will never be 200 or higher no matter what score you earn in round 5.

Sample Input 4

10 480
59 98 88 54 70 24 8 94 46

Sample Output 4

45


A positive integer x is called a 321-like Number when it satisfies the following condition. This definition is the same as the one in Problem A.

- The digits of x are strictly decreasing from top to bottom.
- In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le i < d:
- (the i-th digit from the top of x) > (the (i+1)-th digit from the top of x).

Note that all one-digit positive integers are 321-like Numbers.
For example, 321, 96410, and 1 are 321-like Numbers, but 123, 2109, and 86411 are not.
Find the K-th smallest 321-like Number.

Input

The input is given from Standard Input in the following format:
K

Output

Print the K-th smallest 321-like Number as an integer.

Constraints

- All input values are integers.
- 1 \le K
- At least K 321-like Numbers exist.

Sample Input 1

15

Sample Output 1

32

The 321-like Numbers are (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) from smallest to largest.
The 15-th smallest of them is 32.

Sample Input 2

321

Sample Output 2

9610

Sample Input 3

777

Sample Output 3

983210


AtCoder cafeteria offers N main dishes and M side dishes. The price of the i-th main dish is A_i, and that of the j-th side dish is B_j.
The cafeteria is considering introducing a new set meal menu.
A set meal consists of one main dish and one side dish. Let s be the sum of the prices of the main dish and the side dish, then the price of the set meal is \min(s,P).
Here, P is a constant given in the input.
There are NM ways to choose a main dish and a side dish for a set meal. Find the total price of all these set meals.

Input

The input is given from Standard Input in the following format:
N M P
A_1 A_2 \dots A_N
B_1 B_2 \dots B_M

Output

Print the answer as an integer.
Under the constraints of this problem, it can be proved that the answer fits into a 64-bit signed integer.

Constraints

- 1\leq N,M \leq 2\times 10^5
- 1\leq A_i,B_j \leq 10^8
- 1\leq P \leq 2\times 10^8
- All input values are integers.

Sample Input 1

2 2 7
3 5
6 1

Sample Output 1

24

- If you choose the first main dish and the first side dish, the price of the set meal is \min(3+6,7)=7.
- If you choose the first main dish and the second side dish, the price of the set meal is \min(3+1,7)=4.
- If you choose the second main dish and the first side dish, the price of the set meal is \min(5+6,7)=7.
- If you choose the second main dish and the second side dish, the price of the set meal is \min(5+1,7)=6.

Thus, the answer is 7+4+7+6=24.

Sample Input 2

1 3 2
1
1 1 1

Sample Output 2

6

Sample Input 3

7 12 25514963
2436426 24979445 61648772 23690081 33933447 76190629 62703497
11047202 71407775 28894325 31963982 22804784 50968417 30302156 82631932 61735902 80895728 23078537 7723857

Sample Output 3

2115597124


There is a tree with N vertices numbered 1 to N.
For each i\ (2 \leq i \leq N), there is an edge connecting vertex i and vertex \lfloor \frac{i}{2} \rfloor.
There are no other edges.
In this tree, find the number of vertices whose distance from vertex X is K.
Here, the distance between two vertices u and v is defined as the number of edges in the simple path connecting vertices u and v.
You have T test cases to solve.

Input

The input is given from Standard Input in the following format, where \mathrm{test}_i represents the i-th test case:
T
\mathrm{test}_1
\mathrm{test}_2
\vdots
\mathrm{test}_T

Each test case is given in the following format:
N X K

Output

Print T lines.
The i-th line (1 \leq i \leq T) should contain the answer to the i-th test case as an integer.

Constraints

- 1\leq T \leq 10^5
- 1\leq N \leq 10^{18}
- 1\leq X \leq N
- 0\leq K \leq N-1
- All input values are integers.

Sample Input 1

5
10 2 0
10 2 1
10 2 2
10 2 3
10 2 4

Sample Output 1

1
3
4
2
0

The tree for N=10 is shown in the following figure.

Here,

- There is 1 vertex, 2, whose distance from vertex 2 is 0.
- There are 3 vertices, 1,4,5, whose distance from vertex 2 is 1.
- There are 4 vertices, 3,8,9,10, whose distance from vertex 2 is 2.
- There are 2 vertices, 6,7, whose distance from vertex 2 is 3.
- There are no vertices whose distance from vertex 2 is 4.

Sample Input 2

10
822981260158260522 52 20
760713016476190629 2314654 57
1312150450968417 1132551176249851 7
1000000000000000000 1083770654 79
234122432773361868 170290518806790 23
536187734191890310 61862 14
594688604155374934 53288633578 39
1000000000000000000 120160810 78
89013034180999835 14853481725739 94
463213054346948152 825589 73

Sample Output 2

1556480
140703128616960
8
17732923532771328
65536
24576
2147483640
33776997205278720
7881299347898368
27021597764222976


You are given a string S of length N consisting of A, B, and C.
Find the position where ABC first appears as a (contiguous) substring in S. In other words, find the smallest integer n that satisfies all of the following conditions.

- 1 \leq n \leq N - 2.
- The string obtained by extracting the n-th through (n+2)-th characters of S is ABC.

If ABC does not appear in S, print -1.

Input

The input is given from Standard Input in the following format:
N
S

Output

Print the position where ABC first appears as a substring in S, or -1 if it does not appear in S.

Constraints

- 3 \leq N \leq 100
- S is a string of length N consisting of A, B, and C.

Sample Input 1

8
ABABCABC

Sample Output 1

3

ABC first appears in S at the 3-rd through 5-th characters of S. Therefore, the answer is 3.

Sample Input 2

3
ACB

Sample Output 2

-1

If ABC does not appear in S, print -1.

Sample Input 3

20
BBAAABBACAACABCBABAB

Sample Output 3

13


You are given two strings S and T consisting of lowercase English letters. The lengths of S and T are N and M, respectively. (The constraints guarantee that N \leq M.)
S is said to be a prefix of T when the first N characters of T coincide S.
S is said to be a suffix of T when the last N characters of T coincide S.
If S is both a prefix and a suffix of T, print 0;
If S is a prefix of T but not a suffix, print 1;
If S is a suffix of T but not a prefix, print 2;
If S is neither a prefix nor a suffix of T, print 3.

Input

The input is given from Standard Input in the following format:
N M
S
T

Output

Print the answer according to the instructions in the problem statement.

Constraints

- 1 \leq N \leq M \leq 100
- S is a string of length N consisting of lowercase English letters.
- T is a string of length M consisting of lowercase English letters.

Sample Input 1

3 7
abc
abcdefg

Sample Output 1

1

S is a prefix of T but not a suffix, so you should print 1.

Sample Input 2

3 4
abc
aabc

Sample Output 2

2

S is a suffix of T but not a prefix.

Sample Input 3

3 3
abc
xyz

Sample Output 3

3

S is neither a prefix nor a suffix of T.

Sample Input 4

3 3
aaa
aaa

Sample Output 4

0

S and T may coincide, in which case S is both a prefix and a suffix of T.


The AtCoder Kingdom holds a festival for N days. On M of these days, namely on the A_1-th, A_2-th, \dots, A_M-th days, fireworks will be launched. It is guaranteed that fireworks will be launched on the last day of the festival. (In other words, A_M=N is guaranteed.)
For each i=1,2,\dots,N, solve the following problem.

- How many days later from the i-th day will fireworks be launched for the first time on or after the i-th day? If fireworks are launched on the i-th day, it is considered to be 0 days later.

Input

The input is given from Standard Input in the following format:
N M
A_1 A_2 \dots A_M

Output

Print N lines.
The i-th line (1 \le i \le N) should contain an integer representing the number of days from the i-th day until fireworks are launched for the first time on or after the i-th day.

Constraints

- 1 \le M \le N \le 2 \times 10^5
- 1 \le A_1 < A_2 < \dots < A_M = N
- All input values are integers.

Sample Input 1

3 2
2 3

Sample Output 1

1
0
0

The kingdom holds a festival for 3 days, and fireworks are launched on the 2-nd and 3-rd days.

- From the 1-st day, the first time fireworks are launched is the 2-nd day of the festival, which is 1 day later.
- From the 2-nd day, the first time fireworks are launched is the 2-nd day of the festival, which is 0 days later.
- From the 3-rd day, the first time fireworks are launched is the 3-rd day of the festival, which is 0 days later.

Sample Input 2

8 5
1 3 4 7 8

Sample Output 2

0
1
0
0
2
1
0
0


A polyomino is a puzzle piece in the shape of a connected polygon made by connecting several squares by their edges.
There is a grid with four rows and four columns, and three polyominoes that fit within the grid.
The shape of the i-th polyomino is represented by 16 characters P_{i,j,k} (1 \leq j, k \leq 4). They describe the state of the grid when the i-th polyomino is placed on it. If P_{i, j, k} is #, the square at the j-th row from the top and k-th column from the left is occupied by the polyomino; if it is ., the square is not occupied. (Refer to the figures at Sample Input/Output 1.)
You want to fill the grid with all three polyominoes so that all of the following conditions are satisfied.

- All squares of the grid are covered by the polyominoes.
- The polyominoes must not overlap each other.
- The polyominoes must not stick out of the grid.
- The polyominoes may be freely translated and rotated but may not be flipped over.

Can the grid be filled with the polyominoes to satisfy these conditions?

Input

The input is given from Standard Input in the following format:
P_{1,1,1}P_{1,1,2}P_{1,1,3}P_{1,1,4}
P_{1,2,1}P_{1,2,2}P_{1,2,3}P_{1,2,4}
P_{1,3,1}P_{1,3,2}P_{1,3,3}P_{1,3,4}
P_{1,4,1}P_{1,4,2}P_{1,4,3}P_{1,4,4}
P_{2,1,1}P_{2,1,2}P_{2,1,3}P_{2,1,4}
P_{2,2,1}P_{2,2,2}P_{2,2,3}P_{2,2,4}
P_{2,3,1}P_{2,3,2}P_{2,3,3}P_{2,3,4}
P_{2,4,1}P_{2,4,2}P_{2,4,3}P_{2,4,4}
P_{3,1,1}P_{3,1,2}P_{3,1,3}P_{3,1,4}
P_{3,2,1}P_{3,2,2}P_{3,2,3}P_{3,2,4}
P_{3,3,1}P_{3,3,2}P_{3,3,3}P_{3,3,4}
P_{3,4,1}P_{3,4,2}P_{3,4,3}P_{3,4,4}

Output

If it is possible to fill the grid with the polyominoes to satisfy the conditions in the problem statement, print Yes; otherwise, print No.

Constraints

- P_{i, j, k} is # or ..
- The given polyominoes are connected. In other words, the squares that make up a polyomino can be reached from each other by following only the squares up, down, left, and right.
- The given polyominoes are not empty.

Sample Input 1

....
###.
.#..
....
....
.###
.##.
....
..#.
.##.
.##.
.##.

Sample Output 1

Yes

The figure below shows the shapes of the polyominoes corresponding to Sample Input 1.

In this case, you can fill the grid with them to satisfy the conditions in the problem statement by placing them as shown in the figure below.

Thus, the answer is Yes.

Sample Input 2

###.
#.#.
##..
....
....
..#.
....
....
####
##..
#...
#...

Sample Output 2

Yes

As in the first polyomino in Sample Input 2, a polyomino may be in the shape of a polygon with a hole.

Sample Input 3

##..
#..#
####
....
....
##..
.##.
....
.#..
.#..
.#..
.#..

Sample Output 3

No

Note that the polyominoes may not be flipped over when filling the grid.

Sample Input 4

....
..#.
....
....
....
..#.
....
....
....
..#.
....
....

Sample Output 4

No

Sample Input 5

....
####
#...
#...
....
####
...#
..##
....
..##
..#.
..##

Sample Output 5

No

Sample Input 6

###.
.##.
..#.
.###
....
...#
..##
...#
....
#...
#...
#...

Sample Output 6

Yes


AtCoder Inc. is planning to develop a product. The product has K parameters, whose values are currently all zero. The company aims to raise all parameter values to at least P.
There are N development plans. Executing the i-th development plan (1 \le i \le N) increases the value of the j-th parameter by A_{i,j} for every integer j such that 1 \le j \le K, at the cost of C_i.
A development plan cannot be executed more than once. Determine whether the company can achieve its goal, and if it can, find the minimum total cost required to achieve the goal.

Input

The input is given from Standard Input in the following format:
N K P
C_1 A_{1,1} A_{1,2} \dots A_{1,K}
C_2 A_{2,1} A_{2,2} \dots A_{2,K}
\dots
C_N A_{N,1} A_{N,2} \dots A_{N,K}

Output

If AtCoder Inc. can achieve its goal, print the minimum total cost required to achieve the goal; otherwise, print -1.

Constraints

- 1 \le N \le 100
- 1 \le K,P \le 5
- 0 \le A_{i,j} \le P(1 \le i \le N,1 \le j \le K)
- 1 \le C_i \le 10^9(1 \le i \le N)
- All input values are integers.

Sample Input 1

4 3 5
5 3 0 2
3 1 2 3
3 2 4 0
1 0 1 4

Sample Output 1

9

If you execute the first, third, and fourth development plans, each parameter will be 3+2+0=5,0+4+1=5,2+0+4=6, all of which are at least 5, so the goal is achieved. The total cost in this case is 5 + 3 + 1 = 9.
It is impossible to achieve the goal at a total cost of 8 or less. Thus, the answer is 9.

Sample Input 2

7 3 5
85 1 0 1
37 1 1 0
38 2 0 0
45 0 2 2
67 1 1 0
12 2 2 0
94 2 2 1

Sample Output 2

-1

You cannot achieve the goal no matter what you do. Thus, print -1.


You are given a string S of length 16 consisting of 0 and 1.
If the i-th character of S is 0 for every even number i from 2 through 16, print Yes; otherwise, print No.

Input

The input is given from Standard Input in the following format:
S

Output

If the i-th character of S is 0 for every even number i from 2 through 16, print Yes; otherwise, print No.

Constraints

- S is a string of length 16 consisting of 0 and 1.

Sample Input 1

1001000000001010

Sample Output 1

No

The 4-th character of S= 1001000000001010 is 1, so you should print No.

Sample Input 2

1010100000101000

Sample Output 2

Yes

Every even-positioned character in S= 1010100000101000 is 0, so you should print Yes.

Sample Input 3

1111111111111111

Sample Output 3

No

Every even-positioned character in S is 1.
Particularly, they are not all 0, so you should print No.


There are N players numbered 1 to N, who have played a round-robin tournament. For every match in this tournament, one player won and the other lost.
The results of the matches are given as N strings S_1,S_2,\ldots,S_N of length N each, in the following format:

-
If i\neq j, the j-th character of S_i is o or x. o means that player i won against player j, and x means that player i lost to player j.

-
If i=j, the j-th character of S_i is -.

The player with more wins ranks higher. If two players have the same number of wins, the player with the smaller player number ranks higher. Report the player numbers of the N players in descending order of rank.

Input

The input is given from Standard Input in the following format:
N
S_1
S_2
\vdots
S_N

Output

Print the player numbers of the N players in descending order of rank.

Constraints

- 2\leq N\leq 100
- N is an integer.
- S_i is a string of length N consisting of o, x, and -.
- S_1,\ldots,S_N conform to the format described in the problem statement.

Sample Input 1

3
-xx
o-x
oo-

Sample Output 1

3 2 1

Player 1 has 0 wins, player 2 has 1 win, and player 3 has 2 wins. Thus, the player numbers in descending order of rank are 3,2,1.

Sample Input 2

7
-oxoxox
x-xxxox
oo-xoox
xoo-ooo
ooxx-ox
xxxxx-x
oooxoo-

Sample Output 2

4 7 3 1 5 2 6

Both players 4 and 7 have 5 wins, but player 4 ranks higher because their player number is smaller.


The programming contest World Tour Finals is underway, where N players are participating, and half of the competition time has passed.
There are M problems in this contest, and the score A_i of problem i is a multiple of 100 between 500 and 2500, inclusive.
For each i = 1, \ldots, N, you are given a string S_i that indicates which problems player i has already solved.
S_i is a string of length M consisting of o and x, where the j-th character of S_i is o if player i has already solved problem j, and x if they have not yet solved it.
Here, none of the players have solved all the problems yet.
The total score of player i is calculated as the sum of the scores of the problems they have solved, plus a bonus score of i points.
For each i = 1, \ldots, N, answer the following question.

- At least how many of the problems that player i has not yet solved must player i solve to exceed all other players' current total scores?

Note that under the conditions in this statement and the constraints, it can be proved that player i can exceed all other players' current total scores by solving all the problems, so the answer is always defined.

Input

The input is given from Standard Input in the following format:
N M
A_1 A_2 \ldots A_M
S_1
S_2
\vdots
S_N

Output

Print N lines. The i-th line should contain the answer to the question for player i.

Constraints

- 2\leq N\leq 100
- 1\leq M\leq 100
- 500\leq A_i\leq 2500
- A_i is a multiple of 100.
- S_i is a string of length M consisting of o and x.
- S_i contains at least one x.
- All numeric values in the input are integers.

Sample Input 1

3 4
1000 500 700 2000
xxxo
ooxx
oxox

Sample Output 1

0
1
1

The players' total scores at the halfway point of the competition time are 2001 points for player 1, 1502 points for player 2, and 1703 points for player 3.
Player 1 is already ahead of all other players' total scores without solving any more problems.
Player 2 can, for example, solve problem 4 to have a total score of 3502 points, which would exceed all other players' total scores.
Player 3 can also, for example, solve problem 4 to have a total score of 3703 points, which would exceed all other players' total scores.

Sample Input 2

5 5
1000 1500 2000 2000 2500
xxxxx
oxxxx
xxxxx
oxxxx
oxxxx

Sample Output 2

1
1
1
1
0

Sample Input 3

7 8
500 500 500 500 500 500 500 500
xxxxxxxx
oxxxxxxx
ooxxxxxx
oooxxxxx
ooooxxxx
oooooxxx
ooooooxx

Sample Output 3

7
6
5
4
3
2
0


Initially, there are N sizes of slimes.
Specifically, for each 1\leq i\leq N, there are C_i slimes of size S_i.
Takahashi can repeat slime synthesis any number of times (possibly zero) in any order.
Slime synthesis is performed as follows.

- Choose two slimes of the same size. Let this size be X, and a new slime of size 2X appears. Then, the two original slimes disappear.

Takahashi wants to minimize the number of slimes.
What is the minimum number of slimes he can end up with by an optimal sequence of syntheses?

Input

The input is given from Standard Input in the following format:
N
S_1 C_1
S_2 C_2
\vdots
S_N C_N

Output

Print the minimum possible number of slimes after Takahashi has repeated the synthesis.

Constraints

- 1\leq N\leq 10^5
- 1\leq S_i\leq 10^9
- 1\leq C_i\leq 10^9
- S_1,S_2,\ldots,S_N are all different.
- All input values are integers.

Sample Input 1

3
3 3
5 1
6 1

Sample Output 1

3

Initially, there are three slimes of size 3, one of size 5, and one of size 6.
Takahashi can perform the synthesis twice as follows:

- First, perform the synthesis by choosing two slimes of size 3. There will be one slime of size 3, one of size 5, and two of size 6.
- Next, perform the synthesis by choosing two slimes of size 6. There will be one slime of size 3, one of size 5, and one of size 12.

No matter how he repeats the synthesis from the initial state, he cannot reduce the number of slimes to 2 or less, so you should print 3.

Sample Input 2

3
1 1
2 1
3 1

Sample Output 2

3

He cannot perform the synthesis.

Sample Input 3

1
1000000000 1000000000

Sample Output 3

13


Takahashi has a playlist with N songs.
Song i (1 \leq i \leq N) lasts T_i seconds.
Takahashi has started random play of the playlist at time 0.
Random play repeats the following: choose one song from the N songs with equal probability and play that song to the end.
Here, songs are played continuously: once a song ends, the next chosen song starts immediately.
The same song can be chosen consecutively.
Find the probability that song 1 is being played (X + 0.5) seconds after time 0, modulo 998244353.

How to print a probability modulo 998244353
It can be proved that the probability to be found in this problem is always a rational number.
Also, the constraints of this problem guarantee that when the probability to be found is expressed as an irreducible fraction \frac{y}{x}, x is not divisible by 998244353.
Then, there is a unique integer z between 0 and 998244352, inclusive, such that xz \equiv y \pmod{998244353}. Report this z.

Input

The input is given from Standard Input in the following format:
N X
T_1 T_2 \ldots T_N

Output

Print the probability, modulo 998244353, that the first song in the playlist is being played (X+0.5) seconds after time 0.

Constraints

- 2 \leq N\leq 10^3
- 0 \leq X\leq 10^4
- 1 \leq T_i\leq 10^4
- All input values are integers.

Sample Input 1

3 6
3 5 6

Sample Output 1

369720131

Song 1 will be playing 6.5 seconds after time 0 if songs are played in one of the following orders.

- Song 1 \to Song 1 \to Song 1
- Song 2 \to Song 1
- Song 3 \to Song 1

The probability that one of these occurs is \frac{7}{27}.
We have 369720131\times 27\equiv 7 \pmod{998244353}, so you should print 369720131.

Sample Input 2

5 0
1 2 1 2 1

Sample Output 2

598946612

0.5 seconds after time 0, the first song to be played is still playing, so the sought probability is \frac{1}{5}.
Note that different songs may have the same length.

Sample Input 3

5 10000
1 2 3 4 5

Sample Output 3

586965467


You are given N integers A _ 1,A _ 2,\ldots,A _ N.
If their values are all equal, print Yes; otherwise, print No.

Input

The input is given from Standard Input in the following format:
N
A _ 1 A _ 2 \ldots A _ N

Output

Print a single line containing Yes if the values of the given A _ 1,A _ 2,\ldots,A _ N are all equal, and No otherwise.

Constraints

- 2\leq N\leq100
- 1\leq A _ i\leq100\ (1\leq i\leq N)
- All input values are integers.

Sample Input 1

3
3 2 4

Sample Output 1

No

We have A _ 1\neq A _ 2, so you should print No.

Sample Input 2

4
3 3 3 3

Sample Output 2

Yes

We have A _ 1=A _ 2=A _ 3=A _ 4, so you should print Yes.

Sample Input 3

10
73 8 55 26 97 48 37 47 35 55

Sample Output 3

No


You are given a positive integer N.
If there are integers x and y such that N=2^x3^y, print Yes; otherwise, print No.

Input

The input is given from Standard Input in the following format:
N

Output

Print a single line containing Yes if there are integers x and y that satisfy the condition, and No otherwise.

Constraints

- 1\leq N\leq10^{18}
- N is an integer.

Sample Input 1

324

Sample Output 1

Yes

For x=2,y=4, we have 2^x3^y=2^23^4=4\times81=324, so the condition is satisfied.
Thus, you should print Yes.

Sample Input 2

5

Sample Output 2

No

There are no integers x and y such that 2^x3^y=5.
Thus, you should print No.

Sample Input 3

32

Sample Output 3

Yes

For x=5,y=0, we have 2^x3^y=32\times1=32, so you should print Yes.

Sample Input 4

37748736

Sample Output 4

Yes


Takahashi sent a string T consisting of lowercase English letters to Aoki. As a result, Aoki received a string T' consisting of lowercase English letters.
T' may have been altered from T. Specifically, exactly one of the following four conditions is known to hold.

- T' is equal to T.
- T' is a string obtained by inserting one lowercase English letter at one position (possibly the beginning and end) in T.
- T' is a string obtained by deleting one character from T.
- T' is a string obtained by changing one character in T to another lowercase English letter.

You are given the string T' received by Aoki and N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters. Find all the strings among S_1, S_2, \ldots, S_N that could equal the string T sent by Takahashi.

Input

The input is given from Standard Input in the following format:
N T'
S_1
S_2
\vdots
S_N

Output

Let (i_1, i_2, \ldots, i_K) be the sequence of indices of all the strings among S_1, S_2, \ldots, S_N that could be equal to T, in ascending order.
Print the length K of this sequence, and the sequence itself, in the following format:
K
i_1 i_2 \ldots i_K

Constraints

- N is an integer.
- 1 \leq N \leq 5 \times 10^5
- S_i and T' are strings of length between 1 and 5 \times 10^5, inclusive, consisting of lowercase English letters.
- The total length of S_1, S_2, \ldots, S_N is at most 5 \times 10^5.

Sample Input 1

5 ababc
ababc
babc
abacbc
abdbc
abbac

Sample Output 1

4
1 2 3 4

Among S_1, S_2, \ldots, S_5, the strings that could be equal to T are S_1, S_2, S_3, S_4, as explained below.

- S_1 could be equal to T, because T' =  ababc is equal to S_1 =  ababc.
- S_2 could be equal to T, because T' =  ababc is obtained by inserting the letter a at the beginning of S_2 =  babc.
- S_3 could be equal to T, because T' =  ababc is obtained by deleting the fourth character c from S_3 =  abacbc.
- S_4 could be equal to T, because T' =  ababc is obtained by changing the third character d in S_4 =  abdbc to b.
- S_5 could not be equal to T, because if we take S_5 =  abbac as T, then T' =  ababc does not satisfy any of the four conditions in the problem statement.

Sample Input 2

1 aoki
takahashi

Sample Output 2

0

Sample Input 3

9 atcoder
atoder
atcode
athqcoder
atcoder
tacoder
jttcoder
atoder
atceoder
atcoer

Sample Output 3

6
1 2 4 7 8 9


You are given a string S of length N consisting of digits.
Find the number of square numbers that can be obtained by interpreting a permutation of S as a decimal integer.
More formally, solve the following.
Let s _ i be the number corresponding to the i-th digit (1\leq i\leq N) from the beginning of S.
Find the number of square numbers that can be represented as \displaystyle \sum _ {i=1} ^ N s _ {p _ i}10 ^ {N-i} with a permutation P=(p _ 1,p _ 2,\ldots,p _ N) of (1, \dots, N).

Input

The input is given from Standard Input in the following format:
N
S

Output

Print the answer in a single line.

Constraints

- 1\leq N\leq 13
- S is a string of length N consisting of digits.
- N is an integer.

Sample Input 1

4
4320

Sample Output 1

2

For P=(4,2,3,1), we have s _ 4\times10 ^ 3+s _ 2\times10 ^ 2+s _ 3\times10 ^ 1+s _ 1=324=18 ^ 2.
For P=(3,2,4,1), we have s _ 3\times10 ^ 3+s _ 2\times10 ^ 2+s _ 4\times10 ^ 1+s _ 1=2304=48 ^ 2.
No other permutations result in square numbers, so you should print 2.

Sample Input 2

3
010

Sample Output 2

2

For P=(1,3,2) or P=(3,1,2), we have \displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=1=1 ^ 2.
For P=(2,1,3) or P=(2,3,1), we have \displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=100=10 ^ 2.
No other permutations result in square numbers, so you should print 2.
Note that different permutations are not distinguished if they result in the same number.

Sample Input 3

13
8694027811503

Sample Output 3

840


You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters, and a string T consisting of lowercase English letters.
There are N^2 pairs (i, j) of integers between 1 and N, inclusive. Print the number of pairs among them that satisfy the following condition.

- The concatenation of S_i and S_j in this order contains T as a (not necessarily contiguous) subsequence.

Input

The input is given from Standard Input in the following format:
N T
S_1
S_2
\vdots
S_N

Output

Print the answer.

Constraints

- N is an integer.
- 1 \leq N \leq 5 \times 10^5
- S_i and T are strings of length 1 to 5 \times 10^5, inclusive, consisting of lowercase English letters.
- The total length of S_1, S_2, \ldots, S_N is at most 5 \times 10^5.

Sample Input 1

3 bac
abba
bcb
aaca

Sample Output 1

3

The pairs (i, j) that satisfy the condition in the problem statement are (1, 2), (1, 3), (2, 3), as seen below.

- For (i, j) = (1, 2), the concatenation abbabcb of S_1 and S_2 in this order contains bac as a subsequence.
- For (i, j) = (1, 3), the concatenation abbaaaca of S_1 and S_3 in this order contains bac as a subsequence.
- For (i, j) = (2, 3), the concatenation bcbaaca of S_2 and S_3 in this order contains bac as a subsequence.

Sample Input 2

5 xx
x
x
x
x
x

Sample Output 2

25

Sample Input 3

1 y
x

Sample Output 3

0

Sample Input 4

10 ms
mkgn
m
hlms
vmsle
mxsm
nnzdhi
umsavxlb
ffnsybomr
yvmm
naouel

Sample Output 4

68


There is a directed graph with N vertices and M edges. Each edge has two positive integer values: beauty and cost.
For i = 1, 2, \ldots, M, the i-th edge is directed from vertex u_i to vertex v_i, with beauty b_i and cost c_i.
Here, the constraints guarantee that u_i \lt v_i.
Find the maximum value of the following for a path P from vertex 1 to vertex N.

- The total beauty of all edges on P divided by the total cost of all edges on P.

Here, the constraints guarantee that the given graph has at least one path from vertex 1 to vertex N.

Input

The input is given from Standard Input in the following format:
N M
u_1 v_1 b_1 c_1
u_2 v_2 b_2 c_2
\vdots
u_M v_M b_M c_M

Output

Print the answer. Your output will be judged as correct if the relative or absolute error from the true answer is at most 10^{-9}.

Constraints

- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq u_i \lt v_i \leq N
- 1 \leq b_i, c_i \leq 10^4
- There is a path from vertex 1 to vertex N.
- All input values are integers.

Sample Input 1

5 7
1 2 3 6
1 3 9 5
2 3 1 5
2 4 5 3
2 5 1 9
3 4 4 8
4 5 2 7

Sample Output 1

0.7500000000000000

For the path P that passes through the 2-nd, 6-th, and 7-th edges in this order and visits vertices 1 \rightarrow 3 \rightarrow 4 \rightarrow 5, the total beauty of all edges on P divided by the total cost of all edges on P
is
(b_2 + b_6 + b_7) / (c_2 + c_6 + c_7) = (9 + 4 + 2) / (5 + 8 + 7) = 15 / 20 = 0.75, and this is the maximum possible value.

Sample Input 2

3 3
1 3 1 1
1 3 2 1
1 3 3 1

Sample Output 2

3.0000000000000000

Sample Input 3

10 20
3 4 1 2
7 9 4 5
2 4 4 5
4 5 1 4
6 9 4 1
9 10 3 2
6 10 5 5
5 6 1 2
5 6 5 2
2 3 2 3
6 10 4 4
4 6 3 4
4 8 4 1
3 5 3 2
2 4 3 2
3 5 4 2
1 5 3 4
1 2 4 2
3 7 2 2
7 8 1 3

Sample Output 3

1.8333333333333333


Keyence has a culture of addressing everyone with the honorific "san," regardless of their role, age, or position.
Even a new employee would call the president "Nakata-san." [Translator's note: this is a bit unusual in Japan.]

You are given a person's surname and first name as strings S and T, respectively.
Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.

Input

The input is given from Standard Input in the following format:
S T

Output

Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.

Constraints

- Each of S and T is a string that satisfies the following conditions.
- The length is between 1 and 10, inclusive.
- The first character is an uppercase English letter.
- All characters except the first one are lowercase English letters.

Sample Input 1

Takahashi Chokudai

Sample Output 1

Takahashi san

Print the concatenation of the surname (Takahashi), a space ( ), and the honorific (san) in this order.

Sample Input 2

K Eyence

Sample Output 2

K san


Keyence has N bases worldwide, numbered 1 to N.
Base i has W_i employees, and at 0 o'clock in Coordinated Universal Time (UTC), it is X_i o'clock at base i.
You want to hold a one-hour meeting across the entire company.
Each employee can only participate in the meeting if the meeting time is completely within the 9:00-18:00 time slot at their base. Find the maximum number of employees who can participate when deciding the meeting time to allow as many employees as possible to participate.

Input

The input is given from Standard Input in the following format:
N
W_1 X_1
W_2 X_2
\vdots
W_N X_N

Output

Print the maximum number of employees who can participate in the meeting.

Constraints

- 1\leq N \leq 1000
- 1\leq W_i \leq 10^6
- 0\leq X_i < 24
- All input values are integers.

Sample Input 1

3
5 0
3 3
2 18

Sample Output 1

8

Consider holding the meeting from 14:00 to 15:00 in UTC.

- The meeting is held from 14:00 to 15:00 at base 1, so the 5 employees at base 1 can participate in the meeting.
- The meeting is held from 17:00 to 18:00 at base 2, so the 3 employees at base 2 can participate in the meeting.
- The meeting is held from 8:00 to 9:00 at base 3, so the 2 employees at base 3 cannot participate in the meeting.

Thus, a total of 5+3=8 employees can participate in the meeting.
No meeting time allows more employees to participate.

Sample Input 2

2
1 10
1000000 20

Sample Output 2

1000000

Sample Input 3

6
31 3
20 8
11 5
4 3
47 14
1 18

Sample Output 3

67


There are zero or more sensors placed on a grid of H rows and W columns. Let (i, j) denote the square in the i-th row from the top and the j-th column from the left.
Whether each square contains a sensor is given by the strings S_1, S_2, \ldots, S_H, each of length W. (i, j) contains a sensor if and only if the j-th character of S_i is #.
These sensors interact with other sensors in the squares horizontally, vertically, or diagonally adjacent to them and operate as one sensor.
Here, a cell (x, y) and a cell (x', y') are said to be horizontally, vertically, or diagonally adjacent if and only if \max(|x-x'|,|y-y'|) = 1.
Note that if sensor A interacts with sensor B and sensor A interacts with sensor C, then sensor B and sensor C also interact.
Considering the interacting sensors as one sensor, find the number of sensors on this grid.

Input

The input is given from Standard Input in the following format:
H W
S_1
S_2
\vdots
S_H

Output

Print the answer.

Constraints

- 1 \leq H, W \leq 1000
- H and W are integers.
- S_i is a string of length W where each character is # or ..

Sample Input 1

5 6
.##...
...#..
....##
#.#...
..#...

Sample Output 1

3

When considering the interacting sensors as one sensor, the following three sensors exist:

- The interacting sensors at (1,2),(1,3),(2,4),(3,5),(3,6)
- The sensor at (4,1)
- The interacting sensors at (4,3),(5,3)

Sample Input 2

3 3
#.#
.#.
#.#

Sample Output 2

1

Sample Input 3

4 2
..
..
..
..

Sample Output 3

0

Sample Input 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

Sample Output 4

7


There are N products labeled 1 to N flowing on a conveyor belt.
A Keyence printer is attached to the conveyor belt, and product i enters the range of the printer T_i microseconds from now and leaves it D_i microseconds later.
The Keyence printer can instantly print on one product within the range of the printer (in particular, it is possible to print at the moment the product enters or leaves the range of the printer).
However, after printing once, it requires a charge time of 1 microseconds before it can print again.
What is the maximum number of products the printer can print on when the product and timing for the printer to print are chosen optimally?

Input

The input is given from Standard Input in the following format:
N
T_1 D_1
T_2 D_2
\vdots
T_N D_N

Output

Print the maximum number of products the printer can print on.

Constraints

- 1\leq N \leq 2\times 10^5
- 1\leq T_i,D_i \leq 10^{18}
- All input values are integers.

Sample Input 1

5
1 1
1 1
2 1
1 2
1 4

Sample Output 1

4

Below, we will simply call the moment t microseconds from now time t.
For example, you can print on four products as follows:

- Time 1 : Products 1,2,4,5 enter the range of the printer. Print on product 4.
- Time 2 : Product 3 enters the range of the printer, and products 1,2 leave the range of the printer. Print on product 1.
- Time 3 : Products 3,4 leave the range of the printer. Print on product 3.
- Time 4.5 : Print on product 5.
- Time 5 : Product 5 leaves the range of the printer.

It is impossible to print on all five products, so the answer is 4.

Sample Input 2

2
1 1
1000000000000000000 1000000000000000000

Sample Output 2

2

Sample Input 3

10
4 1
1 2
1 4
3 2
5 1
5 1
4 1
2 1
4 1
2 4

Sample Output 3

6


There are N cities in a certain country.
You will travel from your office in city 1 to a destination in city N, via zero or more cities.
Two types of transportation are available: company car and train. The time required to travel from city i to city j is as follows:

- D_{i,j} \times A minutes by company car, and
- D_{i,j} \times B + C minutes by train.

You can switch from company car to train, but not vice versa.
You can do so without spending time, but only in a city.
What is the minimum time in minutes to travel from city 1 to city N?

Input

The input is given from Standard Input in the following format:
N A B C
D_{1,1} D_{1,2} \ldots D_{1,N}
D_{2,1} D_{2,2} \ldots D_{2,N}
\vdots
D_{N,1} D_{N,2} \ldots D_{N,N}

Output

Print the answer as an integer.

Constraints

- 2 \leq N \leq 1000
- 1 \leq A, B, C \leq 10^6
- D_{i,j} \leq 10^6
- D_{i,i} = 0
- D_{i,j} = D_{j,i} > 0 (i \neq j)
- All input values are integers.

Sample Input 1

4 8 5 13
0 6 2 15
6 0 3 5
2 3 0 13
15 5 13 0

Sample Output 1

78

You can travel from city 1 to city 4 in a total of 78 minutes by moving as follows.

- Travel by company car from city 1 to city 3. This takes 2 \times 8 = 16 minutes.
- Travel by company car from city 3 to city 2. This takes 3 \times 8 = 24 minutes.
- Travel by train from city 2 to city 4. This takes 5 \times 5 + 13 = 38 minutes.

It is impossible to travel from city 1 to city 4 in less than 78 minutes.

Sample Input 2

3 1 1000000 1000000
0 10 1
10 0 10
1 10 0

Sample Output 2

1

Sample Input 3

5 954257 954213 814214
0 84251 214529 10017 373342
84251 0 91926 32336 164457
214529 91926 0 108914 57762
10017 32336 108914 0 234705
373342 164457 57762 234705 0

Sample Output 3

168604826785


As the factory manager of Keyence, you want to monitor several sections on a conveyor belt. There are a total of N sections you want to monitor, and the length of the i-th section is D_i meters.
There are two types of sensors to choose from, and below is some information about each sensor.

- Type-j sensor (1\leq j \leq 2): Can monitor a section of length L_j meters.
The price is C_j per sensor, and you can use at most K_j sensors of this type in total.

You can divide one section into several sections for monitoring.
It is fine if the sections monitored by the sensors overlap, or if they monitor more than the length of the section you want to monitor.
For example, when L_1=4 and L_2=2, you can use one type-1 sensor to monitor a section of length 3 meters, or use one type-1 and one type-2 sensor to monitor a section of length 5 meters.
Determine whether it is possible to monitor all N sections, and if it is possible, find the minimum total cost of the necessary sensors.

Input

The input is given from Standard Input in the following format:
N
D_1 D_2 \dots D_N
L_1 C_1 K_1
L_2 C_2 K_2

Output

If it is impossible to monitor all N sections, print -1. Otherwise, print the minimum total cost of the necessary sensors.

Constraints

- 1\leq N \leq 100
- 1\leq D_i,L_j \leq 10^5
- 1\leq C_j \leq 10^9
- 1\leq K_j \leq 10^3
- All input values are integers.

Sample Input 1

3
3 5 10
4 3 3
2 2 6

Sample Output 1

17

You can monitor all sections by using three type-1 sensors and four type-2 sensors as follows.

- Use one type-1 sensor to monitor the first section.
- Use one type-1 and one type-2 sensor to monitor the second section.
- Use one type-1 and three type-2 sensors to monitor the third section.

In this case, the total cost of the necessary sensors is 3\times 3 + 2\times 4 = 17, which is the minimum.

Sample Input 2

3
3 5 10
4 3 3
2 2 3

Sample Output 2

-1

Sample Input 3

2
4 8
3 1 100
4 10000 100

Sample Output 3

5

It is fine if one type of sensor is not used at all.


Takahashi is in a building with 100 floors.
He uses the stairs for moving up two floors or less or moving down three floors or less, and uses the elevator otherwise.
Does he use the stairs to move from floor X to floor Y?

Input

The input is given from Standard Input in the following format:
X Y

Output

If Takahashi uses the stairs for the move, print Yes; if he uses the elevator, print No.

Constraints

- 1 \leq X,Y \leq 100
- X \neq Y
- All input values are integers.

Sample Input 1

1 4

Sample Output 1

No

The move from floor 1 to floor 4 involves going up three floors, so Takahashi uses the elevator.

Sample Input 2

99 96

Sample Output 2

Yes

The move from floor 99 to floor 96 involves going down three floors, so Takahashi uses the stairs.

Sample Input 3

100 1

Sample Output 3

No


A 326-like number is a three-digit positive integer where the product of the hundreds and tens digits equals the ones digit.
For example, 326,400,144 are 326-like numbers, while 623,777,429 are not.
Given an integer N, find the smallest 326-like number greater than or equal to N. It always exists under the constraints.

Input

The input is given from Standard Input in the following format:
N

Output

Print the answer.

Constraints

- 100 \leq N \leq 919
- N is an integer.

Sample Input 1

320

Sample Output 1

326

320,321,322,323,324,325 are not 326-like numbers, while 326 is a 326-like number.

Sample Input 2

144

Sample Output 2

144

144 is a 326-like number.

Sample Input 3

516

Sample Output 3

600


Takahashi has placed N gifts on a number line. The i-th gift is placed at coordinate A_i.
You will choose a half-open interval [x,x+M) of length M on the number line and acquire all the gifts included in it.
More specifically, you acquire gifts according to the following procedure.

- First, choose one real number x.
- Then, acquire all the gifts whose coordinates satisfy x \le A_i < x+M.

What is the maximum number of gifts you can acquire?

Input

The input is given from Standard Input in the following format:
N M
A_1 A_2 \dots A_N

Output

Print the answer as an integer.

Constraints

- All input values are integers.
- 1 \le N \le 3 \times 10^5
- 1 \le M \le 10^9
- 0 \le A_i \le 10^9

Sample Input 1

8 6
2 3 5 7 11 13 17 19

Sample Output 1

4

For example, specify the half-open interval [1.5,7.5).
In this case, you can acquire the four gifts at coordinates 2,3,5,7, the maximum number of gifts that can be acquired.

Sample Input 2

10 1
3 1 4 1 5 9 2 6 5 3

Sample Output 2

2

There may be multiple gifts at the same coordinate.

Sample Input 3

10 998244353
100000007 0 1755647 998244353 495 1000000000 1755648 503 1755649 998244853

Sample Output 3

7


You are given an integer N and strings R and C of length N consisting of A, B, and C. Solve the following problem.
There is a N \times N grid. All cells are initially empty.
You can write at most one character from A, B, and C in each cell. (You can also leave the cell empty.)
Determine if it is possible to satisfy all of the following conditions, and if it is possible, print one way to do so.

- Each row and each column contain exactly one A, one B, and one C.
- The leftmost character written in the i-th row matches the i-th character of R.
- The topmost character written in the i-th column matches the i-th character of C.

Input

The input is given from Standard Input in the following format:
N
R
C

Output

If there is no way to fill the grid to satisfy the conditions in the problem statement, print No in one line.
Otherwise, print one such way to fill the grid in the following format:
Yes
A_1
A_2
\vdots
A_N

The first line should contain Yes.
The i-th of the subsequent N lines should contain a string A_i of length N.

- If the j-th character of A_i is ., it indicates that the cell in the i-th row from the top and the j-th column from the left is empty.
- If the j-th character of A_i is A, it indicates that A is written in the cell in the i-th row from the top and the j-th column from the left.
- If the j-th character of A_i is B, it indicates that B is written in the cell in the i-th row from the top and the j-th column from the left.
- If the j-th character of A_i is C, it indicates that C is written in the cell in the i-th row from the top and the j-th column from the left.

If there are multiple correct ways to fill the grid, you may print any of them.

Constraints

- N is an integer between 3 and 5, inclusive.
- R and C are strings of length N consisting of A, B, and C.

Sample Input 1

5
ABCBC
ACAAB

Sample Output 1

Yes
AC..B
.BA.C
C.BA.
BA.C.
..CBA

The grid in the output example satisfies all the following conditions, so it will be treated as correct.

- Each row contains exactly one A, one B, and one C.
- Each column contains exactly one A, one B, and one C.
- The leftmost characters written in the rows are A, B, C, B, C from top to bottom.
- The topmost characters written in the columns are A, C, A, A, B from left to right.

Sample Input 2

3
AAA
BBB

Sample Output 2

No

For this input, there is no way to fill the grid to satisfy the conditions.


Aoki, an employee at AtCoder Inc., has his salary for this month determined by an integer N and a sequence A of length N as follows.
First, he is given an N-sided die (dice) that shows the integers from 1 to N with equal probability, and a variable x=0.
Then, the following steps are repeated until terminated.

- Roll the die once and let y be the result.
- If x<y, pay him A_y yen and let x=y.
- Otherwise, terminate the process.

Aoki's salary for this month is the total amount paid through this process.
Find the expected value of Aoki's salary this month, modulo 998244353.
How to find an expected value modulo 998244353

It can be proved that the sought expected value in this problem is always a rational number. Also, the constraints of this problem guarantee that if the sought expected value is expressed as a reduced fraction \frac yx, then x is not divisible by 998244353.

Here, there is exactly one 0\leq z\lt998244353 such that y\equiv xz\pmod{998244353}. Print this z.

Input

The input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_N

Output

Print the answer.

Constraints

- All inputs are integers.
- 1 \le N \le 3 \times 10^5
- 0 \le A_i < 998244353

Sample Input 1

3
3 2 6

Sample Output 1

776412280

Here is an example of how the process goes.

- Initially, x=0.
- Roll the die once, and it shows 1. Since 0<1, pay him A_1 = 3 yen and let x=1.
- Roll the die once, and it shows 3. Since 1<3, pay him A_3 = 6 yen and let x=3.
- Roll the die once, and it shows 1. Since 3 \ge 1, terminate the process.

In this case, his salary for this month is 9 yen.
It can be calculated that the expected value of his salary this month is \frac{49}{9} yen, whose representation modulo 998244353 is 776412280.

Sample Input 2

1
998244352

Sample Output 2

998244352

Sample Input 3

9
3 14 159 2653 58979 323846 2643383 27950288 419716939

Sample Output 3

545252774


You are given a string S of length N consisting of lowercase English letters.
If there are any adjacent occurrences of a and b in S, print Yes; otherwise, print No. (The order of a and b does not matter.)

Input

The input is given from Standard Input in the following format:
N
S

Output

If there are any adjacent occurrences of a and b in S, print Yes; otherwise, print No.

Constraints

- 2 \leq N \leq 100
- S is a string of length N consisting of lowercase English letters.

Sample Input 1

3
abc

Sample Output 1

Yes

The string abc has a as the first character and b as the second character, which are adjacent. Thus, print Yes.

Sample Input 2

2
ba

Sample Output 2

Yes

The string ba has a as the second character and b as the first character, which are adjacent. (Note that the order of a and b does not matter.)

Sample Input 3

7
atcoder

Sample Output 3

No


You are given an integer B.
If there exists a positive integer A such that A^A = B, print its value; otherwise, output -1.

Input

The input is given from Standard Input in the following format:
B

Output

If there exists a positive integer A such that A^A = B, print its value; otherwise, print -1.
If there are multiple positive integers A such that A^A = B, any of them will be accepted.

Constraints

- 1 \leq B \leq 10^{18}
- B is an integer.

Sample Input 1

27

Sample Output 1

3

3^3 = 27, so print 3.

Sample Input 2

100

Sample Output 2

-1

There is no A such that A^A = B.

Sample Input 3

10000000000

Sample Output 3

10


There is a 9\times 9 grid A, where each cell contains an integer between 1 and 9, inclusive.
Specifically, the cell at the i-th row from the top and j-th column from the left contains A_{i,j}.
If A satisfies all of the following conditions, print Yes. Otherwise, print No.

- For each row of A, the nine cells in that row contain each integer from 1 to 9 exactly once.
- For each column of A, the nine cells in that column contain each integer from 1 to 9 exactly once.
- Divide the rows of A into three groups, each of three rows, from top to bottom, and similarly divide the columns into three groups, each of three columns, from left to right.
Each 3\times 3 grid obtained from A in this way contains each integer from 1 to 9 exactly once.

Input

The input is given from Standard Input in the following format:
A_{1,1} A_{1,2} \ldots A_{1,9}
A_{2,1} A_{2,2} \ldots A_{2,9}
\vdots
A_{9,1} A_{9,2} \ldots A_{9,9}

Output

If the grid A satisfies all the conditions in the problem statement, print Yes; otherwise, print No.

Constraints

- 1\leq A_{i,j}\leq 9
- All input values are integers.

Sample Input 1

1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8

Sample Output 1

Yes

The grid A is shown below.

The grid A satisfies all three conditions, so print Yes.

Sample Input 2

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8

Sample Output 2

No

The grid A is shown below.

For example, if you look at the top left 3\times 3 grid, you can see that the third condition is unsatisfied, so print No.

Sample Input 3

1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6

Sample Output 3

No

The grid A is shown below.

For example, if you look at the leftmost column, you can see that the second condition is unsatisfied, so print No.


A pair of sequences of length M consisting of positive integers at most N, (S, T) = ((S_1, S_2, \dots, S_M), (T_1, T_2, \dots, T_M)), is said to be a good pair of sequences when (S, T) satisfies the following condition.

- There exists a sequence X = (X_1, X_2, \dots, X_N) of length N consisting of 0 and 1 that satisfies the following condition:
- X_{S_i} \neq X_{T_i} for each i=1, 2, \dots, M.

You are given a pair of sequences of length M consisting of positive integers at most N: (A, B) = ((A_1, A_2, \dots, A_M), (B_1, B_2, \dots, B_M)). If (A, B) is a good pair of sequences, print Yes; otherwise, print No.

Input

The input is given from Standard Input in the following format:
N M
A_1 A_2 \dots A_M
B_1 B_2 \dots B_M

Output

If (A, B) is a good pair of sequences, print Yes; otherwise, print No.

Constraints

- 1 \leq N, M \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- All input values are integers.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

Yes

If we set X=(0,1,0), then X is a sequence of length N consisting of 0 and 1 that satisfies X_{A_1} \neq X_{B_1} and X_{A_2} \neq X_{B_2}.
Thus, (A, B) satisfies the condition of being a good pair of sequences.

Sample Input 2

3 3
1 2 3
2 3 1

Sample Output 2

No

No sequence X satisfies the condition, so (A, B) is not a good pair of sequences.

Sample Input 3

10 1
1
1

Sample Output 3

No

Sample Input 4

7 8
1 6 2 7 5 4 2 2
3 2 7 2 1 2 3 3

Sample Output 4

Yes


Takahashi participated in N contests and earned a performance P_i in the i-th contest.
He wants to choose some (at least one) contests from these and maximize his rating calculated from the results of those contests.
Find the maximum possible rating he can achieve by optimally choosing the contests.
Here, Takahashi's rating R is calculated as the following, where k is the number of chosen contests and (Q_1, Q_2, \ldots, Q_k) are the performances in the chosen contests in the order he participated:

\displaystyle R=\frac{\sum_{i=1}^k (0.9)^{k-i}Q_i}{\sum_{i=1}^k (0.9)^{k-i}}-\frac{1200}{\sqrt{k}}.

Input

The input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N

Output

Print the maximum possible rating that Takahashi can achieve.
Your output will be considered correct if the absolute or relative error from the true value is at most 10^{-6}.

Constraints

- 1\leq N\leq 5000
- 1\leq P_i\leq 5000
- All input values are integers.

Sample Input 1

3
1000 600 1200

Sample Output 1

256.735020470879931

If Takahashi chooses the first and third contests, his rating will be:
\displaystyle R=\frac{0.9\times 1000+ 1.0\times 1200}{0.9+1.0}-\frac{1200}{\sqrt{2}}=256.73502....
This is the maximum possible rating.

Sample Input 2

3
600 1000 1200

Sample Output 2

261.423219407873376

The rating is maximized when all the first, second, and third contests are selected.

Sample Input 3

1
100

Sample Output 3

-1100.000000000000000

The rating can also be negative.


There is a programming contest with N problems. For each i = 1, 2, \ldots, N, the score for the i-th problem is S_i.
Print the total score for all problems with a score of X or less.

Input

The input is given from Standard Input in the following format:
N X
S_1 S_2 \ldots S_N

Output

Print the answer.

Constraints

- All input values are integers.
- 4 \leq N \leq 8
- 100 \leq S_i \leq 675
- 100 \leq X \leq 675

Sample Input 1

6 200
100 675 201 200 199 328

Sample Output 1

499

Three problems have a score of 200 or less: the first, fourth, and fifth, for a total score of S_1 + S_4 + S_5 = 100 + 200 + 199 = 499.

Sample Input 2

8 675
675 675 675 675 675 675 675 675

Sample Output 2

5400

Sample Input 3

8 674
675 675 675 675 675 675 675 675

Sample Output 3

0


AtCoder Kingdom uses a calendar whose year has N months.
Month i (1\leq i\leq N) has D _ i days, from day 1 of month i to day D _ i of month i.
How many days in a year of AtCoder have "repdigits" dates?
Here, day j of month i (1\leq i\leq N,1\leq j\leq D _ i) is said to have a repdigit date if and only if all digits in the decimal notations of i and j are the same.

Input

The input is given from Standard Input in the following format:
N
D _ 1 D _ 2 \ldots D _ N

Output

Print the answer.

Constraints

- 1\leq N\leq100
- 1\leq D _ i\leq100\ (1\leq i\leq N)
- All input values are integers.

Sample Input 1

12
31 29 31 30 31 30 31 31 30 31 30 31

Sample Output 1

13

In AtCoder Kingdom, the days that have repdigit dates are January 1, January 11, February 2, February 22, March 3, April 4, May 5, June 6, July 7, August 8, September 9, November 1, and November 11, for a total of 13 days.

Sample Input 2

10
10 1 2 3 4 5 6 7 8 100

Sample Output 2

1

In AtCoder Kingdom, only January 1 has a repdigit date.

Sample Input 3

30
73 8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32

Sample Output 3

15


You are given a string S = S_1S_2\ldots S_N of length N consisting of lowercase English letters.
Additionally, you are given Q queries about the string S.
For i = 1, 2, \ldots, Q, the i-th query is represented by two integers l_i, r_i and asks the following.

In the substring S_{l_i}S_{l_i+1}\ldots S_{r_i} of S, which ranges from the l_i-th to the r_i-th character, how many places are there where the same lowercase English letter occurs twice in a row?
In other words, how many integers p satisfy l_i \leq p \leq r_i-1 and S_p = S_{p+1}?

Print the answer for each of the Q queries.

Input

The input is given from Standard Input in the following format:
N Q
S
l_1 r_1
l_2 r_2
\vdots
l_Q r_Q

Output

Print Q lines.
For i = 1, 2, \ldots, Q, the i-th line should contain the answer to the i-th query.

Constraints

- N and Q are integers.
- 1 \leq N, Q \leq 3 \times 10^5
- S is a string of length N consisting of lowercase English letters.
- l_i and r_i are integers.
- 1 \leq l_i \leq r_i \leq N

Sample Input 1

11 4
mississippi
3 9
4 10
4 6
7 7

Sample Output 1

2
2
0
0

The answers to the four queries are as follows.

- For the first query, S_3S_4\ldots S_9 =  ssissip has two places where the same lowercase English letter occurs twice in a row: S_3S_4 =  ss and S_6S_7 =  ss.
- For the second query, S_4S_5\ldots S_{10} =  sissipp has two places where the same lowercase English letter occurs twice in a row: S_6S_7 =  ss and S_9S_{10} =  pp.
- For the third query, S_4S_5S_6 =  sis has zero places where the same lowercase English letter occurs twice in a row.
- For the fourth query, S_7 =  s has zero places where the same lowercase English letter occurs twice in a row.

Sample Input 2

5 1
aaaaa
1 5

Sample Output 2

4

S_1S_2\ldots S_5 =  aaaaa has four places where the same lowercase English letter occurs twice in a row:
S_1S_2 =  aa, S_2S_3 =  aa, S_3S_4 =  aa, and S_4S_5 =  aa.


You are given a string S consisting of three different characters: A, B, and C.
As long as S contains the string ABC as a consecutive substring, repeat the following operation:

Remove the leftmost occurrence of the substring ABC from S.

Print the final string S after performing the above procedure.

Input

The input is given from Standard Input in the following format:
S

Output

Print the answer.

Constraints

- S is a string of length between 1 and 2 \times 10^5, inclusive, consisting of the characters A, B, and C.

Sample Input 1

BAABCBCCABCAC

Sample Output 1

BCAC

For the given string S =  BAABCBCCABCAC, the operations are performed as follows.

- In the first operation, the ABC from the 3-rd to the 5-th character in S =  BAABCBCCABCAC is removed, resulting in S =  BABCCABCAC.
- In the second operation, the ABC from the 2-nd to the 4-th character in S =  BABCCABCAC is removed, resulting in S =  BCABCAC.
- In the third operation, the ABC from the 3-rd to the 5-th character in S =  BCABCAC is removed, resulting in S =  BCAC.

Therefore, the final S is BCAC.

Sample Input 2

ABCABC

Sample Output 2

In this example, the final S is an empty string.

Sample Input 3

AAABCABCABCAABCABCBBBAABCBCCCAAABCBCBCC

Sample Output 3

AAABBBCCC


You are given a weighted simple connected undirected graph with N vertices and M edges, where vertices are numbered 1 to N, and edges are numbered 1 to M. Additionally, a positive integer K is given.
Edge i\ (1\leq i\leq M) connects vertices u_i and v_i and has a weight of w_i.
For a spanning tree T of this graph, the cost of T is defined as the sum, modulo K, of the weights of the edges in T.
Find the minimum cost of a spanning tree of this graph.

Input

The input is given from Standard Input in the following format:
N M K
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_M v_M w_M

Output

Print the answer.

Constraints

- 2\leq N\leq8
- N-1\leq M\leq\dfrac{N(N-1)}2
- 1\leq K\leq10^{15}
- 1\leq u_i\lt v_i\leq N\ (1\leq i\leq M)
- 0\leq w_i\lt K\ (1\leq i\leq M)
- The given graph is simple and connected.
- All input values are integers.

Sample Input 1

5 6 328
1 2 99
1 3 102
2 3 86
2 4 94
2 5 95
3 4 81

Sample Output 1

33

The given graph is shown below:

The cost of the spanning tree containing edges 1,3,5,6 is (99+86+81+95)\bmod{328}=361\bmod{328}=33.
The cost of every spanning tree of this graph is at least 33, so print 33.

Sample Input 2

6 5 998244353
1 2 337361568
1 6 450343304
2 3 61477244
2 5 745383438
4 5 727360840

Sample Output 2

325437688

Print the cost of the only spanning tree of this graph, which is  325437688.

Sample Input 3

8 28 936294041850197
1 2 473294720906780
1 3 743030800139244
1 4 709363019414774
1 5 383643612490312
1 6 557102781022861
1 7 623179288538138
1 8 739618599410809
2 3 857687812294404
2 4 893923168139714
2 5 581822471860662
2 6 740549363586558
2 7 307226438833222
2 8 447399029952998
3 4 636318083622768
3 5 44548707643622
3 6 307262781240755
3 7 12070267388230
3 8 700247263184082
4 5 560567890325333
4 6 704726113717147
4 7 588263818615687
4 8 549007536393172
5 6 779230871080408
5 7 825982583786498
5 8 713928998174272
6 7 751331074538826
6 8 449873635430228
7 8 11298381761479

Sample Output 3

11360716373

Note that the input and the answer may not fit into a 32\operatorname{bit} integer.


You are given a string S consisting of uppercase English letters. Separate each character of S with a space and print them one by one in order.

Input

The input is given from Standard Input in the following format:
S

Output

Separate each character of S with a space and print them one by one.

Constraints

- S is a string consisting of uppercase English letters with a length between 2 and 100, inclusive.

Sample Input 1

ABC

Sample Output 1

A B C

Separate A, B, and C with spaces and print them one by one.
There is no need to print a space after C.

Sample Input 2

ZZZZZZZ

Sample Output 2

Z Z Z Z Z Z Z

Sample Input 3

OOXXOO

Sample Output 3

O O X X O O


You are given N integers A_1, A_2, \ldots, A_N. Find the largest among those integers that are not the largest.
The constraints of this problem guarantee that the answer exists.

Input

The input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N

Output

Print the answer.

Constraints

- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- It is not the case that all A_1, A_2, \ldots, A_N are equal.
- All input values are integers.

Sample Input 1

5
2 1 3 3 2

Sample Output 1

2

The largest integer among 2,1,3,3,2 is 3.
The integers that are not 3 among 2,1,3,3,2 are 2,1,2, among which the largest is 2.

Sample Input 2

4
4 3 2 1

Sample Output 2

3

Sample Input 3

8
22 22 18 16 22 18 18 22

Sample Output 3

18


You are given a string S of length N consisting of lowercase English letters.
Find the number of non-empty substrings of S that are repetitions of one character. Here, two substrings that are equal as strings are not distinguished even if they are obtained differently.
A non-empty substring of S is a string of length at least one obtained by deleting zero or more characters from the beginning and zero or more characters from the end of S. For example, ab and abc are non-empty substrings of abc, while ac and the empty string are not.

Input

The input is given from Standard Input in the following format:
N
S

Output

Print the number of non-empty substrings of S that are repetitions of one character.

Constraints

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

Sample Input 1

6
aaabaa

Sample Output 1

4

The non-empty substrings of S that are repetitions of one character are a, aa, aaa, and b; there are four of them. Note that there are multiple ways to obtain a or aa from S, but each should only be counted once.

Sample Input 2

1
x

Sample Output 2

1

Sample Input 3

12
ssskkyskkkky

Sample Output 3

8


There is an election to choose one winner from N candidates with candidate numbers 1, 2, \ldots, N, and there have been M votes cast.
Each vote is for exactly one candidate, with the i-th vote being for candidate A_i.
The votes will be counted in order from first to last, and after each vote is counted, the current winner will be updated and displayed.
The candidate with the most votes among those counted is the winner. If there are multiple candidates with the most votes, the one with the smallest candidate number is the winner.
For each i = 1, 2, \ldots, M, determine the winner when counting only the first i votes.

Input

The input is given from Standard Input in the following format:
N M
A_1 A_2 \ldots A_M

Output

Print M lines.
The i-th line should contain the winner's candidate number when counting only the first i votes.

Constraints

- 1 \leq N, M \leq 200000
- 1 \leq A_i \leq N
- All input values are integers.

Sample Input 1

3 7
1 2 2 3 1 3 3

Sample Output 1

1
1
2
2
1
1
3

Let C_i denote the number of votes for candidate i.

- After the first vote is counted, (C_1, C_2, C_3) = (1, 0, 0), so the winner is 1.
- After the second vote is counted, (C_1, C_2, C_3) = (1, 1, 0), so the winner is 1.
- After the third vote is counted, (C_1, C_2, C_3) = (1, 2, 0), so the winner is 2.
- After the fourth vote is counted, (C_1, C_2, C_3) = (1, 2, 1), so the winner is 2.
- After the fifth vote is counted, (C_1, C_2, C_3) = (2, 2, 1), so the winner is 1.
- After the sixth vote is counted, (C_1, C_2, C_3) = (2, 2, 2), so the winner is 1.
- After the seventh vote is counted, (C_1, C_2, C_3) = (2, 2, 3), so the winner is 3.

Sample Input 2

100 5
100 90 80 70 60

Sample Output 2

100
90
80
70
60

Sample Input 3

9 8
8 8 2 2 8 8 2 2

Sample Output 3

8
8
8
2
8
8
8
2


You are given two strings: S, which consists of uppercase English letters and has length N, and T, which also consists of uppercase English letters and has length M\ (\leq N).
There is a string X of length N consisting only of the character #. Determine whether it is possible to make X match S by performing the following operation any number of times:

- Choose M consecutive characters in X and replace them with T.

Input

The input is given from Standard Input in the following format:
N M
S
T

Output

Print Yes if it is possible to make X match S; print No otherwise.

Constraints

- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq \min(N, 5)
- S is a string consisting of uppercase English letters with length N.
- T is a string consisting of uppercase English letters with length M.

Sample Input 1

7 3
ABCBABC
ABC

Sample Output 1

Yes

Below, let X[l:r] denote the part from the l-th through the r-th character of X.
You can make X match S by operating as follows.

- Replace X[3:5] with T. X becomes ##ABC##.
- Replace X[1:3] with T. X becomes ABCBC##.
- Replace X[5:7] with T. X becomes ABCBABC.

Sample Input 2

7 3
ABBCABC
ABC

Sample Output 2

No

No matter how you operate, it is impossible to make X match S.

Sample Input 3

12 2
XYXXYXXYYYXY
XY

Sample Output 3

Yes


There are N boxes numbered 1, 2, \ldots, N. Initially, box i contains one ball of color C_i.
You are given Q queries, which you should process in order.
Each query is given by a pair of integers (a,b) and asks you to do the following:

- Move all the balls from box a to box b, and then print the number of different colors of balls in box b.

Here, the boxes a and b may be empty.

Input

The input is given from Standard Input in the following format, where \text{query}_i represents the i-th query:
N Q
C_1 C_2 \ldots C_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

Each query is given in the following format:
a b

Output

Print Q lines.
The i-th line should contain the response to the i-th query.

Constraints

- 1 \leq N, Q \leq 200000
- 1 \leq C_i \leq N
- 1 \leq a, b \leq N
- a \neq b
- All input values are integers.

Sample Input 1

6 5
1 1 1 2 2 3
1 2
6 4
5 1
3 6
4 6

Sample Output 1

1
2
1
1
3

-
For the first query, move all the balls from box 1 to box 2. Box 2 now contains two balls of color 1, so print 1.

-
For the second query, move all the balls from box 6 to box 4. Box 4 now contains one ball of color 2 and one ball of color 3, so print 2.

-
For the third query, move all the balls from box 5 to box 1. Box 1 now contains one ball of color 2, so print 1.

-
For the fourth query, move all the balls from box 3 to box 6. Box 6 now contains one ball of color 1, so print 1.

-
For the fifth query, move all the balls from box 4 to box 6. Box 6 now contains one ball of color 1, one ball of color 2, and one ball of color 3, so print 3.

Sample Input 2

5 3
2 4 2 4 2
3 1
2 5
3 2

Sample Output 2

1
2
0


N people labeled 1,2,\dots,N took an exam, and person i scored A_i points.
Only those who scored at least L points pass this exam.
Determine how many people out of the N have passed the exam.

Input

The input is given from Standard Input in the following format:
N L
A_1 A_2 \dots A_N

Output

Print the answer as an integer.

Constraints

- All input values are integers.
- 1 \le N \le 100
- 1 \le L \le 1000
- 0 \le A_i \le 1000

Sample Input 1

5 60
60 20 100 90 40

Sample Output 1

3

Five people took the exam. You need to score at least 60 points to pass.

- Person 1 scored 60 points, so they passed.
- Person 2 scored 20 points, so they did not pass.
- Person 3 scored 100 points, so they passed.
- Person 4 scored 90 points, so they passed.
- Person 5 scored 40 points, so they did not pass.

From the above, we can see that three people have passed.

Sample Input 2

4 80
79 78 77 76

Sample Output 2

0

There may be cases no one has passed.

Sample Input 3

10 50
31 41 59 26 53 58 97 93 23 84

Sample Output 3

6


You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N and integers L and R such that L\leq R.
For each i=1,2,\ldots,N, find the integer X_i that satisfies both of the following conditions. Note that the integer to be found is always uniquely determined.

- L\leq X_i \leq R.
- For every integer Y such that L \leq Y \leq R, it holds that |X_i - A_i| \leq |Y - A_i|.

Input

The input is given from Standard Input in the following format:
N L R
A_1 \ldots A_N

Output

Print X_i for i=1,2,\ldots,N, separated by spaces.

Constraints

- 1\leq N\leq 2\times 10^5
- 1\leq L\leq R \leq 10^9
- 1\leq A_i\leq 10^9
- All input values are integers.

Sample Input 1

5 4 7
3 1 4 9 7

Sample Output 1

4 4 4 7 7

For i=1:

- |4-3|=1
- |5-3|=2
- |6-3|=3
- |7-3|=4

Thus, X_i = 4.

Sample Input 2

3 10 10
11 10 9

Sample Output 2

10 10 10


You are given a positive integer D.
Find the minimum value of |x^2+y^2-D| for non-negative integers x and y.

Input

The input is given from Standard Input in the following format:
D

Output

Print the answer.

Constraints

- 1\leq D  \leq 2\times 10^{12}
- All input values are integers.

Sample Input 1

21

Sample Output 1

1

For x=4 and y=2, we have |x^2+y^2-D| = |16+4-21|=1.
There are no non-negative integers x and y such that |x^2+y^2-D|=0, so the answer is 1.

Sample Input 2

998244353

Sample Output 2

0

Sample Input 3

264428617

Sample Output 3

32


You are given an N \times N grid. Let (i,j) denote the cell in the i-th row from the top and the j-th column from the left.
The states of the cells are given by N strings of length N, S_1, S_2, \dots, S_N, in the following format:

- If the j-th character of S_i is o, there is an o written in cell (i,j).
- If the j-th character of S_i is x, there is an x written in cell (i,j).

Find the number of triples of cells that satisfy all of the following conditions:

- The three cells in the triple are distinct.
- All three cells have an o written in them.
- Exactly two of the cells are in the same row.
- Exactly two of the cells are in the same column.

Here, two triples are considered different if and only if some cell is contained in exactly one of the triples.

Input

The input is given from Standard Input in the following format:
N
S_1
S_2
\vdots
S_N

Output

Print the answer as an integer.

Constraints

- N is an integer between 2 and 2000, inclusive.
- S_i is a string of length N consisting of o and x.

Sample Input 1

3
ooo
oxx
xxo

Sample Output 1

4

The following four triples satisfy the conditions:

- (1,1),(1,2),(2,1)
- (1,1),(1,3),(2,1)
- (1,1),(1,3),(3,3)
- (1,2),(1,3),(3,3)

Sample Input 2

4
oxxx
xoxx
xxox
xxxo

Sample Output 2

0

Sample Input 3

15
xooxxooooxxxoox
oxxoxoxxxoxoxxo
oxxoxoxxxoxoxxx
ooooxooooxxoxxx
oxxoxoxxxoxoxxx
oxxoxoxxxoxoxxo
oxxoxooooxxxoox
xxxxxxxxxxxxxxx
xooxxxooxxxooox
oxxoxoxxoxoxxxo
xxxoxxxxoxoxxoo
xooxxxooxxoxoxo
xxxoxxxxoxooxxo
oxxoxoxxoxoxxxo
xooxxxooxxxooox

Sample Output 3

2960


You are given a sequence A=(A_1,A_2,\dots,A_N) of length N.
Respond to the following Q queries in the order they are given.
The k-th query is given in the following format:
i_k x_k

- First, change A_{i_k} to x_k. This change will carry over to subsequent queries.
- Then, print the \rm{mex} of A.
- The \rm{mex} of A is the smallest non-negative integer not contained in A.

Input

Input is given from Standard Input in the following format:
N Q
A_1 A_2 \dots A_N
i_1 x_1
i_2 x_2
\vdots
i_Q x_Q

Output

Print Q lines in total.
The k-th line should contain the answer to the k-th query as an integer.

Constraints

- All input values are integers.
- 1 \le N,Q \le 2 \times 10^5
- 0 \le A_i \le 10^9
- 1 \le i_k \le N
- 0 \le x_k \le 10^9

Sample Input 1

8 5
2 0 2 2 1 1 2 5
4 3
4 4
6 3
8 1000000000
2 1

Sample Output 1

4
3
6
5
0

Initially, the sequence A is (2,0,2,2,1,1,2,5).
This input gives you five queries.

- The first query changes A_4 to 3, making A=(2,0,2,3,1,1,2,5).
- At this point, the \rm{mex} of A is 4.

- The second query changes A_4 to 4, making A=(2,0,2,4,1,1,2,5).
- At this point, the \rm{mex} of A is 3.

- The third query changes A_6 to 3, making A=(2,0,2,4,1,3,2,5).
- At this point, the \rm{mex} of A is 6.

- The fourth query changes A_8 to 1000000000, making A=(2,0,2,4,1,3,2,1000000000).
- At this point, the \rm{mex} of A is 5.

- The fifth query changes A_2 to 1, making A=(2,1,2,4,1,3,2,1000000000).
- At this point, the \rm{mex} of A is 0.


In the calendar of AtCoder Kingdom, a year consists of M months from month 1 to month M, and each month consists of D days from day 1 to day D.
What day follows year y, month m, day d in this calendar?

Input

The input is given from Standard Input in the following format:
M D
y m d

Output

If the day following year y, month m, day d in the calendar of AtCoder Kingdom is year y', month m', day d', print y', m', and d' in this order, separated by spaces.

Constraints

- 1000 \leq y \leq 9000
- 1 \leq m \leq M \leq 99
- 1 \leq d \leq D \leq 99
- All input values are integers.

Sample Input 1

12 30
2023 12 30

Sample Output 1

2024 1 1

In the calendar of the kingdom, a year consists of 12 months, and each month consists of 30 days.
Thus, the day following year 2023, month 12, day 30 is year 2024, month 1, day 1.

Sample Input 2

36 72
6789 23 45

Sample Output 2

6789 23 46

In the calendar of the kingdom, one year consists of 36 months, and each month consists of 72 days.
Thus, the day following year 6789, month 23, day 45 is year 6789, month 23, day 46.

Sample Input 3

12 30
2012 6 20

Sample Output 3

2012 6 21


A supermarket sells egg packs.
A pack of 6 eggs costs S yen, a pack of 8 eggs costs M yen, and a pack of 12 eggs costs L yen.
When you can buy any number of each pack, find the minimum amount of money required to purchase at least N eggs.

Input

The input is given from Standard Input in the following format:
N S M L

Output

Print the answer.

Constraints

- 1 \leq N \leq 100
- 1 \leq S,M,L \leq 10^4
- All input values are integers.

Sample Input 1

16 120 150 200

Sample Output 1

300

It is optimal to buy two 8-egg packs.

Sample Input 2

10 100 50 10

Sample Output 2

10

It is optimal to buy one 12-egg pack.

Sample Input 3

99 600 800 1200

Sample Output 3

10000

It is optimal to buy five 8-egg packs and five 12-egg packs.


You are given a sequence A=(A_1,\ldots,A_N) of length N.
For each i=1,\ldots,N, solve the following problem.
Problem: Find the sum of all elements in A that are greater than A_i.

Input

The input is given from Standard Input in the following format:
N
A_1 \ldots A_N

Output

For each 1\leq k\leq N, let B_k be the answer to the problem when i=k. Print B_1,\ldots,B_N in this order, separated by spaces.

Constraints

- 1 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^6
- All input values are integers.

Sample Input 1

5
1 4 1 4 2

Sample Output 1

10 0 10 0 8

- For i=1, the sum of elements greater than A_1=1 is 4+4+2=10.
- For i=2, the sum of elements greater than A_2=4 is 0.
- For i=3, the sum of elements greater than A_3=1 is 4+4+2=10.
- For i=4, the sum of elements greater than A_4=4 is 0.
- For i=5, the sum of elements greater than A_5=2 is 4+4=8.

Sample Input 2

10
31 42 59 26 53 58 97 93 23 54

Sample Output 2

456 414 190 487 361 249 0 97 513 307

Sample Input 3

50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Sample Output 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


There is a grid with 10^9 by 10^9 squares. Let (i, j) denote the square at the (i + 1)-th row from the top and the (j + 1)-th column from the left (0 \leq i, j \lt 10^9). (Note the unusual index assignment.)
Each square is black or white. The color of the square (i, j) is represented by a character P[i \bmod N][j \bmod N], where B means black, and W means white. Here, a \bmod b denotes the remainder when a is divided by b.
Answer Q queries.
Each query gives you four integers A, B, C, D and asks you to find the number of black squares contained in the rectangular area with (A, B) as the top-left corner and (C, D) as the bottom-right corner.

Input

The input is given from Standard Input in the following format. Here, \text{query}_i is the i-th query to be processed.
N Q
P[0][0]P[0][1]\dots P[0][N-1]
P[1][0]P[1][1]\dots P[1][N-1]
\vdots
P[N-1][0]P[N-1][1]\dots P[N-1][N-1]
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

Each query is given in the following format:
A B C D

Output

Follow the instructions in the problem statement and print the answers to the queries, separated by newlines.

Constraints

- 1 \leq N \leq 1000
- P[i][j] is W or B.
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq A \leq C \lt 10^9
- 0 \leq B \leq D \lt 10^9
- N, Q, A, B, C, D are all integers.

Sample Input 1

3 2
WWB
BBW
WBW
1 2 3 4
0 3 4 5

Sample Output 1

4
7

The figure below illustrates the upper left part of the grid.

For the first query, the rectangular area with (1, 2) as the top-left corner and (3, 4) as the bottom-right corner, surrounded by the red frame in the figure, contains four black squares.
For the second query, the rectangular area with (0, 3) as the top-left corner and (4, 5) as the bottom-right corner, surrounded by the blue frame in the figure, contains seven black squares.

Sample Input 2

10 5
BBBWWWBBBW
WWWWWBBBWB
BBBWBBWBBB
BBBWWBWWWW
WWWWBWBWBW
WBBWBWBBBB
WWBBBWWBWB
WBWBWWBBBB
WBWBWBBWWW
WWWBWWBWWB
5 21 21 93
35 35 70 43
55 72 61 84
36 33 46 95
0 0 999999999 999999999

Sample Output 2

621
167
44
344
500000000000000000


AtCoder cafeteria sells meals consisting of a main dish and a side dish.
There are N types of main dishes, called main dish 1, main dish 2, \dots, main dish N. Main dish i costs a_i yen.
There are M types of side dishes, called side dish 1, side dish 2, \dots, side dish M. Side dish i costs b_i yen.
A set meal is composed by choosing one main dish and one side dish. The price of a set meal is the sum of the prices of the chosen main dish and side dish.
However, for L distinct pairs (c_1, d_1), \dots, (c_L, d_L), the set meal consisting of main dish c_i and side dish d_i is not offered because they do not go well together.
That is, NM - L set meals are offered. (The constraints guarantee that at least one set meal is offered.)
Find the price of the most expensive set meal offered.

Input

The input is given from Standard Input in the following format:
N M L
a_1 a_2 \dots a_N
b_1 b_2 \dots b_M
c_1 d_1
c_2 d_2
\vdots
c_L d_L

Output

Print the price, in yen, of the most expensive set meal offered.

Constraints

- 1 \leq N, M \leq 10^5
- 0 \leq L \leq \min(10^5, NM - 1)
- 1 \leq a_i, b_i \leq 10^9
- 1 \leq c_i \leq N
- 1 \leq d_j \leq M
- (c_i, d_i) \neq (c_j, d_j) if i \neq j.
- All input values are integers.

Sample Input 1

2 3 3
2 1
10 30 20
1 2
2 1
2 3

Sample Output 1

31

They offer three set meals, listed below, along with their prices:

- A set meal consisting of main dish 1 and side dish 1, at a price of 2 + 10 = 12 yen.
- A set meal consisting of main dish 1 and side dish 3, at a price of 2 + 20 = 22 yen.
- A set meal consisting of main dish 2 and side dish 2, at a price of 1 + 30 = 31 yen.

Among them, the most expensive is the third one. Thus, print 31.

Sample Input 2

2 1 0
1000000000 1
1000000000

Sample Output 2

2000000000

Sample Input 3

10 10 10
47718 21994 74148 76721 98917 73766 29598 59035 69293 29127
7017 46004 16086 62644 74928 57404 32168 45794 19493 71590
1 3
2 6
4 5
5 4
5 5
5 6
5 7
5 8
5 10
7 3

Sample Output 3

149076


AtCoder Inc. sells merchandise through its online shop.
Takahashi has decided to purchase N types of products from there.
For each integer i from 1 to N, the i-th type of product has a price of P_i yen each, and he will buy Q_i of this.
Additionally, he must pay a shipping fee.
The shipping fee is 0 yen if the total price of the products purchased is S yen or above, and K yen otherwise.
He will pay the total price of the products purchased plus the shipping fee.
Calculate the amount he will pay.

Input

The input is given from Standard Input in the following format:
N S K
P_1 Q_1
P_2 Q_2
\vdots
P_N Q_N

Output

Print the amount Takahashi will pay for online shopping.

Constraints

- 1\leq N\leq 100
- 1\leq S\leq 10000
- 1\leq K\leq 10000
- 1\leq P_i\leq 10000
- 1\leq Q_i\leq 100
- All input values are integers.

Sample Input 1

2 2000 500
1000 1
100 6

Sample Output 1

2100

Takahashi buys one product for 1000 yen and six products for 100 yen each.
Thus, the total price of the products is 1000\times 1+100\times 6=1600 yen.
Since the total amount for the products is less than 2000 yen, the shipping fee will be 500 yen.
Therefore, the amount Takahashi will pay is 1600+500=2100 yen.

Sample Input 2

3 2000 500
1000 1
100 6
5000 1

Sample Output 2

6600

The total price of the products is 1000\times 1+100\times 6+5000\times 1=6600 yen.
Since the total amount for the products is not less than 2000 yen, the shipping fee will be 0 yen.
Therefore, the amount Takahashi will pay is 6600+0=6600 yen.

Sample Input 3

2 2000 500
1000 1
1000 1

Sample Output 3

2000

There may be multiple products with the same price per item.


AtCoder Inc. sells glasses and mugs.
Takahashi has a glass with a capacity of G milliliters and a mug with a capacity of M milliliters.
Here, G<M.
Initially, both the glass and the mug are empty.
After performing the following operation K times, determine how many milliliters of water are in the glass and the mug, respectively.

- When the glass is filled with water, that is, the glass contains exactly G milliliters of water, discard all the water from the glass.
- Otherwise, if the mug is empty, fill the mug with water.
- Otherwise, transfer water from the mug to the glass until the mug is empty or the glass is filled with water.

Input

The input is given from Standard Input in the following format:
K G M

Output

Print the amounts, in milliliters, of water in the glass and the mug, in this order, separated by a space, after performing the operation K times.

Constraints

- 1\leq K\leq 100
- 1\leq G<M\leq 1000
- G, M, and K are integers.

Sample Input 1

5 300 500

Sample Output 1

200 500

The operation will be performed as follows. Initially, both the glass and the mug are empty.

- Fill the mug with water. The glass has 0 milliliters, and the mug has 500 milliliters of water.
- Transfer water from the mug to the glass until the glass is filled. The glass has 300 milliliters, and the mug has 200 milliliters of water.
- Discard all the water from the glass. The glass has 0 milliliters, and the mug has 200 milliliters of water.
- Transfer water from the mug to the glass until the mug is empty. The glass has 200 milliliters, and the mug has 0 milliliters of water.
- Fill the mug with water. The glass has 200 milliliters, and the mug has 500 milliliters of water.

Thus, after five operations, the glass has 200 milliliters, and the mug has 500 milliliters of water.
Hence, print 200 and 500 in this order, separated by a space.

Sample Input 2

5 100 200

Sample Output 2

0 0


AtCoder Inc. sells T-shirts with its logo.
You are given Takahashi's schedule for N days as a string S of length N consisting of 0, 1, and 2.
Specifically, for an integer i satisfying 1\leq i\leq N,

- if the i-th character of S is 0, he has no plan scheduled for the i-th day;
- if the i-th character of S is 1, he plans to go out for a meal on the i-th day;
- if the i-th character of S is 2, he plans to attend a competitive programming event on the i-th day.

Takahashi has M plain T-shirts, all washed and ready to wear just before the first day.
In addition, to be able to satisfy the following conditions, he will buy several AtCoder logo T-shirts.

- On days he goes out for a meal, he will wear a plain or logo T-shirt.
- On days he attends a competitive programming event, he will wear a logo T-shirt.
- On days with no plans, he will not wear any T-shirts. Also, he will wash all T-shirts worn at that point. He can wear them again from the next day onwards.
- Once he wears a T-shirt, he cannot wear it again until he washes it.

Determine the minimum number of T-shirts he needs to buy to be able to wear appropriate T-shirts on all scheduled days during the N days. If he does not need to buy new T-shirts, print 0.
Assume that the purchased T-shirts are also washed and ready to use just before the first day.

Input

The input is given from Standard Input in the following format:
N M
S

Output

Print the minimum number of T-shirts Takahashi needs to buy to be able to satisfy the conditions in the problem statement.
If he does not need to buy new T-shirts, print 0.

Constraints

- 1\leq M\leq N\leq 1000
- S is a string of length N consisting of 0, 1, and 2.
- N and M are integers.

Sample Input 1

6 1
112022

Sample Output 1

2

If Takahashi buys two logo T-shirts, he can wear T-shirts as follows:

- On the first day, he wears a logo T-shirt to go out for a meal.
- On the second day, he wears a plain T-shirt to go out for a meal.
- On the third day, he wears a logo T-shirt to attend a competitive programming event.
- On the fourth day, he has no plans, so he washes all the worn T-shirts. This allows him to reuse the T-shirts worn on the first, second, and third days.
- On the fifth day, he wears a logo T-shirt to attend a competitive programming event.
- On the sixth day, he wears a logo T-shirt to attend a competitive programming event.

If he buys one or fewer logo T-shirts, he cannot use T-shirts to meet the conditions no matter what. Hence, print 2.

Sample Input 2

3 1
222

Sample Output 2

3

Sample Input 3

2 1
01

Sample Output 3

0

He does not need to buy new T-shirts.