Turtle Codes
A. Turtle Art
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Read a name from the input. Then output the name and a picture of a turtle like the one shown in the sample (don't forget the newline at the end).

Input

A single string denoting a name.

Output

On the first line, output the inputted name.

Then output the drawing of the turtle like shown in the sample.

Example
Input
Aakash
Output
Aakash
  ___
 ((_))  _
(_|_|_)('>
 .   .

B. String Shifts
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string that has been encrypted by shifting each letter by a certain number (for example, 'a' shifted by 1 is 'b'). Given that the word "tino" is in the unencrypted string, print the number of possible shift numbers that could have been used to form the encrypted string. (0 counts as a shift number.)

Input

A string consisting only of lowercase letters. $$$0 \le length \le 1000$$$

Output

The number of possible shift numbers that could have been used

Example
Input
tinoujopvkpq
Output
3

C. Max Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Keys is trying to solve this very difficult question. He is too busy watching anime so he doesn't have enough time to solve the problem. He needs your help.

Given an integer $$$n$$$, print a permutation where the number of distinct values of $$$p_i \cdot i$$$ is maximized.

Note that the permutation is $$$1$$$ indexed ($$$i$$$ starts from $$$1$$$ and goes to $$$n$$$).

You can print any answer that works.

Input

The first and only line contains a single number $$$n$$$, $$$1 \le n \le 2 \cdot 10^5$$$.

Output

The first and only line should contain $$$n$$$ spaces separated integers denoting a permutation of length $$$n$$$.

Examples
Input
4
Output
3 4 2 1
Input
5
Output
5 4 3 1 2
Input
7
Output
6 5 4 2 1 3 7
Note

In the first test case one valid permutation is $$$[3, 4, 2, 1]$$$. When we multiply this by $$$[1, 2, 3, 4]$$$ we get $$$[3, 8, 6, 4]$$$ which gives us $$$4$$$ distinct values which is the max for this value of $$$n$$$.

D. Binary Sorting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a binary string of length $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). You can peform and operation which involves choosing $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) and reversing the substring from $$$l$$$ to $$$r$$$. What is the minimum number of moves to sort the binary string (all $$$0$$$s should be before all $$$1$$$s)?

Input

First line contains a single number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).

Second line contains a string with $$$n$$$ characters, each either $$$0$$$ or $$$1$$$.

Output

Output a single number $$$X$$$, the minimum number of moves to sort the inputted binary string.

Example
Input
5
11010
Output
2
Note

We can first choose the range ($$$1, 5$$$), giving us the string $$$01011$$$ after the reversing operation. We then choose the range $$$(2, 3)$$$, giving us $$$00111$$$ which is fully sorted. There is no way to get to a fully sorted binary string in less operations.

E. Turnaround
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a number $$$N$$$ $$$(1 \le N \le 10^{18})$$$, find its binary representation without any leading zeros. Then, reverse the binary representation (i.e. $$$1011$$$ becomes $$$1101$$$). Print the base-10 number this reversed number represents.

Input

The first line has $$$N$$$ $$$(0 \le N \le 10^{18})$$$

Output

The decimal value of the reversed binary representation of $$$N$$$.

Examples
Input
5
Output
5
Input
731053868524
Output
238960798805

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

The seniors of Cupertino Competitive Programming Club are going through terrible senioritis! If their GPA gets below $$$2.8$$$, they may just abandon the club altogether!!! Thankfully, you recently discovered a potion for senioritis... but it takes a long time to work, only works on one person at a time, and will only improve the senior's GPA by $$$1.0$$$.

Given the amount of time the potion takes to work, the amount of time you have to cure their senioritis, and a list of GPAs, please output the least amount of people who will be unable to be cured of their senioritis.

Input

The first line contains two number $$$m$$$ and $$$k$$$ which represent the amount of time the potion takes to work and the amount of time you have to cure their senioritis respectively. The second line contains contains $$$n$$$, the number of seniors you have to cure. The next $$$n$$$ lines contain a single number $$$a_i$$$, $$$0 \le a_i \le 5$$$ which represents the gpa of the $$$i$$$th senior.

Output

The output should be exactly one number representing the least amount of people who will be unable to be cured of their senioritis.

Example
Input
5 21
6
1.7
3.9
4
2.6
0.7
2.4
Output
1
Note

In the above example, you know that the potion takes $$$5$$$ units of time to make, and you have $$$21$$$ units of time to cure all the seniors. The $$$1.7$$$ GPA is atrocious, so you could choose to try to cure that first, taking away ($$$2$$$ uses of the potion) $$$\cdot$$$ ($$$5$$$ units of time) $$$= 10$$$ units of time used -> $$$11$$$ units left. Then you could get the $$$2.6$$$ GPA up to $$$3.6$$$, but you'd only have 6 units of time left and would be able to cure the $$$2.4$$$ GPA, but not the $$$0.7$$$.

G. No Anime
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
I love anime
— Keys, probably

