JCPC 2022
A. Round 1
time limit per test
1 second
memory limit per test
256 megabytes
input
Round1.in
output
standard output

"Guys!!! Omda is coming in 5 minutes" said the battle's organizer. Till then let us tell you some things about this contest:

  • First, This contest has only one setter who came up with all the problems.
  • Second, This contest's theme is Nesr El Scene.
  • Third, If you don't enjoy this contest we hope you at least enjoy the jokes.
  • The fourth was scored by Origi.
  • fifth fifth fifth fifth fifth.
  • The answer to this problem is "Yes" if there exists a string consisting of lowercase English letters of size $$$N$$$ (input) with no palindromic subsequences of size $$$2$$$ or more otherwise, the answer is "No".

A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 10^5)$$$.

The first line of each test case contains one integer $$$N$$$ $$$(1 \leq N \leq 10^9)$$$.

Output

For each test case, print "Yes" (without quotes and case insensitive) if there is a solution for the problem and "No" otherwise.

Example
Input
3
2
420
42
Output
Yes
No
No

B. I'll call him Hanya
time limit per test
1 second
memory limit per test
256 megabytes
input
hanya.in
output
standard output

"I'll call him Hanya" said Omda.

Omda in one of his amazing punchlines tried to call his opponent Hanya. However, It backfired because his aunt's name is Hanya and as we all know Omda's aunt is dead.

Hanya was a working aunt. She delivered packages to people everywhere. However, she didn't like to turn around a lot ... it hurts her back.

Let's represent the world as a number line. Initially, Hanya's on point $$$0$$$ with no direction set for her.

In one move, she can either set a direction or move in that direction (of course, the direction needs to be set first).

Given $$$N$$$ packages where the $$$i^{th}$$$ package needs to be delivered to point $$$A_{i}$$$, What's the minimum number of times Hanya needs to set a direction to deliver all packages in any order if Hanya can carry all packages at once?

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 10^5)$$$.

The first line of each test case contains one integer $$$N$$$ $$$(1 \leq N \leq 10^5)$$$.

The second line of each test case contains $$$N$$$ space-separated integers $$$A_{1},A_{2},\dots,A_{N}$$$ $$$(|A_i| \leq 10^9)$$$.

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

Output

For each test case, print the minimum number of times Hanya needs to set a direction.

Example
Input
3
2
1 0
5
1 2 -10 -2 1
3
-1 -1 -1
Output
1
2
1
Note

In the first test case, Hanya just sets the direction to the right and then goes to deliver the package at one, note that she's already at $$$0$$$ at the beginning.

C. Disney Land
time limit per test
3 seconds
memory limit per test
256 megabytes
input
disney.in
output
standard output

"I found Donald Duck, Micky Mouse, and Minnie Mouse. What are you doing? We're not in Disney Land" said Omda.

There was an invasion of Sasa's studio by Disney characters. Help us, God!!.

Moda wanted to find out the order in which the characters entered the studio so that, he could hunt them down.

Disney characters are represented by a permutation of $$$N$$$ integers.

A permutation is an array consisting of $$$N$$$ distinct integers from $$$1$$$ to $$$N$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$N=3$$$ but there is $$$4$$$ in the array)

Additionally, you are given $$$M$$$ restrictions. You want to recover the lexicographically smallest permutation under those restrictions or report that there isn't any valid permutation.

The $$$i^{th}$$$ restriction says that $$$P_{X_i} \neq Y_i$$$.

Please help Moda recover the permutation of Disney characters.

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 10^5)$$$.

The first line of each test case contains two integers $$$N$$$ and $$$M$$$ $$$(1 \leq N \leq 10^3)$$$ $$$(1 \leq M \leq 10^5)$$$.

The following $$$M$$$ lines of each test case contains two space-separated integers $$$X_i$$$ and $$$Y_i$$$ $$$(1 \leq X_i,Y_i \leq N)$$$

It is guaranteed that there is that for any $$$1 \leq i \le j \leq M$$$ either $$$X_i \neq X_j$$$ or $$$Y_i \neq Y_j$$$.

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

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

Output

For each test case, print the answer $$$P$$$ or $$$-1$$$ if there is no answer.

Example
Input
2
5 5
1 1
1 2
1 3
2 2
2 3

