- E869120's and square1001's 16-th birthday is
- coming soon.
- Takahashi from AtCoder Kingdom gave them a round cake
- cut into 16 equal fan-shaped pieces.
-
-
- E869120 and square1001 were just about to eat
- A and B of those pieces,
- respectively,
- when they found a note attached to the cake saying that
- "the same person should not take two adjacent pieces of
- cake".
-
-
- Can both of them obey the instruction in the note and
- take desired numbers of pieces of cake?
-
-
-
-
-
-
-
Constraints
-
-
- A and B are integers between
- 1 and 16 (inclusive).
-
-
A+B is at most 16.
-
-
-
-
-
-
-
-
-
-
Input
-
- Input is given from Standard Input in the following
- format:
-
-
AB
-
-
-
-
-
-
-
Output
-
- If both E869120 and square1001 can obey the
- instruction in the note and take desired numbers of
- pieces of cake, print Yay!; otherwise,
- print :(.
-
-
-
-
-
-
-
-
-
-
Sample Input 1
-
-5 4
-
-
-
-
-
-
-
Sample Output 1
-
-Yay!
-
-
-
- Both of them can take desired number of pieces as
- follows:
-
-
-
-
-
-
-
-
-
-
Sample Input 2
-
-8 8
-
-
-
-
-
-
-
Sample Output 2
-
-Yay!
-
-
-
- Both of them can take desired number of pieces as
- follows:
-
-
-
-
-
-
-
-
-
-
Sample Input 3
-
-11 4
-
-
-
-
-
-
-
Sample Output 3
-
-:(
-
-
-
- In this case, there is no way for them to take desired
- number of pieces, unfortunately.
-
E869120's and square1001's 16-th birthday is coming soon.
+Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.
+
E869120 and square1001 were just about to eat A and B of those pieces, respectively,
+when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".
+
Can both of them obey the instruction in the note and take desired numbers of pieces of cake?
+
+
+
+
+
+
Constraints
+
+
A and B are integers between 1 and 16 (inclusive).
+
A+B is at most 16.
+
+
+
+
+
+
+
+
+
+
Input
+
Input is given from Standard Input in the following format:
+
AB
+
+
+
+
+
+
+
+
Output
+
If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(.
+
+
+
+
+
+
+
+
+
Sample Input 1
5 4
+
+
+
+
+
+
+
+
Sample Output 1
Yay!
+
+
+
Both of them can take desired number of pieces as follows:
+
+
+
+
+
+
+
+
+
Sample Input 2
8 8
+
+
+
+
+
+
+
+
Sample Output 2
Yay!
+
+
+
Both of them can take desired number of pieces as follows:
+
+
+
+
+
+
+
+
+
Sample Input 3
11 4
+
+
+
+
+
+
+
+
Sample Output 3
:(
+
+
+
In this case, there is no way for them to take desired number of pieces, unfortunately.
- Today, the memorable AtCoder Beginner Contest 100 takes
- place. On this occasion, Takahashi would like to give an
- integer to Ringo.
- As the name of the contest is AtCoder Beginner Contest
- 100, Ringo would be happy if he is given a positive
- integer that can be divided by 100
- exactlyD times.
-
-
- Find the N-th smallest integer that would
- make Ringo happy.
-
-
-
-
-
-
-
Constraints
-
-
- D is 0, 1 or
- 2.
-
-
- N is an integer between 1 and
- 100 (inclusive).
-
-
-
-
-
-
-
-
-
-
-
Input
-
- Input is given from Standard Input in the following
- format:
-
-
DN
-
-
-
-
-
-
-
Output
-
- Print the N-th smallest integer that can be
- divided by 100 exactly D times.
-
-
-
-
-
-
-
-
-
-
Sample Input 1
-
-0 5
-
-
-
-
-
-
-
Sample Output 1
-
-5
-
-
-
- The integers that can be divided by
- 100 exactly 0 times (that is, not
- divisible by 100) are as follows:
- 1, 2, 3, 4,
- 5, 6, 7, ...
- Thus, the 5-th smallest integer that would
- make Ringo happy is 5.
-
-
-
-
-
-
-
-
-
Sample Input 2
-
-1 11
-
-
-
-
-
-
-
Sample Output 2
-
-1100
-
-
-
- The integers that can be divided by
- 100 exactly once are as follows:
- 100, 200, 300,
- 400, 500, 600,
- 700, 800, 900,
- 1 \ 000, 1 \ 100, ...
- Thus, the integer we are seeking is 1 \ 100.
-
-
-
-
-
-
-
-
-
Sample Input 3
-
-2 85
-
-
-
-
-
-
-
Sample Output 3
-
-850000
-
-
-
- The integers that can be divided by
- 100 exactly twice are as follows:
- 10 \ 000, 20 \ 000,
- 30 \ 000, ...
- Thus, the integer we are seeking is
- 850 \ 000.
-
Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
+As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100exactlyD times.
+
Find the N-th smallest integer that would make Ringo happy.
+
+
+
+
+
+
Constraints
+
+
D is 0, 1 or 2.
+
N is an integer between 1 and 100 (inclusive).
+
+
+
+
+
+
+
+
+
+
Input
+
Input is given from Standard Input in the following format:
+
DN
+
+
+
+
+
+
+
+
Output
+
Print the N-th smallest integer that can be divided by 100 exactly D times.
+
+
+
+
+
+
+
+
+
Sample Input 1
0 5
+
+
+
+
+
+
+
+
Sample Output 1
5
+
+
+
The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...
+Thus, the 5-th smallest integer that would make Ringo happy is 5.
+
+
+
+
+
+
+
+
Sample Input 2
1 11
+
+
+
+
+
+
+
+
Sample Output 2
1100
+
+
+
The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...
+Thus, the integer we are seeking is 1 \ 100.
+
+
+
+
+
+
+
+
Sample Input 3
2 85
+
+
+
+
+
+
+
+
Sample Output 3
850000
+
+
+
The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...
+Thus, the integer we are seeking is 850 \ 000.
As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.
+Snuke, an employee, would like to play with this sequence.
+
Specifically, he would like to repeat the following operation as many times as possible:
+
For every i satisfying 1 \leq i \leq N, perform one of the following: "divide a_i by 2" and "multiply a_i by 3".
+Here, choosing "multiply a_i by 3" for every i is not allowed, and the value of a_i after the operation must be an integer.
+
+
+
At most how many operations can be performed?
+
+
+
+
+
+
Constraints
+
+
N is an integer between 1 and 10 \ 000 (inclusive).
+
a_i is an integer between 1 and 1 \ 000 \ 000 \ 000 (inclusive).
+
+
+
+
+
+
+
+
+
+
Input
+
Input is given from Standard Input in the following format:
+
N
+a_1a_2a_3...a_N
+
+
+
+
+
+
+
+
Output
+
Print the maximum number of operations that Snuke can perform.
+
+
+
+
+
+
+
+
+
Sample Input 1
3
+5 2 4
+
+
+
+
+
+
+
+
Sample Output 1
3
+
+
+
The sequence is initially {5, 2, 4}. Three operations can be performed as follows:
+
+
First, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.
+
Next, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.
+
Finally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.
+
+
+
+
+
+
+
+
+
Sample Input 2
4
+631 577 243 199
+
+
+
+
+
+
+
+
Sample Output 2
0
+
+
+
No operation can be performed since all the elements are odd. Thus, the answer is 0.
Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100.
+
The shop sells N kinds of cakes.
+Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the popularity of z_i.
+These values may be zero or negative.
+
Ringo has decided to have M pieces of cakes here. He will choose the set of cakes as follows:
+
+
Do not have two or more pieces of the same kind of cake.
+
Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
+
+
Find the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.
+
+
+
+
+
+
Constraints
+
+
N is an integer between 1 and 1 \ 000 (inclusive).
+
M is an integer between 0 and N (inclusive).
+
x_i, y_i, z_i \ (1 \leq i \leq N) are integers between -10 \ 000 \ 000 \ 000 and 10 \ 000 \ 000 \ 000 (inclusive).
+
+
+
+
+
+
+
+
+
+
Input
+
Input is given from Standard Input in the following format:
+
NM
+x_1y_1z_1
+x_2y_2z_2
+ ::
+x_Ny_Nz_N
+
+
+
+
+
+
+
+
Output
+
Print the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.
+
+
+
+
+
+
+
+
+
Sample Input 1
5 3
+3 1 4
+1 5 9
+2 6 5
+3 5 8
+9 7 9
+
+
+
+
+
+
+
+
Sample Output 1
56
+
+
+
Consider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:
+
+
Beauty: 1 + 3 + 9 = 13
+
Tastiness: 5 + 5 + 7 = 17
+
Popularity: 9 + 8 + 9 = 26
+
+
The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 13 + 17 + 26 = 56. This is the maximum value.
Consider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:
+
+
Beauty: 1 + 7 + 13 = 21
+
Tastiness: (-2) + (-8) + (-14) = -24
+
Popularity: 3 + (-9) + 15 = 9
+
+
The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 21 + 24 + 9 = 54. This is the maximum value.
If we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total beauty, tastiness and popularity will be -323, 66 and 249, respectively.
+The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 323 + 66 + 249 = 638. This is the maximum value.
Let's call an array a consisting of n positive (greater than 0) integers beautiful if the following condition is held for every i from 1 to n: either ai=1, or at least one of the numbers ai−1 and ai−2 exists in the array as well.
For example:
the array [5,3,1] is beautiful: for a1, the number a1−2=3 exists in the array; for a2, the number a2−2=1 exists in the array; for a3, the condition a3=1 holds;
the array [1,2,2,2,2] is beautiful: for a1, the condition a1=1 holds; for every other number ai, the number ai−1=1 exists in the array;
the array [1,4] is not beautiful: for a2, neither a2−2=2 nor a2−1=3 exists in the array, and a2≠1;
the array [2] is not beautiful: for a1, neither a1−1=1 nor a1−2=0 exists in the array, and a1≠1;
the array [2,1,3] is beautiful: for a1, the number a1−1=1 exists in the array; for a2, the condition a2=1 holds; for a3, the number a3−2=1 exists in the array.
You are given a positive integer s. Find the minimum possible size of a beautiful array with the sum of elements equal to s.
Input
The first line contains one integer t (1≤t≤5000) — the number of test cases.
Then t lines follow, the i-th line contains one integer s (1≤s≤5000) for the i-th test case.
Output
Print t integers, the i-th integer should be the answer for the i-th testcase: the minimum possible size of a beautiful array with the sum of elements equal to s.
Example
Input
Copy
4
+1
+8
+7
+42
+
Output
Copy
1
+3
+3
+7
+
Note
Consider the example test:
in the first test case, the array [1] meets all conditions;
in the second test case, the array [3,4,1] meets all conditions;
in the third test case, the array [1,2,4] meets all conditions;
in the fourth test case, the array [1,4,6,8,10,2,11] meets all conditions.
You are given a string s of length n consisting only of the characters 0 and 1.
You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the remaining two parts together (any of them can be empty) in the same order. For example, if you erase the substring 111 from the string 111110, you will get the string 110. When you delete a substring of length l, you get a⋅l+b points.
Your task is to calculate the maximum number of points that you can score in total, if you have to make the given string empty.
Input
The first line contains a single integer t (1≤t≤2000) — the number of testcases.
The first line of each testcase contains three integers n, a and b (1≤n≤100;−100≤a,b≤100) — the length of the string s and the parameters a and b.
The second line contains the string s. The string s consists only of the characters 0 and 1.
Output
For each testcase, print a single integer — the maximum number of points that you can score.
Example
Input
Copy
3
+3 2 0
+000
+5 -2 5
+11001
+6 1 -4
+100111
+
Output
Copy
6
+15
+-2
+
Note
In the first example, it is enough to delete the entire string, then we will get 2⋅3+0=6 points.
In the second example, if we delete characters one by one, then for each deleted character we will get (−2)⋅1+5=3 points, i. e. 15 points in total.
In the third example, we can delete the substring 00 from the string 100111, we get 1⋅2+(−4)=−2 points, and the string will be equal to 1111, removing it entirely we get 1⋅4+(−4)=0 points. In total, we got −2 points for 2 operations.
Suppose you have two points p=(xp,yp) and q=(xq,yq). Let's denote the Manhattan distance between them as d(p,q)=|xp−xq|+|yp−yq|.
Let's say that three points p, q, r form a bad triple if d(p,r)=d(p,q)+d(q,r).
Let's say that an array b1,b2,…,bm is good if it is impossible to choose three distinct indices i, j, k such that the points (bi,i), (bj,j) and (bk,k) form a bad triple.
You are given an array a1,a2,…,an. Calculate the number of good subarrays of a. A subarray of the array a is the array al,al+1,…,ar for some 1≤l≤r≤n.
Note that, according to the definition, subarrays of length 1 and 2 are good.
Input
The first line contains one integer t (1≤t≤5000) — the number of test cases.
The first line of each test case contains one integer n (1≤n≤2⋅105) — the length of array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109).
It's guaranteed that the sum of n doesn't exceed 2⋅105.
Output
For each test case, print the number of good subarrays of array a.
Example
Input
Copy
3
+4
+2 4 1 3
+5
+6 9 1 9 6
+2
+13 37
+
Output
Copy
10
+12
+3
+
Note
In the first test case, it can be proven that any subarray of a is good. For example, subarray [a2,a3,a4] is good since it contains only three elements and:
You are given a string s of length n. Each character is either one of the first k lowercase Latin letters or a question mark.
You are asked to replace every question mark with one of the first k lowercase Latin letters in such a way that the following value is maximized.
Let fi be the maximum length substring of string s, which consists entirely of the i-th Latin letter. A substring of a string is a contiguous subsequence of that string. If the i-th letter doesn't appear in a string, then fi is equal to 0.
The value of a string s is the minimum value among fi for all i from 1 to k.
What is the maximum value the string can have?
Input
The first line contains two integers n and k (1≤n≤2⋅105; 1≤k≤17) — the length of the string and the number of first Latin letters used.
The second line contains a string s, consisting of n characters. Each character is either one of the first k lowercase Latin letters or a question mark.
Output
Print a single integer — the maximum value of the string after every question mark is replaced with one of the first k lowercase Latin letters.
Examples
Input
Copy
10 2
+a??ab????b
+
Output
Copy
4
+
Input
Copy
9 4
+?????????
+
Output
Copy
2
+
Input
Copy
2 3
+??
+
Output
Copy
0
+
Input
Copy
15 3
+??b?babbc??b?aa
+
Output
Copy
3
+
Input
Copy
4 4
+cabd
+
Output
Copy
1
+
Note
In the first example the question marks can be replaced in the following way: "aaaababbbb". f1=4, f2=4, thus the answer is 4. Replacing it like this is also possible: "aaaabbbbbb". That way f1=4, f2=6, however, the minimum of them is still 4.
In the second example one of the possible strings is "aabbccdda".
In the third example at least one letter won't appear in the string, thus, the minimum of values fi is always 0.
There is an infinite pond that can be represented with a number line. There are n rocks in the pond, numbered from 1 to n. The i-th rock is located at an integer coordinate ai. The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of the coordinate, so a1<a2<⋯<an.
A robot frog sits on the rock number s. The frog is programmable. It has a base jumping distance parameter d. There also is a setting for the jumping distance range. If the jumping distance range is set to some integer k, then the frog can jump from some rock to any rock at a distance from d−k to d+k inclusive in any direction. The distance between two rocks is an absolute difference between their coordinates.
You are assigned a task to implement a feature for the frog. Given two integers i and k determine if the frog can reach a rock number i from a rock number s performing a sequence of jumps with the jumping distance range set to k. The sequence can be arbitrarily long or empty.
You will be given q testcases for that feature, the j-th testcase consists of two integers i and k. Print "Yes" if the i-th rock is reachable and "No" otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes", "Yes" and 'YES"' will be recognized as a positive answer).
Input
The first line contains four integers n, q, s and d (1≤n,q≤2⋅105; 1≤s≤n; 1≤d≤106) — the number of rocks, the number of testcases, the starting rock and the base jumping distance parameter.
The second line contains n integers a1,a2,…,an (1≤ai≤106) — the coordinates of the rocks. The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of distance from the land, so a1<a2<⋯<an.
Each of the next q lines contains two integers i and k (1≤i≤n; 1≤k≤106) — the parameters to the testcase.
Output
For each of the testcases print an answer. If there is a sequence of jumps from a rock number s to a rock number i with the jumping distance range set to k, then print "Yes". Otherwise, print "No".
In the first testcase the destination rock is the same as the starting rock, thus no jumps are required to reach it.
In the second testcase the frog can jump any distance in the range [5−2;5+2]. Thus, it can reach rock number 5 (by jumping 7 to the right) and rock number 3 (by jumping 3 to the left). From rock number 3 it can reach rock number 2 (by jumping 5 to the left). From rock number 2 it can reach rock number 1 (by jumping 4 to the left). However, there is no way to reach rock number 7.
In the third testcase the frog can jump any distance in the range [5−3;5+3]. Thus, it can reach rock number 7 by jumping to rock 5 first and to 7 afterwards.
The fourth testcase is shown in the explanation for the second testcase.