Mark is asked to take a group photo of $$$2n$$$ people. The $$$i$$$-th person has height $$$h_i$$$ units.
To do so, he ordered these people into two rows, the front row and the back row, each consisting of $$$n$$$ people. However, to ensure that everyone is seen properly, the $$$j$$$-th person of the back row must be at least $$$x$$$ units taller than the $$$j$$$-th person of the front row for each $$$j$$$ between $$$1$$$ and $$$n$$$, inclusive.
Help Mark determine if this is possible.
The first line contains one integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. Each test case consists of two lines.
The first line of each test case contains two positive integers $$$n$$$ and $$$x$$$ ($$$1\leq n\leq 100$$$, $$$1\leq x\leq 10^3$$$) — the number of people in each row and the minimum difference Mark wants.
The second line of each test case contains $$$2n$$$ positive integers $$$h_1,h_2,\ldots,h_{2n}$$$ ($$$1\leq h_i\leq 10^3$$$) — the height of each person in units.
Note that the sum of $$$n$$$ over all test cases is not bounded.
For each test case, print a single line containing "YES" if Mark could arrange people satisfying his condition and "NO" otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answers).
33 61 3 9 10 12 163 12 5 2 2 2 51 28 6
YES NO YES
In the first test case, one possible order is to have the third, fifth, and sixth person on the back row and the second, first, and fourth on the front row. The heights of the people will look like this.
| Back | $$$9$$$ | $$$12$$$ | $$$16$$$ |
| Front | $$$3$$$ | $$$1$$$ | $$$10$$$ |
It works because
In the second test case, it can be shown there is no way to order people in a way that satisfies the condition.
In the third test case, the only way to arrange people to satisfy the condition is to have the first person on the back row and the second person on the front row.
Mark is cleaning a row of $$$n$$$ rooms. The $$$i$$$-th room has a nonnegative dust level $$$a_i$$$. He has a magical cleaning machine that can do the following three-step operation.
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 a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$) — the number of rooms.
The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0\leq a_i\leq 10^9$$$) — the dust level of each room.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print a line containing a single integer — the minimum number of operations. It can be proven that there is a sequence of operations that meets the goal.
432 0 050 2 0 2 062 0 3 0 4 640 0 0 10
3 5 11 0
In the first case, one possible sequence of operations is as follows.
In the second case, one possible sequence of operations is as follows.
In the last case, the array already satisfies the condition.
One night, Mark realized that there is an essay due tomorrow. He hasn't written anything yet, so Mark decided to randomly copy-paste substrings from the prompt to make the essay.
More formally, the prompt is a string $$$s$$$ of initial length $$$n$$$. Mark will perform the copy-pasting operation $$$c$$$ times. Each operation is described by two integers $$$l$$$ and $$$r$$$, which means that Mark will append letters $$$s_l s_{l+1} \ldots s_r$$$ to the end of string $$$s$$$. Note that the length of $$$s$$$ increases after this operation.
Of course, Mark needs to be able to see what has been written. After copying, Mark will ask $$$q$$$ queries: given an integer $$$k$$$, determine the $$$k$$$-th letter of the final string $$$s$$$.
The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 1000$$$) — the number of test cases.
The first line of each test case contains three integers $$$n$$$, $$$c$$$, and $$$q$$$ ($$$1\leq n\leq 2\cdot 10^5$$$, $$$1\leq c\leq 40$$$, and $$$1\leq q\leq 10^4$$$) — the length of the initial string $$$s$$$, the number of copy-pasting operations, and the number of queries, respectively.
The second line of each test case contains a single string $$$s$$$ of length $$$n$$$. It is guaranteed that $$$s$$$ only contains lowercase English letters.
The following $$$c$$$ lines describe the copy-pasting operation. Each line contains two integers $$$l$$$ and $$$r$$$ ($$$1\leq l\leq r\leq 10^{18}$$$). It is also guaranteed that $$$r$$$ does not exceed the current length of $$$s$$$.
The last $$$q$$$ lines of each test case describe the queries. Each line contains a single integer $$$k$$$ ($$$1\leq k\leq 10^{18}$$$). It is also guaranteed that $$$k$$$ does not exceed the final length of $$$s$$$.
It is guaranteed that the sum of $$$n$$$ and $$$q$$$ across all test cases does not exceed $$$2\cdot 10^5$$$ and $$$10^4$$$, respectively.
For each query, print the $$$k$$$-th letter of the final string $$$s$$$.
24 3 3mark1 45 73 8110127 3 3creamii2 33 42 991112
m a r e a r
In the first test case, the copy-paste process is as follows.
In the second test case, the copy-paste process is as follows.
Mark has just purchased a rack of $$$n$$$ lightbulbs. The state of the lightbulbs can be described with binary string $$$s = s_1s_2\dots s_n$$$, where $$$s_i=\texttt{1}$$$ means that the $$$i$$$-th lightbulb is turned on, while $$$s_i=\texttt{0}$$$ means that the $$$i$$$-th lightbulb is turned off.
Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following:
Mark wants the state of the lightbulbs to be another binary string $$$t$$$. Help Mark determine the minimum number of operations to do so.
The first line of the input contains a single integer $$$q$$$ ($$$1\leq q\leq 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$3\leq n\leq 2\cdot 10^5$$$) — the number of lightbulbs.
The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ — the initial state of the lightbulbs.
The third line of each test case contains a binary string $$$t$$$ of length $$$n$$$ — the final state of the lightbulbs.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $$$s$$$ to $$$t$$$. If there is no such sequence of operations, print $$$-1$$$.
4401000010410100100501001000116000101010011
2 -1 -1 5
In the first test case, one sequence of operations that achieves the minimum number of operations is the following.
In the third test case, even though the first digits of $$$s$$$ and $$$t$$$ are the same and the last digits of $$$s$$$ and $$$t$$$ are the same, it can be shown that there is no sequence of operations that satisfies the condition.
In the fourth test case, one sequence that achieves the minimum number of operations is the following:
After watching a certain anime before going to sleep, Mark dreams of standing in an old classroom with a blackboard that has a sequence of $$$n$$$ positive integers $$$a_1, a_2,\dots,a_n$$$ on it.
Then, professor Koro comes in. He can perform the following operation:
Professor Koro then asks Mark the question, "what is the maximum possible number that could appear on the board after some operations?"
Mark quickly solves this question, but he is still slower than professor Koro. Thus, professor Koro decides to give Mark additional challenges. He will update the initial sequence of integers $$$q$$$ times. Each time, he will choose positive integers $$$k$$$ and $$$l$$$, then change $$$a_k$$$ to $$$l$$$. After each update, he will ask Mark the same question again.
Help Mark answer these questions faster than Professor Koro!
Note that the updates are persistent. Changes made to the sequence $$$a$$$ will apply when processing future updates.
The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$2\leq n\leq 2\cdot 10^5$$$, $$$1\leq q\leq 2\cdot 10^5$$$) — the length of the sequence $$$a$$$ and the number of updates, respectively.
The second line contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$1\leq a_i\leq 2\cdot 10^5$$$)
Then, $$$q$$$ lines follow, each consisting of two integers $$$k$$$ and $$$l$$$ ($$$1\leq k\leq n$$$, $$$1\leq l\leq 2\cdot 10^5$$$), telling to update $$$a_k$$$ to $$$l$$$.
Print $$$q$$$ lines. The $$$i$$$-th line should consist of a single integer — the answer after the $$$i$$$-th update.
5 4 2 2 2 4 5 2 3 5 3 4 1 1 4
6 5 4 5
2 1 200000 1 2 200000
200001
In the first example test, the program must proceed through $$$4$$$ updates.
The sequence after the first update is $$$[2,3,2,4,5]$$$. One sequence of operations that achieves the number $$$6$$$ the following.
Then, in the second update, the array is changed to $$$[2,3,2,4,3]$$$. This time, Mark cannot achieve $$$6$$$. However, one sequence that Mark can use to achieve $$$5$$$ is shown below.
In the third update, the array is changed to $$$[2,3,2,1,3]$$$. One way to achieve $$$4$$$ is shown below.
Mark is administering an online exam consisting of $$$n$$$ true-false questions. However, he has lost all answer keys. He needs a way to retrieve the answers before his client gets infuriated.
Fortunately, he has access to the grading system. Thus, for each query, you can input the answers to all $$$n$$$ questions, and the grading system will output how many of them are correct.
He doesn't have much time, so he can use the grading system at most $$$675$$$ times. Help Mark determine the answer keys.
Note that answer keys are fixed in advance and will not change depending on your queries.
The first line of the input consists of an integer $$$n$$$ ($$$1\leq n\leq 1000$$$) — the number of questions.
After reading $$$n$$$, you can start making queries to the grading system. For each query, print a line containing a string $$$s$$$ of length $$$n$$$ consisting of only letters 'T' and 'F'.
After a successful query, you should read an integer $$$k$$$ ($$$0\leq k\leq n$$$) — the number of correct answers. If you read $$$n$$$, then you found the answers, and your program should not make any more queries.
If your program reads $$$k = -1$$$ instead of the number of correct answers, it means that you either made an invalid query or exceeded the query limits. Exit immediately after receiving $$$-1$$$, and you will see Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
Hacks
To hack, use the following format:
The first line contains an integer $$$n$$$ ($$$1\leq n\leq 1000$$$) — the number of questions.
The second line contains a string $$$s$$$ of length $$$n$$$ consisting of only 'T' and 'F' — the answer key.
3 1 3
FTT TTF
4 0 3 4
FTFF TTTT TFTT
The empty lines in the example are just for you to better understand the interaction process. You're not required to print them.
In the first example, there are $$$3$$$ questions, and the answer to each question is 'true', 'true', and 'false', respectively.
In the second example, there are $$$4$$$ questions, and the answer to each question is 'true', 'false', 'true', and 'true', respectively.