Summer Trainings | Week 0
A. Stair, Peak, or Neither?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given three digits $$$a$$$, $$$b$$$, and $$$c$$$. Determine whether they form a stair, a peak, or neither.

  • A stair satisfies the condition $$$a \lt b \lt c$$$.
  • A peak satisfies the condition $$$a \lt b \gt c$$$.
Input

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

The only line of each test case contains three digits $$$a$$$, $$$b$$$, $$$c$$$ ($$$0 \leq a$$$, $$$b$$$, $$$c \leq 9$$$).

Output

For each test case, output "STAIR" if the digits form a stair, "PEAK" if the digits form a peak, and "NONE" otherwise (output the strings without quotes).

Example
Input
7
1 2 3
3 2 1
1 5 3
3 4 1
0 0 0
4 1 7
4 5 7
Output
STAIR
NONE
PEAK
PEAK
NONE
NONE
STAIR

B. Vlad and the Best of Five
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vladislav has a string of length $$$5$$$, whose characters are each either $$$\texttt{A}$$$ or $$$\texttt{B}$$$.

Which letter appears most frequently: $$$\texttt{A}$$$ or $$$\texttt{B}$$$?

Input

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

The only line of each test case contains a string of length $$$5$$$ consisting of letters $$$\texttt{A}$$$ and $$$\texttt{B}$$$.

All $$$t$$$ strings in a test are different (distinct).

Output

For each test case, output one letter ($$$\texttt{A}$$$ or $$$\texttt{B}$$$) denoting the character that appears most frequently in the string.

Example
Input
8
ABABB
ABABA
BBBAB
AAAAA
BBBBB
BABAA
AAAAB
BAAAA
Output
B
A
B
A
B
A
A
A

C. Increasing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array $$$a$$$ of $$$n$$$ positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that $$$a_1 \lt a_2 \lt \dots \lt a_n$$$ holds.

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the length of the array.

The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.

Output

For each test case, output "YES" (without quotes) if the array satisfies the condition, and "NO" (without quotes) 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
3
4
1 1 1 1
5
8 7 1 3 4
1
5
Output
NO
YES
YES
Note

In the first test case any rearrangement will keep the array $$$[1,1,1,1]$$$, which is not strictly increasing.

In the second test case, you can make the array $$$[1,3,4,7,8]$$$.

D. Word Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows:

  • if a word was written by one person — that person gets 3 points,
  • if a word was written by two people — each of the two gets 1 point,
  • if a word was written by all — nobody gets any points.
In the end, how many points does each player have?
Input

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person.

The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.

Output

For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.

Example
Input
3
1
abc
def
abc
3
orz for qaq
qaq orz for
cod for ces
5
iat roc hem ica lly
bac ter iol ogi sts
bac roc lly iol iat
Output
1 3 1 
2 2 6 
9 11 5 
Note

In the first test case:

  • The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point.
  • The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.

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.

F. Long Multiplication
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two integers $$$x$$$ and $$$y$$$ of the same length, consisting of digits from $$$1$$$ to $$$9$$$.

You can perform the following operation any number of times (possibly zero): swap the $$$i$$$-th digit in $$$x$$$ and the $$$i$$$-th digit in $$$y$$$.

For example, if $$$x=73$$$ and $$$y=31$$$, you can swap the $$$2$$$-nd digits and get $$$x=71$$$ and $$$y=33$$$.

Your task is to maximize the product of $$$x$$$ and $$$y$$$ using the aforementioned operation any number of times. If there are multiple answers, print any of them.

Input

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

The first line of each test case contains a single integer $$$x$$$ ($$$1 \le x \lt 10^{100}$$$).

The second line of each test case contains a single integer $$$y$$$ ($$$1 \le y \lt 10^{100}$$$).

Additional constraint on input: the integers $$$x$$$ and $$$y$$$ consist only of digits from $$$1$$$ to $$$9$$$.

Output

For each test case, print two lines — the first line should contain the number $$$x$$$ after performing the operations; similarly, the second line should contain the number $$$y$$$ after performing the operations. If there are multiple answers, print any of them.

Example
Input
3
73
31
2
5
3516
3982
Output
71
33
5
2
3912
3586

G. Tiles Comeback
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vlad remembered that he had a series of $$$n$$$ tiles and a number $$$k$$$. The tiles were numbered from left to right, and the $$$i$$$-th tile had colour $$$c_i$$$.

