Codeforces Round 1066 (Div. 1 + Div. 2)
A. Dungeon Equilibrium
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An array is called balanced if every integer $$$x$$$ that occurs at least once, occurs exactly $$$x$$$ times in the array. For example, $$$[1, 4, 2, 4, 4, 4, 2]$$$ is balanced, but $$$[2]$$$ and $$$[2, 2, 2]$$$ are not.

You are given an array $$$a$$$ of $$$n$$$ elements, $$$[a_1, a_2, \ldots, a_n]$$$. The array may not be balanced currently, and you can delete some elements to make it balanced. What is the minimum number of elements you need to delete to make the array balanced?

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows.

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

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq n$$$) — the elements of the array $$$a$$$.

Note that there are no constraints on the sum of $$$n$$$ over all test cases.

Output

For each test case, output a single line containing an integer: the minimum number of elements you should remove from the array to make it balanced.

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

In the first test case, the given array is already balanced.

In the second test case, we can delete one occurrence of $$$1$$$ and one occurrence of $$$3$$$ to get the array $$$[1, 2, 2]$$$ which is balanced.

B. Expansion Plan 2
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are analyzing an infinite grid with coordinates $$$(X, Y)$$$ (specifically, the cell immediately above $$$(0, 0)$$$ is $$$(0, 1)$$$, and the cell immediately on the right of $$$(0, 0)$$$ is $$$(1, 0)$$$). Initially, only the cell at $$$(0, 0)$$$ is black.

You are given a string $$$a_1a_2 \ldots a_n$$$ of length $$$n$$$ consisting of characters $$$\texttt{"4"}$$$ and $$$\texttt{"8"}$$$, which describes $$$n$$$ expansion operations. For each $$$i$$$ from $$$1$$$ to $$$n$$$, the following happens for all cells simultaneously:

  • if $$$s_i = \texttt{"4"}$$$: for each cell, if it is orthogonally adjacent to a black cell (i.e., it shares a side), it becomes black; otherwise, its state remains the same;
  • if $$$s_i = \texttt{"8"}$$$: for each cell, if it is orthogonally or diagonally adjacent to a black cell (i.e, it shares a side or a corner), it becomes black; otherwise, its state remains the same.

Is the cell $$$(x, y)$$$ black at the end of the process?

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.

The first line of each test case contains three integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5, -10^9 \le x, y \le 10^9$$$) — the number of expansion operations, and the $$$x$$$ and $$$y$$$ coordinates of the cell you are interested in, respectively.

The second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting of characters $$$\texttt{"4"}$$$ and $$$\texttt{"8"}$$$ — the types of expansion operations.

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 $$$\texttt{YES}$$$ if the cell $$$(x, y)$$$ is black after the expansion operations described by the string $$$s$$$, and $$$\texttt{NO}$$$ otherwise.

The judge is case-insensitive (for example, $$$\texttt{YES}$$$, $$$\texttt{Yes}$$$, $$$\texttt{yes}$$$, $$$\texttt{yEs}$$$ will all be recognized as positive answers).

Example
Input
6
3 3 3
888
4 5 1
4884
4 3 -3
4884
7 -7 -5
4884884
10 0 0
4884884888
1 1 1
4
Output
YES
NO
YES
NO
YES
NO
Note

The first three test cases are illustrated below:

In the first test case, after the expansion operations in the string $$$\texttt{"888"}$$$, cell $$$(3, 3)$$$ is black, so the answer is $$$\texttt{YES}$$$.

In the second test case, cell $$$(5, 1)$$$ is white after the expansion operations in the string $$$\texttt{"4884"}$$$.

C. Meximum Array 2
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given three positive integers $$$n$$$, $$$k$$$, and $$$q$$$. You are also given $$$q$$$ tuples $$$(c, l, r)$$$, with $$$1 \leq c \leq 2$$$ and $$$1 \leq l \leq r \leq n$$$.

