ICPC Central Russia Regional Contest, 2023
A. Dilation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Dilation – is one of the simplest methods of morphological image processing. Its main purpose is to expand image objects by applying some kernel.

Suppose we have some initial image $$$A$$$ consisting only of black (objects) and white (background) pixels. If a $$$3 \times 3$$$ kernel is used for dilation, then in the target image $$$B$$$ the pixel $$$B_{i, j}$$$ will be black if it was black in the source image ($$$A_{i, j}$$$ is black) or at least one was black from neighboring pixels (some neighbors may not exist): $$$A_{i - 1, j - 1}$$$, $$$A_{i - 1, j}$$$, $$$A_{i - 1, j + 1}$$$, $$$A_{i, j - 1}$$$, $$$A_{i, j + 1}$$$, $$$A_{i + 1, j - 1}$$$, $$$A_{i + 1, j}$$$ or $$$A_{i + 1, j + 1}$$$.

Let's assume that you have a processed $$$B$$$ image. Can you restore the original one? Write a program that, based on the image $$$B$$$, builds the image from which $$$B$$$ came after dilation using a kernel of size $$$3 \times 3$$$, if possible.

Input

The first line contains the integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 100$$$) – the number of rows and columns in the image, respectively.

This is followed by $$$n$$$ lines, each of which contains $$$m$$$ characters. Each symbol describes a pixel in the image. The white pixel is indicated by a dot «.», and the black one is a hash symbol «#». It is guaranteed that there are no other characters in the lines.

Output

The first line should contain the word «Possible», if it is possible to restore the original image, or «Impossible» – if it is not.

If the word «Possible» was output, then print $$$n$$$ lines, each containing $$$m$$$ characters – the supposed source image, encoded in the same way as the input one.

If there are multiple solutions print any of them.

Examples
Input
5 5
.....
.###.
.###.
.###.
.....
Output
Possible
.....
.....
..#..
.....
.....
Input
3 3
...
.#.
...
Output
Impossible

B. Destroy them all!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The grandson of Professor R. Vanya downloaded the game 'Destroy them all!' and plays it all day long.

The game has a checkered field of size $$$n \times m$$$. It contains $$$k$$$ cells. The player can select any unmarked cell of the field and destroy all the marked cells exactly in one of the directions (left, right, above, below it). The grandson really wants to know the maximum number of cells he can destroy in one move at the current state of the field, but he is still too young to calculate this number. Help him – find the maximum number of cells that can be destroyed in one move if the coordinates of the $$$k$$$ marked cells are known.

Input

The first line contains the numbers $$$n$$$, $$$m$$$ and $$$k$$$ $$$(1 \le n, m \le 10^9, 1 \le k \le min(n \cdot m, 2 \cdot 10^5))$$$ - the size of the playing field and the number of marked cells.

The next $$$k$$$ lines contain pairs of numbers $$$x_i$$$ and $$$y_i$$$ $$$(1 \le x_i \le n, 1 \le y_i \le m)$$$ – the coordinates of the $$$i$$$-th marked cell.

Output

In the first line, print one number – the maximum number of cells that can be destroyed in one move. In the second line, print two numbers – the coordinates of an empty cell from which the maximum number of cells can be destroyed.

If there are no unmarked points, print «0» (without quotes) in the first line and «0 0» (without quotes) in the second line.

If there are multiple solutions print any of them.

Example
Input
12 12 4
3 7
3 11
6 4
12 4
Output
2
3 4
Note

From a point with coordinates $$$(3, 4)$$$, either two points above or two points to the right can be destroyed.

C. Martian Meteorology
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has been very interested in exploring other planets since childhood. Growing up, he was able to fulfill his dream and participate in the launch of a meteorological station to Mars. Unfortunately, an error was made during the assembly of the station. To even greater regret, it was discovered after the station started working on the surface of the planet.

The problem lies in the data from an ultra-sensitive temperature sensor capable of receiving readings with an accuracy of up to millionths of a degree. Vasya was instructed to try to solve the problem.

The sensor takes data every second and sends readings to Earth as a series of 32-bit integers. The series consists of $$$n$$$ sequential temperature measurements $$$t_1, t_2, ..., t_n$$$.