If you stand on the first tile and start jumping any number of tiles right, you can get a path of length $$$p$$$. The length of the path is the number of tiles you stood on.

Vlad wants to see if it is possible to get a path of length $$$p$$$ such that:

  • it ends at tile with index $$$n$$$;
  • $$$p$$$ is divisible by $$$k$$$
  • the path is divided into blocks of length exactly $$$k$$$ each;
  • tiles in each block have the same colour, the colors in adjacent blocks are not necessarily different.

For example, let $$$n = 14$$$, $$$k = 3$$$.

The colours of the tiles are contained in the array $$$c$$$ = [$$$\color{red}{1}, \color{violet}{2}, \color{red}{1}, \color{red}{1}, \color{gray}{7}, \color{orange}{5}, \color{green}{3}, \color{green}{3}, \color{red}{1}, \color{green}{3}, \color{blue}{4}, \color{blue}{4}, \color{violet}{2}, \color{blue}{4}$$$]. Then we can construct a path of length $$$6$$$ consisting of $$$2$$$ blocks:

$$$\color{red}{c_1} \rightarrow \color{red}{c_3} \rightarrow \color{red}{c_4} \rightarrow \color{blue}{c_{11}} \rightarrow \color{blue}{c_{12}} \rightarrow \color{blue}{c_{14}}$$$

All tiles from the $$$1$$$-st block will have colour $$$\color{red}{\textbf{1}}$$$, from the $$$2$$$-nd block will have colour $$$\color{blue}{\textbf{4}}$$$.

It is also possible to construct a path of length $$$9$$$ in this example, in which all tiles from the $$$1$$$-st block will have colour $$$\color{red}{\textbf{1}}$$$, from the $$$2$$$-nd block will have colour $$$\color{green}{\textbf{3}}$$$, and from the $$$3$$$-rd block will have colour $$$\color{blue}{\textbf{4}}$$$.

Input

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$)—the number of tiles in the series and the length of the block.

The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, c_3, \dots, c_n$$$ ($$$1 \le c_i \le n$$$) — the colours of the tiles.

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

Output

For each test case, output on a separate line:

  • YES if you can get a path that satisfies these conditions;
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).

Example
Input
10
4 2
1 1 1 1
14 3
1 2 1 1 7 5 3 3 1 3 4 4 2 4
3 3
3 1 3
10 4
1 2 1 2 1 2 1 2 1 2
6 2
1 3 4 1 6 6
2 2
1 1
4 2
2 1 1 1
2 1
1 2
3 2
2 2 2
4 1
1 1 2 2
Output
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
Note

In the first test case, you can jump from the first tile to the last tile;

The second test case is explained in the problem statement.

H. Binary Deque
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Slavic has an array of length $$$n$$$ consisting only of zeroes and ones. In one operation, he removes either the first or the last element of the array.

What is the minimum number of operations Slavic has to perform such that the total sum of the array is equal to $$$s$$$ after performing all the operations? In case the sum $$$s$$$ can't be obtained after any amount of operations, you should output -1.

Input

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

The first line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \leq n, s \leq 2 \cdot 10^5$$$) — the length of the array and the needed sum of elements.

The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$0 \leq a_i \leq 1$$$) — the elements of the array.

It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Output

For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to $$$s$$$, or -1 if obtaining an array with sum $$$s$$$ isn't possible.

Example
Input
7
3 1
1 0 0
3 1
1 1 0
9 3
0 1 0 1 1 1 0 0 1
6 4
1 1 1 1 1 1
5 1
0 0 1 1 0
16 2
1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1
6 3
1 0 1 0 0 0
Output
0
1
3
2
2
7
-1
Note

In the first test case, the sum of the whole array is $$$1$$$ from the beginning, so we don't have to make any operations.

In the second test case, the sum of the array is $$$2$$$ and we want it to be equal to $$$1$$$, so we should remove the first element. The array turns into $$$[1, 0]$$$, which has a sum equal to $$$1$$$.

In the third test case, the sum of the array is $$$5$$$ and we need it to be $$$3$$$. We can obtain such a sum by removing the first two elements and the last element, doing a total of three operations. The array turns into $$$[0, 1, 1, 1, 0, 0]$$$, which has a sum equal to $$$3$$$.