Summer-training-01-Beginners
A. Moon is moving on Finally!! (wink wink)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While Moon is trying to have a better life after his explosive break up, in order to be happy again he wanted to move on.

He started counting the number of empty seats on the train that they used to ride everyday but he doesn't want to sit in the same cabin as his EX.

The train consists of $$$n$$$ cabins and each cabin consists of $$$4$$$ seats. She is currently sitting in cabin $$$x$$$.

Moon wants to find the number of seats he can sit on.

Input

The first integer contains one integer $$$n$$$ $$$(1 \le n\le10^5)$$$ — the number of cabins.

the second integer contain one integer $$$x$$$ $$$( 1 \le x\le n )$$$ — The cabin in which his EX sits in .

the next n integers represent the number of occupied seats in the ith cabin $$$(0 \le a_{i} \le 4 )$$$ .

Output

Print the number of seats Moon can sit on

Examples
Input
4 1
1 2 3 0
Output
7
Input
7 3
3 2 3 3 2 3 1
Output
10
Note

its guaranteed that there is at least one cabin that has at least one occupied seat ( His EX )

Moon in fact did not move on :´)

B. zarqawi and the string
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Zarqawi, a man from the infamous city of Zarqa, has spent his life mastering the ancient art of string manipulation. Known for his quick wit and sharp tongue, he's earned a reputation among both his friends and enemies — if you challenge him, you better be ready for more than just a test of intellect.

For the master to test Zarqawi's skills, he gave Zarqawi a string $$$S$$$ and $$$q$$$ queries.

On each query Zarqawi is given two letters $$$x$$$ and $$$y$$$.

On each query he must find the longest substring in the string s that starts with the letter $$$x$$$ and ends with the letter $$$y$$$.

If he can't find such a substring, he must immediately answer $$$-1$$$.

With his reputation at stake and no time to waste, can you help Zarqawi solve the mystery of the sacred string, and maybe teach a few of his friends a lesson along the way?

Input

the first line containing two integers $$$n$$$ and $$$q$$$ ($$$1$$$ ≤ $$$n$$$ ≤ $$$10^5$$$, $$$1$$$ ≤ $$$q$$$ ≤ $$$10^5$$$) — the length of the string $$$S$$$ and the number of challenges.

the second line containing the string $$$S$$$ of length $$$n$$$, consisting only of lowercase English letters.

Then $$$q$$$ lines follow, each line containing two space-separated lowercase letters $$$x$$$ and $$$y$$$ — representing the starting and the ending characters of the string.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each challenge, output a single integer — the length of the longest substring that starts with $$$x$$$ and ends with $$$y$$$. If there is no such substring, output $$$-1$$$.

Examples
Input
6 3
abcdef
a f
b d
a z
Output
6
3
-1
Input
7 4
bacdbca
b a
a c
c d
d b
Output
7
5
2
2

C. Assembly via Minimums
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Sasha has an array $$$a$$$ of $$$n$$$ integers. He got bored and for all $$$i$$$, $$$j$$$ ($$$i \lt j$$$), he wrote down the minimum value of $$$a_i$$$ and $$$a_j$$$. He obtained a new array $$$b$$$ of size $$$\frac{n\cdot (n-1)}{2}$$$.

For example, if $$$a=$$$ [$$$2,3,5,1$$$], he would write [$$$\min(2, 3), \min(2, 5), \min(2, 1), \min(3, 5), \min(3, 1), min(5, 1)$$$] $$$=$$$ [$$$2, 2, 1, 3, 1, 1$$$].

Then, he randomly shuffled all the elements of the array $$$b$$$.

Unfortunately, he forgot the array $$$a$$$, and your task is to restore any possible array $$$a$$$ from which the array $$$b$$$ could have been obtained.

The elements of array $$$a$$$ should be in the range $$$[-10^9,10^9]$$$.

Input

The first line contains a single integer $$$t$$$ ($$$1\le t\le 200$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$2\le n\le 10^3$$$) — the length of array $$$a$$$.

The second line of each test case contains $$$\frac{n\cdot (n-1)}{2}$$$ integers $$$b_1,b_2,\dots,b_{\frac{n\cdot (n-1)}{2}}$$$ ($$$−10^9\le b_i\le 10^9$$$) — the elements of array $$$b$$$.

