Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:  if the last digit of the number is non-zero, she decreases the number by one;  if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $$$n$$$. Tanya will subtract one from it $$$k$$$ times. Your task is to print the result after all $$$k$$$ subtractions.It is guaranteed that the result will be positive integer number.

The first line of the input contains two integer numbers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le k \le 50$$$) — the number from which Tanya will subtract and the number of subtractions correspondingly.

Print one integer number — the result of the decreasing $$$n$$$ by one $$$k$$$ times. It is guaranteed that the result will be positive integer number.

NoteThe first example corresponds to the following sequence: $$$512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$$$.


The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1 ≤ d < n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d + 1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day d + 1) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel.The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.

The first line contains two space-separated integers, n and c (2 ≤ n ≤ 100, 0 ≤ c ≤ 100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100), the price of a honey barrel on day i.

Print a single integer — the answer to the problem.

NoteIn the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.


Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below.

Input will consist of a single integer A (1 ≤ A ≤ 105), the desired number of ways.

In the first line print integers N and M (1 ≤ N ≤ 106, 1 ≤ M ≤ 10), the amount of change to be made, and the number of denominations, respectively. Then print M integers D1, D2, ..., DM (1 ≤ Di ≤ 106), the denominations of the coins. All denominations must be distinct: for any i ≠ j we must have Di ≠ Dj. If there are multiple tests, print any of them. You can print denominations in atbitrary order.


Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).  Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.

The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.

In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).

NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right.


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$$$.


Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.You are given a string $$$s$$$ consisting of $$$n$$$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $$$s$$$ = "BBAABBBA" the answer is two-gram "BB", which contained in $$$s$$$ three times. In other words, find any most frequent two-gram.Note that occurrences of the two-gram can overlap with each other.

The first line of the input contains integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ capital Latin letters.

Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $$$s$$$ as a substring (i.e. two consecutive characters of the string) maximal number of times.

NoteIn the first example "BA" is also valid answer.In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.


So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

NoteIn the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.In the second sample letter "P" is missing from the pile and there's an extra letter "L".In the third sample there's an extra letter "L".


Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

Output one integer — the answer to the problem.

NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\textbf 7$$$] Weight 2: [$$$\textbf 3$$$, $$$\textbf 3$$$, 1] Weight 3: [$$$\textbf 2$$$, $$$\textbf 2$$$, $$$\textbf 2$$$, 1] Weight 7: [$$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$]


Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.For each two integer numbers a and b such that l ≤ a ≤ r and x ≤ b ≤ y there is a potion with experience a and cost b in the store (that is, there are (r - l + 1)·(y - x + 1) potions).Kirill wants to buy a potion which has efficiency k. Will he be able to do this?

First string contains five integer numbers l, r, x, y, k (1 ≤ l ≤ r ≤ 107, 1 ≤ x ≤ y ≤ 107, 1 ≤ k ≤ 107).

Print "YES" without quotes if a potion with efficiency exactly k can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.


ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?

The first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.

If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print  - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.

NoteIn the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1.In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.


Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3. Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, которые пришли вовремя, вам предстоит определить номер опоздавшего брата.

В первой строке входных данных следуют два различных целых числа a и b (1 ≤ a, b ≤ 3, a ≠ b) — номера братьев, которые пришли на встречу вовремя. Номера даны в произвольном порядке.

Выведите единственное целое число — номер брата, который опоздал на встречу.


The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A - B is minimum possible. Help the teacher and find the least possible value of A - B.

The first line contains space-separated integers n and m (2 ≤ n ≤ m ≤ 50). The second line contains m space-separated integers f1, f2, ..., fm (4 ≤ fi ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.

Print a single integer — the least possible difference the teacher can obtain.

NoteSample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.


Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.They will be N guests tonight: N - 1 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to N - 1, and Heidi, who still appears slightly different from the others, is attributed the highest rank, N. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure:The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes – in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.)You should know that zombies are very greedy and sly, and they know this too – basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order:   survive the event (they experienced death already once and know it is no fun),  get as many brains as possible. Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself.What is the smallest number of brains that have to be in the chest for this to be possible?

The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).

Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home.