After watching the video of the satellite assembly, Vasya found out that some sensor connectors were connected backward ; as a result, some bits are transmitted in an inverted form ($$$0$$$ instead of $$$1$$$ and $$$1$$$ instead of $$$0$$$). Also, in all measurements, these bits have the same numbers (the numbering of bits traditionally starts with the least significant one, which has the number $$$0$$$). It is not clear from the video which bits are being transmitted incorrectly, but Vasya decided to try to determine them from the data received.

Vasya has a series of measurements consisting of $$$n$$$ obtained distorted numbers $$$t_1, t_2, ..., t_n$$$. From the readings of other devices, it is known that the temperature first rose and then fell during the measurement process. Vasya wants to try to select some value $$$k$$$ and apply $$$t_i$$$ to the elements using the xor operation (bitwise exclusive «OR»): $$$r_i = t_i \, xor \, k$$$. The resulting sequence $$$r_1, r_2, ..., r_n$$$ should behave like the Martian temperature. First, it does not decrease and then does not increase, and the intervals of non-decreasing and non-increasing must be of length at least 2 (the intervals themselves can intersect).

Write a program that helps Vasya find the number $$$k$$$.

Input

The first line of the input data contains the number of measurements $$$n$$$ ($$$3 \leq n \leq 10\,000$$$).

The second line contains distorted measurements in the form of integers $$$t_i$$$ ($$$0 \leq t_i \leq 2\,147\,483\,647$$$), separated by spaces.

Output

In a single line, print the integer $$$k$$$ ($$$0 \leq k \leq 2\,147\,483\,647$$$). It is guaranteed that the data is correct and at least one such number exists.

If there are multiple solutions print any of them.

Examples
Input
3
2 1 2
Output
2
Input
3
1 2 1
Output
0
Note

The xor operation exists in all modern programming languages; for example, in the languages $$$C\!+\!+$$$, $$$Python$$$ and $$$Java$$$ it is designated as «$$$ ^\wedge $$$», in $$$Pascal$$$ – as «xor». An example of using the «xor» operation: $$$10101_2 \oplus 10001_2 = 00100_2$$$.

D. DNA
time limit per test
1 s
memory limit per test
256 megabytes
input
standard input
output
standard output

In nature, DNA molecules are responsible for the transmission of hereditary information. The structure of DNA is simple and complex at the same time – its molecules are two long polymer strands bonded together in a double helix. Each DNA strand is built based on only four nucleotides: Adenine (A – Adenine), Guanine (G – Guanine), Thymine (T – Thymine), and Cytosine (C – Cytosine). It is customary to encode nucleotides in capital Latin letters and write their sequence as a line. For example: «ACTG».

In the first strand, nucleotides are connected sequentially in any order. Still, the second strand of the helix is built strictly on the principle of complementarity: Adenine always forms a pair with Thymine (A–T or T–A) and Cytosine with Guanine (C–G or G–C). So, a nucleotide located at a particular place in the first strand uniquely defines a nucleotide situated at the same place in the second strand.

For example, if one strand consists of «ACTGTAC» nucleotides, then the second will have the form «TGACATG».

This method of recording information is redundant and, in some places, ambiguous. For example, it may happen that the same sequence of nucleotides occurs in the first strand in one direction, in the second strand – in a different place and in exactly the opposite direction.

Write a program that, based on the sequence of nucleotides in one strand, will determine the longest subsequence of consecutive nucleotides that also occurs in the complementary strand, but in the reverse sequence. The location of the searched subsequence is not important.

Input

The input contains a single line with a length from $$$ 1 $$$ to $$$ 100\,000 $$$ characters. It is guaranteed that the string consists only of the letters «A», «C», «G» and «T».

Output

If the searched sequence does not exist, print $$$0$$$ in a single line. If the sequence exists, indicate its length in the first line, and print the sequence itself as a chain of capital Latin letters in the second line.

If there are multiple solutions print any of them.

Examples
Input
AGCT
Output
4
AGCT
Input
AACGTACGTG
Output
8
ACGTACGT
Note

Let's look at the second example. The complementary to the chain «AACGTACGTG» is «TTGCATGCAC». The «ACGTACGT» gene occurs both in the direct «A–ACGTACGT–G» and in the complementary chain «T–TGCATGCA–C», but in the latter it is written backwards.

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