Keys loves watching anime. Unfortunately, his friend Tortles does not. Currently, the two of them are on an infinite grid. In every second, Keys will move one tile (either directly north, south, east, or west) and Tortles will move two tiles (any valid path such that the manhattan distance equals $$$0$$$ or $$$2$$$). Keys always moves before Tortles (even though they move in the same second, Keys will take his turn first, and then when he is finished moving, Tortles will move.) When Keys moves, he will leave behind an anime poster in the location he last was. Tortles' job is to stop Keys. If Tortles walks onto a tile with an anime poster, he will remove it from the grid.

Assuming both Tortles and Keys moves optimally, output the minimum number of moves for Tortles to pick up all of the posters Keys leaves behind and also tag Keys by moving onto the same tile he is on after he has picked up all of the posters.

Keys and Tortles start in distinct locations, and the grid starts empty (free of anime posters).

Input

The first line contains one integer $$$T (1 \le T \le 100)$$$, denoting the number of tests. Afterwards, $$$T$$$ lines follow. Each line contains four space-separated integers $$$X_1$$$ $$$Y_1$$$ $$$X_2$$$ $$$Y_2$$$, where $$$X_1$$$ and $$$Y_1$$$ represents the starting location of Tortles, and $$$X_2$$$ and $$$Y_2$$$ represents the startling location of Keys $$$(1 \le X_1, Y_1, X_2, Y_2 \le 10^9)$$$.

Output

Output $$$T$$$ lines, with each line containing a single integer representing the minimum number of moves for Tortles to catch Keys while picking up all the posters.

Example
Input
1
1 1 1 2
Output
1
Note

Keys when he has a single second of free time:

H. Cake
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, after creating a surplus amount of milk, Bessie has decided to create a cake! She creates a square cake with dimensions $$$N$$$ and $$$N$$$. However, Farmer John is forcing her to share the cake with Elsie. Farmer John wants Bessie to create a permutation of $$$0…N$$$, which she will use to cut the cake by basing the height of the cut-off on the permutation. For example, if the permutation was $$$0 2 1 3$$$, Bessie would start off at a height of zero on the left of the cake. Then she will move up to $$$2$$$ for the next cut, then $$$1$$$, then finally finish at $$$3$$$ on the right of the cake. Here is an image describing the outcome of the previous permutation.

Bessie will get the bottom portion of the cake, while Elsie will get the top. Find the maximum area Bessie can obtain.

Input

The first line contains a single integer $$$N (1≤N≤2⋅10^5)$$$, the dimensions of the cake.

Output

Output a single number, the maximum area Bessie can obtain. Your answer will be accepted if the absolute or relative error does not exceed $$$10^{−9}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a - b|}{max(1, |b|)} \le 10^{-9}$$$.

I. 2048
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently Bessie has gotten into the game 2048! The goal of 2048 is to create the number 2048 on a 4x4 grid by moving blocks left, right, up, and down. For example, if you move the blocks left, it will be as if you simulated gravity on the left side, with each block moving as far left as possible before colliding with another block. If 2 blocks are squished together and they have the same value, then they will combine to form 1 block that's double the value. After playing for many hours, Bessie has developed what she believes is the best strategy in the world, which is to go right, then go down, then repeat infinitely. However, using this strategy, the board will eventually become stuck. Given a 2048 board, print out the position in which the board gets stuck if Bessie uses her strategy. (Note that this isn't like actual 2048, where blocks will spawn after every move, so solve this problem as if no other blocks will be spawned in after every move. Also, note that even though sometimes going down or right might not change the grid, it is possible that the next right move may change the grid, in which you should continue the right down right down pattern).

In addition, note that on a single move, a block can't combine multiple times. For example, if you had the row $$$[2, 2, 2, 2]$$$, it would combine to form $$$[0, 0, 4, 4]$$$ rather than $$$[0, 0, 0, 8]$$$.

The blocks always merge with the rightmost/downmost blocks having greatest priority. For example the row $$$[0, 2, 2, 2]$$$ would merge into $$$[0, 0, 2, 4]$$$ rather than $$$[0, 0, 4, 2]$$$.

Input

A 4x4 grid, with each position containing either a 0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, or 2048, with the tiles separated by spaces as well. positions with a 0 should be considered blank spaces that aren't actual blocks.

Output

Please output the final 4x4 grid where the grid will not change with any down or right movement.

Example
Input
0 2 0 2
0 0 4 0
8 2 2 0
0 4 2 0
Output
0 0 0 0 
0 0 0 4 
0 0 0 16 
0 0 4 2 