An array $$$a_1, a_2, \ldots, a_n$$$ is meximum if $$$0 \leq a_i \leq 10^9$$$ for each $$$i$$$ in $$$[1, n]$$$, and for each given tuple $$$(c, l, r)$$$,

  • if $$$c = 1$$$, then $$$\min(a_l, a_{l+1}, \ldots, a_r) = k$$$;
  • if $$$c = 2$$$, then $$$\operatorname{MEX}$$$$$$^{\text{∗}}$$$$$$(a_l, a_{l+1}, \ldots, a_r) = k$$$.

Note that the parameter $$$k$$$ is the same for all the conditions.

Find a meximum array $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$. The input is generated in such a way that a valid array always exists. If there are multiple possible arrays, you can print any one of them.

$$$^{\text{∗}}$$$The minimum excluded (MEX) of a collection of integers $$$a_1, a_2, \ldots, a_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$a$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows.

The first line of each test case contains three integers $$$n$$$, $$$k$$$, $$$q$$$ ($$$1 \leq k \leq n \leq 100$$$, $$$1 \leq q \leq 100$$$) — the length of the array $$$a_1, a_2, \ldots, a_n$$$, the result of the $$$\min$$$ and $$$\operatorname{MEX}$$$ calculations described by the tuples, and the number of tuples.

Then, $$$q$$$ lines follow. The $$$i$$$-th line contains a tuple $$$(c, l, r)$$$, which gives a constraint to $$$a_l, a_{l+1}, \ldots, a_r$$$ according to the statement.

It is guaranteed that there exists a valid array corresponding to the given input.

Note that there are no constraints on the sum of $$$n$$$, $$$k$$$, or $$$q$$$ over all test cases.

Output

For each test case, print a single line containing a meximum array $$$a_1, a_2, \ldots, a_n$$$.

Example
Input
4
6 2 2
1 1 3
2 2 6
3 3 1
2 1 3
3 3 2
1 1 1
1 3 3
3 2 2
2 1 2
2 2 3
Output
2 5 4 3 0 1
2 0 1
3 3 3
1 0 1
Note

In the first test case, you have to build a meximum array with $$$n = 6$$$, $$$k = 2$$$ and with $$$q = 2$$$ constraints given by tuples.

  • tuple $$$(1, 1, 3)$$$: $$$\min(a_1, a_2, a_3)$$$ must be $$$2$$$;
  • tuple $$$(2, 2, 6)$$$: $$$\operatorname{MEX}(a_2, a_3, a_4, a_5, a_6)$$$ must be $$$2$$$.

A possible array that satisfies all these constraints, and has elements $$$0 \leq a_i \leq 10^9$$$, is $$$[2, 5, 4, 3, 0, 1]$$$.

In the second test case, you have to build a meximum array with $$$n = 3$$$, $$$k = 3$$$ and with $$$q = 1$$$ constraint given by a tuple.

  • tuple $$$(2, 1, 3)$$$: $$$\operatorname{MEX}(a_1, a_2, a_3)$$$ must be $$$3$$$.

A possible array that satisfies this constraint, and has elements $$$0 \leq a_i \leq 10^9$$$, is $$$[2, 0, 1]$$$.

D. Billion Players Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are following the world championship of the Billion Players Game. There are $$$10^9$$$ players competing, and you want to predict the final ranking $$$p$$$ of Godflex, your favorite streamer. After analyzing recent matches, you are sure that $$$l \leq p \leq r$$$, but you don't know anything else.

There are $$$n$$$ offers made by the in-game bookmaker. In the $$$i$$$-th offer, the bookmaker suggests an estimation $$$a_i$$$ for Godflex's final ranking. For each offer, you must choose exactly one of the following actions:

  • Ignore the offer.
  • Accept the offer by claiming that $$$p \leq a_i$$$. If you are right, you earn $$$|p-a_i|$$$ robocoins; otherwise you lose $$$|p-a_i|$$$ robocoins.
  • Accept the offer by claiming that $$$p \geq a_i$$$. If you are right, you earn $$$|p-a_i|$$$ robocoins; otherwise you lose $$$|p-a_i|$$$ robocoins.

After you decide how to deal with all the offers, the actual Billion Players Game is played. Godflex gets a position $$$p$$$ in $$$[l, r]$$$, and then all the offers are settled up.