Positive integers that are convenient for forming various measurement systems are called practical. A positive integer $$$x$$$ will be practical if any natural number less than $$$x$$$ can be represented as the sum of any different divisors of $$$x$$$.

For example, the number $$$6$$$ is practical since using the sum of its divisors $$$1, 2, 3, 6$$$, you can represent any number from $$$1$$$ to $$$6$$$: $$$1 = 1$$$, $$$2 = 2$$$, $$$3 = 3$$$, $$$4 = 1 + 3$$$, $$$5 = 2 + 3$$$, and $$$6 = 6$$$.

On the other hand, the number $$$9$$$ is not practical since, using its divisors $$$1, 3, 9$$$, it is impossible to represent the numbers $$$2, 5, 6, 7$$$ and $$$8$$$.

There are infinitely many practical numbers, and they have many useful properties. In particular:

  • the product of two practical numbers is also always a practical number;
  • if $$$p$$$ is a practical number, and $$$d$$$ is some kind of its divisor, then their product $$$p \cdot d$$$ is also a practical number;
  • one is the only odd number among practical number.

Among the practical numbers, primitive practical numbers stand out - those that cannot be obtained from other practical numbers by multiplying them or multiplying a practical number by any of its divisors.

Write a program that, by the number $$$n$$$, returns the $$$n$$$-th largest primitive practical number.

Input

The single line contains an integer $$$n$$$ ($$$1 \leq n \leq 10\,000$$$) – the number of the desired primitive practical number.

Output

In a single line, print a positive integer – the $$$n$$$-th largest primitive practical number.

Examples
Input
5
Output
28
Input
1
Output
1

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

Alexander hosted tournaments in the sports version of the game "What? Where? When?" for a long time.

In sports version of "What? Where? When?" several teams of 6 people play simultaneously. The host asks a question, after which, within 60 seconds, the teams must come up with an answer to it and write it down on the answer form. After a minute to think, players have 10 seconds to hand over the forms to the moderator.

Sasha is collecting questions for a new game. The game consists of $$$R$$$ rounds, with $$$Q$$$ questions in each round. There is a database of $$$N$$$ questions; for each question, it is known how many teams tried to answer the question and how many teams answered it incorrectly. Based on this data, a question rating is calculated for each question: the proportion of incorrect answers to the question is counted, multiplied by 10000 and rounded down to an integer. The easiest question has the lowest rating. Sasha wants to form a pack of questions for the game according to the following rules:

  • There must be at least one question in the package with a rating less than $$$L$$$. This question is called "candle" and is answered correctly by almost all teams. If there are several candidates for such a question, then "candle" is the question with the lowest rating among the candidates. A question with a minimum rating in the database may not be a "candle".
  • There must be at least one question in the package with a rating of more than $$$C$$$. Such a question is called "coffin", and only the best teams answer it correctly. If there are several candidates for such a question, then "coffin" is the question with the highest rating among the candidates. The question with the highest rating in the database may not be "coffin".
  • The "candle" question should be in the first half of the game.
  • The "coffin" question should be in the middle of the game. If the number of questions in game is even, then the "coffin" can be any question in the middle.
  • Round ratings should strictly increase to the middle of the game (in the first half), then strictly decrease (in the second half). The rating of each round is the rounded down arithmetic mean of the round questions' ratings.
  • The game needs to be diverse. If we order all the questions in the game by rating $$$Q_1 \le Q_2 \le \dots \le Q_{RQ}$$$, then the complexity of any two consecutive questions $$$Q_i$$$ and $$$Q_{i+1}$$$ satisfies the inequality $$$Q_{i+1} - Q_i \ge D$$$, where $$$D$$$ is the diversity coefficient.
  • If there are more than 2 questions in a round, the question ratings cannot strictly increase or strictly decrease.
  • If you order all the questions in the game by rating $$$Q_1 \le Q_2 \le \dots \le Q_{RQ}$$$, then the complexity of any two consecutive questions $$$Q_i$$$ and $$$Q_{i+1}$$$ should not differ by more than $$$S$$$.

