Replay of Battle of Brains 2022, University of Dhaka
A. First Year, Second Year
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Battle of Brains (BoB) is the yearly programming contest among students of the University of Dhaka. Only first and second year students of DU (any department or institute) can take part in the contest. The sole purpose of this contest is to spark an interest in the realm of problem solving in the mind of the freshers and sophomores.

In CSEDU lab, there are two computers on each table. Two contestants may communicate if they are classmates and sit at the same table. But communication is not allowed between contestants since this is an individual contest. So the organizers planned not to seat two classmates at the same table. After all the contestants arrive, the volunteers are going to seat two contestants from two different years at each table. An interesting fact is that every year the number of first-year contestants is larger than the number of second-year contestants. So after a while, some contestants are still standing there and all are first-year students.

The volunteers count the total number of contestants and the number of first-year students who are still standing there.

Now you will be given the total number of contestants and the number of first-year contestants who are still standing there. Your task is to find the number of contestants from first-year and the number of contestants from second-year.

It is guaranteed that the given data is valid according to the aforementioned scenario.

Input

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

The only line of each test case contains two integers $$$ a $$$ and $$$ b $$$ $$$ ( 1 \le b \lt a \lt 10^9) $$$ describing the total number of contestants and the number of first-year students who are still standing there.

Output

For each test case print a single line containing two integers separated by a space describing the number of first-year contestants and the number of second-year contestants.

Example
Input
2
12 2
15 3
Output
7 5
9 6
Note

In the first sample, there are $$$7$$$ first year students and $$$5$$$ second year students. One can see that this is correct because the total number of students is $$$12$$$ and there will be exactly $$$2$$$ first year students still standing because $$$5$$$ of them will be paired with $$$5$$$ second year students.

B. Even Out
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$$$ integers, where the $$$i$$$-th element is $$$A_i$$$. You can choose exactly one $$$i$$$ such that $$$1 \leq i \leq n$$$ and change $$$A_i$$$ to $$$-A_i$$$ (in other words, you change the sign of $$$A_i$$$). You want to make the sum of the array even. In how many ways can you do this?

Input

The first line contains an integer $$$T(1 \leq T \leq 100)$$$, the number of test cases.

For each test case, there are two lines. On the first line you are given $$$n\space(1 \leq n \leq 100)$$$, the number of integers in the array. The next line contains $$$n$$$ space-separated integers $$$A_1, A_2, ... , A_n\space(-100 \leq A_i \leq 100) $$$ denoting the array $$$A$$$.

Output

For each test case, print one integer in seperate lines denoting the number of ways you can make the sum of the array even.

Example
Input
2
2
0 0
6
2 3 5 -2 -3 0
Output
2
0
Note

In the first sample, there are two $$$0$$$s. You can change the sign of either of them (it remains $$$0$$$). So the sum is always $$$0$$$, which is even. So there are $$$2$$$ ways to make the sum even.

In the second sample, you can verify that no matter which element you change the sign of, the sum is not even. So there are $$$0$$$ ways.

C. Odd One Out
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an integer $$$X$$$, let $$$f(X)$$$ denote the number of ordered pairs $$$(a,b)$$$ such that $$$\gcd(a,b) \times \text{lcm}(a,b) = X$$$.

A number $$$Y$$$ is beautiful if $$$f(Y)$$$ is odd.

Count the number of beautiful numbers that lie in a given range $$$[L, R]$$$.

Refer to the notes below if you don't understand some of these terms.

Input

Input starts with an integer $$$T$$$ ($$$1 \leq T \leq 10$$$), denoting the number of test cases.

Each case starts with a line containing two integers $$$L$$$ and $$$R$$$ ($$$1 \le L \le R \le 10^9$$$).

Output

For each query, you have to print a line containing the number of beautiful numbers in the range $$$[L,R]$$$.

Example
Input
2
2 8
4669 176420
Output
1
352
Note

The first three beautiful numbers are $$$1,4,9$$$.