Your total score is the number of robocoins you are guaranteed to earn, that is, the minimum number of robocoins you earn over all possible values of $$$p$$$ in $$$[l, r]$$$. Find the maximum possible score you can guarantee.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.

The first line of each test case contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq l \leq r \leq 10^9$$$) — the number of offers and the possible range of Godflex's final ranking.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the bookmaker's estimations of Godflex's ranking in each offer.

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 a single line containing an integer: the maximum possible score you can guarantee.

Example
Input
4
1 1 5
3
2 100 100
50 200
5 1 10
5 7 3 9 1
5 6 10
9 3 1 7 5
Output
0
150
12
13
Note

In the first test case, there is only one offer.

  • If you ignore the offer, your score is $$$0$$$;
  • if you accept the offer claiming that $$$p \leq 3$$$, your score is $$$-2$$$ (reached when $$$p = 5$$$, which makes you lose $$$|5-3| = 2$$$ robocoins);
  • if you accept the offer claiming that $$$p \geq 3$$$, your score is $$$-2$$$ (reached when $$$p = 1$$$, which makes you lose $$$|1-3| = 2$$$ robocoins).

So the maximum possible score is $$$0$$$.

In the second test case, it is optimal to accept the offers claiming that $$$p \geq 50$$$ and $$$p \leq 200$$$. Since $$$p$$$ must be $$$100$$$, you gain $$$|100-50| + |100-200| = 150$$$ robocoins.

E. Adjusting Drones
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are managing a fleet of $$$n$$$ drones, each with an energy level $$$a_1, \ldots, a_n$$$. You are also given a positive integer $$$k$$$, which represents the maximum number of drones allowed to share the same energy level.

To prevent overloads, the drones automatically perform energy balancing operations as follows. While there exists an energy level that appears strictly more than $$$k$$$ times, they execute the following steps:

  • first, every drone $$$i$$$ whose energy $$$a_i$$$ appears earlier (that is, there exists $$$j \lt i$$$ with $$$a_j = a_i$$$) is marked;
  • then, for each marked drone, its energy is increased by $$$1$$$ unit;
  • then, the marks are removed.

The process stops once no energy level appears more than $$$k$$$ times. Determine how many energy balancing operations will be performed.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq k \leq n \leq 2 \cdot 10^5$$$) — the number of drones and the maximum allowed number of drones with the same energy level.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2n$$$) — the initial energy levels of the drones.

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 a single line containing an integer: the number of energy balancing operations performed.

Example
Input
5
6 3
1 1 1 1 1 1
5 1
1 3 2 1 4
6 2
1 1 1 2 3 3
4 1
8 8 8 8
2 2
1 2
Output
3
4
4
3
0
Note

In the first test case, the drones' energy levels evolve as follows:

  • at the beginning, $$$[1, 1, 1, 1, 1, 1]$$$;
  • after $$$1$$$ operation, $$$[1, 2, 2, 2, 2, 2]$$$;
  • after $$$2$$$ operations, $$$[1, 2, 3, 3, 3, 3]$$$;
  • after $$$3$$$ operations, $$$[1, 2, 3, 4, 4, 4]$$$.

After $$$3$$$ operations, every energy level appears at most $$$3$$$ times, so the process stops.

In the second test case, the energy levels change as follows: $$$[1, 3, 2, 1, 4] \rightarrow [1, 3, 2, 2, 4] \rightarrow [1, 3, 2, 3, 4] \rightarrow [1, 3, 2, 4, 4] \rightarrow [1, 3, 2, 4, 5]$$$. The process stops after $$$4$$$ operations.

F. Git Gud
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are an adventurer working for the futuristic corporation RoboCorp. Your current skill level is an integer $$$s$$$ in the range $$$[1, n]$$$, but you don't know its exact value. Your goal is to reach skill $$$\geq n$$$ by completing missions for RoboCorp, but each mission costs precious robocoins.

You can choose missions of any difficulty and any positive integer duration (in hours). However, the cost depends both on the new mission's length, and on how the new mission's difficulty compares to your most recent one.

Let $$$x$$$ be the difficulty of your most recent mission. If you want to undertake a new mission of difficulty $$$y$$$ and duration $$$l$$$:

  • If it is your first mission, or $$$y \leq x$$$, the cost is $$$l$$$ robocoins.
  • If $$$y \gt x$$$, the cost is $$$1000 + l$$$ robocoins.

