2019 USP-ICMC
A. Jumping Buildings
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Bob is developing a new game called jumping Lario. In this game the main protagonist, Lario, has to jump on top of buildings until he reaches the end of the level. The level is composed of N buildings of possibly different heights. The building where Lario starts is chosen randomly at the beginning of the game.

Bob started to write the code for his game but then realized that he didn't know how to implement the jumps mechanics. The thing is, if Lario is currently on top of building X and the height of this building is h, then Lario should be able to reach building min(X + h, n) in one jump. Unless, of course, there's a taller building somewhere on the path from building X to building X + h, then in this case, Lario would face smash the taller building on the path and end up landing right before it.

For example, in the image bellow, if Lario had started on the first building (of height 5), with one jump he should be able to reach building six. But on the path from building one to building six, he would end up hitting building five that has height 6. When doing so, he would land on building four (the one with height 3).

Given the heights for all the N buildings, your task is to figure out for every possible start position of Lario, how far he would be able to go with just one jump.

Input

The first line of the input contains a single integer N (1 ≤ N ≤ 105), indicating the number of buildings.

The second line of the input contains N integers h1, h2... hN (1 ≤ hi ≤ 105), indicating the height of each building.

Output

Output N integers. The i-th integer indicating the farthest building that Lario can reach with one jump if he starts on top of the i-th building.

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

B. Divples
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

After your death, you're sent to a mysterious room. There are two guardian cats and two doors, one goes to heaven of AC problems and another goes to hell NO. One cat likes all divisors of an integer a and the other cat likes all multiples of an integer b. You where asked to write all integers that satisfies both. If you answer correctly, you may go to heaven of AC problems, full of balloons, otherwise you're sent to hell NO.

Input

The input consists of two integers a and b, where 1 ≤ b ≤ a ≤ 1012.

Output

The output consists of one line with all integers from smallest to largest that satisfies both guardian cats.

Examples
Input
12 3
Output
3 6 12 
Input
10 3
Output
Input
128 2
Output
2 4 8 16 32 64 128 

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

Sancho is a weird kid, he really likes rectangles. You are in charge of babysitting him and you want to keep Sancho distracted. You decided to give him a gridded sheet of paper with many dots in it, so that Sancho can draw a lot of rectangles by connecting those dots.

You don't want him to get overwhelmed with too many rectangles, so you want to know what is the number of distinct rectangles that can be formed such that each of the rectangle's vertexes is a dot, there are no dots inside or on the edges of the rectangle besides the ones on its vertexes and all sides are parallel to the axis of the grid.

Input

The first line of the input contains one integer $$$N$$$ $$$(1\leq N \leq 2000)$$$, indicating how many dots there are total in the sheet. $$$N$$$ lines will follow. The $$$i$$$th line will contain two numbers $$$x$$$ $$$(0 \leq x \leq 10^9)$$$ and $$$y$$$ $$$(0 \leq y \leq 10^9)$$$. The pair $$$(x, y)$$$ represents the coordinate of the $$$i$$$th dot on the sheet. No two dots will be in the same position.

Output

Output the number of distinct of rectangles that can be formed such that each vertex of the rectangle is a dot, there are no dots inside or on the edges of the rectangle besides the ones on its vertexes and each rectangle is parallel to the axis of the grid.

Example
Input
6
1 1
1 2
2 1
2 2
3 1
3 2
Output
2

D. Guessing Messages
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Samuelo is a very good friend of Roppa. Whenever they feel bored, they like to exchange secret messages.

To do that, they craft some text in such a way so that the hidden message is a subsequence of it. To make things harder, they never use whitespaces.

An example of message exchanged in the past is (hidden message is red and underlined):

It can be very hard to uncover a message hidden like that, but it's usually not a problem for them since their minds are pretty much in sync.

Samuelo just wrote one of those messages. Roppa decided to take a step further this time and test their friendship by trying to guess the hidden message before even receiving it.

Given the message that Samuelo wrote and Roppa's guess, help Roppa on figuring out if his guess is in fact hidden in Samuelo's message.

Input