Help Sasha: form a pack of questions for the game, that satisfies the rules above.

Input

The first line of the input contains non-negative integers $$$N, R, Q, L, C, D, S$$$ in accordance with the statement ($$$1 \le N, R, Q \le 10^6$$$, $$$1 \le R \cdot Q \le 10^6$$$, $$$2 \le L, C \le 9999$$$, $$$L \lt C$$$, $$$1 \le D, S \le 10000$$$).

The following $$$N$$$ lines contain two non-negative integers $$$A_i, B_i$$$ — how many teams were asked the question and how many teams answered the question incorrectly ($$$0 \le B_i \le A_i \le 10^9$$$).

Output

If it is possible to form a package without breaking the rules, then output $$$R \cdot Q$$$ integers — the numbers of questions from the database in the order in which they should be asked in the game.

If there are multiple solutions print any of them.

If it is impossible to form a package, output 0.

Example
Input
10 3 2 4000 6000 100 5000
1000 100
1000 200
1000 300
1000 400
1000 500
1000 550
1000 600
1000 700
1000 850
1000 950
Output
4 3 8 7 6 5 

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

Veronica loves to play with her toys. Cubes are one of her favorite toys.

Veronica builds towers, pyramids, and many other forms from multi-colored cubes. Today, Veronica wants to build a tower of $$$n$$$ cubes in height. Veronica has unlimited quantities of red, green, and blue cubes. Veronica wants to build a beautiful multi-colored tower, so she wants the tower to have no more than $$$k_r$$$ in a row of red cubes, $$$k_g$$$ in a row of green cubes, and $$$k_b$$$ in a row of blue cubes.

Help Veronica to determine how many different towers with a height of $$$n$$$ cubes she can build. Since this number may be very large, print the answer modulo $$$10^9 + 7$$$.

Input

A single line contains four integers $$$n$$$, $$$k_r$$$, $$$k_g$$$, $$$k_b$$$ $$$(1\leq n,k_r,k_g,k_b\leq 10^6)$$$  — tower height and restrictions on the number of consecutive red, green and blue cubes, respectively.

Output

In a single line, print an integer – the number of different variants of towers, taken modulo $$$10^9 + 7$$$.

Examples
Input
5 2 2 2
Output
180
Input
6 1 1 3
Output
222
Input
3 1 1 1
Output
12
Input
4 4 4 4
Output
81

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

Veronika has a huge number of toys – as many as $$$n$$$ pieces. Veronica decided to determine which toys she liked the most. To do this, she put all $$$n$$$ toys in one row. She gave the first toy a value equal to $$$a_1$$$. She gave each next toy a value according to the following rule:

$$$a_i = (a_{i-1}*k)\%p$$$.

where $$$k$$$, $$$p$$$  — beauty parameters. Veronica wants to find out the five largest values from the whole set of her toys. Help her in this difficult task.

Input

A single line contains four integers $$$n$$$, $$$a_1$$$, $$$k$$$, $$$p$$$ $$$(5\leq n\leq 2 \cdot 10^7, 1\leq a_1, k, p\leq 10^9)$$$  — the number of toys, the value of the first toy and the dependency parameters.

Output

Print the five largest values among Veronica's toys, separated by space, in ascending order.

Examples
Input
5 1 2 100
Output
1 2 4 8 16 
Input
10 10 3 1000
Output
430 610 810 830 870 

I. Line pinball
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Line pinball is played with $$$n$$$ metal balls having weights of $$$1, 2, 3, ..., n$$$ grams. Along a straight line, there are $$$n + 1$$$ holes equipped with plungers. The holes are numbered from left to right with numbers from $$$0$$$ to $$$n$$$.

Each plunger is inclined to the right and has its impact force $$$p_i$$$, where $$$i$$$ is the number of the hole. The design and inclination of the plunger are such that if it hits a ball with a mass of $$$x$$$ grams with force $$$p_i$$$, then the ball will move into the hole numbered $$$i + \lfloor p_i / x \rfloor$$$, where $$$\lfloor ... \rfloor$$$ means round down to a lower integer.