5 5
1 5
2 5
3 5
4 5
5 5
Output
4 1 2 3 5
-1

D. Do and Tak Game
time limit per test
1 second
memory limit per test
256 megabytes
input
dotak.in
output
standard output

"I was going with a "Do", but I think you guys are going for a "Tak"" said Teemo.

Teemo and Omda are playing Do and Tak Game.

The rules of Do and Tak are simple. Just stand in a circle and $$$\dots$$$ Oh wait wrong game.

Initially, We have $$$N \times K$$$ chips. A player can make one of two moves :

  • Use a Do, i.e remove $$$K$$$ chips. You can only use a Do if the current number of chips is $$$\ge K$$$
  • Use a Tak, i.e remove $$$1$$$ chip.

The one who removes all chips first wins. If Omda starts playing, can you figure out who will win this game?

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 10^5)$$$.

The only line of each test case contains two integers $$$N$$$ and $$$K$$$ $$$(1 \leq N, K \leq 10^5)$$$.

Output

For each test case print "Omda" if Omda wins otherwise, print "Teemo".

Example
Input
2
10 20
2 2
Output
Omda
Omda

E. I am not done yet
time limit per test
1 second
memory limit per test
256 megabytes
input
bedone.in
output
standard output

"I'm not done yet. I'm not done yet. I'm not done yet." said Omda.

We want Omda to be done with Battle rap.

Let's define the map as a 2D plane with $$$N$$$ integer points on it. These points are the positions of rappers.

For Omda to be done with Battle Rap he needs to choose one point and then defeat some number of rappers and remove their points from the map.

Omda becomes done with Battle rap when his point becomes a part of the plane's Convex Hull's perimeter.

You want Omda to be done. So you decided to calculate for each point the minimum number of rappers he needs to defeat, such that this point becomes a part of the plane's Convex Hull's perimeter.

A convex hull is a shape of the minimum area that contains all points on the plane.

Input

The first line of the input contains an integer $$$T$$$ – the number of test cases.

The first line of each test case contains one integer $$$N$$$$$$(3 \leq N \leq 10^3)$$$ – The number of points.

The follow $$$N$$$ lines, every line contains two integers $$$X$$$ and $$$Y$$$ $$$(-10^6 \leq X, Y \leq 10^6)$$$ – the points. No three points lie on one straight line.

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

Output

For each test case print $$$N$$$ lines, Every line contains one integer the minimum number of rappers he needs to defeat, such that this point becomes a part of the plane's Convex Hull's perimeter.

Example
Input
1
5
0 0
100 0
0 100
100 100
49 50
Output
0
0
0
0
1

F. Nesr El Sieve
time limit per test
1 second
memory limit per test
256 megabytes
input
sieve.in
output
standard output

"I graduated from Engineering Ain Shams University" - said Omda.

As we all know engineers are the third known gender in Egypt. As an engineer, Omda was trying to add a little engineering to his sick rhymes by getting the greatest common divisor of two rap tracks $$$A$$$ and $$$B$$$.

A rap track is a string consisting of lowercase English letters.

A divisor of a track $$$S$$$ is another $$$T$$$ such that $$$T$$$ can be concatenated some number of times to make $$$S$$$.

More formally $$$T$$$ is a divisor of $$$S$$$ if $$$T_1+T_2+T_3+\dots+T_{\frac{|S|}{|T|}} = S$$$ where $$$T_i = T_{i-1}$$$

The greater of the two divisors is the one with a bigger length.

Help Omda find the greatest common divisor of tracks $$$A$$$ and $$$B$$$.

It's guaranteed that there's always a solution.

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 10^5)$$$.

The first line of each test case contains a string $$$A$$$ $$$(1 \leq |A| \leq 10^3)$$$.

The second line of each test case contains a string $$$B$$$ $$$(1 \leq |B| \leq 10^3)$$$.

The total length of both strings over all testcases doesn't exceed $$$2 \cdot 10^3$$$.

Output

For each test case, print one integer which is the answer for this problem.

Example
Input
2
abcabc
abc
cccccccc
cc
Output
3
2

G. You're Milky
time limit per test
1 second
memory limit per test
256 megabytes
input
milk.in
output
standard output

"From your blood I drink, Milk" said Omda.

We all know that good rappers drink milk every day.

