Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.

The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.

Output amount of years from the current year to the next lucky one.

NoteIn the first example next lucky year is 5. In the second one — 300. In the third — 5000.


After passing a test, Vasya got himself a box of $$$n$$$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $$$k$$$, same for all days. After that, in the morning he eats $$$k$$$ candies from the box (if there are less than $$$k$$$ candies in the box, he eats them all), then in the evening Petya eats $$$10\%$$$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $$$k$$$ candies again, and Petya — $$$10\%$$$ of the candies left in a box, and so on.If the amount of candies in the box is not divisible by $$$10$$$, Petya rounds the amount he takes from the box down. For example, if there were $$$97$$$ candies in the box, Petya would eat only $$$9$$$ of them. In particular, if there are less than $$$10$$$ candies in a box, Petya won't eat any at all.Your task is to find out the minimal amount of $$$k$$$ that can be chosen by Vasya so that he would eat at least half of the $$$n$$$ candies he initially got. Note that the number $$$k$$$ must be integer.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$) — the initial amount of candies in the box.

Output a single integer — the minimal amount of $$$k$$$ that would allow Vasya to eat at least half of candies he got.

NoteIn the sample, the amount of candies, with $$$k=3$$$, would change in the following way (Vasya eats first):$$$68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$$$.In total, Vasya would eat $$$39$$$ candies, while Petya — $$$29$$$.


Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.  He ate coffee mix without water again, so right now he's really messed up and can't think.Your task is to help him by telling him what to type.

The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.

In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.

NoteYou can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals .


There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $$$[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$$$ $$$\to$$$ two cuts $$$\to$$$ $$$[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$$$. On each segment the number of even elements should be equal to the number of odd elements.The cost of the cut between $$$x$$$ and $$$y$$$ numbers is $$$|x - y|$$$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $$$B$$$ bitcoins.

First line of the input contains an integer $$$n$$$ ($$$2 \le n \le 100$$$) and an integer $$$B$$$ ($$$1 \le B \le 100$$$) — the number of elements in the sequence and the number of bitcoins you have. Second line contains $$$n$$$ integers: $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 100$$$) — elements of the sequence, which contains the equal number of even and odd numbers

Print the maximum possible number of cuts which can be made while spending no more than $$$B$$$ bitcoins.

NoteIn the first sample the optimal answer is to split sequence between $$$2$$$ and $$$5$$$. Price of this cut is equal to $$$3$$$ bitcoins.In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.In the third sample the sequence should be cut between $$$2$$$ and $$$3$$$, and between $$$4$$$ and $$$5$$$. The total price of the cuts is $$$1 + 1 = 2$$$ bitcoins.


One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.

The single input line contains space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.

Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.

NoteIn the first sample the author has to get a 2 for all his exams.In the second sample he should get a 3 for two exams and a 2 for two more.In the third sample he should get a 3 for one exam.


There are $$$b$$$ boys and $$$g$$$ girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and $$$n$$$ participants have accepted the invitation. The organizers do not know how many boys and girls are among them.Organizers are preparing red badges for girls and blue ones for boys.Vasya prepared $$$n+1$$$ decks of badges. The $$$i$$$-th (where $$$i$$$ is from $$$0$$$ to $$$n$$$, inclusive) deck contains $$$i$$$ blue badges and $$$n-i$$$ red ones. The total number of badges in any deck is exactly $$$n$$$.Determine the minimum number of decks among these $$$n+1$$$ that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.

The first line contains an integer $$$b$$$ ($$$1 \le b \le 300$$$), the number of boys.  The second line contains an integer $$$g$$$ ($$$1 \le g \le 300$$$), the number of girls.  The third line contains an integer $$$n$$$ ($$$1 \le n \le b + g$$$), the number of the board games tournament participants.

Output the only integer, the minimum number of badge decks that Vasya could take.

NoteIn the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used.


You are given a text of single-space separated words, consisting of small and capital Latin letters.Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.Calculate the volume of the given text.

The first line contains one integer number n (1 ≤ n ≤ 200) — length of the text. The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.

Print one integer number — volume of text.

NoteIn the first example there is only one word, there are 5 capital letters in it.In the second example all of the words contain 0 capital letters.


This is the easy version of the problem. The only difference between the easy version and the hard version is the constraints on $$$n$$$. You can only make hacks if both versions are solved.A permutation of $$$1, 2, \ldots, n$$$ is a sequence of $$$n$$$ integers, where each integer from $$$1$$$ to $$$n$$$ appears exactly once. For example, $$$[2,3,1,4]$$$ is a permutation of $$$1, 2, 3, 4$$$, but $$$[1,4,2,2]$$$ isn't because $$$2$$$ appears twice in it.Recall that the number of inversions in a permutation $$$a_1, a_2, \ldots, a_n$$$ is the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i > a_j$$$.Let $$$p$$$ and $$$q$$$ be two permutations of $$$1, 2, \ldots, n$$$. Find the number of permutation pairs $$$(p,q)$$$ that satisfy the following conditions:  $$$p$$$ is lexicographically smaller than $$$q$$$.  the number of inversions in $$$p$$$ is greater than the number of inversions in $$$q$$$. Print the number of such pairs modulo $$$mod$$$. Note that $$$mod$$$ may not be a prime.

The only line contains two integers $$$n$$$ and $$$mod$$$ ($$$1\le n\le 50$$$, $$$1\le mod\le 10^9$$$).

Print one integer, which is the answer modulo $$$mod$$$.


Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.Note that she can paint tiles in any order she wants.Given the required information, find the maximum number of chocolates Joty can get.

The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 109).

