question
stringlengths
29
1.88k
test_input
listlengths
0
10
test_output
listlengths
0
10
test_time_limit
int64
1
1
test_method
stringclasses
1 value
Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way. -----Input----- The first line of the input contains a positive integer n (1 ≤ n ≤ 2·10^9) — the length of Pasha's stick. -----Output----- The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. -----Examples----- Input 6 Output 1 Input 20 Output 4 -----Note----- There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
[ "6\n", "20\n", "1\n", "2\n", "3\n", "4\n", "2000000000\n", "1924704072\n", "73740586\n", "1925088820\n" ]
[ "1\n", "4\n", "0\n", "0\n", "0\n", "0\n", "499999999\n", "481176017\n", "18435146\n", "481272204\n" ]
1
stdio
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? [Image] One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs W_{r} grams and each blue candy weighs W_{b} grams. Eating a single red candy gives Om Nom H_{r} joy units and eating a single blue candy gives Om Nom H_{b} joy units. Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat. -----Input----- The single line contains five integers C, H_{r}, H_{b}, W_{r}, W_{b} (1 ≤ C, H_{r}, H_{b}, W_{r}, W_{b} ≤ 10^9). -----Output----- Print a single integer — the maximum number of joy units that Om Nom can get. -----Examples----- Input 10 3 5 2 3 Output 16 -----Note----- In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
[ "10 3 5 2 3\n", "5 3 1 6 7\n", "982068341 55 57 106 109\n", "930064129 32726326 25428197 83013449 64501049\n", "927155987 21197 15994 54746 41309\n", "902303498 609628987 152407246 8 2\n", "942733698 9180 9072 1020 1008\n", "951102310 39876134 24967176 70096104 43888451\n", "910943911 107 105 60 59\n", "910943911 38162 31949 67084 56162\n" ]
[ "16\n", "0\n", "513558662\n", "363523396\n", "358983713\n", "68758795931537065\n", "8484603228\n", "539219654\n", "1624516635\n", "518210503\n" ]
1
stdio
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits. If a solution exists, you should print it. -----Input----- The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits. -----Output----- Print "NO" (without quotes), if there is no such way to remove some digits from number n. Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8. If there are multiple possible answers, you may print any of them. -----Examples----- Input 3454 Output YES 344 Input 10 Output YES 0 Input 111111 Output NO
[ "3454\n", "10\n", "111111\n", "8996988892\n", "5555555555\n", "1\n", "8147522776919916277306861346922924221557534659480258977017038624458370459299847590937757625791239188\n", "8\n", "14\n", "2363\n" ]
[ "YES\n344\n", "YES\n0\n", "NO\n", "YES\n8\n", "NO\n", "NO\n", "YES\n8\n", "YES\n8\n", "NO\n", "NO\n" ]
1
stdio
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X. X. .X XX XX Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square. Vasya has a board with $2\times n$ squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully. Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns. -----Input----- The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$. -----Output----- Output a single integer — the maximum amount of bishwocks that can be placed onto the given board. -----Examples----- Input 00 00 Output 1 Input 00X00X0XXX0 0XXX0X00X00 Output 4 Input 0X0X0 0X0X0 Output 0 Input 0XXX0 00000 Output 2
[ "00\n00\n", "00X00X0XXX0\n0XXX0X00X00\n", "0X0X0\n0X0X0\n", "0XXX0\n00000\n", "0\n0\n", "0\nX\n", "X\n0\n", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n", "0000X0XX000X0XXXX0X0XXXX000X0X0XX000XXX0X00XX00XX00X0000XX0XX00X0X00X0X00X0XX000XX00XXXXXXXXXXXXXXX0\nX00XX0XX00XXXX00XXXX00XX0000000000XXX0X00XX0XX00XXX00X00X0XX0000X00XXXXXXX00X00000XXX00XXX00XXX0X0XX\n", "X\nX\n" ]
[ "1", "4", "0", "2", "0", "0", "0", "0", "18", "0" ]
1
stdio
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on positions from A in the string are all distinct and lowercase; there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a_1 < j < a_2 for some a_1 and a_2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. -----Output----- Print maximum number of elements in pretty set of positions for string s. -----Examples----- Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 -----Note----- In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
[ "11\naaaaBaabAbA\n", "12\nzACaAbbaazzC\n", "3\nABC\n", "1\na\n", "2\naz\n", "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLrRExpQzxzqzcqsqzsiisswqitswzCtJQxOavicSdBIodideVRKHPojCNHmbnrLgwJlwOpyrJJIhrUePszxSjJGeUgTtOfewPQnPVWhZAtogRPrJLwyShNQaeNsvrJwjuuBOMPCeSckBMISQzGngfOmeyfDObncyeNsihYVtQbSEh\n", "2\nAZ\n", "28\nAabcBabcCBNMaaaaabbbbbcccccc\n", "200\nrsgraosldglhdoorwhkrsehjpuxrjuwgeanjgezhekprzarelduuaxdnspzjuooguuwnzkowkuhzduakdrzpnslauejhrrkalwpurpuuswdgeadlhjwzjgegwpknepazwwleulppwrlgrgedlwdzuodzropsrrkxusjnuzshdkjrxxpgzanzdrpnggdwxarpwohxdepJ\n", "1\nk\n" ]
[ "2\n", "3\n", "0\n", "1\n", "2\n", "8\n", "0\n", "3\n", "17\n", "1\n" ]
1
stdio
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? -----Input----- The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a. The second line contains n integers a_1, a_2, ..., a_{n} ( - 100 ≤ a_{i} ≤ 100) — the elements of sequence a. -----Output----- 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. -----Examples----- Input 3 1 -2 0 Output 3 Input 6 16 23 16 15 42 8 Output 120 -----Note----- In 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.
[ "3\n1 -2 0\n", "6\n16 23 16 15 42 8\n", "1\n-1\n", "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100\n", "2\n-1 5\n", "3\n-2 0 1\n", "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3\n", "4\n1 -1 1 -1\n", "4\n100 -100 100 -100\n", "3\n-2 -5 10\n" ]
[ "3\n", "120\n", "1\n", "10000\n", "6\n", "3\n", "94\n", "4\n", "400\n", "17\n" ]
1
stdio
You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). -----Input----- The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. -----Output----- If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k — the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s — from left to right. If there are several solutions print any of them. -----Examples----- Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
[ "5 2 3\nHello\n", "10 9 5\nCodeforces\n", "6 4 5\nPrivet\n", "8 1 1\nabacabac\n", "1 1 1\n1\n", "10 8 1\nuTl9w4lcdo\n", "20 6 4\nfmFRpk2NrzSvnQC9gB61\n", "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6\n", "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde\n", "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu\n" ]
[ "2\nHe\nllo\n", "2\nCodef\norces\n", "-1\n", "8\na\nb\na\nc\na\nb\na\nc\n", "1\n1\n", "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no\n", "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61\n", "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6\n", "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde\n", "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu\n" ]
1
stdio
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? -----Input----- The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and bitwise xor of the pair of positive integers, respectively. -----Output----- Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0. -----Examples----- Input 9 5 Output 4 Input 3 3 Output 2 Input 5 2 Output 0 -----Note----- In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2). In the second sample, the only solutions are (1, 2) and (2, 1).
[ "9 5\n", "3 3\n", "5 2\n", "6 0\n", "549755813887 549755813887\n", "2 0\n", "2 2\n", "433864631347 597596794426\n", "80 12\n", "549755813888 549755813886\n" ]
[ "4\n", "2\n", "0\n", "1\n", "549755813886\n", "1\n", "0\n", "0\n", "4\n", "274877906944\n" ]
1
stdio
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. [Image] The picture corresponds to the first example. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'. -----Input----- The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. -----Output----- Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. -----Examples----- Input ABABBBACFEYUKOTT Output 4 Input AAA Output 1
[ "ABABBBACFEYUKOTT\n", "AAA\n", "A\n", "B\n", "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU\n", "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI\n", "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC\n", "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ\n", "PKLKBWTXVJ\n", "CFHFPTGMOKXVLJJZJDQW\n" ]
[ "4", "1", "1", "2", "39", "1", "85", "18", "11", "12" ]
1
stdio
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal. Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal. -----Input----- The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — elements of the array. -----Output----- If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). -----Examples----- Input 5 1 3 3 2 1 Output YES Input 5 1 2 3 4 5 Output NO -----Note----- In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
[ "5\n1 3 3 2 1\n", "5\n1 2 3 4 5\n", "2\n1 2\n", "3\n1 2 3\n", "3\n1 1 1\n", "2\n1 1000000000\n", "4\n1 2 3 4\n", "10\n1 1 1 1 1 2 2 2 2 2\n", "2\n4 2\n", "4\n1 1 4 7\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n" ]
1
stdio
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 k_1 knights with lightsabers of the first color, k_2 knights with lightsabers of the second color, ..., k_{m} knights with lightsabers of the m-th color. Help her find out if this is possible. -----Input----- 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 k_1, k_2, ..., k_{m} (with $1 \leq \sum_{i = 1}^{m} k_{i} \leq n$) – the desired counts of lightsabers of each color from 1 to m. -----Output----- Output YES if an interval with prescribed color counts exists, or output NO if there is none. -----Example----- Input 5 2 1 1 2 2 1 1 2 Output YES
[ "5 2\n1 1 2 2 1\n1 2\n", "1 1\n1\n1\n", "2 1\n1 1\n1\n", "2 1\n1 1\n2\n", "2 2\n1 2\n1 1\n", "3 3\n1 1 3\n0 1 2\n", "4 4\n2 3 3 2\n0 0 1 0\n", "2 2\n2 2\n0 2\n", "3 3\n1 1 3\n0 1 1\n", "4 4\n2 4 4 3\n1 1 1 1\n" ]
[ "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n" ]
1
stdio
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. $0$ You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace. -----Input----- The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. -----Output----- Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower). -----Examples----- Input -o-o-- Output YES Input -o--- Output YES Input -o---o- Output NO Input ooo Output YES
[ "-o-o--\n", "-o---\n", "-o---o-\n", "ooo\n", "---\n", "--o-o-----o----o--oo-o-----ooo-oo---o--\n", "-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--\n", "-ooo--\n", "---o--\n", "oo-ooo\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n" ]
1
stdio
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt? -----Input----- The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed. -----Output----- Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. -----Examples----- Input 4 6 2 Output 2 Input 3 10 3 Output 4 Input 3 6 1 Output 3 -----Note----- In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n", "3 3 3\n", "1 1 1\n", "1 1000000000 1\n", "100 1000000000 20\n", "1000 1000 994\n", "100000000 200000000 54345\n", "1000000000 1000000000 1\n" ]
[ "2\n", "4\n", "3\n", "1\n", "1\n", "1000000000\n", "10000034\n", "1\n", "10001\n", "1\n" ]
1
stdio
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible. A polyline defined by points p_1, p_2, p_3, p_4 consists of the line segments p_1 p_2, p_2 p_3, p_3 p_4, and its length is the sum of the lengths of the individual line segments. -----Input----- The only line of the input contains two integers n and m (0 ≤ n, m ≤ 1000). It is guaranteed that grid contains at least 4 different points. -----Output----- Print 4 lines with two integers per line separated by space — coordinates of points p_1, p_2, p_3, p_4 in order which represent the longest possible polyline. Judge program compares your answer and jury's answer with 10^{ - 6} precision. -----Examples----- Input 1 1 Output 1 1 0 0 1 0 0 1 Input 0 10 Output 0 1 0 10 0 0 0 9
[ "1 1\n", "0 10\n", "10 10\n", "100 100\n", "10 100\n", "20 1000\n", "1000 20\n", "100 10\n", "2 2\n", "3 3\n" ]
[ "1 1\n0 0\n1 0\n0 1\n", "0 1\n0 10\n0 0\n0 9\n", "10 9\n0 0\n10 10\n1 0\n", "0 1\n100 100\n0 0\n99 100\n", "9 100\n0 0\n10 100\n1 0\n", "1 0\n20 1000\n0 0\n19 1000\n", "0 1\n1000 20\n0 0\n1000 19\n", "100 9\n0 0\n100 10\n0 1\n", "2 2\n0 0\n2 0\n0 2\n", "3 3\n0 0\n3 0\n0 3\n" ]
1
stdio
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? -----Input----- The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. -----Output----- First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. -----Examples----- Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 -----Note----- The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
[ "1\n", "5\n", "2\n", "3\n", "7\n", "12\n", "15\n", "18\n", "38\n", "47\n" ]
[ "5\n5 6 7 8 9 ", "0", "5\n10 11 12 13 14 ", "5\n15 16 17 18 19 ", "5\n30 31 32 33 34 ", "5\n50 51 52 53 54 ", "5\n65 66 67 68 69 ", "5\n75 76 77 78 79 ", "5\n155 156 157 158 159 ", "5\n195 196 197 198 199 " ]
1
stdio
You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 5). Next n lines contain four integers each, describing a single rectangle: x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 31400, 0 ≤ y_1 < y_2 ≤ 31400) — x_1 and x_2 are x-coordinates of the left and right edges of the rectangle, and y_1 and y_2 are y-coordinates of the bottom and top edges of the rectangle. No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle). -----Output----- In a single line print "YES", if the given rectangles form a square, or "NO" otherwise. -----Examples----- Input 5 0 0 2 3 0 3 3 5 2 0 5 2 3 2 5 5 2 2 3 3 Output YES Input 4 0 0 2 3 0 3 3 5 2 0 5 2 3 2 5 5 Output NO
[ "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n", "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400\n", "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 15000 20000\n0 20000 15000 31400\n15000 0 31400 31400\n", "5\n10359 859 28918 4384\n2895 26520 28918 26882\n2895 26424 28918 26520\n2895 859 10359 4384\n2895 4384 28918 26424\n", "5\n12750 0 25688 1\n1094 0 12750 1\n0 0 956 1\n956 0 1094 1\n25688 0 31400 1\n", "4\n18006 16484 25725 31400\n0 0 31400 16484\n29563 16484 31400 31400\n25725 16484 29563 31400\n", "1\n0 0 31400 31400\n", "2\n0 0 31400 13313\n0 13313 31400 31400\n", "3\n0 9388 31400 31400\n26020 0 31400 9388\n0 0 26020 9388\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n" ]
1
stdio
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≤ n, s ≤ 10^18). -----Output----- Print one integer — the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20). In the third example 10 is the only really big number (10 - 1 ≥ 9).
[ "12 1\n", "25 20\n", "10 9\n", "300 1000\n", "500 1000\n", "1000 2000\n", "10000 1000\n", "1000000000000000000 1000000000000000000\n", "1000000000000000000 100000000000000000\n", "1000000000000000000 10000000000000000\n" ]
[ "3\n", "0\n", "1\n", "0\n", "0\n", "0\n", "8991\n", "0\n", "899999999999999991\n", "989999999999999991\n" ]
1
stdio
You are given a string $s$ of length $n$ consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd. Calculate the minimum number of operations to delete the whole string $s$. -----Input----- The first line contains one integer $n$ ($1 \le n \le 500$) — the length of string $s$. The second line contains the string $s$ ($|s| = n$) consisting of lowercase Latin letters. -----Output----- Output a single integer — the minimal number of operation to delete string $s$. -----Examples----- Input 5 abaca Output 3 Input 8 abcddcba Output 4
[ "5\nabaca\n", "8\nabcddcba\n", "1\nx\n", "500\nbbababaabaabaabbbbbbaabbabbabbaabababababbbbabaaabbbbaaabbbbbbbabababaaaaabbbbabaababbababbaaaaaabbaaabbaabaaababbbbbabbaabaabaabbbaaabaabbaaabbaabababbaaabaaabaaaaabbbababaabbbbabbbbbababbbaabaabbabaabbabbababbbbbaababbaabbbbbbbbaabbabbbabababaaaaaaaaaabababaaabbaabbbabbabbbbabbbaabaaabbbaabbabbbbbbbaaabbbabaaaaaabaabbbabbbbaaaabbbbbbabaaaaaaabbbbbbabababbaabbbaabaabbbabbbbaaaabbbbbabaaababbababbbabaaabbbbaababaababaaaaabbbaabbababaabaaabaaabbbbbabbbabbaaabbbbbbbaaaaabaaabbabaabbabbbbbbbbabbbab\n", "500\nccacbbbbbbbccbccbccbacbabcaaaabbcbcaabbababcbbcbcbbcbabbacbacbacbcaccccaaccbabcbbbbccbbaacbcbcaaabbbbbaaabbabacacaabcaababcbbcbcababbbabbaaaccbcabcabbbcbcccbcbcacabbbbbacbcbabbcbaabcbcbcacacccabbbccacaacaaccbbabbbaaccabcaaaaacbbcacacbacabbccaaaccccaabbaacbabbcbccababbabacabbcacbcbaaccbcaccabbbbacabcbccbabacbcbaaaacbbcbccacaaaabacaabbaaccabacababcbcbcacbcccccbbabbccbaabcbaaabbcbacacbbbbabbacbabbabbaacccbaababccaaccbaaabcaccaaacbbbcaabcbcbcbccbbbbcbacbccbabcbbcbbbabbcbaccabacbbbabcbcbcbbbacccbabab\n", "500\ndadcbaaaabbddbbacdbabdcbcdcabacbddddbaabacbcabdccdcdadcbabdbcabcccbdcabdcaacdbabdcbbbdbacdddaaddccbacabbdbbcbbcadcdaadcababbbacabcdbbbadbdacbcddbccdbacbddbdababdcadbbabccbcdcccccadbbdbdbdcbcbdcddaacdababdddacadaddcdcbaabaddaadacbaadcdcacbdcbaddddbdbddacaadaaaaabdccccbccbcabddbbcaacadccdbcccdcdbbabbcbabdbccdcdbcbbadaaadddcbcbbbabbadcddbaaabbbdabbcbcacbbaaaddbcbaccaaadcdbcdbbbbbcdbbbcdadacdbcbbaaddbdabcbccabbadadbbbbdccacbbbacacadbcaadbccdbadacdaddacddcccbcbdbdbcbdbdaabdcdabbaadcdccdbdcccadabdbddd\n", "500\neebcacaadebcdebdeaaaceaabacabbaadaadebbceeabbdbdbaaeababdaeddabbeebccbcbbdbdecececebdcceaddbbabbcdadcacecedaabbeeaaddbbddddddadcaeeebabeaadbaabcecadaabbabcbeadbdaabebeeadbadcaadbecdcecaeeebeebbececdeddbdcdccacaeccbdcbbeeeedeabdceaaacdbbddaceccbeaedbadcebebdceeabadeceeedecaaeedeebabdadcaeabdadaeabcbccdacbabcacbcaeadbacbddbcecddebeabbedbcadeeeaebabbeccdbadceccaeecdaccccceeccbebabaaaacedaadbbaddacbaedccabeaddbedaadacedacdbcabddbeaaecaebddecddacbbceebeacadeeaadcbdcbccbccdcddabdcecaebadccccaeadddacbe\n", "500\nbceeccdebbecfffabeeeeaceaaeeecccfcafeefdadfbfceaacceacabefbceaaeefabaabaabcefdcdccabeddbdabebcbdfdbbfcefffcccedbbfbcbafcabaddcdfecedfdeafccbfbbabaabaccadfcaccdbdbbbacfcebebcadecabdfcefddffbffabbaaddbccdaadeadefebcdfefddceefcdeefbbeeebdcaacdcfafcdbadbaeadcbfbbcaacdeacbceddefebbaddbadaeebefcffcecbacfeabebfbeabdfbefeeeaaeebcdfecedecdeeeefcaeaeffcafcecedddcbbffbeaadfbfcccfbeacfddbbfccbafdfccebbbfadebbceedfafcbffbacafdbcaabdbcfdceffbbdbceaefcabfbbeedffecaafccaafbeadaaabedccfcecceebebfdfcbedaddfeefcea\n", "500\nafdfdcfebagfdcdbacdeggffebbcgfdbeeeegbgagaccbgegdfbffdbfaaeabebcgcabdebdeadbggadffdedfgadbdcdeacffebbceefedbeabeaefdcgddaccfaagcaedgdcfeafaaadfgcgcabdddgcccbbaeccgbfefaggabddeaffbaabadfbddcdafcfdaedbdfafgagddgdgdfdabbceddfcffafbabefeadecccadebbbfeegbfdgbbaaffgeaagegbbeddfbfeeecdagbfacffebbbfcfeffbcddaaecadfdbegfacbfeeggdbacfgecfbgfdfacffebfabddebgcdfdaacdedgeggdbaadagebbdbfdcbbbbbfabafddebfaffacffccdbccedbaadbdcgbedbddebbcadfbgdgfagffgacgeadbdgedcccgbcecadgbdcafbffggcccfffbffaefdbcdgdeefceceaagd\n", "500\ndbcbdhbacghbacfeaecddchgffchhbhheacheagadabedhfcgfbgfahgebdgdecfgeaggebahhbhaaeagdhbadegebdfbededdffdfcbebhchgahafdegbbhhgaecadcdhaecbbceaefbadgedfhgfdaeheeeabbehbeddhdgdhbegefdffdbeebdegdbefbadbehacecdaedbeeedehfhddeggdafaagehefcefbghadhbehgbdehaeaeeecbbagbdefafhcgffgcfeefehgddgggbegcaabcfehcdbfcbbccheeafebdfageefeafafhffdaadcddgbfaegafbhafdbhfgebaaebegcddgcadddfgfcddggbdffffhghcbghbhdcebeacagbdfadhdbghaeacadbccbbebhfeeaghgebghbabbfhcdfagccaadhhgdeechghceefaaeacheedhbdaedcffhcgfeagdgfdchghbbfbf\n" ]
[ "3\n", "4\n", "1\n", "121\n", "174\n", "196\n", "217\n", "228\n", "246\n", "261\n" ]
1
stdio
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. -----Input----- The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100), where a_{i} is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b_1, b_2, ..., b_{m} (1 ≤ b_{j} ≤ 100), where b_{j} is the j-th girl's dancing skill. -----Output----- Print a single number — the required maximum possible number of pairs. -----Examples----- Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
[ "4\n1 4 6 2\n5\n5 1 5 7 9\n", "4\n1 2 3 4\n4\n10 11 12 13\n", "5\n1 1 1 1 1\n3\n1 2 3\n", "1\n1\n1\n1\n", "2\n1 10\n1\n9\n", "4\n4 5 4 4\n5\n5 3 4 2 4\n", "1\n2\n1\n1\n", "1\n3\n2\n3 2\n", "1\n4\n3\n4 4 4\n", "1\n2\n4\n3 1 4 2\n" ]
[ "3\n", "0\n", "2\n", "1\n", "1\n", "4\n", "1\n", "1\n", "1\n", "1\n" ]
1
stdio
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18. -----Input----- The first line contains two space-separated integers, m and k (0 ≤ m ≤ 10^18; 1 ≤ k ≤ 64). -----Output----- Print the required number n (1 ≤ n ≤ 10^18). If there are multiple answers, print any of them. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 5
[ "1 1\n", "3 2\n", "3 3\n", "1 11\n", "4 20\n", "45902564 24\n", "330 8\n", "10 10\n", "0 2\n", "1000000 55\n" ]
[ "1\n", "5\n", "7\n", "1024\n", "983040\n", "6406200698\n", "2033\n", "1023\n", "1\n", "504262282264444927\n" ]
1
stdio
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
[ "2 15\n", "3 0\n", "2 1\n", "3 10\n", "100 100\n", "1 900\n", "1 9\n", "1 0\n", "1 1\n", "1 2\n" ]
[ "69 96\n", "-1 -1\n", "10 10\n", "109 910\n", "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "-1 -1\n", "9 9\n", "0 0\n", "1 1\n", "2 2\n" ]
1
stdio
Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct. For given n find out to which integer will Vasya round it. -----Input----- The first line contains single integer n (0 ≤ n ≤ 10^9) — number that Vasya has. -----Output----- Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer. -----Examples----- Input 5 Output 0 Input 113 Output 110 Input 1000000000 Output 1000000000 Input 5432359 Output 5432360 -----Note----- In the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
[ "5\n", "113\n", "1000000000\n", "5432359\n", "999999994\n", "10\n", "9\n", "1\n", "0\n", "3\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n", "999999990\n", "10\n", "10\n", "0\n", "0\n", "0\n" ]
1
stdio
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". -----Input----- The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. -----Output----- Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. -----Examples----- Input harry potter Output hap Input tom riddle Output tomr
[ "harry potter\n", "tom riddle\n", "a qdpinbmcrf\n", "wixjzniiub ssdfodfgap\n", "z z\n", "ertuyivhfg v\n", "asdfghjkli ware\n", "udggmyop ze\n", "fapkdme rtzxovx\n", "mybiqxmnqq l\n" ]
[ "hap\n", "tomr\n", "aq\n", "wis\n", "zz\n", "ertuv\n", "asdfghjkliw\n", "udggmyopz\n", "fapkdmer\n", "ml\n" ]
1
stdio
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: the Power Gem of purple color, the Time Gem of green color, the Space Gem of blue color, the Soul Gem of orange color, the Reality Gem of red color, the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. -----Input----- In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. -----Output----- In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. -----Examples----- Input 4 red purple yellow orange Output 2 Space Time Input 0 Output 6 Time Mind Soul Power Reality Space -----Note----- In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
[ "4\nred\npurple\nyellow\norange\n", "0\n", "6\npurple\nblue\nyellow\nred\ngreen\norange\n", "1\npurple\n", "3\nblue\norange\npurple\n", "2\nyellow\nred\n", "1\ngreen\n", "2\npurple\ngreen\n", "1\nblue\n", "2\npurple\nblue\n" ]
[ "2\nTime\nSpace\n", "6\nReality\nTime\nMind\nSpace\nPower\nSoul\n", "0\n", "5\nMind\nSpace\nReality\nSoul\nTime\n", "3\nReality\nMind\nTime\n", "4\nTime\nPower\nSoul\nSpace\n", "5\nReality\nSpace\nMind\nPower\nSoul\n", "4\nSpace\nReality\nSoul\nMind\n", "5\nMind\nSoul\nTime\nPower\nReality\n", "4\nReality\nTime\nSoul\nMind\n" ]
1
stdio
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number". Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n. -----Input----- The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis. -----Output----- Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 10^3. It is guaranteed the the answer exists. -----Examples----- Input 3 Output 1 Input 4 Output 2 -----Note----- A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. For the first sample testcase, 3·1 + 1 = 4. We can output 1. In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.
[ "3\n", "4\n", "10\n", "153\n", "1000\n", "1\n", "2\n", "5\n", "6\n", "7\n" ]
[ "1", "2", "2", "1", "1", "3", "4", "1", "4", "1" ]
1
stdio
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string. -----Input----- The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. -----Output----- Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. -----Examples----- Input VK Output 1 Input VV Output 1 Input V Output 0 Input VKKKKKKKKKVVVVVVVVVK Output 3 Input KVKV Output 1 -----Note----- For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear. For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring. For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
[ "VK\n", "VV\n", "V\n", "VKKKKKKKKKVVVVVVVVVK\n", "KVKV\n", "VKKVVVKVKVK\n", "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV\n", "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK\n", "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK\n", "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK\n" ]
[ "1\n", "1\n", "0\n", "3\n", "1\n", "5\n", "14\n", "32\n", "32\n", "21\n" ]
1
stdio
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 × 5 table there are 15 squares with side one, 8 squares with side two and 3 squares with side three. The total number of distinct squares in a 3 × 5 table is 15 + 8 + 3 = 26. -----Input----- The first line of the input contains a single integer x (1 ≤ x ≤ 10^18) — the number of squares inside the tables Spongebob is interested in. -----Output----- First print a single integer k — the number of tables with exactly x distinct squares inside. Then print k pairs of integers describing the tables. Print the pairs in the order of increasing n, and in case of equality — in the order of increasing m. -----Examples----- Input 26 Output 6 1 26 2 9 3 5 5 3 9 2 26 1 Input 2 Output 2 1 2 2 1 Input 8 Output 4 1 8 2 3 3 2 8 1 -----Note----- In a 1 × 2 table there are 2 1 × 1 squares. So, 2 distinct squares in total. [Image] In a 2 × 3 table there are 6 1 × 1 squares and 2 2 × 2 squares. That is equal to 8 squares in total. [Image]
[ "26\n", "2\n", "8\n", "1\n", "5005\n", "17284\n", "151618\n", "360700\n", "500500500\n", "200200\n" ]
[ "6\n1 26\n2 9\n3 5\n5 3\n9 2\n26 1\n", "2\n1 2\n2 1\n", "4\n1 8\n2 3\n3 2\n8 1\n", "1\n1 1\n", "12\n1 5005\n5 335\n6 240\n10 94\n13 59\n14 52\n52 14\n59 13\n94 10\n240 6\n335 5\n5005 1\n", "2\n1 17284\n17284 1\n", "2\n1 151618\n151618 1\n", "8\n1 360700\n4 36071\n5 24048\n24 1210\n1210 24\n24048 5\n36071 4\n360700 1\n", "8\n1 500500500\n4 50050051\n8 13902794\n9 11122236\n11122236 9\n13902794 8\n50050051 4\n500500500 1\n", "26\n1 200200\n4 20021\n5 13348\n6 9535\n7 7152\n10 3643\n13 2204\n14 1911\n15 1673\n24 675\n25 624\n55 148\n77 92\n92 77\n148 55\n624 25\n675 24\n1673 15\n1911 14\n2204 13\n3643 10\n7152 7\n9535 6\n13348 5\n20021 4\n200200 1\n" ]
1
stdio
Vasya has got three integers $n$, $m$ and $k$. He'd like to find three integer points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$, such that $0 \le x_1, x_2, x_3 \le n$, $0 \le y_1, y_2, y_3 \le m$ and the area of the triangle formed by these points is equal to $\frac{nm}{k}$. Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them. -----Input----- The single line contains three integers $n$, $m$, $k$ ($1\le n, m \le 10^9$, $2 \le k \le 10^9$). -----Output----- If there are no such points, print "NO". Otherwise print "YES" in the first line. The next three lines should contain integers $x_i, y_i$ — coordinates of the points, one point per line. If there are multiple solutions, print any of them. You can print each letter in any case (upper or lower). -----Examples----- Input 4 3 3 Output YES 1 0 2 3 4 1 Input 4 4 7 Output NO -----Note----- In the first example area of the triangle should be equal to $\frac{nm}{k} = 4$. The triangle mentioned in the output is pictured below: [Image] In the second example there is no triangle with area $\frac{nm}{k} = \frac{16}{7}$.
[ "4 3 3\n", "4 4 7\n", "3 4 2\n", "3 4 3\n", "3 4 12\n", "16904235 79092881 127345237\n", "1000000000 999999937 1024\n", "229999981 1000000000 2048\n", "1 1 2\n", "1000000000 1000000000 2\n" ]
[ "YES\n0 0\n0 2\n4 0\n", "NO\n", "YES\n0 0\n0 4\n3 0\n", "YES\n0 0\n0 4\n2 0\n", "YES\n0 0\n0 2\n1 0\n", "YES\n0 0\n0 699937\n30 0\n", "YES\n0 0\n0 999999937\n1953125 0\n", "NO\n", "YES\n0 0\n0 1\n1 0\n", "YES\n0 0\n0 1000000000\n1000000000 0\n" ]
1
stdio
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. -----Input----- The first line contains two integers n and k (1 ≤ n, k ≤ 10^18, k ≤ n) — the number of sticks drawn by Sasha and the number k — the number of sticks to be crossed out on each turn. -----Output----- If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). -----Examples----- Input 1 1 Output YES Input 10 4 Output NO -----Note----- In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
[ "1 1\n", "10 4\n", "251656215122324104 164397544865601257\n", "963577813436662285 206326039287271924\n", "1000000000000000000 1\n", "253308697183523656 25332878317796706\n", "669038685745448997 501718093668307460\n", "116453141993601660 87060381463547965\n", "766959657 370931668\n", "255787422422806632 146884995820359999\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n" ]
1
stdio
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
[ "2 4\n", "1 3\n", "8 5\n", "0 0\n", "1 1\n", "5 8\n", "0 10\n", "0 1\n", "10 2\n", "38795264078389352 381146357267900812\n" ]
[ "2\n3 1", "3\n1 1 1", "-1", "0", "1\n1", "-1", "2\n5 5", "-1", "-1", "2\n209970810673145082 171175546594755730" ]
1
stdio
Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum. -----Input----- The first line of the input contains integer n (1 ≤ n < 10^15). -----Output----- Print expected minimal number of digits 1. -----Examples----- Input 121 Output 6
[ "121\n", "10\n", "72\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n" ]
[ "6\n", "3\n", "15\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "6\n" ]
1
stdio
Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants. -----Input----- The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b < p$, $1 \leq x \leq 10^{12}$). It is guaranteed that $p$ is a prime. -----Output----- Print a single integer: the number of possible answers $n$. -----Examples----- Input 2 3 5 8 Output 2 Input 4 6 7 13 Output 1 Input 233 233 10007 1 Output 1 -----Note----- In the first sample, we can see that $n=2$ and $n=8$ are possible answers.
[ "2 3 5 8\n", "4 6 7 13\n", "233 233 10007 1\n", "338792 190248 339821 152634074578\n", "629260 663548 739463 321804928248\n", "656229 20757 818339 523535590429\n", "1000002 1000002 1000003 1000000000000\n", "345 2746 1000003 5000000\n", "802942 824238 836833 605503824329\n", "1 1 2 880336470888\n" ]
[ "2\n", "1\n", "1\n", "449263\n", "434818\n", "639482\n", "999998\n", "4\n", "723664\n", "440168235444\n" ]
1
stdio
Recently Anton found a box with digits in his room. There are k_2 digits 2, k_3 digits 3, k_5 digits 5 and k_6 digits 6. Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task! Each digit can be used no more than once, i.e. the composed integers should contain no more than k_2 digits 2, k_3 digits 3 and so on. Of course, unused digits are not counted in the sum. -----Input----- The only line of the input contains four integers k_2, k_3, k_5 and k_6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k_2, k_3, k_5, k_6 ≤ 5·10^6). -----Output----- Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box. -----Examples----- Input 5 1 3 4 Output 800 Input 1 1 1 1 Output 256 -----Note----- In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer. In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
[ "5 1 3 4\n", "1 1 1 1\n", "10 2 1 5\n", "4 2 7 2\n", "489 292 127 263\n", "9557 5242 1190 7734\n", "1480320 1969946 1158387 3940412\n", "0 0 0 0\n", "5000000 5000000 5000000 5000000\n", "1048576 256 1048576 1048576\n" ]
[ "800\n", "256\n", "320\n", "576\n", "41856\n", "472384\n", "306848928\n", "0\n", "1280000000\n", "268435456\n" ]
1
stdio
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on. For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1). In how many seconds will Mr. Bender get happy? -----Input----- The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 10^9; 1 ≤ x, y ≤ n; c ≤ n^2). -----Output----- In a single line print a single integer — the answer to the problem. -----Examples----- Input 6 4 3 1 Output 0 Input 9 3 8 10 Output 2 -----Note----- Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. [Image].
[ "6 4 3 1\n", "9 3 8 10\n", "9 4 3 10\n", "9 8 2 10\n", "1 1 1 1\n", "10 7 2 7\n", "8 2 6 10\n", "8 1 2 10\n", "6 1 4 10\n", "1000000 951981 612086 60277\n" ]
[ "0\n", "2\n", "2\n", "2\n", "0\n", "2\n", "2\n", "3\n", "3\n", "174\n" ]
1
stdio
While playing with geometric figures Alex has accidentally invented a concept of a $n$-th order rhombus in a cell grid. A $1$-st order rhombus is just a square $1 \times 1$ (i.e just a cell). A $n$-th order rhombus for all $n \geq 2$ one obtains from a $n-1$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better). [Image] Alex asks you to compute the number of cells in a $n$-th order rhombus. -----Input----- The first and only input line contains integer $n$ ($1 \leq n \leq 100$) — order of a rhombus whose numbers of cells should be computed. -----Output----- Print exactly one integer — the number of cells in a $n$-th order rhombus. -----Examples----- Input 1 Output 1 Input 2 Output 5 Input 3 Output 13 -----Note----- Images of rhombus corresponding to the examples are given in the statement.
[ "1\n", "2\n", "3\n", "11\n", "21\n", "31\n", "41\n", "51\n", "100\n", "34\n" ]
[ "1", "5", "13", "221", "841", "1861", "3281", "5101", "19801", "2245" ]
1
stdio
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. -----Output----- Output "YES", if the string is a pangram and "NO" otherwise. -----Examples----- Input 12 toosmallword Output NO Input 35 TheQuickBrownFoxJumpsOverTheLazyDog Output YES
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n", "1\na\n", "26\nqwertyuiopasdfghjklzxcvbnm\n", "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n", "48\nthereisasyetinsufficientdataforameaningfulanswer\n", "30\nToBeOrNotToBeThatIsTheQuestion\n", "30\njackdawslovemybigsphinxofquarz\n", "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY\n", "26\naaaaaaaaaaaaaaaaaaaaaaaaaa\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n" ]
1
stdio
You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here https://en.wikipedia.org/wiki/24-hour_clock. -----Input----- The first line contains the current time in the format hh:mm (0 ≤ hh < 24, 0 ≤ mm < 60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes). The second line contains integer a (0 ≤ a ≤ 10^4) — the number of the minutes passed. -----Output----- The only line should contain the time after a minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed). See the examples to check the input/output format. -----Examples----- Input 23:59 10 Output 00:09 Input 20:20 121 Output 22:21 Input 10:10 0 Output 10:10
[ "23:59\n10\n", "20:20\n121\n", "10:10\n0\n", "12:34\n10000\n", "00:00\n10000\n", "00:00\n1440\n", "23:59\n8640\n", "10:01\n0\n", "04:05\n0\n", "02:59\n1\n" ]
[ "00:09\n", "22:21\n", "10:10\n", "11:14\n", "22:40\n", "00:00\n", "23:59\n", "10:01\n", "04:05\n", "03:00\n" ]
1
stdio
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. -----Input----- The first line contains a single positive integer n (2 ≤ n ≤ 10^5). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers x_{i} and y_{i} (|x_{i}|, |y_{i}| ≤ 10^9, x_{i} ≠ 0). No two points coincide. -----Output----- Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower). -----Examples----- Input 3 1 1 -1 -1 2 -1 Output Yes Input 4 1 1 2 2 -1 1 -2 2 Output No Input 3 1 2 2 1 4 60 Output Yes -----Note----- In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n", "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1\n", "2\n1000000000 -1000000000\n1000000000 1000000000\n", "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\n-6 -2\n-7 -11\n-4 -4\n-8 -5\n", "4\n-1000000000 -1000000000\n1000000000 1000000000\n-1000000000 1000000000\n1000000000 -1000000000\n", "2\n-1000000000 1000000000\n-1000000000 -1000000000\n", "5\n-1 -1\n-2 2\n2 2\n2 -2\n3 2\n", "2\n1 0\n-1 0\n" ]
[ "Yes", "No", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "No", "Yes" ]
1
stdio
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? -----Input----- The first and single line contains two integers A and B (1 ≤ A, B ≤ 10^9, min(A, B) ≤ 12). -----Output----- Print a single integer denoting the greatest common divisor of integers A! and B!. -----Example----- Input 4 3 Output 6 -----Note----- Consider 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.
[ "4 3\n", "10 399603090\n", "6 973151934\n", "2 841668075\n", "7 415216919\n", "3 283733059\n", "11 562314608\n", "3 990639260\n", "11 859155400\n", "1 1\n" ]
[ "6\n", "3628800\n", "720\n", "2\n", "5040\n", "6\n", "39916800\n", "6\n", "39916800\n", "1\n" ]
1
stdio
Let's call a positive integer composite if it has at least one divisor other than $1$ and itself. For example: the following numbers are composite: $1024$, $4$, $6$, $9$; the following numbers are not composite: $13$, $1$, $2$, $3$, $37$. You are given a positive integer $n$. Find two composite integers $a,b$ such that $a-b=n$. It can be proven that solution always exists. -----Input----- The input contains one integer $n$ ($1 \leq n \leq 10^7$): the given integer. -----Output----- Print two composite integers $a,b$ ($2 \leq a, b \leq 10^9, a-b=n$). It can be proven, that solution always exists. If there are several possible solutions, you can print any. -----Examples----- Input 1 Output 9 8 Input 512 Output 4608 4096
[ "1\n", "512\n", "10000000\n", "2\n", "3\n", "4\n", "8958020\n", "6\n", "7\n", "8\n" ]
[ "9 8\n", "4608 4096\n", "90000000 80000000\n", "18 16\n", "27 24\n", "36 32\n", "80622180 71664160\n", "54 48\n", "63 56\n", "72 64\n" ]
1
stdio
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum! A xor-sum of a sequence of integers a_1, a_2, ..., a_{m} is defined as the bitwise XOR of all its elements: $a_{1} \oplus a_{2} \oplus \ldots \oplus a_{m}$, here $\oplus$ denotes the bitwise XOR operation; more about bitwise XOR can be found here. Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. -----Input----- The sole string contains two integers n and k (1 ≤ k ≤ n ≤ 10^18). -----Output----- Output one number — the largest possible xor-sum. -----Examples----- Input 4 3 Output 7 Input 6 6 Output 7 -----Note----- In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
[ "4 3\n", "6 6\n", "2 2\n", "1022 10\n", "415853337373441 52\n", "75 12\n", "1000000000000000000 1000000000000000000\n", "1 1\n", "1000000000000000000 2\n", "49194939 22\n" ]
[ "7\n", "7\n", "3\n", "1023\n", "562949953421311\n", "127\n", "1152921504606846975\n", "1\n", "1152921504606846975\n", "67108863\n" ]
1
stdio
There are $n$ points on the plane, $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$. You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle. -----Input----- First line contains one integer $n$ ($1 \leq n \leq 10^5$). Each of the next $n$ lines contains two integers $x_i$ and $y_i$ ($1 \leq x_i,y_i \leq 10^9$). -----Output----- Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer. -----Examples----- Input 3 1 1 1 2 2 1 Output 3 Input 4 1 1 1 2 2 1 2 2 Output 4 -----Note----- Illustration for the first example: [Image] Illustration for the second example: [Image]
[ "3\n1 1\n1 2\n2 1\n", "4\n1 1\n1 2\n2 1\n2 2\n", "1\n233 666\n", "5\n7 7\n5 8\n8 5\n4 9\n9 4\n", "10\n100 34\n27 17\n17 73\n12 60\n53 25\n46 31\n61 86\n22 91\n82 91\n8 41\n", "2\n5 5\n7 2\n", "2\n5 5\n2 7\n", "2\n5 1\n3 4\n", "2\n2 3\n5 1\n", "2\n6 1\n4 4\n" ]
[ "3", "4", "899", "14", "173", "10", "10", "7", "6", "8" ]
1
stdio
Alice likes word "nineteen" very much. She has a string s and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. -----Input----- The first line contains a non-empty string s, consisting only of lowercase English letters. The length of string s doesn't exceed 100. -----Output----- Print a single integer — the maximum number of "nineteen"s that she can get in her string. -----Examples----- Input nniinneetteeeenn Output 2 Input nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii Output 2 Input nineteenineteen Output 2
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n", "nssemsnnsitjtihtthij\n", "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss\n", "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs\n", "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi\n", "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn\n", "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti\n", "rmeetriiitijmrenmeiijt\n" ]
[ "2", "2", "2", "0", "1", "2", "2", "1", "2", "0" ]
1
stdio
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. -----Input----- The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 10^5 characters. -----Output----- If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. -----Examples----- Input abcd defgh Output 5 Input a a Output -1 -----Note----- In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
[ "abcd\ndefgh\n", "a\na\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb\n", "abcde\nfghij\n", "abcde\nabcdf\n", "abcde\nbbcde\n", "abcde\neabcd\n", "abcdefgh\nabdcefgh\n" ]
[ "5\n", "-1\n", "100\n", "199\n", "99\n", "5\n", "5\n", "5\n", "5\n", "8\n" ]
1
stdio
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... [Image] The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time. -----Input----- The first line of input contains two integers a and b (1 ≤ a, b ≤ 100). The second line contains two integers c and d (1 ≤ c, d ≤ 100). -----Output----- Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time. -----Examples----- Input 20 2 9 19 Output 82 Input 2 1 16 12 Output -1 -----Note----- In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
[ "20 2\n9 19\n", "2 1\n16 12\n", "39 52\n88 78\n", "59 96\n34 48\n", "87 37\n91 29\n", "11 81\n49 7\n", "39 21\n95 89\n", "59 70\n48 54\n", "87 22\n98 32\n", "15 63\n51 13\n" ]
[ "82\n", "-1\n", "1222\n", "1748\n", "211\n", "301\n", "3414\n", "1014\n", "718\n", "-1\n" ]
1
stdio
Little C loves number «3» very much. He loves all things about it. Now he has a positive integer $n$. He wants to split $n$ into $3$ positive integers $a,b,c$, such that $a+b+c=n$ and none of the $3$ integers is a multiple of $3$. Help him to find a solution. -----Input----- A single line containing one integer $n$ ($3 \leq n \leq 10^9$) — the integer Little C has. -----Output----- Print $3$ positive integers $a,b,c$ in a single line, such that $a+b+c=n$ and none of them is a multiple of $3$. It can be proved that there is at least one solution. If there are multiple solutions, print any of them. -----Examples----- Input 3 Output 1 1 1 Input 233 Output 77 77 79
[ "3\n", "233\n", "4\n", "5\n", "1234\n", "387420489\n", "1000000000\n", "6\n", "7\n", "8\n" ]
[ "1 1 1", "1 2 230", "1 1 2", "1 2 2", "1 1 1232", "1 1 387420487", "1 1 999999998", "1 1 4", "1 1 5", "1 2 5" ]
1
stdio
JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $n$, you can perform the following operations zero or more times: mul $x$: multiplies $n$ by $x$ (where $x$ is an arbitrary positive integer). sqrt: replaces $n$ with $\sqrt{n}$ (to apply this operation, $\sqrt{n}$ must be an integer). You can perform these operations as many times as you like. What is the minimum value of $n$, that can be achieved and what is the minimum number of operations, to achieve that minimum value? Apparently, no one in the class knows the answer to this problem, maybe you can help them? -----Input----- The only line of the input contains a single integer $n$ ($1 \le n \le 10^6$) — the initial number. -----Output----- Print two integers: the minimum integer $n$ that can be achieved using the described operations and the minimum number of operations required. -----Examples----- Input 20 Output 10 2 Input 5184 Output 6 4 -----Note----- In the first example, you can apply the operation mul $5$ to get $100$ and then sqrt to get $10$. In the second example, you can first apply sqrt to get $72$, then mul $18$ to get $1296$ and finally two more sqrt and you get $6$. Note, that even if the initial value of $n$ is less or equal $10^6$, it can still become greater than $10^6$ after applying one or more operations.
[ "20\n", "5184\n", "1000000\n", "999979\n", "559872\n", "256\n", "279936\n", "1\n", "786432\n", "531441\n" ]
[ "10 2", "6 4", "10 4", "999979 0", "6 4", "2 3", "6 4", "1 0\n", "6 6", "3 5" ]
1
stdio
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese. -----Input----- The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. -----Output----- Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower). -----Examples----- Input sumimasen Output YES Input ninja Output YES Input codeforces Output NO -----Note----- In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
[ "sumimasen\n", "ninja\n", "codeforces\n", "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen\n", "n\n", "necnei\n", "nternn\n", "aucunuohja\n", "a\n", "b\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n" ]
1
stdio
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name $s$ can transform to another superhero with name $t$ if $s$ can be made equal to $t$ by changing any vowel in $s$ to any other vowel and any consonant in $s$ to any other consonant. Multiple changes can be made. In this problem, we consider the letters 'a', 'e', 'i', 'o' and 'u' to be vowels and all the other letters to be consonants. Given the names of two superheroes, determine if the superhero with name $s$ can be transformed to the Superhero with name $t$. -----Input----- The first line contains the string $s$ having length between $1$ and $1000$, inclusive. The second line contains the string $t$ having length between $1$ and $1000$, inclusive. Both strings $s$ and $t$ are guaranteed to be different and consist of lowercase English letters only. -----Output----- Output "Yes" (without quotes) if the superhero with name $s$ can be transformed to the superhero with name $t$ and "No" (without quotes) otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input a u Output Yes Input abc ukm Output Yes Input akm ua Output No -----Note----- In the first sample, since both 'a' and 'u' are vowels, it is possible to convert string $s$ to $t$. In the third sample, 'k' is a consonant, whereas 'a' is a vowel, so it is not possible to convert string $s$ to $t$.
[ "a\nu\n", "abc\nukm\n", "akm\nua\n", "u\nd\n", "aaaaaeeeeeiiiiiooooouuuuu\naeiouaeiouaeiouaeiouaeiou\n", "aaaaaeeeeeiiiiiooooouuuuu\nqwrtysdfghjklzxcvbnmplmjk\n", "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdchiytqlfsevymipufxkxojlvkkqxvjhpjmcxeiluua\nblcdiwjphlpzwvknsyvbcodpyktizgatrlieiikktghixbikehsiknjuateltwkyyhgabygwtclyeyquaoiqnypoxnvyzvyhfejole\n", "oihjee\naedcouklbbbcccvfgjkl\n", "abcdefghikl\njhg\n", "eeiaoouoouaiaiizjgkmwdqsgvqltfylymtdfrggphtfcaieiuueouaeieeiuuieuieaaeueiaeuaaiuiauueuiuieeaaoudymrtstxqsa\nouiiuaaaieiaueetzfpsncxlscpkwjlqymqqyckydhrhweueoeoeaauiiuaeauueuioueuioeoeoooeeuieoiouaieeuieegmrhdbfwttu\n" ]
[ "Yes\n", "Yes\n", "No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n" ]
1
stdio
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. -----Input----- The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. -----Output----- Print "YES", if problem is from this contest, and "NO" otherwise. -----Examples----- Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n", "Slava____and_the_game\n", "Olya_and_energy_drinks\n", "Danil_and_part_time_job\n", "Ann_and_books\n", "Olya\n", "Nikita\n", "Slava\n" ]
[ "NO", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES" ]
1
stdio
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers a, a + 1, ..., b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any integer x (a ≤ x ≤ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers. Find and print the required minimum l. If no value l meets the described limitations, print -1. -----Input----- A single line contains three space-separated integers a, b, k (1 ≤ a, b, k ≤ 10^6; a ≤ b). -----Output----- In a single line print a single integer — the required minimum l. If there's no solution, print -1. -----Examples----- Input 2 4 2 Output 3 Input 6 13 1 Output 4 Input 1 4 3 Output -1
[ "2 4 2\n", "6 13 1\n", "1 4 3\n", "5 8 2\n", "8 10 3\n", "1 5 2\n", "6 8 3\n", "21 29 2\n", "17 27 3\n", "1 1000000 10000\n" ]
[ "3\n", "4\n", "-1\n", "4\n", "-1\n", "3\n", "-1\n", "9\n", "11\n", "137970\n" ]
1
stdio
You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices. Calculate the minimum weight among all triangulations of the polygon. -----Input----- The first line contains single integer $n$ ($3 \le n \le 500$) — the number of vertices in the regular polygon. -----Output----- Print one integer — the minimum weight among all triangulations of the given polygon. -----Examples----- Input 3 Output 6 Input 4 Output 18 -----Note----- According to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $P$ into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is $P$. In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $1 \cdot 2 \cdot 3 = 6$. In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $1-3$ so answer is $1 \cdot 2 \cdot 3 + 1 \cdot 3 \cdot 4 = 6 + 12 = 18$.
[ "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "100\n", "101\n" ]
[ "6\n", "18\n", "38\n", "68\n", "110\n", "166\n", "238\n", "328\n", "333298\n", "343398\n" ]
1
stdio
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the books. -----Input----- The first line contains integer n (1 ≤ n ≤ 10^9) — the number of books in the library. -----Output----- Print the number of digits needed to number all the books. -----Examples----- Input 13 Output 17 Input 4 Output 4 -----Note----- Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
[ "13\n", "4\n", "100\n", "99\n", "1000000000\n", "1000000\n", "999\n", "55\n", "222222222\n", "8\n" ]
[ "17\n", "4\n", "192\n", "189\n", "8888888899\n", "5888896\n", "2889\n", "101\n", "1888888896\n", "8\n" ]
1
stdio
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$. It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $S$? -----Input----- The only line of the input contains two integers $n$ and $S$ ($1 \le n \le 100\,000$, $1 \le S \le 10^9$) -----Output----- Print exactly one integer — the minimum number of coins required to obtain sum $S$. -----Examples----- Input 5 11 Output 3 Input 6 16 Output 3 -----Note----- In the first example, some of the possible ways to get sum $11$ with $3$ coins are: $(3, 4, 4)$ $(2, 4, 5)$ $(1, 5, 5)$ $(3, 3, 5)$ It is impossible to get sum $11$ with less than $3$ coins. In the second example, some of the possible ways to get sum $16$ with $3$ coins are: $(5, 5, 6)$ $(4, 6, 6)$ It is impossible to get sum $16$ with less than $3$ coins.
[ "5 11\n", "6 16\n", "14 28\n", "5 29\n", "10 24\n", "1 30\n", "14969 66991573\n", "1 1000000000\n", "100000 1\n", "10 46\n" ]
[ "3", "3", "2", "6", "3", "30", "4476", "1000000000", "1", "5" ]
1
stdio
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. -----Input----- The only line contains string s (1 ≤ |s| ≤ 2·10^5) consisting of only lowercase Latin letters. -----Output----- Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. -----Examples----- Input aabc Output abba Input aabcd Output abcba
[ "aabc\n", "aabcd\n", "u\n", "ttttt\n", "xxxvvvxxvv\n", "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrrrffffwrrrwrwfffwrffrwwwrwww\n", "aabbcccdd\n", "baaab\n", "aaabbbhhlhlugkjgckj\n", "aabcc\n" ]
[ "abba\n", "abcba\n", "u\n", "ttttt\n", "vvvxxxxvvv\n", "fffffffffffffffrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrrrrrrrrrrrrrrrrrrfffffffffffffff\n", "abcdcdcba\n", "ababa\n", "aabbghjklclkjhgbbaa\n", "acbca\n" ]
1
stdio
You are given two circles. Find the area of their intersection. -----Input----- The first line contains three integers x_1, y_1, r_1 ( - 10^9 ≤ x_1, y_1 ≤ 10^9, 1 ≤ r_1 ≤ 10^9) — the position of the center and the radius of the first circle. The second line contains three integers x_2, y_2, r_2 ( - 10^9 ≤ x_2, y_2 ≤ 10^9, 1 ≤ r_2 ≤ 10^9) — the position of the center and the radius of the second circle. -----Output----- Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed 10^{ - 6}. -----Examples----- Input 0 0 4 6 0 4 Output 7.25298806364175601379 Input 0 0 5 11 0 5 Output 0.00000000000000000000
[ "0 0 4\n6 0 4\n", "0 0 5\n11 0 5\n", "0 0 10\n9 0 1\n", "0 0 2\n2 2 2\n", "0 0 10\n5 0 5\n", "-9 8 7\n-9 8 5\n", "-60 -85 95\n-69 -94 95\n", "159 111 998\n161 121 1023\n", "6008 8591 6693\n5310 8351 7192\n", "-13563 -6901 22958\n-19316 -16534 18514\n" ]
[ "7.25298806364175601379\n", "0.00000000000000000000\n", "3.14159265358979311600\n", "2.28318530717958647659\n", "78.53981633974482789995\n", "78.53981633974482789995\n", "25936.37843115316246844770\n", "3129038.84934604830277748988\n", "138921450.46886559338599909097\n", "868466038.83295116270892322063\n" ]
1
stdio
Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games. He came up with the following game. The player has a positive integer $n$. Initially the value of $n$ equals to $v$ and the player is able to do the following operation as many times as the player want (possibly zero): choose a positive integer $x$ that $x<n$ and $x$ is not a divisor of $n$, then subtract $x$ from $n$. The goal of the player is to minimize the value of $n$ in the end. Soon, Chouti found the game trivial. Can you also beat the game? -----Input----- The input contains only one integer in the first line: $v$ ($1 \le v \le 10^9$), the initial value of $n$. -----Output----- Output a single integer, the minimum value of $n$ the player can get. -----Examples----- Input 8 Output 1 Input 1 Output 1 -----Note----- In the first example, the player can choose $x=3$ in the first turn, then $n$ becomes $5$. He can then choose $x=4$ in the second turn to get $n=1$ as the result. There are other ways to get this minimum. However, for example, he cannot choose $x=2$ in the first turn because $2$ is a divisor of $8$. In the second example, since $n=1$ initially, the player can do nothing.
[ "8\n", "1\n", "4\n", "3\n", "158260522\n", "2\n", "1000000000\n", "5\n", "7\n", "9\n" ]
[ "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n" ]
1
stdio
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. -----Input----- The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. -----Output----- Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. -----Examples----- Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 -----Note----- In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy".
[ "7\nreading\ntrading\n", "5\nsweet\nsheep\n", "3\ntoy\ntry\n", "5\nspare\nspars\n", "1\na\nb\n", "1\nz\ny\n", "2\nab\nac\n", "2\nba\nca\n", "2\nac\ncb\n", "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\ndacdeebebeaeaacdeedadbcbaedcbddddddedacbabeddebaaebbdcebebaaccbaeccbecdbcbceadaaecadecbadbcddcdabecd\n" ]
[ "1\n", "0\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "0\n" ]
1
stdio
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. -----Input----- Each of the three lines of the input contains two integers. The i-th line contains integers x_{i} and y_{i} ( - 10^9 ≤ x_{i}, y_{i} ≤ 10^9) — the coordinates of the i-th point. It is guaranteed that all points are distinct. -----Output----- Print a single number — the minimum possible number of segments of the polyline. -----Examples----- Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 -----Note----- The variant of the polyline in the first sample: [Image] The variant of the polyline in the second sample: $1$ The variant of the polyline in the third sample: $\because$
[ "1 -1\n1 1\n1 2\n", "-1 -1\n-1 3\n4 3\n", "1 1\n2 3\n3 2\n", "1000000000 -1000000000\n1000000000 1000000000\n-1000000000 -1000000000\n", "-510073119 -991063686\n583272581 -991063686\n623462417 -991063686\n", "-422276230 -422225325\n-422276230 -544602611\n-282078856 -544602611\n", "127447697 -311048187\n-644646254 135095006\n127447697 135095006\n", "-609937696 436598127\n-189924209 241399893\n-883780251 296798182\n", "-931665727 768789996\n234859675 808326671\n-931665727 879145023\n", "899431605 238425805\n899431605 339067352\n940909482 333612216\n" ]
[ "1\n", "2\n", "3\n", "2\n", "1\n", "2\n", "2\n", "3\n", "3\n", "3\n" ]
1
stdio
An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components. Build a connected undirected k-regular graph containing at least one bridge, or else state that such graph doesn't exist. -----Input----- The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph. -----Output----- Print "NO" (without quotes), if such graph doesn't exist. Otherwise, print "YES" in the first line and the description of any suitable graph in the next lines. The description of the made graph must start with numbers n and m — the number of vertices and edges respectively. Each of the next m lines must contain two integers, a and b (1 ≤ a, b ≤ n, a ≠ b), that mean that there is an edge connecting the vertices a and b. A graph shouldn't contain multiple edges and edges that lead from a vertex to itself. A graph must be connected, the degrees of all vertices of the graph must be equal k. At least one edge of the graph must be a bridge. You can print the edges of the graph in any order. You can print the ends of each edge in any order. The constructed graph must contain at most 10^6 vertices and 10^6 edges (it is guaranteed that if at least one graph that meets the requirements exists, then there also exists the graph with at most 10^6 vertices and at most 10^6 edges). -----Examples----- Input 1 Output YES 2 1 1 2 -----Note----- In the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge.
[ "1\n", "3\n", "10\n", "2\n", "4\n", "5\n", "6\n", "7\n", "8\n", "12\n" ]
[ "YES\n2 1\n1 2\n", "YES\n10 15\n1 6\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10\n", "NO\n", "NO\n", "NO\n", "YES\n14 35\n1 8\n1 2\n1 3\n1 4\n1 5\n2 6\n2 7\n2 4\n2 5\n3 6\n3 7\n3 4\n3 5\n4 6\n4 7\n5 6\n5 7\n6 7\n8 9\n8 10\n8 11\n8 12\n9 13\n9 14\n9 11\n9 12\n10 13\n10 14\n10 11\n10 12\n11 13\n11 14\n12 13\n12 14\n13 14\n", "NO\n", "YES\n18 63\n1 10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 8\n2 9\n2 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 4\n3 5\n3 6\n3 7\n4 8\n4 9\n4 6\n4 7\n5 8\n5 9\n5 6\n5 7\n6 8\n6 9\n7 8\n7 9\n8 9\n10 11\n10 12\n10 13\n10 14\n10 15\n10 16\n11 17\n11 18\n11 13\n11 14\n11 15\n11 16\n12 17\n12 18\n12 13\n12 14\n12 15\n12 16\n13 17\n13 18\n13 15\n13 16\n14 17\n14 18\n14 15\n14 16\n15 17\n15 18\n16 17\n16 18\n17 18\n", "NO\n", "NO\n" ]
1
stdio
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree. A k-tree is an infinite rooted tree where: each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k. The picture below shows a part of a 3-tree. [Image] As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?". Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7). -----Input----- A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k). -----Output----- Print a single integer — the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 3 3 2 Output 3 Input 3 3 3 Output 1 Input 4 3 2 Output 6 Input 4 5 2 Output 7
[ "3 3 2\n", "3 3 3\n", "4 3 2\n", "4 5 2\n", "28 6 3\n", "5 100 1\n", "50 6 3\n", "10 13 6\n", "20 16 14\n", "1 10 1\n" ]
[ "3\n", "1\n", "6\n", "7\n", "110682188\n", "16\n", "295630102\n", "48\n", "236\n", "1\n" ]
1
stdio
You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'. The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ($0$-indexed) for each $i$. Note that this implies that $k$ won't always divide $a+b = |s|$. For example, the period of string "ABAABAA" is $3$, the period of "AAAA" is $1$, and the period of "AABBB" is $5$. Find the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'. -----Input----- The first line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the number of letters 'A' and 'B', respectively. -----Output----- Print the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'. -----Examples----- Input 2 4 Output 4 Input 5 3 Output 5 -----Note----- All the possible periods for the first example: $3$ "BBABBA" $4$ "BBAABB" $5$ "BBBAAB" $6$ "AABBBB" All the possible periods for the second example: $3$ "BAABAABA" $5$ "BAABABAA" $6$ "BABAAABA" $7$ "BAABAAAB" $8$ "AAAAABBB" Note that these are not the only possible strings for the given periods.
[ "2 4\n", "5 3\n", "1 1\n", "1 2\n", "2 1\n", "1000000000 1\n", "1 1000000000\n", "1000000000 1000000000\n", "49464524 956817411\n", "917980664 839933539\n" ]
[ "4\n", "5\n", "1\n", "2\n", "2\n", "500000001\n", "500000001\n", "1999936805\n", "1006177186\n", "1757835091\n" ]
1
stdio
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal". The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal. -----Input----- The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 10^9). -----Output----- If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0. -----Examples----- Input 15 20 Output 3 Input 14 8 Output -1 Input 6 6 Output 0
[ "15 20\n", "14 8\n", "6 6\n", "1 1\n", "1 1024\n", "1024 729\n", "1024 1048576\n", "36 30\n", "100 10\n", "21 35\n" ]
[ "3\n", "-1\n", "0\n", "0\n", "10\n", "16\n", "10\n", "3\n", "2\n", "2\n" ]
1
stdio
You are given a cube of size k × k × k, which consists of unit cubes. Two unit cubes are considered neighbouring, if they have common face. Your task is to paint each of k^3 unit cubes one of two colours (black or white), so that the following conditions must be satisfied: each white cube has exactly 2 neighbouring cubes of white color; each black cube has exactly 2 neighbouring cubes of black color. -----Input----- The first line contains integer k (1 ≤ k ≤ 100), which is size of the cube. -----Output----- Print -1 if there is no solution. Otherwise, print the required painting of the cube consequently by layers. Print a k × k matrix in the first k lines, showing how the first layer of the cube should be painted. In the following k lines print a k × k matrix — the way the second layer should be painted. And so on to the last k-th layer. Note that orientation of the cube in the space does not matter. Mark a white unit cube with symbol "w" and a black one with "b". Use the format of output data, given in the test samples. You may print extra empty lines, they will be ignored. -----Examples----- Input 1 Output -1 Input 2 Output bb ww bb ww
[ "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "9\n", "11\n", "13\n" ]
[ "-1\n", "bb\nww\n\nbb\nww\n", "-1\n", "bbbb\nbwwb\nbwwb\nbbbb\n\nwwww\nwbbw\nwbbw\nwwww\n\nbbbb\nbwwb\nbwwb\nbbbb\n\nwwww\nwbbw\nwbbw\nwwww\n", "-1\n", "bbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwwwwww\nwbbbbw\nwbwwbw\nwbwwbw\nwbbbbw\nwwwwww\n\nbbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwwwwww\nwbbbbw\nwbwwbw\nwbwwbw\nwbbbbw\nwwwwww\n\nbbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwwwwww\nwbbbbw\nwbwwbw\nwbwwbw\nwbbbbw\nwwwwww\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
1
stdio
Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a^2 is a divisor of x. [Image] Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible. Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store. -----Input----- The first and only line of input contains one integer, n (1 ≤ n ≤ 10^12). -----Output----- Print the answer in one line. -----Examples----- Input 10 Output 10 Input 12 Output 6 -----Note----- In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely. In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2^2, so 12 is not lovely, while 6 is indeed lovely.
[ "10\n", "12\n", "1\n", "2\n", "4\n", "8\n", "3\n", "31\n", "97\n", "1000000000000\n" ]
[ "10\n", "6\n", "1\n", "2\n", "2\n", "2\n", "3\n", "31\n", "97\n", "10\n" ]
1
stdio
A positive integer is called a 2-3-integer, if it is equal to 2^{x}·3^{y} for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not. Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r. -----Input----- The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·10^9). -----Output----- Print a single integer the number of 2-3-integers on the segment [l, r]. -----Examples----- Input 1 10 Output 7 Input 100 200 Output 5 Input 1 2000000000 Output 326 -----Note----- In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9. In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
[ "1 10\n", "100 200\n", "1 2000000000\n", "1088391168 1934917632\n", "1088391167 1934917632\n", "1088391169 1934917632\n", "1088391168 1934917631\n", "1088391168 1934917633\n", "4 134217728\n", "209952 43046722\n" ]
[ "7\n", "5\n", "326\n", "17\n", "17\n", "16\n", "16\n", "17\n", "250\n", "112\n" ]
1
stdio
Imp likes his plush toy a lot. [Image] Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. -----Input----- The only line contains two integers x and y (0 ≤ x, y ≤ 10^9) — the number of copies and the number of original toys Imp wants to get (including the initial one). -----Output----- Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). -----Examples----- Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes -----Note----- In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
[ "6 3\n", "4 2\n", "1000 1001\n", "1000000000 999999999\n", "81452244 81452247\n", "188032448 86524683\n", "365289629 223844571\n", "247579518 361164458\n", "424836699 793451637\n", "602093880 930771525\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n" ]
1
stdio
Ivan has number $b$. He is sorting through the numbers $a$ from $1$ to $10^{18}$, and for every $a$ writes $\frac{[a, \,\, b]}{a}$ on blackboard. Here $[a, \,\, b]$ stands for least common multiple of $a$ and $b$. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board. -----Input----- The only line contains one integer — $b$ $(1 \le b \le 10^{10})$. -----Output----- Print one number — answer for the problem. -----Examples----- Input 1 Output 1 Input 2 Output 2 -----Note----- In the first example $[a, \,\, 1] = a$, therefore $\frac{[a, \,\, b]}{a}$ is always equal to $1$. In the second example $[a, \,\, 2]$ can be equal to $a$ or $2 \cdot a$ depending on parity of $a$. $\frac{[a, \,\, b]}{a}$ can be equal to $1$ and $2$.
[ "1\n", "2\n", "16\n", "433494437\n", "10000000000\n", "169\n", "244078129\n", "7169516929\n", "2147483647\n", "2971215073\n" ]
[ "1", "2", "5", "2", "121", "3", "9", "3", "2", "2" ]
1
stdio
The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching). Since she knows how reckless her pilots are, she wants to be sure that any two (straight) paths – from a base to its assigned spaceship – do not intersect in the galaxy plane (that is, in 2D), and so there is no risk of collision. -----Input----- The first line contains two space-separated integers R, B(1 ≤ R, B ≤ 10). For 1 ≤ i ≤ R, the i + 1-th line contains two space-separated integers x_{i} and y_{i} (|x_{i}|, |y_{i}| ≤ 10000) denoting the coordinates of the i-th Rebel spaceship. The following B lines have the same format, denoting the position of bases. It is guaranteed that no two points coincide and that no three points are on the same line. -----Output----- If it is possible to connect Rebel spaceships and bases so as satisfy the constraint, output Yes, otherwise output No (without quote). -----Examples----- Input 3 3 0 0 2 0 3 1 -2 1 0 3 2 2 Output Yes Input 2 1 1 0 2 2 3 1 Output No -----Note----- For the first example, one possible way is to connect the Rebels and bases in order. For the second example, there is no perfect matching between Rebels and bases.
[ "3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2\n", "2 1\n1 0\n2 2\n3 1\n", "1 1\n3686 4362\n-7485 5112\n", "1 2\n1152 -7324\n-5137 -35\n-6045 -5271\n", "1 3\n-8824 -9306\n-5646 -9767\n8123 9355\n-6203 -1643\n", "1 5\n-8775 6730\n-3806 -6906\n-9256 -8240\n-1320 6849\n8155 746\n8284 -7317\n", "1 8\n8741 3638\n381 -9191\n7534 8792\n-8848 -414\n2926 -7444\n9475 559\n6938 2359\n2570 4721\n3329 -9365\n", "1 9\n6207 1655\n2728 8520\n9142 3418\n-1258 -8727\n5370 3161\n-5167 -7691\n517 2242\n3702 -9904\n-6862 -2997\n2524 -5492\n", "1 10\n9424 3979\n-8582 9252\n-2432 -3287\n-4247 1932\n-9491 5544\n-635 5689\n8260 -6790\n8841 3067\n-5624 -1990\n1569 1045\n-8844 -8462\n", "2 1\n2893 -5488\n-5087 -5042\n-8928 -9453\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
1
stdio
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n. Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result? -----Input----- The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 10^4), separated by a space . -----Output----- Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n. -----Examples----- Input 4 6 Output 2 Input 10 1 Output 9 -----Note----- In the first example you need to push the blue button once, and then push the red button once. In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
[ "4 6\n", "10 1\n", "1 2\n", "2 1\n", "1 3\n", "3 1\n", "2 10\n", "100 99\n", "99 100\n", "10 17\n" ]
[ "2\n", "9\n", "1\n", "1\n", "3\n", "2\n", "5\n", "1\n", "50\n", "3\n" ]
1
stdio
We get more and more news about DDoS-attacks of popular websites. Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $100 \cdot t$, where $t$ — the number of seconds in this time segment. Arseny knows statistics on the number of requests per second since the server is booted. He knows the sequence $r_1, r_2, \dots, r_n$, where $r_i$ — the number of requests in the $i$-th second after boot. Determine the length of the longest continuous period of time, which Arseny considers to be a DDoS-attack. A seeking time period should not go beyond the boundaries of the segment $[1, n]$. -----Input----- The first line contains $n$ ($1 \le n \le 5000$) — number of seconds since server has been booted. The second line contains sequence of integers $r_1, r_2, \dots, r_n$ ($0 \le r_i \le 5000$), $r_i$ — number of requests in the $i$-th second. -----Output----- Print the only integer number — the length of the longest time period which is considered to be a DDoS-attack by Arseny. If it doesn't exist print 0. -----Examples----- Input 5 100 200 1 1 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 2 101 99 Output 1
[ "5\n100 200 1 1 1\n", "5\n1 2 3 4 5\n", "2\n101 99\n", "1\n41\n", "2\n1 91\n", "10\n58 10 43 61 64 6 39 199 46 29\n", "10\n33 202 11 64 5 295 34 25 89 50\n", "20\n46 291 21 20 60 47 47 43 243 78 75 44 41 54 11 79 47 93 268 3\n", "30\n67 3 99 36 53 9 17 55 63 7 42 3 42 10 67 97 65 266 65 17 52 76 17 47 269 159 24 12 64 40\n", "40\n81 222 69 50 73 51 78 94 17 69 17 54 13 59 44 291 3 67 293 32 7 155 29 49 170 69 72 56 62 94 34 194 58 32 42 27 46 56 8 46\n" ]
[ "3\n", "0\n", "1\n", "0\n", "0\n", "2\n", "6\n", "4\n", "11\n", "12\n" ]
1
stdio
We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds. Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others. Let S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of S - T are there? -----Constraints----- - -10^8 \leq X, D \leq 10^8 - 1 \leq N \leq 2 \times 10^5 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N X D -----Output----- Print the number of possible values of S - T. -----Sample Input----- 3 4 2 -----Sample Output----- 8 A is (4, 6, 8). There are eight ways for (Takahashi, Aoki) to take the elements: ((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4))), and ((4, 6, 8), ()). The values of S - T in these ways are -18, -10, -6, -2, 2, 6, 10, and 18, respectively, so there are eight possible values of S - T.
[ "3 4 2\n", "2 3 -3\n", "100 14 20\n", "17 3 -4\n", "7 5 5\n", "2 -5 -3\n", "2 -7 5\n", "3 0 -9\n", "8 6 0\n", "8 6 -4\n" ]
[ "8\n", "2\n", "49805\n", "494\n", "29\n", "4\n", "4\n", "4\n", "9\n", "41\n" ]
1
stdio
In the city of Saint Petersburg, a day lasts for $2^{100}$ minutes. From the main station of Saint Petersburg, a train departs after $1$ minute, $4$ minutes, $16$ minutes, and so on; in other words, the train departs at time $4^k$ for each integer $k \geq 0$. Team BowWow has arrived at the station at the time $s$ and it is trying to count how many trains have they missed; in other words, the number of trains that have departed strictly before time $s$. For example if $s = 20$, then they missed trains which have departed at $1$, $4$ and $16$. As you are the only one who knows the time, help them! Note that the number $s$ will be given you in a binary representation without leading zeroes. -----Input----- The first line contains a single binary number $s$ ($0 \leq s < 2^{100}$) without leading zeroes. -----Output----- Output a single number — the number of trains which have departed strictly before the time $s$. -----Examples----- Input 100000000 Output 4 Input 101 Output 2 Input 10100 Output 3 -----Note----- In the first example $100000000_2 = 256_{10}$, missed trains have departed at $1$, $4$, $16$ and $64$. In the second example $101_2 = 5_{10}$, trains have departed at $1$ and $4$. The third example is explained in the statements.
[ "100000000\n", "101\n", "10100\n", "1111010010000101100100001110011101111\n", "11110010110000101001001101010111110101101111001000100100101111011\n", "0\n", "10000\n", "1000010011100010111000001101000011001010011101011001101100000001011011000000101101101011101111011011\n", "1000\n", "1\n" ]
[ "4\n", "2\n", "3\n", "19\n", "33\n", "0\n", "2\n", "50\n", "2\n", "0\n" ]
1
stdio
A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time l_{i} and the finish time r_{i} (l_{i} ≤ r_{i}). Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept? No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both. -----Input----- The first line contains integer number n (1 ≤ n ≤ 5·10^5) — number of orders. The following n lines contain integer values l_{i} and r_{i} each (1 ≤ l_{i} ≤ r_{i} ≤ 10^9). -----Output----- Print the maximal number of orders that can be accepted. -----Examples----- Input 2 7 11 4 7 Output 1 Input 5 1 2 2 3 3 4 4 5 5 6 Output 3 Input 6 4 8 1 5 4 7 2 5 1 3 6 8 Output 2
[ "2\n7 11\n4 7\n", "5\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n", "1\n1 1\n", "2\n4 6\n4 8\n", "3\n22 22\n14 21\n9 25\n", "4\n20 59\n30 62\n29 45\n29 32\n", "5\n40 124\n40 117\n67 106\n36 121\n38 102\n", "6\n124 155\n50 93\n45 120\n54 171\n46 190\n76 179\n", "7\n94 113\n54 248\n64 325\n280 306\n62 328\n49 341\n90 324\n" ]
[ "1\n", "3\n", "2\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "2\n" ]
1
stdio
Ania has a large integer $S$. Its decimal representation has length $n$ and doesn't contain any leading zeroes. Ania is allowed to change at most $k$ digits of $S$. She wants to do it in such a way that $S$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? -----Input----- The first line contains two integers $n$ and $k$ ($1 \leq n \leq 200\,000$, $0 \leq k \leq n$) — the number of digits in the decimal representation of $S$ and the maximum allowed number of changed digits. The second line contains the integer $S$. It's guaranteed that $S$ has exactly $n$ digits and doesn't contain any leading zeroes. -----Output----- Output the minimal possible value of $S$ which Ania can end with. Note that the resulting integer should also have $n$ digits. -----Examples----- Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 -----Note----- A number has leading zeroes if it consists of at least two digits and its first digit is $0$. For example, numbers $00$, $00069$ and $0101$ have leading zeroes, while $0$, $3000$ and $1010$ don't have leading zeroes.
[ "5 3\n51528\n", "3 2\n102\n", "1 1\n1\n", "8 3\n76185080\n", "10 9\n6605076924\n", "17 14\n70419129275429261\n", "1 0\n1\n", "1 1\n0\n", "2 1\n16\n", "1 0\n0\n" ]
[ "10028\n", "100\n", "0\n", "10085080\n", "1000000000\n", "10000000000000061\n", "1\n", "0\n", "10\n", "0\n" ]
1
stdio
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance. [Image] Illustration for n = 6, a = 2, b = - 5. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. -----Input----- The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n, - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. -----Output----- Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk. -----Examples----- Input 6 2 -5 Output 3 Input 5 1 3 Output 4 Input 3 2 7 Output 3 -----Note----- The first example is illustrated by the picture in the statements.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n", "1 1 0\n", "1 1 -1\n", "1 1 1\n", "100 1 -1\n", "100 54 100\n", "100 37 -100\n", "99 41 0\n" ]
[ "3\n", "4\n", "3\n", "1\n", "1\n", "1\n", "100\n", "54\n", "37\n", "41\n" ]
1
stdio
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[ "4 2\nabba\n", "8 1\naabaabaa\n", "1 0\na\n", "1 1\nb\n", "1 0\nb\n", "1 1\na\n", "10 10\nbbbbbbbbbb\n", "10 2\nbbbbbbbbbb\n", "10 1\nbbabbabbba\n", "10 10\nbbabbbaabb\n" ]
[ "4\n", "5\n", "1\n", "1\n", "1\n", "1\n", "10\n", "10\n", "6\n", "10\n" ]
1
stdio
Santa Claus has n candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has. -----Input----- The only line contains positive integer number n (1 ≤ n ≤ 1000) — number of candies Santa Claus has. -----Output----- Print to the first line integer number k — maximal number of kids which can get candies. Print to the second line k distinct integer numbers: number of candies for each of k kid. The sum of k printed numbers should be exactly n. If there are many solutions, print any of them. -----Examples----- Input 5 Output 2 2 3 Input 9 Output 3 3 5 1 Input 2 Output 1 2
[ "5\n", "9\n", "2\n", "1\n", "3\n", "1000\n", "4\n", "6\n", "7\n", "8\n" ]
[ "2\n1 4 \n", "3\n1 2 6 \n", "1\n2 \n", "1\n1 \n", "2\n1 2 \n", "44\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 54 \n", "2\n1 3 \n", "3\n1 2 3 \n", "3\n1 2 4 \n", "3\n1 2 5 \n" ]
1
stdio
The following problem is well-known: given integers n and m, calculate $2^{n} \operatorname{mod} m$, where 2^{n} = 2·2·...·2 (n factors), and $x \operatorname{mod} y$ denotes the remainder of division of x by y. You are asked to solve the "reverse" problem. Given integers n and m, calculate $m \operatorname{mod} 2^{n}$. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 10^8). The second line contains a single integer m (1 ≤ m ≤ 10^8). -----Output----- Output a single integer — the value of $m \operatorname{mod} 2^{n}$. -----Examples----- Input 4 42 Output 10 Input 1 58 Output 0 Input 98765432 23456789 Output 23456789 -----Note----- In the first example, the remainder of division of 42 by 2^4 = 16 is equal to 10. In the second example, 58 is divisible by 2^1 = 2 without remainder, and the answer is 0.
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n", "8\n88127381\n", "32\n92831989\n", "92831989\n25\n", "100000000\n100000000\n", "7\n1234\n", "1\n1\n", "1\n100000000\n" ]
[ "10\n", "0\n", "23456789\n", "149\n", "92831989\n", "25\n", "100000000\n", "82\n", "1\n", "0\n" ]
1
stdio
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word s. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels. -----Input----- The first line contains one integer n (1 ≤ n ≤ 100) — the number of letters in word s before the correction. The second line contains a string s consisting of exactly n lowercase Latin letters — the word before the correction. -----Output----- Output the word s after the correction. -----Examples----- Input 5 weird Output werd Input 4 word Output word Input 5 aaeaa Output a -----Note----- Explanations of the examples: There is only one replace: weird $\rightarrow$ werd; No replace needed since there are no two consecutive vowels; aaeaa $\rightarrow$ aeaa $\rightarrow$ aaa $\rightarrow$ aa $\rightarrow$ a.
[ "5\nweird\n", "4\nword\n", "5\naaeaa\n", "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw\n", "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "12\nmmmmmmmmmmmm\n", "18\nyaywptqwuyiqypwoyw\n", "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "13\nmmmmmmmmmmmmm\n", "10\nmmmmmmmmmm\n" ]
[ "werd\n", "word\n", "a\n", "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw\n", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "mmmmmmmmmmmm\n", "ywptqwuqypwow\n", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "mmmmmmmmmmmmm\n", "mmmmmmmmmm\n" ]
1
stdio
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor. Heidi figured out that Madame Kovarian uses a very complicated hashing function in order to change the names of the babies she steals. In order to prevent this from happening to future Doctors, Heidi decided to prepare herself by learning some basic hashing techniques. The first hashing function she designed is as follows. Given two positive integers $(x, y)$ she defines $H(x,y):=x^2+2xy+x+1$. Now, Heidi wonders if the function is reversible. That is, given a positive integer $r$, can you find a pair $(x, y)$ (of positive integers) such that $H(x, y) = r$? If multiple such pairs exist, output the one with smallest possible $x$. If there is no such pair, output "NO". -----Input----- The first and only line contains an integer $r$ ($1 \le r \le 10^{12}$). -----Output----- Output integers $x, y$ such that $H(x,y) = r$ and $x$ is smallest possible, or "NO" if no such pair exists. -----Examples----- Input 19 Output 1 8 Input 16 Output NO
[ "19\n", "16\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n" ]
[ "1 8\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "1 1\n", "NO\n", "1 2\n", "NO\n" ]
1
stdio
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), x_{i} + x_{j} is a prime. You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size. A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it. -----Input----- The first line contains integer n (1 ≤ n ≤ 1000) — the number of integers in the array a. The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^6) — the elements of the array a. -----Output----- On the first line print integer m — the maximum possible size of simple subset of a. On the second line print m integers b_{l} — the elements of the simple subset of the array a with the maximum size. If there is more than one solution you can print any of them. You can print the elements of the subset in any order. -----Examples----- Input 2 2 3 Output 2 3 2 Input 2 2 2 Output 1 2 Input 3 2 1 1 Output 3 1 1 2 Input 2 83 14 Output 2 14 83
[ "2\n2 3\n", "2\n2 2\n", "3\n2 1 1\n", "2\n83 14\n", "10\n10 10 1 2 3 3 1 2 1 5\n", "100\n314 905 555 526 981 360 424 104 920 814 143 872 741 592 105 573 837 962 220 692 560 493 889 824 145 491 828 960 889 87 375 486 609 423 386 323 124 830 206 446 899 522 514 696 786 783 268 483 318 261 675 445 1000 896 812 277 131 264 860 514 701 678 792 394 324 244 483 357 69 931 590 452 626 451 976 317 722 564 809 40 265 709 13 700 769 869 131 834 712 478 661 369 805 668 512 184 477 896 808 168\n", "100\n174 816 593 727 182 151 842 277 1 942 307 939 447 738 823 744 319 394 515 451 875 950 319 789 384 292 190 758 927 103 246 1 675 42 398 631 382 893 646 2 773 157 992 425 804 565 500 242 2 657 611 647 4 331 99 1 694 18 119 364 458 569 94 999 72 7 297 102 982 859 786 868 178 393 642 254 707 41 103 764 934 70 775 41 188 199 767 64 84 899 626 224 279 188 659 374 105 178 154 758\n", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "100\n966 680 370 134 202 826 254 620 700 336 938 344 368 108 732 130 134 700 996 904 644 734 184 134 996 46 146 928 320 664 304 160 358 306 330 132 674 16 338 138 926 994 196 960 972 972 756 276 600 982 588 978 868 572 446 578 692 976 780 434 882 344 980 536 856 916 966 936 178 300 294 568 984 54 238 718 582 400 572 142 118 306 222 850 948 954 682 256 70 550 830 980 646 970 688 56 552 592 200 682\n", "100\n598 236 971 958 277 96 651 366 629 50 601 822 744 326 276 330 413 531 791 655 450 173 992 80 401 760 227 64 350 711 258 545 212 690 996 515 983 835 388 311 970 608 185 164 491 419 295 293 274 93 339 761 155 307 991 857 309 957 563 232 328 682 779 637 312 888 305 184 15 556 427 211 327 313 516 815 914 588 592 988 151 839 828 339 196 462 752 454 865 479 356 529 320 59 908 840 294 882 189 6\n" ]
[ "2\n3 2\n", "1\n2\n", "3\n1 1 2\n", "2\n14 83\n", "4\n1 1 10 1\n", "2\n104 905\n", "4\n1 1 738 1\n", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "1\n966\n", "2\n96 277\n" ]
1
stdio
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes. Some examples of beautiful numbers: 1_2 (1_10); 110_2 (6_10); 1111000_2 (120_10); 111110000_2 (496_10). More formally, the number is beautiful iff there exists some positive integer k such that the number is equal to (2^{k} - 1) * (2^{k} - 1). Luba has got an integer number n, and she wants to find its greatest beautiful divisor. Help her to find it! -----Input----- The only line of input contains one number n (1 ≤ n ≤ 10^5) — the number Luba has got. -----Output----- Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. -----Examples----- Input 3 Output 1 Input 992 Output 496
[ "3\n", "992\n", "81142\n", "76920\n", "2016\n", "1\n", "6\n", "32640\n", "12096\n", "55948\n" ]
[ "1\n", "496\n", "1\n", "120\n", "2016\n", "1\n", "6\n", "32640\n", "2016\n", "1\n" ]
1
stdio
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? -----Input----- The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). -----Output----- Output the minimum number of bills that Allen could receive. -----Examples----- Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 -----Note----- In 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.
[ "125\n", "43\n", "1000000000\n", "4\n", "5\n", "1\n", "74\n", "31\n", "59\n", "79\n" ]
[ "3\n", "5\n", "10000000\n", "4\n", "1\n", "1\n", "8\n", "3\n", "8\n", "9\n" ]
1
stdio
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains two space-separated integers p, q (1 ≤ q ≤ p ≤ 10^18) — the numerator and the denominator of the first fraction. The second line contains integer n (1 ≤ n ≤ 90) — the height of the second fraction. The third line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^18) — the continued fraction. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Output----- Print "YES" if these fractions are equal and "NO" otherwise. -----Examples----- Input 9 4 2 2 4 Output YES Input 9 4 3 2 3 1 Output YES Input 9 4 3 1 2 4 Output NO -----Note----- In the first sample $2 + \frac{1}{4} = \frac{9}{4}$. In the second sample $2 + \frac{1}{3 + \frac{1}{1}} = 2 + \frac{1}{4} = \frac{9}{4}$. In the third sample $1 + \frac{1}{2 + \frac{1}{4}} = \frac{13}{9}$.
[ "9 4\n2\n2 4\n", "9 4\n3\n2 3 1\n", "9 4\n3\n1 2 4\n", "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2\n", "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4\n", "61305790721611591 37889062373143906\n80\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4\n", "61305790721611591 37889062373143906\n80\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2\n", "565049485241691020 228217260073568804\n40\n2 2 9 1 7 1 2 1 2 1 1 1 9 1 2 1 9 1 3 2 3 10 13 2 1 2 7 1 1 2 2 2 1 1 2 1 6 5 3 2\n", "2 1\n4\n2 1 1 1\n", "4 1\n2\n3 1\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n" ]
1
stdio
Let us define the oddness of a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n} as \sum_{i = 1}^n |i - p_i|. Find the number of permutations of {1,\ 2,\ ...,\ n} of oddness k, modulo 10^9+7. -----Constraints----- - All values in input are integers. - 1 \leq n \leq 50 - 0 \leq k \leq n^2 -----Input----- Input is given from Standard Input in the following format: n k -----Output----- Print the number of permutations of {1,\ 2,\ ...,\ n} of oddness k, modulo 10^9+7. -----Sample Input----- 3 2 -----Sample Output----- 2 There are six permutations of {1,\ 2,\ 3}. Among them, two have oddness of 2: {2,\ 1,\ 3} and {1,\ 3,\ 2}.
[ "3 2\n", "39 14\n", "44 350\n", "22 444\n", "1 0\n", "34 712\n", "10 82\n", "17 222\n", "40 1062\n", "38 716\n" ]
[ "2\n", "74764168\n", "15060087\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "810790165\n" ]
1
stdio
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers. The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here. To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length. Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking! -----Input----- The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview. The second line contains the string s of length n, consisting of lowercase English letters. -----Output----- Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. -----Examples----- Input 7 aogogob Output a***b Input 13 ogogmgogogogo Output ***gmg*** Input 9 ogoogoogo Output ********* -----Note----- The first sample contains one filler word ogogo, so the interview for printing is "a***b". The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
[ "7\naogogob\n", "13\nogogmgogogogo\n", "9\nogoogoogo\n", "32\nabcdefogoghijklmnogoopqrstuvwxyz\n", "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo\n", "10\nogooggoggo\n", "20\nooggooogooogooogooog\n", "30\ngoggogoooggooggggoggoggoogoggo\n", "40\nogggogooggoogoogggogooogogggoogggooggooo\n", "50\noggggogoogggggggoogogggoooggooogoggogooogogggogooo\n" ]
[ "a***b\n", "***gmg***\n", "*********\n", "abcdef***ghijklmn***opqrstuvwxyz\n", "gg***oogg***oggoggoggggg******ggooooggooggooogg***ooggoggoogggo***ggogggoooggoggoggoggg***ogggoooo\n", "***oggoggo\n", "ooggoo***o***o***oog\n", "gogg***ooggooggggoggoggo***ggo\n", "oggg***oggo***oggg***o***gggoogggooggooo\n", "ogggg***ogggggggo***gggoooggoo***gg***o***ggg***oo\n" ]
1
stdio
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds in such a way, that at least n·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. -----Input----- The first line contains two integers c and d (1 ≤ c, d ≤ 100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100). Finally, the third line contains an integer k (1 ≤ k ≤ 100) — the number of the pre-chosen winners. -----Output----- In the first line, print a single integer — the minimum number of problems the jury needs to prepare. -----Examples----- Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
[ "1 10\n7 2\n1\n", "2 2\n2 1\n2\n", "8 9\n2 2\n3\n", "5 5\n8 8\n7\n", "1 8\n8 10\n8\n", "5 7\n9 1\n8\n", "35 28\n35 60\n44\n", "19 76\n91 91\n87\n", "20 38\n38 70\n58\n", "2 81\n3 39\n45\n" ]
[ "2\n", "0\n", "8\n", "40\n", "9\n", "5\n", "2065\n", "1729\n", "1380\n", "48\n" ]
1
stdio
Let's consider equation:x^2 + 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. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — 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. -----Output----- 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. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
[ "2\n", "110\n", "4\n", "8\n", "10000000100000000\n", "10000006999999929\n", "172541340\n", "172580744\n", "10000100000\n", "1000001000000\n" ]
[ "1\n", "10\n", "-1\n", "2\n", "100000000\n", "99999999\n", "13131\n", "13132\n", "100000\n", "1000000\n" ]
1
stdio
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample). -----Input----- The first line contains current time s as a string in the format "hh:mm". The second line contains time t in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59. -----Output----- In the single line print time p — the time George went to bed in the format similar to the format of the time in the input. -----Examples----- Input 05:50 05:44 Output 00:06 Input 00:00 01:00 Output 23:00 Input 00:01 00:00 Output 00:01 -----Note----- In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect. In the second sample, George went to bed yesterday. In the third sample, George didn't do to bed at all.
[ "05:50\n05:44\n", "00:00\n01:00\n", "00:01\n00:00\n", "23:59\n23:59\n", "23:44\n23:55\n", "00:00\n13:12\n", "12:00\n23:59\n", "12:44\n12:44\n", "05:55\n07:12\n", "07:12\n05:55\n" ]
[ "00:06\n", "23:00\n", "00:01\n", "00:00\n", "23:49\n", "10:48\n", "12:01\n", "00:00\n", "22:43\n", "01:17\n" ]
1
stdio
You are given array $a_1, a_2, \dots, a_n$. Find the subsegment $a_l, a_{l+1}, \dots, a_r$ ($1 \le l \le r \le n$) with maximum arithmetic mean $\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$ (in floating-point numbers, i.e. without any rounding). If there are many such subsegments find the longest one. -----Input----- The first line contains single integer $n$ ($1 \le n \le 10^5$) — length of the array $a$. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$) — the array $a$. -----Output----- Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean. -----Example----- Input 5 6 1 6 6 0 Output 2 -----Note----- The subsegment $[3, 4]$ is the longest among all subsegments with maximum arithmetic mean.
[ "5\n6 1 6 6 0\n", "1\n1000000000\n", "6\n1 1 0 1 1 1\n", "5\n2 2 2 2 3\n", "6\n3 3 2 2 2 2\n", "2\n1 2\n", "69\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70\n", "3\n0 0 0\n", "6\n2 2 2 2 1 5\n", "5\n0 0 0 0 0\n" ]
[ "2\n", "1\n", "3\n", "1\n", "2\n", "1\n", "1\n", "3\n", "1\n", "5\n" ]
1
stdio
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. -----Input----- The first line of input contains an integer n, (1 ≤ n ≤ 10^9). This number doesn't contain leading zeros. -----Output----- Print "YES" if n is a magic number or print "NO" if it's not. -----Examples----- Input 114114 Output YES Input 1111 Output YES Input 441231 Output NO
[ "114114\n", "1111\n", "441231\n", "1\n", "14\n", "114\n", "9\n", "414\n", "1000000000\n", "144144144\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n" ]
1
stdio
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1. You are given a positive integer x. Your task is to count the number of cells in a table that contain number x. -----Input----- The single line contains numbers n and x (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9) — the size of the table and the number that we are looking for in the table. -----Output----- Print a single number: the number of times x occurs in the table. -----Examples----- Input 10 5 Output 2 Input 6 12 Output 4 Input 5 13 Output 0 -----Note----- A table for the second sample test is given below. The occurrences of number 12 are marked bold. [Image]
[ "10 5\n", "6 12\n", "5 13\n", "1 1\n", "2 1\n", "100000 1\n", "1 1000000000\n", "100000 1000000000\n", "100000 362880\n", "1 4\n" ]
[ "2\n", "4\n", "0\n", "1\n", "1\n", "1\n", "0\n", "16\n", "154\n", "0\n" ]
1
stdio
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives! The funny part is that these tasks would be very easy for a human to solve. The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point. -----Input----- The first line contains an integer $n$ ($2 \le n \le 10$). Each of the following $4n + 1$ lines contains two integers $x_i, y_i$ ($0 \leq x_i, y_i \leq 50$), describing the coordinates of the next point. It is guaranteed that there are at least $n$ points on each side of the square and all $4n + 1$ points are distinct. -----Output----- Print two integers — the coordinates of the point that is not on the boundary of the square. -----Examples----- Input 2 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2 Output 1 1 Input 2 0 0 0 1 0 2 0 3 1 0 1 2 2 0 2 1 2 2 Output 0 3 -----Note----- In both examples, the square has four sides $x=0$, $x=2$, $y=0$, $y=2$.
[ "2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2\n", "2\n0 0\n0 1\n0 2\n0 3\n1 0\n1 2\n2 0\n2 1\n2 2\n", "2\n5 14\n5 17\n25 43\n26 43\n32 41\n33 0\n38 0\n48 17\n48 30\n", "2\n17 44\n19 14\n19 25\n24 27\n32 1\n34 27\n38 1\n45 5\n45 12\n", "2\n1 2\n1 27\n1 45\n10 45\n28 48\n38 1\n44 1\n45 7\n45 26\n", "2\n2 27\n2 40\n9 44\n10 13\n12 1\n22 44\n26 13\n33 22\n33 36\n", "2\n0 30\n0 33\n18 1\n21 1\n31 47\n42 50\n49 16\n49 21\n49 50\n", "3\n1 3\n1 18\n1 41\n4 43\n12 1\n21 50\n27 1\n27 50\n33 1\n34 50\n50 6\n50 7\n50 26\n", "3\n8 18\n8 25\n8 31\n13 43\n14 43\n24 11\n33 43\n34 11\n37 11\n40 21\n40 28\n40 35\n44 38\n", "3\n9 8\n23 15\n23 19\n23 23\n27 30\n31 30\n37 30\n38 6\n39 6\n47 6\n47 16\n47 21\n47 25\n" ]
[ "1 1\n", "0 3\n", "32 41\n", "17 44\n", "28 48\n", "12 1\n", "31 47\n", "4 43\n", "44 38\n", "9 8\n" ]
1
stdio
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$. -----Input----- The only input line contains the integer $n$ ($1 \le n \le 2\cdot10^9$). -----Output----- Print the maximum product of digits among all integers from $1$ to $n$. -----Examples----- Input 390 Output 216 Input 7 Output 7 Input 1000000000 Output 387420489 -----Note----- In 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$).
[ "390\n", "7\n", "1000000000\n", "1\n", "9\n", "2000000000\n", "4876\n", "889878787\n", "1382011913\n", "999999999\n" ]
[ "216\n", "7\n", "387420489\n", "1\n", "9\n", "387420489\n", "2268\n", "301327047\n", "387420489\n", "387420489\n" ]
1
stdio
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right. You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it. How many operations will you need to perform until the next operation does not have any points to delete? -----Input----- Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc. The number of the points is between 1 and 10^6. -----Output----- Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete. -----Examples----- Input aabb Output 2 Input aabcaa Output 1 -----Note----- In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to. In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.
[ "aabb\n", "aabcaa\n", "abbcccbba\n", "aaaaaaaaaaa\n", "aaaaaaaaabbbbbaaaabaaaaaaaaaaaaaaaaabaaaaaabbbbbbbaaabbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "abc\n", "a\n", "ab\n", "ba\n", "aaabbb\n" ]
[ "2\n", "1\n", "1\n", "0\n", "12\n", "1\n", "0\n", "1\n", "1\n", "3\n" ]
1
stdio
After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i,  j,  k) (i < j < k), such that a_{i}·a_{j}·a_{k} is minimum possible, are there in the array? Help him with it! -----Input----- The first line of input contains a positive integer number n (3 ≤ n ≤ 10^5) — the number of elements in array a. The second line contains n positive integer numbers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of a given array. -----Output----- Print one number — the quantity of triples (i,  j,  k) such that i,  j and k are pairwise distinct and a_{i}·a_{j}·a_{k} is minimum possible. -----Examples----- Input 4 1 1 1 1 Output 4 Input 5 1 3 2 3 4 Output 2 Input 6 1 3 3 1 3 2 Output 1 -----Note----- In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4. In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2. In the third example a triple of numbers (1, 1, 2) is chosen, and there's only one way to choose indices.
[ "4\n1 1 1 1\n", "5\n1 3 2 3 4\n", "6\n1 3 3 1 3 2\n", "3\n1000000000 1000000000 1000000000\n", "4\n1 1 2 2\n", "3\n1 3 1\n", "11\n1 2 2 2 2 2 2 2 2 2 2\n", "5\n1 2 2 2 2\n", "6\n1 2 2 3 3 4\n", "8\n1 1 2 2 2 3 3 3\n" ]
[ "4\n", "2\n", "1\n", "1\n", "2\n", "1\n", "45\n", "6\n", "1\n", "3\n" ]
1
stdio
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro. She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over. Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator. As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? -----Input----- A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. -----Output----- A single integer — the number of straight cuts Shiro needs. -----Examples----- Input 3 Output 2 Input 4 Output 5 -----Note----- To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
[ "3\n", "4\n", "10\n", "10000000000\n", "1234567891\n", "7509213957\n", "99999999999999999\n", "21\n", "712394453192\n", "172212168\n" ]
[ "2", "5", "11", "10000000001", "617283946", "3754606979", "50000000000000000", "11", "712394453193", "172212169" ]
1
stdio
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. -----Input----- The single line contains integer n (10 ≤ |n| ≤ 10^9) — the state of Ilya's bank account. -----Output----- In a single line print an integer — the maximum state of the bank account that Ilya can get. -----Examples----- Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 -----Note----- In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
[ "2230\n", "-10\n", "-100003\n", "544883178\n", "-847251738\n", "423654797\n", "-623563697\n", "645894116\n", "-384381709\n", "437587210\n" ]
[ "2230\n", "0\n", "-10000\n", "544883178\n", "-84725173\n", "423654797\n", "-62356367\n", "645894116\n", "-38438170\n", "437587210\n" ]
1
stdio
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. -----Input----- The single line contains two integers a and k (1 ≤ a ≤ 10^18; 0 ≤ k ≤ 100). -----Output----- Print the maximum number that Pasha can get if he makes at most k swaps. -----Examples----- Input 1990 1 Output 9190 Input 300 0 Output 300 Input 1034 2 Output 3104 Input 9090000078001234 6 Output 9907000008001234
[ "1990 1\n", "300 0\n", "1034 2\n", "9090000078001234 6\n", "1234 3\n", "5 100\n", "1234 5\n", "1234 6\n", "9022 2\n", "66838 4\n" ]
[ "9190\n", "300\n", "3104\n", "9907000008001234\n", "4123\n", "5\n", "4312\n", "4321\n", "9220\n", "86863\n" ]
1
stdio