The only difference between easy and hard versions is the length of the string.You are given a string $$$s$$$ and a string $$$t$$$, both consisting only of lowercase Latin letters. It is guaranteed that $$$t$$$ can be obtained from $$$s$$$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $$$s$$$ without changing order of remaining characters (in other words, it is guaranteed that $$$t$$$ is a subsequence of $$$s$$$).For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".You want to remove some substring (contiguous subsequence) from $$$s$$$ of maximum possible length such that after removing this substring $$$t$$$ will remain a subsequence of $$$s$$$.If you want to remove the substring $$$s[l;r]$$$ then the string $$$s$$$ will be transformed to $$$s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$$$ (where $$$|s|$$$ is the length of $$$s$$$).Your task is to find the maximum possible length of the substring you can remove so that $$$t$$$ is still a subsequence of $$$s$$$.

The first line of the input contains one string $$$s$$$ consisting of at least $$$1$$$ and at most $$$200$$$ lowercase Latin letters. The second line of the input contains one string $$$t$$$ consisting of at least $$$1$$$ and at most $$$200$$$ lowercase Latin letters. It is guaranteed that $$$t$$$ is a subsequence of $$$s$$$.

Print one integer — the maximum possible length of the substring you can remove so that $$$t$$$ is still a subsequence of $$$s$$$.


Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.Help Kurt find the maximum possible product of digits among all integers from $$$1$$$ to $$$n$$$.

The only input line contains the integer $$$n$$$ ($$$1 \le n \le 2\cdot10^9$$$).

Print the maximum product of digits among all integers from $$$1$$$ to $$$n$$$.

NoteIn the first example the maximum product is achieved for $$$389$$$ (the product of digits is $$$3\cdot8\cdot9=216$$$).In the second example the maximum product is achieved for $$$7$$$ (the product of digits is $$$7$$$).In the third example the maximum product is achieved for $$$999999999$$$ (the product of digits is $$$9^9=387420489$$$).


One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.

The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.

It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.


Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.

The first line contains two integers x1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot. The second line contains two integers x2, y2 ( - 109 ≤ x2, y2 ≤ 109) — the finish position of the robot.

Print the only integer d — the minimal number of steps to get the finish position.

NoteIn the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.


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.


Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1, 2, ..., z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.

The only string contains three integers — n, m and z (1 ≤ n, m, z ≤ 104).

Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.

NoteTaymyr is a place in the north of Russia.In the first test the artists come each minute, as well as the calls, so we need to kill all of them.In the second test we need to kill artists which come on the second and the fourth minutes.In the third test — only the artist which comes on the sixth minute.


Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are $$$n$$$ parties, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th party has received $$$a_i$$$ seats in the parliament.Alice's party has number $$$1$$$. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil:   The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has $$$200$$$ (or $$$201$$$) seats, then the majority is $$$101$$$ or more seats.  Alice's party must have at least $$$2$$$ times more seats than any other party in the coalition. For example, to invite a party with $$$50$$$ seats, Alice's party must have at least $$$100$$$ seats. For example, if $$$n=4$$$ and $$$a=[51, 25, 99, 25]$$$ (note that Alice'a party has $$$51$$$ seats), then the following set $$$[a_1=51, a_2=25, a_4=25]$$$ can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition:  $$$[a_2=25, a_3=99, a_4=25]$$$ since Alice's party is not there;  $$$[a_1=51, a_2=25]$$$ since coalition should have a strict majority;  $$$[a_1=51, a_2=25, a_3=99]$$$ since Alice's party should have at least $$$2$$$ times more seats than any other party in the coalition. Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice's party has enough people to create a coalition on her own, she can invite no parties.Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.Find and print any suitable coalition.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of parties. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 100$$$) — the number of seats the $$$i$$$-th party has.

If no coalition satisfying both conditions is possible, output a single line with an integer $$$0$$$. Otherwise, suppose there are $$$k$$$ ($$$1 \leq k \leq n$$$) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are $$$c_1, c_2, \dots, c_k$$$ ($$$1 \leq c_i \leq n$$$). Output two lines, first containing the integer $$$k$$$, and the second the space-separated indices $$$c_1, c_2, \dots, c_k$$$.  You may print the parties in any order. Alice's party (number $$$1$$$) must be on that list. If there are multiple solutions, you may print any of them.

NoteIn the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because $$$100$$$ is not a strict majority out of $$$200$$$.In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.In the third example, Alice already has the majority. The fourth example is described in the problem statement.


Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first k Latin letters and not containing any other ones. Also, the title should be a palindrome, that is it should be read similarly from the left to the right and from the right to the left.Vasya has already composed the approximate variant of the title. You are given the title template s consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues.

The first line contains an integer k (1 ≤ k ≤ 26) which is the number of allowed alphabet letters. The second line contains s which is the given template. In s only the first k lowercase letters of Latin alphabet and question marks can be present, the length of s is from 1 to 100 characters inclusively.