Print the only integer s — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.


The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching). Since she knows how reckless her pilots are, she wants to be sure that any two (straight) paths – from a base to its assigned spaceship – do not intersect in the galaxy plane (that is, in 2D), and so there is no risk of collision.

The first line contains two space-separated integers R, B(1 ≤ R, B ≤ 10). For 1 ≤ i ≤ R, the i + 1-th line contains two space-separated integers xi and yi (|xi|, |yi| ≤ 10000) denoting the coordinates of the i-th Rebel spaceship. The following B lines have the same format, denoting the position of bases. It is guaranteed that no two points coincide and that no three points are on the same line.

If it is possible to connect Rebel spaceships and bases so as satisfy the constraint, output Yes, otherwise output No (without quote).

NoteFor the first example, one possible way is to connect the Rebels and bases in order.For the second example, there is no perfect matching between Rebels and bases.


Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing successively one after another, or there are strictly more than k2 horsemen standing successively one after another. Find the number of beautiful arrangements of the soldiers. Note that all n1 + n2 warriors should be present at each arrangement. All footmen are considered indistinguishable among themselves. Similarly, all horsemen are considered indistinguishable among themselves.

The only line contains four space-separated integers n1, n2, k1, k2 (1 ≤ n1, n2 ≤ 100, 1 ≤ k1, k2 ≤ 10) which represent how many footmen and horsemen there are and the largest acceptable number of footmen and horsemen standing in succession, correspondingly.

Print the number of beautiful arrangements of the army modulo 100000000 (108). That is, print the number of such ways to line up the soldiers, that no more than k1 footmen stand successively, and no more than k2 horsemen stand successively.

NoteLet's mark a footman as 1, and a horseman as 2.In the first sample the only beautiful line-up is: 121In the second sample 5 beautiful line-ups exist: 12122, 12212, 21212, 21221, 22121


There is an infinite board of square tiles. Initially all tiles are white.Vova has a red marker and a blue marker. Red marker can color $$$a$$$ tiles. Blue marker can color $$$b$$$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should be exactly $$$a$$$ red tiles and exactly $$$b$$$ blue tiles across the board.Vova wants to color such a set of tiles that:  they would form a rectangle, consisting of exactly $$$a+b$$$ colored tiles;  all tiles of at least one color would also form a rectangle. Here are some examples of correct colorings:  Here are some examples of incorrect colorings:  Among all correct colorings Vova wants to choose the one with the minimal perimeter. What is the minimal perimeter Vova can obtain?It is guaranteed that there exists at least one correct coloring.

A single line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^{14}$$$) — the number of tiles red marker should color and the number of tiles blue marker should color, respectively.

Print a single integer — the minimal perimeter of a colored rectangle Vova can obtain by coloring exactly $$$a$$$ tiles red and exactly $$$b$$$ tiles blue. It is guaranteed that there exists at least one correct coloring.

NoteThe first four examples correspond to the first picture of the statement.Note that for there exist multiple correct colorings for all of the examples.In the first example you can also make a rectangle with sides $$$1$$$ and $$$8$$$, though its perimeter will be $$$18$$$ which is greater than $$$8$$$.In the second example you can make the same resulting rectangle with sides $$$3$$$ and $$$4$$$, but red tiles will form the rectangle with sides $$$1$$$ and $$$3$$$ and blue tiles will form the rectangle with sides $$$3$$$ and $$$3$$$.


Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.Neko has two integers $$$a$$$ and $$$b$$$. His goal is to find a non-negative integer $$$k$$$ such that the least common multiple of $$$a+k$$$ and $$$b+k$$$ is the smallest possible. If there are multiple optimal integers $$$k$$$, he needs to choose the smallest one.Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?

The only line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

Print the smallest non-negative integer $$$k$$$ ($$$k \ge 0$$$) such that the lowest common multiple of $$$a+k$$$ and $$$b+k$$$ is the smallest possible. If there are many possible integers $$$k$$$ giving the same value of the least common multiple, print the smallest one.

NoteIn the first test, one should choose $$$k = 2$$$, as the least common multiple of $$$6 + 2$$$ and $$$10 + 2$$$ is $$$24$$$, which is the smallest least common multiple possible.