The game begins with one of the balls being placed in the starting hole numbered $$$0$$$. Next, the plungers of all the holes into which the ball falls are used sequentially. The game ends and is considered successful when the ball hits the hole number $$$n$$$. The game is considered lost if, at some point, the force of the plunger is too small to throw the ball into another hole or too strong and throws it further than the hole number $$$n$$$.

Write a program that selects the impact force $$$p_i$$$ for all $$$n$$$ plungers so that any ball with a mass from $$$1$$$ to $$$n$$$, starting from hole $$$0$$$, ends up in hole $$$n$$$.

Input

The only line contains the integer $$$n$$$ ($$$1 \leq n \leq 50$$$).

Output

In a single line print $$$n$$$ integers separated by spaces – the impact forces of the plungers $$$p_0, p_1, ..., p_{n-1}$$$ ($$$1 \leq p_i \leq 10^6$$$). The $$$n$$$-th hole plunger is never used, and its parameter must not be printed. It is guaranteed that a solution exists.

If there are multiple solutions print any of them.

Examples
Input
2
Output
2 2
Input
3
Output
3 5 3

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

Veronika really likes to visit shops because there are a lot of different colorful items. Arriving at the shop, Veronica first asks her dad to pick her up. As soon as Veronica is picked up, she immediately begins to command where to go. To do this, Veronica points her finger in the direction to go and says the word «there». Dad, of course, is happy to carry Veronica in his arms and goes in the direction shown by Veronica, but only until he meets an obstacle in the form of another customer, a shelf, or a wall.

For simplification, the shop can be represented as a rectangular matrix of size $$$n \times m$$$. Each cell of the shop can be empty and marked with the symbol «.», or occupied «#». Initially, Veronica is in the Dad's arms in the bottom left cell with coordinates $$$x$$$ equal to 1 and $$$y$$$ equal to 1. Veronica can show one of the four directions in letters, setting the movement: «U»  — increasing the coordinates of $$$x$$$, «D»  — decrease of the $$$x$$$ coordinate, «R»  — increase of the $$$y$$$ coordinate, «L»  — decrease of the $$$y$$$ coordinate.

Find the coordinates of Veronica and her dad after following all the instructions.

Input

The first line contains two integers $$$n$$$, $$$m$$$$$$(1\leq n,m\leq 1000)$$$  — the size of the shop.

Next, $$$n$$$ lines are given, each has $$$m$$$ characters. All lines consist of the characters «.»  — the cell is empty, «#»  — the cell is occupied.

The last line of input contains a single line $$$s$$$, consisting of the characters «D», «U», «L», «R», denoting Veronica's commands. The length of the line $$$s$$$ does not exceed $$$2 \cdot 10^6$$$.

Output

In a single line, print the final coordinates of the cell in which Veronica is located.

Examples
Input
4 4
....
....
....
....
DRLU
Output
1 4
Input
4 4
....
...#
....
....
DRUL
Output
1 2
Input
5 6
#..#..
#..#..
......
##..#.
....#.
RURD
Output
6 1

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

Before the appearance of Veronica, Igor and Ira chose a stroller for a long time. The stroller should satisfy many parameters: it should be comfortable, warm, stable, and multifunctional. One of the essential criteria is its size when folded.

For transportation during the trip, the stroller must be located in the trunk of the car. The trunk is a rectangle with the size $$$a \times b$$$. The stroller must be transported only folded to not damage it. When folded, the stroller occupies a space of $$$c \times d$$$. Igor wants to find out if a folded stroller will fit in the trunk. Help him - write a program to determine whether it can be done.

Input

A single line contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ $$$(1\leq a,b,c,d\leq 1000)$$$  — the dimensions of the trunk and the dimensions of the folded stroller.

Output

In a single line print «YES» (without quotes), if the stroller can be placed in the trunk according to the rules, otherwise output «NO» (without quotes).

Examples
Input
10 10 4 8
Output
YES
Input
8 11 10 12
Output
NO
Input
14 14 1 15
Output
YES

L. Bee coloring book
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Veronica is very good at drawing and coloring pictures. Igor and Ira bought her a new bee coloring book.

The coloring consists of $$$n$$$ lines, each contains exactly $$$m$$$ cells. Each cell is a regular hexagon, like a honeycomb in bees, and has no more than 6 neighbors. As an example, the $$$5 \times 5$$$ field looks like this:

Initially, some cells in the coloring are already colored. Veronica wants to get a continuous line of colored cells that connects the first row with the $$$n$$$-th row by coloring the minimum number of cells.

Input

The first line contains two integers $$$n$$$, $$$m$$$ $$$(1 \leq n, m \leq 1000)$$$  — the number of lines in the coloring and the number of cells in each line.

Next, $$$n$$$ lines are given, each line contains exactly $$$m$$$ characters and each line consists only of the characters «.» and «#». The symbol «.» means that the cell is not colored, «#»  — the cell is colored.

Output

Print one integer – the minimum number of cells that need to be colored to connect the first row with the $$$n$$$-th row.

Example
Input
5 5
....#
.#...
.#...
...#.
.#...
Output
2

M. Cinema
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A group of n students decided to go to the cinema. They bought a whole row of seats in the cinema for n places in advance. Of course, some seats for students are preferable to others. Therefore, each student knows the number of a seat he wants to sit in. Moreover, it is known that a student will be dissatisfied if he sits in the wrong place. You need to seat the students so that the total dissatisfaction is minimal.

Input

In the first line, you are given a single number n – the number of students and seats (1 ≤ n ≤ 105). In the next line, you are given n numbers, each from 1 to n, i-th of them is the number of a seat the i-th student wants to sit on.

The following line contains n numbers – students' dissatisfaction. The dissatisfaction of any student is an integer not less than 0 and not exceeding 106.

Output

In the first line, print a single number – the minimum total dissatisfaction of students.

In the following line, print a permutation of numbers from 1 to n, the ith of them should equal the seat number where the ith student should be seated. The total dissatisfaction with this should be the minimum possible.

If there are multiple solutions print any of them.

Examples
Input
3
1 2 3
1 2 3
Output
0
1 2 3
Input
4
3 3 2 2
2 1 3 4
Output
4
3 1 4 2
Input
3
3 3 3
3 2 1
Output
3
3 1 2

N. Entomologist
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A keen entomologist, Vasya studied an ant population in the neighboring forest. He discovered a huge anthill and, after spending a lot of time, determined that $$$k$$$ ants lived in it.

Due to the imposed quarantine, Vasya could not continue his field research. However, Vasya knows that there are $$$n$$$ anthills in total in the forest, which means that one may try to apply Zipf's law to estimate their size.

Zipf's law states: if $$$k$$$ insects live in the largest anthill, then in the second largest will be approximately half as many ($$$k / 2$$$), in the third three times less ($$$k / 3$$$), and in the $$$i$$$-th largest will live $$$i$$$ times less than ($$$k / i$$$).

Vasya made a forecast – a series of integers $$$c_1, c_2, ..., c_n$$$, where $$$c_i = k / i$$$, rounded to the nearest integer (according to mathematical rules, that is, numbers like $$$1.5, 2.5, ... $$$ were rounded up).

Unfortunately, the ants living on the home ant farm did not appreciate the researcher's impulse and damaged his notes. The saddest thing is that the original number $$$k$$$ was also damaged. However, some of the $$$c_i$$$ numbers have been preserved. Help Vasya recover the lost data.

Write a program that uses the preserved records $$$c_i$$$ to find the minimum initial number $$$k$$$. If there are several such numbers, print the minimum of them.

Input

The first line of input data contains the single integer $$$n$$$ ($$$3 \leq n \leq 1\,000$$$) – the number of anthills in the forest.

The second line contains $$$n$$$ entries separated by a space – the sequence $$$c_1, c_2, ..., c_n$$$. If the entry $$$c_i$$$ is not affected by ants, then the integer $$$c_i = k / i$$$ ($$$0 \leq c_i \leq 2\,147\,483\,647$$$) is indicated there, rounded to the nearest integer. If the record is damaged, then a question mark is indicated «?». It is guaranteed that the numbers $$$c_i$$$ are not contradictory and the desired number $$$k$$$ exists. It is also guaranteed that sequence always starts with «?».

Output

In a single line, print an integer – the minimum value of $$$k$$$ from satisfying the conditions of the problem.

Examples
Input
3
? 3 2
Output
5
Input
3
? 4 ?
Output
7