If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first k letters of the Latin alphabet. At that, each of those k letters must be present at least once. If there are several suitable titles, print the lexicographically minimal one.  The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if exists such an i (1 ≤ i ≤ |s|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |s| stands for the length of the given template.


There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmost digit of A and appends it to his or her number Si. After that this leftmost digit is erased from A. Initially the numbers of both players (S1 and S2) are «empty». Leading zeroes in numbers A, S1, S2 are allowed. In the end of the game the first player gets S1 dollars, and the second gets S2 dollars.One day Homer and Marge came to play the game. They managed to know the number A beforehand. They want to find such sequence of their moves that both of them makes exactly n moves and which maximizes their total prize. Help them.

The first line contains integer n (1 ≤ n ≤ 18). The second line contains integer A consisting of exactly 2n digits. This number can have leading zeroes.

Output the line of 2n characters «H» and «M» — the sequence of moves of Homer and Marge, which gives them maximum possible total prize. Each player must make exactly n moves. If there are several solutions, output any of them.


There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission. Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.

The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with ) – the desired counts of lightsabers of each color from 1 to m.

Output YES if an interval with prescribed color counts exists, or output NO if there is none.


Mishka got a six-faced dice. It has integer numbers from $$$2$$$ to $$$7$$$ written on its faces (all numbers on faces are different, so this is an almost usual dice).Mishka wants to get exactly $$$x$$$ points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly $$$x$$$ points for them. Mishka is very lucky, so if the probability to get $$$x$$$ points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.Mishka is also very curious about different number of points to score so you have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. Each of the next $$$t$$$ lines contains one integer each. The $$$i$$$-th line contains one integer $$$x_i$$$ ($$$2 \le x_i \le 100$$$) — the number of points Mishka wants to get.

Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query (i.e. any number of rolls Mishka can make to be able to get exactly $$$x_i$$$ points for them). It is guaranteed that at least one answer exists.

NoteIn the first query Mishka can roll a dice once and get $$$2$$$ points.In the second query Mishka can roll a dice $$$3$$$ times and get points $$$5$$$, $$$5$$$ and $$$3$$$ (for example).In the third query Mishka can roll a dice $$$8$$$ times and get $$$5$$$ points $$$7$$$ times and $$$2$$$ points with the remaining roll.In the fourth query Mishka can roll a dice $$$27$$$ times and get $$$2$$$ points $$$11$$$ times, $$$3$$$ points $$$6$$$ times and $$$6$$$ points $$$10$$$ times.


One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as  lines, drinks another cup of tea, then he writes  lines and so on: , , , ...The expression  is regarded as the integral part from dividing number a by number b.The moment the current value  equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.Vasya is wondering, what minimum allowable value v can take to let him write not less than n lines of code before he falls asleep.

The input consists of two integers n and k, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1 ≤ n ≤ 109, 2 ≤ k ≤ 10.

Print the only integer — the minimum value of v that lets Vasya write the program in one night.

NoteIn the first sample the answer is v = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.In the second sample the answer is v = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than n = 59.


Allen has a LOT of money. He has $$$n$$$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $$$1$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$100$$$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?

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

Output the minimum number of bills that Allen could receive.

NoteIn the first sample case, Allen can withdraw this with a $$$100$$$ dollar bill, a $$$20$$$ dollar bill, and a $$$5$$$ dollar bill. There is no way for Allen to receive $$$125$$$ dollars in one or two bills.In the second sample case, Allen can withdraw two $$$20$$$ dollar bills and three $$$1$$$ dollar bills.In the third sample case, Allen can withdraw $$$100000000$$$ (ten million!) $$$100$$$ dollar bills.


Amr loves Geometry. One day he came up with a very interesting problem.Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.Help Amr to achieve his goal in minimum number of steps.

Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105,  - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.

Output a single integer — minimum number of steps required to move the center of the circle to the destination point.

NoteIn the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).


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.


The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:   At least one participant should get a diploma.  None of those with score equal to zero should get awarded.  When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≤ ai ≤ 600) — participants' scores. It's guaranteed that at least one participant has non-zero score.

Print a single integer — the desired number of ways.

NoteThere are three ways to choose a subset in sample case one.  Only participants with 3 points will get diplomas.  Participants with 2 or 3 points will get diplomas.  Everyone will get a diploma! The only option in sample case two is to award everyone.Note that in sample case three participants with zero scores cannot get anything.


Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.

The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).