For some experiments little Petya needs a synchrophasotron. He has already got the device, all that's left is to set the fuel supply. Fuel comes through a system of nodes numbered from 1 to n and connected by pipes. Pipes go from every node with smaller number to every node with greater number. Fuel can only flow through pipes in direction from node with smaller number to node with greater number. Any amount of fuel can enter through the first node and the last node is connected directly to the synchrophasotron. It is known that every pipe has three attributes: the minimum amount of fuel that should go through it, the maximum amount of fuel that can possibly go through it and the cost of pipe activation. If cij units of fuel (cij > 0) flow from node i to node j, it will cost aij + cij2 tugriks (aij is the cost of pipe activation), and if fuel doesn't flow through the pipe, it doesn't cost anything. Only integer number of units of fuel can flow through each pipe.Constraints on the minimal and the maximal fuel capacity of a pipe take place always, not only if it is active. You may assume that the pipe is active if and only if the flow through it is strictly greater than zero.Petya doesn't want the pipe system to be overloaded, so he wants to find the minimal amount of fuel, that, having entered the first node, can reach the synchrophasotron. Besides that he wants to impress the sponsors, so the sum of money needed to be paid for fuel to go through each pipe, must be as big as possible.

First line contains integer n (2 ≤ n ≤ 6), which represents the number of nodes. Each of the next n(n - 1) / 2 lines contains five integers s, f, l, h, a that describe pipes — the first node of the pipe, the second node of the pipe, the minimum and the maximum amount of fuel that can flow through the pipe and the the activation cost, respectively. (1 ≤ s < f ≤ n, 0 ≤ l ≤ h ≤ 5, 0 ≤ a ≤ 6). It is guaranteed that for each pair of nodes with distinct numbers there will be exactly one pipe between them described in the input.

Output in the first line two space-separated numbers: the minimum possible amount of fuel that can flow into the synchrophasotron, and the maximum possible sum that needs to be paid in order for that amount of fuel to reach synchrophasotron. If there is no amount of fuel that can reach synchrophasotron, output "-1 -1". The amount of fuel which will flow into synchrophasotron is not neccessary positive. It could be equal to zero if the minimum constraint of every pipe is equal to zero.

NoteIn the first test, we can either pass 1 or 2 units of fuel from node 1 to node 2. The minimum possible amount is 1, it costs a12 + 12 = 4.In the second test, you can pass at most 2 units from node 1 to node 2, and at you have to pass at least 3 units from node 2 to node 3. It is impossible.In the third test, the minimum possible amount is 2. You can pass each unit of fuel through two different paths: either 1->2->3->4 or 1->3->4. If you use the first path twice, it will cost a12 + 22 + a23 + 22 + a34 + 22=14. If you use the second path twice, it will cost a13 + 22 + a34 + 22=14. However, if you use each path (allowing one unit of fuel go through pipes 1->2, 2->3, 1->3, and two units go through 3->4) it will cost a12 + 12 + a23 + 12 + a13 + 12 + a34 + 22=15 and it is the maximum possible cost.Also note that since no fuel flows from node 1 to node 4, activation cost for that pipe is not added to the answer.


Maksim walks on a Cartesian plane. Initially, he stands at the point $$$(0, 0)$$$ and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point $$$(0, 0)$$$, he can go to any of the following points in one move:   $$$(1, 0)$$$;  $$$(0, 1)$$$;  $$$(-1, 0)$$$;  $$$(0, -1)$$$. There are also $$$n$$$ distinct key points at this plane. The $$$i$$$-th point is $$$p_i = (x_i, y_i)$$$. It is guaranteed that $$$0 \le x_i$$$ and $$$0 \le y_i$$$ and there is no key point $$$(0, 0)$$$.Let the first level points be such points that $$$max(x_i, y_i) = 1$$$, the second level points be such points that $$$max(x_i, y_i) = 2$$$ and so on. Maksim wants to visit all the key points. But he shouldn't visit points of level $$$i + 1$$$ if he does not visit all the points of level $$$i$$$. He starts visiting the points from the minimum level of point from the given set.The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$ where $$$|v|$$$ is the absolute value of $$$v$$$.Maksim wants to visit all the key points in such a way that the total distance he walks will be minimum possible. Your task is to find this distance.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of key points. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^9$$$) — $$$x$$$-coordinate of the key point $$$p_i$$$ and $$$y$$$-coordinate of the key point $$$p_i$$$. It is guaranteed that all the points are distinct and the point $$$(0, 0)$$$ is not in this set.

Print one integer — the minimum possible total distance Maksim has to travel if he needs to visit all key points in a way described above.

NoteThe picture corresponding to the first example: There is one of the possible answers of length $$$15$$$.The picture corresponding to the second example: There is one of the possible answers of length $$$9$$$.


A divisor tree is a rooted tree that meets the following conditions:   Each vertex of the tree contains a positive integer number.  The numbers written in the leaves of the tree are prime numbers.  For any inner vertex, the number within it is equal to the product of the numbers written in its children. Manao has n distinct integers a1, a2, ..., an. He tries to build a divisor tree which contains each of these numbers. That is, for each ai, there should be at least one vertex in the tree which contains ai. Manao loves compact style, but his trees are too large. Help Manao determine the minimum possible number of vertices in the divisor tree sought.

The first line contains a single integer n (1 ≤ n ≤ 8). The second line contains n distinct space-separated integers ai (2 ≤ ai ≤ 1012).

Print a single integer — the minimum number of vertices in the divisor tree that contains each of the numbers ai.

NoteSample 1. The smallest divisor tree looks this way: Sample 2. In this case you can build the following divisor tree: Sample 3. Note that the tree can consist of a single vertex.


Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance.    Illustration for n = 6, a = 2, b =  - 5. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.

