Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Educational Codeforces Round 111 (Rated for Div. 2)
A. Find The Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ai1 and ai2 exists in the array as well.

For example:

  • the array [5,3,1] is beautiful: for a1, the number a12=3 exists in the array; for a2, the number a22=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 ai1=1 exists in the array;
  • the array [1,4] is not beautiful: for a2, neither a22=2 nor a21=3 exists in the array, and a21;
  • the array [2] is not beautiful: for a1, neither a11=1 nor a12=0 exists in the array, and a11;
  • the array [2,1,3] is beautiful: for a1, the number a11=1 exists in the array; for a2, the condition a2=1 holds; for a3, the number a32=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 (1t5000) — the number of test cases.

Then t lines follow, the i-th line contains one integer s (1s5000) 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:

  1. in the first test case, the array [1] meets all conditions;
  2. in the second test case, the array [3,4,1] meets all conditions;
  3. in the third test case, the array [1,2,4] meets all conditions;
  4. in the fourth test case, the array [1,4,6,8,10,2,11] meets all conditions.

B. Maximum Cost Deletion
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 al+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 (1t2000) — the number of testcases.

The first line of each testcase contains three integers n, a and b (1n100;100a,b100) — 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 23+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 12+(4)=2 points, and the string will be equal to 1111, removing it entirely we get 14+(4)=0 points. In total, we got 2 points for 2 operations.

C. Manhattan Subarrays
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Suppose you have two points p=(xp,yp) and q=(xq,yq). Let's denote the Manhattan distance between them as d(p,q)=|xpxq|+|ypyq|.

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 1lrn.

Note that, according to the definition, subarrays of length 1 and 2 are good.

Input

The first line contains one integer t (1t5000) — the number of test cases.

The first line of each test case contains one integer n (1n2105) — the length of array a.

The second line of each test case contains n integers a1,a2,,an (1ai109).

It's guaranteed that the sum of n doesn't exceed 2105.

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:

  • d((a2,2),(a4,4))=|43|+|24|=3<d((a2,2),(a3,3))+d((a3,3),(a4,4))=3+1+2+1=7;
  • d((a2,2),(a3,3))<d((a2,2),(a4,4))+d((a4,4),(a3,3));
  • d((a3,3),(a4,4))<d((a3,3),(a2,2))+d((a2,2),(a4,4));

In the second test case, for example, subarray [a1,a2,a3,a4] is not good, since it contains a bad triple (a1,1), (a2,2), (a4,4):

  • d((a1,1),(a4,4))=|69|+|14|=6;
  • d((a1,1),(a2,2))=|69|+|12|=4;
  • d((a2,2),(a4,4))=|99|+|24|=2;

So, d((a1,1),(a4,4))=d((a1,1),(a2,2))+d((a2,2),(a4,4)).

D. Excellent Arrays
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's call an integer array a1,a2,,angood if aii for each i.

Let F(a) be the number of pairs (i,j) (1i<jn) such that ai+aj=i+j.

Let's say that an array a1,a2,,an is excellent if:

  • a is good;
  • lair for each i;
  • F(a) is the maximum possible among all good arrays of size n.

Given n, l and r, calculate the number of excellent arrays modulo 109+7.

Input

The first line contains a single integer t (1t1000) — the number of test cases.

The first and only line of each test case contains three integers n, l, and r (2n2105; 109l1; nr109).

It's guaranteed that the sum of n doesn't exceed 2105.

Output

For each test case, print the number of excellent arrays modulo 109+7.

Example
Input
Copy
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
Copy
4
10
143922563
698570404
Note

In the first test case, it can be proven that the maximum F(a) among all good arrays a is equal to 2. The excellent arrays are:

  1. [2,1,2];
  2. [0,3,2];
  3. [2,3,2];
  4. [3,0,1].

E. Stringforces
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 (1n2105; 1k17) — 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.

F. Jumping Around
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 dk 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 (1n,q2105; 1sn; 1d106) — 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 (1ai106) — 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 (1in; 1k106) — 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".

Examples
Input
Copy
7 4 4 5
1 5 10 13 20 22 28
4 1
7 2
7 3
3 2
Output
Copy
Yes
No
Yes
Yes
Input
Copy
10 8 6 11
1 2 4 7 8 9 11 13 19 20
2 13
5 8
8 1
6 15
1 15
2 7
7 6
8 9
Output
Copy
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Input
Copy
6 9 6 6
1 2 4 9 18 19
2 17
1 18
5 4
2 11
5 17
6 8
4 3
3 3
6 6
Output
Copy
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Input
Copy
4 1 1 10
1 8 10 19
2 1
Output
Copy
Yes
Note

Explanation of the first example:

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 [52;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 [53;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.