Output the decoded ternary number. It can have leading zeroes.


Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:   one resistor;  an element and one resistor plugged in sequence;  an element and one resistor plugged in parallel.   With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals . In this case Re equals the resistance of the element being connected.Mike needs to assemble an element with a resistance equal to the fraction . Determine the smallest possible number of resistors he needs to make such an element.

The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction  is irreducible. It is guaranteed that a solution always exists.

Print a single number — the answer to the problem. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample, one resistor is enough.In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance . We cannot make this element using two resistors.


One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

Input data contains the only number n (1 ≤ n ≤ 109).

Output the only number — answer to the problem.

NoteFor n = 10 the answer includes numbers 1 and 10.


There are $$$n$$$ benches in the Berland Central park. It is known that $$$a_i$$$ people are currently sitting on the $$$i$$$-th bench. Another $$$m$$$ people are coming to the park and each of them is going to have a seat on some bench out of $$$n$$$ available.Let $$$k$$$ be the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park. Calculate the minimum possible $$$k$$$ and the maximum possible $$$k$$$.Nobody leaves the taken seat during the whole process.

The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of benches in the park. The second line contains a single integer $$$m$$$ $$$(1 \le m \le 10\,000)$$$ — the number of people additionally coming to the park. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ $$$(1 \le a_i \le 100)$$$ — the initial number of people on the $$$i$$$-th bench.

Print the minimum possible $$$k$$$ and the maximum possible $$$k$$$, where $$$k$$$ is the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park.

NoteIn the first example, each of four benches is occupied by a single person. The minimum $$$k$$$ is $$$3$$$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum $$$k$$$ is $$$7$$$. That requires all six new people to occupy the same bench.The second example has its minimum $$$k$$$ equal to $$$15$$$ and maximum $$$k$$$ equal to $$$15$$$, as there is just a single bench in the park and all $$$10$$$ people will occupy it.


Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6.The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.

The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend.  The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b.

Print the minimum possible total tiredness if the friends meet in the same point.

NoteIn the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.


Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers. The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can print each letter in arbitrary case (small or large).

NoteIn the first example the integers can denote months July, August, September and October.In the second example the answer is no, because there are no two consecutive months each having 30 days.In the third example the months are: February (leap year) — March — April – May — June.In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.In the fifth example the months are: December — January — February (non-leap year).


You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into $$$w\times h$$$ cells. There should be $$$k$$$ gilded rings, the first one should go along the edge of the plate, the second one — $$$2$$$ cells away from the edge and so on. Each ring has a width of $$$1$$$ cell. Formally, the $$$i$$$-th of these rings should consist of all bordering cells on the inner rectangle of size $$$(w - 4(i - 1))\times(h - 4(i - 1))$$$.  The picture corresponds to the third example. Your task is to compute the number of cells to be gilded.

The only line contains three integers $$$w$$$, $$$h$$$ and $$$k$$$ ($$$3 \le w, h \le 100$$$, $$$1 \le k \le \left\lfloor \frac{min(n, m) + 1}{4}\right\rfloor$$$, where $$$\lfloor x \rfloor$$$ denotes the number $$$x$$$ rounded down) — the number of rows, columns and the number of rings, respectively.

Print a single positive integer — the number of cells to be gilded.

NoteThe first example is shown on the picture below.  The second example is shown on the picture below.  The third example is shown in the problem description.


Stepan has a very big positive integer.Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203 and integers 20310 and 31020.Stepan wants to know the minimum remainder of the division by the given number m among all good shifts. Your task is to determine the minimum remainder of the division by m.

The first line contains the integer which Stepan has. The length of Stepan's integer is between 2 and 200 000 digits, inclusive. It is guaranteed that Stepan's integer does not contain leading zeros. The second line contains the integer m (2 ≤ m ≤ 108) — the number by which Stepan divides good shifts of his integer.

Print the minimum remainder which Stepan can get if he divides all good shifts of his integer by the given number m.

NoteIn the first example all good shifts of the integer 521 (good shifts are equal to 521, 215 and 152) has same remainder 2 when dividing by 3.In the second example there are only two good shifts: the Stepan's integer itself and the shift by one position to the right. The integer itself is 1001 and the remainder after dividing it by 5 equals 1. The shift by one position to the right equals to 1100 and the remainder after dividing it by 5 equals 0, which is the minimum possible remainder.


Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Print the maximum number that Pasha can get if he makes at most k swaps.


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.