The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n,  - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.

Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.

NoteThe first example is illustrated by the picture in the statements.


This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.After the qualifying round completes, you know K of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round.

The first line of input contains K (1 ≤ K ≤ 25), the number of onsite finalists you know. The second line of input contains r1, r2, ..., rK (1 ≤ ri ≤ 106), the qualifying ranks of the finalists you know. All these ranks are distinct.

Print the minimum possible number of contestants that declined the invitation to compete onsite.

NoteIn the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.


Mislove had an array $$$a_1$$$, $$$a_2$$$, $$$\cdots$$$, $$$a_n$$$ of $$$n$$$ positive integers, but he has lost it. He only remembers the following facts about it: The number of different numbers in the array is not less than $$$l$$$ and is not greater than $$$r$$$; For each array's element $$$a_i$$$ either $$$a_i = 1$$$ or $$$a_i$$$ is even and there is a number $$$\dfrac{a_i}{2}$$$ in the array.For example, if $$$n=5$$$, $$$l=2$$$, $$$r=3$$$ then an array could be $$$[1,2,2,4,4]$$$ or $$$[1,1,1,1,2]$$$; but it couldn't be $$$[1,2,2,4,8]$$$ because this array contains $$$4$$$ different numbers; it couldn't be $$$[1,2,2,3,3]$$$ because $$$3$$$ is odd and isn't equal to $$$1$$$; and it couldn't be $$$[1,1,2,2,16]$$$ because there is a number $$$16$$$ in the array but there isn't a number $$$\frac{16}{2} = 8$$$.According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.

The only input line contains three integers $$$n$$$, $$$l$$$ and $$$r$$$ ($$$1 \leq n \leq 1\,000$$$, $$$1 \leq l \leq r \leq \min(n, 20)$$$) — an array's size, the minimal number and the maximal number of distinct elements in an array.

Output two numbers — the minimal and the maximal possible sums of all elements in an array.

NoteIn the first example, an array could be the one of the following: $$$[1,1,1,2]$$$, $$$[1,1,2,2]$$$ or $$$[1,2,2,2]$$$. In the first case the minimal sum is reached and in the last case the maximal sum is reached.In the second example, the minimal sum is reached at the array $$$[1,1,1,1,1]$$$, and the maximal one is reached at the array $$$[1,2,4,8,16]$$$.


You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.It is allowed to leave a as it is.

The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.

Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.


Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:  On the checkered paper a coordinate system is drawn. A dot is initially put in the position (x, y).  A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line y = x.  Anton and Dasha take turns. Anton goes first.  The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses. Help them to determine the winner.

The first line of the input file contains 4 integers x, y, n, d ( - 200 ≤ x, y ≤ 200, 1 ≤ d ≤ 200, 1 ≤ n ≤ 20) — the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (0 ≤ xi, yi ≤ 200) — the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.

You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.

NoteIn the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line y = x. Dasha will respond to it with the same move and return the dot in position (2;3).


Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.Let's suppose that video's length is c seconds and Valeric and Valerko wait t seconds before the watching. Then for any moment of time t0, t ≤ t0 ≤ c + t, the following condition must fulfill: the size of data received in t0 seconds is not less than the size of data needed to watch t0 - t seconds of the video.Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.

The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 1000, a > b). The first number (a) denotes the size of data needed to watch one second of the video. The second number (b) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (c) denotes the video's length in seconds.

Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.

NoteIn the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.In the second sample guys need 2 · 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary.


Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:   After the cutting each ribbon piece should have length a, b or c.  After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.

The first line contains four space-separated integers n, a, b and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.

Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.

NoteIn the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.


Ivan has number $$$b$$$. He is sorting through the numbers $$$a$$$ from $$$1$$$ to $$$10^{18}$$$, and for every $$$a$$$ writes $$$\frac{[a, \,\, b]}{a}$$$ on blackboard. Here $$$[a, \,\, b]$$$ stands for least common multiple of $$$a$$$ and $$$b$$$. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.

The only line contains one integer — $$$b$$$ $$$(1 \le b \le 10^{10})$$$.

Print one number — answer for the problem.

NoteIn the first example $$$[a, \,\, 1] = a$$$, therefore $$$\frac{[a, \,\, b]}{a}$$$ is always equal to $$$1$$$.In the second example $$$[a, \,\, 2]$$$ can be equal to $$$a$$$ or $$$2 \cdot a$$$ depending on parity of $$$a$$$. $$$\frac{[a, \,\, b]}{a}$$$ can be equal to $$$1$$$ and $$$2$$$.


Today, Osama gave Fadi an integer $$$X$$$, and Fadi was wondering about the minimum possible value of $$$max(a, b)$$$ such that $$$LCM(a, b)$$$ equals $$$X$$$. Both $$$a$$$ and $$$b$$$ should be positive integers.$$$LCM(a, b)$$$ is the smallest positive integer that is divisible by both $$$a$$$ and $$$b$$$. For example, $$$LCM(6, 8) = 24$$$, $$$LCM(4, 12) = 12$$$, $$$LCM(2, 3) = 6$$$.Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?