It is guaranteed that the sum of $$$n$$$ over all tests does not exceed $$$10^3$$$ and for each array $$$b$$$ in the test, there exists an original array.

Output

For each test case, output any possible array $$$a$$$ of length $$$n$$$.

Example
Input
5
3
1 3 1
2
10
4
7 5 3 5 3 3
5
2 2 2 2 2 2 2 2 2 2
5
3 0 0 -2 0 -2 0 0 -2 -2
Output
1 3 3
10 10
7 5 3 12
2 2 2 2 2
0 -2 0 3 5
Note

In the first sample, Sasha chose the array $$$[1,3,3]$$$, then the array $$$b$$$ will look like $$$[\min(a_1,a_2)=1, \min(a_1,a_3)=1, \min(a_2,a_3)=3]$$$, after shuffling its elements, the array can look like $$$[1,3,1]$$$.

In the second sample, there is only one pair, so the array $$$[10,10]$$$ is suitable. Another suitable array could be $$$[15,10]$$$.

D. Wara B3d Wara B3d
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your task is to determine whether it is possible to find exactly $$$m$$$ consecutive positive integers such that their total sum is exactly equal to $$$n$$$.

A sequence of numbers is considered strictly consecutive positive integers if it consists of integers greater than zero that follow each other continuously, with each subsequent number being exactly $$$1$$$ greater than the previous one. For example, $$$4, 5, 6$$$ are three consecutive positive integers, while $$$2, 4, 6$$$ (has gaps) and $$$-1, 0, 1$$$ (contains non-positive numbers) are not

Input

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.Each of the next $$$t$$$ lines contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^{9},1 \le m \le 10^{9}$$$) — the target sum and the required number of consecutive positive integers, respectively.

Output

For each test case, output YES if it is possible to form the sum $$$n$$$ using exactly $$$m$$$ consecutive positive integers. Otherwise, output NO.You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as a positive answer).

Example
Input
1
18 3
Output
YES
Note

for the given testcase the three consecutive integers are: 5,6,7

E. Colorful Stamp
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A row of $$$n$$$ cells is given, all initially white. Using a stamp, you can stamp any two neighboring cells such that one becomes red and the other becomes blue. A stamp can be rotated, i.e. it can be used in both ways: as $$$\color{blue}{\texttt{B}}\color{red}{\texttt{R}}$$$ and as $$$\color{red}{\texttt{R}}\color{blue}{\texttt{B}}$$$.

During use, the stamp must completely fit on the given $$$n$$$ cells (it cannot be partially outside the cells). The stamp can be applied multiple times to the same cell. Each usage of the stamp recolors both cells that are under the stamp.

For example, one possible sequence of stamps to make the picture $$$\color{blue}{\texttt{B}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\color{blue}{\texttt{B}}\texttt{W}$$$ could be $$$\texttt{WWWWW} \to \texttt{WW}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\texttt{W} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\texttt{W} \to \color{blue}{\texttt{B}}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}}\texttt{W}$$$. Here $$$\texttt{W}$$$, $$$\color{red}{\texttt{R}}$$$, and $$$\color{blue}{\texttt{B}}$$$ represent a white, red, or blue cell, respectively, and the cells that the stamp is used on are marked with an underline.

Given a final picture, is it possible to make it using the stamp zero or more times?

Input

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.

The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the picture.

The second line of each test case contains a string $$$s$$$ — the picture you need to make. It is guaranteed that the length of $$$s$$$ is $$$n$$$ and that $$$s$$$ only consists of the characters $$$\texttt{W}$$$, $$$\texttt{R}$$$, and $$$\texttt{B}$$$, representing a white, red, or blue cell, respectively.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if it possible to make the picture using the stamp zero or more times, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

Example
Input
12
5
BRBBW
1
B
2
WB
2
RW
3
BRB
3
RBB
7
WWWWWWW
9
RBWBWRRBW
10
BRBRBRBRRB
12
BBBRWWRRRWBR
10
BRBRBRBRBW
5
RBWBW
Output
YES
NO
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO
Note

The first test case is explained in the statement.

For the second, third, and fourth test cases, it is not possible to stamp a single cell, so the answer is "NO".

For the fifth test case, you can use the stamp as follows: $$$\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{blue}{\texttt{B}}$$$.

For the sixth test case, you can use the stamp as follows: $$$\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}}$$$.

For the seventh test case, you don't need to use the stamp at all.