The 2019 University of Jordan Collegiate Programming Contest
A. Picky Eater
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Once upon a time, Hamza was hungry, only leftover food could be found in the fridge, so he wanted to order online.

Hamza currently has $$$x$$$ JDs, and the sandwich he wants to buy costs $$$y$$$ JDs, can Hamza order food online or he has to face his biggest enemies, leftover food?

Input

The first and only line in the input contains exactly 2 space separated integers $$$x,y$$$($$$1 \le x,y \le 10$$$), the amount of money he has, and the cost of the sandwich.

Output

If Hamza can buy the sandwich print "1"(on a single line without quotes), otherwise print "0"(on a single line without quotes).

Examples
Input
4 2
Output
1
Input
1 10
Output
0
Input
5 5
Output
1

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

A prime number is a natural number greater than 1 and has exactly 2 divisors which are 1 and the number itself.

You are given a prime number $$$n$$$, find any 2 prime numbers $$$a$$$ and $$$b$$$ such that $$$a+b=n$$$ or state that no such pair of primes exists.

Input

The input contains a single prime number $$$n$$$($$$2 \le n \le 10^7$$$).

Output

If there doesn't exist any 2 primes such that their summation is equal to $$$n$$$ then print -1, otherwise print the 2 primes on a single line separated by a space.

Examples
Input
5
Output
2 3
Input
11
Output
-1

C. Matryoshka Dolls
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Matryoshka Dolls are Russia's most popular souvenirs. They are sets of wooden figurines of decreasing size placed one inside another, though they have the same exact shape.

Our Matryoshka Doll is known to have an integer size $$$S$$$ which is the largest doll size in the collection, and each doll should have size $$$X$$$ times less than the doll that holds it($$$\textrm{size of the doll} \le \frac{\textrm{size of the doll that holds it}}{X}$$$).

Given $$$S$$$ and $$$X$$$, What is the maximum number of dolls that can be nested inside each other.

Input

The first and only line contains $$$2$$$ integers $$$S,X$$$($$$1 \le S \le 10^9$$$ , $$$2 \le X \le 10^9$$$).

Output

Output one integer, the maximum number of dolls.

Example
Input
10 2
Output
4

D. Robots Easy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice was playing her favorite game, "Tales of the Abyss", while playing she encountered the following puzzle that can be described as a $$$12 \times 12$$$ grid:

A robot is standing somewhere in this grid, you can order the robot to move up, down, right or left. The robot can't move to a blocked cell(fully black cell), but it can move to other cells(white and crossed cells). If you order the robot to move to a blocked cell or to move outside the grid then the robot won't move.

The goal of the puzzle is to move the robot to a crossed cell in at most 1000 moves. You will be given the description of some levels of this puzzle that Alice has solved, can you solve them too?

Input

In the first line you will be given the integer $$$L$$$($$$1 \le L \le 134$$$), the number of levels you need to solve.

Then you will be given $$$L$$$ lines describing the levels, each line will contain two integers $$$r,c$$$($$$1 \le r,c \le 12$$$), the row and column of the cell the robot is currently standing at, it's guaranteed that this cell is not a blocked cell(not a fully black cell). The rows are numbered from top(1) to bottom(12), and columns are numbered from left(1) to right(12).

Output

For each level output exactly 2 lines, the first line containing a single integer $$$n$$$($$$0 \le n \le 1000$$$), representing the number of moves you want to make, and the second line a string of length $$$n$$$ made of the letters 'U','D','R' and 'L'(upper_case) meaning Up, Down, Right and Left describing the moves.

Please note that in order to get accepted you have to follow the above format exactly, printing the number of moves and the string on the same line, or printing lower_case letters instead of upper_case for example might give you a wrong answer verdict.

Example
Input
2
2 3
9 4
Output
4
UUDD
3
LDL
Note

In the first level, the robot moves as follows: $$$(2,3)\rightarrow(1,3)\rightarrow(1,3)\rightarrow(2,3)\rightarrow(3,3)$$$.

In the second level, the robot moves as follows: $$$(9,4)\rightarrow(9,4)\rightarrow(10,4)\rightarrow(10,3)$$$.

E. Robots Hard
time limit per test
1 second
memory limit per test
5 megabytes
input
standard input
output
standard output

Notice that you need to read the statement of "D. Robots Easy" in order to understand this problem.

Also notice the unusual 5 megabytes memory limit.