The first and only line contains an integer $$$X$$$ ($$$1 \le X \le 10^{12}$$$).

Print two positive integers, $$$a$$$ and $$$b$$$, such that the value of $$$max(a, b)$$$ is minimum possible and $$$LCM(a, b)$$$ equals $$$X$$$. If there are several possible such pairs, you can print any.


Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:  on this day the gym is closed and the contest is not carried out;  on this day the gym is closed and the contest is carried out;  on this day the gym is open and the contest is not carried out;  on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:    ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;  ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;  ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;  ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:   to do sport on any two consecutive days,  to write the contest on any two consecutive days.

NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.


A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m > n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?

The first and only input line contains two positive integers — n and m (2 ≤ n < m ≤ 50). It is guaranteed that n is prime. Pretests contain all the cases with restrictions 2 ≤ n < m ≤ 4.

Print YES, if m is the next prime number after n, or NO otherwise.


Your task is to calculate the number of arrays such that:  each array contains $$$n$$$ elements;  each element is an integer from $$$1$$$ to $$$m$$$;  for each array, there is exactly one pair of equal elements;  for each array $$$a$$$, there exists an index $$$i$$$ such that the array is strictly ascending before the $$$i$$$-th element and strictly descending after it (formally, it means that $$$a_j < a_{j + 1}$$$, if $$$j < i$$$, and $$$a_j > a_{j + 1}$$$, if $$$j \ge i$$$).

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le m \le 2 \cdot 10^5$$$).

Print one integer — the number of arrays that meet all of the aforementioned conditions, taken modulo $$$998244353$$$.


You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.

The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).

Print a single number — the length of a sought sequence.

NoteThe array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.


Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the screen as possible and fits within it completely. Thus, he may have to zoom the movie in or out, but Manao will always change the frame proportionally in both dimensions.Calculate the ratio of empty screen (the part of the screen not occupied by the movie) to the total screen size. Print the answer as an irreducible fraction p / q.

A single line contains four space-separated integers a, b, c, d (1 ≤ a, b, c, d ≤ 1000).

Print the answer to the problem as "p/q", where p is a non-negative integer, q is a positive integer and numbers p and q don't have a common divisor larger than 1.

NoteSample 1. Manao's monitor has a square screen. The movie has 3:2 horizontal to vertical length ratio. Obviously, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. In this case, only 2/3 of the monitor will project the movie in the horizontal dimension: Sample 2. This time the monitor's width is 4/3 times larger than its height and the movie's frame is square. In this case, the picture must take up the whole monitor in the vertical dimension and only 3/4 in the horizontal dimension:


Petya is having a party soon, and he has decided to invite his $$$n$$$ friends.He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with $$$k$$$ sheets. That is, each notebook contains $$$k$$$ sheets of either red, green, or blue.Find the minimum number of notebooks that Petya needs to buy to invite all $$$n$$$ of his friends.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\leq n, k\leq 10^8$$$) — the number of Petya's friends and the number of sheets in each notebook respectively.

Print one number — the minimum number of notebooks that Petya needs to buy.

NoteIn the first example, we need $$$2$$$ red notebooks, $$$3$$$ green notebooks, and $$$5$$$ blue notebooks.In the second example, we need $$$5$$$ red notebooks, $$$13$$$ green notebooks, and $$$20$$$ blue notebooks.


Consider a playoff tournament where $$$2^n$$$ athletes compete. The athletes are numbered from $$$1$$$ to $$$2^n$$$.The tournament is held in $$$n$$$ stages. In each stage, the athletes are split into pairs in such a way that each athlete belongs exactly to one pair. In each pair, the athletes compete against each other, and exactly one of them wins. The winner of each pair advances to the next stage, the athlete who was defeated gets eliminated from the tournament.The pairs are formed as follows:  in the first stage, athlete $$$1$$$ competes against athlete $$$2$$$; $$$3$$$ competes against $$$4$$$; $$$5$$$ competes against $$$6$$$, and so on;  in the second stage, the winner of the match "$$$1$$$–$$$2$$$" competes against the winner of the match "$$$3$$$–$$$4$$$"; the winner of the match "$$$5$$$–$$$6$$$" competes against the winner of the match "$$$7$$$–$$$8$$$", and so on;  the next stages are held according to the same rules. When athletes $$$x$$$ and $$$y$$$ compete, the winner is decided as follows:  if $$$x+y$$$ is odd, the athlete with the lower index wins (i. e. if $$$x < y$$$, then $$$x$$$ wins, otherwise $$$y$$$ wins);  if $$$x+y$$$ is even, the athlete with the higher index wins. The following picture describes the way the tournament with $$$n = 3$$$ goes.  Your task is the following one: given the integer $$$n$$$, determine the index of the athlete who wins the tournament.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 30$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 30$$$).

For each test case, print one integer — the index of the winner of the tournament.

NoteThe case $$$n = 3$$$ is shown in the picture from the statement.If $$$n = 1$$$, then there's only one match between athletes $$$1$$$ and $$$2$$$. Since $$$1 + 2 = 3$$$ is an odd number, the athlete with the lower index wins. So, the athlete $$$1$$$ is the winner.