In the first sample, the only beautiful number which lies between $$$2$$$ and $$$8$$$ is the number $$$4$$$. It is a beautiful number because there are $$$3$$$ ordered pairs $$$(a,b)$$$ satisfying the equation given in the statement: they are $$$(1,4),(2,2),(4,1)$$$. Since this number $$$3$$$ is odd, the number $$$4$$$ qualifies as beautiful. One can check that the other numbers between $$$2$$$ and $$$8$$$ do not satisfy these conditions.

Definitions

  • An ordered pair $$$(a, b)$$$ is a pair where the order in which the elements $$$a,b$$$ appear is significant. The ordered pair $$$(a, b)$$$ is different from the ordered pair $$$(b, a)$$$ unless $$$a = b$$$.
  • The greatest common divisor $$$\gcd(a,b)$$$ of two numbers $$$a,b$$$ is the largest number which divides both $$$a$$$ and $$$b$$$. For example: $$$\gcd(6, 15)=3$$$.
  • The least common multiply $$$\text{lcm}(a,b)$$$ of two numbers $$$a,b$$$ is the smallest number that both $$$a$$$ and $$$b$$$ divide. For example: $$$\text{lcm}(6,15)=30$$$.

D. Yet Another Mysterious Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob went on an adventure, where they found a mysterious array $$$A$$$ consisting of $$$N$$$ positive integers. The $$$i$$$-th element of the array is called $$$A_i$$$.

Alice and Bob decided to play a game with this array, where each player moves in turn, and whoever can't find a valid move loses. Alice goes first. In simple words, Alice makes her move, then it is Bob's move, then it is Alice's move again, and so on. In every move, the player (whose move it is) does the following things sequentially:

  1. Select any prime number $$$p$$$ such that there exists an index $$$i$$$ such that $$$p$$$ divides $$$A_i$$$. If no such prime number is found, the player immediately loses.
  2. For each element $$$A_j$$$ from the array, if $$$p$$$ divides $$$A_j$$$, replace $$$A_j$$$ by $$$\dfrac{A_j}{p}$$$, else $$$A_j$$$ is kept unchanged. (Note that this part should be done for every element of the array, not just one).
  3. The updated array is passed to the next player.
Given the array, can you tell who will win the game if both players play optimally?
Input

The first line contains a positive integer representing the number of test cases.

For each test case, the first line contains a positive integer $$$N$$$ and the following line contains $$$N$$$ space-separated positive integers representing the array $$$A$$$.

Constraints

  • $$$1 \leq T \leq 10$$$
  • $$$1 \leq N \leq 10^5$$$
  • $$$1 \leq A_i \leq 10^5$$$
  • Sum over $$$N$$$ in all test cases will not exceed $$$10^5$$$.
Output

For each test case, print "Alice" or "Bob" in a single line without the quotes referring to who will win the game.

Example
Input
2
4
2 3 2 1
5
727 86197 46727 43969 34157
Output
Bob
Alice
Note

In the first sample test case:

  • Alice selects $$$2$$$, the array becomes $$$[1, 3, 1, 1]$$$.
  • Bob selects $$$3$$$, the array becomes $$$[1, 1, 1, 1]$$$.
  • Alice has no move, and Bob wins.