Alice now is trying to beat the harder version of this puzzle, the only difference from the easy version is that there are 4 robots instead of 1, when ordering the robots to move in a specific direction, all 4 robots move at the same time(that is you can't order a single robot to move).

If the cell the robot should move to is blocked, then the robot doesn't move, if it's empty or crossed then it does move, if the cell already has another robot standing in it then if that robot in that cell is moving then the current robot will also move, otherwise it will not move.

For example if there's a robot in cell $$$(1,1)$$$ and another in cell $$$(1,2)$$$ and you order the robots to move to the left, then both of these robots won't move, but if there's a robot in cell $$$(1,2)$$$ and another in cell $$$(1,3)$$$ and you order the robots to move to the left then both robots will move to the left.

In order to beat the level you need to move the robots such that in the end each robot is standing in a crossed cell. Alice couldn't solve any of the hard levels, can you solve them with at most 1000 moves for a level?

Input

In the first line you will be given the integer $$$L$$$($$$1 \le L \le 1000$$$), the number of levels you need to solve.

Then you will be given $$$L$$$ lines describing the levels, each line will contain eight integers $$$r_1,c_1,r_2,c_2,r_3,c_3,r_4,c_4$$$($$$1 \le r_i,c_i \le 12,1\le i\le 4$$$), the positions of the robots, it's guaranteed that none of the cells are blocked cells and all four cells are distinct.

Output

The output is the same as the easy version.

Example
Input
1
4 2 4 9 11 2 10 10
Output
2
RU

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

Kassandra is participating in the Arena Olympics of Sparta. In order to win the arena fight, she has to knockout all the other $$$N$$$ fighters.

Being a computer scientist, she wanted to do it while preserving her energy as much as possible, so she wants to win the fight without being noticed by any of the other fighters. To be more exact, she knows the position of each other fighter in the arena, the angle of the center of his field of view, and the range of his field of view.

If she knocks a fighter out while she's in the field of view of another fighter, she will be noticed and she would have to fight everyone face on. So she wonders if there exists an order of fighters to knockout such that no one notices her during the whole process.

Print any permutation such that if she knocks-out the fighters in this order, she won't be noticed. Or print $$$-1$$$ if there exists no such permutation.

Note that Kassandra can move freely while not knocking someone out to get to the position of any other fighter.

Input

The first line of the input will contain an integer $$$N$$$ $$$(1 \le N \le 3000)$$$.

Each of the following lines will contain 4 integers each: $$$x_i$$$, $$$y_i$$$, $$$a_i$$$, $$$r_i$$$ $$$(-10^{6} \le x_i, y_i \le 10^{6}, 0 \le a_i \le 359, 0 \le r_i \le 89)$$$ - the $$$x$$$ coordinate, $$$y$$$ coordinate, the angle of the center of the field of view, and the range of the field of view of the $$$i_{th}$$$ fighter respectively. No two fighters share the same position.

Output

If there exists such a permutation, print the order of the ids of the $$$N$$$ participants on a single line separated by a space. Otherwise, print $$$-1$$$.

Examples
Input
4
-2 1 35 25
-3 -2 35 25
0 -3 110 25
2 1 245 25
Output
2 4 3 1
Input
2
-3 -3 45 45
3 3 225 45
Output
-1
Note

The field of view ranges from the angle $$$a-r$$$ to the angle $$$a+r$$$.

Below is the illustration of the first case:

G. Diet
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dr. Diet has a special process. He has $$$n$$$ rooms in each room he has a patient. Each patient can be characterized by two numbers $$$a_i$$$ and $$$b_i$$$. Each day a stupid robot carrying food goes through the rooms starting from the first room. At the room of the $$$i_{th}$$$ patient if the value $$$a_i$$$ is greater than the amount of available food then the robot stops and returns to the charging mount, otherwise, the robot gives the patient $$$a_i$$$ food and continues on to the next patient. If the patient sees more than $$$b_i$$$ food with the robot after taking $$$a_i$$$ food he gets a stroke and dies.

At the end of the day the doctor checks on the patients and reports how many didn't get food and how many died.

He then updates the robot so that it stops giving food to the rooms with dead patients. The doctor is getting old so he came to you to ask for your help.

He needs you to answer two queries:

1) $$$1 $$$ $$$x $$$ the robot was given $$$x$$$ food you need to tell him how many patients died and how many didn't receive food.

2) $$$2$$$ $$$a$$$ $$$b$$$ $$$c $$$ the doctor got a new patient with values $$$a$$$ and $$$b$$$ the patient is given room $$$c$$$. If the room contains a dead patient then he gets thrown out and the new one gets the room otherwise, the old patient gets released and the new patient takes his place.