Your skill improves only when you take on a mission whose difficulty exactly matches your current skill:

  • If $$$y = s$$$, then your skill increases by $$$l$$$.
  • Otherwise, your skill does not change.

After each mission, you still don't know your actual skill value.

You start with $$$10^6$$$ robocoins. Find a strategy (a sequence of missions) that does not exceed your budget and guarantees your skill becomes at least $$$n$$$, no matter what your initial skill was.

Input

The input contains a single line with an integer $$$n$$$ ($$$n = 4$$$ or $$$n = 250\,000$$$) — the target skill level (that is, by the end, your skill must be $$$\geq n$$$).

There are exactly $$$2$$$ tests in this problem (including the example). The example has $$$n = 4$$$, and the other test has $$$n = 250\,000$$$.

Hacks are not allowed in this problem.

Output

In the first line, print a single integer $$$k$$$ ($$$0 \leq k \leq 10^6$$$) — the number of missions you plan to complete.

Then, print $$$k$$$ lines. The $$$i$$$-th line must contain two integers $$$y$$$ and $$$l$$$ ($$$1 \leq y, l \leq 10^6$$$) — the difficulty and duration (in hours) of the $$$i$$$-th mission, respectively.

Example
Input
4
Output
4
1 4
3 1
2 1
3 1
Note

In the example, your target skill is $$$n = 4$$$. You can use the following strategy:

  • Take a mission of difficulty $$$y = 1$$$ and duration $$$l = 4$$$. It's your first mission, so you pay $$$l = 4$$$ robocoins.
  • Take a mission of difficulty $$$y = 3$$$ and duration $$$l = 1$$$. The previous mission had difficulty $$$x = 1$$$, so since $$$y \gt x$$$, you pay $$$l + 1000 = 1001$$$ robocoins.
  • Take a mission of difficulty $$$y = 2$$$ and duration $$$l = 1$$$. Now $$$x = 3$$$, and since $$$y \leq x$$$, you pay $$$l = 1$$$ robocoin.
  • Take a mission of difficulty $$$y = 3$$$ and duration $$$l = 1$$$. Now $$$x = 2$$$, and since $$$y \gt x$$$, you pay $$$l + 1000 = 1001$$$ robocoins.

In total, you spend $$$2007$$$ robocoins, which is within your $$$10^6$$$-robocoin budget.

Now we verify that this strategy always works:

  • If your initial skill was $$$1$$$, after the first mission it becomes $$$5$$$.
  • If your initial skill was $$$2$$$, after the third mission it becomes $$$3$$$, and after the fourth mission it becomes $$$4$$$.
  • If your initial skill was $$$3$$$, after the second mission it becomes $$$4$$$.
  • If your initial skill was $$$4$$$, it stays $$$4$$$.

So no matter what your starting skill is, you end with skill $$$\geq n$$$.

G. Isaac's Queries
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have reached the final level of the popular roguelike game "Isaac's Keybindings". Instead of a boss, you encounter a shopkeeper who holds an hidden array of integers $$$a_1, a_2, \ldots, a_n$$$, where $$$0 \leq a_i \lt 2^{30}$$$ for each $$$i$$$ in $$$[1, n]$$$.

It is guaranteed that the array is generated randomly, i.e., each $$$a_i$$$ ($$$1 \leq i \leq n$$$) is an integer independently generated uniformly at random in $$$[0, 2^{30})$$$, in all the tests excluding the example.

Let $$$f(u, v) = a_u \oplus a_{u+1} \oplus \ldots \oplus a_v$$$, where $$$\oplus$$$ is the bitwise $$$\texttt{XOR}$$$.

You can ask queries of the following form: $$$\texttt{? u v}$$$, with $$$1 \leq u \leq v \leq n$$$.

The answer to the query is:

  • $$$-1$$$, if $$$f(u, v) = 0$$$;
  • $$$\lfloor \log_2(f(u, v)) \rfloor$$$ otherwise.