The first line the input contains a string $$$s$$$ ($$$1 \leq \lvert s \rvert \leq 10^6$$$), indicating the message that Samuelo wrote. The second line of the input contains a string $$$t$$$ ($$$1 \leq \lvert t \rvert \leq 10^6$$$), indicating Roppa's guess.

Both strings are composed only of lowercase English letters.

Output

Output YES if Roppa's guess is hidden in Samuelo's message. Otherwise, output NO.

Examples
Input
threeyellowfurryfiends
hellofriend
Output
YES
Input
hardcontest
easyac
Output
NO

E. Chi's performance
time limit per test
2.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Chi is a little kid that goes to a middle school in London, Ontario. He is in a band, and they are planning on performing this weekend. There are $$$N$$$ members in this band, and each one is categorized by the id of the instrument that they play, represented by a number $$$V$$$, and their ability level represented by a number $$$P$$$.

The enjoyment of a performance depends on the order in which people play, and their ability levels. The playing order goes as follows: the order of people presenting has to be in the order of their instrument's id, from smallest to largest, and in case of ties any order of the people with the same instrument is valid. If two people in a row are playing the same instrument, the enjoyment level doesn't change. If two people in a row have different instruments, the enjoyment increases by the absolute diference of their ability levels, because people like to see very different kinds of performances even if the ability level decreases.

Chi wants to have the best performance ever, and he asked your help with this task. He wants to know what is the highest enjoyment of the performance, given an optimal ordering.

Input

The first line will have an integer $$$N$$$ $$$(1 \leq N \leq 10^6)$$$. $$$N$$$ lines will follow. The $$$i$$$-th line will contain two integers $$$V_i$$$ $$$(1 \leq V_i \leq 10^9)$$$ and $$$P_i$$$ $$$(0 \leq P_i \leq 10^9)$$$ each, representing the $$$i$$$-th person's instrument id and ability level respectively.

Output

Print a single number, representing the highest enjoyment possible of the performance, given an optimal ordering of the players.

Example
Input
6
3 10
1 5
1 8
4 3
3 12
4 1
Output
16

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

You have a box with N cards numbered 1...N and you can also create new cards.

You are going to draw cards from the box, every time you draw a card of a number that has already been drawn you put that card back into the box. If you draw a card of a number that has not been drawn before, you lay it on the desk and you create another card to put back into the box. The number of the new card is chosen randomly with the same probability from the interval [1, N].

In this problem you have to answer what is the expected number of cards on the desk when you draw a card numbered 1 for the first time.

Input

One integer N (1 ≤ N ≤ 106).

Output

One floating point number, the expected number of cards on the desk when a card with the number 1 is drawn for the first time. Your answer will be considered correct if the absolute and relative error compared with the judge's solution is less than 10 - 4.

Example
Input
2
Output
1.5000000000

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

Tomaz and Danftito are playing a game with 3 stacks of rocks, each with a, b and c rocks respectively. Each turn, a player must take from 1 to m rocks from a stack, but they can't empty a stack if there are rocks in any stack to the left. The player that removes the last rock wins. If Tomaz goes first and they take turns playing, determine who will win the game if both players play optimally.

Input

The input contains one line with four integers: m (1 ≤ m ≤ 1018) representing the maximum amount of rocks to be removed in a single turn, a, b and c (1 ≤ a, b, c ≤ 1018) each representing how many rocks there are initially in the first, second and third stacks respectively.

Output

Print "Tomaz" if Tomaz will win the game, and "Danftito" otherwise.

Example
Input
3 1 1 1
Output
Tomaz

H. Log Concave Sequences
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

A sequence of numbers A is said to be logarithm concave if, and only if, for every 2 ≤ i ≤ n - 1, ai - 1 * ai + 1 ≤ ai2.

For example the sequence A = (1, 2, 3) is logarithm concave. The sequence A = (2, 2, 3) is not logarithm concave.

In this problem, you will have to answer what is the number of log concave sequences which contain only the numbers 0, 1 or 2, with N elements.

As this number could be very large, print the answer mod 109 + 7.

Input

The input consists of a single integer N (3 ≤ N ≤ 1018) indicating the size of the log concave sequence.

Output

One integer with the number of log concave sequences with size N that contains only the numbers 0, 1 or 2.

Example
Input
3
Output
20

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