Input

The first line contains a single integer $$$n $$$ $$$(1 \le n \le 10^5)$$$, the number of rooms.

Each of the next $$$n$$$ lines contains two integers $$$a_i $$$ and $$$b_i $$$ $$$(1\le a_i\le 10^9,1\le b_i\le 10^{18})$$$, the amount of food the patients demands and the amount he can see without getting a stroke,respectively.

The next line contains a single integer $$$q $$$ $$$(1\le q\le 10^5)$$$, the number of queries;

The next $$$q$$$ lines contain the description of the queries:

1) $$$1 $$$ $$$x $$$ $$$(1\le x\le 10^{18}) $$$, $$$1 $$$ represents the first query and $$$x $$$ represents the amount of food the robot carries.

2) $$$2 $$$ $$$a $$$ $$$b $$$ $$$c $$$ $$$(1\le a\le 10^9,1\le b\le 10^{18},1\le c\le n)$$$, $$$2 $$$ represents the second query the values $$$a,b,c$$$ describe the new patient where $$$a$$$ is the amount of food the patient requires, $$$b$$$ is the amount of food the patient can see safely and finally $$$c$$$ is the index of the room the patient is going to use.

Output

For each query of the first type print two integers $$$a$$$ and $$$b$$$. Where $$$a$$$ is the number of patients who died and $$$b$$$ is the number of patients who didn't receive food.

Examples
Input
5
1 10
5 12
103 70
1 1
5 3
4
1 400
2 3 13 3
2 5 3 1
1 3
Output
5 0
0 2
Input
3
1 2
2 3
3 4
5
1 6
1 13
2 1 1 1
2 2 4 2
1 20
Output
1 0
2 0
2 0

H. Circle of Polygon
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A $$$\textbf{circumscribed circle}$$$ of a polygon is the circle that passes through all the vertices of that polygon.

Let's assume we have a $$$\textbf{regular}$$$ polygon, we want to find the area of the circumscribed circle around this polygon. Given the number of vertices and the side length of the polygon, can you find the circle's area?

Input

The only line contains $$$2$$$ integers , $$$V(3 \le V \le 359)$$$ the number of vertices of the polygon and $$$S(1 \le S \le 10^9)$$$

Output

Find the area of the resulting circumscribed circle.Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$$\frac{|a-b|}{max(1,b)}\le 10^{-6}$$$.

Example
Input
8 2
Output
21.452136491
Note

The octagon in the picture illustrates the first example.

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

3 days, that's how much time the king gave Daffy to find him the ultimate army organization plan before he cuts his head off.

2 days already passed with no progress, but luckily Bugs came to the rescue, he gave Daffy the "ultimate"{} plan as a string, unfortunately Daffy couldn't understand this string, now only 4 hours remain.

A soldier can be described in Bugs's string as this: first the $$$id$$$ of the soldier is written then following it $$$x$$$ brackets $$$()$$$ each for a subordinate of this soldier, each subordinate is described inside their bracket in the same way, for example the following string "$$$2(3(4))(1)$$$"{} means that soldier $$$2$$$ is the supervisor of soldiers $$$3$$$ and $$$1$$$, and soldier $$$3$$$ is the supervisor of soldier $$$4$$$, while soldiers $$$1$$$ and $$$4$$$ doesn't supervise any soldiers. The string Bugs gave you describes the king(he has no supervisor) and his subordinates and their subordinates and so on.

Or more formally: $$$$$$ Soldier = Id+Subordinates$$$$$$ $$$$$$ Subordinates = (Soldier)+Subordinates | \phi$$$$$$ where $$$\phi$$$ is the empty string.

Can you figure out the supervisor of each soldier and save Daffy's head?

Input

In the first line you're given an integer $$$n$$$($$$1 \le n \le 1.4 \times 10^5$$$), the number of soldiers(including the king) in the army.

In the second line you're given Bugs's string as described above, the string's length is less than or equal to $$$10^6$$$.

It's guaranteed that each $$$id$$$ from $$$1$$$ to $$$n$$$ appears exactly once in the string.

Output