n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?

The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 109, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.

Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.

NoteIn the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.In the second example Frodo can take at most four pillows, giving three pillows to each of the others.In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.


Absent-minded Masha got set of n cubes for her birthday.At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.The number can't contain leading zeros. It's not required to use all cubes to build a number.Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.

In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday. Each of next n lines contains 6 integers aij (0 ≤ aij ≤ 9) — number on j-th face of i-th cube.

Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.

NoteIn the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.


Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.  The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.

The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.

If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".

NoteThe figure above shows street directions in the second sample test case.


A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.    It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.

The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.

Print one integer — the number of seconds Vasya has to wait until he gets his lunch.

NoteIn the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.


Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≤ 1.Iahub thinks that point x belongs to segment [l, r], if inequality l ≤ x ≤ r holds.Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing.

The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤ 100) — the borders of the i-th segment. It's guaranteed that all the points are distinct.

If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.


When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2, petricium la petricium la petricium stands for k3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.

The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.


Do you remember how Kai constructed the word "eternity" using pieces of ice as components?Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry".Sheldon favourite number is t. He wants to have as many instances of t as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.

The first line contains integer t (1 ≤ t ≤ 10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.

NoteThis problem contains very weak pretests.


Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $$$n$$$ actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options:  the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by $$$1$$$;  the second option is to put candies in the box. In this case, Alya will put $$$1$$$ more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option.For example, one possible sequence of Alya's actions look as follows:  put one candy into the box;  put two candies into the box;  eat one candy from the box;  eat one candy from the box;  put three candies into the box;  eat one candy from the box;  put four candies into the box;  eat one candy from the box;  put five candies into the box; This way she will perform $$$9$$$ actions, the number of candies at the end will be $$$11$$$, while Alya will eat $$$4$$$ candies in total.You know the total number of actions $$$n$$$ and the number of candies at the end $$$k$$$. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given $$$n$$$ and $$$k$$$ the answer always exists.Please note, that during an action of the first option, Alya takes out and eats exactly one candy.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9$$$; $$$0 \le k \le 10^9$$$) — the total number of moves and the number of candies in the box at the end.  It's guaranteed, that for the given $$$n$$$ and $$$k$$$ the answer exists.

Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data.

NoteIn the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate $$$0$$$ candies.In the second example the possible sequence of Alya's actions looks as follows:   put $$$1$$$ candy,  put $$$2$$$ candies,  eat a candy,  eat a candy,  put $$$3$$$ candies,  eat a candy,  put $$$4$$$ candies,  eat a candy,  put $$$5$$$ candies.  This way, she will make exactly $$$n=9$$$ actions and in the end the box will contain $$$1+2-1-1+3-1+4-1+5=11$$$ candies. The answer is $$$4$$$, since she ate $$$4$$$ candies in total.


This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points.Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined, there were n contestants in the tournament, numbered from 1 to n. Each of them had already obtained some amount of tournament points, namely the i-th fighter had pi points.Manao is going to engage in a single fight against each contestant. Each of Manao's fights ends in either a win or a loss. A win grants Manao one point, and a loss grants Manao's opponent one point. For each i, Manao estimated the amount of effort ei he needs to invest to win against the i-th contestant. Losing a fight costs no effort.After Manao finishes all of his fights, the ranklist will be determined, with 1 being the best rank and n + 1 being the worst. The contestants will be ranked in descending order of their tournament points. The contestants with the same number of points as Manao will be ranked better than him if they won the match against him and worse otherwise. The exact mechanism of breaking ties for other fighters is not relevant here.Manao's objective is to have rank k or better. Determine the minimum total amount of effort he needs to invest in order to fulfill this goal, if it is possible.

The first line contains a pair of integers n and k (1 ≤ k ≤ n + 1). The i-th of the following n lines contains two integers separated by a single space — pi and ei (0 ≤ pi, ei ≤ 200000). The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.   In subproblem C1 (4 points), the constraint 1 ≤ n ≤ 15 will hold.  In subproblem C2 (4 points), the constraint 1 ≤ n ≤ 100 will hold.  In subproblem C3 (8 points), the constraint 1 ≤ n ≤ 200000 will hold.

Print a single number in a single line — the minimum amount of effort Manao needs to use to rank in the top k. If no amount of effort can earn Manao such a rank, output number -1.

NoteConsider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters 1 and 3, after which Manao, fighter 2, and fighter 3 will all have 2 points. Manao will rank better than fighter 3 and worse than fighter 2, thus finishing in second place.Consider the second test case. Even if Manao wins against both opponents, he will still rank third.


"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).

Output the number of participants who advance to the next round.

NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score.


To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.

The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).

Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.


A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?  One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs Wr grams and each blue candy weighs Wb grams. Eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.

The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).

Print a single integer — the maximum number of joy units that Om Nom can get.

NoteIn the sample test Om Nom can eat two candies of each type and thus get 16 joy units.


Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the n-th bit.Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded.Sergey wrote certain values of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of bits in the cell. The second line contains a string consisting of n characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.

Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.

NoteIn the first sample the cell ends up with value 0010, in the second sample — with 0000.