Laersh is a Pokemino trainer and he just captured his first pokemino. Throughout his journey he will capture more Pokeminos. Each Pokemino has an attack and a defense level. A Pokemino is better than another one if it has greater attack and greater defense level. Besides capturing Pokeminos, Laersh can breed any two Pokeminos that he owns and generate a new Pokemino. This new Pokemino's attack and defense will be a linear combination of its parents attributes:

Attackchild = Attackparent1 * c + Attackparent2 * (1 - c)

Defensechild = Defenseparent1 * c + Defenseparent2 * (1 - c)

The number c is the same for attack and defense, and can be any number 0 ≤ c ≤ 1.

An useless Pokemino is a Pokemino such that Laersh owns a better Pokemino, or he can breed a better Pokemino. For each new Pokemino that Laersh captures, help him figuring out the number of useless Pokeminos that he owns.

Input

The first line of the input contains one integer N (1 ≤ N ≤ 105). N lines will follow. The i-th line will contain two integers Ai (0 ≤ Ai ≤ 109) and Di (0 ≤ Di ≤ 109) each. Ai represents the attack of Pokemino i and Di represents the defense of Pokemino i. Note: No two captured Pokeminos will have the same attack and defense.

Output

Output N numbers, the i-th number represents how many useless Pokeminos there are when the i-th Pokemino is captured.

Examples
Input
10
10 0
10 1
10 2
9 3
8 4
7 4
3 4
2 4
1 4
0 4
Output
0
0
0
0
0
0
0
0
0
0
Input
5
3 6
6 4
6 9
7 2
10 8
Output
0
0
1
2
3

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

Sanchola is getting an array of integers as gift. He's weird, so he doesn't like having distinct integers in the same array and he only likes prime numbers. That's why he believes that he might need to fix the array after receiving it by turning all elements into the same prime number.

Sanchola is also very lazy and wants to do that using the minimum number of operations. In one operation Sanchola can either increase or decrease a single element of the array by one.

Given the array that he received as a gift, help Sanchola figuring out the minimum number of operations required to fix the array.

Input

The first line contains a single integer $$$N$$$ $$$(1 \leq N \leq 10^{5})$$$, indicating the length of the array.

The second line contains $$$N$$$ integers $$$a_{1}$$$, $$$a_{2}$$$, ..., $$$a_{n}$$$ $$$(1 \leq N \leq 10^{9})$$$, indicating the elements of the array $$$a$$$.

Output

In a single line output the minimum number of operations to satisfy Sanchola.

Examples
Input
3
2 3 10
Output
8
Input
2
1 1000000000
Output
999999999
Input
4
3 5 7 11
Output
10

K. Candies
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Nicoleta received a box of candies from his sister. It has a rectangular shape with dimensions $$$1$$$ x $$$N$$$ and contains $$$N$$$ candies, and each one has a value $$$C_i$$$ of deliciousness.

Sanchola lives with Nicoleta in Revuocnav and he loves to make Nicoleta upset. Sanchola found out about the gift and decided to take a consecutive subsequence of candies from the box when Nicoleta is not looking. The total deliciousness taken by Sanchola should be at least L so that he can enjoy the candies, but not greater than R, to not raise suspicion.

Sanchola needs your help to calculate the number of distinct consecutive subsequences that he can take from Nicoleta.

Two consecutive subsequences $$$C_{l_1} \cdots C_{r_1}$$$ and $$$C_{l_2} \cdots C_{r_2}$$$ are considered equal if and only if they have the same number of candies $$$x$$$ and $$$\forall{k}$$$ $$$C_{l_1 + k} = C_{l_2 + k}, 0 \leq k \lt x$$$.

Input

The first line consists of three integers $$$N$$$ $$$(1 \leq N \leq 5 * 10^{5})$$$, $$$L$$$ and $$$R$$$ $$$(-10^{18} \leq L \leq R \leq 10^{18})$$$ .

The second line contains $$$N$$$ integers $$$C_{1}, C_{2}, \cdots, C_{n}$$$ ($$$-10^{9} \leq a_{i} \leq 10^{9}$$$), indicating the deliciousness of each candy.

Output

Output a single integer - The number of distinct consecutive subsequences whose sum is between $$$L$$$ and $$$R$$$.

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