Each query has a cost of $$$\frac{1}{v-u+1}$$$ robocoins. On each test, you are given $$$300$$$ robocoins in total to pass at most $$$30$$$ test cases (that is, you can spend $$$10$$$ robocoins on average for a single test case). If your balance ever becomes negative you lose. Note that your robocoin balance does not need to be an integer at any moment.

Find the answer to all possible $$$\frac{n(n+1)}{2}$$$ queries without losing.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 30$$$). The description of the test cases follows.

The first line of each test case contains one integer $$$n$$$ ($$$n = 3$$$ or $$$n = 100$$$) — the length of the array $$$a_1, a_2, \ldots, a_n$$$. It is guaranteed that the array is generated randomly in all the tests excluding the example.

There are exactly $$$50$$$ tests in this problem (including the example). The example has $$$t = 1$$$ and $$$n = 3$$$, and all the other tests have $$$t = 30$$$ and $$$n = 100$$$.

Hacks are not allowed in this problem.

Interaction

For each test case, first read a single integer $$$n$$$. If the integer you read is $$$-2$$$, it means that the answer to the previous test case was wrong, and you should exit immediately.

To ask a query, print a line in the format $$$\texttt{? u v}$$$ with $$$1 \leq u \leq v \leq n$$$.

As a response to the query, you will receive $$$-2$$$ if you made an invalid query (i.e., the format is invalid, or you would reach a negative amount of robocoins). In that case, you should exit immediately. Otherwise, you will receive the answer to the query.

When you determine the answers to all the $$$\frac{n(n+1)}{2}$$$ queries, print them in the following format.

Print $$$n+1$$$ lines. The first line must contain a single character $$$\texttt{!}$$$. The $$$i$$$-th of the next $$$n$$$ lines must contain $$$n-i+1$$$ integers: the answers to queries $$$\texttt{? i i}, \, \texttt{? i i+1}, \,\ldots, \, \texttt{? i n}$$$, respectively.

After printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get $$$\texttt{Idleness limit exceeded}$$$. To do this, use:

  • $$$\texttt{fflush(stdout)}$$$ or $$$\texttt{cout.flush()}$$$ in C++;
  • $$$\texttt{System.out.flush()}$$$ in Java;
  • $$$\texttt{stdout.flush()}$$$ in Python;
  • see the documentation for other languages.
Example
Input
1
3

2

-1

1
Output


? 1 2

? 1 3

? 2 3

!
1 2 -1 
2 1 
2 
Note

In the example, the hidden array is $$$[a_1, a_2, a_3] = [2, 4, 6]$$$.

  • First, you ask $$$\texttt{? 1 2}$$$. Since $$$f(1, 2) = a_1 \oplus a_2 = 6$$$, the answer is $$$\lfloor \log_2(6) \rfloor = 2$$$.
  • Then, you ask $$$\texttt{? 1 3}$$$. Since $$$f(1, 3) = a_1 \oplus a_2 \oplus a_3 = 0$$$, the answer is $$$-1$$$.
  • Then, you ask $$$\texttt{? 2 3}$$$. Since $$$f(2, 3) = a_2 \oplus a_3 = 2$$$, the answer is $$$\lfloor \log_2(2) \rfloor = 1$$$.

Now, even without knowing the hidden array, you claim the answer to all the possible $$$6$$$ queries. For example, you claim that the answer to $$$\texttt{? 1 1}$$$ is $$$1$$$.

You have spent $$$1/2 + 1/3 + 1/2 = 4/3$$$ robocoins, which is less than the allowed $$$300$$$ robocoins.

H. Keygen 3
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A permutation$$$^{\text{∗}}$$$ of length $$$n$$$ is called valid if it has both of the following properties:

  • It is bitonic$$$^{\dagger}$$$;
  • Exactly $$$m$$$ of its subsets are cycles$$$^{\ddagger}$$$.

Let $$$k$$$ denote the number of permutations satisfying the above condition. Your task is to find and print $$$\min(k, 2000)$$$ examples of such permutations.

$$$^{\dagger}$$$ A permutation $$$p_1, p_2, \ldots, p_n$$$ is bitonic if there exists an index $$$i$$$ ($$$1 \leq i \leq n$$$) such that

  • $$$p_{j-1} \leq p_j$$$ for $$$2 \leq j \leq i$$$;
  • $$$p_j \geq p_{j+1}$$$ for $$$i \leq j \leq n-1$$$.