Omda was trying to walk on the beat same as he does every day.

Initially, Omda is standing on point $$$0$$$ on the beat. Each moment he'd do one of three operations:

  • Build the beat by using his rap skills and move from point $$$i$$$ to point $$$i+1$$$.
  • He gets some beats from the beat and moves from point $$$i$$$ to point $$$i-1$$$.
  • He stands at point $$$i$$$ drinking his milk.

Badran was taking pics of Omda while he was doing this greatness. So he took $$$N$$$ pics the $$$i-th$$$ pic Omda was standing at point $$$A_i$$$.

Badran will ask you $$$Q$$$ questions, each question is in the form of $$$U_i$$$ and $$$V_i$$$ and goes like this, Are you sure that Omda went to point $$$U_i$$$ and then went to point $$$V_i$$$?

More formally, according to the above rules are there some two points in time $$$A \leq B$$$ were at $$$A$$$ Omda was standing at $$$U_i$$$ and at $$$B$$$ Omda was standing at $$$V_i$$$?

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 10^5)$$$.

The first line of each test case contains two integers $$$N$$$ and $$$Q$$$ $$$(1 \leq N, Q \leq 10^5)$$$.

The second line of each test case contains $$$N$$$ space-separated integers $$$A_{1},A_{2},\dots,A_{N}$$$ $$$(0 \leq A_i \leq 10^9)$$$.

The following $$$Q$$$ lines of each test case contains two integers each $$$U_i, V_i$$$ $$$(0 \leq U_i, V_i \leq 10^9)$$$.

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

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

Output

For each query, print "Yes" (without quotes and case insensitive) if you're sure that Omda did go to $$$U_i$$$ at some point then to $$$V_i$$$ and "No" otherwise.

Example
Input
1
5 6
3 1 7 2 10
4 6
7 1
3 1
10 11
6 3
1 20
Output
Yes
No
Yes
No
Yes
No
Note

For the first query, Omda did go all the way up to $$$7$$$ so he'd have had to pass by $$$4$$$ to go to $$$6$$$.

For the second query, Omda did go all the way up to $$$7$$$ then to $$$2$$$ but we're not sure about $$$1$$$.

For the third query, Omda did go to $$$3$$$ and then to $$$1$$$.

H. Alexandria Library
time limit per test
4 seconds
memory limit per test
256 megabytes
input
library.in
output
standard output

"Tell him we're going to Alexandria Library today and tomorrow we go to Marwan" said Omda.

Omda is using his car to go to his fellow rappers in Cairo to make feats that will eventually become hits and show us his talent.

Cairo is a connected acyclic graph of $$$N$$$ nodes and $$$N - 1$$$ bidirectional unweighted edges, i.e a tree.

Omda wants to play a game with you.

Let's define $$$dist(X, Y)$$$ as the shortest distance between $$$X$$$ and $$$Y$$$

He's going to give him $$$Q$$$ queries each query consists of 2 nodes $$$U$$$ and $$$V$$$ and he wants you to find out the number of nodes $$$K$$$ where $$$dist(U, K) = dist(V, K)$$$.

The point of this query is to find out at the $$$i^{th}$$$ moment for those two nodes what common cities will people come from to kill listen to Omda's singing.

Input

The first line of the input contains an integer $$$T$$$ – the number of test cases.

The first line of each test case contains two integers $$$N$$$ and $$$Q$$$ $$$(1 \leq N, Q \leq 3 \cdot 10^5)$$$ – The number of Nodes and the number of queries.

The follow $$$N-1$$$ lines, every line contains two integers $$$U$$$ and $$$V$$$ $$$(1 \leq U, V \leq N)$$$ – the edges of the tree.

Then $$$Q$$$ lines every line contains a query, and every query contains two integers $$$U$$$ and $$$V$$$ $$$(1 \leq U, V \leq N)$$$.

It is guaranteed that the sum of $$$N$$$ and $$$Q$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output

For each query print one line the number of nodes $$$K$$$ where $$$dist(U, K) = dist(V, K)$$$.

Example
Input
1
7 2
1 2
1 3
2 4
2 5
3 6
3 7
4 7
1 7
Output
1
2

I. Wigz
time limit per test
6 seconds
memory limit per test
256 megabytes
input
wigz.in
output
standard output

"Wigz is here" said Badran.