Polycarp is preparing the first programming contest for robots. There are $$$n$$$ problems in it, and a lot of robots are going to participate in it. Each robot solving the problem $$$i$$$ gets $$$p_i$$$ points, and the score of each robot in the competition is calculated as the sum of $$$p_i$$$ over all problems $$$i$$$ solved by it. For each problem, $$$p_i$$$ is an integer not less than $$$1$$$.Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results — or manipulating them. For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of $$$p_i$$$ in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of $$$p_i$$$ will be large, it may look very suspicious — so Polycarp wants to minimize the maximum value of $$$p_i$$$ over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of problems. The second line contains $$$n$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_n$$$ ($$$0 \le r_i \le 1$$$). $$$r_i = 1$$$ means that the "Robo-Coder Inc." robot will solve the $$$i$$$-th problem, $$$r_i = 0$$$ means that it won't solve the $$$i$$$-th problem. The third line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$0 \le b_i \le 1$$$). $$$b_i = 1$$$ means that the "BionicSolver Industries" robot will solve the $$$i$$$-th problem, $$$b_i = 0$$$ means that it won't solve the $$$i$$$-th problem.

If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer $$$-1$$$. Otherwise, print the minimum possible value of $$$\max \limits_{i = 1}^{n} p_i$$$, if all values of $$$p_i$$$ are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.

NoteIn the first example, one of the valid score assignments is $$$p = [3, 1, 3, 1, 1]$$$. Then the "Robo-Coder" gets $$$7$$$ points, the "BionicSolver" — $$$6$$$ points.In the second example, both robots get $$$0$$$ points, and the score distribution does not matter.In the third example, both robots solve all problems, so their points are equal.


Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below.  The dimension of this tile is perfect for this kitchen, as he will need exactly $$$w \times h$$$ tiles without any scraps. That is, the width of the kitchen is $$$w$$$ tiles, and the height is $$$h$$$ tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black.    The picture on the left shows one valid tiling of a $$$3 \times 2$$$ kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts. Find the number of possible tilings. As this number may be large, output its remainder when divided by $$$998244353$$$ (a prime number).

The only line contains two space separated integers $$$w$$$, $$$h$$$ ($$$1 \leq w,h \leq 1\,000$$$) — the width and height of the kitchen, measured in tiles.

Output a single integer $$$n$$$ — the remainder of the number of tilings when divided by $$$998244353$$$.


The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this.  In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).

The first line contains the chessboard coordinates of square s, the second line — of square t. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.

In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.  L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.


Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.So they play with each other according to following rules:  Alex and Bob play the first game, and Carl is spectating;  When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner. Alex, Bob and Carl play in such a way that there are no draws.Today they have played n games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!

The first line contains one integer n (1 ≤ n ≤ 100) — the number of games Alex, Bob and Carl played. Then n lines follow, describing the game log. i-th line contains one integer ai (1 ≤ ai ≤ 3) which is equal to 1 if Alex won i-th game, to 2 if Bob won i-th game and 3 if Carl won i-th game.

Print YES if the situation described in the log was possible. Otherwise print NO.

NoteIn the first example the possible situation is:  Alex wins, Carl starts playing instead of Bob;  Alex wins, Bob replaces Carl;  Bob wins. The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.


Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.Help Vasya count to which girlfriend he will go more often.

The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).

Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.

NoteLet's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often. If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.


Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.

The first line contains the positive integer a (1 ≤ a ≤ 1000) — the number of lemons Nikolay has.  The second line contains the positive integer b (1 ≤ b ≤ 1000) — the number of apples Nikolay has.  The third line contains the positive integer c (1 ≤ c ≤ 1000) — the number of pears Nikolay has.

Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.

NoteIn the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.


Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.

In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

NoteIn the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.


Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:  If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great.  If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose?

The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".

Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).

NoteIn the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.In the second sample, no choice is great, so the child will choose the luckiest choice C.In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.


For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence).You are given two positive integers n and m. Let S be the set of all sequences of length n consisting of numbers from 1 to m. Compute the sum f(a) over all a in S modulo 109 + 7.

The only line contains two integers n and m (1 ≤ n, m ≤ 106) — the number of elements in arrays and the upper bound for elements.

Print the only integer c — the desired sum modulo 109 + 7.


One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.Lesha is tired now so he asked you to split the array. Help Lesha!

The first line contains single integer n (1 ≤ n ≤ 100) — the number of elements in the array A. The next line contains n integers a1, a2, ..., an ( - 103 ≤ ai ≤ 103) — the elements of the array A.

If it is not possible to split the array A and satisfy all the constraints, print single line containing "NO" (without quotes). Otherwise in the first line print "YES" (without quotes). In the next line print single integer k — the number of new arrays. In each of the next k lines print two integers li and ri which denote the subarray A[li... ri] of the initial array A being the i-th new array. Integers li, ri should satisfy the following conditions:   l1 = 1  rk = n  ri + 1 = li + 1 for each 1 ≤ i < k.  If there are multiple answers, print any of them.


Berland Football Cup starts really soon! Commentators from all over the world come to the event.Organizers have already built $$$n$$$ commentary boxes. $$$m$$$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.If $$$n$$$ is not divisible by $$$m$$$, it is impossible to distribute the boxes to the delegations at the moment.Organizers can build a new commentary box paying $$$a$$$ burles and demolish a commentary box paying $$$b$$$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$)?

