ArabellaCPC 2019
A. Is It Easy ?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

ArabellaCPC's Judges decided to print the problem statements.

Each one of the $$$n$$$ participated teams will get exactly one copy of the problem-statements, and each copy costs $$$k$$$ coins.

How many coins it will cost judges to print exactly one problem-statements for each team.

Input

The input consists of two integers $$$n$$$ and $$$k$$$, $$$(1 \leq n,k \leq 1000)$$$

Output

print the total cost of all problem statements.

Examples
Input
5 3
Output
15
Input
4 1
Output
4

B. Road to Arabella
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ayoub and Kilani felt board while they are going to ArabellaCPC in (Amman-Irbid) road, so Kilani invented a new game to play with Ayoub.

The game is described by the following rules :

Ayoub picks a random integer $$$n$$$ $$$(1 \leq n \leq 10^{9})$$$ , and Kilani picks a random integer $$$k$$$ $$$(1 \leq k \leq n)$$$, then they will start playing. In each turn a player can choose any number $$$x$$$ $$$(1 \leq x \leq max(1 , m-k) )$$$ (which $$$m$$$ is the current value of $$$n$$$) and subtract it from $$$n$$$. if $$$n$$$ equals zero then the player can't make a move. The player who can't make a move is considered to lose the game.

If Kilani starts, and each player played optimally, who would be the winner?

Input

First line of input contains integer $$$T$$$ $$$(1 \leq T \leq 10^4)$$$ the number of test cases.

Each one of next $$$T$$$ lines contains two integers $$$n$$$ and $$$k$$$, $$$(1 \leq k \leq n \leq 10^9)$$$.

Output

print "Kilani" if he wins, and print "Ayoub" otherwise. (the output is case sensitive)

Example
Input
2
2 1
4 1
Output
Ayoub
Kilani

C. Check The Text
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Roze has a special keyboard which consists only of 29 keys:

-26 alphabetic a-z keys, which prints the 26 lowercase Latin letters.

-"Space" key, which prints a single space.

-"CapsLock" key, which converts the status of the letters keys from lowercase to uppercase and vice versa. The status initially is lowercase.

-"Backspace" key, which deletes the last letter/space that was written on the screen.

If Roze presses "Backspace" and there is nothing to delete on the screen, nothing will happen.

Given the text that Roze had to print and the order of the keys she has pressed on the keyboard, check if Roze has printed the text correctly (including exactly one space between every two words).

Input

The first line contains an integer $$$n$$$ ($$$1 \lt n \lt 2000$$$), which is the number of the words in the text Roze has to print.

Then n strings represent the text Roze has to print separated by exactly one space.

Each string consists only of uppercase and lowercase Latin letters, and the total length of all strings less than 2000

The following line contains an integer $$$m$$$ ($$$1 \lt m \lt 2000$$$), which is the number of the keys Roze has pressed.

Then m lines, each line contains a string that represents the key was pressed.

It's guaranteed that the last key pressed is a letter and the first key is not a space key.

Output

Print a single line containing the result of checking.

If Roze has printed the text correctly, print "Correct". Otherwise, print "Incorrect".

Example
Input
2
Hello World
18
CapsLock
h
CapsLock
e
l
l
Backspace
o
Space
w
o
Backspace
Backspace
w
o
r
l
d
Output
Incorrect

D. Meeting Bahosain
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Essa wanted to meet the most powerful number theorist of all time: Bahosain, but Bahosain does not waste his precious time, so he gave Essa this puzzle in order to test his abilities.

Given two arrays, the second array only has distinct elements, Essa can do the following as many times as he wants to make all numbers in first array equal.

  1. Choose a number from the first array
  2. Add or subtract from it a number in the second array
  3. Replace the number in the first array with the result
Of course, Essa is unworthy of meeting the almighty Bahosain, and he can't solve this puzzle on his own, so can you help him?
Input

The first line containing two space separated integers $$$n,m$$$ ($$$1\le n,k \le 10^6$$$) represent the length of the first and second array.

the second line contains n integers represent the first array ($$$1\le a[i] \le 10^9$$$)

the third line contains m integers represent the second array ($$$1\le b[i] \le 10^9$$$)

Output

Print Yes, if it's possible to make all numbers in first array equal; and No in the opposite case.