You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly $$$k\ \%$$$ magic essence and $$$(100 - k)\ \%$$$ water.In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.A small reminder: if you pour $$$e$$$ liters of essence and $$$w$$$ liters of water ($$$e + w > 0$$$) into the cauldron, then it contains $$$\frac{e}{e + w} \cdot 100\ \%$$$ (without rounding) magic essence and $$$\frac{w}{e + w} \cdot 100\ \%$$$ water.

The first line contains the single $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first and only line of each test case contains a single integer $$$k$$$ ($$$1 \le k \le 100$$$) — the percentage of essence in a good potion.

For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.

NoteIn the first test case, you should pour $$$3$$$ liters of magic essence and $$$97$$$ liters of water into the cauldron to get a potion with $$$3\ \%$$$ of magic essence.In the second test case, you can pour only $$$1$$$ liter of essence to get a potion with $$$100\ \%$$$ of magic essence.In the third test case, you can pour $$$1$$$ liter of magic essence and $$$3$$$ liters of water.


Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.Note that to display number 0 section of the watches is required to have at least one place.Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.

The first line of the input contains two integers, given in the decimal notation, n and m (1 ≤ n, m ≤ 109) — the number of hours in one day and the number of minutes in one hour, respectively.

Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.

NoteIn the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).


Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print  - 1.

The single line contains two numbers, n and t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10) — the length of the number and the number it should be divisible by.

Print one such positive number without leading zeroes, — the answer to the problem, or  - 1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.


Let's consider equation:x2 + s(x)·x - n = 0,  where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots.

A single line contains integer n (1 ≤ n ≤ 1018) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds.

NoteIn the first test case x = 1 is the minimum root. As s(1) = 1 and 12 + 1·1 - 2 = 0.In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 102 + 1·10 - 110 = 0.In the third test case the equation has no roots.


Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from  - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor  - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,  - 180, 808 are all lucky while 42,  - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.

The only line of input contains an integer a ( - 109 ≤ a ≤ 109).

NoteFor the first sample, he has to arrive at the floor numbered 180.For the second sample, he will arrive at 8.Note that b should be positive, so the answer for the third sample is 10, not 0.


Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.You are given a 3 × 3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:   illegal — if the given board layout can't appear during a valid game;  the first player won — if in the given board layout the first player has just won;  the second player won — if in the given board layout the second player has just won;  draw — if the given board layout has just let to a draw.

The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).

Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.


The circle line of the Roflanpolis subway has $$$n$$$ stations.There are two parallel routes in the subway. The first one visits stations in order $$$1 \to 2 \to \ldots \to n \to 1 \to 2 \to \ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x+1)$$$ if $$$x < n$$$ and $$$1$$$ otherwise). The second route visits stations in order $$$n \to (n-1) \to \ldots \to 1 \to n \to (n-1) \to \ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x-1)$$$ if $$$x>1$$$ and $$$n$$$ otherwise). All trains depart their stations simultaneously, and it takes exactly $$$1$$$ minute to arrive at the next station.Two toads live in this city, their names are Daniel and Vlad.Daniel is currently in a train of the first route at station $$$a$$$ and will exit the subway when his train reaches station $$$x$$$.Coincidentally, Vlad is currently in a train of the second route at station $$$b$$$ and he will exit the subway when his train reaches station $$$y$$$.Surprisingly, all numbers $$$a,x,b,y$$$ are distinct.Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.

The first line contains five space-separated integers $$$n$$$, $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ ($$$4 \leq n \leq 100$$$, $$$1 \leq a, x, b, y \leq n$$$, all numbers among $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.

Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).

NoteIn the first example, Daniel and Vlad start at the stations $$$(1, 3)$$$. One minute later they are at stations $$$(2, 2)$$$. They are at the same station at this moment. Note that Vlad leaves the subway right after that.Consider the second example, let's look at the stations Vlad and Daniel are at. They are:   initially $$$(2, 9)$$$,  after $$$1$$$ minute $$$(3, 8)$$$,  after $$$2$$$ minutes $$$(4, 7)$$$,  after $$$3$$$ minutes $$$(5, 6)$$$,  after $$$4$$$ minutes $$$(6, 5)$$$,  after $$$5$$$ minutes $$$(7, 4)$$$,  after $$$6$$$ minutes $$$(8, 3)$$$,  after $$$7$$$ minutes $$$(9, 2)$$$,  after $$$8$$$ minutes $$$(10, 1)$$$,  after $$$9$$$ minutes $$$(1, 10)$$$. After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station.


A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci roubles. The number of bottles of each type in the store can be considered infinite.You want to buy at least L liters of lemonade. How many roubles do you have to spend?

