"Guys!!! Omda is coming in 5 minutes" said the battle's organizer. Till then let us tell you some things about this contest:
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.
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)$$$.
For each test case, print "Yes" (without quotes and case insensitive) if there is a solution for the problem and "No" otherwise.
3 2 420 42
Yes No No
"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?
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$$$.
For each test case, print the minimum number of times Hanya needs to set a direction.
321 051 2 -10 -2 13-1 -1 -1
1 2 1
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.
"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.
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$$$.
For each test case, print the answer $$$P$$$ or $$$-1$$$ if there is no answer.
25 51 11 21 32 22 35 51 52 53 54 55 5
4 1 2 3 5 -1
"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 :
The one who removes all chips first wins. If Omda starts playing, can you figure out who will win this game?
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)$$$.
For each test case print "Omda" if Omda wins otherwise, print "Teemo".
2 10 20 2 2
Omda Omda
"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.
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$$$.
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.
1 5 0 0 100 0 0 100 100 100 49 50
0 0 0 0 1
"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.
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$$$.
For each test case, print one integer which is the answer for this problem.
2 abcabc abc cccccccc cc
3 2
"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:
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$$$?
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$$$.
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.
15 63 1 7 2 104 67 13 110 116 31 20
Yes No Yes No Yes No
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$$$.
"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.
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$$$.
For each query print one line the number of nodes $$$K$$$ where $$$dist(U, K) = dist(V, K)$$$.
1 7 2 1 2 1 3 2 4 2 5 3 6 3 7 4 7 1 7
1 2
"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?
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$$$
For each test case, print one integer which is the answer for this problem.
1 3 3 2 1 3 1 2 4 1 3 3 2
16
"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?
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})$$$.
For each test case, print Hobz's Salkan.
25 101 4 3 4 54 2 4 4 42 1112 1312 13
7 1
"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.
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$$$
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".
3 0 1 01
YES NO YES