Example
Input
5 2
3 6 7 2 5
2 4
Output
No

E. Longest path Problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a weighted undirected connected tree that contains n nodes and n - 1 edges.

every edge has a weight and there is exactly one path between every pair of different nodes.

Now you should take each edge independently and do the following :

1.remove the edge from tree (that will divide the tree into two components).

2.reconnect the edge again in which it is still a connected tree (every end of the edge should be connected to a node from a different component).

You should do this so that the longest path in the tree is minimised.

Input

First line contains one integer n (2 ≤ n ≤ 200000)

The next n - 1 lines will contain 3 integers for each,u v w (1 ≤ u, v ≤ n) (1 ≤ w ≤ 109), which means that there is an edge of weight w connecting the nodes u and v.

it is guaranteed that the edges describes one connected tree.

Output

you should print n - 1 lines, the ith line should be the answer for the ith edge.

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

The sample graph

Solution for the second edge: after removing the second edge, add it to again between Node 2 and Node 3

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

Essa is playing Musical Chairs with his friends, Musical chairs, is a game of elimination involving players, chairs, and music, with one fewer chair than players.

When the song ends whichever player fails to sit on a chair is eliminated, with a chair then being removed and the process repeated until only one player remains.

As we know Essa gets really competitive and will be willing to do anything to win, so he memorized each song's length in the playlist and the order they will be played. He also knows the order of the chairs that will be eliminated at the beginning of each turn, now at each beginning of a turn, Essa decides whether the group moves in clockwise or counterclockwise.

Each player changes their position after each second. The chairs will be used to form a circle, so if Essa chooses to move clockwise, each $$$i^{\text{th}}$$$ player will move to $$$i+1$$$ position and the player at the last position will move to the first position. If Essa chooses to move counterclockwise, each $$$i^{\text{th}}$$$ player will move to $$$i-1$$$ position, and the player at the first position will move to the last position. Given Essa's initial position, the length of each song and the order the chairs will be eliminated. Is there a way Essa can win?

Note that each time a chair is removed, the circle gets smaller.

Input

The first line will contain 2 integers $$$n$$$ number of players ($$$2\le n \le 1000$$$) and $$$p$$$ Essa's initial position ($$$1\le p \le n$$$).

The second line will contain $$$n-1$$$ integers, the length of the $$$i^{\text{th}}$$$ song in seconds ($$$1\le ai^{\text{th}} \le 10^9$$$).

The third line will contain $$$n-1$$$ distinct integers $$$j^{\text{th}}$$$ the order that the chairs will be eliminated ($$$1\le aj^{\text{th}} \le n$$$).

Output

print "Yes" without quotations if there's a way Essa can win, otherwise print "No" without quotations.

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

G. Card Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Zeyad and Ehab are playing a simple card game, each player initially has a deck of $$$n$$$ cards numbered from $$$1$$$ to $$$n$$$, the game lasts $$$n$$$ turns and in each turn both players privately choose one card and then both players reveal the chosen cards, the player that chose the card with the higher number earns points equal to that number, for example if Ehab chooses $$$4$$$ and Zeyad chooses $$$6$$$ Zeyad earns $$$6$$$ points, if the numbers chosen are equal no one earns any point, the cards chosen do not return to the deck, they are discarded instead.

Ehab doesn't care about winning or losing, he cares about mathematical values of the game, specifically he wants to know the expected number of points he'll earn considering all possible outcomes, can you help him?

Input

The first and only line of input contains a single integer $$$n(1 \leq n \leq 10^6)$$$.

Output

Print a real number, the expected number of points Ehab will earn in the game.

The answer is considered correct if the absolute or relative error is not greater than $$$10^{-6}$$$.

Examples
Input
3
Output
2.6666666667
Input
7
Output
16.0000000000

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

Motasem wants to cook n steaks (the steak consists of two faces) for his friends, and each face of the steak needs to be cooked for 5 minutes. Unfortunately, his pans can only fit 2 steaks at a time, and he only has k pans. If Motasem is cooking his steaks optimally, what is the minimum number of minutes he needs to cook all n steaks?

Input

A single line containing two space separated integers $$$n,k$$$ ($$$1\le n,k \le 10^9$$$) represent the number of steaks and pans respectively.