The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 109) — the costs of bottles of different types.

Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.

NoteIn the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.


Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers "A factorial" and "B factorial". Formally the hacker wants to find out GCD(A!, B!). It's well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1·2·3·...·(x - 1)·x. For example 4! = 1·2·3·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y.Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?

The first and single line contains two integers A and B (1 ≤ A, B ≤ 109, min(A, B) ≤ 12).

Print a single integer denoting the greatest common divisor of integers A! and B!.

NoteConsider the sample.4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.


Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", — Volodya said and was right for sure. And your task is to say whether whites had won or not.Pieces on the chessboard are guaranteed to represent a correct position (every piece occupies one cell, no two pieces occupy the same cell and kings cannot take each other). Thus, your task is only to decide whether whites mate blacks. We would remind you that it means that the black king can be taken by one of the opponent's pieces at the moment and also it cannot move to an unbeaten position. A rook moves vertically or horizontally by any number of free cells (assuming there are no other pieces on its path), a king — to the adjacent cells (either by corner or by side). Certainly, pieces cannot leave the board. The black king might be able to take opponent's rooks at his turn (see sample 3).

The input contains 4 space-separated piece positions: positions of the two rooks, the white king and the black king. Each position on 8 × 8 chessboard is denoted by two symbols — ('a' - 'h') and ('1' - '8') — which stand for horizontal and vertical coordinates of the cell occupied by the piece. It is guaranteed, that no two pieces occupy the same cell, and kings cannot take each other.

Output should contain one word: "CHECKMATE" if whites mate blacks, and "OTHER" otherwise.


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.

The only line contains an integer n (1 ≤ n ≤ 1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).

NoteIn the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".In the third sample there are no lucky digits, so the answer is "NO".


The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one). When the guesser is answered "4 bulls 0 cows", the game is over.Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.

The first input line contains an integer n (1 ≤ n ≤ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 ≤ i ≤ n, 0 ≤ bi, ci, bi + ci ≤ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.

If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.


Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:  on Mondays, Thursdays and Sundays he eats fish food;  on Tuesdays and Saturdays he eats rabbit stew;  on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains:  $$$a$$$ daily rations of fish food;  $$$b$$$ daily rations of rabbit stew;  $$$c$$$ daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

The first line of the input contains three positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 7\cdot10^8$$$) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.

NoteIn the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday — rabbit stew and during Wednesday — chicken stake. So, after four days of the trip all food will be eaten.In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack.In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be $$$99$$$ portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.


Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.

The first line contains a single integer n (2 ≤ n ≤ 100) — number of cards. It is guaranteed that n is an even number. The following n lines contain a sequence of integers a1, a2, ..., an (one integer per line, 1 ≤ ai ≤ 100) — numbers written on the n cards.

If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.

NoteIn the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.


The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:    Elements of the main diagonal.   Elements of the secondary diagonal.   Elements of the "middle" row — the row which has exactly  rows above it and the same number of rows below it.   Elements of the "middle" column — the column that has exactly  columns to the left of it and the same number of columns to the right of it.    The figure shows a 5 × 5 matrix.   The good elements are marked with green.  Help the Smart Beaver count the sum of good elements of the given matrix.

The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are:    1 ≤ n ≤ 5  The input limitations for getting 100 points are:   1 ≤ n ≤ 101

Print a single integer — the sum of good matrix elements.

NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.


Alice and Bob are decorating a Christmas Tree. Alice wants only $$$3$$$ types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have $$$y$$$ yellow ornaments, $$$b$$$ blue ornaments and $$$r$$$ red ornaments.In Bob's opinion, a Christmas Tree will be beautiful if:  the number of blue ornaments used is greater by exactly $$$1$$$ than the number of yellow ornaments, and  the number of red ornaments used is greater by exactly $$$1$$$ than the number of blue ornaments. That is, if they have $$$8$$$ yellow ornaments, $$$13$$$ blue ornaments and $$$9$$$ red ornaments, we can choose $$$4$$$ yellow, $$$5$$$ blue and $$$6$$$ red ornaments ($$$5=4+1$$$ and $$$6=5+1$$$).Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.In the example two paragraphs above, we would choose $$$7$$$ yellow, $$$8$$$ blue and $$$9$$$ red ornaments. If we do it, we will use $$$7+8+9=24$$$ ornaments. That is the maximum number.Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree! It is guaranteed that it is possible to choose at least $$$6$$$ ($$$1+2+3=6$$$) ornaments.