J. Keys and the Subtree Permutation (Easy Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Keys needs your help! Tortles gave Keys a problem to solve, and the problem is as follows: You are given a tree rooted at node $$$1$$$ with N nodes $$$(1 \le N \le 2 \cdot 10^5)$$$. Each node has a value $$$P$$$ in the range of $$$[1, N]$$$, and each node has a unique value. He was asked to solve the problem, for each node $$$i \in [1, N]$$$, find if the subtree of $$$i$$$ contains values that are a permutation of length size of that subtree. Unfortunately, Keys is too busy watching anime and playing Rinbot to solve the problem, so he turned to you for help. Please help Keys!

Input

The first line contains a single integer $$$N$$$. The next line contains $$$N$$$ integers $$$P_1, P_2, ..., P_N$$$. The next $$$N - 1$$$ lines contain two integers $$$U$$$ and $$$V$$$, denoting an undirected edge between node $$$U$$$ and node $$$V$$$.

Output

Print $$$N$$$ lines, with the $$$i$$$th line being "YES" if the subtree of $$$i$$$ contains values that are a permutation of length size of that subtree, and being "NO" otherwise.

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

For the first example:

The subtree at node $$$1$$$ is of size $$$4$$$ and contains the values $$$4, 2, 1, 3$$$, so it has a valid permutation.

The subtree at node $$$2$$$ is of size $$$2$$$ contains the values $$$2$$$ and $$$1$$$, so it has a valid permutation.

The subtree at node $$$3$$$ is of size $$$1$$$ and contains the value $$$1$$$, so it has a valid permutation.

The subtree at node $$$4$$$ is of size $$$1$$$ and contains the value $$$3$$$, so it does not have a valid permutation.

K. Keys and the Subtree Permutation (Hard Version)
time limit per test
2 s
memory limit per test
256 megabytes
input
standard input
output
standard output

Keys needs your help! Tortles gave Keys a problem to solve, and the problem is as follows: You are given a tree rooted at node $$$1$$$ with N nodes $$$(1 \le N \le 2 \cdot 10^5)$$$. Each node has a value $$$P$$$ in the range of $$$[1, N]$$$. He was asked to solve the problem, for each node $$$i \in [1, N]$$$, find if the subtree of $$$i$$$ contains values that are a permutation of length size of that subtree. Unfortunately, Keys is too busy watching anime and playing Rinbot to solve the problem, so he turned to you for help. Please help Keys!

Input

The first line contains a single integer $$$N$$$. The next line contains $$$N$$$ integers $$$P_1, P_2, ..., P_N$$$. The next $$$N - 1$$$ lines contain two integers $$$U$$$ and $$$V$$$, denoting an undirected edge between node $$$U$$$ and node $$$V$$$.

Output

Print $$$N$$$ lines, with the $$$i$$$th line being "YES" if the subtree of $$$i$$$ contains values that are a permutation of length size of that subtree, and being "NO" otherwise.

Examples
Input
4
4 2 1 3
2 1
3 2
4 1
Output
YES
YES
YES
NO
Input
4
1 1 2 3
2 1
3 1
4 1
Output
NO
YES
NO
NO
Note

For the first example:

The subtree at node $$$1$$$ is of size $$$4$$$ and contains the values $$$4, 2, 1, 3$$$, so it has a valid permutation.

The subtree at node $$$2$$$ is of size $$$2$$$ contains the values $$$2$$$ and $$$1$$$, so it has a valid permutation.

The subtree at node $$$3$$$ is of size $$$1$$$ and contains the value $$$1$$$, so it has a valid permutation.

The subtree at node $$$4$$$ is of size $$$1$$$ and contains the value $$$3$$$, so it does not have a valid permutation.

L. Turtle and GCD
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This problem was supposed to have a cool statement but I forgot to add it.

Given two numbers $$$a$$$ and $$$b$$$, consider the set of integers $$$a$$$, $$$a + 1$$$, $$$a + 2$$$, …, $$$a + b - 1$$$. Partition this set into two nonempty sets such that each element belongs to exactly one set and the GCD of the sum of the sets is maximized. What is that maximum GCD?

Input

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

The first line contains two space separated integers $$$a$$$ and $$$b$$$ ($$$1 \le a \le 10^5$$$, $$$2 \le b \le 10^5$$$).

It is guaranteed that the sum of $$$a$$$ over all test cases is at most $$$10^5$$$.

It is also guaranteed that the sum of $$$b$$$ over all test cases is at most $$$10^5$$$.

Output

For each test case, output a single line, the maximum possible GCD.

Example
Input
6
11 4
3 3
1 6
25 36
6253 9564
69 420
Output
25
4
7
765
52766979
58485
Note

In the first test case, the numbers are $$$[11, 12, 13, 14]$$$ which we can partition into $$$[11, 14]$$$ and $$$[12, 13]$$$. The sum of the sets are $$$11 + 14 = 25$$$ and $$$12 + 13 = 25$$$ and GCD$$$(25, 25) = 25$$$. Guys after reading this, please be sure to orz Richard (both of them).

In the second test case, the set of numbers is $$$[3, 4, 5]$$$ which we partition into $$$[3, 5]$$$ and $$$[4]$$$. The sum of the subsets are $$$3 + 5 = 8$$$ and $$$4$$$ and GCD$$$(4, 8) = 4$$$.