Output

A single integer represents the minimum time needed to cook all steaks

Example
Input
3 1
Output
15

I. Bashar and Hamada
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bashar is a very smart person, he invented a new function $$$F(S)$$$, where $$$S$$$ is a multiset of integers.

The function $$$F(S)$$$ returns the sum of the absolute difference between every pair of elements in $$$S$$$.

For example $$$F($$${$$$3 , 3 , 1 , 7$$$}$$$)$$$ = $$$\vert 3 - 3 \vert$$$ + $$$\vert 3 - 1 \vert$$$ + $$$\vert 3 - 7 \vert$$$ + $$$\vert 3 - 1 \vert$$$ + $$$\vert 3 - 7 \vert$$$ + $$$\vert 1 - 7 \vert$$$ = $$$18$$$.

After that Bashar gave Hamada an array $$$a$$$ that contains $$$n$$$ integers, and asked him to solve this problem.

For every $$$k$$$ such that $$$(2 \leq k \leq n)$$$, Hamada should choose a subsequence of $$$k$$$ integers from $$$a$$$, such that $$$F(S)$$$ is maximised.

Hamada couldn't solve the problem and he asked you for help.

Input

The first line of input contains one integer $$$n$$$ $$$(2 \leq n \leq 3 \times 10 ^ {5})$$$ which is the size of array $$$a$$$.

The second line contains $$$n$$$ integers, the $$$i^{th}$$$ one is $$$a_i$$$ $$$(1 \leq a_i \leq 10 ^ 8)$$$, which is the $$$i^{th}$$$ element in the array.

Output

For every $$$k$$$ such that $$$(2 \leq k \leq n)$$$, print the maximum possible $$$F(S)$$$ of a subsequence of size $$$k$$$, starting from $$$k = 2$$$ ending at $$$k = n$$$.

Example
Input
3
1 7 5
Output
6 12
Note

a subsequence of size $$$k$$$ is a sequnece that can be obtained be removing $$$n-k$$$ integers from $$$a$$$.

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

After gathering all the infinity stones and dusting half the population of the universe, Thanos went to gardens street. He decided to plant some flowers using the reality stone.

So Thanos now wants to plant $$$N$$$ flowers in least number of steps needed. In each step he can: Choose a number $$$(0 \leq x)$$$,then Plant $$$10^x$$$ plants or remove $$$10^x$$$ plants with the help of the power stone. What is the least number of steps he needs to plant exactly $$$N$$$ flowers.

Input

A single integer $$$N$$$ $$$(0 \le N \le 10^{10^5})$$$, the number of flowers Thanos wants to plant.

Output

The least number of steps Thanos needs to plant $$$N$$$ plants.

Examples
Input
3000
Output
3
Input
231
Output
6
Note

In the first sample, fastest way to plant 3000 plants is:

step 1 plant $$$10^3$$$

step 2 plant $$$10^3$$$

step 3 plant $$$10^3$$$

so the answer is 3 steps.

K. Smart Strategies
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Jaber loves video games, his favorite game is DS:GO, unfortunately he's very bad at it, that's why he decided to quit competitive programming and train for DS:GO instead.

Maps in DS:GO can be seen as a grid with $$$n$$$ rows and $$$m$$$ columns, Jaber believed that in order to get better he have to fully explore the maps of the game, so he decided to build a strategy for exploring the maps.

In order to build a strategy, for each cell in the map except for the bottom right cell he labels it either with a go right sign $$$\rightarrow$$$ or a go down sign $$$\downarrow$$$, so a strategy can be described as a grid with $$$\rightarrow$$$ and $$$\downarrow$$$ sings(note that he chooses all the signs in the bottom row as $$$\rightarrow$$$ and all the signs in the rightmost column as $$$\downarrow$$$).

To fully explore the map using a strategy he picks a cell, then start the game in that cell, then move using the signs($$$\rightarrow$$$ for right and $$$\downarrow$$$ for down) until reaching the bottom right cell, after that if he visited all cells then he's done training with this map, otherwise he picks another cell, then restarts the game in that cell, repeating that until all cells are visited.