The only line contains three integers $$$y$$$, $$$b$$$, $$$r$$$ ($$$1 \leq y \leq 100$$$, $$$2 \leq b \leq 100$$$, $$$3 \leq r \leq 100$$$) — the number of yellow, blue and red ornaments.  It is guaranteed that it is possible to choose at least $$$6$$$ ($$$1+2+3=6$$$) ornaments.

Print one number — the maximum number of ornaments that can be used.

NoteIn the first example, the answer is $$$7+8+9=24$$$.In the second example, the answer is $$$2+3+4=9$$$.


Right now she actually isn't. But she will be, if you don't solve this problem.You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations:   Subtract 1 from x. This operation costs you A coins.  Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins.  What is the minimum amount of coins you have to pay to make x equal to 1?

The first line contains a single integer n (1 ≤ n ≤ 2·109). The second line contains a single integer k (1 ≤ k ≤ 2·109). The third line contains a single integer A (1 ≤ A ≤ 2·109). The fourth line contains a single integer B (1 ≤ B ≤ 2·109).

Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.

NoteIn the first testcase, the optimal strategy is as follows:   Subtract 1 from x (9 → 8) paying 3 coins.  Divide x by 2 (8 → 4) paying 1 coin.  Divide x by 2 (4 → 2) paying 1 coin.  Divide x by 2 (2 → 1) paying 1 coin. The total cost is 6 coins.In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total.


Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.

The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.

Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.


Recently Vasya found a golden ticket — a sequence which consists of $$$n$$$ digits $$$a_1a_2\dots a_n$$$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $$$350178$$$ is lucky since it can be divided into three segments $$$350$$$, $$$17$$$ and $$$8$$$: $$$3+5+0=1+7=8$$$. Note that each digit of sequence should belong to exactly one segment.Help Vasya! Tell him if the golden ticket he found is lucky or not.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of digits in the ticket. The second line contains $$$n$$$ digits $$$a_1 a_2 \dots a_n$$$ ($$$0 \le a_i \le 9$$$) — the golden ticket. Digits are printed without spaces.

If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).

NoteIn the first example the ticket can be divided into $$$7$$$, $$$34$$$ and $$$52$$$: $$$7=3+4=5+2$$$.In the second example it is impossible to divide ticket into segments with equal sum.


Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Print a single integer, denoting the minimum possible height of the tallest tower.

NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.


You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?

The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a. The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.

Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.

NoteIn the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C =  - 2, B - C = 3.In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.


Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $$$A$$$ students, BeaverKing — by $$$B$$$ students and $$$C$$$ students visited both restaurants. Vasya also knows that there are $$$N$$$ students in his group.Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?

The first line contains four integers — $$$A$$$, $$$B$$$, $$$C$$$ and $$$N$$$ ($$$0 \leq A, B, C, N \leq 100$$$).

If a distribution of $$$N$$$ students exists in which $$$A$$$ students visited BugDonalds, $$$B$$$ — BeaverKing, $$$C$$$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.  If such a distribution does not exist and Vasya made a mistake while determining the numbers $$$A$$$, $$$B$$$, $$$C$$$ or $$$N$$$ (as in samples 2 and 3), output $$$-1$$$.

NoteThe first sample describes following situation: $$$5$$$ only visited BugDonalds, $$$5$$$ students only visited BeaverKing, $$$5$$$ visited both of them and $$$5$$$ students (including Vasya) didn't pass the exam.In the second sample $$$2$$$ students only visited BugDonalds and $$$2$$$ only visited BeaverKing, but that means all $$$4$$$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.The third sample describes a situation where $$$2$$$ students visited BugDonalds but the group has only $$$1$$$ which makes it clearly impossible.


Let's call a string good if and only if it consists of only two types of letters — 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings and "abb" is a bad string.You have $$$a$$$ strings "a", $$$b$$$ strings "b" and $$$c$$$ strings "ab". You want to choose some subset of these strings and concatenate them in any arbitrarily order.What is the length of the longest good string you can obtain this way?

The first line contains three positive integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \leq a, b, c \leq 10^9$$$) — the number of strings "a", "b" and "ab" respectively.

Print a single number — the maximum possible length of the good string you can obtain.

NoteIn the first example the optimal string is "baba".In the second example the optimal string is "abababa".In the third example the optimal string is "bababababab".In the fourth example the optimal string is "ababab".