$$$^{\ddagger}$$$ A subset $$$C \subseteq \{ 1, 2, \ldots, n \}$$$ is a cycle if it satisfies the following conditions:

  • $$$C$$$ is non-empty;
  • if $$$x \in C$$$, then $$$p_x \in C$$$;
  • $$$C$$$ is minimal, i.e., there does not exist a cycle $$$C'$$$ such that $$$C' \subset C$$$.

$$$^{\text{∗}}$$$A permutation of length $$$n$$$ 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).

Input

The input consists of a single line containing two integers $$$n$$$, $$$m$$$ ($$$1 \le m \leq n \le 100$$$) — the length of the permutations and the target number of cycles.

Output

In the first line, print a single integer $$$r$$$: the number of permutations you are going to print. Note that $$$r$$$ must be $$$\min(k, 2000)$$$ as defined in the statement.

Then, print $$$r$$$ lines. Each line must contain a bitonic permutation of length $$$n$$$, with $$$m$$$ cycles.

Example
Input
6 3
Output
9
1 4 5 6 3 2
6 5 4 3 2 1
1 2 4 5 6 3
1 2 5 6 4 3
1 3 4 6 5 2
1 5 6 4 3 2
3 5 6 4 2 1
1 3 6 5 4 2
2 6 5 4 3 1
Note

In the example, there are $$$9$$$ valid permutations (i.e., bitonic permutations of length $$$6$$$, with $$$3$$$ cycles). For example, $$$[3, 5, 6, 4, 2, 1]$$$ is bitonic (in the above definition, $$$i = 3$$$), and it has $$$3$$$ cycles: $$$\{1, 3, 6\}$$$, $$$\{2, 5\}$$$, $$$\{4\}$$$. So you have to print $$$r = \min(9, 2000) = 9$$$ such permutations.

I. Hyper Smawk Bros
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You and Bob are playing Hyper Smawk Bros against each other, facing a single boss with health $$$n$$$.

You and Bob act alternately, and you start. On your turn, you may use an attack that deals an integer amount of damage $$$x$$$ in $$$[1, m]$$$, replacing $$$n$$$ with $$$n - x$$$. However, one cannot use the same $$$x$$$ that his opponent just used on the previous turn (on the very first move of the game, any $$$x$$$ in $$$[1, m]$$$ is allowed).

The winner is the first player to reduce the boss's health to $$$n \leq 0$$$. Determine whether you can force a win if Bob plays optimally.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.

The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 10^6$$$, $$$2 \leq m \leq 10^6$$$) — the starting health $$$n$$$ and the maximum damage per attack $$$m$$$.

Note that there are no constraints on the sum of $$$n$$$ over all test cases, and there are no constraints on the sum of $$$m$$$ over all test cases.

Output

For each test case, output $$$\texttt{YES}$$$ if you can force a win against Bob, and $$$\texttt{NO}$$$ otherwise.

The judge is case-insensitive (for example, $$$\texttt{YES}$$$, $$$\texttt{Yes}$$$, $$$\texttt{yes}$$$, $$$\texttt{yEs}$$$ will all be recognized as positive answers).

Example
Input
8
6 9
20 10
69 2
42 9
42 10
44 9
44 10
400000 400000
Output
YES
YES
NO
NO
YES
YES
NO
YES
Note

In the first test case, you can win immediately by dealing damage $$$8$$$, so that $$$n$$$ becomes $$$6-8 = -2 \leq 0$$$.

In the second test case,

  • you choose to deal damage $$$10$$$;
  • Bob can choose to deal any damage in $$$[1, 10]$$$ different from $$$10$$$;
  • then you can choose to deal damage $$$10$$$ and win.

In the third test case,

  • either you start by dealing damage $$$1$$$, then Bob must deal damage $$$2$$$, then you must deal damage $$$1$$$, etc.;
  • or you start by dealing damage $$$2$$$, then Bob must deal damage $$$1$$$, then you must deal damage $$$2$$$, etc.

In both cases, you lose.