Jaber want's to explore maps as fast as possible, that's why when using a strategy he always chooses the starting cells such that he restarts the game minimum number of times. Now Jaber is wondering how many strategies are there such that the minimum number of times he will start the game is exactly $$$x$$$, since Jaber quit competitive programming, he gave this task to you, calculate the answer module $$$10^9+7$$$.

Input

A single line containing three space separated integers $$$n,m,x$$$($$$1\le n,m \le 100, 1 \le x \le nm$$$).

Output

A single integer containing the answer module $$$10^9+7$$$.

Examples
Input
2 3 3
Output
2
Input
3 3 9
Output
0
Note

In the first example, the following are the 2 strategies.

L. Burgers
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Hiasat loves burgers, that's why he dreams about them while sleeping. One day he dreamed about an infinite grid of burgers, it can be described as an infinite grid with each cell having height of $$$n$$$ and width of $$$m$$$, inside each cell there's another grid of $$$n$$$ rows and $$$m$$$ columns with each cell having a height and width of 1.

In each cell of the $$$n \times m$$$ grid there was a burger, burgers in the first row had deliciousness equal to $$$1,2,3,...,m$$$ from left to right, in the second row the deliciousness of the burgers were equal to $$$m+1,m+2,m+3,...,2m$$$, and so on until the last row where the deliciousness of the burgers were equal to $$$(n-1)m+1,(n-1)m+2,(n-1)m+3,...,nm$$$.

Hiasat is currently standing at some cell in the infinite grid, he will repeatedly do the following: If Hiasat ate before a burger that has deliciousness equal to the deliciousness of the burger in the cell he's currently standing at then he wakes up from the dream, otherwise he eats that burger and jump $$$r$$$ rows down and $$$c$$$ columns to the right.

When Hiasat wakes up from the dream his happiness will be equal to the sum of deliciousness of all the burgers he ate in his dream, if he chooses his starting cell optimally, what is the maximum possible happiness Hiasat can wake up with(it's guaranteed that Hiasat will wake up eventually regardless of his starting cell)? Print it module $$$10^9+7$$$.

Input

A single line containing four space separated integers $$$n,m,r,c$$$($$$1\le r \le n \le 2\cdot 10^9, 1 \le c \le m \le 2\cdot 10^9$$$).

Output

Print a single integer the maximum happiness module $$$10^9+7$$$.

Examples
Input
3 3 1 1
Output
15
Input
1 4 1 2
Output
6
Input
2000000000 1 1 1
Output
91
Note

In the first example the grid looks like the grid below, Hiasat starts at the marked cell, he eats burgers with deliciousness $$$3+4+8=15$$$.

M. Two Operations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ayoub has a string $$$S$$$ consists of only lower case Latin letters, and he wants you to make some operations on it:

  1. you can swap any two characters in the string.
  2. you can delete any two adjacent characters that have the same value and replace them with the next character alphabetically,for example string $$$"abbx"$$$ could be $$$"acx"$$$ after one operation, string $$$"zz"$$$ could not be changed; because z is the last character in the English alphabets.

Ayoub wants you to make the string lexicographically maximal using the mentioned operations as many times as you want, can you help him?

String $$$x = x_1x_2... x_{|x|}$$$ is lexicographically larger than string $$$y = y_1y_2... y_{|y|}$$$, if either $$$|x| \gt |y|$$$ and $$$x_1 = y_1, x_2 = y_2, ... , x_{|y|}= y_{|y|}$$$, or exists such number $$$r (r \lt |x|, r \lt |y|)$$$, that $$$x_1 = y_1, x_2 = y_2, ... , x_r = y_r$$$ and $$$x_r + 1 \gt y_r + 1$$$. Characters in lines are compared like their ASCII codes.

Input

The input contains a single string $$$S$$$ $$$(1 \leq |S| \leq 10^5)$$$.

It is guaranteed that string $$$S$$$ consists of only lower case Latin letters.

Output

print the lexicographically maximal string that could be obtained using these two operations.

Examples
Input
abbx
Output
xca
Input
zyayz
Output
zzza
Note

In the first test case Ayoub replaced $$$"bb"$$$ with $$$"c"$$$ so the string has been changed to $$$"acx"$$$, then he swapped 'a' with 'x' so the result is $$$"xca"$$$ and it is the lexicographically maximal string.