Polycarp loves ciphers. He has invented his own cipher called repeating.Repeating cipher is used for strings. To encrypt the string $$$s=s_{1}s_{2} \dots s_{m}$$$ ($$$1 \le m \le 10$$$), Polycarp uses the following algorithm:  he writes down $$$s_1$$$ ones,  he writes down $$$s_2$$$ twice,  he writes down $$$s_3$$$ three times,  ...  he writes down $$$s_m$$$ $$$m$$$ times. For example, if $$$s$$$="bab" the process is: "b" $$$\to$$$ "baa" $$$\to$$$ "baabbb". So the encrypted $$$s$$$="bab" is "baabbb".Given string $$$t$$$ — the result of encryption of some string $$$s$$$. Your task is to decrypt it, i. e. find the string $$$s$$$.

The first line contains integer $$$n$$$ ($$$1 \le n \le 55$$$) — the length of the encrypted string. The second line of the input contains $$$t$$$ — the result of encryption of some string $$$s$$$. It contains only lowercase Latin letters. The length of $$$t$$$ is exactly $$$n$$$. It is guaranteed that the answer to the test exists.

Print such string $$$s$$$ that after encryption it equals $$$t$$$.


Today, Mezo is playing a game. Zoma, a character in that game, is initially at position $$$x = 0$$$. Mezo starts sending $$$n$$$ commands to Zoma. There are two possible commands:  'L' (Left) sets the position $$$x: =x - 1$$$;  'R' (Right) sets the position $$$x: =x + 1$$$. Unfortunately, Mezo's controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position $$$x$$$ doesn't change and Mezo simply proceeds to the next command.For example, if Mezo sends commands "LRLR", then here are some possible outcomes (underlined commands are sent successfully):   "LRLR" — Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position $$$0$$$;  "LRLR" — Zoma recieves no commands, doesn't move at all and ends up at position $$$0$$$ as well;  "LRLR" — Zoma moves to the left, then to the left again and ends up in position $$$-2$$$. Mezo doesn't know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.

The first line contains $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of commands Mezo sends. The second line contains a string $$$s$$$ of $$$n$$$ commands, each either 'L' (Left) or 'R' (Right).

Print one integer — the number of different positions Zoma may end up at.

NoteIn the example, Zoma may end up anywhere between $$$-2$$$ and $$$2$$$.


n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.The game consists of m steps. On each step the current leader with index i counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.You are given numbers l1, l2, ..., lm — indices of leaders in the beginning of each step. Child with number l1 is the first leader in the game. Write a program which will restore a possible permutation a1, a2, ..., an. If there are multiple solutions then print any of them. If there is no solution then print -1.

The first line contains two integer numbers n, m (1 ≤ n, m ≤ 100). The second line contains m integer numbers l1, l2, ..., lm (1 ≤ li ≤ n) — indices of leaders in the beginning of each step.

Print such permutation of n numbers a1, a2, ..., an that leaders in the game will be exactly l1, l2, ..., lm if all the rules are followed. If there are multiple solutions print any of them.  If there is no permutation which satisfies all described conditions print -1.

NoteLet's follow leadership in the first example:   Child 2 starts.  Leadership goes from 2 to 2 + a2 = 3.  Leadership goes from 3 to 3 + a3 = 5. As it's greater than 4, it's going in a circle to 1.  Leadership goes from 1 to 1 + a1 = 4.  Leadership goes from 4 to 4 + a4 = 8. Thus in circle it still remains at 4.


In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?

The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).

Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.


Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $$$360$$$ degrees and a pointer which initially points at zero:  Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $$$n$$$ times. The $$$i$$$-th rotation should be $$$a_i$$$ degrees, either clockwise or counterclockwise, and after all $$$n$$$ rotations the pointer should again point at zero.This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $$$n$$$ rotations the pointer will point at zero again.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 15$$$) — the number of rotations. Each of the following $$$n$$$ lines contains one integer $$$a_i$$$ ($$$1 \leq a_i \leq 180$$$) — the angle of the $$$i$$$-th rotation in degrees.

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower).

NoteIn the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $$$360$$$ degrees clockwise and the pointer will point at zero again.


Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has a, b, c, a, b and c adjacent tiles, correspondingly.To better visualize the situation, look at the picture showing a similar hexagon for a = 2, b = 3 and c = 4.  According to the legend, as the King of Berland obtained the values a, b and c, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?

The first line contains three integers: a, b and c (2 ≤ a, b, c ≤ 1000).

Print a single number — the total number of tiles on the hall floor.


When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead."What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone.""But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.

The first and only line of input contains a non-empty string $$$s$$$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($$$\lvert s \rvert \leq 100$$$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.

Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).

NoteIn the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.