E. Rasta Thamaye Dilo
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Jubayer is a nice and talented kid. He is a two times ICPC World Finalist. He used to utilize his time solving problems after problems. But after all those years of hard work and achievements, he decides to enjoy a tiny break from his daily routine and roam to the villages of his very own B.Baria district. So, he went to B.Baria. But he soon became very fed up as he saw he cannot go to every village in his district as there are not enough roads that can help him reach every village. Also, a weird pattern was caught to the attention of this great programmer. In his district, there are $$$n-1$$$ villages. The villages are named with natural numbers (don't ask me why, I am just a simple problem setter). For some weird reason, there is no village numbered as $$$1$$$. Villages are named from $$$2$$$ to $$$n$$$ (for example: if $$$n=5$$$ then name of the villages are $$$2$$$, $$$3$$$, $$$4$$$ and $$$5$$$). And there is a road connecting the village $$$i$$$ and the village $$$j$$$ if and only if either $$$i$$$ is divisible by $$$j$$$, or $$$j$$$ is divisible by $$$i$$$.

Now, Jubayer wishes to create some new roads to extend the reachability: he wants to connect every village and roam everywhere without any hassle. But he is failing to determine the minimum number of roads that he needs to construct in order to fulfill this purpose. Now it is your turn to help this world famous programmer.

Input

First line will be number of test cases, $$$T\space(1 \le T \le 10^5)$$$.

Next $$$T$$$ lines will have a number $$$n\space(2 \le n \le 10^7)$$$ denoting the name of the last village in the district.

Output

For each test case, print the minimum number of roads needed to connect all the villages in a single line.

Example
Input
2
2
5
Output
0
2
Note

Use faster input/output.

Explanation of the second test case: Here $$$n = 5$$$, so the villages are named $$$2,3,4,5$$$. There's already an edge between $$$2$$$ and $$$4$$$ because $$$2$$$ divides $$$4$$$.

You have to construct at least $$$2$$$ roads to make every village reachable to every other (via some roads).

F. Lucky Seats
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The FIFA World Cup 2022 will take place in Qatar. The organizers plan to provide a prize to random attendees at the opening game. So they chose two integers $$$a$$$ and $$$b$$$. The integer $$$a$$$ represents bitwise $$$\textbf{OR}$$$ of a set of seat numbers and $$$b$$$ represents bitwise $$$\textbf{XOR}$$$ of the same set of seat numbers. The attendees assigned to those seats will receive the prizes. The organizers want to award prizes to as many people as possible. They therefore recruited you to identify the maximum possible number of attendees who are qualified for the award as well as their seat numbers. Each seat has a unique seat number, which is a non-negative integer.

See the notes if you forgot what bitwise $$$\textbf{OR}$$$ and $$$\textbf{XOR}$$$ means.

Input

Each test consists of multiple test cases. The first line contains a single integer $$$T\space(1 \leq T \leq 100) $$$ — the number of test cases.

For each testcase, there will be two numbers representing $$$a$$$ and $$$b$$$ $$$(0 \leq a, b \leq 10^4)$$$.

Output

For each testcase, if there is no solution, print $$$\textbf{-1}$$$.

Otherwise, print two lines.

  • First line will contain the maximum possible number of attendees who will get prize.
  • The next line will contain the seat numbers in increasing order separated by a single space. If there are multiple solutions for the given input, print any of them.
Example
Input
3
5 1
11 2
11 4
Output
3
0 4 5
7
0 1 3 8 9 10 11
-1
Note

Consider the first sample test. One can verify that the bitwise OR of the numbers $$$[0,4,5]$$$ is $$$5$$$, and the bitwise XOR of the numbers $$$[0,4,5]$$$ is $$$1$$$. One can verify that there's no set of (distinct) numbers with a bigger size that satisfies these conditions.

Bitwise XOR: The bitwise XOR of non-negative integers $$$A$$$ and $$$B$$$, denoted $$$A\oplus B$$$, is defined as follows:

  • When $$$A\oplus B$$$ is written in base two, the $$$k$$$-th digit from the right $$$(k\geq 0)$$$ is $$$1$$$ if and only if exactly one of the digits in that place of $$$A$$$ and $$$B$$$ is $$$1$$$, and $$$0$$$ otherwise. For example, we have $$$3\oplus 5=6$$$ (in base two: $$$011\oplus 101=110$$$).

Bitwise OR: The bitwise OR of non-negative integers $$$A$$$ and $$$B$$$, denoted $$$A\mid B$$$, is defined as follows:

  • When $$$A\mid B$$$ is written in base two, the $$$k$$$-th digit from the right $$$(k\geq 0)$$$ is $$$1$$$ if and only if at least one of the digits in that place of $$$A$$$ and $$$B$$$ is $$$1$$$, and $$$0$$$ otherwise. For example, we have $$$3\mid 5=7$$$ (in base two: $$$011\mid 101 = 111$$$).

G. Winter Gifts
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

At the beginning of the winter season in 2022, Ayon and Lagno received two colorful scarves as gifts from their mother. The scarves each have their own color patterns which can be described as a string of letters where each letter identifies as a unique color. Lagno was worried that her scarf would not match her brother's, but fortunately, she found a way to modify the colors on her own scarf.

Consider the color pattern of a scarf as a string consisting of lowercase English letters only. The pattern for Lagno's scarf is $$$S$$$ and Ayon's scarf is $$$T$$$. Both strings are of equal length $$$n$$$. For a given integer $$$k$$$, you can perform the following operation as many times as you want (maybe zero).

  1. Choose two indices $$$i$$$ and $$$j$$$ such that $$$1\leq i,j\leq n$$$ and $$$\left|i-j\right|=k$$$.
  2. Change $$$S[i]$$$ to $$$S[j]$$$.
Here, $$$\left|i - j\right|$$$ is the absolute difference between $$$i$$$ and $$$j$$$.

Can Lagno change her string $$$S$$$ to make it equal to her brother's string $$$T$$$?

Input

Input starts with an integer $$$T$$$ ($$$1\leq T\leq 10^6$$$), denoting the number of test cases.

Each case contains three lines. The first line contains two integers $$$n$$$ ($$$2 \leq n \leq 10^6$$$) and $$$k$$$ ($$$0 \lt k \lt n$$$). The following two lines contain Lagno's string $$$S$$$ and Ayon's string $$$T$$$. It is guaranteed that both strings have a length of $$$n$$$. The strings consist of lowercase English letters.

The sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.

Output

For each test case, print a single line containing "Yes" (without quotes) if string $$$S$$$ can be made equal to $$$T$$$ after zero or more operations, and "No" (without quotes) otherwise.

Example
Input
2
5 2
ebadc
abcbc
12 1
aaabccabbdbb
abaaaabdbbbc
Output
Yes
No
Note

In the first sample, you can perform the following operations:

  1. $$$i = 1$$$ and $$$j = 3$$$ to make $$$S=$$$ 'abadc'.
  2. $$$i = 3$$$ and $$$j = 5$$$ to make $$$S=$$$ 'abcdc'.
  3. $$$i = 4$$$ and $$$j = 2$$$ to make $$$S=$$$ 'abcbc'.

H. A Dance with DS
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob are playing a game. Alice gives Bob an integer $$$k$$$. Then Bob picks another non-negative integer $$$n$$$ and performs some moves (possibly zero) on $$$n$$$. In one move, he does the following:

  • If $$$k$$$ divides $$$n$$$ (i.e. $$$n\bmod k = 0$$$), then he divides $$$n$$$ by $$$k$$$. Formally, he does $$$n:=\dfrac{n}{k}$$$.
  • Otherwise, he subtracts $$$1$$$ from $$$n$$$. Formally, he does $$$n:=n-1$$$.
If $$$n = 0$$$, he stops performing any further move. Bob wants to play for as long as possible, but he does not want to start with a number too big. Specifically, he doesn't want $$$n$$$ to be bigger than a limit $$$r$$$. Given the limit $$$r$$$, what is the maximum number of moves that can be performed if he chooses $$$n$$$ such that, $$$0 \leq n \leq r$$$?
Input

Input starts with an integer $$$T$$$ ($$$1\leq T\leq 10^5$$$), denoting the number of test cases.

Each of the next $$$T$$$ lines contain two integers $$$r$$$ ($$$0 \leq r \leq 10^{18}$$$) and $$$k$$$ ($$$2 \leq k \leq 10^{18}$$$).

Output

For each test case, you have to print the maximum number of moves that can be performed among all $$$n$$$, such that $$$0 \leq n \leq r$$$.

Example
Input
2
5 2
4 3
Output
4
3
Note

In the first sample, we have $$$r=5$$$. So $$$n$$$ cannot be bigger than $$$5$$$.

  • If $$$n = 0$$$, number of moves $$$=0$$$.
  • If $$$n = 1$$$, number of moves $$$=1$$$ ($$$1 \rightarrow 0$$$).
  • If $$$n = 2$$$, number of moves $$$=2$$$ ($$$2 \rightarrow 1 \rightarrow 0$$$).
  • If $$$n = 3$$$, number of moves $$$=3$$$ ($$$3 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$).
  • If $$$n = 4$$$, number of moves $$$=3$$$ ($$$4 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$).
  • If $$$n = 5$$$, number of moves $$$=4$$$ ($$$5 \rightarrow 4 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$).

If we choose $$$n = 5$$$, we get the maximum number of moves $$$=4$$$.

I. Stairway To Heaven
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob found a divine stairway when they went on an adventure to the seventh sky. As always, they decided to play a game with it. The rules of the game are following:

  1. The first step is labeled by a positive integer $$$u$$$, and the labels of the following steps are increased by $$$1$$$ sequentially all the way up to $$$v$$$ which is the topmost step of the stairway.
  2. Bob can not simply walk up the stairs due to its divine characteristics. But with the power of his infinity stones, he can teleport from step $$$a$$$ to step $$$b$$$ if and only if $$$a \lt b$$$ and the number of common divisors between $$$a$$$ and $$$b$$$ is $$$1$$$.
  3. Bob is currently at step $$$u$$$ which they are calling hell and he must reach step $$$v$$$ which they are calling heaven to win the game.
Bob realized that the game was too easy for him. To make the game exciting, Alice asked him the number of different paths he can take to reach heaven from hell. As the answer might be big, print the number of paths modulo $$$998244353$$$.
Input

The only line contains two positive integers $$$u$$$ and $$$v$$$ ($$$ 2 \le u \lt v\le 10^5$$$) denoting the label of hell and heaven respectively.

Output

Print the number of different ways Bob can reach heaven from hell in a single line. The answer might be very big. So print the answer modulo $$$998244353$$$.

Examples
Input
2 5
Output
3
Input
69 69420
Output
81268163
Note

For the sample test, the following $$$3$$$ paths are valid:

  1. $$$2 \rightarrow 3 \rightarrow 4 \rightarrow 5$$$
  2. $$$2 \rightarrow 3 \rightarrow 5$$$
  3. $$$2 \rightarrow 5$$$
He can't directly go to $$$4$$$ from $$$2$$$ because there are more than $$$1$$$ common divisors between them ($$$1,2$$$). Also, note that he cannot go from $$$3$$$ to $$$2$$$ because he can't go to a smaller number.

J. XORted
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a sorted array $$$A$$$ with $$$N$$$ elements (non-decreasing order), you will be given $$$Q$$$ queries. In each query, you will be given a range $$$[L, R]$$$. For each query, you have to find the number of non-negative integers $$$X$$$ such that $$$X \lt 2^{20}$$$ and after doing the following operation the whole array remains sorted (non-decreasing order):

  • For each $$$i$$$ such that $$$L \le i \le R$$$, assign $$$A_i := A_i \oplus X$$$.

Note that the queries are independent. So you do not actually apply the operations on the array when you move on to the next query.

Input

Input starts with an integer $$$T\space(1 \le T \le 10^5)$$$, denoting the number of test cases.

Each case starts with an integer $$$N\space(1 \le N \le 10^5)$$$, denoting the number of elements in the array $$$A$$$. The next line will contain $$$N$$$ integers $$$A_1,A_2, ...., A_N\space(1 \le A_i \lt 2^{20})$$$ separated by spaces which denote the elements of the array.

The next line contains an integer $$$Q\space(1 \le Q \le 10^5)$$$ which denotes the number of queries. Each of the next $$$Q$$$ lines contains two space separated integer denoting $$$L$$$ and $$$R\space(1 \le L \le R \le N)$$$.

Additional constraint on the input:

  • $$$\sum N \le 10^5$$$ over all test cases
  • $$$\sum Q \le 10^5$$$ over all test cases
Output

For each query, you have to print a line containing the number of such $$$X$$$.

Example
Input
1
4
1 4 5 5
3
1 2
2 3
1 4
Output
2
2
262144