The only line contains four integer numbers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n, m \le 10^{12}$$$, $$$1 \le a, b \le 100$$$), where $$$n$$$ is the initial number of the commentary boxes, $$$m$$$ is the number of delegations to come, $$$a$$$ is the fee to build a box and $$$b$$$ is the fee to demolish a box.

Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$). It is allowed that the final number of the boxes is equal to $$$0$$$.

NoteIn the first example organizers can build $$$5$$$ boxes to make the total of $$$14$$$ paying $$$3$$$ burles for the each of them.In the second example organizers can demolish $$$2$$$ boxes to make the total of $$$0$$$ paying $$$7$$$ burles for the each of them.In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $$$5$$$ boxes.


Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing.   An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.

The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers l, s, r, p — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.

On a single line, print "YES" if an accident is possible, and "NO" otherwise.

NoteIn the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.


You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.For example, f("ab", "ba") = "aa", and f("nzwzl", "zizez") = "niwel".You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x, z) = y, or print -1 if no such string z exists.

The first line of input contains the string x. The second line of input contains the string y. Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.

If there is no string z such that f(x, z) = y, print -1. Otherwise, print a string z such that f(x, z) = y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.

NoteThe first case is from the statement.Another solution for the second case is "zizez"There is no solution for the third case. That is, there is no z such that f("ab", z) =  "ba".


A chessboard n × m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly four corner-adjacent squares painted i - 1 (all such squares are repainted simultaneously). This process continues ad infinitum. You have to figure out how many squares we repainted exactly x times.The upper left square of the board has to be assumed to be always black. Two squares are called corner-adjacent, if they have exactly one common point.

The first line contains integers n and m (1 ≤ n, m ≤ 5000). The second line contains integer x (1 ≤ x ≤ 109).

Print how many squares will be painted exactly x times.


Dawid has four bags of candies. The $$$i$$$-th of them contains $$$a_i$$$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?Note, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.

The only line contains four integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$ and $$$a_4$$$ ($$$1 \leq a_i \leq 100$$$) — the numbers of candies in each bag.

Output YES if it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).

NoteIn the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive $$$12$$$ candies.In the second sample test, it's impossible to distribute the bags.


Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc.  Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.

The first and only line of input contains three integers t, s and x (0 ≤ t, x ≤ 109, 2 ≤ s ≤ 109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.

Print a single "YES" (without quotes) if the pineapple will bark at time x or a single "NO" (without quotes) otherwise in the only line of output.

NoteIn the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.


As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.

The first line contains two lowercase English letters — the password on the phone. The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows. The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.

Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).

NoteIn the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.In the third example the string "hahahaha" contains "ah" as a substring.


Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day. Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.

The first line contains the integer n (1 ≤ n ≤ 50 000) — the number of pens Stepan has. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of milliliters of ink which the pen number i currently has.

Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above.  Pens are numbered in the order they are given in input data. The numeration begins from one.  Note that the answer is always unambiguous, since several pens can not end at the same time.

NoteIn the first test Stepan uses ink of pens as follows:   on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it;  on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it;  on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it;  on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it;  on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it;  on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it;  on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it;  on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink. So, the first pen which will not have ink is the pen number 2.


The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information.Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out.

The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format.

The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations.

4
XOOO
XXOO
OOOO
XXXX
XOOO
XOOO
XOXO
XOXX

NoteIn the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.


Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n1 + n2 + ... + nk = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition ni ≥ 2 should hold for all i from 1 to k.Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.

The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) — the total year income of mr. Funt.

Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.


You are given a regular polygon with $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.Calculate the minimum weight among all triangulations of the polygon.

The first line contains single integer $$$n$$$ ($$$3 \le n \le 500$$$) — the number of vertices in the regular polygon.

Print one integer — the minimum weight among all triangulations of the given polygon.

NoteAccording to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $$$P$$$ into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is $$$P$$$.In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $$$1 \cdot 2 \cdot 3 = 6$$$.In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $$$1-3$$$ so answer is $$$1 \cdot 2 \cdot 3 + 1 \cdot 3 \cdot 4 = 6 + 12 = 18$$$.


There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:   this list contains all Jinotega's flights in this year (in arbitrary order),  Jinotega has only flown from his hometown to a snooker contest and back,  after each competition Jinotega flies back home (though they may attend a competition in one place several times),  and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location!

In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.

If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".

4
SVO
SVO->CDG
LHR->SVO
SVO->LHR
CDG->SVO

NoteIn the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.


Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m.Number x is considered close to number n modulo m, if:  it can be obtained by rearranging the digits of number n,  it doesn't have any leading zeroes,  the remainder after dividing number x by m equals 0. Roman is a good mathematician, but the number of such numbers is too huge for him. So he asks you to help him.

The first line contains two integers: n (1 ≤ n < 1018) and m (1 ≤ m ≤ 100).

In a single line print a single integer — the number of numbers close to number n modulo m.

NoteIn the first sample the required numbers are: 104, 140, 410.In the second sample the required number is 232.