Omda wants to make a feature with Wigz. However, Wigz has a condition for them to make a feat.

Omda needs to pick some Wigz for Wigz to wear.

Given a carton of Wigz represented by a grid of $$$N$$$ rows and $$$M$$$ columns where the Wig at row $$$i$$$ and column $$$j$$$ has a value $$$G_{i,j}$$$.

Omda has an integer $$$K$$$ he needs to choose a set of rows $$$R$$$ and a set of columns $$$C$$$ such that $$$|R| + |C| \leq K$$$ and $$$ \sum_{i \in R \space or \space j \in C} G_{i,j} $$$ is maximum.

Can you get help Omda to get the maximum sum for the above problem?

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 50)$$$.

The first line of each test case contains $$$3$$$ integers $$$N$$$, $$$M$$$, and $$$K$$$ $$$(1 \leq N \times M \leq 500) (1 \leq K \leq N+M)$$$.

Each of the next $$$N$$$ lines contains $$$M$$$ integers $$$A_{ij}(0 \leq A_{ij} \leq 1000)$$$.

It is guaranteed that the sum of $$$N \times M$$$ over all test cases doesn't exceed $$$500$$$

Output

For each test case, print one integer which is the answer for this problem.

Example
Input
1
3 3 2
1 3 1
2 4 1
3 3 2
Output
16

J. Two Faced Hobz
time limit per test
6 seconds
memory limit per test
256 megabytes
input
salkan.in
output
standard output

"There's no difference" said Hanz.

As we all know, Hobz is a hundred-faced person. Damn, With all these hundered-faced people I miss two-faced people.

However, thank god today we will only be dealing with $$$N$$$ two-faced copies of Hobz. The $$$i-th$$$ Hobz has value $$$A_i$$$ on the first face and value $$$B_i$$$ on the second face.

Now let's calculate their Salkan. Salkan is the Xor of values on their faces.

Now Hobz has a plan to deceive us. Because we all know he has $$$0$$$ Salkan. He will choose which face each of his copies will show so that their Salkan is maximum.

However, Hanz knows about Hobz's plan. So he decided to place a parameter $$$K$$$.

If Hobz's copies output Salkan $$$ \gt K$$$ Hanz will be sure that Hobz is playing them. Then Hobz's Salkan Becomes $$$0$$$.

Do you know what value Hobz will print if he wants his Salkan to be maximum?

Input

The first line contains the number of test cases $$$T$$$ $$$(1 \leq T \leq 10)$$$.

The first line of each test case contains two integers $$$N$$$ and $$$K$$$ $$$(1 \leq N \leq 10^5) (0 \leq K \lt 2^{30})$$$.

The second line of each test case contains $$$N$$$ space-separated integers $$$A_{1},A_{2},\dots,A_{N}$$$ $$$(0 \leq A_i \lt 2^{30})$$$.

The third line of each test case contains $$$N$$$ space-separated integers $$$B_{1},B_{2},\dots,B_{N}$$$ $$$(0 \leq B_i \lt 2^{30})$$$.

Output

For each test case, print Hobz's Salkan.

Example
Input
2
5 10
1 4 3 4 5
4 2 4 4 4
2 11
12 13
12 13
Output
7
1

K. Hobz is a good guy
time limit per test
1 second
memory limit per test
256 megabytes
input
hobz.in
output
standard output

"I swear to god if what I am thinking is true. I will $$$010101010100011$$$ And $$$01010100001111$$$" said Modda.

Modda can rap in binary. As we all know to rap in binary the string must be non-empty and have the number of ones in even positions equal to the number of ones in odd positions.

Now Modda asks you if you can remove some number of characters from the given binary string $$$S$$$ so that you can use it in rap.

If I were you, I'd answer his question quickly. You don't want to know what happened to Hobz.

Input

The first line contains one integer $$$T$$$ $$$(1 \leq T \leq 10^{5})$$$ — the number of test cases.

The only line of each testcase contains a binary string.

The total length of the sequences over all testcases doesn't exceed $$$2$$$ $$$*$$$ $$$10^5$$$

Output

For each test case, print "Yes" if you can remove some number of characters from the given binary string $$$S$$$ so that you can use it in rap. Otherwise, print "No".

Example
Input
3
0
1
01
Output
YES
NO
YES