Output in a single line $$$n$$$ space separated integers, the $$$i$$$th of these integers is the supervisor of the $$$i$$$th soldier or $$$0$$$ if this soldier has no supervisor(he's the king, notice that there will be only one such soldier).

Examples
Input
4
2(3(4))(1)
Output
2 0 2 3
Input
7
4(2)(5(3(6)(1))(7))
Output
3 4 5 0 4 3 5

J. Zoo
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The mayor built a new Zoo. The Zoo looks like a cycle made up of $$$n$$$ animal viewing locations, the locations are numbered from $$$1$$$ to $$$n$$$ where locations $$$i$$$ and $$$i+1$$$ are adjacent and locations $$$1$$$ and $$$n$$$ are also adjacent. Before entering the Zoo, citizens pick two locations $$$a$$$, $$$b$$$ such that $$$(a \neq b)$$$, and one of the two simple paths connecting them(clockwise or counter clockwise) such that the distance between $$$a$$$ and $$$b$$$ is at most $$$k$$$ along that path.

The citizens then starts walking between the locations following 4 conditions:

1) The citizens shouldn't move outside the path between $$$a$$$ and $$$b$$$.

2) All locations between $$$a$$$ and $$$b$$$ along the chosen path should be visited.

3) The walk should end on the starting location $$$a$$$.

4) The length of the walk is at most $$$m$$$.

How many possible walks can the citizens make? print that number module $$$10^9+7$$$.

Input

The input is made up of one line containing $$$3$$$ integers $$$n$$$, $$$k$$$, $$$m$$$, $$$(1 \leq k \lt n \leq 10^5, 1 \leq m \leq 2000)$$$.

Output

Print one integer $$$x$$$ the answer to the problem module $$$10^9+7$$$.

Examples
Input
4 3 3
Output
8
Input
10 5 6
Output
160

K. Birthday Puzzle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today is the Birthday of a beautiful girl, she's happy and she's telling her friends loudly to bring her birthday gifts. One of her best friends who is fond of puzzles decided to bring her a very special gift, a magic box, this box cannot be opened unless the beautiful girl solves the mysterious puzzle written on the box and writes the answer on a small piece of paper under where the puzzle is written.

"You are given an array $$$a$$$, the answer is obtained by doing OR operation to the numbers in each subset of array $$$a$$$, then by summing all the subset ORing results". Help the beautiful girl to find the answer so she can open the magic box and continue celebrating her blessed birthday.

Input

The first line contains integer $$$n(1\le n \le 20),$$$ the size for array $$$a$$$ The second line contains $$$n$$$ integers, $$$a_{i}(1 \le a_{i} \le 10^5)$$$ the array $$$a$$$ elements

Output

Help the beautiful girl to find the answer for the puzzle.

Example
Input
3
1 2 3
Output
18
Note

Note: a subset of an array $$$a$$$ is another array that can be obtained by removing zero or more elements from $$$a$$$.

The first sample subsets:

1

2

3

1|2 = 3

1|3 = 3

2|3 = 3

1|2|3 = 3

Answer = 1+2+3+3+3+3+3 = 18

Where | is the OR operation.

For more information about the OR operation use this link: https://en.wikipedia.org/wiki/Bitwise_operation#OR

L. ABC
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string consisting of letters 'a', 'b' and 'c', and there are 4 kinds of operations you can do on it:

  1. Replace a character 'a' in the string with "ab".
  2. Replace a character 'b' in the string with "bc".
  3. Replace a character 'c' in the string with "ba".
  4. Remove a substring(consecutive characters) "abc" from the string.

Let $$$n$$$ be the length of the string, can you remove the whole string using at most $$$3n$$$ operations or state that it's impossible to do so?

Input

The first and only line contains the string $$$s$$$($$$1 \le n \le 2\times 10^5$$$) consisting of characters 'a', 'b' and 'c'.

Output

If it's impossible to remove the whole string print -1, otherwise in the first line print $$$m$$$($$$1 \le m \le 3n$$$), the number of operations you will make.

In each of the next $$$m$$$ lines print an operation of the form $$$type_i,index_i$$$($$$1 \le type_i \le 4, 1 \le index_i \le |s|$$$), the type of the $$$i$$$th operation and the index of the character you want to do the $$$i$$$th operation on, if the operation is of type 4, then $$$index_i$$$ should be the index of the first character of the substring "abc" that you want to remove. $$$Index_i$$$ is $$$1-$$$based and the string is updated after each operation, see example notes for better understanding.

Examples
Input
acab
Output
4
1 1
4 1
2 2
4 1
Input
bac
Output
-1
Note

This is how the string changes in the first example: acab$$$\rightarrow$$$abcab$$$\rightarrow$$$ab$$$\rightarrow$$$abc$$$\rightarrow\phi$$$, where $$$\phi$$$ is the empty string.