{"nl": {"description": "During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i\u2009+\u20091)-th position, then at time x\u2009+\u20091 the i-th position will have a girl and the (i\u2009+\u20091)-th position will have a boy. The time is given in seconds.You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.", "input_spec": "The first line contains two integers n and t (1\u2009\u2264\u2009n,\u2009t\u2009\u2264\u200950), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals \"B\", otherwise the i-th character equals \"G\".", "output_spec": "Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal \"B\", otherwise it must equal \"G\".", "sample_inputs": ["5 1\nBGGBG", "5 2\nBGGBG", "4 1\nGGGB"], "sample_outputs": ["GBGGB", "GGBGB", "GGGB"], "notes": null}, "src_uid": "964ed316c6e6715120039b0219cc653a"} {"nl": {"description": "From beginning till end, this message has been waiting to be conveyed.For a given unordered multiset of n lowercase English letters (\"multi\" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n\u2009-\u20091 times: Remove any two elements s and t from the set, and add their concatenation s\u2009+\u2009t to the set. The cost of such operation is defined to be , where f(s,\u2009c) denotes the number of times character c appears in string s.Given a non-negative integer k, construct any valid non-empty set of no more than 100\u2009000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.", "input_spec": "The first and only line of input contains a non-negative integer k (0\u2009\u2264\u2009k\u2009\u2264\u2009100\u2009000) \u2014 the required minimum cost.", "output_spec": "Output a non-empty string of no more than 100\u2009000 lowercase English letters \u2014 any multiset satisfying the requirements, concatenated to be a string. Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.", "sample_inputs": ["12", "3"], "sample_outputs": ["abababab", "codeforces"], "notes": "NoteFor the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows: {\"ab\", \"a\", \"b\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 0; {\"aba\", \"b\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 1; {\"abab\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 1; {\"abab\", \"ab\", \"a\", \"b\"}, with a cost of 0; {\"abab\", \"aba\", \"b\"}, with a cost of 1; {\"abab\", \"abab\"}, with a cost of 1; {\"abababab\"}, with a cost of 8. The total cost is 12, and it can be proved to be the minimum cost of the process."}, "src_uid": "b991c064562704b6106a6ff2a297e64a"} {"nl": {"description": "The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A\u2009-\u2009B is minimum possible. Help the teacher and find the least possible value of A\u2009-\u2009B.", "input_spec": "The first line contains space-separated integers n and m (2\u2009\u2264\u2009n\u2009\u2264\u2009m\u2009\u2264\u200950). The second line contains m space-separated integers f1,\u2009f2,\u2009...,\u2009fm (4\u2009\u2264\u2009fi\u2009\u2264\u20091000) \u2014 the quantities of pieces in the puzzles sold in the shop.", "output_spec": "Print a single integer \u2014 the least possible difference the teacher can obtain.", "sample_inputs": ["4 6\n10 12 10 7 5 22"], "sample_outputs": ["5"], "notes": "NoteSample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5."}, "src_uid": "7830aabb0663e645d54004063746e47f"} {"nl": {"description": "Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1,\u2009a2,\u2009...,\u2009an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of the program gets number n and array a.loop integer variable i from 1 to n\u2009-\u20091\u00a0\u00a0\u00a0\u00a0loop integer variable j from i to n\u2009-\u20091\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (aj\u2009>\u2009aj\u2009+\u20091), then swap the values of elements aj and aj\u2009+\u20091But Valera could have made a mistake, because he hasn't yet fully learned the sorting algorithm. If Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program sort the array not in the non-decreasing order). If such example for the given value of n doesn't exist, print -1.", "input_spec": "You've got a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the size of the sorted array.", "output_spec": "Print n space-separated integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1. If there are several counter-examples, consisting of n numbers, you are allowed to print any of them.", "sample_inputs": ["1"], "sample_outputs": ["-1"], "notes": null}, "src_uid": "fe8a0332119bd182a0a5b7758716317e"} {"nl": {"description": "The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.Help the park administration count the number of ways to place the benches.", "input_spec": "The only line of the input contains one integer n (5\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of east to west paths and north to south paths.", "output_spec": "Output one integer \u2014 the number of ways to place the benches.", "sample_inputs": ["5"], "sample_outputs": ["120"], "notes": null}, "src_uid": "92db14325cd8aee06b502c12d2e3dd81"} {"nl": {"description": "The following problem is well-known: given integers n and m, calculate , where 2n\u2009=\u20092\u00b72\u00b7...\u00b72 (n factors), and denotes the remainder of division of x by y.You are asked to solve the \"reverse\" problem. Given integers n and m, calculate . ", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009108). The second line contains a single integer m (1\u2009\u2264\u2009m\u2009\u2264\u2009108).", "output_spec": "Output a single integer\u00a0\u2014 the value of .", "sample_inputs": ["4\n42", "1\n58", "98765432\n23456789"], "sample_outputs": ["10", "0", "23456789"], "notes": "NoteIn the first example, the remainder of division of 42 by 24\u2009=\u200916 is equal to 10.In the second example, 58 is divisible by 21\u2009=\u20092 without remainder, and the answer is 0."}, "src_uid": "c649052b549126e600691931b512022f"} {"nl": {"description": "Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:Find the sum modulo 1073741824 (230).", "input_spec": "The first line contains three space-separated integers a, b and c (1\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20092000).", "output_spec": "Print a single integer \u2014 the required sum modulo 1073741824 (230).", "sample_inputs": ["2 2 2", "4 4 4", "10 10 10"], "sample_outputs": ["20", "328", "11536"], "notes": "NoteFor the first example. d(1\u00b71\u00b71)\u2009=\u2009d(1)\u2009=\u20091; d(1\u00b71\u00b72)\u2009=\u2009d(2)\u2009=\u20092; d(1\u00b72\u00b71)\u2009=\u2009d(2)\u2009=\u20092; d(1\u00b72\u00b72)\u2009=\u2009d(4)\u2009=\u20093; d(2\u00b71\u00b71)\u2009=\u2009d(2)\u2009=\u20092; d(2\u00b71\u00b72)\u2009=\u2009d(4)\u2009=\u20093; d(2\u00b72\u00b71)\u2009=\u2009d(4)\u2009=\u20093; d(2\u00b72\u00b72)\u2009=\u2009d(8)\u2009=\u20094. So the result is 1\u2009+\u20092\u2009+\u20092\u2009+\u20093\u2009+\u20092\u2009+\u20093\u2009+\u20093\u2009+\u20094\u2009=\u200920."}, "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"} {"nl": {"description": "Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square k\u2009\u00d7\u2009k in size, divided into blocks 1\u2009\u00d7\u20091 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie k in size. Fangy also has a box with a square base 2n\u2009\u00d7\u20092n, divided into blocks 1\u2009\u00d7\u20091 in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4 respectively on the figure: To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end.", "input_spec": "The first line contains a single integer n (0\u2009\u2264\u2009n\u2009\u2264\u20091000).", "output_spec": "Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106\u2009+\u20093.", "sample_inputs": ["3"], "sample_outputs": ["9"], "notes": "NoteIf the box possesses the base of 23\u2009\u00d7\u200923 (as in the example), then the cookies will be put there in the following manner: "}, "src_uid": "1a335a9638523ca0315282a67e18eec7"} {"nl": {"description": "Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which a and b are two non-negative integers and x is a variable. We call a positive integer x for which a solution of our equation.Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers a and b determines how many answers the Modular Equation has.", "input_spec": "In the only line of the input two space-separated integers a and b (0\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109) are given.", "output_spec": "If there is an infinite number of answers to our equation, print \"infinity\" (without the quotes). Otherwise print the number of solutions of the Modular Equation .", "sample_inputs": ["21 5", "9435152 272", "10 10"], "sample_outputs": ["2", "282", "infinity"], "notes": "NoteIn the first sample the answers of the Modular Equation are 8 and 16 since "}, "src_uid": "6e0715f9239787e085b294139abb2475"} {"nl": {"description": " The number \"zero\" is called \"love\" (or \"l'oeuf\" to be precise, literally means \"egg\" in French), for example when denoting the zero score in a game of tennis. Aki is fond of numbers, especially those with trailing zeros. For example, the number $$$9200$$$ has two trailing zeros. Aki thinks the more trailing zero digits a number has, the prettier it is.However, Aki believes, that the number of trailing zeros of a number is not static, but depends on the base (radix) it is represented in. Thus, he considers a few scenarios with some numbers and bases. And now, since the numbers he used become quite bizarre, he asks you to help him to calculate the beauty of these numbers.Given two integers $$$n$$$ and $$$b$$$ (in decimal notation), your task is to calculate the number of trailing zero digits in the $$$b$$$-ary (in the base/radix of $$$b$$$) representation of $$$n\\,!$$$ (factorial of $$$n$$$). ", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$b$$$ ($$$1 \\le n \\le 10^{18}$$$, $$$2 \\le b \\le 10^{12}$$$).", "output_spec": "Print an only integer\u00a0\u2014 the number of trailing zero digits in the $$$b$$$-ary representation of $$$n!$$$", "sample_inputs": ["6 9", "38 11", "5 2", "5 10"], "sample_outputs": ["1", "3", "3", "1"], "notes": "NoteIn the first example, $$$6!_{(10)} = 720_{(10)} = 880_{(9)}$$$.In the third and fourth example, $$$5!_{(10)} = 120_{(10)} = 1111000_{(2)}$$$.The representation of the number $$$x$$$ in the $$$b$$$-ary base is $$$d_1, d_2, \\ldots, d_k$$$ if $$$x = d_1 b^{k - 1} + d_2 b^{k - 2} + \\ldots + d_k b^0$$$, where $$$d_i$$$ are integers and $$$0 \\le d_i \\le b - 1$$$. For example, the number $$$720$$$ from the first example is represented as $$$880_{(9)}$$$ since $$$720 = 8 \\cdot 9^2 + 8 \\cdot 9 + 0 \\cdot 1$$$.You can read more about bases here."}, "src_uid": "491748694c1a53771be69c212a5e0e25"} {"nl": {"description": "Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.We define a pair of integers (a,\u2009b) good, if GCD(a,\u2009b)\u2009=\u2009x and LCM(a,\u2009b)\u2009=\u2009y, where GCD(a,\u2009b) denotes the greatest common divisor of a and b, and LCM(a,\u2009b) denotes the least common multiple of a and b.You are given two integers x and y. You are to find the number of good pairs of integers (a,\u2009b) such that l\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009r. Note that pairs (a,\u2009b) and (b,\u2009a) are considered different if a\u2009\u2260\u2009b.", "input_spec": "The only line contains four integers l,\u2009r,\u2009x,\u2009y (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109, 1\u2009\u2264\u2009x\u2009\u2264\u2009y\u2009\u2264\u2009109).", "output_spec": "In the only line print the only integer\u00a0\u2014 the answer for the problem.", "sample_inputs": ["1 2 1 2", "1 12 1 12", "50 100 3 30"], "sample_outputs": ["2", "4", "0"], "notes": "NoteIn the first example there are two suitable good pairs of integers (a,\u2009b): (1,\u20092) and (2,\u20091).In the second example there are four suitable good pairs of integers (a,\u2009b): (1,\u200912), (12,\u20091), (3,\u20094) and (4,\u20093).In the third example there are good pairs of integers, for example, (3,\u200930), but none of them fits the condition l\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009r."}, "src_uid": "d37dde5841116352c9b37538631d0b15"} {"nl": {"description": "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_spec": "The only line contains one integer\u00a0\u2014 $$$b$$$ $$$(1 \\le b \\le 10^{10})$$$.", "output_spec": "Print one number\u00a0\u2014 answer for the problem.", "sample_inputs": ["1", "2"], "sample_outputs": ["1", "2"], "notes": "NoteIn the first example $$$[a, \\,\\, 1] = a$$$, therefore $$$\\frac{[a, \\,\\, b]}{a}$$$ is always equal to $$$1$$$.In the second example $$$[a, \\,\\, 2]$$$ can be equal to $$$a$$$ or $$$2 \\cdot a$$$ depending on parity of $$$a$$$. $$$\\frac{[a, \\,\\, b]}{a}$$$ can be equal to $$$1$$$ and $$$2$$$."}, "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"} {"nl": {"description": "Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.", "input_spec": "The first and the single line of the input contains 6 space-separated integers a1,\u2009a2,\u2009a3,\u2009a4,\u2009a5 and a6 (1\u2009\u2264\u2009ai\u2009\u2264\u20091000) \u2014 the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.", "output_spec": "Print a single integer \u2014 the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.", "sample_inputs": ["1 1 1 1 1 1", "1 2 1 2 1 2"], "sample_outputs": ["6", "13"], "notes": "NoteThis is what Gerald's hexagon looks like in the first sample:And that's what it looks like in the second sample:"}, "src_uid": "382475475427f0e76c6b4ac6e7a02e21"} {"nl": {"description": "\"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score...\" \u2014 an excerpt from contest rules.A total of n participants took part in the contest (n\u2009\u2265\u2009k), and you already know their scores. Calculate how many participants will advance to the next round.", "input_spec": "The first line of the input contains two integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u200950) separated by a single space. The second line contains n space-separated integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u2009100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n\u2009-\u20091 the following condition is fulfilled: ai\u2009\u2265\u2009ai\u2009+\u20091).", "output_spec": "Output the number of participants who advance to the next round.", "sample_inputs": ["8 5\n10 9 8 7 7 7 5 5", "4 2\n0 0 0 0"], "sample_outputs": ["6", "0"], "notes": "NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score."}, "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"nl": {"description": "Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure. Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion: Map shows that the position of Captain Bill the Hummingbird is (x1,\u2009y1) and the position of the treasure is (x2,\u2009y2).You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output \"YES\", otherwise \"NO\" (without quotes).The potion can be used infinite amount of times.", "input_spec": "The first line contains four integer numbers x1,\u2009y1,\u2009x2,\u2009y2 (\u2009-\u2009105\u2009\u2264\u2009x1,\u2009y1,\u2009x2,\u2009y2\u2009\u2264\u2009105) \u2014 positions of Captain Bill the Hummingbird and treasure respectively. The second line contains two integer numbers x,\u2009y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009105) \u2014 values on the potion bottle.", "output_spec": "Print \"YES\" if it is possible for Captain to reach the treasure using the potion, otherwise print \"NO\" (without quotes).", "sample_inputs": ["0 0 0 6\n2 3", "1 1 3 6\n1 5"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example there exists such sequence of moves: \u2014 the first type of move \u2014 the third type of move "}, "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"nl": {"description": "A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105)\u00a0\u2014 the number of schools.", "output_spec": "Print single integer: the minimum cost of tickets needed to visit all schools.", "sample_inputs": ["2", "10"], "sample_outputs": ["0", "4"], "notes": "NoteIn the first example we can buy a ticket between the schools that costs ."}, "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"nl": {"description": "Arthur and Alexander are number busters. Today they've got a competition. Arthur took a group of four integers a,\u2009b,\u2009w,\u2009x (0\u2009\u2264\u2009b\u2009<\u2009w,\u20090\u2009<\u2009x\u2009<\u2009w) and Alexander took integer \u0441. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: c\u2009=\u2009c\u2009-\u20091. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if b\u2009\u2265\u2009x, perform the assignment b\u2009=\u2009b\u2009-\u2009x, if b\u2009<\u2009x, then perform two consecutive assignments a\u2009=\u2009a\u2009-\u20091;\u00a0b\u2009=\u2009w\u2009-\u2009(x\u2009-\u2009b).You've got numbers a,\u2009b,\u2009w,\u2009x,\u2009c. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if c\u2009\u2264\u2009a.", "input_spec": "The first line contains integers a,\u2009b,\u2009w,\u2009x,\u2009c (1\u2009\u2264\u2009a\u2009\u2264\u20092\u00b7109,\u20091\u2009\u2264\u2009w\u2009\u2264\u20091000,\u20090\u2009\u2264\u2009b\u2009<\u2009w,\u20090\u2009<\u2009x\u2009<\u2009w,\u20091\u2009\u2264\u2009c\u2009\u2264\u20092\u00b7109).", "output_spec": "Print a single integer \u2014 the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits.", "sample_inputs": ["4 2 3 1 6", "4 2 3 1 7", "1 2 3 2 6", "1 1 2 1 1"], "sample_outputs": ["2", "4", "13", "0"], "notes": null}, "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143"} {"nl": {"description": "You are given an array of positive integers a1,\u2009a2,\u2009...,\u2009an\u2009\u00d7\u2009T of length n\u2009\u00d7\u2009T. We know that for any i\u2009>\u2009n it is true that ai\u2009=\u2009ai\u2009-\u2009n. Find the length of the longest non-decreasing sequence of the given array.", "input_spec": "The first line contains two space-separated integers: n, T (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 1\u2009\u2264\u2009T\u2009\u2264\u2009107). The second line contains n space-separated integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009300).", "output_spec": "Print a single number \u2014 the length of a sought sequence.", "sample_inputs": ["4 3\n3 1 4 2"], "sample_outputs": ["5"], "notes": "NoteThe array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence. "}, "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2"} {"nl": {"description": "Tattah's youngest brother, Tuftuf, is new to programming.Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1,\u2009a2,\u2009... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai\u2009-\u20091 inclusive. Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x\u00b7x does not fit in some other type j (in aj bits) where ai\u2009<\u2009aj, then Tuftuf will stop using Gava.Your task is to determine Tuftuf's destiny.", "input_spec": "The first line contains integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1\u2009\u2264\u2009ai\u2009\u2264\u2009109) \u2014 sizes of datatypes in bits. Some datatypes may have equal sizes.", "output_spec": "Print \"YES\" if Tuftuf will stop using Gava, and \"NO\" otherwise.", "sample_inputs": ["3\n64 16 32", "4\n4 2 1 3"], "sample_outputs": ["NO", "YES"], "notes": "NoteIn the second example, x\u2009=\u20097 (1112) fits in 3 bits, but x2\u2009=\u200949 (1100012) does not fit in 4 bits."}, "src_uid": "ab003ab094931fc105384df9d144131e"} {"nl": {"description": "Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: 1+2*3=7 1*(2+3)=5 1*2*3=6 (1+2)*3=9 Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.It's easy to see that the maximum value that you can obtain is 9.Your task is: given a, b and c print the maximum value that you can get.", "input_spec": "The input contains three integers a, b and c, each on a single line (1\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u200910).", "output_spec": "Print the maximum value of the expression that you can obtain.", "sample_inputs": ["1\n2\n3", "2\n10\n3"], "sample_outputs": ["9", "60"], "notes": null}, "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"nl": {"description": "There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is \"R\", \"G\", or \"B\", the color of the corresponding stone is red, green, or blue, respectively.Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.Each instruction is one of the three types: \"RED\", \"GREEN\", or \"BLUE\". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.", "input_spec": "The input contains two lines. The first line contains the string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200950). The second line contains the string t (1\u2009\u2264\u2009|t|\u2009\u2264\u200950). The characters of each string will be one of \"R\", \"G\", or \"B\". It is guaranteed that Liss don't move out of the sequence.", "output_spec": "Print the final 1-based position of Liss in a single line.", "sample_inputs": ["RGB\nRRR", "RRRBGBRBBB\nBBBRR", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB"], "sample_outputs": ["2", "3", "15"], "notes": null}, "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"} {"nl": {"description": "Polycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: $$$1$$$, $$$4$$$, $$$8$$$, $$$9$$$, ....For a given number $$$n$$$, count the number of integers from $$$1$$$ to $$$n$$$ that Polycarp likes. In other words, find the number of such $$$x$$$ that $$$x$$$ is a square of a positive integer number or a cube of a positive integer number (or both a square and a cube simultaneously).", "input_spec": "The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 20$$$) \u2014 the number of test cases. Then $$$t$$$ lines contain the test cases, one per line. Each of the lines contains one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).", "output_spec": "For each test case, print the answer you are looking for \u2014 the number of integers from $$$1$$$ to $$$n$$$ that Polycarp likes.", "sample_inputs": ["6\n10\n1\n25\n1000000000\n999999999\n500000000"], "sample_outputs": ["4\n1\n6\n32591\n32590\n23125"], "notes": null}, "src_uid": "015afbefe1514a0e18fcb9286c7b6624"} {"nl": {"description": "You are given a rectangular cake, represented as an r\u2009\u00d7\u2009c grid. Each cell either has an evil strawberry, or is empty. For example, a 3\u2009\u00d7\u20094 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.Please output the maximum number of cake cells that the cakeminator can eat.", "input_spec": "The first line contains two integers r and c (2\u2009\u2264\u2009r,\u2009c\u2009\u2264\u200910), denoting the number of rows and the number of columns of the cake. The next r lines each contains c characters \u2014 the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these: '.' character denotes a cake cell with no evil strawberry; 'S' character denotes a cake cell with an evil strawberry. ", "output_spec": "Output the maximum number of cake cells that the cakeminator can eat.", "sample_inputs": ["3 4\nS...\n....\n..S."], "sample_outputs": ["8"], "notes": "NoteFor the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). "}, "src_uid": "ebaf7d89c623d006a6f1ffd025892102"} {"nl": {"description": "Paul is at the orchestra. The string section is arranged in an r\u2009\u00d7\u2009c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.Two pictures are considered to be different if the coordinates of corresponding rectangles are different.", "input_spec": "The first line of input contains four space-separated integers r, c, n, k (1\u2009\u2264\u2009r,\u2009c,\u2009n\u2009\u2264\u20093000, 1\u2009\u2264\u2009k\u2009\u2264\u2009min(n,\u200910))\u00a0\u2014 the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively. The next n lines each contain two integers xi and yi (1\u2009\u2264\u2009xi\u2009\u2264\u2009r, 1\u2009\u2264\u2009yi\u2009\u2264\u2009c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.", "output_spec": "Print a single integer\u00a0\u2014 the number of photographs Paul can take which include at least k violas. ", "sample_inputs": ["2 2 1 1\n1 2", "3 2 3 3\n1 1\n3 1\n2 2", "3 2 3 2\n1 1\n3 1\n2 2"], "sample_outputs": ["4", "1", "4"], "notes": "NoteWe will use '*' to denote violinists and '#' to denote violists.In the first sample, the orchestra looks as follows: *#** Paul can take a photograph of just the viola, the 1\u2009\u00d7\u20092 column containing the viola, the 2\u2009\u00d7\u20091 row containing the viola, or the entire string section, for 4 pictures total.In the second sample, the orchestra looks as follows: #**##* Paul must take a photograph of the entire section.In the third sample, the orchestra looks the same as in the second sample."}, "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"} {"nl": {"description": "Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.", "input_spec": "The first input line contains a non-empty string consisting of characters \"0\" and \"1\", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.", "output_spec": "Print \"YES\" if the situation is dangerous. Otherwise, print \"NO\".", "sample_inputs": ["001001", "1000000001"], "sample_outputs": ["NO", "YES"], "notes": null}, "src_uid": "ed9a763362abc6ed40356731f1036b38"} {"nl": {"description": "To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.The parking lot before the office consists of one line of (2n\u2009-\u20092) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever.Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly n successive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.", "input_spec": "The only line of the input contains one integer n (3\u2009\u2264\u2009n\u2009\u2264\u200930) \u2014 the amount of successive cars of the same make.", "output_spec": "Output one integer \u2014 the number of ways to fill the parking lot by cars of four makes using the described way.", "sample_inputs": ["3"], "sample_outputs": ["24"], "notes": "NoteLet's denote car makes in the following way: A \u2014 Aston Martin, B \u2014 Bentley, M \u2014 Mercedes-Maybach, Z \u2014 Zaporozhets. For n\u2009=\u20093 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMMOriginally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City."}, "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9"} {"nl": {"description": "On her way to programming school tiger Dasha faced her first test \u2014 a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values \u2014 the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the l-th to the r-th (1\u2009\u2264\u2009l\u2009\u2264\u2009r), for which values that Dasha has found are correct.", "input_spec": "In the only line you are given two integers a, b (0\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009100) \u2014 the number of even and odd steps, accordingly.", "output_spec": "In the only line print \"YES\", if the interval of steps described above exists, and \"NO\" otherwise.", "sample_inputs": ["2 3", "3 1"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example one of suitable intervals is from 1 to 5. The interval contains two even steps\u00a0\u2014 2 and 4, and three odd: 1, 3 and 5."}, "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"nl": {"description": "The only difference between easy and hard versions is constraints.A session has begun at Beland State University. Many students are taking exams.Polygraph Poligrafovich is going to examine a group of $$$n$$$ students. Students will take the exam one-by-one in order from $$$1$$$-th to $$$n$$$-th. Rules of the exam are following: The $$$i$$$-th student randomly chooses a ticket. if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. if the student finds the ticket easy, he spends exactly $$$t_i$$$ minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.The duration of the whole exam for all students is $$$M$$$ minutes ($$$\\max t_i \\le M$$$), so students at the end of the list have a greater possibility to run out of time to pass the exam.For each student $$$i$$$, you should count the minimum possible number of students who need to fail the exam so the $$$i$$$-th student has enough time to pass the exam.For each student $$$i$$$, find the answer independently. That is, if when finding the answer for the student $$$i_1$$$ some student $$$j$$$ should leave, then while finding the answer for $$$i_2$$$ ($$$i_2>i_1$$$) the student $$$j$$$ student does not have to go home.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$M$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le M \\le 100$$$)\u00a0\u2014 the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains $$$n$$$ integers $$$t_i$$$ ($$$1 \\le t_i \\le 100$$$)\u00a0\u2014 time in minutes that $$$i$$$-th student spends to answer to a ticket. It's guaranteed that all values of $$$t_i$$$ are not greater than $$$M$$$.", "output_spec": "Print $$$n$$$ numbers: the $$$i$$$-th number must be equal to the minimum number of students who have to leave the exam in order to $$$i$$$-th student has enough time to pass the exam.", "sample_inputs": ["7 15\n1 2 3 4 5 6 7", "5 100\n80 40 40 40 60"], "sample_outputs": ["0 0 0 0 0 2 3", "0 1 1 2 3"], "notes": "NoteThe explanation for the example 1.Please note that the sum of the first five exam times does not exceed $$$M=15$$$ (the sum is $$$1+2+3+4+5=15$$$). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are $$$0$$$.In order for the $$$6$$$-th student to pass the exam, it is necessary that at least $$$2$$$ students must fail it before (for example, the $$$3$$$-rd and $$$4$$$-th, then the $$$6$$$-th will finish its exam in $$$1+2+5+6=14$$$ minutes, which does not exceed $$$M$$$).In order for the $$$7$$$-th student to pass the exam, it is necessary that at least $$$3$$$ students must fail it before (for example, the $$$2$$$-nd, $$$5$$$-th and $$$6$$$-th, then the $$$7$$$-th will finish its exam in $$$1+3+4+7=15$$$ minutes, which does not exceed $$$M$$$)."}, "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"} {"nl": {"description": "You are given three sticks with positive integer lengths of a,\u2009b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most l centimeters. In particular, it is allowed not to increase the length of any stick.Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them.", "input_spec": "The single line contains 4 integers a,\u2009b,\u2009c,\u2009l (1\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20093\u00b7105, 0\u2009\u2264\u2009l\u2009\u2264\u20093\u00b7105).", "output_spec": "Print a single integer \u2014 the number of ways to increase the sizes of the sticks by the total of at most l centimeters, so that you can make a non-degenerate triangle from it.", "sample_inputs": ["1 1 1 2", "1 2 3 1", "10 2 1 7"], "sample_outputs": ["4", "2", "0"], "notes": "NoteIn the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter.In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions."}, "src_uid": "185ff90a8b0ae0e2b75605f772589410"} {"nl": {"description": "Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k.In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k\u2009=\u20093, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103\u2009=\u20091000.Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit).It is guaranteed that the answer exists.", "input_spec": "The only line of the input contains two integer numbers n and k (0\u2009\u2264\u2009n\u2009\u2264\u20092\u2009000\u2009000\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u20099). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros.", "output_spec": "Print w \u2014 the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0).", "sample_inputs": ["30020 3", "100 9", "10203049 2"], "sample_outputs": ["1", "2", "3"], "notes": "NoteIn the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number."}, "src_uid": "7a8890417aa48c2b93b559ca118853f9"} {"nl": {"description": "A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?", "input_spec": "The input contains two integers a and b (0\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009103), separated by a single space.", "output_spec": "Output the sum of the given integers.", "sample_inputs": ["5 14", "381 492"], "sample_outputs": ["19", "873"], "notes": null}, "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add"} {"nl": {"description": "Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.Some of them celebrated in the BugDonalds restaurant, some of them\u00a0\u2014 in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $$$A$$$ students, BeaverKing\u00a0\u2014 by $$$B$$$ students and $$$C$$$ students visited both restaurants. Vasya also knows that there are $$$N$$$ students in his group.Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?", "input_spec": "The first line contains four integers\u00a0\u2014 $$$A$$$, $$$B$$$, $$$C$$$ and $$$N$$$ ($$$0 \\leq A, B, C, N \\leq 100$$$).", "output_spec": "If a distribution of $$$N$$$ students exists in which $$$A$$$ students visited BugDonalds, $$$B$$$ \u2014 BeaverKing, $$$C$$$ \u2014 both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer\u00a0\u2014 amount of students (including Vasya) who did not pass the exam. If such a distribution does not exist and Vasya made a mistake while determining the numbers $$$A$$$, $$$B$$$, $$$C$$$ or $$$N$$$ (as in samples 2 and 3), output $$$-1$$$.", "sample_inputs": ["10 10 5 20", "2 2 0 4", "2 2 2 1"], "sample_outputs": ["5", "-1", "-1"], "notes": "NoteThe first sample describes following situation: $$$5$$$ only visited BugDonalds, $$$5$$$ students only visited BeaverKing, $$$5$$$ visited both of them and $$$5$$$ students (including Vasya) didn't pass the exam.In the second sample $$$2$$$ students only visited BugDonalds and $$$2$$$ only visited BeaverKing, but that means all $$$4$$$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.The third sample describes a situation where $$$2$$$ students visited BugDonalds but the group has only $$$1$$$ which makes it clearly impossible."}, "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"} {"nl": {"description": "Alice has a lovely piece of cloth. It has the shape of a square with a side of length $$$a$$$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $$$b$$$ centimeters (where $$$b < a$$$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?", "input_spec": "The first line contains a number $$$t$$$\u00a0($$$1 \\leq t \\leq 5$$$)\u00a0\u2014 the number of test cases. Each of the next $$$t$$$ lines describes the $$$i$$$-th test case. It contains two integers $$$a$$$ and $$$b~(1 \\leq b < a \\leq 10^{11})$$$\u00a0\u2014 the side length of Alice's square and the side length of the square that Bob wants.", "output_spec": "Print $$$t$$$ lines, where the $$$i$$$-th line is the answer to the $$$i$$$-th test case. Print \"YES\" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print \"NO\". You can print each letter in an arbitrary case (upper or lower).", "sample_inputs": ["4\n6 5\n16 13\n61690850361 24777622630\n34 33"], "sample_outputs": ["YES\nNO\nNO\nYES"], "notes": "NoteThe figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $$$6^2 - 5^2 = 36 - 25 = 11$$$, which is prime, so the answer is \"YES\". In the second case, the area is $$$16^2 - 13^2 = 87$$$, which is divisible by $$$3$$$. In the third case, the area of the remaining piece is $$$61690850361^2 - 24777622630^2 = 3191830435068605713421$$$. This number is not prime because $$$3191830435068605713421 = 36913227731 \\cdot 86468472991 $$$.In the last case, the area is $$$34^2 - 33^2 = 67$$$."}, "src_uid": "5a052e4e6c64333d94c83df890b1183c"} {"nl": {"description": "You have two integers $$$l$$$ and $$$r$$$. Find an integer $$$x$$$ which satisfies the conditions below: $$$l \\le x \\le r$$$. All digits of $$$x$$$ are different. If there are multiple answers, print any of them.", "input_spec": "The first line contains two integers $$$l$$$ and $$$r$$$ ($$$1 \\le l \\le r \\le 10^{5}$$$).", "output_spec": "If an answer exists, print any of them. Otherwise, print $$$-1$$$.", "sample_inputs": ["121 130", "98766 100000"], "sample_outputs": ["123", "-1"], "notes": "NoteIn the first example, $$$123$$$ is one of the possible answers. However, $$$121$$$ can't be the answer, because there are multiple $$$1$$$s on different digits.In the second example, there is no valid answer."}, "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"} {"nl": {"description": "Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9\u2009-\u2009t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.", "input_spec": "The first line contains a single integer x (1\u2009\u2264\u2009x\u2009\u2264\u20091018) \u2014 the number that Luke Skywalker gave to Chewbacca.", "output_spec": "Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.", "sample_inputs": ["27", "4545"], "sample_outputs": ["22", "4444"], "notes": null}, "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"} {"nl": {"description": "The gym leaders were fascinated by the evolutions which took place at Felicity camp. So, they were curious to know about the secret behind evolving Pokemon. The organizers of the camp gave the gym leaders a PokeBlock, a sequence of n ingredients. Each ingredient can be of type 0 or 1. Now the organizers told the gym leaders that to evolve a Pokemon of type k (k\u2009\u2265\u20092), they need to make a valid set of k cuts on the PokeBlock to get smaller blocks.Suppose the given PokeBlock sequence is b0b1b2... bn\u2009-\u20091. You have a choice of making cuts at n\u2009+\u20091 places, i.e., Before b0, between b0 and b1, between b1 and b2, ..., between bn\u2009-\u20092 and bn\u2009-\u20091, and after bn\u2009-\u20091.The n\u2009+\u20091 choices of making cuts are as follows (where a | denotes a possible cut):| b0 | b1 | b2 | ... | bn\u2009-\u20092 | bn\u2009-\u20091 |Consider a sequence of k cuts. Now each pair of consecutive cuts will contain a binary string between them, formed from the ingredient types. The ingredients before the first cut and after the last cut are wasted, which is to say they are not considered. So there will be exactly k\u2009-\u20091 such binary substrings. Every substring can be read as a binary number. Let m be the maximum number out of the obtained numbers. If all the obtained numbers are positive and the set of the obtained numbers contains all integers from 1 to m, then this set of cuts is said to be a valid set of cuts.For example, suppose the given PokeBlock sequence is 101101001110 and we made 5 cuts in the following way:10 | 11 | 010 | 01 | 1 | 10So the 4 binary substrings obtained are: 11, 010, 01 and 1, which correspond to the numbers 3, 2, 1 and 1 respectively. Here m\u2009=\u20093, as it is the maximum value among the obtained numbers. And all the obtained numbers are positive and we have obtained all integers from 1 to m. Hence this set of cuts is a valid set of 5 cuts.A Pokemon of type k will evolve only if the PokeBlock is cut using a valid set of k cuts. There can be many valid sets of the same size. Two valid sets of k cuts are considered different if there is a cut in one set which is not there in the other set.Let f(k) denote the number of valid sets of k cuts. Find the value of . Since the value of s can be very large, output s modulo 109\u2009+\u20097.", "input_spec": "The input consists of two lines. The first line consists an integer n (1\u2009\u2264\u2009n\u2009\u2264\u200975)\u00a0\u2014 the length of the PokeBlock. The next line contains the PokeBlock, a binary string of length n.", "output_spec": "Output a single integer, containing the answer to the problem, i.e., the value of s modulo 109\u2009+\u20097.", "sample_inputs": ["4\n1011", "2\n10"], "sample_outputs": ["10", "1"], "notes": "NoteIn the first sample, the sets of valid cuts are:Size 2: |1|011, 1|01|1, 10|1|1, 101|1|.Size 3: |1|01|1, |10|1|1, 10|1|1|, 1|01|1|.Size 4: |10|1|1|, |1|01|1|.Hence, f(2)\u2009=\u20094, f(3)\u2009=\u20094 and f(4)\u2009=\u20092. So, the value of s\u2009=\u200910.In the second sample, the set of valid cuts is:Size 2: |1|0.Hence, f(2)\u2009=\u20091 and f(3)\u2009=\u20090. So, the value of s\u2009=\u20091."}, "src_uid": "61f88159762cbc7c51c36e7b56ecde48"} {"nl": {"description": "User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this: << p\u2009-\u2009k p\u2009-\u2009k\u2009+\u20091 ... p\u2009-\u20091 (p) p\u2009+\u20091 ... p\u2009+\u2009k\u2009-\u20091 p\u2009+\u2009k >> When someone clicks the button \"<<\" he is redirected to page 1, and when someone clicks the button \">>\" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.There are some conditions in the navigation: If page 1 is in the navigation, the button \"<<\" must not be printed. If page n is in the navigation, the button \">>\" must not be printed. If the page number is smaller than 1 or greater than n, it must not be printed. \u00a0You can see some examples of the navigations. Make a program that prints the navigation.", "input_spec": "The first and the only line contains three integers n, p, k (3\u2009\u2264\u2009n\u2009\u2264\u2009100; 1\u2009\u2264\u2009p\u2009\u2264\u2009n; 1\u2009\u2264\u2009k\u2009\u2264\u2009n)", "output_spec": "Print the proper navigation. Follow the format of the output from the test samples.", "sample_inputs": ["17 5 2", "6 5 2", "6 1 2", "6 2 2", "9 6 3", "10 6 3", "8 5 4"], "sample_outputs": ["<< 3 4 (5) 6 7 >>", "<< 3 4 (5) 6", "(1) 2 3 >>", "1 (2) 3 4 >>", "<< 3 4 5 (6) 7 8 9", "<< 3 4 5 (6) 7 8 9 >>", "1 2 3 4 (5) 6 7 8"], "notes": null}, "src_uid": "526e2cce272e42a3220e33149b1c9c84"} {"nl": {"description": "Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l \u2014 left, s \u2014 straight, r \u2014 right) and a light p for a pedestrian crossing. An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.", "input_spec": "The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers l, s, r, p \u2014 for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.", "output_spec": "On a single line, print \"YES\" if an accident is possible, and \"NO\" otherwise.", "sample_inputs": ["1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0"], "sample_outputs": ["YES", "NO", "NO"], "notes": "NoteIn the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur."}, "src_uid": "44fdf71d56bef949ec83f00d17c29127"} {"nl": {"description": "During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green\u00a0\u2014 one yellow and one blue, and for a blue ball, three blue crystals are enough.Right now there are A yellow and B blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.", "input_spec": "The first line features two integers A and B (0\u2009\u2264\u2009A,\u2009B\u2009\u2264\u2009109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers x, y and z (0\u2009\u2264\u2009x,\u2009y,\u2009z\u2009\u2264\u2009109)\u00a0\u2014 the respective amounts of yellow, green and blue balls to be obtained.", "output_spec": "Print a single integer\u00a0\u2014 the minimum number of crystals that Grisha should acquire in addition.", "sample_inputs": ["4 3\n2 1 1", "3 9\n1 1 3", "12345678 87654321\n43043751 1000000000 53798715"], "sample_outputs": ["2", "1", "2147483648"], "notes": "NoteIn the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue."}, "src_uid": "35202a4601a03d25e18dda1539c5beba"} {"nl": {"description": "We define $$$x \\bmod y$$$ as the remainder of division of $$$x$$$ by $$$y$$$ ($$$\\%$$$ operator in C++ or Java, mod operator in Pascal).Let's call an array of positive integers $$$[a_1, a_2, \\dots, a_k]$$$ stable if for every permutation $$$p$$$ of integers from $$$1$$$ to $$$k$$$, and for every non-negative integer $$$x$$$, the following condition is met: $$$ (((x \\bmod a_1) \\bmod a_2) \\dots \\bmod a_{k - 1}) \\bmod a_k = (((x \\bmod a_{p_1}) \\bmod a_{p_2}) \\dots \\bmod a_{p_{k - 1}}) \\bmod a_{p_k} $$$ That is, for each non-negative integer $$$x$$$, the value of $$$(((x \\bmod a_1) \\bmod a_2) \\dots \\bmod a_{k - 1}) \\bmod a_k$$$ does not change if we reorder the elements of the array $$$a$$$.For two given integers $$$n$$$ and $$$k$$$, calculate the number of stable arrays $$$[a_1, a_2, \\dots, a_k]$$$ such that $$$1 \\le a_1 < a_2 < \\dots < a_k \\le n$$$.", "input_spec": "The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 5 \\cdot 10^5$$$).", "output_spec": "Print one integer \u2014 the number of stable arrays $$$[a_1, a_2, \\dots, a_k]$$$ such that $$$1 \\le a_1 < a_2 < \\dots < a_k \\le n$$$. Since the answer may be large, print it modulo $$$998244353$$$.", "sample_inputs": ["7 3", "3 7", "1337 42", "1 1", "500000 1"], "sample_outputs": ["16", "0", "95147305", "1", "500000"], "notes": null}, "src_uid": "8e8eb64a047cb970a549ee870c3d280d"} {"nl": {"description": "Alice and Bob are playing a game with $$$n$$$ piles of stones. It is guaranteed that $$$n$$$ is an even number. The $$$i$$$-th pile has $$$a_i$$$ stones.Alice and Bob will play a game alternating turns with Alice going first.On a player's turn, they must choose exactly $$$\\frac{n}{2}$$$ nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than $$$\\frac{n}{2}$$$ nonempty piles).Given the starting configuration, determine who will win the game.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\leq n \\leq 50$$$)\u00a0\u2014 the number of piles. It is guaranteed that $$$n$$$ is an even number. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 50$$$)\u00a0\u2014 the number of stones in the piles.", "output_spec": "Print a single string \"Alice\" if Alice wins; otherwise, print \"Bob\" (without double quotes).", "sample_inputs": ["2\n8 8", "4\n3 1 4 1"], "sample_outputs": ["Bob", "Alice"], "notes": "NoteIn the first example, each player can only remove stones from one pile ($$$\\frac{2}{2}=1$$$). Alice loses, since Bob can copy whatever Alice does on the other pile, so Alice will run out of moves first.In the second example, Alice can remove $$$2$$$ stones from the first pile and $$$3$$$ stones from the third pile on her first move to guarantee a win."}, "src_uid": "4b9cf82967aa8441e9af3db3101161e9"} {"nl": {"description": "You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days?", "input_spec": "The only line containing one integer x (1\u2009\u2264\u2009x\u2009\u2264\u2009109).", "output_spec": "The only line containing one integer: the answer.", "sample_inputs": ["5", "8"], "sample_outputs": ["2", "1"], "notes": "NoteFor the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1."}, "src_uid": "03e4482d53a059134676f431be4c16d2"} {"nl": {"description": "There is a beautiful garden of stones in Innopolis.Its most beautiful place is the $$$n$$$ piles with stones numbered from $$$1$$$ to $$$n$$$.EJOI participants have visited this place twice. When they first visited it, the number of stones in piles was $$$x_1, x_2, \\ldots, x_n$$$, correspondingly. One of the participants wrote down this sequence in a notebook. They visited it again the following day, and the number of stones in piles was equal to $$$y_1, y_2, \\ldots, y_n$$$. One of the participants also wrote it down in a notebook.It is well known that every member of the EJOI jury during the night either sits in the room $$$108$$$ or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.Participants want to know whether their notes can be correct or they are sure to have made a mistake.", "input_spec": "The first line of the input file contains a single integer $$$n$$$, the number of piles with stones in the garden ($$$1 \\leq n \\leq 50$$$). The second line contains $$$n$$$ integers separated by spaces $$$x_1, x_2, \\ldots, x_n$$$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time ($$$0 \\leq x_i \\leq 1000$$$). The third line contains $$$n$$$ integers separated by spaces $$$y_1, y_2, \\ldots, y_n$$$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time ($$$0 \\leq y_i \\leq 1000$$$).", "output_spec": "If the records can be consistent output \"Yes\", otherwise output \"No\" (quotes for clarity).", "sample_inputs": ["5\n1 2 3 4 5\n2 1 4 3 5", "5\n1 1 1 1 1\n1 0 1 0 1", "3\n2 3 9\n1 7 9"], "sample_outputs": ["Yes", "Yes", "No"], "notes": "NoteIn the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.In the second example, the jury took stones from the second and fourth piles.It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array."}, "src_uid": "e0ddac5c6d3671070860dda10d50c28a"} {"nl": {"description": "The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits.", "input_spec": "The only line of input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u200955) \u2014 the maximum length of a number that a door-plate can hold.", "output_spec": "Output one integer \u2014 the maximum number of offices, than can have unique lucky numbers not longer than n digits.", "sample_inputs": ["2"], "sample_outputs": ["6"], "notes": null}, "src_uid": "f1b43baa14d4c262ba616d892525dfde"} {"nl": {"description": "Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.", "input_spec": "The first line contains two numbers n, k (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 0\u2009\u2264\u2009k\u2009\u2264\u200910\u2009000), the number of instruments and number of days respectively. The second line contains n integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009100), representing number of days required to learn the i-th instrument.", "output_spec": "In the first line output one integer m representing the maximum number of instruments Amr can learn. In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.", "sample_inputs": ["4 10\n4 3 1 2", "5 6\n4 3 1 1 2", "1 3\n4"], "sample_outputs": ["4\n1 2 3 4", "3\n1 3 4", "0"], "notes": "NoteIn the first test Amr can learn all 4 instruments.In the second test other possible solutions are: {2,\u20093,\u20095} or {3,\u20094,\u20095}.In the third test Amr doesn't have enough time to learn the only presented instrument."}, "src_uid": "dbb164a8dd190e63cceba95a31690a7c"} {"nl": {"description": "At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these.", "input_spec": "The first input line contains 6 space-separated integers x1,\u2009y1,\u2009x2,\u2009y2,\u2009x3,\u2009y3 \u2014 coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.", "output_spec": "If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER.", "sample_inputs": ["0 0 2 0 0 1", "2 3 4 5 6 6", "-1 0 2 0 0 1"], "sample_outputs": ["RIGHT", "NEITHER", "ALMOST"], "notes": null}, "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"} {"nl": {"description": "On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.There are $$$n$$$ bricks lined in a row on the ground. Chouti has got $$$m$$$ paint buckets of different colors at hand, so he painted each brick in one of those $$$m$$$ colors.Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are $$$k$$$ bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure).So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo $$$998\\,244\\,353$$$.", "input_spec": "The first and only line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \\leq n,m \\leq 2000, 0 \\leq k \\leq n-1$$$)\u00a0\u2014 the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it.", "output_spec": "Print one integer\u00a0\u2014 the number of ways to color bricks modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["3 3 0", "3 2 1"], "sample_outputs": ["3", "4"], "notes": "NoteIn the first example, since $$$k=0$$$, the color of every brick should be the same, so there will be exactly $$$m=3$$$ ways to color the bricks.In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all $$$4$$$ possible colorings. "}, "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b"} {"nl": {"description": "Awruk is taking part in elections in his school. It is the final round. He has only one opponent\u00a0\u2014 Elodreip. The are $$$n$$$ students in the school. Each student has exactly $$$k$$$ votes and is obligated to use all of them. So Awruk knows that if a person gives $$$a_i$$$ votes for Elodreip, than he will get exactly $$$k - a_i$$$ votes from this person. Of course $$$0 \\le k - a_i$$$ holds.Awruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows $$$a_1, a_2, \\dots, a_n$$$ \u2014 how many votes for Elodreip each student wants to give. Now he wants to change the number $$$k$$$ to win the elections. Of course he knows that bigger $$$k$$$ means bigger chance that somebody may notice that he has changed something and then he will be disqualified.So, Awruk knows $$$a_1, a_2, \\dots, a_n$$$ \u2014 how many votes each student will give to his opponent. Help him select the smallest winning number $$$k$$$. In order to win, Awruk needs to get strictly more votes than Elodreip.", "input_spec": "The first line contains integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of students in the school. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 100$$$)\u00a0\u2014 the number of votes each student gives to Elodreip.", "output_spec": "Output the smallest integer $$$k$$$ ($$$k \\ge \\max a_i$$$) which gives Awruk the victory. In order to win, Awruk needs to get strictly more votes than Elodreip.", "sample_inputs": ["5\n1 1 1 5 1", "5\n2 2 3 2 2"], "sample_outputs": ["5", "5"], "notes": "NoteIn the first example, Elodreip gets $$$1 + 1 + 1 + 5 + 1 = 9$$$ votes. The smallest possible $$$k$$$ is $$$5$$$ (it surely can't be less due to the fourth person), and it leads to $$$4 + 4 + 4 + 0 + 4 = 16$$$ votes for Awruk, which is enough to win.In the second example, Elodreip gets $$$11$$$ votes. If $$$k = 4$$$, Awruk gets $$$9$$$ votes and loses to Elodreip."}, "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"nl": {"description": "Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.Photo can be represented as a matrix sized n\u2009\u00d7\u2009m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: 'C' (cyan) 'M' (magenta) 'Y' (yellow) 'W' (white) 'G' (grey) 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.", "input_spec": "The first line of the input contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100)\u00a0\u2014 the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.", "output_spec": "Print the \"#Black&White\" (without quotes), if the photo is black-and-white and \"#Color\" (without quotes), if it is colored, in the only line.", "sample_inputs": ["2 2\nC M\nY Y", "3 2\nW W\nW W\nB B", "1 1\nW"], "sample_outputs": ["#Color", "#Black&White", "#Black&White"], "notes": null}, "src_uid": "19c311c02380f9a73cd477e4fde27454"} {"nl": {"description": "Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: if the last digit of the number is non-zero, she decreases the number by one; if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $$$n$$$. Tanya will subtract one from it $$$k$$$ times. Your task is to print the result after all $$$k$$$ subtractions.It is guaranteed that the result will be positive integer number.", "input_spec": "The first line of the input contains two integer numbers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 10^9$$$, $$$1 \\le k \\le 50$$$) \u2014 the number from which Tanya will subtract and the number of subtractions correspondingly.", "output_spec": "Print one integer number \u2014 the result of the decreasing $$$n$$$ by one $$$k$$$ times. It is guaranteed that the result will be positive integer number. ", "sample_inputs": ["512 4", "1000000000 9"], "sample_outputs": ["50", "1"], "notes": "NoteThe first example corresponds to the following sequence: $$$512 \\rightarrow 511 \\rightarrow 510 \\rightarrow 51 \\rightarrow 50$$$."}, "src_uid": "064162604284ce252b88050b4174ba55"} {"nl": {"description": "So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two \"New Year and Christmas Men\" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the \"New Year and Christmas Men\" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.", "input_spec": "The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.", "output_spec": "Print \"YES\" without the quotes, if the letters in the pile could be permuted to make the names of the \"New Year and Christmas Men\". Otherwise, print \"NO\" without the quotes.", "sample_inputs": ["SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER"], "sample_outputs": ["YES", "NO", "NO"], "notes": "NoteIn the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.In the second sample letter \"P\" is missing from the pile and there's an extra letter \"L\".In the third sample there's an extra letter \"L\"."}, "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"nl": {"description": "You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,\u20090,\u20090) and (1,\u20091,\u20091). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube.", "input_spec": "The first line contains three space-separated integers (0 or 1) \u2014 the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.", "output_spec": "Output \"YES\" (without quotes) if the flies see each other. Otherwise, output \"NO\".", "sample_inputs": ["0 0 0\n0 1 0", "1 1 0\n0 1 0", "0 0 0\n1 1 1"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"} {"nl": {"description": "Luba has to do n chores today. i-th chore takes ai units of time to complete. It is guaranteed that for every the condition ai\u2009\u2265\u2009ai\u2009-\u20091 is met, so the sequence is sorted.Also Luba can work really hard on some chores. She can choose not more than k any chores and do each of them in x units of time instead of ai ().Luba is very responsible, so she has to do all n chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously.", "input_spec": "The first line contains three integers n,\u2009k,\u2009x\u00a0(1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009x\u2009\u2264\u200999) \u2014 the number of chores Luba has to do, the number of chores she can do in x units of time, and the number x itself. The second line contains n integer numbers ai\u00a0(2\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the time Luba has to spend to do i-th chore. It is guaranteed that , and for each ai\u2009\u2265\u2009ai\u2009-\u20091.", "output_spec": "Print one number \u2014 minimum time Luba needs to do all n chores.", "sample_inputs": ["4 2 2\n3 6 7 10", "5 2 1\n100 100 100 100 100"], "sample_outputs": ["13", "302"], "notes": "NoteIn the first example the best option would be to do the third and the fourth chore, spending x\u2009=\u20092 time on each instead of a3 and a4, respectively. Then the answer is 3\u2009+\u20096\u2009+\u20092\u2009+\u20092\u2009=\u200913.In the second example Luba can choose any two chores to spend x time on them instead of ai. So the answer is 100\u00b73\u2009+\u20092\u00b71\u2009=\u2009302."}, "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"} {"nl": {"description": "There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the number of stones on the table. The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals \"R\", if the i-th stone is red, \"G\", if it's green and \"B\", if it's blue.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["3\nRRG", "5\nRRRRR", "4\nBRBG"], "sample_outputs": ["1", "4", "0"], "notes": null}, "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"nl": {"description": "The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.A path called normalized if it contains the smallest possible number of characters '/'.Your task is to transform a given path to the normalized form.", "input_spec": "The first line of the input contains only lowercase Latin letters and character '/'\u00a0\u2014 the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.", "output_spec": "The path in normalized form.", "sample_inputs": ["//usr///local//nginx/sbin"], "sample_outputs": ["/usr/local/nginx/sbin"], "notes": null}, "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"} {"nl": {"description": "Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled \"a\" to \"z\", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some \"special edition\" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?Please help Haruhi solve this problem.", "input_spec": "The first line of input will be a single string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200920). String s consists only of lowercase English letters. ", "output_spec": "Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.", "sample_inputs": ["a", "hi"], "sample_outputs": ["51", "76"], "notes": "NoteIn the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. "}, "src_uid": "556684d96d78264ad07c0cdd3b784bc9"} {"nl": {"description": "You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: the password length is at least 5 characters; the password contains at least one large English letter; the password contains at least one small English letter; the password contains at least one digit. You are given a password. Please implement the automatic check of its complexity for company Q.", "input_spec": "The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: \"!\", \"?\", \".\", \",\", \"_\".", "output_spec": "If the password is complex enough, print message \"Correct\" (without the quotes), otherwise print message \"Too weak\" (without the quotes).", "sample_inputs": ["abacaba", "X12345", "CONTEST_is_STARTED!!11"], "sample_outputs": ["Too weak", "Too weak", "Correct"], "notes": null}, "src_uid": "42a964b01e269491975965860ec92be7"} {"nl": {"description": "Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to \"All World Classical Singing Festival\". Other than Devu, comedian Churu was also invited.Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.You as one of the organizers should make an optimal s\u0441hedule for the event. For some reasons you must follow the conditions: The duration of the event must be no more than d minutes; Devu must complete all his songs; With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.", "input_spec": "The first line contains two space separated integers n, d (1\u2009\u2264\u2009n\u2009\u2264\u2009100;\u00a01\u2009\u2264\u2009d\u2009\u2264\u200910000). The second line contains n space-separated integers: t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u2009100).", "output_spec": "If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.", "sample_inputs": ["3 30\n2 2 1", "3 20\n2 1 1"], "sample_outputs": ["5", "-1"], "notes": "NoteConsider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: First Churu cracks a joke in 5 minutes. Then Devu performs the first song for 2 minutes. Then Churu cracks 2 jokes in 10 minutes. Now Devu performs second song for 2 minutes. Then Churu cracks 2 jokes in 10 minutes. Now finally Devu will perform his last song in 1 minutes. Total time spent is 5\u2009+\u20092\u2009+\u200910\u2009+\u20092\u2009+\u200910\u2009+\u20091\u2009=\u200930 minutes.Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. "}, "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"nl": {"description": "Amr bought a new video game \"Guess Your Way Out!\". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the leaf nodes from the left to the right from 1 to 2h. The exit is located at some node n where 1\u2009\u2264\u2009n\u2009\u2264\u20092h, the player doesn't know where the exit is so he has to guess his way out!Amr follows simple algorithm to choose the path. Let's consider infinite command string \"LRLRLRLRL...\" (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules: Character 'L' means \"go to the left child of the current node\"; Character 'R' means \"go to the right child of the current node\"; If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node; If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command; If he reached a leaf node that is not the exit, he returns to the parent of the current node; If he reaches an exit, the game is finished. Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?", "input_spec": "Input consists of two integers h,\u2009n (1\u2009\u2264\u2009h\u2009\u2264\u200950, 1\u2009\u2264\u2009n\u2009\u2264\u20092h).", "output_spec": "Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.", "sample_inputs": ["1 2", "2 3", "3 6", "10 1024"], "sample_outputs": ["2", "5", "10", "2046"], "notes": "NoteA perfect binary tree of height h is a binary tree consisting of h\u2009+\u20091 levels. Level 0 consists of a single node called root, level h consists of 2h nodes called leaves. Each node that is not a leaf has exactly two children, left and right one. Following picture illustrates the sample test number 3. Nodes are labeled according to the order of visit."}, "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781"} {"nl": {"description": "Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2\u2009\u00d7\u20092 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.", "input_spec": "The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1\u2009\u2264\u2009r1,\u2009r2,\u2009c1,\u2009c2,\u2009d1,\u2009d2\u2009\u2264\u200920). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. ", "output_spec": "Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number \"-1\" (without the quotes). If there are several solutions, output any.", "sample_inputs": ["3 7\n4 6\n5 5", "11 10\n13 8\n5 16", "1 2\n3 4\n5 6", "10 10\n10 10\n10 10"], "sample_outputs": ["1 2\n3 4", "4 7\n9 1", "-1", "-1"], "notes": "NotePay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number \"5\". However, Vasilisa only has one gem with each number from 1 to 9."}, "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"nl": {"description": "Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0,\u20090),\u2009(1,\u20090)], [(1,\u20090),\u2009(1,\u20091)], [(1,\u20091),\u2009(\u2009-\u20091,\u20091)], [(\u2009-\u20091,\u20091),\u2009(\u2009-\u20091,\u2009\u2009-\u20091)], [(\u2009-\u20091,\u2009\u2009-\u20091),\u2009(2,\u2009\u2009-\u20091)], [(2,\u2009\u2009-\u20091),\u2009(2,\u20092)] and so on. Thus, this infinite spiral passes through each integer point of the plane.Valera the horse lives on the plane at coordinates (0,\u20090). He wants to walk along the spiral to point (x,\u2009y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0,\u20090) to point (x,\u2009y).", "input_spec": "The first line contains two space-separated integers x and y (|x|,\u2009|y|\u2009\u2264\u2009100).", "output_spec": "Print a single integer, showing how many times Valera has to turn.", "sample_inputs": ["0 0", "1 0", "0 1", "-1 -1"], "sample_outputs": ["0", "0", "2", "3"], "notes": null}, "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"} {"nl": {"description": "Masha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on the floor $$$x$$$, Egor on the floor $$$y$$$ (not on the same floor with Masha).The house has a staircase and an elevator. If Masha uses the stairs, it takes $$$t_1$$$ seconds for her to walk between adjacent floors (in each direction). The elevator passes between adjacent floors (in each way) in $$$t_2$$$ seconds. The elevator moves with doors closed. The elevator spends $$$t_3$$$ seconds to open or close the doors. We can assume that time is not spent on any action except moving between adjacent floors and waiting for the doors to open or close. If Masha uses the elevator, it immediately goes directly to the desired floor.Coming out of the apartment on her floor, Masha noticed that the elevator is now on the floor $$$z$$$ and has closed doors. Now she has to choose whether to use the stairs or use the elevator. If the time that Masha needs to get to the Egor's floor by the stairs is strictly less than the time it will take her using the elevator, then she will use the stairs, otherwise she will choose the elevator.Help Mary to understand whether to use the elevator or the stairs.", "input_spec": "The only line contains six integers $$$x$$$, $$$y$$$, $$$z$$$, $$$t_1$$$, $$$t_2$$$, $$$t_3$$$ ($$$1 \\leq x, y, z, t_1, t_2, t_3 \\leq 1000$$$)\u00a0\u2014 the floor Masha is at, the floor Masha wants to get to, the floor the elevator is located on, the time it takes Masha to pass between two floors by stairs, the time it takes the elevator to pass between two floors and the time it takes for the elevator to close or open the doors. It is guaranteed that $$$x \\ne y$$$.", "output_spec": "If the time it will take to use the elevator is not greater than the time it will take to use the stairs, print \u00abYES\u00bb (without quotes), otherwise print \u00abNO> (without quotes). You can print each letter in any case (upper or lower).", "sample_inputs": ["5 1 4 4 2 1", "1 6 6 2 1 1", "4 1 7 4 1 2"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example:If Masha goes by the stairs, the time she spends is $$$4 \\cdot 4 = 16$$$, because she has to go $$$4$$$ times between adjacent floors and each time she spends $$$4$$$ seconds. If she chooses the elevator, she will have to wait $$$2$$$ seconds while the elevator leaves the $$$4$$$-th floor and goes to the $$$5$$$-th. After that the doors will be opening for another $$$1$$$ second. Then Masha will enter the elevator, and she will have to wait for $$$1$$$ second for the doors closing. Next, the elevator will spend $$$4 \\cdot 2 = 8$$$ seconds going from the $$$5$$$-th floor to the $$$1$$$-st, because the elevator has to pass $$$4$$$ times between adjacent floors and spends $$$2$$$ seconds each time. And finally, it will take another $$$1$$$ second before the doors are open and Masha can come out. Thus, all the way by elevator will take $$$2 + 1 + 1 + 8 + 1 = 13$$$ seconds, which is less than $$$16$$$ seconds, so Masha has to choose the elevator.In the second example, it is more profitable for Masha to use the stairs, because it will take $$$13$$$ seconds to use the elevator, that is more than the $$$10$$$ seconds it will takes to go by foot.In the third example, the time it takes to use the elevator is equal to the time it takes to walk up by the stairs, and is equal to $$$12$$$ seconds. That means Masha will take the elevator."}, "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"} {"nl": {"description": "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_spec": "The first line contains two space-separated integers a and b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109). ", "output_spec": "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.", "sample_inputs": ["15 20", "14 8", "6 6"], "sample_outputs": ["3", "-1", "0"], "notes": null}, "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"} {"nl": {"description": "To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.", "input_spec": "The first line contains four integers \u2014 n, a, b, c (1\u2009\u2264\u2009n\u2009\u2264\u200910000, 0\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20095000).", "output_spec": "Print the unique number \u2014 the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0. ", "sample_inputs": ["10 5 5 5", "3 0 0 2"], "sample_outputs": ["9", "0"], "notes": null}, "src_uid": "474e527d41040446a18186596e8bdd83"} {"nl": {"description": "One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm \u2009\u00d7\u2009 b mm sheet of paper (a\u2009>\u2009b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (a\u2009-\u2009b) mm \u2009\u00d7\u2009 b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.Can you determine how many ships Vasya will make during the lesson?", "input_spec": "The first line of the input contains two integers a, b (1\u2009\u2264\u2009b\u2009<\u2009a\u2009\u2264\u20091012) \u2014 the sizes of the original sheet of paper.", "output_spec": "Print a single integer \u2014 the number of ships that Vasya will make.", "sample_inputs": ["2 1", "10 7", "1000000000000 1"], "sample_outputs": ["2", "6", "1000000000000"], "notes": "NotePictures to the first and second sample test. "}, "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"} {"nl": {"description": "Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. ", "input_spec": "The first line contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 number of cards. It is guaranteed that n is an even number. The following n lines contain a sequence of integers a1,\u2009a2,\u2009...,\u2009an (one integer per line, 1\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 numbers written on the n cards.", "output_spec": "If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print \"NO\" (without quotes) in the first line. In this case you should not print anything more. In the other case print \"YES\" (without quotes) in the first line. In the second line print two distinct integers \u2014 number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.", "sample_inputs": ["4\n11\n27\n27\n11", "2\n6\n6", "6\n10\n20\n30\n20\n10\n20", "6\n1\n1\n2\n2\n3\n3"], "sample_outputs": ["YES\n11 27", "NO", "NO", "NO"], "notes": "NoteIn the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards \u2014 Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards \u2014 for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards."}, "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"nl": {"description": "Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.", "input_spec": "The input consists of a single line containing a positive integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of employees in Fafa's company.", "output_spec": "Print a single integer representing the answer to the problem.", "sample_inputs": ["2", "10"], "sample_outputs": ["1", "3"], "notes": "NoteIn the second sample Fafa has 3 ways: choose only 1 employee as a team leader with 9 employees under his responsibility. choose 2 employees as team leaders with 4 employees under the responsibility of each of them. choose 5 employees as team leaders with 1 employee under the responsibility of each of them. "}, "src_uid": "89f6c1659e5addbf909eddedb785d894"} {"nl": {"description": "Madoka decided to entrust the organization of a major computer game tournament \"OSU\"!In this tournament, matches are held according to the \"Olympic system\". In other words, there are $$$2^n$$$ participants in the tournament, numbered with integers from $$$1$$$ to $$$2^n$$$. There are $$$n$$$ rounds in total in the tournament. In the $$$i$$$-th round there are $$$2^{n - i}$$$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament\u00a0\u2014 is the last remaining participant.But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win\u00a0\u2014 the participant on the left or right.But Madoka knows that tournament sponsors can change the winner in matches no more than $$$k$$$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $$$1$$$ and $$$3$$$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $$$10^9 + 7$$$. Note that we need to minimize the answer, and only then take it modulo.", "input_spec": "The first and the only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 10^5, 1 \\le k \\le \\min(2^n - 1, 10^9)$$$)\u00a0\u2014 the number of rounds in the tournament and the number of outcomes that sponsors can change.", "output_spec": "Print exactly one integer\u00a0\u2014 the minimum number of the winner modulo $$$10^9 + 7$$$", "sample_inputs": ["1 1", "2 1", "3 2"], "sample_outputs": ["2", "3", "7"], "notes": "NoteIn the first example, there is only one match between players $$$1$$$ and $$$2$$$, so the sponsors can always make player $$$2$$$ wins.The tournament grid from the second example is shown in the picture in the statement."}, "src_uid": "dc7b887afcc2e95c4e90619ceda63071"} {"nl": {"description": "You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into $$$w\\times h$$$ cells. There should be $$$k$$$ gilded rings, the first one should go along the edge of the plate, the second one\u00a0\u2014 $$$2$$$ cells away from the edge and so on. Each ring has a width of $$$1$$$ cell. Formally, the $$$i$$$-th of these rings should consist of all bordering cells on the inner rectangle of size $$$(w - 4(i - 1))\\times(h - 4(i - 1))$$$. The picture corresponds to the third example. Your task is to compute the number of cells to be gilded.", "input_spec": "The only line contains three integers $$$w$$$, $$$h$$$ and $$$k$$$ ($$$3 \\le w, h \\le 100$$$, $$$1 \\le k \\le \\left\\lfloor \\frac{min(n, m) + 1}{4}\\right\\rfloor$$$, where $$$\\lfloor x \\rfloor$$$ denotes the number $$$x$$$ rounded down) \u2014 the number of rows, columns and the number of rings, respectively.", "output_spec": "Print a single positive integer\u00a0\u2014 the number of cells to be gilded.", "sample_inputs": ["3 3 1", "7 9 1", "7 9 2"], "sample_outputs": ["8", "28", "40"], "notes": "NoteThe first example is shown on the picture below. The second example is shown on the picture below. The third example is shown in the problem description."}, "src_uid": "2c98d59917337cb321d76f72a1b3c057"} {"nl": {"description": "The only king stands on the standard chess board. You are given his position in format \"cd\", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king.Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). King moves from the position e4 ", "input_spec": "The only line contains the king's position in the format \"cd\", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.", "output_spec": "Print the only integer x \u2014 the number of moves permitted for the king.", "sample_inputs": ["e4"], "sample_outputs": ["8"], "notes": null}, "src_uid": "6994331ca6282669cbb7138eb7e55e01"} {"nl": {"description": "Ralph has a magic field which is divided into n\u2009\u00d7\u2009m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007\u2009=\u2009109\u2009+\u20097.Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.", "input_spec": "The only line contains three integers n, m and k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091018, k is either 1 or -1).", "output_spec": "Print a single number denoting the answer modulo 1000000007.", "sample_inputs": ["1 1 -1", "1 3 1", "3 3 -1"], "sample_outputs": ["1", "1", "16"], "notes": "NoteIn the first example the only way is to put -1 into the only block.In the second example the only way is to put 1 into every block."}, "src_uid": "6b9eff690fae14725885cbc891ff7243"} {"nl": {"description": "Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.You know that there will be n interesting minutes t1,\u2009t2,\u2009...,\u2009tn. Your task is to calculate for how many minutes Limak will watch the game.", "input_spec": "The first line of the input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u200990)\u00a0\u2014 the number of interesting minutes. The second line contains n integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009t1\u2009<\u2009t2\u2009<\u2009... tn\u2009\u2264\u200990), given in the increasing order.", "output_spec": "Print the number of minutes Limak will watch the game.", "sample_inputs": ["3\n7 20 88", "9\n16 20 30 40 50 60 70 80 90", "9\n15 20 30 40 50 60 70 80 90"], "sample_outputs": ["35", "15", "90"], "notes": "NoteIn the first sample, minutes 21,\u200922,\u2009...,\u200935 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.In the second sample, the first 15 minutes are boring.In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game."}, "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"} {"nl": {"description": "Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.Consider the point (x,\u2009y) in the 2D plane such that x and y are integers and 0\u2009\u2264\u2009x,\u2009y. There is a tree in such a point, and it has x\u2009+\u2009y bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.Okabe is sure that the answer does not exceed 1018. You can trust him.", "input_spec": "The first line of input contains two space-separated integers m and b (1\u2009\u2264\u2009m\u2009\u2264\u20091000, 1\u2009\u2264\u2009b\u2009\u2264\u200910000).", "output_spec": "Print the maximum number of bananas Okabe can get from the trees he cuts.", "sample_inputs": ["1 5", "2 3"], "sample_outputs": ["30", "25"], "notes": "Note The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas."}, "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"} {"nl": {"description": "You will receive 3 points for solving this problem.Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string \"GTTAAAG\". It contains four maximal sequences of consecutive identical nucleotides: \"G\", \"TT\", \"AAA\", and \"G\". The protein is nonfunctional because sequence \"TT\" has even length.Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.", "input_spec": "The input consists of a single line, containing a string s of length n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). Each character of s will be from the set {'A', 'T', 'G', 'C'}. This problem doesn't have subproblems. You will get 3 points for the correct submission.", "output_spec": "The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.", "sample_inputs": ["GTTAAAG", "AACCAACCAAAAC"], "sample_outputs": ["1", "5"], "notes": "NoteIn the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein."}, "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f"} {"nl": {"description": "Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word \"abracadabra\" Hongcow will get words \"aabracadabr\", \"raabracadab\" and so on.Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.", "input_spec": "The first line of input will be a single string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200950), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'\u2013'z').", "output_spec": "Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.", "sample_inputs": ["abcd", "bbb", "yzyz"], "sample_outputs": ["4", "1", "2"], "notes": "NoteFor the first sample, the strings Hongcow can generate are \"abcd\", \"dabc\", \"cdab\", and \"bcda\".For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate \"bbb\".For the third sample, the two strings Hongcow can generate are \"yzyz\" and \"zyzy\"."}, "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"} {"nl": {"description": "Like any unknown mathematician, Yuri has favourite numbers: $$$A$$$, $$$B$$$, $$$C$$$, and $$$D$$$, where $$$A \\leq B \\leq C \\leq D$$$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $$$x$$$, $$$y$$$, and $$$z$$$ exist, such that $$$A \\leq x \\leq B \\leq y \\leq C \\leq z \\leq D$$$ holds?Yuri is preparing problems for a new contest now, so he is very busy. That's why he asked you to calculate the number of triangles with described property.The triangle is called non-degenerate if and only if its vertices are not collinear.", "input_spec": "The first line contains four integers: $$$A$$$, $$$B$$$, $$$C$$$ and $$$D$$$ ($$$1 \\leq A \\leq B \\leq C \\leq D \\leq 5 \\cdot 10^5$$$)\u00a0\u2014 Yuri's favourite numbers.", "output_spec": "Print the number of non-degenerate triangles with integer sides $$$x$$$, $$$y$$$, and $$$z$$$ such that the inequality $$$A \\leq x \\leq B \\leq y \\leq C \\leq z \\leq D$$$ holds.", "sample_inputs": ["1 2 3 4", "1 2 2 5", "500000 500000 500000 500000"], "sample_outputs": ["4", "3", "1"], "notes": "NoteIn the first example Yuri can make up triangles with sides $$$(1, 3, 3)$$$, $$$(2, 2, 3)$$$, $$$(2, 3, 3)$$$ and $$$(2, 3, 4)$$$.In the second example Yuri can make up triangles with sides $$$(1, 2, 2)$$$, $$$(2, 2, 2)$$$ and $$$(2, 2, 3)$$$.In the third example Yuri can make up only one equilateral triangle with sides equal to $$$5 \\cdot 10^5$$$."}, "src_uid": "4f92791b9ec658829f667fcea1faee01"} {"nl": {"description": "wHAT DO WE NEED cAPS LOCK FOR?Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: either it only contains uppercase letters; or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words \"hELLO\", \"HTTP\", \"z\" should be changed.Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.", "input_spec": "The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.", "output_spec": "Print the result of the given word's processing.", "sample_inputs": ["cAPS", "Lock"], "sample_outputs": ["Caps", "Lock"], "notes": null}, "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"} {"nl": {"description": "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_spec": "The only line of input contains an integer m (1\u2009\u2264\u2009m\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the required number of trailing zeroes in factorial.", "output_spec": "First print k\u00a0\u2014 the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order.", "sample_inputs": ["1", "5"], "sample_outputs": ["5\n5 6 7 8 9", "0"], "notes": "NoteThe factorial of n is equal to the product of all integers from 1 to n inclusive, that is n!\u2009=\u20091\u00b72\u00b73\u00b7...\u00b7n.In the first sample, 5!\u2009=\u2009120, 6!\u2009=\u2009720, 7!\u2009=\u20095040, 8!\u2009=\u200940320 and 9!\u2009=\u2009362880."}, "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744"} {"nl": {"description": "Let\u2019s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLMNOPQRSTUVWXYZ We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, \"ABC\" is a path, and so is \"KXWIHIJK\". \"MAB\" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).You\u2019re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there\u2019s no solution, print \"Impossible\" (without the quotes).", "input_spec": "The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.", "output_spec": "Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print \"Impossible\".", "sample_inputs": ["ABCDEFGHIJKLMNOPQRSGTUVWXYZ", "BUVTYZFQSNRIWOXXGJLKACPEMDH"], "sample_outputs": ["YXWVUTGHIJKLM\nZABCDEFSRQPON", "Impossible"], "notes": null}, "src_uid": "56c5ea443dec7a732802b16aed5b934d"} {"nl": {"description": "In Pavlopolis University where Noora studies it was decided to hold beauty contest \"Miss Pavlopolis University\". Let's describe the process of choosing the most beautiful girl in the university in more detail.The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format \"each with each\". In this way, if group consists of x girls, then comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly participants will enter the next stage. The contest continues until there is exactly one girl left who will be \"Miss Pavlopolis University\"But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: t0\u00b7f(l)\u2009+\u2009t1\u00b7f(l\u2009+\u20091)\u2009+\u2009...\u2009+\u2009tr\u2009-\u2009l\u00b7f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109\u2009+\u20097. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.", "input_spec": "The first and single line contains three integers t, l and r (1\u2009\u2264\u2009t\u2009<\u2009109\u2009+\u20097,\u20092\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20095\u00b7106).", "output_spec": "In the first line print single integer \u2014 the value of the expression modulo 109\u2009+\u20097.", "sample_inputs": ["2 2 4"], "sample_outputs": ["19"], "notes": "NoteConsider the sample.It is necessary to find the value of .f(2)\u2009=\u20091. From two girls you can form only one group of two people, in which there will be one comparison.f(3)\u2009=\u20093. From three girls you can form only one group of three people, in which there will be three comparisons.f(4)\u2009=\u20093. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2\u2009+\u20091\u2009=\u20093 comparisons. You can also leave all girls in same group in the first stage. Then comparisons will occur. Obviously, it's better to split girls into groups in the first way.Then the value of the expression is ."}, "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b"} {"nl": {"description": "The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2\u2009>\u2009h1) on the same tree hung an apple and the caterpillar was crawling to the apple.Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.", "input_spec": "The first line contains two integers h1,\u2009h2 (1\u2009\u2264\u2009h1\u2009<\u2009h2\u2009\u2264\u2009105) \u2014 the heights of the position of the caterpillar and the apple in centimeters. The second line contains two integers a,\u2009b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009105) \u2014 the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.", "output_spec": "Print the only integer k \u2014 the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple. If the caterpillar can't get the apple print the only integer \u2009-\u20091.", "sample_inputs": ["10 30\n2 1", "10 13\n1 1", "10 19\n1 2", "1 50\n5 4"], "sample_outputs": ["1", "0", "-1", "1"], "notes": "NoteIn the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day."}, "src_uid": "2c39638f07c3d789ba4c323a205487d7"} {"nl": {"description": "Absent-minded Masha got set of n cubes for her birthday.At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.The number can't contain leading zeros. It's not required to use all cubes to build a number.Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.", "input_spec": "In first line integer n is given (1\u2009\u2264\u2009n\u2009\u2264\u20093)\u00a0\u2014 the number of cubes, Masha got for her birthday. Each of next n lines contains 6 integers aij (0\u2009\u2264\u2009aij\u2009\u2264\u20099)\u00a0\u2014 number on j-th face of i-th cube.", "output_spec": "Print single integer\u00a0\u2014 maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.", "sample_inputs": ["3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7", "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9"], "sample_outputs": ["87", "98"], "notes": "NoteIn the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8."}, "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"} {"nl": {"description": "A and B are preparing themselves for programming contests.To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.For each chess piece we know its weight: the queen's weight is 9, the rook's weight is 5, the bishop's weight is 3, the knight's weight is 3, the pawn's weight is 1, the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board.As A doesn't like counting, he asked you to help him determine which player has the larger position weight.", "input_spec": "The input contains eight lines, eight characters each \u2014 the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook \u2014 as 'R', the bishop \u2014 as'B', the knight \u2014 as 'N', the pawn \u2014 as 'P', the king \u2014 as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.", "output_spec": "Print \"White\" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print \"Black\" if the weight of the black pieces is more than the weight of the white pieces and print \"Draw\" if the weights of the white and black pieces are equal.", "sample_inputs": ["...QK...\n........\n........\n........\n........\n........\n........\n...rk...", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........"], "sample_outputs": ["White", "Draw", "Black"], "notes": "NoteIn the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.In the second test sample the weights of the positions of the black and the white pieces are equal to 39.In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16."}, "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"nl": {"description": "Vasya has got an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect the same pair of vertices. Since the graph is undirected, the pair of edges $$$(1, 2)$$$ and $$$(2, 1)$$$ is considered to be multiple edges. Isolated vertex of the graph is a vertex such that there is no edge connecting this vertex to any other vertex.Vasya wants to know the minimum and maximum possible number of isolated vertices in an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. ", "input_spec": "The only line contains two integers $$$n$$$ and $$$m~(1 \\le n \\le 10^5, 0 \\le m \\le \\frac{n (n - 1)}{2})$$$. It is guaranteed that there exists a graph without any self-loops or multiple edges with such number of vertices and edges.", "output_spec": "In the only line print two numbers $$$min$$$ and $$$max$$$ \u2014 the minimum and maximum number of isolated vertices, respectively.", "sample_inputs": ["4 2", "3 1"], "sample_outputs": ["0 1", "1 1"], "notes": "NoteIn the first example it is possible to construct a graph with $$$0$$$ isolated vertices: for example, it should contain edges $$$(1, 2)$$$ and $$$(3, 4)$$$. To get one isolated vertex, we may construct a graph with edges $$$(1, 2)$$$ and $$$(1, 3)$$$. In the second example the graph will always contain exactly one isolated vertex."}, "src_uid": "daf0dd781bf403f7c1bb668925caa64d"} {"nl": {"description": "Amr loves Geometry. One day he came up with a very interesting problem.Amr has a circle of radius r and center in point (x,\u2009y). He wants the circle center to be in new position (x',\u2009y').In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.Help Amr to achieve his goal in minimum number of steps.", "input_spec": "Input consists of 5 space-separated integers r, x, y, x' y' (1\u2009\u2264\u2009r\u2009\u2264\u2009105, \u2009-\u2009105\u2009\u2264\u2009x,\u2009y,\u2009x',\u2009y'\u2009\u2264\u2009105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.", "output_spec": "Output a single integer \u2014 minimum number of steps required to move the center of the circle to the destination point.", "sample_inputs": ["2 0 0 0 4", "1 1 1 4 4", "4 5 6 5 6"], "sample_outputs": ["1", "3", "0"], "notes": "NoteIn the first sample test the optimal way is to put a pin at point (0,\u20092) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter)."}, "src_uid": "698da80c7d24252b57cca4e4f0ca7031"} {"nl": {"description": "Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains unchanged.", "input_spec": "A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.", "output_spec": "Output the given word after capitalization.", "sample_inputs": ["ApPLe", "konjac"], "sample_outputs": ["ApPLe", "Konjac"], "notes": null}, "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"nl": {"description": "Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility. Initially Sam has a list with a single element n. Then he has to perform certain operations on this list. In each operation Sam must remove any element x, such that x\u2009>\u20091, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.Now the masters want the total number of 1s in the range l to r (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?", "input_spec": "The first line contains three integers n, l, r (0\u2009\u2264\u2009n\u2009<\u2009250, 0\u2009\u2264\u2009r\u2009-\u2009l\u2009\u2264\u2009105, r\u2009\u2265\u20091, l\u2009\u2265\u20091) \u2013 initial element and the range l to r. It is guaranteed that r is not greater than the length of the final list.", "output_spec": "Output the total number of 1s in the range l to r in the final sequence.", "sample_inputs": ["7 2 5", "10 3 10"], "sample_outputs": ["4", "5"], "notes": "NoteConsider first example:Elements on positions from 2-nd to 5-th in list is [1,\u20091,\u20091,\u20091]. The number of ones is 4.For the second example:Elements on positions from 3-rd to 10-th in list is [1,\u20091,\u20091,\u20090,\u20091,\u20090,\u20091,\u20090]. The number of ones is 5."}, "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a"} {"nl": {"description": "A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. \u00a0It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one\u00a0\u2014 in seat 'c'. Assume that all seats are occupied.Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.", "input_spec": "The only line of input contains a description of Vasya's seat in the format ns, where n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.", "output_spec": "Print one integer\u00a0\u2014 the number of seconds Vasya has to wait until he gets his lunch.", "sample_inputs": ["1f", "2d", "4a", "5e"], "sample_outputs": ["1", "10", "11", "18"], "notes": "NoteIn the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6\u2009+\u20091\u2009+\u20093\u2009=\u200910."}, "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"} {"nl": {"description": "You are given a string $$$s$$$ consisting of lowercase Latin letters. Let the length of $$$s$$$ be $$$|s|$$$. You may perform several operations on this string.In one operation, you can choose some index $$$i$$$ and remove the $$$i$$$-th character of $$$s$$$ ($$$s_i$$$) if at least one of its adjacent characters is the previous letter in the Latin alphabet for $$$s_i$$$. For example, the previous letter for b is a, the previous letter for s is r, the letter a has no previous letters. Note that after each removal the length of the string decreases by one. So, the index $$$i$$$ should satisfy the condition $$$1 \\le i \\le |s|$$$ during each operation.For the character $$$s_i$$$ adjacent characters are $$$s_{i-1}$$$ and $$$s_{i+1}$$$. The first and the last characters of $$$s$$$ both have only one adjacent character (unless $$$|s| = 1$$$).Consider the following example. Let $$$s=$$$ bacabcab. During the first move, you can remove the first character $$$s_1=$$$ b because $$$s_2=$$$ a. Then the string becomes $$$s=$$$ acabcab. During the second move, you can remove the fifth character $$$s_5=$$$ c because $$$s_4=$$$ b. Then the string becomes $$$s=$$$ acabab. During the third move, you can remove the sixth character $$$s_6=$$$'b' because $$$s_5=$$$ a. Then the string becomes $$$s=$$$ acaba. During the fourth move, the only character you can remove is $$$s_4=$$$ b, because $$$s_3=$$$ a (or $$$s_5=$$$ a). The string becomes $$$s=$$$ acaa and you cannot do anything with it. Your task is to find the maximum possible number of characters you can remove if you choose the sequence of operations optimally.", "input_spec": "The only line of the input contains one integer $$$|s|$$$ ($$$1 \\le |s| \\le 100$$$) \u2014 the length of $$$s$$$. The second line of the input contains one string $$$s$$$ consisting of $$$|s|$$$ lowercase Latin letters.", "output_spec": "Print one integer \u2014 the maximum possible number of characters you can remove if you choose the sequence of moves optimally.", "sample_inputs": ["8\nbacabcab", "4\nbcda", "6\nabbbbb"], "sample_outputs": ["4", "3", "5"], "notes": "NoteThe first example is described in the problem statement. Note that the sequence of moves provided in the statement is not the only, but it can be shown that the maximum possible answer to this test is $$$4$$$.In the second example, you can remove all but one character of $$$s$$$. The only possible answer follows. During the first move, remove the third character $$$s_3=$$$ d, $$$s$$$ becomes bca. During the second move, remove the second character $$$s_2=$$$ c, $$$s$$$ becomes ba. And during the third move, remove the first character $$$s_1=$$$ b, $$$s$$$ becomes a. "}, "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38"} {"nl": {"description": "Arpa is researching the Mexican wave.There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator stands. At time k\u2009+\u20091, the (k\u2009+\u20091)-th spectator stands and the first spectator sits. At time k\u2009+\u20092, the (k\u2009+\u20092)-th spectator stands and the second spectator sits. ... At time n, the n-th spectator stands and the (n\u2009-\u2009k)-th spectator sits. At time n\u2009+\u20091, the (n\u2009+\u20091\u2009-\u2009k)-th spectator sits. ... At time n\u2009+\u2009k, the n-th spectator sits. Arpa wants to know how many spectators are standing at time t.", "input_spec": "The first line contains three integers n, k, t (1\u2009\u2264\u2009n\u2009\u2264\u2009109, 1\u2009\u2264\u2009k\u2009\u2264\u2009n, 1\u2009\u2264\u2009t\u2009<\u2009n\u2009+\u2009k).", "output_spec": "Print single integer: how many spectators are standing at time t.", "sample_inputs": ["10 5 3", "10 5 7", "10 5 12"], "sample_outputs": ["3", "5", "3"], "notes": "NoteIn the following a sitting spectator is represented as -, a standing spectator is represented as ^. At t\u2009=\u20090\u2002 ---------- number of standing spectators = 0. At t\u2009=\u20091\u2002 ^--------- number of standing spectators = 1. At t\u2009=\u20092\u2002 ^^-------- number of standing spectators = 2. At t\u2009=\u20093\u2002 ^^^------- number of standing spectators = 3. At t\u2009=\u20094\u2002 ^^^^------ number of standing spectators = 4. At t\u2009=\u20095\u2002 ^^^^^----- number of standing spectators = 5. At t\u2009=\u20096\u2002 -^^^^^---- number of standing spectators = 5. At t\u2009=\u20097\u2002 --^^^^^--- number of standing spectators = 5. At t\u2009=\u20098\u2002 ---^^^^^-- number of standing spectators = 5. At t\u2009=\u20099\u2002 ----^^^^^- number of standing spectators = 5. At t\u2009=\u200910 -----^^^^^ number of standing spectators = 5. At t\u2009=\u200911 ------^^^^ number of standing spectators = 4. At t\u2009=\u200912 -------^^^ number of standing spectators = 3. At t\u2009=\u200913 --------^^ number of standing spectators = 2. At t\u2009=\u200914 ---------^ number of standing spectators = 1. At t\u2009=\u200915 ---------- number of standing spectators = 0. "}, "src_uid": "7e614526109a2052bfe7934381e7f6c2"} {"nl": {"description": "Given an integer $$$x$$$, find 2 integers $$$a$$$ and $$$b$$$ such that: $$$1 \\le a,b \\le x$$$ $$$b$$$ divides $$$a$$$ ($$$a$$$ is divisible by $$$b$$$). $$$a \\cdot b>x$$$. $$$\\frac{a}{b}<x$$$. ", "input_spec": "The only line contains the integer $$$x$$$ $$$(1 \\le x \\le 100)$$$.", "output_spec": "You should output two integers $$$a$$$ and $$$b$$$, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print \"-1\" (without quotes).", "sample_inputs": ["10", "1"], "sample_outputs": ["6 3", "-1"], "notes": null}, "src_uid": "883f67177474d23d7a320d9dbfa70dd3"} {"nl": {"description": "Even if the world is full of counterfeits, I still regard it as wonderful.Pile up herbs and incense, and arise again from the flames and ashes of its predecessor\u00a0\u2014 as is known to many, the phoenix does it like this.The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a!\u2009=\u20091\u2009\u00d7\u20092\u2009\u00d7\u2009...\u2009\u00d7\u2009a. Specifically, 0!\u2009=\u20091.Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, . Note that when b\u2009\u2265\u2009a this value is always integer.As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.", "input_spec": "The first and only line of input contains two space-separated integers a and b (0\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u20091018).", "output_spec": "Output one line containing a single decimal digit\u00a0\u2014 the last digit of the value that interests Koyomi.", "sample_inputs": ["2 4", "0 10", "107 109"], "sample_outputs": ["2", "0", "2"], "notes": "NoteIn the first example, the last digit of is 2;In the second example, the last digit of is 0;In the third example, the last digit of is 2."}, "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"} {"nl": {"description": "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,\u20092,\u20093,\u2009...,\u2009k. The picture below shows a part of a 3-tree. 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 (109\u2009+\u20097). ", "input_spec": "A single line contains three space-separated integers: n, k and d (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009100; 1\u2009\u2264\u2009d\u2009\u2264\u2009k).", "output_spec": "Print a single integer \u2014 the answer to the problem modulo 1000000007 (109\u2009+\u20097). ", "sample_inputs": ["3 3 2", "3 3 3", "4 3 2", "4 5 2"], "sample_outputs": ["3", "1", "6", "7"], "notes": null}, "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"nl": {"description": "There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i\u2009-\u2009j|.Limak is a police officer. He lives in a city a. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city a. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.", "input_spec": "The first line of the input contains two integers n and a (1\u2009\u2264\u2009a\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of cities and the index of city where Limak lives. The second line contains n integers t1,\u2009t2,\u2009...,\u2009tn (0\u2009\u2264\u2009ti\u2009\u2264\u20091). There are ti criminals in the i-th city.", "output_spec": "Print the number of criminals Limak will catch.", "sample_inputs": ["6 3\n1 1 1 0 1 0", "5 2\n0 0 0 1 0"], "sample_outputs": ["3", "1"], "notes": "NoteIn the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: There is one criminal at distance 0 from the third city\u00a0\u2014 Limak is sure that this criminal is exactly in the third city. There is one criminal at distance 1 from the third city\u00a0\u2014 Limak doesn't know if a criminal is in the second or fourth city. There are two criminals at distance 2 from the third city\u00a0\u2014 Limak is sure that there is one criminal in the first city and one in the fifth city. There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is. "}, "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"nl": {"description": "Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1\u2009234\u2009567 game-coins each), cars (for 123\u2009456 game-coins each) and computers (for 1\u2009234 game-coins each).Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers a, b and c such that a\u2009\u00d7\u20091\u2009234\u2009567\u2009+\u2009b\u2009\u00d7\u2009123\u2009456\u2009+\u2009c\u2009\u00d7\u20091\u2009234\u2009=\u2009n?Please help Kolya answer this question.", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109)\u00a0\u2014 Kolya's initial game-coin score.", "output_spec": "Print \"YES\" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print \"NO\" (without quotes).", "sample_inputs": ["1359257", "17851817"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1\u2009234\u2009567\u2009+\u2009123\u2009456\u2009+\u20091234\u2009=\u20091\u2009359\u2009257 game-coins in total."}, "src_uid": "72d7e422a865cc1f85108500bdf2adf2"} {"nl": {"description": "Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).Print -1 if she can't give him k candies during n given days.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 1\u2009\u2264\u2009k\u2009\u2264\u200910000). The second line contains n integers a1,\u2009a2,\u2009a3,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100).", "output_spec": "If it is impossible for Arya to give Bran k candies within n days, print -1. Otherwise print a single integer\u00a0\u2014 the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.", "sample_inputs": ["2 3\n1 2", "3 17\n10 10 10", "1 9\n10"], "sample_outputs": ["2", "3", "-1"], "notes": "NoteIn the first sample, Arya can give Bran 3 candies in 2 days.In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day."}, "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"} {"nl": {"description": "A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i\u00b7k dollars for the i-th banana). He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?", "input_spec": "The first line contains three positive integers k,\u2009n,\u2009w (1\u2009\u2009\u2264\u2009\u2009k,\u2009w\u2009\u2009\u2264\u2009\u20091000, 0\u2009\u2264\u2009n\u2009\u2264\u2009109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. ", "output_spec": "Output one integer \u2014 the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.", "sample_inputs": ["3 17 4"], "sample_outputs": ["13"], "notes": null}, "src_uid": "e87d9798107734a885fd8263e1431347"} {"nl": {"description": "One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters \"a\", \"b\" and \"c\" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: G has exactly n vertices, numbered from 1 to n. For all pairs of vertices i and j, where i\u2009\u2260\u2009j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs \"a\"-\"b\" and \"b\"-\"c\" are neighbouring, while letters \"a\"-\"c\" are not. Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.", "input_spec": "The first line of the input contains two integers n and m \u00a0\u2014 the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1\u2009\u2264\u2009ui,\u2009vi\u2009\u2264\u2009n,\u2009ui\u2009\u2260\u2009vi)\u00a0\u2014 the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.", "output_spec": "In the first line print \"Yes\" (without the quotes), if the string s Petya is interested in really exists and \"No\" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters \"a\", \"b\" and \"c\" only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.", "sample_inputs": ["2 1\n1 2", "4 3\n1 2\n1 3\n1 4"], "sample_outputs": ["Yes\naa", "No"], "notes": "NoteIn the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings \"aa\", \"ab\", \"ba\", \"bb\", \"bc\", \"cb\", \"cc\" meets the graph's conditions. In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c."}, "src_uid": "e71640f715f353e49745eac5f72e682a"} {"nl": {"description": "Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.For example, the following three arrays are unimodal: [5,\u20097,\u200911,\u200911,\u20092,\u20091], [4,\u20094,\u20092], [7], but the following three are not unimodal: [5,\u20095,\u20096,\u20096,\u20091], [1,\u20092,\u20091,\u20092], [4,\u20095,\u20095,\u20096].Write a program that checks if an array is unimodal.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of elements in the array. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u20091\u2009000) \u2014 the elements of the array.", "output_spec": "Print \"YES\" if the given array is unimodal. Otherwise, print \"NO\". You can output each letter in any case (upper or lower).", "sample_inputs": ["6\n1 5 5 5 4 2", "5\n10 20 30 20 10", "4\n1 2 1 2", "7\n3 3 3 3 3 3 3"], "sample_outputs": ["YES", "YES", "NO", "YES"], "notes": "NoteIn the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively)."}, "src_uid": "5482ed8ad02ac32d28c3888299bf3658"} {"nl": {"description": "Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.", "input_spec": "The only line of input contains integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u20091012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print the number that will stand at the position number k after Volodya's manipulations.", "sample_inputs": ["10 3", "7 7"], "sample_outputs": ["5", "6"], "notes": "NoteIn the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5."}, "src_uid": "1f8056884db00ad8294a7cc0be75fe97"} {"nl": {"description": "Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?", "input_spec": "The first line of the input contains three integers t, w and b (1\u2009\u2264\u2009t,\u2009w,\u2009b\u2009\u2264\u20095\u00b71018) \u2014 the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.", "output_spec": "Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (p and q are integers, and both p\u2009\u2265\u20090 and q\u2009>\u20090 holds) is called irreducible, if there is no such integer d\u2009>\u20091, that both p and q are divisible by d.", "sample_inputs": ["10 3 2", "7 1 2"], "sample_outputs": ["3/10", "3/7"], "notes": "NoteIn the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack."}, "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"} {"nl": {"description": "Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1,\u20092,\u2009...,\u2009z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.", "input_spec": "The only string contains three integers\u00a0\u2014 n, m and z (1\u2009\u2264\u2009n,\u2009m,\u2009z\u2009\u2264\u2009104).", "output_spec": "Print single integer\u00a0\u2014 the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.", "sample_inputs": ["1 1 10", "1 2 5", "2 3 9"], "sample_outputs": ["10", "2", "1"], "notes": "NoteTaymyr is a place in the north of Russia.In the first test the artists come each minute, as well as the calls, so we need to kill all of them.In the second test we need to kill artists which come on the second and the fourth minutes.In the third test\u00a0\u2014 only the artist which comes on the sixth minute. "}, "src_uid": "e7ad55ce26fc8610639323af1de36c2d"} {"nl": {"description": "Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0\u2009<\u2009x\u2009<\u2009109) of the equation:x\u2009=\u2009b\u00b7s(x)a\u2009+\u2009c,\u2009 where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.", "input_spec": "The first line contains three space-separated integers: a,\u2009b,\u2009c (1\u2009\u2264\u2009a\u2009\u2264\u20095;\u00a01\u2009\u2264\u2009b\u2009\u2264\u200910000;\u00a0\u2009-\u200910000\u2009\u2264\u2009c\u2009\u2264\u200910000).", "output_spec": "Print integer n \u2014 the number of the solutions that you've found. Next print n integers in the increasing order \u2014 the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.", "sample_inputs": ["3 2 8", "1 2 -18", "2 2 -1"], "sample_outputs": ["3\n10 2008 13726", "0", "4\n1 31 337 967"], "notes": null}, "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"nl": {"description": "Vasya has a pile, that consists of some number of stones. $$$n$$$ times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.You are given $$$n$$$ operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.", "input_spec": "The first line contains one positive integer $$$n$$$\u00a0\u2014 the number of operations, that have been made by Vasya ($$$1 \\leq n \\leq 100$$$). The next line contains the string $$$s$$$, consisting of $$$n$$$ symbols, equal to \"-\" (without quotes) or \"+\" (without quotes). If Vasya took the stone on $$$i$$$-th operation, $$$s_i$$$ is equal to \"-\" (without quotes), if added, $$$s_i$$$ is equal to \"+\" (without quotes).", "output_spec": "Print one integer\u00a0\u2014 the minimal possible number of stones that can be in the pile after these $$$n$$$ operations.", "sample_inputs": ["3\n---", "4\n++++", "2\n-+", "5\n++-++"], "sample_outputs": ["0", "4", "1", "3"], "notes": "NoteIn the first test, if Vasya had $$$3$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$0$$$. It is impossible to have less number of piles, so the answer is $$$0$$$. Please notice, that the number of stones at the beginning can't be less, than $$$3$$$, because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty).In the second test, if Vasya had $$$0$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$4$$$. It is impossible to have less number of piles because after making $$$4$$$ operations the number of stones in the pile increases on $$$4$$$ stones. So, the answer is $$$4$$$.In the third test, if Vasya had $$$1$$$ stone in the pile at the beginning, after making operations the number of stones will be equal to $$$1$$$. It can be proved, that it is impossible to have less number of stones after making the operations.In the fourth test, if Vasya had $$$0$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$3$$$."}, "src_uid": "a593016e4992f695be7c7cd3c920d1ed"} {"nl": {"description": "Maksim walks on a Cartesian plane. Initially, he stands at the point $$$(0, 0)$$$ and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point $$$(0, 0)$$$, he can go to any of the following points in one move: $$$(1, 0)$$$; $$$(0, 1)$$$; $$$(-1, 0)$$$; $$$(0, -1)$$$. There are also $$$n$$$ distinct key points at this plane. The $$$i$$$-th point is $$$p_i = (x_i, y_i)$$$. It is guaranteed that $$$0 \\le x_i$$$ and $$$0 \\le y_i$$$ and there is no key point $$$(0, 0)$$$.Let the first level points be such points that $$$max(x_i, y_i) = 1$$$, the second level points be such points that $$$max(x_i, y_i) = 2$$$ and so on. Maksim wants to visit all the key points. But he shouldn't visit points of level $$$i + 1$$$ if he does not visit all the points of level $$$i$$$. He starts visiting the points from the minimum level of point from the given set.The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$ where $$$|v|$$$ is the absolute value of $$$v$$$.Maksim wants to visit all the key points in such a way that the total distance he walks will be minimum possible. Your task is to find this distance.If you are Python programmer, consider using PyPy instead of Python when you submit your code.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the number of key points. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \\le x_i, y_i \\le 10^9$$$) \u2014 $$$x$$$-coordinate of the key point $$$p_i$$$ and $$$y$$$-coordinate of the key point $$$p_i$$$. It is guaranteed that all the points are distinct and the point $$$(0, 0)$$$ is not in this set.", "output_spec": "Print one integer \u2014 the minimum possible total distance Maksim has to travel if he needs to visit all key points in a way described above.", "sample_inputs": ["8\n2 2\n1 4\n2 3\n3 1\n3 4\n1 1\n4 3\n1 2", "5\n2 1\n1 0\n2 0\n3 2\n0 3"], "sample_outputs": ["15", "9"], "notes": "NoteThe picture corresponding to the first example: There is one of the possible answers of length $$$15$$$.The picture corresponding to the second example: There is one of the possible answers of length $$$9$$$."}, "src_uid": "06646a9bdce2d65e92e525e97b2c975d"} {"nl": {"description": "Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.When a garland is switched on, it periodically changes its state \u2014 sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x\u2009+\u2009ki, x\u2009+\u20092ki, x\u2009+\u20093ki and so on.Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one \u2014 during x2-th second, and the third one \u2014 during x3-th second, respectively, and during each second starting from max(x1,\u2009x2,\u2009x3) at least one garland will be lit.Help Mishka by telling him if it is possible to do this!", "input_spec": "The first line contains three integers k1, k2 and k3 (1\u2009\u2264\u2009ki\u2009\u2264\u20091500) \u2014 time intervals of the garlands.", "output_spec": "If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.", "sample_inputs": ["2 2 3", "4 2 3"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example Mishka can choose x1\u2009=\u20091, x2\u2009=\u20092, x3\u2009=\u20091. The first garland will be lit during seconds 1,\u20093,\u20095,\u20097,\u2009..., the second \u2014 2,\u20094,\u20096,\u20098,\u2009..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1,\u20094,\u20097,\u200910,\u2009..., though.In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit."}, "src_uid": "df48af9f5e68cb6efc1214f7138accf9"} {"nl": {"description": "Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8\u2009\u00d7\u20098 table. A field is represented by a pair of integers (r,\u2009c) \u2014 the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: A rook moves any number of fields horizontally or vertically. A bishop moves any number of fields diagonally. A king moves one field in any direction \u2014 horizontally, vertically or diagonally. The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1,\u2009c1) to field (r2,\u2009c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.", "input_spec": "The input contains four integers r1,\u2009c1,\u2009r2,\u2009c2 (1\u2009\u2264\u2009r1,\u2009c1,\u2009r2,\u2009c2\u2009\u2264\u20098) \u2014 the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.", "output_spec": "Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1,\u2009c1) to field (r2,\u2009c2). If a piece cannot make such a move, print a 0 instead of the corresponding number.", "sample_inputs": ["4 3 1 6", "5 5 5 6"], "sample_outputs": ["2 1 3", "1 0 1"], "notes": null}, "src_uid": "7dbf58806db185f0fe70c00b60973f4b"} {"nl": {"description": "Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.Now he wonders what is an average value of sum of digits of the number A written in all bases from 2 to A\u2009-\u20091.Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.", "input_spec": "Input contains one integer number A (3\u2009\u2264\u2009A\u2009\u2264\u20091000).", "output_spec": "Output should contain required average value in format \u00abX/Y\u00bb, where X is the numerator and Y is the denominator.", "sample_inputs": ["5", "3"], "sample_outputs": ["7/3", "2/1"], "notes": "NoteIn the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively."}, "src_uid": "1366732dddecba26db232d6ca8f35fdc"} {"nl": {"description": "Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw $$$n$$$ squares in the snow with a side length of $$$1$$$. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length $$$1$$$, parallel to the coordinate axes, with vertices at integer points.In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends $$$(x, y)$$$ and $$$(x, y+1)$$$. Then Sofia looks if there is already a drawn segment with the coordinates of the ends $$$(x', y)$$$ and $$$(x', y+1)$$$ for some $$$x'$$$. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates $$$x$$$, $$$x+1$$$ and the differing coordinate $$$y$$$.For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: After that, she can draw the remaining two segments, using the first two as a guide: If Sofia needs to draw two squares, she will have to draw three segments using a ruler: After that, she can draw the remaining four segments, using the first three as a guide: Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.", "input_spec": "The only line of input contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^{9}$$$), the number of squares that Sofia wants to draw.", "output_spec": "Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw $$$n$$$ squares in the manner described above.", "sample_inputs": ["1", "2", "4"], "sample_outputs": ["2", "3", "4"], "notes": null}, "src_uid": "eb8212aec951f8f69b084446da73eaf7"} {"nl": {"description": "Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.Fortunately the child knows how to solve such complicated test. The child will follow the algorithm: If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose?", "input_spec": "The first line starts with \"A.\" (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix \"X.\", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or \"_\". ", "output_spec": "Print a single line with the child's choice: \"A\", \"B\", \"C\" or \"D\" (without quotes).", "sample_inputs": ["A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "A.ab\nB.abcde\nC.ab\nD.abc", "A.c\nB.cc\nC.c\nD.c"], "sample_outputs": ["D", "C", "B"], "notes": "NoteIn the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.In the second sample, no choice is great, so the child will choose the luckiest choice C.In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B."}, "src_uid": "30725e340dc07f552f0cce359af226a4"} {"nl": {"description": "Do you remember a kind cartoon \"Beauty and the Beast\"? No, no, there was no firing from machine guns or radiation mutants time-travels!There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll. Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.You can only rotate the hands forward, that is, as is shown in the picture: As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.", "input_spec": "The only line of input contains current time according to the digital clock, formatted as HH:MM (00\u2009\u2264\u2009HH\u2009\u2264\u200923, 00\u2009\u2264\u2009MM\u2009\u2264\u200959). The mantel clock initially shows 12:00. Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.", "output_spec": "Print two numbers x and y \u2014 the angles of turning the hour and minute hands, respectively (0\u2009\u2264\u2009x,\u2009y\u2009<\u2009360). The absolute or relative error in the answer should not exceed 10\u2009-\u20099.", "sample_inputs": ["12:00", "04:30", "08:17"], "sample_outputs": ["0 0", "135 180", "248.5 102"], "notes": "NoteA note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5."}, "src_uid": "175dc0bdb5c9513feb49be6644d0d150"} {"nl": {"description": "You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the end of the string. Besides, at most once you may perform one additional operation: copy the string and append it to itself.For example, if you have to type string abcabca, you can type it in 7 operations if you type all the characters one by one. However, you can type it in 5 operations if you type the string abc first and then copy it and type the last character.If you have to type string aaaaaaaaa, the best option is to type 4 characters one by one, then copy the string, and then type the remaining character.Print the minimum number of operations you need to type the given string.", "input_spec": "The first line of the input containing only one integer number n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the length of the string you have to type. The second line containing the string s consisting of n lowercase Latin letters.", "output_spec": "Print one integer number\u00a0\u2014 the minimum number of operations you need to type the given string.", "sample_inputs": ["7\nabcabca", "8\nabcdefgh"], "sample_outputs": ["5", "8"], "notes": "NoteThe first test described in the problem statement.In the second test you can only type all the characters one by one."}, "src_uid": "ed8725e4717c82fa7cfa56178057bca3"} {"nl": {"description": "Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples.Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them.", "input_spec": "The first line contains integers n, a, b (1\u2009\u2264\u2009n\u2009\u2264\u2009100;\u00a01\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009n) \u2014 the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains a distinct integers \u2014 the numbers of the apples Arthur likes. The next line contains b distinct integers \u2014 the numbers of the apples Alexander likes. Assume that the apples are numbered from 1 to n. The input is such that the answer exists.", "output_spec": "Print n characters, each of them equals either 1 or 2. If the i-h character equals 1, then the i-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.", "sample_inputs": ["4 2 3\n1 2\n2 3 4", "5 5 2\n3 4 1 2 5\n2 3"], "sample_outputs": ["1 1 2 2", "1 1 1 1 1"], "notes": null}, "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93"} {"nl": {"description": "Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1,\u2009y1) and should go to the point (x2,\u2009y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.", "input_spec": "The first line contains two integers x1,\u2009y1 (\u2009-\u2009109\u2009\u2264\u2009x1,\u2009y1\u2009\u2264\u2009109) \u2014 the start position of the robot. The second line contains two integers x2,\u2009y2 (\u2009-\u2009109\u2009\u2264\u2009x2,\u2009y2\u2009\u2264\u2009109) \u2014 the finish position of the robot.", "output_spec": "Print the only integer d \u2014 the minimal number of steps to get the finish position.", "sample_inputs": ["0 0\n4 5", "3 4\n6 1"], "sample_outputs": ["5", "3"], "notes": "NoteIn the first example robot should increase both of its coordinates by one four times, so it will be in position (4,\u20094). After that robot should simply increase its y coordinate and get the finish position.In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times."}, "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"} {"nl": {"description": "In this problem you will meet the simplified model of game King of Thieves.In a new ZeptoLab game called \"King of Thieves\" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'. One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1, he can make a sequence of jumps through the platforms i1\u2009<\u2009i2\u2009<\u2009...\u2009<\u2009ik, if i2\u2009-\u2009i1\u2009=\u2009i3\u2009-\u2009i2\u2009=\u2009...\u2009=\u2009ik\u2009-\u2009ik\u2009-\u20091. Of course, all segments i1,\u2009i2,\u2009... ik should be exactly the platforms, not pits. Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i1,\u2009i2,\u2009...,\u2009i5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of segments on the level. Next line contains the scheme of the level represented as a string of n characters '*' and '.'.", "output_spec": "If the level is good, print the word \"yes\" (without the quotes), otherwise print the word \"no\" (without the quotes).", "sample_inputs": ["16\n.**.*..*.***.**.", "11\n.*.*...*.*."], "sample_outputs": ["yes", "no"], "notes": "NoteIn the first sample test you may perform a sequence of jumps through platforms 2,\u20095,\u20098,\u200911,\u200914."}, "src_uid": "12d451eb1b401a8f426287c4c6909e4b"} {"nl": {"description": "Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. The painting is a square 3\u2009\u00d7\u20093, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers. The sum of integers in each of four squares 2\u2009\u00d7\u20092 is equal to the sum of integers in the top left square 2\u2009\u00d7\u20092. Four elements a, b, c and d are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.", "input_spec": "The first line of the input contains five integers n, a, b, c and d (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000, 1\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d\u2009\u2264\u2009n)\u00a0\u2014 maximum possible value of an integer in the cell and four integers that Vasya remembers.", "output_spec": "Print one integer\u00a0\u2014 the number of distinct valid squares.", "sample_inputs": ["2 1 1 1 2", "3 3 1 2 3"], "sample_outputs": ["2", "6"], "notes": "NoteBelow are all the possible paintings for the first sample. In the second sample, only paintings displayed below satisfy all the rules. "}, "src_uid": "b732869015baf3dee5094c51a309e32c"} {"nl": {"description": "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_spec": "The first line contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the length of the interview. The second line contains the string s of length n, consisting of lowercase English letters.", "output_spec": "Print the interview text after the replacement of each of the fillers with \"***\". It is allowed for the substring \"***\" to have several consecutive occurences.", "sample_inputs": ["7\naogogob", "13\nogogmgogogogo", "9\nogoogoogo"], "sample_outputs": ["a***b", "***gmg***", "*********"], "notes": "NoteThe 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***\"."}, "src_uid": "619665bed79ecf77b083251fe6fe7eb3"} {"nl": {"description": "Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages.A brave hero decided to put an end to the dragon. He moved from point A to fight with Gorynych. The hero rode from point A along a straight road and met point B on his way. The hero knows that in this land for every pair of roads it is true that they are either parallel to each other, or lie on a straight line, or are perpendicular to each other. He also knows well that points B and C are connected by a road. So the hero must either turn 90 degrees to the left or continue riding straight ahead or turn 90 degrees to the right. But he forgot where the point C is located.Fortunately, a Brave Falcon flew right by. It can see all three points from the sky. The hero asked him what way to go to get to the dragon's lair.If you have not got it, you are the falcon. Help the hero and tell him how to get him to point C: turn left, go straight or turn right.At this moment the hero is believed to stand at point B, turning his back to point A.", "input_spec": "The first input line contains two space-separated integers xa,\u2009ya (|xa|,\u2009|ya|\u2009\u2264\u2009109) \u2014 the coordinates of point A. The second line contains the coordinates of point B in the same form, the third line contains the coordinates of point C. It is guaranteed that all points are pairwise different. It is also guaranteed that either point B lies on segment AC, or angle ABC is right.", "output_spec": "Print a single line. If a hero must turn left, print \"LEFT\" (without the quotes); If he must go straight ahead, print \"TOWARDS\" (without the quotes); if he should turn right, print \"RIGHT\" (without the quotes).", "sample_inputs": ["0 0\n0 1\n1 1", "-1 -1\n-3 -3\n-4 -4", "-4 -6\n-3 -7\n-2 -6"], "sample_outputs": ["RIGHT", "TOWARDS", "LEFT"], "notes": "NoteThe picture to the first sample: The red color shows points A, B and C. The blue arrow shows the hero's direction. The green color shows the hero's trajectory.The picture to the second sample: "}, "src_uid": "f6e132d1969863e9f28c87e5a44c2b69"} {"nl": {"description": "You are given two strings $$$s$$$ and $$$t$$$ consisting of lowercase Latin letters. The length of $$$t$$$ is $$$2$$$ (i.e. this string consists only of two characters).In one move, you can choose any character of $$$s$$$ and replace it with any lowercase Latin letter. More formally, you choose some $$$i$$$ and replace $$$s_i$$$ (the character at the position $$$i$$$) with some character from 'a' to 'z'.You want to do no more than $$$k$$$ replacements in such a way that maximizes the number of occurrences of $$$t$$$ in $$$s$$$ as a subsequence.Recall that a subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 200$$$; $$$0 \\le k \\le n$$$) \u2014 the length of $$$s$$$ and the maximum number of moves you can make. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. The third line of the input contains the string $$$t$$$ consisting of two lowercase Latin letters.", "output_spec": "Print one integer \u2014 the maximum possible number of occurrences of $$$t$$$ in $$$s$$$ as a subsequence if you replace no more than $$$k$$$ characters in $$$s$$$ optimally.", "sample_inputs": ["4 2\nbbaa\nab", "7 3\nasddsaf\nsd", "15 6\nqwertyhgfdsazxc\nqa", "7 2\nabacaba\naa"], "sample_outputs": ["3", "10", "16", "15"], "notes": "NoteIn the first example, you can obtain the string \"abab\" replacing $$$s_1$$$ with 'a' and $$$s_4$$$ with 'b'. Then the answer is $$$3$$$.In the second example, you can obtain the string \"ssddsdd\" and get the answer $$$10$$$.In the fourth example, you can obtain the string \"aaacaaa\" and get the answer $$$15$$$."}, "src_uid": "9c700390ac13942cbde7c3428965b18a"} {"nl": {"description": "Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $$$n$$$ rows and $$$m$$$ columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo $$$10^9 + 7$$$.", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 100\\,000$$$), the number of rows and the number of columns of the field.", "output_spec": "Print one integer, the number of random pictures modulo $$$10^9 + 7$$$.", "sample_inputs": ["2 3"], "sample_outputs": ["8"], "notes": "NoteThe picture below shows all possible random pictures of size $$$2$$$ by $$$3$$$. "}, "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"nl": {"description": "A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right. Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture: Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'. Find any of the most convenient vacant places for Petya.", "input_spec": "The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' \u2014 the description of the left desk in the current row; a character '-' \u2014 the aisle; two characters, each is '*' or '.' \u2014 the description of the center desk in the current row; a character '-' \u2014 the aisle; two characters, each is '*' or '.' \u2014 the description of the right desk in the current row. So, the length of each of the six lines is 8. It is guaranteed that there is at least one vacant place in the classroom.", "output_spec": "Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input. If there are multiple answers, print any.", "sample_inputs": ["..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..", "**-**-*.\n*.-*.-**\n**-**-**\n**-**-**\n..-..-..\n..-**-.."], "sample_outputs": ["..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-..", "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-..", "**-**-*.\n*.-*P-**\n**-**-**\n**-**-**\n..-..-..\n..-**-.."], "notes": "NoteIn the first example the maximum convenience is 3.In the second example the maximum convenience is 2.In the third example the maximum convenience is 4."}, "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"} {"nl": {"description": "After seeing the \"ALL YOUR BASE ARE BELONG TO US\" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.", "input_spec": "The first line of the input contains two space-separated integers n and bx (1\u2009\u2264\u2009n\u2009\u2264\u200910, 2\u2009\u2264\u2009bx\u2009\u2264\u200940), where n is the number of digits in the bx-based representation of X. The second line contains n space-separated integers x1,\u2009x2,\u2009...,\u2009xn (0\u2009\u2264\u2009xi\u2009<\u2009bx) \u2014 the digits of X. They are given in the order from the most significant digit to the least significant one. The following two lines describe Y in the same way: the third line contains two space-separated integers m and by (1\u2009\u2264\u2009m\u2009\u2264\u200910, 2\u2009\u2264\u2009by\u2009\u2264\u200940, bx\u2009\u2260\u2009by), where m is the number of digits in the by-based representation of Y, and the fourth line contains m space-separated integers y1,\u2009y2,\u2009...,\u2009ym (0\u2009\u2264\u2009yi\u2009<\u2009by) \u2014 the digits of Y. There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.", "output_spec": "Output a single character (quotes for clarity): '<' if X\u2009<\u2009Y '>' if X\u2009>\u2009Y '=' if X\u2009=\u2009Y ", "sample_inputs": ["6 2\n1 0 1 1 1 1\n2 10\n4 7", "3 3\n1 0 2\n2 5\n2 4", "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0"], "sample_outputs": ["=", "<", ">"], "notes": "NoteIn the first sample, X\u2009=\u20091011112\u2009=\u20094710\u2009=\u2009Y.In the second sample, X\u2009=\u20091023\u2009=\u2009215 and Y\u2009=\u2009245\u2009=\u20091123, thus X\u2009<\u2009Y.In the third sample, and Y\u2009=\u200948031509. We may notice that X starts with much larger digits and bx is much larger than by, so X is clearly larger than Y."}, "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"} {"nl": {"description": "Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.Arithmetic progression is a sequence a1, a1\u2009+\u2009d, a1\u2009+\u20092d, ..., a1\u2009+\u2009(n\u2009-\u20091)d, where a1 and d are any numbers.Geometric progression is a sequence b1, b2\u2009=\u2009b1q, ..., bn\u2009=\u2009bn\u2009-\u20091q, where b1\u2009\u2260\u20090, q\u2009\u2260\u20090, q\u2009\u2260\u20091. Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.", "input_spec": "The first line contains exactly four integer numbers between 1 and 1000, inclusively.", "output_spec": "Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element. Print 42 if the given sequence is not an arithmetic or geometric progression.", "sample_inputs": ["836 624 412 200", "1 334 667 1000"], "sample_outputs": ["-12", "1333"], "notes": "NoteThis problem contains very weak pretests!"}, "src_uid": "68a9508d49fec672f9c61766d6051047"} {"nl": {"description": "There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?It's guaranteed that the optimal answer is always integer.", "input_spec": "The first line of the input contains three distinct integers x1, x2 and x3 (1\u2009\u2264\u2009x1,\u2009x2,\u2009x3\u2009\u2264\u2009100)\u00a0\u2014 the coordinates of the houses of the first, the second and the third friends respectively. ", "output_spec": "Print one integer\u00a0\u2014 the minimum total distance the friends need to travel in order to meet together.", "sample_inputs": ["7 1 4", "30 20 10"], "sample_outputs": ["6", "20"], "notes": "NoteIn the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4."}, "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"} {"nl": {"description": "n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1,\u2009a2,\u2009...,\u2009an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.The game consists of m steps. On each step the current leader with index i counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.You are given numbers l1,\u2009l2,\u2009...,\u2009lm \u2014 indices of leaders in the beginning of each step. Child with number l1 is the first leader in the game. Write a program which will restore a possible permutation a1,\u2009a2,\u2009...,\u2009an. If there are multiple solutions then print any of them. If there is no solution then print -1.", "input_spec": "The first line contains two integer numbers n, m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100). The second line contains m integer numbers l1,\u2009l2,\u2009...,\u2009lm (1\u2009\u2264\u2009li\u2009\u2264\u2009n) \u2014 indices of leaders in the beginning of each step.", "output_spec": "Print such permutation of n numbers a1,\u2009a2,\u2009...,\u2009an that leaders in the game will be exactly l1,\u2009l2,\u2009...,\u2009lm if all the rules are followed. If there are multiple solutions print any of them. If there is no permutation which satisfies all described conditions print -1.", "sample_inputs": ["4 5\n2 3 1 4 4", "3 3\n3 1 2"], "sample_outputs": ["3 1 2 4", "-1"], "notes": "NoteLet's follow leadership in the first example: Child 2 starts. Leadership goes from 2 to 2\u2009+\u2009a2\u2009=\u20093. Leadership goes from 3 to 3\u2009+\u2009a3\u2009=\u20095. As it's greater than 4, it's going in a circle to 1. Leadership goes from 1 to 1\u2009+\u2009a1\u2009=\u20094. Leadership goes from 4 to 4\u2009+\u2009a4\u2009=\u20098. Thus in circle it still remains at 4. "}, "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b"} {"nl": {"description": "Nastya received a gift on New Year\u00a0\u2014 a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k\u2009+\u20091 months.Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109\u2009+\u20097, because it is easy to see that it is always integer.", "input_spec": "The only line contains two integers x and k (0\u2009\u2264\u2009x,\u2009k\u2009\u2264\u20091018), where x is the initial number of dresses and k\u2009+\u20091 is the number of months in a year in Byteland.", "output_spec": "In the only line print a single integer\u00a0\u2014 the expected number of dresses Nastya will own one year later modulo 109\u2009+\u20097.", "sample_inputs": ["2 0", "2 1", "3 2"], "sample_outputs": ["4", "7", "21"], "notes": "NoteIn the first example a year consists on only one month, so the wardrobe does not eat dresses at all.In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6\u2009+\u20098)\u2009/\u20092\u2009=\u20097."}, "src_uid": "e0e017e8c8872fc1957242ace739464d"} {"nl": {"description": "Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n\u2009\u2265\u20092) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n\u2009=\u20096 then Funt has to pay 3 burles, while for n\u2009=\u200925 he needs to pay 5 and if n\u2009=\u20092 he pays only 1 burle.As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n1\u2009+\u2009n2\u2009+\u2009...\u2009+\u2009nk\u2009=\u2009n (here k is arbitrary, even k\u2009=\u20091 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition ni\u2009\u2265\u20092 should hold for all i from 1 to k.Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.", "input_spec": "The first line of the input contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7109)\u00a0\u2014 the total year income of mr. Funt.", "output_spec": "Print one integer\u00a0\u2014 minimum possible number of burles that mr. Funt has to pay as a tax.", "sample_inputs": ["4", "27"], "sample_outputs": ["2", "3"], "notes": null}, "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b"} {"nl": {"description": "Baby Ehab was toying around with arrays. He has an array $$$a$$$ of length $$$n$$$. He defines an array to be good if there's no way to partition it into $$$2$$$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $$$a$$$ so that it becomes a good array. Can you help him?A sequence $$$b$$$ is a subsequence of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $$$2$$$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.", "input_spec": "The first line contains an integer $$$n$$$ ($$$2 \\le n \\le 100$$$)\u00a0\u2014 the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\\ldots$$$, $$$a_{n}$$$ ($$$1 \\le a_i \\le 2000$$$)\u00a0\u2014 the elements of the array $$$a$$$.", "output_spec": "The first line should contain the minimum number of elements you need to remove. The second line should contain the indices of the elements you're removing, separated by spaces. We can show that an answer always exists. If there are multiple solutions, you can print any.", "sample_inputs": ["4\n6 3 9 12", "2\n1 2"], "sample_outputs": ["1\n2", "0"], "notes": "NoteIn the first example, you can partition the array into $$$[6,9]$$$ and $$$[3,12]$$$, so you must remove at least $$$1$$$ element. Removing $$$3$$$ is sufficient.In the second example, the array is already good, so you don't need to remove any elements."}, "src_uid": "29063ad54712b4911c6bf871969ee147"} {"nl": {"description": "Consider the infinite sequence of integers: 1,\u20091,\u20092,\u20091,\u20092,\u20093,\u20091,\u20092,\u20093,\u20094,\u20091,\u20092,\u20093,\u20094,\u20095.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).Find the number on the n-th position of the sequence.", "input_spec": "The only line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091014) \u2014 the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "output_spec": "Print the element in the n-th position of the sequence (the elements are numerated from one).", "sample_inputs": ["3", "5", "10", "55", "56"], "sample_outputs": ["2", "2", "4", "10", "1"], "notes": null}, "src_uid": "1db5631847085815461c617854b08ee5"} {"nl": {"description": "Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x1,\u2009x2,\u2009x3 and three more integers y1,\u2009y2,\u2009y3, such that x1\u2009<\u2009x2\u2009<\u2009x3, y1\u2009<\u2009y2\u2009<\u2009y3 and the eight point set consists of all points (xi,\u2009yj) (1\u2009\u2264\u2009i,\u2009j\u2009\u2264\u20093), except for point (x2,\u2009y2).You have a set of eight points. Find out if Gerald can use this set?", "input_spec": "The input consists of eight lines, the i-th line contains two space-separated integers xi and yi (0\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009106). You do not have any other conditions for these points.", "output_spec": "In a single line print word \"respectable\", if the given set of points corresponds to Gerald's decency rules, and \"ugly\" otherwise.", "sample_inputs": ["0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2"], "sample_outputs": ["respectable", "ugly", "ugly"], "notes": null}, "src_uid": "f3c96123334534056f26b96f90886807"} {"nl": {"description": "You are given a sequence of integers $$$a_1, a_2, \\dots, a_n$$$. You need to paint elements in colors, so that: If we consider any color, all elements of this color must be divisible by the minimal element of this color. The number of used colors must be minimized. For example, it's fine to paint elements $$$[40, 10, 60]$$$ in a single color, because they are all divisible by $$$10$$$. You can use any color an arbitrary amount of times (in particular, it is allowed to use a color only once). The elements painted in one color do not need to be consecutive.For example, if $$$a=[6, 2, 3, 4, 12]$$$ then two colors are required: let's paint $$$6$$$, $$$3$$$ and $$$12$$$ in the first color ($$$6$$$, $$$3$$$ and $$$12$$$ are divisible by $$$3$$$) and paint $$$2$$$ and $$$4$$$ in the second color ($$$2$$$ and $$$4$$$ are divisible by $$$2$$$). For example, if $$$a=[10, 7, 15]$$$ then $$$3$$$ colors are required (we can simply paint each element in an unique color).", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$), where $$$n$$$ is the length of the given sequence. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$). These numbers can contain duplicates.", "output_spec": "Print the minimal number of colors to paint all the given numbers in a valid way.", "sample_inputs": ["6\n10 2 3 5 4 2", "4\n100 100 100 100", "8\n7 6 5 4 3 2 2 3"], "sample_outputs": ["3", "1", "4"], "notes": "NoteIn the first example, one possible way to paint the elements in $$$3$$$ colors is: paint in the first color the elements: $$$a_1=10$$$ and $$$a_4=5$$$, paint in the second color the element $$$a_3=3$$$, paint in the third color the elements: $$$a_2=2$$$, $$$a_5=4$$$ and $$$a_6=2$$$. In the second example, you can use one color to paint all the elements.In the third example, one possible way to paint the elements in $$$4$$$ colors is: paint in the first color the elements: $$$a_4=4$$$, $$$a_6=2$$$ and $$$a_7=2$$$, paint in the second color the elements: $$$a_2=6$$$, $$$a_5=3$$$ and $$$a_8=3$$$, paint in the third color the element $$$a_3=5$$$, paint in the fourth color the element $$$a_1=7$$$. "}, "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"} {"nl": {"description": "One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:\u2014Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.\u2014No problem! \u2014 said Bob and immediately gave her an answer.Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.", "input_spec": "The first line contains one integer n (0\u2009\u2264\u2009n\u2009\u2264\u2009109) without leading zeroes. The second lines contains one integer m (0\u2009\u2264\u2009m\u2009\u2264\u2009109) \u2014 Bob's answer, possibly with leading zeroes.", "output_spec": "Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.", "sample_inputs": ["3310\n1033", "4\n5"], "sample_outputs": ["OK", "WRONG_ANSWER"], "notes": null}, "src_uid": "d1e381b72a6c09a0723cfe72c0917372"} {"nl": {"description": "Recently Vasya found a golden ticket \u2014 a sequence which consists of $$$n$$$ digits $$$a_1a_2\\dots a_n$$$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $$$350178$$$ is lucky since it can be divided into three segments $$$350$$$, $$$17$$$ and $$$8$$$: $$$3+5+0=1+7=8$$$. Note that each digit of sequence should belong to exactly one segment.Help Vasya! Tell him if the golden ticket he found is lucky or not.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of digits in the ticket. The second line contains $$$n$$$ digits $$$a_1 a_2 \\dots a_n$$$ ($$$0 \\le a_i \\le 9$$$) \u2014 the golden ticket. Digits are printed without spaces.", "output_spec": "If the golden ticket is lucky then print \"YES\", otherwise print \"NO\" (both case insensitive).", "sample_inputs": ["5\n73452", "4\n1248"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example the ticket can be divided into $$$7$$$, $$$34$$$ and $$$52$$$: $$$7=3+4=5+2$$$.In the second example it is impossible to divide ticket into segments with equal sum."}, "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"nl": {"description": "Right now she actually isn't. But she will be, if you don't solve this problem.You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7109). The second line contains a single integer k (1\u2009\u2264\u2009k\u2009\u2264\u20092\u00b7109). The third line contains a single integer A (1\u2009\u2264\u2009A\u2009\u2264\u20092\u00b7109). The fourth line contains a single integer B (1\u2009\u2264\u2009B\u2009\u2264\u20092\u00b7109).", "output_spec": "Output a single integer\u00a0\u2014 the minimum amount of coins you have to pay to make x equal to 1.", "sample_inputs": ["9\n2\n3\n1", "5\n5\n2\n20", "19\n3\n4\n2"], "sample_outputs": ["6", "8", "12"], "notes": "NoteIn the first testcase, the optimal strategy is as follows: Subtract 1 from x (9\u2009\u2192\u20098) paying 3 coins. Divide x by 2 (8\u2009\u2192\u20094) paying 1 coin. Divide x by 2 (4\u2009\u2192\u20092) paying 1 coin. Divide x by 2 (2\u2009\u2192\u20091) paying 1 coin. The total cost is 6 coins.In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total."}, "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"} {"nl": {"description": "In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40\u2009000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20\u2009000 kilometers.Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: \"North\", \"South\", \"West\", \"East\".Limak isn\u2019t sure whether the description is valid. You must help him to check the following conditions: If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. The journey must end on the North Pole. Check if the above conditions are satisfied and print \"YES\" or \"NO\" on a single line.", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950). The i-th of next n lines contains an integer ti and a string diri (1\u2009\u2264\u2009ti\u2009\u2264\u2009106, )\u00a0\u2014 the length and the direction of the i-th part of the journey, according to the description Limak got.", "output_spec": "Print \"YES\" if the description satisfies the three conditions, otherwise print \"NO\", both without the quotes.", "sample_inputs": ["5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "2\n15000 South\n4000 East", "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "3\n20000 South\n10 East\n20000 North", "2\n1000 North\n1000 South", "4\n50 South\n50 North\n15000 South\n15000 North"], "sample_outputs": ["YES", "NO", "YES", "NO", "NO", "YES"], "notes": "NoteDrawings below show how Limak's journey would look like in first two samples. In the second sample the answer is \"NO\" because he doesn't end on the North Pole. "}, "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"nl": {"description": "We consider a positive integer perfect, if and only if the sum of its digits is exactly $$$10$$$. Given a positive integer $$$k$$$, your task is to find the $$$k$$$-th smallest perfect positive integer.", "input_spec": "A single line with a positive integer $$$k$$$ ($$$1 \\leq k \\leq 10\\,000$$$).", "output_spec": "A single number, denoting the $$$k$$$-th smallest perfect integer.", "sample_inputs": ["1", "2"], "sample_outputs": ["19", "28"], "notes": "NoteThe first perfect integer is $$$19$$$ and the second one is $$$28$$$."}, "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"} {"nl": {"description": "Vus the Cossack holds a programming competition, in which $$$n$$$ people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly $$$m$$$ pens and $$$k$$$ notebooks.Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.", "input_spec": "The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \\leq n, m, k \\leq 100$$$)\u00a0\u2014 the number of participants, the number of pens, and the number of notebooks respectively.", "output_spec": "Print \"Yes\" if it possible to reward all the participants. Otherwise, print \"No\". You can print each letter in any case (upper or lower).", "sample_inputs": ["5 8 6", "3 9 3", "8 5 20"], "sample_outputs": ["Yes", "Yes", "No"], "notes": "NoteIn the first example, there are $$$5$$$ participants. The Cossack has $$$8$$$ pens and $$$6$$$ notebooks. Therefore, he has enough pens and notebooks.In the second example, there are $$$3$$$ participants. The Cossack has $$$9$$$ pens and $$$3$$$ notebooks. He has more than enough pens but only the minimum needed number of notebooks.In the third example, there are $$$8$$$ participants but only $$$5$$$ pens. Since the Cossack does not have enough pens, the answer is \"No\"."}, "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"} {"nl": {"description": "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_spec": "A single line contains one non-negative integer $$$n$$$ ($$$0 \\le n \\leq 10^{18}$$$)\u00a0\u2014 the number of Shiro's friends. The circular pizza has to be sliced into $$$n + 1$$$ pieces.", "output_spec": "A single integer\u00a0\u2014 the number of straight cuts Shiro needs.", "sample_inputs": ["3", "4"], "sample_outputs": ["2", "5"], "notes": "NoteTo 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."}, "src_uid": "236177ff30dafe68295b5d33dc501828"} {"nl": {"description": "Dawid has four bags of candies. The $$$i$$$-th of them contains $$$a_i$$$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?Note, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.", "input_spec": "The only line contains four integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$ and $$$a_4$$$ ($$$1 \\leq a_i \\leq 100$$$) \u2014 the numbers of candies in each bag.", "output_spec": "Output YES if it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).", "sample_inputs": ["1 7 11 5", "7 3 2 5"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive $$$12$$$ candies.In the second sample test, it's impossible to distribute the bags."}, "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"} {"nl": {"description": "Ilya is an experienced player in tic-tac-toe on the 4\u2009\u00d7\u20094 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4\u2009\u00d7\u20094 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).", "input_spec": "The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.", "output_spec": "Print single line: \"YES\" in case Ilya could have won by making single turn, and \"NO\" otherwise.", "sample_inputs": ["xx..\n.oo.\nx...\noox.", "x.ox\nox..\nx.o.\noo.x", "x..x\n..oo\no...\nx.xo", "o.x.\no...\n.x..\nooxx"], "sample_outputs": ["YES", "NO", "YES", "NO"], "notes": "NoteIn the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.In the second example it wasn't possible to win by making single turn.In the third example Ilya could have won by placing X in the last row between two existing Xs.In the fourth example it wasn't possible to win by making single turn."}, "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"nl": {"description": "Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1\u2009=\u2009a), and the difference between any two neighbouring elements is equal to c (si\u2009-\u2009si\u2009-\u20091\u2009=\u2009c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si\u2009=\u2009b. Of course, you are the person he asks for a help.", "input_spec": "The first line of the input contain three integers a, b and c (\u2009-\u2009109\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u2009109)\u00a0\u2014 the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.", "output_spec": "If b appears in the sequence s print \"YES\" (without quotes), otherwise print \"NO\" (without quotes).", "sample_inputs": ["1 7 3", "10 10 0", "1 -4 5", "0 60 50"], "sample_outputs": ["YES", "YES", "NO", "NO"], "notes": "NoteIn the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.In the third sample all elements of the sequence are greater than Vasya's favorite integer.In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer."}, "src_uid": "9edf42c20ddf22a251b84553d7305a7d"} {"nl": {"description": "You are given a text of single-space separated words, consisting of small and capital Latin letters.Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.Calculate the volume of the given text.", "input_spec": "The first line contains one integer number n (1\u2009\u2264\u2009n\u2009\u2264\u2009200) \u2014 length of the text. The second line contains text of single-space separated words s1,\u2009s2,\u2009...,\u2009si, consisting only of small and capital Latin letters.", "output_spec": "Print one integer number \u2014 volume of text.", "sample_inputs": ["7\nNonZERO", "24\nthis is zero answer text", "24\nHarbour Space University"], "sample_outputs": ["5", "0", "1"], "notes": "NoteIn the first example there is only one word, there are 5 capital letters in it.In the second example all of the words contain 0 capital letters."}, "src_uid": "d3929a9acf1633475ab16f5dfbead13c"} {"nl": {"description": "Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n\u2009\u00d7\u2009m chessboard, a very tasty candy and two numbers a and b.Dima put the chessboard in front of Inna and placed the candy in position (i,\u2009j) on the board. The boy said he would give the candy if it reaches one of the corner cells of the board. He's got one more condition. There can only be actions of the following types: move the candy from position (x,\u2009y) on the board to position (x\u2009-\u2009a,\u2009y\u2009-\u2009b); move the candy from position (x,\u2009y) on the board to position (x\u2009+\u2009a,\u2009y\u2009-\u2009b); move the candy from position (x,\u2009y) on the board to position (x\u2009-\u2009a,\u2009y\u2009+\u2009b); move the candy from position (x,\u2009y) on the board to position (x\u2009+\u2009a,\u2009y\u2009+\u2009b). Naturally, Dima doesn't allow to move the candy beyond the chessboard borders.Inna and the pony started shifting the candy around the board. They wonder what is the minimum number of allowed actions that they need to perform to move the candy from the initial position (i,\u2009j) to one of the chessboard corners. Help them cope with the task! ", "input_spec": "The first line of the input contains six integers n,\u2009m,\u2009i,\u2009j,\u2009a,\u2009b (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009106;\u00a01\u2009\u2264\u2009i\u2009\u2264\u2009n;\u00a01\u2009\u2264\u2009j\u2009\u2264\u2009m;\u00a01\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009106). You can assume that the chessboard rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. Position (i,\u2009j) in the statement is a chessboard cell on the intersection of the i-th row and the j-th column. You can consider that the corners are: (1,\u2009m), (n,\u20091), (n,\u2009m), (1,\u20091).", "output_spec": "In a single line print a single integer \u2014 the minimum number of moves needed to get the candy. If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line \"Poor Inna and pony!\" without the quotes.", "sample_inputs": ["5 7 1 3 2 2", "5 5 2 3 1 1"], "sample_outputs": ["2", "Poor Inna and pony!"], "notes": "NoteNote to sample 1:Inna and the pony can move the candy to position (1\u2009+\u20092,\u20093\u2009+\u20092)\u2009=\u2009(3,\u20095), from there they can move it to positions (3\u2009-\u20092,\u20095\u2009+\u20092)\u2009=\u2009(1,\u20097) and (3\u2009+\u20092,\u20095\u2009+\u20092)\u2009=\u2009(5,\u20097). These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two."}, "src_uid": "51155e9bfa90e0ff29d049cedc3e1862"} {"nl": {"description": "A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).Consider a permutation $$$p$$$ of length $$$n$$$, we build a graph of size $$$n$$$ using it as follows: For every $$$1 \\leq i \\leq n$$$, find the largest $$$j$$$ such that $$$1 \\leq j < i$$$ and $$$p_j > p_i$$$, and add an undirected edge between node $$$i$$$ and node $$$j$$$ For every $$$1 \\leq i \\leq n$$$, find the smallest $$$j$$$ such that $$$i < j \\leq n$$$ and $$$p_j > p_i$$$, and add an undirected edge between node $$$i$$$ and node $$$j$$$ In cases where no such $$$j$$$ exists, we make no edges. Also, note that we make edges between the corresponding indices, not the values at those indices.For clarity, consider as an example $$$n = 4$$$, and $$$p = [3,1,4,2]$$$; here, the edges of the graph are $$$(1,3),(2,1),(2,3),(4,3)$$$.A permutation $$$p$$$ is cyclic if the graph built using $$$p$$$ has at least one simple cycle. Given $$$n$$$, find the number of cyclic permutations of length $$$n$$$. Since the number may be very large, output it modulo $$$10^9+7$$$.Please refer to the Notes section for the formal definition of a simple cycle", "input_spec": "The first and only line contains a single integer $$$n$$$ ($$$3 \\le n \\le 10^6$$$).", "output_spec": "Output a single integer $$$0 \\leq x < 10^9+7$$$, the number of cyclic permutations of length $$$n$$$ modulo $$$10^9+7$$$.", "sample_inputs": ["4", "583291"], "sample_outputs": ["16", "135712853"], "notes": "NoteThere are $$$16$$$ cyclic permutations for $$$n = 4$$$. $$$[4,2,1,3]$$$ is one such permutation, having a cycle of length four: $$$4 \\rightarrow 3 \\rightarrow 2 \\rightarrow 1 \\rightarrow 4$$$.Nodes $$$v_1$$$, $$$v_2$$$, $$$\\ldots$$$, $$$v_k$$$ form a simple cycle if the following conditions hold: $$$k \\geq 3$$$. $$$v_i \\neq v_j$$$ for any pair of indices $$$i$$$ and $$$j$$$. ($$$1 \\leq i < j \\leq k$$$) $$$v_i$$$ and $$$v_{i+1}$$$ share an edge for all $$$i$$$ ($$$1 \\leq i < k$$$), and $$$v_1$$$ and $$$v_k$$$ share an edge. "}, "src_uid": "3dc1ee09016a25421ae371fa8005fce1"} {"nl": {"description": "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\u00a0\u2014 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 a1,\u2009a2,\u2009...,\u2009am is defined as the bitwise XOR of all its elements: , here 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_spec": "The sole string contains two integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u20091018).", "output_spec": "Output one number\u00a0\u2014 the largest possible xor-sum.", "sample_inputs": ["4 3", "6 6"], "sample_outputs": ["7", "7"], "notes": "NoteIn 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."}, "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"} {"nl": {"description": "Alice has a string $$$s$$$. She really likes the letter \"a\". She calls a string good if strictly more than half of the characters in that string are \"a\"s. For example \"aaabb\", \"axaa\" are good strings, and \"baca\", \"awwwa\", \"\" (empty string) are not.Alice can erase some characters from her string $$$s$$$. She would like to know what is the longest string remaining after erasing some characters (possibly zero) to get a good string. It is guaranteed that the string has at least one \"a\" in it, so the answer always exists.", "input_spec": "The first line contains a string $$$s$$$ ($$$1 \\leq |s| \\leq 50$$$) consisting of lowercase English letters. It is guaranteed that there is at least one \"a\" in $$$s$$$.", "output_spec": "Print a single integer, the length of the longest good string that Alice can get after erasing some characters from $$$s$$$.", "sample_inputs": ["xaxxxxa", "aaabaa"], "sample_outputs": ["3", "6"], "notes": "NoteIn the first example, it's enough to erase any four of the \"x\"s. The answer is $$$3$$$ since that is the maximum number of characters that can remain.In the second example, we don't need to erase any characters."}, "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"} {"nl": {"description": " It's the end of July\u00a0\u2013 the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.", "input_spec": "Two integers are given in the first string: the number of guests n and the number of guards k (1\u2009\u2264\u2009n\u2009\u2264\u2009106, 1\u2009\u2264\u2009k\u2009\u2264\u200926). In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.", "output_spec": "Output \u00abYES\u00bb if at least one door was unguarded during some time, and \u00abNO\u00bb otherwise. You can output each letter in arbitrary case (upper or lower).", "sample_inputs": ["5 1\nAABBB", "5 1\nABABB"], "sample_outputs": ["NO", "YES"], "notes": "NoteIn the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. "}, "src_uid": "216323563f5b2dd63edc30cb9b4849a5"} {"nl": {"description": "Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?See notes for definition of a tandem repeat.", "input_spec": "The first line contains s (1\u2009\u2264\u2009|s|\u2009\u2264\u2009200). This string contains only small English letters. The second line contains number k (1\u2009\u2264\u2009k\u2009\u2264\u2009200) \u2014 the number of the added characters.", "output_spec": "Print a single number \u2014 the maximum length of the tandem repeat that could have occurred in the new string.", "sample_inputs": ["aaba\n2", "aaabbbb\n2", "abracadabra\n10"], "sample_outputs": ["6", "6", "20"], "notes": "NoteA tandem repeat of length 2n is string s, where for any position i (1\u2009\u2264\u2009i\u2009\u2264\u2009n) the following condition fulfills: si\u2009=\u2009si\u2009+\u2009n.In the first sample Kolya could obtain a string aabaab, in the second \u2014 aaabbbbbb, in the third \u2014 abracadabrabracadabra."}, "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab"} {"nl": {"description": "Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.", "input_spec": "In the only line given a non-empty binary string s with length up to 100.", "output_spec": "Print \u00abyes\u00bb (without quotes) if it's possible to remove digits required way and \u00abno\u00bb otherwise.", "sample_inputs": ["100010001", "100"], "sample_outputs": ["yes", "no"], "notes": "NoteIn the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.You can read more about binary numeral system representation here: https://en.wikipedia.org/wiki/Binary_system"}, "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"nl": {"description": "You are given an array of $$$n$$$ integers: $$$a_1, a_2, \\ldots, a_n$$$. Your task is to find some non-zero integer $$$d$$$ ($$$-10^3 \\leq d \\leq 10^3$$$) such that, after each number in the array is divided by $$$d$$$, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least $$$\\lceil\\frac{n}{2}\\rceil$$$). Note that those positive numbers do not need to be an integer (e.g., a $$$2.5$$$ counts as a positive number). If there are multiple values of $$$d$$$ that satisfy the condition, you may print any of them. In case that there is no such $$$d$$$, print a single integer $$$0$$$.Recall that $$$\\lceil x \\rceil$$$ represents the smallest integer that is not less than $$$x$$$ and that zero ($$$0$$$) is neither positive nor negative.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of elements in the array. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$-10^3 \\le a_i \\le 10^3$$$).", "output_spec": "Print one integer $$$d$$$ ($$$-10^3 \\leq d \\leq 10^3$$$ and $$$d \\neq 0$$$) that satisfies the given condition. If there are multiple values of $$$d$$$ that satisfy the condition, you may print any of them. In case that there is no such $$$d$$$, print a single integer $$$0$$$.", "sample_inputs": ["5\n10 0 -7 2 6", "7\n0 0 1 -1 0 0 2"], "sample_outputs": ["4", "0"], "notes": "NoteIn the first sample, $$$n = 5$$$, so we need at least $$$\\lceil\\frac{5}{2}\\rceil = 3$$$ positive numbers after division. If $$$d = 4$$$, the array after division is $$$[2.5, 0, -1.75, 0.5, 1.5]$$$, in which there are $$$3$$$ positive numbers (namely: $$$2.5$$$, $$$0.5$$$, and $$$1.5$$$).In the second sample, there is no valid $$$d$$$, so $$$0$$$ should be printed."}, "src_uid": "a13cb35197f896cd34614c6c0b369a49"} {"nl": {"description": "You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.", "input_spec": "The first contains three single positive integers a, b, c (1\u2009\u2264\u2009a\u2009<\u2009b\u2009\u2264\u2009105, 0\u2009\u2264\u2009c\u2009\u2264\u20099).", "output_spec": "Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.", "sample_inputs": ["1 2 0", "2 3 7"], "sample_outputs": ["2", "-1"], "notes": "NoteThe fraction in the first example has the following decimal notation: . The first zero stands on second position.The fraction in the second example has the following decimal notation: . There is no digit 7 in decimal notation of the fraction. "}, "src_uid": "0bc7bf67b96e2898cfd8d129ad486910"} {"nl": {"description": "Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a \"war\"-like card game. The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins. You have to calculate how many fights will happen and who will win the game, or state that game won't end.", "input_spec": "First line contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u200910), the number of cards. Second line contains integer k1 (1\u2009\u2264\u2009k1\u2009\u2264\u2009n\u2009-\u20091), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack. Third line contains integer k2 (k1\u2009+\u2009k2\u2009=\u2009n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack. All card values are different.", "output_spec": "If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won. If the game won't end and will continue forever output \u2009-\u20091.", "sample_inputs": ["4\n2 1 3\n2 4 2", "3\n1 2\n2 1 3"], "sample_outputs": ["6 2", "-1"], "notes": "NoteFirst sample: Second sample: "}, "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"nl": {"description": "You are given two integer numbers, $$$n$$$ and $$$x$$$. You may perform several operations with the integer $$$x$$$.Each operation you perform is the following one: choose any digit $$$y$$$ that occurs in the decimal representation of $$$x$$$ at least once, and replace $$$x$$$ by $$$x \\cdot y$$$.You want to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$. What is the minimum number of operations required to do that?", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$x$$$ ($$$2 \\le n \\le 19$$$; $$$1 \\le x < 10^{n-1}$$$).", "output_spec": "Print one integer \u2014 the minimum number of operations required to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$, or $$$-1$$$ if it is impossible.", "sample_inputs": ["2 1", "3 2", "13 42"], "sample_outputs": ["-1", "4", "12"], "notes": "NoteIn the second example, the following sequence of operations achieves the goal: multiply $$$x$$$ by $$$2$$$, so $$$x = 2 \\cdot 2 = 4$$$; multiply $$$x$$$ by $$$4$$$, so $$$x = 4 \\cdot 4 = 16$$$; multiply $$$x$$$ by $$$6$$$, so $$$x = 16 \\cdot 6 = 96$$$; multiply $$$x$$$ by $$$9$$$, so $$$x = 96 \\cdot 9 = 864$$$. "}, "src_uid": "cedcc3cee864bf8684148df93804d029"} {"nl": {"description": "Baby Badawy's first words were \"AND 0 SUM BIG\", so he decided to solve the following problem. Given two integers $$$n$$$ and $$$k$$$, count the number of arrays of length $$$n$$$ such that: all its elements are integers between $$$0$$$ and $$$2^k-1$$$ (inclusive); the bitwise AND of all its elements is $$$0$$$; the sum of its elements is as large as possible. Since the answer can be very large, print its remainder when divided by $$$10^9+7$$$.", "input_spec": "The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 10$$$)\u00a0\u2014 the number of test cases you need to solve. Each test case consists of a line containing two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 10^{5}$$$, $$$1 \\le k \\le 20$$$).", "output_spec": "For each test case, print the number of arrays satisfying the conditions. Since the answer can be very large, print its remainder when divided by $$$10^9+7$$$.", "sample_inputs": ["2\n2 2\n100000 20"], "sample_outputs": ["4\n226732710"], "notes": "NoteIn the first example, the $$$4$$$ arrays are: $$$[3,0]$$$, $$$[0,3]$$$, $$$[1,2]$$$, $$$[2,1]$$$. "}, "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"nl": {"description": "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_spec": "Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi (\u2009-\u2009109\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009109)\u00a0\u2014 the coordinates of the i-th point. It is guaranteed that all points are distinct.", "output_spec": "Print a single number\u00a0\u2014 the minimum possible number of segments of the polyline.", "sample_inputs": ["1 -1\n1 1\n1 2", "-1 -1\n-1 3\n4 3", "1 1\n2 3\n3 2"], "sample_outputs": ["1", "2", "3"], "notes": "NoteThe variant of the polyline in the first sample: The variant of the polyline in the second sample: The variant of the polyline in the third sample: "}, "src_uid": "36fe960550e59b046202b5811343590d"} {"nl": {"description": "It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.The bus stop queue has n groups of people. The i-th group from the beginning has ai people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100). The next line contains n integers: a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009m).", "output_spec": "Print a single integer \u2014 the number of buses that is needed to transport all n groups to the dacha countryside.", "sample_inputs": ["4 3\n2 3 2 1", "3 4\n1 2 1"], "sample_outputs": ["3", "1"], "notes": null}, "src_uid": "5c73d6e3770dff034d210cdd572ccf0f"} {"nl": {"description": "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_spec": "The first and only line contains an integer $$$r$$$ ($$$1 \\le r \\le 10^{12}$$$).", "output_spec": "Output integers $$$x, y$$$ such that $$$H(x,y) = r$$$ and $$$x$$$ is smallest possible, or \"NO\" if no such pair exists.", "sample_inputs": ["19", "16"], "sample_outputs": ["1 8", "NO"], "notes": null}, "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba"} {"nl": {"description": "Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named \u00abPawnChess\u00bb.This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed. Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r,\u2009c) the cell located at the row r and at the column c.There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.Moving upward means that the pawn located in (r,\u2009c) will go to the cell (r\u2009-\u20091,\u2009c), while moving down means the pawn located in (r,\u2009c) will go to the cell (r\u2009+\u20091,\u2009c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.", "input_spec": "The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'. It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.", "output_spec": "Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.", "sample_inputs": ["........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........", "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........"], "sample_outputs": ["A", "B"], "notes": "NoteIn the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4,\u20095). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner."}, "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"} {"nl": {"description": "I have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two incident edges. For each pair of nodes, there is at most an edge connecting them. No edge connects a node to itself.I would like to create a new graph in such a way that: The new graph consists of the same number of nodes and edges as the old graph. The properties in the first paragraph still hold. For each two nodes u and v, if there is an edge connecting them in the old graph, there is no edge connecting them in the new graph. Help me construct the new graph, or tell me if it is impossible.", "input_spec": "The first line consists of two space-separated integers: n and m (1\u2009\u2264\u2009m\u2009\u2264\u2009n\u2009\u2264\u2009105), denoting the number of nodes and edges, respectively. Then m lines follow. Each of the m lines consists of two space-separated integers u and v (1\u2009\u2264\u2009u,\u2009v\u2009\u2264\u2009n;\u00a0u\u2009\u2260\u2009v), denoting an edge between nodes u and v.", "output_spec": "If it is not possible to construct a new graph with the mentioned properties, output a single line consisting of -1. Otherwise, output exactly m lines. Each line should contain a description of edge in the same way as used in the input format.", "sample_inputs": ["8 7\n1 2\n2 3\n4 5\n5 6\n6 8\n8 7\n7 4", "3 2\n1 2\n2 3", "5 4\n1 2\n2 3\n3 4\n4 1"], "sample_outputs": ["1 4\n4 6\n1 6\n2 7\n7 5\n8 5\n2 8", "-1", "1 3\n3 5\n5 2\n2 4"], "notes": "NoteThe old graph of the first example:A possible new graph for the first example:In the second example, we cannot create any new graph.The old graph of the third example:A possible new graph for the third example:"}, "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5"} {"nl": {"description": "Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points t minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.", "input_spec": "The first line contains four integers a, b, c, d (250\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20093500, 0\u2009\u2264\u2009c,\u2009d\u2009\u2264\u2009180). It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).", "output_spec": "Output on a single line: \"Misha\" (without the quotes), if Misha got more points than Vasya. \"Vasya\" (without the quotes), if Vasya got more points than Misha. \"Tie\" (without the quotes), if both of them got the same number of points.", "sample_inputs": ["500 1000 20 30", "1000 1000 1 1", "1500 1000 176 177"], "sample_outputs": ["Vasya", "Tie", "Misha"], "notes": null}, "src_uid": "95b19d7569d6b70bd97d46a8541060d0"} {"nl": {"description": "There is the faculty of Computer Science in Berland. In the social net \"TheContact!\" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x \u2014 some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance.", "input_spec": "The first line contains the positive odd integer n (1\u2009\u2264\u2009n\u2009\u2264\u20095) \u2014 the number of groups which Igor joined. The next line contains n distinct integers a1,\u2009a2,\u2009...,\u2009an (2010\u2009\u2264\u2009ai\u2009\u2264\u20092100) \u2014 years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.", "output_spec": "Print the year of Igor's university entrance. ", "sample_inputs": ["3\n2014 2016 2015", "1\n2050"], "sample_outputs": ["2015", "2050"], "notes": "NoteIn the first test the value x\u2009=\u20091. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.In the second test the value x\u2009=\u20090. Igor entered only the group which corresponds to the year of his university entrance. "}, "src_uid": "f03773118cca29ff8d5b4281d39e7c63"} {"nl": {"description": "Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into k bacteria. After that some abnormal effects create b more bacteria in the test tube. Thus, if at the beginning of some second the test tube had x bacteria, then at the end of the second it will have kx\u2009+\u2009b bacteria.The experiment showed that after n seconds there were exactly z bacteria and the experiment ended at this point.For the second experiment Qwerty is going to sterilize the test tube and put there t bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least z bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. Help Qwerty and find the minimum number of seconds needed to get a tube with at least z bacteria in the second experiment.", "input_spec": "The first line contains four space-separated integers k, b, n and t (1\u2009\u2264\u2009k,\u2009b,\u2009n,\u2009t\u2009\u2264\u2009106) \u2014 the parameters of bacterial growth, the time Qwerty needed to grow z bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.", "output_spec": "Print a single number \u2014 the minimum number of seconds Qwerty needs to grow at least z bacteria in the tube.", "sample_inputs": ["3 1 3 5", "1 4 4 7", "2 2 4 100"], "sample_outputs": ["2", "3", "0"], "notes": null}, "src_uid": "e2357a1f54757bce77dce625772e4f18"} {"nl": {"description": "Mishka got a six-faced dice. It has integer numbers from $$$2$$$ to $$$7$$$ written on its faces (all numbers on faces are different, so this is an almost usual dice).Mishka wants to get exactly $$$x$$$ points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly $$$x$$$ points for them. Mishka is very lucky, so if the probability to get $$$x$$$ points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.Mishka is also very curious about different number of points to score so you have to answer $$$t$$$ independent queries.", "input_spec": "The first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of queries. Each of the next $$$t$$$ lines contains one integer each. The $$$i$$$-th line contains one integer $$$x_i$$$ ($$$2 \\le x_i \\le 100$$$) \u2014 the number of points Mishka wants to get.", "output_spec": "Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query (i.e. any number of rolls Mishka can make to be able to get exactly $$$x_i$$$ points for them). It is guaranteed that at least one answer exists.", "sample_inputs": ["4\n2\n13\n37\n100"], "sample_outputs": ["1\n3\n8\n27"], "notes": "NoteIn the first query Mishka can roll a dice once and get $$$2$$$ points.In the second query Mishka can roll a dice $$$3$$$ times and get points $$$5$$$, $$$5$$$ and $$$3$$$ (for example).In the third query Mishka can roll a dice $$$8$$$ times and get $$$5$$$ points $$$7$$$ times and $$$2$$$ points with the remaining roll.In the fourth query Mishka can roll a dice $$$27$$$ times and get $$$2$$$ points $$$11$$$ times, $$$3$$$ points $$$6$$$ times and $$$6$$$ points $$$10$$$ times."}, "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"} {"nl": {"description": "Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?", "input_spec": "The first and only line contains two integers x and y (3\u2009\u2264\u2009y\u2009<\u2009x\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the starting and ending equilateral triangle side lengths respectively.", "output_spec": "Print a single integer\u00a0\u2014 the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.", "sample_inputs": ["6 3", "8 5", "22 4"], "sample_outputs": ["4", "3", "6"], "notes": "NoteIn the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a,\u2009b,\u2009c). Then, Memory can do .In the second sample test, Memory can do .In the third sample test, Memory can do: ."}, "src_uid": "8edf64f5838b19f9a8b19a14977f5615"} {"nl": {"description": "Petya has an array $$$a$$$ consisting of $$$n$$$ integers. He wants to remove duplicate (equal) elements.Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 50$$$) \u2014 the number of elements in Petya's array. The following line contains a sequence $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 1\\,000$$$) \u2014 the Petya's array.", "output_spec": "In the first line print integer $$$x$$$ \u2014 the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $$$x$$$ integers separated with a space \u2014 Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.", "sample_inputs": ["6\n1 5 5 1 6 1", "5\n2 4 2 4 4", "5\n6 6 6 6 6"], "sample_outputs": ["3\n5 6 1", "2\n2 4", "1\n6"], "notes": "NoteIn the first example you should remove two integers $$$1$$$, which are in the positions $$$1$$$ and $$$4$$$. Also you should remove the integer $$$5$$$, which is in the position $$$2$$$.In the second example you should remove integer $$$2$$$, which is in the position $$$1$$$, and two integers $$$4$$$, which are in the positions $$$2$$$ and $$$4$$$.In the third example you should remove four integers $$$6$$$, which are in the positions $$$1$$$, $$$2$$$, $$$3$$$ and $$$4$$$."}, "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"nl": {"description": "Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: \"Which integer type to use if one wants to store a positive integer n?\"Petya knows only 5 integer types:1) byte occupies 1 byte and allows you to store numbers from \u2009-\u2009128 to 1272) short occupies 2 bytes and allows you to store numbers from \u2009-\u200932768 to 327673) int occupies 4 bytes and allows you to store numbers from \u2009-\u20092147483648 to 21474836474) long occupies 8 bytes and allows you to store numbers from \u2009-\u20099223372036854775808 to 92233720368547758075) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.For all the types given above the boundary values are included in the value range.From this list, Petya wants to choose the smallest type that can store a positive integer n. Since BigInteger works much slower, Peter regards it last. Help him.", "input_spec": "The first line contains a positive number n. It consists of no more than 100 digits and doesn't contain any leading zeros. The number n can't be represented as an empty string. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).", "output_spec": "Print the first type from the list \"byte, short, int, long, BigInteger\", that can store the natural number n, in accordance with the data given above.", "sample_inputs": ["127", "130", "123456789101112131415161718192021222324"], "sample_outputs": ["byte", "short", "BigInteger"], "notes": null}, "src_uid": "33041f1832fa7f641e37c4c638ab08a1"} {"nl": {"description": "You are given a rectangular board of M\u2009\u00d7\u2009N squares. Also you are given an unlimited number of standard domino pieces of 2\u2009\u00d7\u20091 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:1. Each domino completely covers two squares.2. No two dominoes overlap.3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.Find the maximum number of dominoes, which can be placed under these restrictions.", "input_spec": "In a single line you are given two integers M and N \u2014 board sizes in squares (1\u2009\u2264\u2009M\u2009\u2264\u2009N\u2009\u2264\u200916).", "output_spec": "Output one number \u2014 the maximal number of dominoes, which can be placed.", "sample_inputs": ["2 4", "3 3"], "sample_outputs": ["4", "4"], "notes": null}, "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"} {"nl": {"description": "JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ of integers, such that $$$1 \\le a_1 < a_2 < \\ldots < a_n \\le 10^3$$$, and then went to the bathroom.JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range $$$[1, 10^3]$$$.JATC wonders what is the greatest number of elements he can erase?", "input_spec": "The first line of the input contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of elements in the array. The second line of the input contains $$$n$$$ integers $$$a_i$$$ ($$$1 \\le a_1<a_2<\\dots<a_n \\le 10^3$$$)\u00a0\u2014 the array written by Giraffe.", "output_spec": "Print a single integer\u00a0\u2014 the maximum number of consecutive elements in the array that JATC can erase. If it is impossible to erase even a single element, print $$$0$$$.", "sample_inputs": ["6\n1 3 4 5 6 9", "3\n998 999 1000", "5\n1 2 3 4 5"], "sample_outputs": ["2", "2", "4"], "notes": "NoteIn the first example, JATC can erase the third and fourth elements, leaving the array $$$[1, 3, \\_, \\_, 6, 9]$$$. As you can see, there is only one way to fill in the blanks.In the second example, JATC can erase the second and the third elements. The array will become $$$[998, \\_, \\_]$$$. Because all the elements are less than or equal to $$$1000$$$, the array is still can be restored. Note, that he can't erase the first $$$2$$$ elements.In the third example, JATC can erase the first $$$4$$$ elements. Since all the elements are greater than or equal to $$$1$$$, Giraffe can still restore the array. Note, that he can't erase the last $$$4$$$ elements."}, "src_uid": "858b5e75e21c4cba6d08f3f66be0c198"} {"nl": {"description": "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. The picture corresponds to the first example. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.", "input_spec": "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_spec": "Print single integer a\u00a0\u2014 the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.", "sample_inputs": ["ABABBBACFEYUKOTT", "AAA"], "sample_outputs": ["4", "1"], "notes": null}, "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"nl": {"description": "You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban \u2014 an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: Set the value of a digit equal to 0. If the go-dama is shifted to the right, add 5. Add the number of ichi-damas shifted to the left. Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720.Write the program that prints the way Soroban shows the given number n.", "input_spec": "The first line contains a single integer n (0\u2009\u2264\u2009n\u2009<\u2009109).", "output_spec": "Print the description of the decimal digits of number n from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number n without leading zeroes. We can assume that number 0 has no leading zeroes.", "sample_inputs": ["2", "13", "720"], "sample_outputs": ["O-|OO-OO", "O-|OOO-O\nO-|O-OOO", "O-|-OOOO\nO-|OO-OO\n-O|OO-OO"], "notes": null}, "src_uid": "c2e3aced0bc76b6484360563355d23a7"} {"nl": {"description": "Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure: if si = \"?\", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively); if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code; if the string contains letters from \"A\" to \"J\", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. The length of the safe code coincides with the length of the hint. For example, hint \"?JGJ9\" has such matching safe code variants: \"51919\", \"55959\", \"12329\", \"93539\" and so on, and has wrong variants such as: \"56669\", \"00111\", \"03539\" and \"13666\".After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show \"Beavers are on the trail\" on his favorite TV channel, or he should work for a sleepless night...", "input_spec": "The first line contains string s \u2014 the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): 1\u2009\u2264\u2009|s|\u2009\u2264\u20095. The input limits for scoring 100 points are (subproblems A1+A2): 1\u2009\u2264\u2009|s|\u2009\u2264\u2009105. Here |s| means the length of string s.", "output_spec": "Print the number of codes that match the given hint.", "sample_inputs": ["AJ", "1?AA"], "sample_outputs": ["81", "100"], "notes": null}, "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82"} {"nl": {"description": "As you have noticed, there are lovely girls in Arpa\u2019s land.People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows.The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: \"Oww...wwf\" (the letter w is repeated t times) and cuts off the phone immediately. If t\u2009>\u20091 then crushx calls crushcrushx and says: \"Oww...wwf\" (the letter w is repeated t\u2009-\u20091 times) and cuts off the phone immediately. The round continues until some person receives an \"Owf\" (t\u2009=\u20091). This person is called the Joon-Joon of the round. There can't be two rounds at the same time.Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t\u2009\u2265\u20091) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible.Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi\u2009=\u2009i).", "input_spec": "The first line of input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1\u2009\u2264\u2009crushi\u2009\u2264\u2009n)\u00a0\u2014 the number of i-th person's crush.", "output_spec": "If there is no t satisfying the condition, print -1. Otherwise print such smallest t.", "sample_inputs": ["4\n2 3 1 4", "4\n4 4 4 4", "4\n2 1 4 3"], "sample_outputs": ["3", "-1", "1"], "notes": "NoteIn the first sample suppose t\u2009=\u20093. If the first person starts some round:The first person calls the second person and says \"Owwwf\", then the second person calls the third person and says \"Owwf\", then the third person calls the first person and says \"Owf\", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1.The process is similar for the second and the third person.If the fourth person starts some round:The fourth person calls himself and says \"Owwwf\", then he calls himself again and says \"Owwf\", then he calls himself for another time and says \"Owf\", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4.In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa."}, "src_uid": "149221131a978298ac56b58438df46c9"} {"nl": {"description": "A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels. Your task is to determine the size of the rectangular display \u2014 the number of lines (rows) of pixels a and the number of columns of pixels b, so that: there are exactly n pixels on the display; the number of rows does not exceed the number of columns, it means a\u2009\u2264\u2009b; the difference b\u2009-\u2009a is as small as possible. ", "input_spec": "The first line contains the positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106)\u00a0\u2014 the number of pixels display should have.", "output_spec": "Print two integers\u00a0\u2014 the number of rows and columns on the display. ", "sample_inputs": ["8", "64", "5", "999999"], "sample_outputs": ["2 4", "8 8", "1 5", "999 1001"], "notes": "NoteIn the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels."}, "src_uid": "f52af273954798a4ae38a1378bfbf77a"} {"nl": {"description": "After passing a test, Vasya got himself a box of $$$n$$$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $$$k$$$, same for all days. After that, in the morning he eats $$$k$$$ candies from the box (if there are less than $$$k$$$ candies in the box, he eats them all), then in the evening Petya eats $$$10\\%$$$ of the candies remaining in the box. If there are still candies left in the box, the process repeats\u00a0\u2014 next day Vasya eats $$$k$$$ candies again, and Petya\u00a0\u2014 $$$10\\%$$$ of the candies left in a box, and so on.If the amount of candies in the box is not divisible by $$$10$$$, Petya rounds the amount he takes from the box down. For example, if there were $$$97$$$ candies in the box, Petya would eat only $$$9$$$ of them. In particular, if there are less than $$$10$$$ candies in a box, Petya won't eat any at all.Your task is to find out the minimal amount of $$$k$$$ that can be chosen by Vasya so that he would eat at least half of the $$$n$$$ candies he initially got. Note that the number $$$k$$$ must be integer.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^{18}$$$)\u00a0\u2014 the initial amount of candies in the box.", "output_spec": "Output a single integer\u00a0\u2014 the minimal amount of $$$k$$$ that would allow Vasya to eat at least half of candies he got.", "sample_inputs": ["68"], "sample_outputs": ["3"], "notes": "NoteIn the sample, the amount of candies, with $$$k=3$$$, would change in the following way (Vasya eats first):$$$68 \\to 65 \\to 59 \\to 56 \\to 51 \\to 48 \\to 44 \\to 41 \\\\ \\to 37 \\to 34 \\to 31 \\to 28 \\to 26 \\to 23 \\to 21 \\to 18 \\to 17 \\to 14 \\\\ \\to 13 \\to 10 \\to 9 \\to 6 \\to 6 \\to 3 \\to 3 \\to 0$$$.In total, Vasya would eat $$$39$$$ candies, while Petya\u00a0\u2014 $$$29$$$."}, "src_uid": "db1a50da538fa82038f8db6104d2ab93"} {"nl": {"description": "This morning, Roman woke up and opened the browser with $$$n$$$ opened tabs numbered from $$$1$$$ to $$$n$$$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.He decided to accomplish this by closing every $$$k$$$-th ($$$2 \\leq k \\leq n - 1$$$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $$$b$$$) and then close all tabs with numbers $$$c = b + i \\cdot k$$$ that satisfy the following condition: $$$1 \\leq c \\leq n$$$ and $$$i$$$ is an integer (it may be positive, negative or zero).For example, if $$$k = 3$$$, $$$n = 14$$$ and Roman chooses $$$b = 8$$$, then he will close tabs with numbers $$$2$$$, $$$5$$$, $$$8$$$, $$$11$$$ and $$$14$$$.After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $$$e$$$) and the amount of remaining social network tabs ($$$s$$$). Help Roman to calculate the maximal absolute value of the difference of those values $$$|e - s|$$$ so that it would be easy to decide what to do next.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\leq k < n \\leq 100$$$) \u2014 the amount of tabs opened currently and the distance between the tabs closed. The second line consists of $$$n$$$ integers, each of them equal either to $$$1$$$ or to $$$-1$$$. The $$$i$$$-th integer denotes the type of the $$$i$$$-th tab: if it is equal to $$$1$$$, this tab contains information for the test, and if it is equal to $$$-1$$$, it's a social network tab.", "output_spec": "Output a single integer \u2014 the maximum absolute difference between the amounts of remaining tabs of different types $$$|e - s|$$$.", "sample_inputs": ["4 2\n1 1 -1 1", "14 3\n-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1"], "sample_outputs": ["2", "9"], "notes": "NoteIn the first example we can choose $$$b = 1$$$ or $$$b = 3$$$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $$$e = 2$$$ and $$$s = 0$$$ and $$$|e - s| = 2$$$.In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them."}, "src_uid": "6119258322e06fa6146e592c63313df3"} {"nl": {"description": "You are given a string q. A sequence of k strings s1,\u2009s2,\u2009...,\u2009sk is called beautiful, if the concatenation of these strings is string q (formally, s1\u2009+\u2009s2\u2009+\u2009...\u2009+\u2009sk\u2009=\u2009q) and the first characters of these strings are distinct.Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist.", "input_spec": "The first line contains a positive integer k (1\u2009\u2264\u2009k\u2009\u2264\u200926) \u2014 the number of strings that should be in a beautiful sequence. The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive.", "output_spec": "If such sequence doesn't exist, then print in a single line \"NO\" (without the quotes). Otherwise, print in the first line \"YES\" (without the quotes) and in the next k lines print the beautiful sequence of strings s1,\u2009s2,\u2009...,\u2009sk. If there are multiple possible answers, print any of them.", "sample_inputs": ["1\nabca", "2\naaacas", "4\nabc"], "sample_outputs": ["YES\nabca", "YES\naaa\ncas", "NO"], "notes": "NoteIn the second sample there are two possible answers: {\"aaaca\",\u2009\"s\"} and {\"aaa\",\u2009\"cas\"}."}, "src_uid": "c1b071f09ef375f19031ce99d10e90ab"} {"nl": {"description": "Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face.One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget \u2014 a rotating camera \u2014 come up to it to see it better, look into it. And the camera takes their photo at that time. What could be better for high quality identification?But not everything is so simple. The pictures from camera appear rotated too (on clockwise camera rotation frame the content becomes rotated counter-clockwise). But the identification algorithm can work only with faces that are just slightly deviated from vertical.Vasya was entrusted to correct the situation \u2014 to rotate a captured image so that image would be minimally deviated from vertical. Requirements were severe. Firstly, the picture should be rotated only on angle divisible by 90 degrees to not lose a bit of information about the image. Secondly, the frames from the camera are so huge and FPS is so big that adequate rotation speed is provided by hardware FPGA solution only. And this solution can rotate only by 90 degrees clockwise. Of course, one can apply 90 degrees turn several times but for the sake of performance the number of turns should be minimized.Help Vasya implement the program that by the given rotation angle of the camera can determine the minimum number of 90 degrees clockwise turns necessary to get a picture in which up direction deviation from vertical is minimum.The next figure contains frames taken from an unrotated camera, then from rotated 90 degrees clockwise, then from rotated 90 degrees counter-clockwise. Arrows show direction to \"true up\". The next figure shows 90 degrees clockwise turn by FPGA hardware. ", "input_spec": "The only line of the input contains one integer x (\u2009-\u20091018\u2009\u2264\u2009x\u2009\u2264\u20091018) \u2014 camera angle in degrees. Positive value denotes clockwise camera rotation, negative \u2014 counter-clockwise.", "output_spec": "Output one integer \u2014 the minimum required number of 90 degrees clockwise turns.", "sample_inputs": ["60", "-60"], "sample_outputs": ["1", "3"], "notes": "NoteWhen the camera is rotated 60 degrees counter-clockwise (the second example), an image from it is rotated 60 degrees clockwise. One 90 degrees clockwise turn of the image result in 150 degrees clockwise total rotation and deviation from \"true up\" for one turn is 150 degrees. Two 90 degrees clockwise turns of the image result in 240 degrees clockwise total rotation and deviation from \"true up\" for two turns is 120 degrees because 240 degrees clockwise equal to 120 degrees counter-clockwise. Three 90 degrees clockwise turns of the image result in 330 degrees clockwise total rotation and deviation from \"true up\" for three turns is 30 degrees because 330 degrees clockwise equal to 30 degrees counter-clockwise.From 60, 150, 120 and 30 degrees deviations the smallest is 30, and it it achieved in three 90 degrees clockwise turns."}, "src_uid": "509db9cb6156b692557ba874a09f150e"} {"nl": {"description": "You are given a chessboard of size 1\u2009\u00d7\u2009n. It is guaranteed that n is even. The chessboard is painted like this: \"BWBW...BW\".Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).", "input_spec": "The first line of the input contains one integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100, n is even) \u2014 the size of the chessboard. The second line of the input contains integer numbers (1\u2009\u2264\u2009pi\u2009\u2264\u2009n) \u2014 initial positions of the pieces. It is guaranteed that all the positions are distinct.", "output_spec": "Print one integer \u2014 the minimum number of moves you have to make to place all the pieces in the cells of the same color.", "sample_inputs": ["6\n1 2 6", "10\n1 2 3 4 5"], "sample_outputs": ["2", "10"], "notes": "NoteIn the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.In the second example the possible strategy is to move in 4 moves, then in 3 moves, in 2 moves and in 1 move."}, "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"nl": {"description": "Imp likes his plush toy a lot. 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_spec": "The only line contains two integers x and y (0\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009109)\u00a0\u2014 the number of copies and the number of original toys Imp wants to get (including the initial one).", "output_spec": "Print \"Yes\", if the desired configuration is possible, and \"No\" otherwise. You can print each letter in arbitrary case (upper or lower).", "sample_inputs": ["6 3", "4 2", "1000 1001"], "sample_outputs": ["Yes", "No", "Yes"], "notes": "NoteIn the first example, Imp has to apply the machine twice to original toys and then twice to copies."}, "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"nl": {"description": "Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.There are $$$n$$$ kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.Also, there are $$$m$$$ boxes. All of them are for different people, so they are pairwise distinct (consider that the names of $$$m$$$ friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.Alice wants to pack presents with the following rules: She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of $$$n$$$ kinds, empty boxes are allowed); For each kind at least one present should be packed into some box. Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo $$$10^9+7$$$.See examples and their notes for clarification.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$, separated by spaces ($$$1 \\leq n,m \\leq 10^9$$$)\u00a0\u2014 the number of kinds of presents and the number of boxes that Alice has.", "output_spec": "Print one integer \u00a0\u2014 the number of ways to pack the presents with Alice's rules, calculated by modulo $$$10^9+7$$$", "sample_inputs": ["1 3", "2 2"], "sample_outputs": ["7", "9"], "notes": "NoteIn the first example, there are seven ways to pack presents:$$$\\{1\\}\\{\\}\\{\\}$$$$$$\\{\\}\\{1\\}\\{\\}$$$$$$\\{\\}\\{\\}\\{1\\}$$$$$$\\{1\\}\\{1\\}\\{\\}$$$$$$\\{\\}\\{1\\}\\{1\\}$$$$$$\\{1\\}\\{\\}\\{1\\}$$$$$$\\{1\\}\\{1\\}\\{1\\}$$$In the second example there are nine ways to pack presents:$$$\\{\\}\\{1,2\\}$$$$$$\\{1\\}\\{2\\}$$$$$$\\{1\\}\\{1,2\\}$$$$$$\\{2\\}\\{1\\}$$$$$$\\{2\\}\\{1,2\\}$$$$$$\\{1,2\\}\\{\\}$$$$$$\\{1,2\\}\\{1\\}$$$$$$\\{1,2\\}\\{2\\}$$$$$$\\{1,2\\}\\{1,2\\}$$$For example, the way $$$\\{2\\}\\{2\\}$$$ is wrong, because presents of the first kind should be used in the least one box."}, "src_uid": "71029e5bf085b0f5f39d1835eb801891"} {"nl": {"description": "A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.The tournament takes place in the following way (below, m is the number of the participants of the current round): let k be the maximal power of the number 2 such that k\u2009\u2264\u2009m, k participants compete in the current round and a half of them passes to the next round, the other m\u2009-\u2009k participants pass to the next round directly, when only one participant remains, the tournament finishes. Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.Find the number of bottles and towels needed for the tournament.Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).", "input_spec": "The only line contains three integers n,\u2009b,\u2009p (1\u2009\u2264\u2009n,\u2009b,\u2009p\u2009\u2264\u2009500) \u2014 the number of participants and the parameters described in the problem statement.", "output_spec": "Print two integers x and y \u2014 the number of bottles and towels need for the tournament.", "sample_inputs": ["5 2 3", "8 2 4"], "sample_outputs": ["20 15", "35 32"], "notes": "NoteIn the first example will be three rounds: in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), in the second round will be only one match, so we need another 5 bottles of water, in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water.In the second example no participant will move on to some round directly."}, "src_uid": "eb815f35e9f29793a120d120968cfe34"} {"nl": {"description": "In Omkar's last class of math, he learned about the least common multiple, or $$$LCM$$$. $$$LCM(a, b)$$$ is the smallest positive integer $$$x$$$ which is divisible by both $$$a$$$ and $$$b$$$.Omkar, having a laudably curious mind, immediately thought of a problem involving the $$$LCM$$$ operation: given an integer $$$n$$$, find positive integers $$$a$$$ and $$$b$$$ such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum value possible.Can you help Omkar solve his ludicrously challenging math problem?", "input_spec": "Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 10$$$). Description of the test cases follows. Each test case consists of a single integer $$$n$$$ ($$$2 \\leq n \\leq 10^{9}$$$).", "output_spec": "For each test case, output two positive integers $$$a$$$ and $$$b$$$, such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum possible.", "sample_inputs": ["3\n4\n6\n9"], "sample_outputs": ["2 2\n3 3\n3 6"], "notes": "NoteFor the first test case, the numbers we can choose are $$$1, 3$$$ or $$$2, 2$$$. $$$LCM(1, 3) = 3$$$ and $$$LCM(2, 2) = 2$$$, so we output $$$2 \\ 2$$$.For the second test case, the numbers we can choose are $$$1, 5$$$, $$$2, 4$$$, or $$$3, 3$$$. $$$LCM(1, 5) = 5$$$, $$$LCM(2, 4) = 4$$$, and $$$LCM(3, 3) = 3$$$, so we output $$$3 \\ 3$$$.For the third test case, $$$LCM(3, 6) = 6$$$. It can be shown that there are no other pairs of numbers which sum to $$$9$$$ that have a lower $$$LCM$$$."}, "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"} {"nl": {"description": "We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,\u20093,\u20092,\u20091} is 2.Diameter of multiset consisting of one point is 0.You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?", "input_spec": "The first line contains two integers n and d (1\u2009\u2264\u2009n\u2009\u2264\u2009100,\u20090\u2009\u2264\u2009d\u2009\u2264\u2009100)\u00a0\u2014 the amount of points and the maximum allowed diameter respectively. The second line contains n space separated integers (1\u2009\u2264\u2009xi\u2009\u2264\u2009100)\u00a0\u2014 the coordinates of the points.", "output_spec": "Output a single integer\u00a0\u2014 the minimum number of points you have to remove.", "sample_inputs": ["3 1\n2 1 4", "3 0\n7 7 7", "6 3\n1 3 4 6 9 10"], "sample_outputs": ["1", "0", "3"], "notes": "NoteIn the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2\u2009-\u20091\u2009=\u20091.In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6\u2009-\u20093\u2009=\u20093."}, "src_uid": "6bcb324c072f796f4d50bafea5f624b2"} {"nl": {"description": "Vivek initially has an empty array $$$a$$$ and some integer constant $$$m$$$.He performs the following algorithm: Select a random integer $$$x$$$ uniformly in range from $$$1$$$ to $$$m$$$ and append it to the end of $$$a$$$. Compute the greatest common divisor of integers in $$$a$$$. In case it equals to $$$1$$$, break Otherwise, return to step $$$1$$$. Find the expected length of $$$a$$$. It can be shown that it can be represented as $$$\\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q\\neq 0 \\pmod{10^9+7}$$$. Print the value of $$$P \\cdot Q^{-1} \\pmod{10^9+7}$$$.", "input_spec": "The first and only line contains a single integer $$$m$$$ ($$$1 \\leq m \\leq 100000$$$).", "output_spec": "Print a single integer\u00a0\u2014 the expected length of the array $$$a$$$ written as $$$P \\cdot Q^{-1} \\pmod{10^9+7}$$$.", "sample_inputs": ["1", "2", "4"], "sample_outputs": ["1", "2", "333333338"], "notes": "NoteIn the first example, since Vivek can choose only integers from $$$1$$$ to $$$1$$$, he will have $$$a=[1]$$$ after the first append operation, and after that quit the algorithm. Hence the length of $$$a$$$ is always $$$1$$$, so its expected value is $$$1$$$ as well.In the second example, Vivek each time will append either $$$1$$$ or $$$2$$$, so after finishing the algorithm he will end up having some number of $$$2$$$'s (possibly zero), and a single $$$1$$$ in the end. The expected length of the list is $$$1\\cdot \\frac{1}{2} + 2\\cdot \\frac{1}{2^2} + 3\\cdot \\frac{1}{2^3} + \\ldots = 2$$$."}, "src_uid": "ff810b16b6f41d57c1c8241ad960cba0"} {"nl": {"description": "Vasily the Bear loves beautiful strings. String s is beautiful if it meets the following criteria: String s only consists of characters 0 and 1, at that character 0 must occur in string s exactly n times, and character 1 must occur exactly m times. We can obtain character g from string s with some (possibly, zero) number of modifications. The character g equals either zero or one. A modification of string with length at least two is the following operation: we replace two last characters from the string by exactly one other character. This character equals one if it replaces two zeros, otherwise it equals zero. For example, one modification transforms string \"01010\" into string \"0100\", two modifications transform it to \"011\". It is forbidden to modify a string with length less than two.Help the Bear, count the number of beautiful strings. As the number of beautiful strings can be rather large, print the remainder after dividing the number by 1000000007 (109\u2009+\u20097). ", "input_spec": "The first line of the input contains three space-separated integers n,\u2009m,\u2009g (0\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105,\u2009n\u2009+\u2009m\u2009\u2265\u20091,\u20090\u2009\u2264\u2009g\u2009\u2264\u20091).", "output_spec": "Print a single integer \u2014 the answer to the problem modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1 1 0", "2 2 0", "1 1 1"], "sample_outputs": ["2", "4", "0"], "notes": "NoteIn the first sample the beautiful strings are: \"01\", \"10\".In the second sample the beautiful strings are: \"0011\", \"1001\", \"1010\", \"1100\".In the third sample there are no beautiful strings."}, "src_uid": "066dd9e6091238edf2912a6af4d29e7f"} {"nl": {"description": "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_spec": "The input contains only one integer in the first line: $$$v$$$ ($$$1 \\le v \\le 10^9$$$), the initial value of $$$n$$$.", "output_spec": "Output a single integer, the minimum value of $$$n$$$ the player can get.", "sample_inputs": ["8", "1"], "sample_outputs": ["1", "1"], "notes": "NoteIn 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."}, "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"} {"nl": {"description": "Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second\u00a0\u2014 v0\u2009+\u2009a pages, at third\u00a0\u2014 v0\u2009+\u20092a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.Help Mister B to calculate how many days he needed to finish the book.", "input_spec": "First and only line contains five space-separated integers: c, v0, v1, a and l (1\u2009\u2264\u2009c\u2009\u2264\u20091000, 0\u2009\u2264\u2009l\u2009<\u2009v0\u2009\u2264\u2009v1\u2009\u2264\u20091000, 0\u2009\u2264\u2009a\u2009\u2264\u20091000) \u2014 the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.", "output_spec": "Print one integer \u2014 the number of days Mister B needed to finish the book.", "sample_inputs": ["5 5 10 5 4", "12 4 12 4 1", "15 1 100 0 0"], "sample_outputs": ["1", "3", "15"], "notes": "NoteIn the first sample test the book contains 5 pages, so Mister B read it right at the first day.In the second sample test at first day Mister B read pages number 1\u2009-\u20094, at second day\u00a0\u2014 4\u2009-\u200911, at third day\u00a0\u2014 11\u2009-\u200912 and finished the book.In third sample test every day Mister B read 1 page of the book, so he finished in 15 days."}, "src_uid": "b743110117ce13e2090367fd038d3b50"} {"nl": {"description": "Salve, mi amice.Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.Rp:\u00a0\u00a0\u00a0\u00a0I Aqua Fortis\u00a0\u00a0\u00a0\u00a0I Aqua Regia\u00a0\u00a0\u00a0\u00a0II Amalgama\u00a0\u00a0\u00a0\u00a0VII Minium\u00a0\u00a0\u00a0\u00a0IV VitriolMisce in vitro et \u00e6stus, et nil admirari. Festina lente, et nulla tenaci invia est via.Fac et spera,Vale,Nicolas Flamel", "input_spec": "The first line of input contains several space-separated integers ai (0\u2009\u2264\u2009ai\u2009\u2264\u2009100).", "output_spec": "Print a single integer.", "sample_inputs": ["2 4 6 8 10"], "sample_outputs": ["1"], "notes": null}, "src_uid": "f914f9b7884cc04b990c7800c6be7b10"} {"nl": {"description": "You are given a bracket sequence $$$s$$$ (not necessarily a regular one). A bracket sequence is a string containing only characters '(' and ')'.A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences \"()()\" and \"(())\" are regular (the resulting expressions are: \"(1)+(1)\" and \"((1+1)+1)\"), and \")(\", \"(\" and \")\" are not.Your problem is to calculate the number of regular bracket sequences of length $$$2n$$$ containing the given bracket sequence $$$s$$$ as a substring (consecutive sequence of characters) modulo $$$10^9+7$$$ ($$$1000000007$$$).", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the half-length of the resulting regular bracket sequences (the resulting sequences must have length equal to $$$2n$$$). The second line of the input contains one string $$$s$$$ ($$$1 \\le |s| \\le 200$$$) \u2014 the string $$$s$$$ that should be a substring in each of the resulting regular bracket sequences ($$$|s|$$$ is the length of $$$s$$$).", "output_spec": "Print only one integer \u2014 the number of regular bracket sequences containing the given bracket sequence $$$s$$$ as a substring. Since this number can be huge, print it modulo $$$10^9+7$$$ ($$$1000000007$$$).", "sample_inputs": ["5\n()))()", "3\n(()", "2\n((("], "sample_outputs": ["5", "4", "0"], "notes": "NoteAll regular bracket sequences satisfying the conditions above for the first example: \"(((()))())\"; \"((()()))()\"; \"((()))()()\"; \"(()(()))()\"; \"()((()))()\". All regular bracket sequences satisfying the conditions above for the second example: \"((()))\"; \"(()())\"; \"(())()\"; \"()(())\". And there is no regular bracket sequences of length $$$4$$$ containing \"(((\" as a substring in the third example."}, "src_uid": "590a49a7af0eb83376ed911ed488d7e5"} {"nl": {"description": "Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya was delivered a string s, containing only digits. He needs to find a string that represents a lucky number without leading zeroes, is not empty, is contained in s as a substring the maximum number of times.Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.", "input_spec": "The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.", "output_spec": "In the only line print the answer to Petya's problem. If the sought string does not exist, print \"-1\" (without quotes).", "sample_inputs": ["047", "16", "472747"], "sample_outputs": ["4", "-1", "7"], "notes": "NoteThe lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1\u2009\u2264\u2009i\u2009\u2264\u2009min(|x|,\u2009|y|)), that xi\u2009<\u2009yi and for any j (1\u2009\u2264\u2009j\u2009<\u2009i) xj\u2009=\u2009yj. Here |a| denotes the length of string a.In the first sample three conditions are fulfilled for strings \"4\", \"7\" and \"47\". The lexicographically minimum one is \"4\".In the second sample s has no substrings which are lucky numbers.In the third sample the three conditions are only fulfilled for string \"7\"."}, "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"} {"nl": {"description": "The Fair Nut lives in $$$n$$$ story house. $$$a_i$$$ people live on the $$$i$$$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $$$x$$$-th floor, but $$$x$$$ hasn't been chosen yet. When a person needs to get from floor $$$a$$$ to floor $$$b$$$, elevator follows the simple algorithm: Moves from the $$$x$$$-th floor (initially it stays on the $$$x$$$-th floor) to the $$$a$$$-th and takes the passenger. Moves from the $$$a$$$-th floor to the $$$b$$$-th floor and lets out the passenger (if $$$a$$$ equals $$$b$$$, elevator just opens and closes the doors, but still comes to the floor from the $$$x$$$-th floor). Moves from the $$$b$$$-th floor back to the $$$x$$$-th. The elevator never transposes more than one person and always goes back to the floor $$$x$$$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $$$a$$$-th floor to the $$$b$$$-th floor requires $$$|a - b|$$$ units of electricity.Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $$$x$$$-th floor. Don't forget than elevator initially stays on the $$$x$$$-th floor. ", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the number of floors. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\leq a_i \\leq 100$$$)\u00a0\u2014 the number of people on each floor.", "output_spec": "In a single line, print the answer to the problem\u00a0\u2014 the minimum number of electricity units.", "sample_inputs": ["3\n0 2 1", "2\n1 1"], "sample_outputs": ["16", "4"], "notes": "NoteIn the first example, the answer can be achieved by choosing the second floor as the $$$x$$$-th floor. Each person from the second floor (there are two of them) would spend $$$4$$$ units of electricity per day ($$$2$$$ to get down and $$$2$$$ to get up), and one person from the third would spend $$$8$$$ units of electricity per day ($$$4$$$ to get down and $$$4$$$ to get up). $$$4 \\cdot 2 + 8 \\cdot 1 = 16$$$.In the second example, the answer can be achieved by choosing the first floor as the $$$x$$$-th floor."}, "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"nl": {"description": "You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly. An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex D to itself in exactly n steps. In other words, you are asked to find out the number of different cyclic paths with the length of n from vertex D to itself. As the number can be quite large, you should print it modulo 1000000007 (109\u2009+\u20097). ", "input_spec": "The first line contains the only integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009107) \u2014 the required length of the cyclic path.", "output_spec": "Print the only integer \u2014 the required number of ways modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["2", "4"], "sample_outputs": ["3", "21"], "notes": "NoteThe required paths in the first sample are: D\u2009-\u2009A\u2009-\u2009D D\u2009-\u2009B\u2009-\u2009D D\u2009-\u2009C\u2009-\u2009D "}, "src_uid": "77627cc366a22e38da412c3231ac91a8"} {"nl": {"description": "Imagine a city with n horizontal streets crossing m vertical streets, forming an (n\u2009-\u20091)\u2009\u00d7\u2009(m\u2009-\u20091) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection. The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.", "input_spec": "The first line of input contains two integers n and m, (2\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200920), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.", "output_spec": "If the given pattern meets the mayor's criteria, print a single line containing \"YES\", otherwise print a single line containing \"NO\".", "sample_inputs": ["3 3\n><>\nv^v", "4 6\n<><>\nv^v^v^"], "sample_outputs": ["NO", "YES"], "notes": "NoteThe figure above shows street directions in the second sample test case."}, "src_uid": "eab5c84c9658eb32f5614cd2497541cf"} {"nl": {"description": "Dante is engaged in a fight with \"The Savior\". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible.", "input_spec": "The first line of the input contains three integers a, b, c (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009c\u2009\u2264\u200910\u2009000)\u00a0\u2014 the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.", "output_spec": "Print \"Yes\" (without quotes) if Dante can deal exactly c damage to the shield and \"No\" (without quotes) otherwise.", "sample_inputs": ["4 6 15", "3 2 7", "6 11 6"], "sample_outputs": ["No", "Yes", "Yes"], "notes": "NoteIn the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1\u00b73\u2009+\u20092\u00b72\u2009=\u20097 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1\u00b76\u2009+\u20090\u00b711\u2009=\u20096 damage. "}, "src_uid": "e66ecb0021a34042885442b336f3d911"} {"nl": {"description": "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_spec": "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_spec": "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.", "sample_inputs": ["3454", "10", "111111"], "sample_outputs": ["YES\n344", "YES\n0", "NO"], "notes": null}, "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"nl": {"description": "zscoder wants to generate an input file for some programming competition problem.His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.", "input_spec": "The only line contains three integers n, x and y (1\u2009\u2264\u2009n\u2009\u2264\u2009107, 1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009109) \u2014 the number of letters 'a' in the input file and the parameters from the problem statement.", "output_spec": "Print the only integer t \u2014 the minimum amount of time needed to generate the input file.", "sample_inputs": ["8 1 1", "8 1 10"], "sample_outputs": ["4", "8"], "notes": null}, "src_uid": "0f270af00be2a523515d5e7bd66800f6"} {"nl": {"description": "Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: \"If you solve the following problem, I'll return it to you.\" The problem is: You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.If we sort all lucky numbers in increasing order, what's the 1-based index of n? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.", "input_spec": "The first and only line of input contains a lucky number n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Print the index of n among all lucky numbers.", "sample_inputs": ["4", "7", "77"], "sample_outputs": ["1", "2", "6"], "notes": null}, "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"nl": {"description": "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 \u2014 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_spec": "The first (and the only) line contains two integers n and s (1\u2009\u2264\u2009n,\u2009s\u2009\u2264\u20091018).", "output_spec": "Print one integer \u2014 the quantity of really big numbers that are not greater than n.", "sample_inputs": ["12 1", "25 20", "10 9"], "sample_outputs": ["3", "0", "1"], "notes": "NoteIn 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\u2009-\u20093\u2009\u2265\u200920).In the third example 10 is the only really big number (10\u2009-\u20091\u2009\u2265\u20099)."}, "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"} {"nl": {"description": "Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.More formally, if a game designer selected cells having coordinates (x1,\u2009y1) and (x2,\u2009y2), where x1\u2009\u2264\u2009x2 and y1\u2009\u2264\u2009y2, then all cells having center coordinates (x,\u2009y) such that x1\u2009\u2264\u2009x\u2009\u2264\u2009x2 and y1\u2009\u2264\u2009y\u2009\u2264\u2009y2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x2\u2009-\u2009x1 is divisible by 2.Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.Help him implement counting of these units before painting. ", "input_spec": "The only line of input contains four integers x1,\u2009y1,\u2009x2,\u2009y2 (\u2009-\u2009109\u2009\u2264\u2009x1\u2009\u2264\u2009x2\u2009\u2264\u2009109,\u2009\u2009-\u2009109\u2009\u2264\u2009y1\u2009\u2264\u2009y2\u2009\u2264\u2009109) \u2014 the coordinates of the centers of two cells.", "output_spec": "Output one integer \u2014 the number of cells to be filled.", "sample_inputs": ["1 1 5 5"], "sample_outputs": ["13"], "notes": null}, "src_uid": "00cffd273df24d1676acbbfd9a39630d"} {"nl": {"description": "Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present \u2014 a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3 third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: any shelf cannot contain both cups and medals at the same time; no shelf can contain more than five cups; no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.", "input_spec": "The first line contains integers a1, a2 and a3 (0\u2009\u2264\u2009a1,\u2009a2,\u2009a3\u2009\u2264\u2009100). The second line contains integers b1, b2 and b3 (0\u2009\u2264\u2009b1,\u2009b2,\u2009b3\u2009\u2264\u2009100). The third line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). The numbers in the lines are separated by single spaces.", "output_spec": "Print \"YES\" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["1 1 1\n1 1 1\n4", "1 1 3\n2 3 4\n2", "1 0 0\n1 0 0\n1"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"nl": {"description": "Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one \u2014 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.Help Ivan to answer this question for several values of x!", "input_spec": "The first line contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of testcases. The i-th of the following n lines contains one integer xi (1\u2009\u2264\u2009xi\u2009\u2264\u2009100) \u2014 the number of chicken chunks Ivan wants to eat.", "output_spec": "Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.", "sample_inputs": ["2\n6\n5"], "sample_outputs": ["YES\nNO"], "notes": "NoteIn the first example Ivan can buy two small portions.In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much."}, "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"} {"nl": {"description": "Alice and Bob have decided to play the game \"Rock, Paper, Scissors\". The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a draw. Otherwise, the following rules applied: if one player showed rock and the other one showed scissors, then the player who showed rock is considered the winner and the other one is considered the loser; if one player showed scissors and the other one showed paper, then the player who showed scissors is considered the winner and the other one is considered the loser; if one player showed paper and the other one showed rock, then the player who showed paper is considered the winner and the other one is considered the loser. Alice and Bob decided to play exactly $$$n$$$ rounds of the game described above. Alice decided to show rock $$$a_1$$$ times, show scissors $$$a_2$$$ times and show paper $$$a_3$$$ times. Bob decided to show rock $$$b_1$$$ times, show scissors $$$b_2$$$ times and show paper $$$b_3$$$ times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that $$$a_1 + a_2 + a_3 = n$$$ and $$$b_1 + b_2 + b_3 = n$$$.Your task is to find two numbers: the minimum number of round Alice can win; the maximum number of rounds Alice can win. ", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 10^{9}$$$) \u2014 the number of rounds. The second line of the input contains three integers $$$a_1, a_2, a_3$$$ ($$$0 \\le a_i \\le n$$$) \u2014 the number of times Alice will show rock, scissors and paper, respectively. It is guaranteed that $$$a_1 + a_2 + a_3 = n$$$. The third line of the input contains three integers $$$b_1, b_2, b_3$$$ ($$$0 \\le b_j \\le n$$$) \u2014 the number of times Bob will show rock, scissors and paper, respectively. It is guaranteed that $$$b_1 + b_2 + b_3 = n$$$.", "output_spec": "Print two integers: the minimum and the maximum number of rounds Alice can win.", "sample_inputs": ["2\n0 1 1\n1 1 0", "15\n5 5 5\n5 5 5", "3\n0 0 3\n3 0 0", "686\n479 178 29\n11 145 530", "319\n10 53 256\n182 103 34"], "sample_outputs": ["0 1", "0 15", "3 3", "22 334", "119 226"], "notes": "NoteIn the first example, Alice will not win any rounds if she shows scissors and then paper and Bob shows rock and then scissors. In the best outcome, Alice will win one round if she shows paper and then scissors, and Bob shows rock and then scissors.In the second example, Alice will not win any rounds if Bob shows the same things as Alice each round.In the third example, Alice always shows paper and Bob always shows rock so Alice will win all three rounds anyway."}, "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402"} {"nl": {"description": "The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x\u2009=\u20090 and x\u2009=\u2009s.Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds. Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.", "input_spec": "The first line contains three integers s, x1 and x2 (2\u2009\u2264\u2009s\u2009\u2264\u20091000, 0\u2009\u2264\u2009x1,\u2009x2\u2009\u2264\u2009s, x1\u2009\u2260\u2009x2)\u00a0\u2014 the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to. The second line contains two integers t1 and t2 (1\u2009\u2264\u2009t1,\u2009t2\u2009\u2264\u20091000)\u00a0\u2014 the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter. The third line contains two integers p and d (1\u2009\u2264\u2009p\u2009\u2264\u2009s\u2009-\u20091, d is either 1 or )\u00a0\u2014 the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If , the tram goes in the direction from the point s to the point 0. If d\u2009=\u20091, the tram goes in the direction from the point 0 to the point s.", "output_spec": "Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.", "sample_inputs": ["4 2 4\n3 4\n1 1", "5 4 0\n1 2\n3 1"], "sample_outputs": ["8", "7"], "notes": "NoteIn the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds. In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total."}, "src_uid": "fb3aca6eba3a952e9d5736c5d8566821"} {"nl": {"description": "A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?", "input_spec": "The only line of the input contains five integers t1, t2, t3, t4 and t5 (1\u2009\u2264\u2009ti\u2009\u2264\u2009100)\u00a0\u2014 numbers written on cards.", "output_spec": "Print the minimum possible sum of numbers written on remaining cards.", "sample_inputs": ["7 3 7 3 20", "7 9 3 1 8", "10 10 10 10 10"], "sample_outputs": ["26", "28", "20"], "notes": "NoteIn the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following. Do nothing and the sum would be 7\u2009+\u20093\u2009+\u20097\u2009+\u20093\u2009+\u200920\u2009=\u200940. Remove two cards with a number 7. The remaining sum would be 3\u2009+\u20093\u2009+\u200920\u2009=\u200926. Remove two cards with a number 3. The remaining sum would be 7\u2009+\u20097\u2009+\u200920\u2009=\u200934. You are asked to minimize the sum so the answer is 26.In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7\u2009+\u20099\u2009+\u20091\u2009+\u20093\u2009+\u20098\u2009=\u200928.In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10\u2009+\u200910\u2009=\u200920."}, "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"} {"nl": {"description": "Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m.Number x is considered close to number n modulo m, if: it can be obtained by rearranging the digits of number n, it doesn't have any leading zeroes, the remainder after dividing number x by m equals 0. Roman is a good mathematician, but the number of such numbers is too huge for him. So he asks you to help him. ", "input_spec": "The first line contains two integers: n (1\u2009\u2264\u2009n\u2009<\u20091018) and m (1\u2009\u2264\u2009m\u2009\u2264\u2009100).", "output_spec": "In a single line print a single integer \u2014 the number of numbers close to number n modulo m.", "sample_inputs": ["104 2", "223 4", "7067678 8"], "sample_outputs": ["3", "1", "47"], "notes": "NoteIn the first sample the required numbers are: 104, 140, 410.In the second sample the required number is 232."}, "src_uid": "5eb90c23ffa3794fdddc5670c0373829"} {"nl": {"description": "You can not just take the file and send it. When Polycarp trying to send a file in the social network \"Codehorses\", he encountered an unexpected problem. If the name of the file contains three or more \"x\" (lowercase Latin letters \"x\") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.Determine the minimum number of characters to remove from the file name so after that the name does not contain \"xxx\" as a substring. Print 0 if the file name does not initially contain a forbidden substring \"xxx\".You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $$$1$$$. For example, if you delete the character in the position $$$2$$$ from the string \"exxxii\", then the resulting string is \"exxii\".", "input_spec": "The first line contains integer $$$n$$$ $$$(3 \\le n \\le 100)$$$ \u2014 the length of the file name. The second line contains a string of length $$$n$$$ consisting of lowercase Latin letters only \u2014 the file name.", "output_spec": "Print the minimum number of characters to remove from the file name so after that the name does not contain \"xxx\" as a substring. If initially the file name dost not contain a forbidden substring \"xxx\", print 0.", "sample_inputs": ["6\nxxxiii", "5\nxxoxx", "10\nxxxxxxxxxx"], "sample_outputs": ["1", "0", "8"], "notes": "NoteIn the first example Polycarp tried to send a file with name contains number $$$33$$$, written in Roman numerals. But he can not just send the file, because it name contains three letters \"x\" in a row. To send the file he needs to remove any one of this letters."}, "src_uid": "8de14db41d0acee116bd5d8079cb2b02"} {"nl": {"description": "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_spec": "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_spec": "Print exactly one integer\u00a0\u2014 the minimum number of coins required to obtain sum $$$S$$$.", "sample_inputs": ["5 11", "6 16"], "sample_outputs": ["3", "3"], "notes": "NoteIn 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."}, "src_uid": "04c067326ec897091c3dbcf4d134df96"} {"nl": {"description": "One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.Can you help him?", "input_spec": "The single line of the input contains two positive integers a and b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009100) \u2014 the number of red and blue socks that Vasya's got.", "output_spec": "Print two space-separated integers \u2014 the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.", "sample_inputs": ["3 1", "2 3", "7 3"], "sample_outputs": ["1 1", "2 0", "3 2"], "notes": "NoteIn the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day."}, "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"nl": {"description": "Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.Embosser is a special devise that allows to \"print\" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.", "input_spec": "The only line of input contains the name of some exhibit\u00a0\u2014 the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.", "output_spec": "Print one integer\u00a0\u2014 the minimum number of rotations of the wheel, required to print the name given in the input.", "sample_inputs": ["zeus", "map", "ares"], "sample_outputs": ["18", "35", "34"], "notes": "Note\u00a0 To print the string from the first sample it would be optimal to perform the following sequence of rotations: from 'a' to 'z' (1 rotation counterclockwise), from 'z' to 'e' (5 clockwise rotations), from 'e' to 'u' (10 rotations counterclockwise), from 'u' to 's' (2 counterclockwise rotations). In total, 1\u2009+\u20095\u2009+\u200910\u2009+\u20092\u2009=\u200918 rotations are required."}, "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"nl": {"description": "Bizon the Champion isn't just charming, he also is very smart.While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n\u2009\u00d7\u2009m multiplication table, where the element on the intersection of the i-th row and j-th column equals i\u00b7j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?Consider the given multiplication table. If you write out all n\u00b7m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.", "input_spec": "The single line contains integers n, m and k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20095\u00b7105;\u00a01\u2009\u2264\u2009k\u2009\u2264\u2009n\u00b7m).", "output_spec": "Print the k-th largest number in a n\u2009\u00d7\u2009m multiplication table.", "sample_inputs": ["2 2 2", "2 3 4", "1 10 5"], "sample_outputs": ["2", "3", "5"], "notes": "NoteA 2\u2009\u00d7\u20093 multiplication table looks like this:1 2 32 4 6"}, "src_uid": "13a918eca30799b240ceb9de47507a26"} {"nl": {"description": "One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0,\u20090,\u20090), and the opposite one is at point (x1,\u2009y1,\u2009z1). The six faces of the box contain some numbers a1,\u2009a2,\u2009...,\u2009a6, exactly one number right in the center of each face. The numbers are located on the box like that: number a1 is written on the face that lies on the ZOX plane; a2 is written on the face, parallel to the plane from the previous point; a3 is written on the face that lies on the XOY plane; a4 is written on the face, parallel to the plane from the previous point; a5 is written on the face that lies on the YOZ plane; a6 is written on the face, parallel to the plane from the previous point. At the moment Vasya is looking at the box from point (x,\u2009y,\u2009z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the ai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some ai\u2009=\u20096, then he can't mistake this number for 9 and so on). ", "input_spec": "The fist input line contains three space-separated integers x, y and z (|x|,\u2009|y|,\u2009|z|\u2009\u2264\u2009106) \u2014 the coordinates of Vasya's position in space. The second line contains three space-separated integers x1, y1, z1 (1\u2009\u2264\u2009x1,\u2009y1,\u2009z1\u2009\u2264\u2009106) \u2014 the coordinates of the box's vertex that is opposite to the vertex at point (0,\u20090,\u20090). The third line contains six space-separated integers a1,\u2009a2,\u2009...,\u2009a6 (1\u2009\u2264\u2009ai\u2009\u2264\u2009106) \u2014 the numbers that are written on the box faces. It is guaranteed that point (x,\u2009y,\u2009z) is located strictly outside the box.", "output_spec": "Print a single integer \u2014 the sum of all numbers on the box faces that Vasya sees.", "sample_inputs": ["2 2 2\n1 1 1\n1 2 3 4 5 6", "0 0 10\n3 2 3\n1 2 3 4 5 6"], "sample_outputs": ["12", "4"], "notes": "NoteThe first sample corresponds to perspective, depicted on the picture. Vasya sees numbers a2 (on the top face that is the darkest), a6 (on the right face that is the lightest) and a4 (on the left visible face).In the second sample Vasya can only see number a4."}, "src_uid": "c7889a8f64c57cf7be4df870f68f749e"} {"nl": {"description": "You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.It is allowed to leave a as it is.", "input_spec": "The first line contains integer a (1\u2009\u2264\u2009a\u2009\u2264\u20091018). The second line contains integer b (1\u2009\u2264\u2009b\u2009\u2264\u20091018). Numbers don't have leading zeroes. It is guaranteed that answer exists.", "output_spec": "Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.", "sample_inputs": ["123\n222", "3921\n10000", "4940\n5000"], "sample_outputs": ["213", "9321", "4940"], "notes": null}, "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"} {"nl": {"description": "Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.Initially, snowball is at height $$$h$$$ and it has weight $$$w$$$. Each second the following sequence of events happens: snowball's weights increases by $$$i$$$, where $$$i$$$\u00a0\u2014 is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.There are exactly two stones on the mountain. First stone has weight $$$u_1$$$ and is located at height $$$d_1$$$, the second one\u00a0\u2014 $$$u_2$$$ and $$$d_2$$$ respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before. Find the weight of the snowball when it stops moving, that is, it reaches height\u00a00.", "input_spec": "First line contains two integers $$$w$$$ and $$$h$$$\u00a0\u2014 initial weight and height of the snowball ($$$0 \\le w \\le 100$$$; $$$1 \\le h \\le 100$$$). Second line contains two integers $$$u_1$$$ and $$$d_1$$$\u00a0\u2014 weight and height of the first stone ($$$0 \\le u_1 \\le 100$$$; $$$1 \\le d_1 \\le h$$$). Third line contains two integers $$$u_2$$$ and $$$d_2$$$\u00a0\u2014 weight and heigth of the second stone ($$$0 \\le u_2 \\le 100$$$; $$$1 \\le d_2 \\le h$$$; $$$d_1 \\ne d_2$$$). Notice that stones always have different heights.", "output_spec": "Output a single integer\u00a0\u2014 final weight of the snowball after it reaches height\u00a00.", "sample_inputs": ["4 3\n1 1\n1 2", "4 3\n9 2\n0 1"], "sample_outputs": ["8", "1"], "notes": "NoteIn the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially: The weight of the snowball increases by 3 (current height), becomes equal to 7. The snowball moves one meter down, the current height becomes equal to 2. The weight of the snowball increases by 2 (current height), becomes equal to 9. The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8. The snowball moves one meter down, the current height becomes equal to 1. The weight of the snowball increases by 1 (current height), becomes equal to 9. The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8. The snowball moves one meter down, the current height becomes equal to 0. Thus, at the end the weight of the snowball is equal to 8."}, "src_uid": "084a12eb3a708b43b880734f3ee51374"} {"nl": {"description": "Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the maximum number of consecutive series that Stepan did not watch.Your task is to determine according to Stepan's memories if his dissatisfaction could be exactly equal to k.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 0\u2009\u2264\u2009k\u2009\u2264\u2009n) \u2014 the number of episodes in the series and the dissatisfaction which should be checked. The second line contains the sequence which consists of n symbols \"Y\", \"N\" and \"?\". If the i-th symbol equals \"Y\", Stepan remembers that he has watched the episode number i. If the i-th symbol equals \"N\", Stepan remembers that he hasn't watched the epizode number i. If the i-th symbol equals \"?\", Stepan doesn't exactly remember if he has watched the episode number i or not.", "output_spec": "If Stepan's dissatisfaction can be exactly equal to k, then print \"YES\" (without qoutes). Otherwise print \"NO\" (without qoutes).", "sample_inputs": ["5 2\nNYNNY", "6 1\n????NN"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row \u2014 the episode number 3 and the episode number 4. The answer is \"YES\", because k\u2009=\u20092.In the second test k\u2009=\u20091, Stepan's dissatisfaction is greater than or equal to 2 (because he remembers that he hasn't watch at least two episodes in a row \u2014 number 5 and number 6), even if he has watched the episodes from the first to the fourth, inclusive."}, "src_uid": "5bd578d3da5837c259b222336a194d12"} {"nl": {"description": "Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of apples. The second line contains n integers w1,\u2009w2,\u2009...,\u2009wn (wi\u2009=\u2009100 or wi\u2009=\u2009200), where wi is the weight of the i-th apple.", "output_spec": "In a single line print \"YES\" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print \"NO\" (without the quotes).", "sample_inputs": ["3\n100 200 100", "4\n100 100 100 200"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa."}, "src_uid": "9679acef82356004e47b1118f8fc836a"} {"nl": {"description": "Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:qwertyuiopasdfghjkl;zxcvbnm,./Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).We have a sequence of characters he has typed and we want to find the original message.", "input_spec": "First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.", "output_spec": "Print a line that contains the original message.", "sample_inputs": ["R\ns;;upimrrfod;pbr"], "sample_outputs": ["allyouneedislove"], "notes": null}, "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"} {"nl": {"description": "Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the n-th bit.Now Sergey wants to test the following instruction: \"add 1 to the value of the cell\". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded.Sergey wrote certain values \u200b\u200bof the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of bits in the cell. The second line contains a string consisting of n characters \u2014 the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.", "output_spec": "Print a single integer \u2014 the number of bits in the cell which change their state after we add 1 to the cell.", "sample_inputs": ["4\n1100", "4\n1111"], "sample_outputs": ["3", "4"], "notes": "NoteIn the first sample the cell ends up with value 0010, in the second sample \u2014 with 0000."}, "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"} {"nl": {"description": "Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?", "input_spec": "The first line of the input contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7109)\u00a0\u2014 the number of movements made by the operator. The second line contains a single integer x (0\u2009\u2264\u2009x\u2009\u2264\u20092)\u00a0\u2014 the index of the shell where the ball was found after n movements.", "output_spec": "Print one integer from 0 to 2\u00a0\u2014 the index of the shell where the ball was initially placed.", "sample_inputs": ["4\n2", "1\n1"], "sample_outputs": ["1", "0"], "notes": "NoteIn the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. "}, "src_uid": "7853e03d520cd71571a6079cdfc4c4b0"} {"nl": {"description": "IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.", "input_spec": "The only line of the input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the prediction on the number of people who will buy the game.", "output_spec": "Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.", "sample_inputs": ["3000"], "sample_outputs": ["1"], "notes": null}, "src_uid": "8551308e5ff435e0fc507b89a912408a"} {"nl": {"description": "Let's consider equation:x2\u2009+\u2009s(x)\u00b7x\u2009-\u2009n\u2009=\u20090,\u2009 where x,\u2009n 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_spec": "A single line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specifier. ", "output_spec": "Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x\u2009>\u20090), that the equation given in the statement holds.", "sample_inputs": ["2", "110", "4"], "sample_outputs": ["1", "10", "-1"], "notes": "NoteIn the first test case x\u2009=\u20091 is the minimum root. As s(1)\u2009=\u20091 and 12\u2009+\u20091\u00b71\u2009-\u20092\u2009=\u20090.In the second test case x\u2009=\u200910 is the minimum root. As s(10)\u2009=\u20091\u2009+\u20090\u2009=\u20091 and 102\u2009+\u20091\u00b710\u2009-\u2009110\u2009=\u20090.In the third test case the equation has no roots."}, "src_uid": "e1070ad4383f27399d31b8d0e87def59"} {"nl": {"description": "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_spec": "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_spec": "Output a single string\u00a0\u2014 alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.", "sample_inputs": ["harry potter", "tom riddle"], "sample_outputs": ["hap", "tomr"], "notes": null}, "src_uid": "aed892f2bda10b6aee10dcb834a63709"} {"nl": {"description": "Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess \u2014 all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag \u2014 her inherent sense of order does not let her do so.You are given the coordinates of the handbag and the coordinates of the objects in some \u0421artesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.", "input_spec": "The first line of the input file contains the handbag's coordinates xs,\u2009ys. The second line contains number n (1\u2009\u2264\u2009n\u2009\u2264\u200924) \u2014 the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.", "output_spec": "In the first line output the only number \u2014 the minimum time the girl needs to put the objects into her handbag. In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them. ", "sample_inputs": ["0 0\n2\n1 1\n-1 1", "1 1\n3\n4 3\n3 4\n0 0"], "sample_outputs": ["8\n0 1 2 0", "32\n0 1 2 0 3 0"], "notes": null}, "src_uid": "2ecbac20dc5f4060bc873553946281bc"} {"nl": {"description": "Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'.You are given a set of q possible operations. Limak can perform them in any order, any operation may be applied any number of times. The i-th operation is described by a string ai of length two and a string bi of length one. No two of q possible operations have the same string ai.When Limak has a string s he can perform the i-th operation on s if the first two letters of s match a two-letter string ai. Performing the i-th operation removes first two letters of s and inserts there a string bi. See the notes section for further clarification.You may note that performing an operation decreases the length of a string s exactly by 1. Also, for some sets of operations there may be a string that cannot be compressed any further, because the first two letters don't match any ai.Limak wants to start with a string of length n and perform n\u2009-\u20091 operations to finally get a one-letter string \"a\". In how many ways can he choose the starting string to be able to get \"a\"? Remember that Limak can use only letters he knows.", "input_spec": "The first line contains two integers n and q (2\u2009\u2264\u2009n\u2009\u2264\u20096, 1\u2009\u2264\u2009q\u2009\u2264\u200936)\u00a0\u2014 the length of the initial string and the number of available operations. The next q lines describe the possible operations. The i-th of them contains two strings ai and bi (|ai|\u2009=\u20092,\u2009|bi|\u2009=\u20091). It's guaranteed that ai\u2009\u2260\u2009aj for i\u2009\u2260\u2009j and that all ai and bi consist of only first six lowercase English letters.", "output_spec": "Print the number of strings of length n that Limak will be able to transform to string \"a\" by applying only operations given in the input.", "sample_inputs": ["3 5\nab a\ncc c\nca a\nee c\nff d", "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c", "6 2\nbb a\nba a"], "sample_outputs": ["4", "1", "0"], "notes": "NoteIn the first sample, we count initial strings of length 3 from which Limak can get a required string \"a\". There are 4 such strings: \"abb\", \"cab\", \"cca\", \"eea\". The first one Limak can compress using operation 1 two times (changing \"ab\" to a single \"a\"). The first operation would change \"abb\" to \"ab\" and the second operation would change \"ab\" to \"a\".Other three strings may be compressed as follows: \"cab\" \"ab\" \"a\" \"cca\" \"ca\" \"a\" \"eea\" \"ca\" \"a\" In the second sample, the only correct initial string is \"eb\" because it can be immediately compressed to \"a\"."}, "src_uid": "c42abec29bfd17de3f43385fa6bea534"} {"nl": {"description": "Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.", "input_spec": "The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 (\u2009-\u2009109\u2009\u2264\u2009x1,\u2009y1,\u2009x2,\u2009y2\u2009\u2264\u2009109) \u2014 coordinates of segment's beginning and end positions. The given segments can degenerate into points.", "output_spec": "Output the word \u00abYES\u00bb, if the given four segments form the required rectangle, otherwise output \u00abNO\u00bb.", "sample_inputs": ["1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0", "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2"], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "ad105c08f63e9761fe90f69630628027"} {"nl": {"description": "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_spec": "The first and only line of input contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).", "output_spec": "Output the minimum number of bills that Allen could receive.", "sample_inputs": ["125", "43", "1000000000"], "sample_outputs": ["3", "5", "10000000"], "notes": "NoteIn the first sample case, Allen can withdraw this with a $$$100$$$ dollar bill, a $$$20$$$ dollar bill, and a $$$5$$$ dollar bill. There is no way for Allen to receive $$$125$$$ dollars in one or two bills.In the second sample case, Allen can withdraw two $$$20$$$ dollar bills and three $$$1$$$ dollar bills.In the third sample case, Allen can withdraw $$$100000000$$$ (ten million!) $$$100$$$ dollar bills."}, "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"} {"nl": {"description": "Your search for Heidi is over \u2013 you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1\u2009\u2264\u2009i\u2009\u2264\u2009n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.There is a problem, though. The capacity of the library is k \u2013 this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.You are given k and the sequence of requests for books a1,\u2009a2,\u2009...,\u2009an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?", "input_spec": "The first line of input will contain two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u200980). The second line will contain n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009n) \u2013 the sequence of book requests.", "output_spec": "On a single line print the minimum cost of buying books at the store so as to satisfy all requests.", "sample_inputs": ["4 80\n1 2 2 1", "4 1\n1 2 2 1", "4 2\n1 2 3 1"], "sample_outputs": ["2", "3", "3"], "notes": "NoteIn the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day."}, "src_uid": "956228e31679caa9952b216e010f9773"} {"nl": {"description": "Vanya has a scales for weighing loads and weights of masses w0,\u2009w1,\u2009w2,\u2009...,\u2009w100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.", "input_spec": "The first line contains two integers w,\u2009m (2\u2009\u2264\u2009w\u2009\u2264\u2009109, 1\u2009\u2264\u2009m\u2009\u2264\u2009109) \u2014 the number defining the masses of the weights and the mass of the item.", "output_spec": "Print word 'YES' if the item can be weighted and 'NO' if it cannot.", "sample_inputs": ["3 7", "100 99", "100 50"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteNote to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7\u2009+\u20093\u2009=\u20099\u2009+\u20091.Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input. "}, "src_uid": "a74adcf0314692f8ac95f54d165d9582"} {"nl": {"description": "Little Petya loves playing with squares. Mum bought him a square 2n\u2009\u00d7\u20092n in size. Petya marked a cell inside the square and now he is solving the following task.The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not have any common points with the marked cell and the resulting two parts should be equal up to rotation.Petya wants to determine whether it is possible to cut the square in the required manner given the sizes of the square side and the coordinates of the marked cell. Help him.", "input_spec": "The first line contains three space-separated integers 2n, x and y (2\u2009\u2264\u20092n\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20092n), representing the length of a square's side and the coordinates of the marked cell. It is guaranteed that 2n is even. The coordinates of the marked cell are represented by a pair of numbers x y, where x represents the number of the row and y represents the number of the column. The rows and columns are numbered by consecutive integers from 1 to 2n. The rows are numbered from top to bottom and the columns are numbered from the left to the right.", "output_spec": "If the square is possible to cut, print \"YES\", otherwise print \"NO\" (without the quotes).", "sample_inputs": ["4 1 1", "2 2 2"], "sample_outputs": ["YES", "NO"], "notes": "NoteA sample test from the statement and one of the possible ways of cutting the square are shown in the picture: "}, "src_uid": "dc891d57bcdad3108dcb4ccf9c798789"} {"nl": {"description": "Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length \u221e (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.Now you are going to take part in Shapur's contest. See if you are faster and more accurate.", "input_spec": "There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.", "output_spec": "Write one line \u2014 the corresponding answer. Do not omit the leading 0s.", "sample_inputs": ["1010100\n0100101", "000\n111", "1110\n1010", "01110\n01100"], "sample_outputs": ["1110001", "111", "0100", "00010"], "notes": null}, "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"nl": {"description": "Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: To make a \"red bouquet\", it needs 3 red flowers. To make a \"green bouquet\", it needs 3 green flowers. To make a \"blue bouquet\", it needs 3 blue flowers. To make a \"mixing bouquet\", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make.", "input_spec": "The first line contains three integers r, g and b (0\u2009\u2264\u2009r,\u2009g,\u2009b\u2009\u2264\u2009109) \u2014 the number of red, green and blue flowers.", "output_spec": "Print the maximal number of bouquets Fox Ciel can make.", "sample_inputs": ["3 6 9", "4 4 4", "0 0 0"], "sample_outputs": ["6", "4", "0"], "notes": "NoteIn test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet."}, "src_uid": "acddc9b0db312b363910a84bd4f14d8e"} {"nl": {"description": "Let's denote a function $$$f(x)$$$ in such a way: we add $$$1$$$ to $$$x$$$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, $$$f(599) = 6$$$: $$$599 + 1 = 600 \\rightarrow 60 \\rightarrow 6$$$; $$$f(7) = 8$$$: $$$7 + 1 = 8$$$; $$$f(9) = 1$$$: $$$9 + 1 = 10 \\rightarrow 1$$$; $$$f(10099) = 101$$$: $$$10099 + 1 = 10100 \\rightarrow 1010 \\rightarrow 101$$$. We say that some number $$$y$$$ is reachable from $$$x$$$ if we can apply function $$$f$$$ to $$$x$$$ some (possibly zero) times so that we get $$$y$$$ as a result. For example, $$$102$$$ is reachable from $$$10098$$$ because $$$f(f(f(10098))) = f(f(10099)) = f(101) = 102$$$; and any number is reachable from itself.You are given a number $$$n$$$; your task is to count how many different numbers are reachable from $$$n$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).", "output_spec": "Print one integer: the number of different numbers that are reachable from $$$n$$$.", "sample_inputs": ["1098", "10"], "sample_outputs": ["20", "19"], "notes": "NoteThe numbers that are reachable from $$$1098$$$ are:$$$1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099$$$."}, "src_uid": "055fbbde4b9ffd4473e6e716da6da899"} {"nl": {"description": "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\u2009+\u20091 consecutive ones, and then k consecutive zeroes.Some examples of beautiful numbers: 12 (110); 1102 (610); 11110002 (12010); 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer k such that the number is equal to (2k\u2009-\u20091)\u2009*\u2009(2k\u2009-\u20091).Luba has got an integer number n, and she wants to find its greatest beautiful divisor. Help her to find it!", "input_spec": "The only line of input contains one number n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number Luba has got.", "output_spec": "Output one number \u2014 the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.", "sample_inputs": ["3", "992"], "sample_outputs": ["1", "496"], "notes": null}, "src_uid": "339246a1be81aefe19290de0d1aead84"} {"nl": {"description": "You have a given integer $$$n$$$. Find the number of ways to fill all $$$3 \\times n$$$ tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap. This picture describes when $$$n = 4$$$. The left one is the shape and the right one is $$$3 \\times n$$$ tiles. ", "input_spec": "The only line contains one integer $$$n$$$ ($$$1 \\le n \\le 60$$$)\u00a0\u2014 the length.", "output_spec": "Print the number of ways to fill.", "sample_inputs": ["4", "1"], "sample_outputs": ["4", "0"], "notes": "NoteIn the first example, there are $$$4$$$ possible cases of filling.In the second example, you cannot fill the shapes in $$$3 \\times 1$$$ tiles."}, "src_uid": "4b7ff467ed5907e32fd529fb39b708db"} {"nl": {"description": "Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.", "input_spec": "The only line contains 14 integers $$$a_1, a_2, \\ldots, a_{14}$$$ ($$$0 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\\leq i \\leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.", "output_spec": "Output one integer, the maximum possible score after one move.", "sample_inputs": ["0 1 1 0 0 0 0 0 0 7 0 0 0 0", "5 1 1 1 1 0 0 0 0 0 0 0 0 0"], "sample_outputs": ["4", "8"], "notes": "NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$."}, "src_uid": "1ac11153e35509e755ea15f1d57d156b"} {"nl": {"description": "One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on.Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1,\u2009t2,\u2009...,\u2009tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n\u2009-\u20091 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time\u00a0\u2014 it is allowed and such parts do not crash.Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells?", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200930)\u00a0\u2014 the total depth of the recursion. The second line contains n integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20095). On the i-th level each of 2i\u2009-\u20091 parts will cover ti cells before exploding.", "output_spec": "Print one integer, denoting the number of cells which will be visited at least once by any part of the firework.", "sample_inputs": ["4\n4 2 2 3", "6\n1 1 1 1 1 3", "1\n3"], "sample_outputs": ["39", "85", "3"], "notes": "NoteFor the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1\u2009=\u20094 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4\u2009+\u20094\u2009+\u20098\u2009+\u200923\u2009=\u200939. For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. "}, "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9"} {"nl": {"description": "InputThe input contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u200930).OutputOutput a single integer.ExampleInput3Output27", "input_spec": "The input contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u200930).", "output_spec": "Output a single integer.", "sample_inputs": ["3"], "sample_outputs": ["27"], "notes": null}, "src_uid": "bf65a25185e9ea5b71e853723b838b04"} {"nl": {"description": "You are given two set of points. The first set is determined by the equation A1x\u2009+\u2009B1y\u2009+\u2009C1\u2009=\u20090, and the second one is determined by the equation A2x\u2009+\u2009B2y\u2009+\u2009C2\u2009=\u20090.Write the program which finds the number of points in the intersection of two given sets.", "input_spec": "The first line of the input contains three integer numbers A1,\u2009B1,\u2009C1 separated by space. The second line contains three integer numbers A2,\u2009B2,\u2009C2 separated by space. All the numbers are between -100 and 100, inclusive.", "output_spec": "Print the number of points in the intersection or -1 if there are infinite number of points.", "sample_inputs": ["1 1 0\n2 2 0", "1 1 0\n2 -2 0"], "sample_outputs": ["-1", "1"], "notes": null}, "src_uid": "c8e869cb17550e888733551c749f2e1a"} {"nl": {"description": "Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed: i := (s div 50) mod 475repeat 25 times: i := (i * 96 + 42) mod 475 print (26 + i)Here \"div\" is the integer division operator, \"mod\" is the modulo (the remainder of division) operator.As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.You're in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?", "input_spec": "The only line contains three integers p, x and y (26\u2009\u2264\u2009p\u2009\u2264\u2009500; 1\u2009\u2264\u2009y\u2009\u2264\u2009x\u2009\u2264\u200920000)\u00a0\u2014 your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.", "output_spec": "Output a single integer\u00a0\u2014 the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt. It's guaranteed that your goal is achievable for any valid input data.", "sample_inputs": ["239 10880 9889", "26 7258 6123", "493 8000 8000", "101 6800 6500", "329 19913 19900"], "sample_outputs": ["0", "2", "24", "0", "8"], "notes": "NoteIn the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: 475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt."}, "src_uid": "c9c22e03c70a94a745b451fc79e112fd"} {"nl": {"description": "Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has a, b, c, a, b and c adjacent tiles, correspondingly.To better visualize the situation, look at the picture showing a similar hexagon for a\u2009=\u20092, b\u2009=\u20093 and c\u2009=\u20094. According to the legend, as the King of Berland obtained the values a, b and c, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?", "input_spec": "The first line contains three integers: a, b and c (2\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20091000).", "output_spec": "Print a single number \u2014 the total number of tiles on the hall floor.", "sample_inputs": ["2 3 4"], "sample_outputs": ["18"], "notes": null}, "src_uid": "8ab25ed4955d978fe20f6872cb94b0da"} {"nl": {"description": "Vasily the bear has a favorite rectangle, it has one vertex at point (0,\u20090), and the opposite vertex at point (x,\u2009y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point B\u2009=\u2009(0,\u20090). That's why today he asks you to find two points A\u2009=\u2009(x1,\u2009y1) and C\u2009=\u2009(x2,\u2009y2), such that the following conditions hold: the coordinates of points: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1\u2009<\u2009x2; the triangle formed by point A, B and C is rectangular and isosceles ( is right); all points of the favorite rectangle are located inside or on the border of triangle ABC; the area of triangle ABC is as small as possible. Help the bear, find the required points. It is not so hard to proof that these points are unique.", "input_spec": "The first line contains two integers x,\u2009y (\u2009-\u2009109\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009109,\u2009x\u2009\u2260\u20090,\u2009y\u2009\u2260\u20090).", "output_spec": "Print in the single line four integers x1,\u2009y1,\u2009x2,\u2009y2 \u2014 the coordinates of the required points.", "sample_inputs": ["10 5", "-10 5"], "sample_outputs": ["0 15 15 0", "-15 0 0 15"], "notes": "NoteFigure to the first sample"}, "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"nl": {"description": "Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1,\u2009N], and it was asked to check whether the equation AB\u2009=\u2009C is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root d(x) of the number x is the sum s(x) of all the digits of this number, if s(x)\u2009\u2264\u20099, otherwise it is d(s(x)). For example, a digital root of the number 6543 is calculated as follows: d(6543)\u2009=\u2009d(6\u2009+\u20095\u2009+\u20094\u2009+\u20093)\u2009=\u2009d(18)\u2009=\u20099. Billy has counted that the digital root of a product of numbers is equal to the digital root of the product of the factors' digital roots, i.e. d(xy)\u2009=\u2009d(d(x)d(y)). And the following solution to the problem came to his mind: to calculate the digital roots and check if this condition is met. However, Billy has doubts that this condition is sufficient. That's why he asks you to find out the amount of test examples for the given problem such that the algorithm proposed by Billy makes mistakes.", "input_spec": "The first line contains the only number N (1\u2009\u2264\u2009N\u2009\u2264\u2009106).", "output_spec": "Output one number \u2014 the amount of required A, B and C from the range [1,\u2009N].", "sample_inputs": ["4", "5"], "sample_outputs": ["2", "6"], "notes": "NoteFor the first sample the required triples are (3,\u20094,\u20093) and (4,\u20093,\u20093)."}, "src_uid": "fc133fe6353089a0ebee08dec919f608"} {"nl": {"description": "A positive integer is called a 2-3-integer, if it is equal to 2x\u00b73y 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 \u2014 are 2-3 integers, while 5, 10, 21 and 120 are not.Print the number of 2-3-integers on the given segment [l,\u2009r], i.\u00a0e. the number of sich 2-3-integers t that l\u2009\u2264\u2009t\u2009\u2264\u2009r.", "input_spec": "The only line contains two integers l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20092\u00b7109).", "output_spec": "Print a single integer the number of 2-3-integers on the segment [l,\u2009r].", "sample_inputs": ["1 10", "100 200", "1 2000000000"], "sample_outputs": ["7", "5", "326"], "notes": "NoteIn 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."}, "src_uid": "05fac54ed2064b46338bb18f897a4411"} {"nl": {"description": "To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $$$s$$$ airplanes.A group of $$$k$$$ people decided to make $$$n$$$ airplanes each. They are going to buy several packs of paper, each of them containing $$$p$$$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $$$n$$$ airplanes. How many packs should they buy?", "input_spec": "The only line contains four integers $$$k$$$, $$$n$$$, $$$s$$$, $$$p$$$ ($$$1 \\le k, n, s, p \\le 10^4$$$)\u00a0\u2014 the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.", "output_spec": "Print a single integer\u00a0\u2014 the minimum number of packs they should buy.", "sample_inputs": ["5 3 2 3", "5 3 100 1"], "sample_outputs": ["4", "5"], "notes": "NoteIn the first sample they have to buy $$$4$$$ packs of paper: there will be $$$12$$$ sheets in total, and giving $$$2$$$ sheets to each person is enough to suit everyone's needs.In the second sample they have to buy a pack for each person as they can't share sheets."}, "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"} {"nl": {"description": "Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.", "input_spec": "In the only line of input there is a string S of lowercase English letters (1\u2009\u2264\u2009|S|\u2009\u2264\u2009500)\u00a0\u2014 the identifiers of a program with removed whitespace characters.", "output_spec": "If this program can be a result of Kostya's obfuscation, print \"YES\" (without quotes), otherwise print \"NO\".", "sample_inputs": ["abacaba", "jinotega"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample case, one possible list of identifiers would be \"number string number character number string number\". Here how Kostya would obfuscate the program: replace all occurences of number with a, the result would be \"a string a character a string a\", replace all occurences of string with b, the result would be \"a b a character a b a\", replace all occurences of character with c, the result would be \"a b a c a b a\", all identifiers have been replaced, thus the obfuscation is finished."}, "src_uid": "c4551f66a781b174f95865fa254ca972"} {"nl": {"description": "The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets $$$w$$$ points, and the opposing team gets $$$0$$$ points. If the game results in a draw, both teams get $$$d$$$ points.The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played $$$n$$$ games and got $$$p$$$ points for them.You have to determine three integers $$$x$$$, $$$y$$$ and $$$z$$$ \u2014 the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple $$$(x, y, z)$$$, report about it.", "input_spec": "The first line contains four integers $$$n$$$, $$$p$$$, $$$w$$$ and $$$d$$$ $$$(1 \\le n \\le 10^{12}, 0 \\le p \\le 10^{17}, 1 \\le d < w \\le 10^{5})$$$ \u2014 the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that $$$w > d$$$, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.", "output_spec": "If there is no answer, print $$$-1$$$. Otherwise print three non-negative integers $$$x$$$, $$$y$$$ and $$$z$$$ \u2014 the number of wins, draws and losses of the team. If there are multiple possible triples $$$(x, y, z)$$$, print any of them. The numbers should meet the following conditions: $$$x \\cdot w + y \\cdot d = p$$$, $$$x + y + z = n$$$. ", "sample_inputs": ["30 60 3 1", "10 51 5 4", "20 0 15 5"], "sample_outputs": ["17 9 4", "-1", "0 0 20"], "notes": "NoteOne of the possible answers in the first example \u2014 $$$17$$$ wins, $$$9$$$ draws and $$$4$$$ losses. Then the team got $$$17 \\cdot 3 + 9 \\cdot 1 = 60$$$ points in $$$17 + 9 + 4 = 30$$$ games.In the second example the maximum possible score is $$$10 \\cdot 5 = 50$$$. Since $$$p = 51$$$, there is no answer.In the third example the team got $$$0$$$ points, so all $$$20$$$ games were lost."}, "src_uid": "503116e144d19eb953954d99c5526a7d"} {"nl": {"description": "A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7108) and integer m (1\u2009\u2264\u2009m\u2009\u2264\u200920). The i\u2009+\u20091-th line contains a pair of numbers ai and bi (1\u2009\u2264\u2009ai\u2009\u2264\u2009108,\u20091\u2009\u2264\u2009bi\u2009\u2264\u200910). All the input numbers are integer.", "output_spec": "Output the only number \u2014 answer to the problem.", "sample_inputs": ["7 3\n5 10\n2 5\n3 6", "3 3\n1 3\n2 2\n3 1"], "sample_outputs": ["62", "7"], "notes": null}, "src_uid": "c052d85e402691b05e494b5283d62679"} {"nl": {"description": "Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has).The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value.Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters \u2014 R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in.", "output_spec": "Print a single integer \u2014 the minimum number of hints that the other players should make.", "sample_inputs": ["2\nG3 G3", "4\nG4 R4 R3 B3", "5\nB1 Y1 W1 G1 R1"], "sample_outputs": ["0", "2", "4"], "notes": "NoteIn the first sample Borya already knows for each card that it is a green three.In the second sample we can show all fours and all red cards.In the third sample you need to make hints about any four colors."}, "src_uid": "3b12863997b377b47bae43566ec1a63b"} {"nl": {"description": "This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly times consecutively. In other words, array a is k-periodic, if it has period of length k.For example, any array is n-periodic, where n is the array length. Array [2,\u20091,\u20092,\u20091,\u20092,\u20091] is at the same time 2-periodic and 6-periodic and array [1,\u20092,\u20091,\u20091,\u20092,\u20091,\u20091,\u20092,\u20091] is at the same time 3-periodic and 9-periodic.For the given array a, consisting only of numbers one and two, find the minimum number of elements to change to make the array k-periodic. If the array already is k-periodic, then the required value equals 0.", "input_spec": "The first line of the input contains a pair of integers n, k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009100), where n is the length of the array and the value n is divisible by k. The second line contains the sequence of elements of the given array a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u20092), ai is the i-th element of the array.", "output_spec": "Print the minimum number of array elements we need to change to make the array k-periodic. If the array already is k-periodic, then print 0.", "sample_inputs": ["6 2\n2 1 2 2 2 1", "8 4\n1 1 2 1 1 1 2 1", "9 3\n2 1 1 1 2 1 1 1 2"], "sample_outputs": ["1", "0", "3"], "notes": "NoteIn the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2,\u20091,\u20092,\u20091,\u20092,\u20091].In the second sample, the given array already is 4-periodic.In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1,\u20091,\u20091,\u20091,\u20091,\u20091,\u20091,\u20091,\u20091] \u2014 this array is simultaneously 1-, 3- and 9-periodic."}, "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281"} {"nl": {"description": "A string is called bracket sequence if it does not contain any characters other than \"(\" and \")\". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters \"+\" and \"1\" into this sequence. For example, \"\", \"(())\" and \"()()\" are regular bracket sequences; \"))\" and \")((\" are bracket sequences (but not regular ones), and \"(a)\" and \"(1)+(1)\" are not bracket sequences at all.You have a number of strings; each string is a bracket sequence of length $$$2$$$. So, overall you have $$$cnt_1$$$ strings \"((\", $$$cnt_2$$$ strings \"()\", $$$cnt_3$$$ strings \")(\" and $$$cnt_4$$$ strings \"))\". You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length $$$2(cnt_1 + cnt_2 + cnt_3 + cnt_4)$$$. You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either.", "input_spec": "The input consists of four lines, $$$i$$$-th of them contains one integer $$$cnt_i$$$ ($$$0 \\le cnt_i \\le 10^9$$$).", "output_spec": "Print one integer: $$$1$$$ if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, $$$0$$$ otherwise.", "sample_inputs": ["3\n1\n4\n3", "0\n0\n0\n0", "1\n2\n3\n4"], "sample_outputs": ["1", "1", "0"], "notes": "NoteIn the first example it is possible to construct a string \"(())()(()((()()()())))\", which is a regular bracket sequence.In the second example it is possible to construct a string \"\", which is a regular bracket sequence."}, "src_uid": "b99578086043537297d374dc01eeb6f8"} {"nl": {"description": "It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one \u2014 into b pieces.Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: Each piece of each cake is put on some plate; Each plate contains at least one piece of cake; No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.Help Ivan to calculate this number x!", "input_spec": "The first line contains three integers n, a and b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009100, 2\u2009\u2264\u2009n\u2009\u2264\u2009a\u2009+\u2009b) \u2014 the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.", "output_spec": "Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.", "sample_inputs": ["5 2 3", "4 7 10"], "sample_outputs": ["1", "3"], "notes": "NoteIn the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3."}, "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"} {"nl": {"description": "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,\u2009b)?", "input_spec": "The first line of the input contains two integers s and x (2\u2009\u2264\u2009s\u2009\u2264\u20091012, 0\u2009\u2264\u2009x\u2009\u2264\u20091012), the sum and bitwise xor of the pair of positive integers, respectively.", "output_spec": "Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.", "sample_inputs": ["9 5", "3 3", "5 2"], "sample_outputs": ["4", "2", "0"], "notes": "NoteIn the first sample, we have the following solutions: (2,\u20097), (3,\u20096), (6,\u20093), (7,\u20092).In the second sample, the only solutions are (1,\u20092) and (2,\u20091)."}, "src_uid": "18410980789b14c128dd6adfa501aea5"} {"nl": {"description": "A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive.", "input_spec": "Input contains one integer number n (1\u2009\u2264\u2009n\u2009\u2264\u20093000).", "output_spec": "Output the amount of almost prime numbers between 1 and n, inclusive.", "sample_inputs": ["10", "21"], "sample_outputs": ["2", "8"], "notes": null}, "src_uid": "356666366625bc5358bc8b97c8d67bd5"} {"nl": {"description": "Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate.Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe?", "input_spec": "The first line contains single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100) - number of candidates. The second line contains n space-separated integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u20091000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000.", "output_spec": "Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.", "sample_inputs": ["5\n5 1 11 2 8", "4\n1 8 8 8", "2\n7 6"], "sample_outputs": ["4", "6", "0"], "notes": "NoteIn the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9,\u20091,\u20097,\u20092,\u20098 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9,\u20090,\u20098,\u20092,\u20098.In the second sample Limak will steal 2 votes from each candidate. Situation will be 7,\u20096,\u20096,\u20096.In the third sample Limak is a winner without bribing any citizen."}, "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"} {"nl": {"description": "This is an interactive problem. In the interaction section below you will find the information about flushing the output.The New Year tree of height h is a perfect binary tree with vertices numbered 1 through 2h\u2009-\u20091 in some order. In this problem we assume that h is at least 2. The drawing below shows one example New Year tree of height 3: Polar bears love decorating the New Year tree and Limak is no exception. To decorate the tree, he must first find its root, i.e. a vertex with exactly two neighbours (assuming that h\u2009\u2265\u20092). It won't be easy because Limak is a little bear and he doesn't even see the whole tree. Can you help him?There are t testcases. In each testcase, you should first read h from the input. Then you can ask at most 16 questions of format \"? x\" (without quotes), where x is an integer between 1 and 2h\u2009-\u20091, inclusive. As a reply you will get the list of neighbours of vertex x (more details in the \"Interaction\" section below). For example, for a tree on the drawing above after asking \"? 1\" you would get a response with 3 neighbours: 4, 5 and 7. Your goal is to find the index of the root y and print it in the format \"! y\". You will be able to read h for a next testcase only after printing the answer in a previous testcase and flushing the output.Each tree is fixed from the beginning and it doesn't change during your questions.", "input_spec": "The first line of the input contains a single integer t (1\u2009\u2264\u2009t\u2009\u2264\u2009500)\u00a0\u2014 the number of testcases. At the beginning of each testcase you should read from the input a single integer h (2\u2009\u2264\u2009h\u2009\u2264\u20097)\u00a0\u2014 the height of the tree. You can't read the value of h in a next testcase until you answer a previous testcase.", "output_spec": null, "sample_inputs": ["1\n3\n3\n4 5 7\n2\n1 2\n1\n2", "2\n2\n1\n3\n2\n1 2\n2\n1 2\n4\n3\n3 12 13"], "sample_outputs": ["? 1\n? 5\n? 6\n! 5", "? 1\n? 3\n? 3\n! 3\n? 6\n! 1"], "notes": "NoteIn the first sample, a tree corresponds to the drawing from the statement.In the second sample, there are two two testcases. A tree in the first testcase has height 2 and thus 3 vertices. A tree in the second testcase has height 4 and thus 15 vertices. You can see both trees on the drawing below. "}, "src_uid": "5c0db518fa326b1e405479313216426a"} {"nl": {"description": "A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. 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_spec": "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_spec": "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).", "sample_inputs": ["-o-o--", "-o---", "-o---o-", "ooo"], "sample_outputs": ["YES", "YES", "NO", "YES"], "notes": null}, "src_uid": "6e006ae3df3bcd24755358a5f584ec03"} {"nl": {"description": "Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.", "input_spec": "The first line contains a non-empty string s \u2014 the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters \"+\". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.", "output_spec": "Print the new sum that Xenia can count.", "sample_inputs": ["3+2+1", "1+1+3+1+3", "2"], "sample_outputs": ["1+2+3", "1+1+1+3+3", "2"], "notes": null}, "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"} {"nl": {"description": "Lenny is playing a game on a 3\u2009\u00d7\u20093 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.", "input_spec": "The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The j-th number in the i-th row is the number of times the j-th light of the i-th row of the grid is pressed.", "output_spec": "Print three lines, each containing three characters. The j-th character of the i-th line is \"1\" if and only if the corresponding light is switched on, otherwise it's \"0\".", "sample_inputs": ["1 0 0\n0 0 0\n0 0 1", "1 0 1\n8 8 8\n2 0 3"], "sample_outputs": ["001\n010\n100", "010\n011\n100"], "notes": null}, "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6"} {"nl": {"description": "Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook.Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight.", "input_spec": "The first line contains two integers n and d (1\u2009\u2264\u2009n,\u2009d\u2009\u2264\u2009100). The next line contains integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100). The third line contains integer m (1\u2009\u2264\u2009m\u2009\u2264\u2009100).", "output_spec": "In a single line print a single integer \u2014 the answer to the problem.", "sample_inputs": ["2 1\n2 1\n2", "2 1\n2 1\n10"], "sample_outputs": ["3", "-5"], "notes": "NoteIn the first test both hooks will be used, so Sereja gets 1\u2009+\u20092\u2009=\u20093 rubles.In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3\u2009-\u20098\u2009=\u2009\u2009-\u20095."}, "src_uid": "5c21e2dd658825580522af525142397d"} {"nl": {"description": "Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.There are $$$n$$$ manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the $$$k$$$-th manhole from the left. She is thinking what to do.In one turn, Nastya can do one of the following: if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong). go to a neighboring manhole; if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves). The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it). Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.Note one time more that Nastya can open a manhole only when there are no stones onto it.", "input_spec": "The first and only line contains two integers $$$n$$$ and $$$k$$$, separated by space ($$$2 \\leq n \\leq 5000$$$, $$$1 \\leq k \\leq n$$$)\u00a0\u2014 the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the $$$n$$$ manholes. ", "output_spec": "Print a single integer\u00a0\u2014 minimum number of moves which lead Nastya to pick all the coins.", "sample_inputs": ["2 2", "4 2", "5 1"], "sample_outputs": ["6", "13", "15"], "notes": "NoteLet's consider the example where $$$n = 2$$$, $$$k = 2$$$. Nastya should play as follows: At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole. Then she opens the second manhole and pick the coin from it. Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it. So, $$$6$$$ moves are required to win."}, "src_uid": "24b02afe8d86314ec5f75a00c72af514"} {"nl": {"description": "Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5\u00b7i minutes to solve the i-th problem.Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.How many problems can Limak solve if he wants to make it to the party?", "input_spec": "The only line of the input contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u200910, 1\u2009\u2264\u2009k\u2009\u2264\u2009240)\u00a0\u2014 the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.", "output_spec": "Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.", "sample_inputs": ["3 222", "4 190", "7 1"], "sample_outputs": ["2", "4", "7"], "notes": "NoteIn the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5\u2009+\u200910\u2009=\u200915 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.In the second sample, Limak can solve all 4 problems in 5\u2009+\u200910\u2009+\u200915\u2009+\u200920\u2009=\u200950 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems."}, "src_uid": "41e554bc323857be7b8483ee358a35e2"} {"nl": {"description": "The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n\u2009-\u20091 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to n in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house n, house 3 is opposite house n\u2009-\u20092, house 5 is opposite house n\u2009-\u20094 and so on. Vasya needs to get to house number a as quickly as possible. He starts driving from the beginning of the street and drives his car to house a. To get from the beginning of the street to houses number 1 and n, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.Your task is: find the minimum time Vasya needs to reach house a.", "input_spec": "The first line of the input contains two integers, n and a (1\u2009\u2264\u2009a\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number n is even.", "output_spec": "Print a single integer \u2014 the minimum time Vasya needs to get from the beginning of the street to house a.", "sample_inputs": ["4 2", "8 5"], "sample_outputs": ["2", "3"], "notes": "NoteIn the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.The second sample corresponds to picture with n\u2009=\u20098. House 5 is the one before last at Vasya's left."}, "src_uid": "aa62dcdc47d0abbba7956284c1561de8"} {"nl": {"description": "After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.In the grid shown below, n\u2009=\u20093 and m\u2009=\u20093. There are n\u2009+\u2009m\u2009=\u20096 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n\u00b7m\u2009=\u20099 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).Assume that both players play optimally. Who will win the game?", "input_spec": "The first line of input contains two space-separated integers, n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100).", "output_spec": "Print a single line containing \"Akshat\" or \"Malvika\" (without the quotes), depending on the winner of the game.", "sample_inputs": ["2 2", "2 3", "3 3"], "sample_outputs": ["Malvika", "Malvika", "Akshat"], "notes": "NoteExplanation of the first sample:The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1\u2009-\u20092 and 1\u2009-\u20093). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.In the empty grid, Akshat cannot make any move, hence he will lose.Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks."}, "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"nl": {"description": "Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.More formally, you are given an array s1,\u2009s2,\u2009...,\u2009sn of zeros and ones. Zero corresponds to an unsuccessful game, one \u2014 to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.", "input_spec": "The first line contains one integer number n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). The second line contains n space-separated integer numbers s1,\u2009s2,\u2009...,\u2009sn (0\u2009\u2264\u2009si\u2009\u2264\u20091). 0 corresponds to an unsuccessful game, 1 \u2014 to a successful one.", "output_spec": "Print one integer \u2014 the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.", "sample_inputs": ["4\n1 1 0 1", "6\n0 1 0 0 1 0", "1\n0"], "sample_outputs": ["3", "4", "1"], "notes": null}, "src_uid": "c7b1f0b40e310f99936d1c33e4816b95"} {"nl": {"description": "Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left.For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings \"131\" and \"002010200\", respectively, which are palindromes.You are given some integer number x. Check if it's a quasi-palindromic number.", "input_spec": "The first line contains one integer number x (1\u2009\u2264\u2009x\u2009\u2264\u2009109). This number is given without any leading zeroes.", "output_spec": "Print \"YES\" if number x is quasi-palindromic. Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["131", "320", "2010200"], "sample_outputs": ["YES", "NO", "YES"], "notes": null}, "src_uid": "d82278932881e3aa997086c909f29051"} {"nl": {"description": "One day, $$$n$$$ people ($$$n$$$ is an even number) met on a plaza and made two round dances, each round dance consists of exactly $$$\\frac{n}{2}$$$ people. Your task is to find the number of ways $$$n$$$ people can make two round dances if each round dance consists of exactly $$$\\frac{n}{2}$$$ people. Each person should belong to exactly one of these two round dances.Round dance is a dance circle consisting of $$$1$$$ or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances $$$[1, 3, 4, 2]$$$, $$$[4, 2, 1, 3]$$$ and $$$[2, 1, 3, 4]$$$ are indistinguishable.For example, if $$$n=2$$$ then the number of ways is $$$1$$$: one round dance consists of the first person and the second one of the second person.For example, if $$$n=4$$$ then the number of ways is $$$3$$$. Possible options: one round dance \u2014 $$$[1,2]$$$, another \u2014 $$$[3,4]$$$; one round dance \u2014 $$$[2,4]$$$, another \u2014 $$$[3,1]$$$; one round dance \u2014 $$$[4,1]$$$, another \u2014 $$$[3,2]$$$. Your task is to find the number of ways $$$n$$$ people can make two round dances if each round dance consists of exactly $$$\\frac{n}{2}$$$ people.", "input_spec": "The input contains one integer $$$n$$$ ($$$2 \\le n \\le 20$$$), $$$n$$$ is an even number.", "output_spec": "Print one integer \u2014 the number of ways to make two round dances. It is guaranteed that the answer fits in the $$$64$$$-bit integer data type.", "sample_inputs": ["2", "4", "8", "20"], "sample_outputs": ["1", "3", "1260", "12164510040883200"], "notes": null}, "src_uid": "ad0985c56a207f76afa2ecd642f56728"} {"nl": {"description": "Valera has got n domino pieces in a row. Each piece consists of two halves \u2014 the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi,\u2009yi (1\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u20096). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.", "output_spec": "Print a single number \u2014 the minimum required number of seconds. If Valera can't do the task in any time, print \u2009-\u20091.", "sample_inputs": ["2\n4 2\n6 4", "1\n2 3", "3\n1 4\n2 3\n4 4"], "sample_outputs": ["0", "-1", "1"], "notes": "NoteIn the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8."}, "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"} {"nl": {"description": "You are given two lists of non-zero digits.Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20099) \u2014 the lengths of the first and the second lists, respectively. The second line contains n distinct digits a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u20099) \u2014 the elements of the first list. The third line contains m distinct digits b1,\u2009b2,\u2009...,\u2009bm (1\u2009\u2264\u2009bi\u2009\u2264\u20099) \u2014 the elements of the second list.", "output_spec": "Print the smallest pretty integer.", "sample_inputs": ["2 3\n4 2\n5 7 6", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1"], "sample_outputs": ["25", "1"], "notes": "NoteIn the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer."}, "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"} {"nl": {"description": "InputThe input contains two integers a1,\u2009a2 (0\u2009\u2264\u2009ai\u2009\u2264\u2009109), separated by a single space.OutputOutput a single integer.ExamplesInput3 14Output44Input27 12Output48Input100 200Output102", "input_spec": "The input contains two integers a1,\u2009a2 (0\u2009\u2264\u2009ai\u2009\u2264\u2009109), separated by a single space.", "output_spec": "Output a single integer.", "sample_inputs": ["3 14", "27 12", "100 200"], "sample_outputs": ["44", "48", "102"], "notes": null}, "src_uid": "69b219054cad0844fc4f15df463e09c0"} {"nl": {"description": "A and B are preparing themselves for programming contests.An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants.A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.There are n experienced members and m newbies on the training session. Can you calculate what maximum number of teams can be formed?", "input_spec": "The first line contains two integers n and m (0\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20095\u00b7105) \u2014 the number of experienced participants and newbies that are present at the training session. ", "output_spec": "Print the maximum number of teams that can be formed.", "sample_inputs": ["2 6", "4 5"], "sample_outputs": ["2", "3"], "notes": "NoteLet's represent the experienced players as XP and newbies as NB.In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB)."}, "src_uid": "0718c6afe52cd232a5e942052527f31b"} {"nl": {"description": "The only difference between easy and hard versions is constraints.Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $$$T$$$ minutes.In the player, Polycarp stores $$$n$$$ songs, each of which is characterized by two parameters: $$$t_i$$$ and $$$g_i$$$, where $$$t_i$$$ is the length of the song in minutes ($$$1 \\le t_i \\le 15$$$), $$$g_i$$$ is its genre ($$$1 \\le g_i \\le 3$$$).Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the $$$i$$$-th song, he would spend exactly $$$t_i$$$ minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly $$$T$$$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$T$$$ ($$$1 \\le n \\le 15, 1 \\le T \\le 225$$$) \u2014 the number of songs in the player and the required total duration, respectively. Next, the $$$n$$$ lines contain descriptions of songs: the $$$i$$$-th line contains two integers $$$t_i$$$ and $$$g_i$$$ ($$$1 \\le t_i \\le 15, 1 \\le g_i \\le 3$$$) \u2014 the duration of the $$$i$$$-th song and its genre, respectively.", "output_spec": "Output one integer \u2014 the number of different sequences of songs, the total length of exactly $$$T$$$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo $$$10^9 + 7$$$ (that is, the remainder when dividing the quantity by $$$10^9 + 7$$$).", "sample_inputs": ["3 3\n1 1\n1 2\n1 3", "3 3\n1 1\n1 1\n1 3", "4 10\n5 3\n2 1\n3 2\n5 1"], "sample_outputs": ["6", "2", "10"], "notes": "NoteIn the first example, Polycarp can make any of the $$$6$$$ possible playlist by rearranging the available songs: $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 2]$$$ and $$$[3, 2, 1]$$$ (indices of the songs are given).In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of $$$2$$$ possible ways: $$$[1, 3, 2]$$$ and $$$[2, 3, 1]$$$ (indices of the songs are given).In the third example, Polycarp can make the following playlists: $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 2]$$$, $$$[3, 2, 1]$$$, $$$[1, 4]$$$, $$$[4, 1]$$$, $$$[2, 3, 4]$$$ and $$$[4, 3, 2]$$$ (indices of the songs are given)."}, "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56"} {"nl": {"description": "An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x\u2009>\u20090) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.", "input_spec": "The first line of the input contains an integer x (1\u2009\u2264\u2009x\u2009\u2264\u20091\u2009000\u2009000)\u00a0\u2014 The coordinate of the friend's house.", "output_spec": "Print the minimum number of steps that elephant needs to make to get from point 0 to point x.", "sample_inputs": ["5", "12"], "sample_outputs": ["1", "3"], "notes": "NoteIn the first sample the elephant needs to make one step of length 5 to reach the point x.In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves."}, "src_uid": "4b3d65b1b593829e92c852be213922b6"} {"nl": {"description": "Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,\u20090) and Varda's home is located in point (a,\u2009b). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (x,\u2009y) he can go to positions (x\u2009+\u20091,\u2009y), (x\u2009-\u20091,\u2009y), (x,\u2009y\u2009+\u20091) or (x,\u2009y\u2009-\u20091). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (a,\u2009b) and continue travelling. Luckily, Drazil arrived to the position (a,\u2009b) successfully. Drazil said to Varda: \"It took me exactly s steps to travel from my house to yours\". But Varda is confused about his words, she is not sure that it is possible to get from (0,\u20090) to (a,\u2009b) in exactly s steps. Can you find out if it is possible for Varda?", "input_spec": "You are given three integers a, b, and s (\u2009-\u2009109\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109, 1\u2009\u2264\u2009s\u2009\u2264\u20092\u00b7109) in a single line.", "output_spec": "If you think Drazil made a mistake and it is impossible to take exactly s steps and get from his home to Varda's home, print \"No\" (without quotes). Otherwise, print \"Yes\".", "sample_inputs": ["5 5 11", "10 15 25", "0 5 1", "0 0 2"], "sample_outputs": ["No", "Yes", "No", "Yes"], "notes": "NoteIn fourth sample case one possible route is: ."}, "src_uid": "9a955ce0775018ff4e5825700c13ed36"} {"nl": {"description": "The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug \u2014 the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.", "input_spec": "The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.", "output_spec": "In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).", "sample_inputs": ["LLUUUR", "RRUULLDD"], "sample_outputs": ["OK", "BUG"], "notes": null}, "src_uid": "bb7805cc9d1cc907b64371b209c564b3"} {"nl": {"description": "Natasha is planning an expedition to Mars for $$$n$$$ people. One of the important tasks is to provide food for each participant.The warehouse has $$$m$$$ daily food packages. Each package has some food type $$$a_i$$$.Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.Formally, for each participant $$$j$$$ Natasha should select his food type $$$b_j$$$ and each day $$$j$$$-th participant will eat one food package of type $$$b_j$$$. The values $$$b_j$$$ for different participants may be different.What is the maximum possible number of days the expedition can last, following the requirements above?", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le m \\le 100$$$)\u00a0\u2014 the number of the expedition participants and the number of the daily food packages available. The second line contains sequence of integers $$$a_1, a_2, \\dots, a_m$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the type of $$$i$$$-th food package.", "output_spec": "Print the single integer\u00a0\u2014 the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.", "sample_inputs": ["4 10\n1 5 2 1 1 1 2 5 7 2", "100 1\n1", "2 5\n5 4 3 2 1", "3 9\n42 42 42 42 42 42 42 42 42"], "sample_outputs": ["2", "0", "1", "3"], "notes": "NoteIn the first example, Natasha can assign type $$$1$$$ food to the first participant, the same type $$$1$$$ to the second, type $$$5$$$ to the third and type $$$2$$$ to the fourth. In this case, the expedition can last for $$$2$$$ days, since each participant can get two food packages of his food type (there will be used $$$4$$$ packages of type $$$1$$$, two packages of type $$$2$$$ and two packages of type $$$5$$$).In the second example, there are $$$100$$$ participants and only $$$1$$$ food package. In this case, the expedition can't last even $$$1$$$ day."}, "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"nl": {"description": "Recently you have received two positive integer numbers $$$x$$$ and $$$y$$$. You forgot them, but you remembered a shuffled list containing all divisors of $$$x$$$ (including $$$1$$$ and $$$x$$$) and all divisors of $$$y$$$ (including $$$1$$$ and $$$y$$$). If $$$d$$$ is a divisor of both numbers $$$x$$$ and $$$y$$$ at the same time, there are two occurrences of $$$d$$$ in the list.For example, if $$$x=4$$$ and $$$y=6$$$ then the given list can be any permutation of the list $$$[1, 2, 4, 1, 2, 3, 6]$$$. Some of the possible lists are: $$$[1, 1, 2, 4, 6, 3, 2]$$$, $$$[4, 6, 1, 1, 2, 3, 2]$$$ or $$$[1, 6, 3, 2, 4, 1, 2]$$$.Your problem is to restore suitable positive integer numbers $$$x$$$ and $$$y$$$ that would yield the same list of divisors (possibly in different order).It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers $$$x$$$ and $$$y$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 128$$$) \u2014 the number of divisors of $$$x$$$ and $$$y$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \\dots, d_n$$$ ($$$1 \\le d_i \\le 10^4$$$), where $$$d_i$$$ is either divisor of $$$x$$$ or divisor of $$$y$$$. If a number is divisor of both numbers $$$x$$$ and $$$y$$$ then there are two copies of this number in the list.", "output_spec": "Print two positive integer numbers $$$x$$$ and $$$y$$$ \u2014 such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.", "sample_inputs": ["10\n10 2 8 1 2 4 1 20 4 5"], "sample_outputs": ["20 8"], "notes": null}, "src_uid": "868407df0a93085057d06367aecaf9be"} {"nl": {"description": "There are a lot of things which could be cut\u00a0\u2014 trees, paper, \"the rope\". In this problem you are going to cut a sequence of integers.There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $$$[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$$$ $$$\\to$$$ two cuts $$$\\to$$$ $$$[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$$$. On each segment the number of even elements should be equal to the number of odd elements.The cost of the cut between $$$x$$$ and $$$y$$$ numbers is $$$|x - y|$$$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $$$B$$$ bitcoins.", "input_spec": "First line of the input contains an integer $$$n$$$ ($$$2 \\le n \\le 100$$$) and an integer $$$B$$$ ($$$1 \\le B \\le 100$$$)\u00a0\u2014 the number of elements in the sequence and the number of bitcoins you have. Second line contains $$$n$$$ integers: $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \\le a_i \\le 100$$$)\u00a0\u2014 elements of the sequence, which contains the equal number of even and odd numbers", "output_spec": "Print the maximum possible number of cuts which can be made while spending no more than $$$B$$$ bitcoins.", "sample_inputs": ["6 4\n1 2 5 10 15 20", "4 10\n1 3 2 4", "6 100\n1 2 3 4 5 6"], "sample_outputs": ["1", "0", "2"], "notes": "NoteIn the first sample the optimal answer is to split sequence between $$$2$$$ and $$$5$$$. Price of this cut is equal to $$$3$$$ bitcoins.In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.In the third sample the sequence should be cut between $$$2$$$ and $$$3$$$, and between $$$4$$$ and $$$5$$$. The total price of the cuts is $$$1 + 1 = 2$$$ bitcoins."}, "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"} {"nl": {"description": "Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh:\u2009mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh:\u2009mm is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.A time is considered lucky if it contains a digit '7'. For example, 13:\u200907 and 17:\u200927 are lucky, while 00:\u200948 and 21:\u200934 are not lucky.Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at hh:\u2009mm.Formally, find the smallest possible non-negative integer y such that the time representation of the time x\u00b7y minutes before hh:\u2009mm contains the digit '7'.Jamie uses 24-hours clock, so after 23:\u200959 comes 00:\u200900.", "input_spec": "The first line contains a single integer x (1\u2009\u2264\u2009x\u2009\u2264\u200960). The second line contains two two-digit integers, hh and mm (00\u2009\u2264\u2009hh\u2009\u2264\u200923,\u200900\u2009\u2264\u2009mm\u2009\u2264\u200959).", "output_spec": "Print the minimum number of times he needs to press the button.", "sample_inputs": ["3\n11 23", "5\n01 07"], "sample_outputs": ["2", "0"], "notes": "NoteIn the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky."}, "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"} {"nl": {"description": "Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite \"Le Hamburger de Polycarpus\" as a string of letters 'B' (bread), 'S' (sausage) \u0438 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe \"\u0412SCBS\" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.", "input_spec": "The first line of the input contains a non-empty string that describes the recipe of \"Le Hamburger de Polycarpus\". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers nb, ns, nc (1\u2009\u2264\u2009nb,\u2009ns,\u2009nc\u2009\u2264\u2009100) \u2014 the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pb, ps, pc (1\u2009\u2264\u2009pb,\u2009ps,\u2009pc\u2009\u2264\u2009100) \u2014 the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1\u2009\u2264\u2009r\u2009\u2264\u20091012) \u2014 the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.", "sample_inputs": ["BBBSSC\n6 4 1\n1 2 3\n4", "BBC\n1 10 1\n1 10 1\n21", "BSC\n1 1 1\n1 1 3\n1000000000000"], "sample_outputs": ["2", "7", "200000000001"], "notes": null}, "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"} {"nl": {"description": "Ayoub had an array $$$a$$$ of integers of size $$$n$$$ and this array had two interesting properties: All the integers in the array were between $$$l$$$ and $$$r$$$ (inclusive). The sum of all the elements was divisible by $$$3$$$. Unfortunately, Ayoub has lost his array, but he remembers the size of the array $$$n$$$ and the numbers $$$l$$$ and $$$r$$$, so he asked you to find the number of ways to restore the array. Since the answer could be very large, print it modulo $$$10^9 + 7$$$ (i.e. the remainder when dividing by $$$10^9 + 7$$$). In case there are no satisfying arrays (Ayoub has a wrong memory), print $$$0$$$.", "input_spec": "The first and only line contains three integers $$$n$$$, $$$l$$$ and $$$r$$$ ($$$1 \\le n \\le 2 \\cdot 10^5 , 1 \\le l \\le r \\le 10^9$$$)\u00a0\u2014 the size of the lost array and the range of numbers in the array.", "output_spec": "Print the remainder when dividing by $$$10^9 + 7$$$ the number of ways to restore the array.", "sample_inputs": ["2 1 3", "3 2 2", "9 9 99"], "sample_outputs": ["3", "1", "711426616"], "notes": "NoteIn the first example, the possible arrays are : $$$[1,2], [2,1], [3, 3]$$$.In the second example, the only possible array is $$$[2, 2, 2]$$$."}, "src_uid": "4c4852df62fccb0a19ad8bc41145de61"} {"nl": {"description": "Recall that the permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).A sequence $$$a$$$ is a subsegment of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as $$$[l, r]$$$, where $$$l, r$$$ are two integers with $$$1 \\le l \\le r \\le n$$$. This indicates the subsegment where $$$l-1$$$ elements from the beginning and $$$n-r$$$ elements from the end are deleted from the sequence.For a permutation $$$p_1, p_2, \\ldots, p_n$$$, we define a framed segment as a subsegment $$$[l,r]$$$ where $$$\\max\\{p_l, p_{l+1}, \\dots, p_r\\} - \\min\\{p_l, p_{l+1}, \\dots, p_r\\} = r - l$$$. For example, for the permutation $$$(6, 7, 1, 8, 5, 3, 2, 4)$$$ some of its framed segments are: $$$[1, 2], [5, 8], [6, 7], [3, 3], [8, 8]$$$. In particular, a subsegment $$$[i,i]$$$ is always a framed segments for any $$$i$$$ between $$$1$$$ and $$$n$$$, inclusive.We define the happiness of a permutation $$$p$$$ as the number of pairs $$$(l, r)$$$ such that $$$1 \\le l \\le r \\le n$$$, and $$$[l, r]$$$ is a framed segment. For example, the permutation $$$[3, 1, 2]$$$ has happiness $$$5$$$: all segments except $$$[1, 2]$$$ are framed segments.Given integers $$$n$$$ and $$$m$$$, Jongwon wants to compute the sum of happiness for all permutations of length $$$n$$$, modulo the prime number $$$m$$$. Note that there exist $$$n!$$$ (factorial of $$$n$$$) different permutations of length $$$n$$$.", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 250\\,000$$$, $$$10^8 \\le m \\le 10^9$$$, $$$m$$$ is prime).", "output_spec": "Print $$$r$$$ ($$$0 \\le r < m$$$), the sum of happiness for all permutations of length $$$n$$$, modulo a prime number $$$m$$$.", "sample_inputs": ["1 993244853", "2 993244853", "3 993244853", "2019 993244853", "2020 437122297"], "sample_outputs": ["1", "6", "32", "923958830", "265955509"], "notes": "NoteFor sample input $$$n=3$$$, let's consider all permutations of length $$$3$$$: $$$[1, 2, 3]$$$, all subsegments are framed segment. Happiness is $$$6$$$. $$$[1, 3, 2]$$$, all subsegments except $$$[1, 2]$$$ are framed segment. Happiness is $$$5$$$. $$$[2, 1, 3]$$$, all subsegments except $$$[2, 3]$$$ are framed segment. Happiness is $$$5$$$. $$$[2, 3, 1]$$$, all subsegments except $$$[2, 3]$$$ are framed segment. Happiness is $$$5$$$. $$$[3, 1, 2]$$$, all subsegments except $$$[1, 2]$$$ are framed segment. Happiness is $$$5$$$. $$$[3, 2, 1]$$$, all subsegments are framed segment. Happiness is $$$6$$$. Thus, the sum of happiness is $$$6+5+5+5+5+6 = 32$$$."}, "src_uid": "020d5dae7157d937c3f58554c9b155f9"} {"nl": {"description": "Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: After the cutting each ribbon piece should have length a, b or c. After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.", "input_spec": "The first line contains four space-separated integers n, a, b and c (1\u2009\u2264\u2009n,\u2009a,\u2009b,\u2009c\u2009\u2264\u20094000) \u2014 the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.", "output_spec": "Print a single number \u2014 the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.", "sample_inputs": ["5 5 3 2", "7 5 5 2"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2."}, "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"nl": {"description": "Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.How many times can Artem give presents to Masha?", "input_spec": "The only line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109)\u00a0\u2014 number of stones Artem received on his birthday.", "output_spec": "Print the maximum possible number of times Artem can give presents to Masha.", "sample_inputs": ["1", "2", "3", "4"], "sample_outputs": ["1", "1", "2", "3"], "notes": "NoteIn the first sample, Artem can only give 1 stone to Masha.In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again."}, "src_uid": "a993069e35b35ae158d35d6fe166aaef"} {"nl": {"description": "Jzzhu has a big rectangular chocolate bar that consists of n\u2009\u00d7\u2009m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5\u2009\u00d7\u20096 chocolate for 5 times. Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.", "input_spec": "A single line contains three integers n,\u2009m,\u2009k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009109;\u00a01\u2009\u2264\u2009k\u2009\u2264\u20092\u00b7109).", "output_spec": "Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.", "sample_inputs": ["3 4 1", "6 4 2", "2 3 4"], "sample_outputs": ["6", "8", "-1"], "notes": "NoteIn the first sample, Jzzhu can cut the chocolate following the picture below: In the second sample the optimal division looks like this: In the third sample, it's impossible to cut a 2\u2009\u00d7\u20093 chocolate 4 times."}, "src_uid": "bb453bbe60769bcaea6a824c72120f73"} {"nl": {"description": "Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card?", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200)\u00a0\u2014 the total number of cards. The next line contains a string s of length n \u2014 the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.", "output_spec": "Print a single string of up to three characters\u00a0\u2014 the possible colors of the final card (using the same symbols as the input) in alphabetical order.", "sample_inputs": ["2\nRB", "3\nGRG", "5\nBBBBB"], "sample_outputs": ["G", "BR", "B"], "notes": "NoteIn the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards."}, "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"} {"nl": {"description": "Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.", "input_spec": "The single line contains two integers, a and b (1\u2009\u2264\u2009a\u2009\u2264\u20091000;\u00a02\u2009\u2264\u2009b\u2009\u2264\u20091000).", "output_spec": "Print a single integer \u2014 the number of hours Vasily can light up the room for.", "sample_inputs": ["4 2", "6 3"], "sample_outputs": ["7", "8"], "notes": "NoteConsider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours."}, "src_uid": "a349094584d3fdc6b61e39bffe96dece"} {"nl": {"description": "A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.What is the minimum time for the car to get from point A to point B without breaking the traffic rules?", "input_spec": "The first line contains integers l, d, v, g, r (1\u2009\u2264\u2009l,\u2009d,\u2009v,\u2009g,\u2009r\u2009\u2264\u20091000,\u2009d\u2009<\u2009l) \u2014 the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.", "output_spec": "Output a single number \u2014 the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10\u2009-\u20096.", "sample_inputs": ["2 1 3 4 5", "5 4 3 1 1"], "sample_outputs": ["0.66666667", "2.33333333"], "notes": null}, "src_uid": "e4a4affb439365c843c9f9828d81b42c"} {"nl": {"description": "IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus.A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.", "input_spec": "The only line of the input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the prediction on the number of people who will buy the game.", "output_spec": "Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10.", "sample_inputs": ["12"], "sample_outputs": ["2"], "notes": null}, "src_uid": "e392be5411ffccc1df50e65ec1f5c589"} {"nl": {"description": "This problem's actual name, \"Lexicographically Largest Palindromic Subsequence\" is too long to fit into the page headline.You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 \u2009\u2264\u2009 p1\u2009<\u2009p2\u2009<\u2009...\u2009<\u2009pk \u2009\u2264\u2009 |s|) a subsequence of string s = s1s2... s|s|, where |s| is the length of string s. For example, strings \"abcb\", \"b\" and \"abacaba\" are subsequences of string \"abacaba\".String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| > |y| and x1\u2009=\u2009y1, x2\u2009=\u2009y2, ...,\u2009x|y|\u2009=\u2009y|y|, or there exists such number r (r\u2009<\u2009|x|, r\u2009<\u2009|y|) that x1\u2009=\u2009y1, x2\u2009=\u2009y2, ..., xr\u2009=\u2009yr and xr\u2009\u2009+\u2009\u20091\u2009>\u2009yr\u2009\u2009+\u2009\u20091. Characters in the strings are compared according to their ASCII codes. For example, string \"ranger\" is lexicographically larger than string \"racecar\" and string \"poster\" is lexicographically larger than string \"post\".String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s|\u2009-\u20091... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are \"racecar\", \"refer\" and \"z\".", "input_spec": "The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.", "output_spec": "Print the lexicographically largest palindromic subsequence of string s.", "sample_inputs": ["radar", "bowwowwow", "codeforces", "mississipp"], "sample_outputs": ["rr", "wwwww", "s", "ssss"], "notes": "NoteAmong all distinct subsequences of string \"radar\" the following ones are palindromes: \"a\", \"d\", \"r\", \"aa\", \"rr\", \"ada\", \"rar\", \"rdr\", \"raar\" and \"radar\". The lexicographically largest of them is \"rr\"."}, "src_uid": "9a40e9b122962a1f83b74ddee6246a40"} {"nl": {"description": "Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity. What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.", "input_spec": "The first line contains three integers n, m, k (1\u2009\u2264\u2009n,\u2009m,\u2009k\u2009\u2264\u200950) \u2014 the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u200950) \u2014 number ai stands for the number of sockets on the i-th supply-line filter.", "output_spec": "Print a single number \u2014 the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.", "sample_inputs": ["3 5 3\n3 1 2", "4 7 2\n3 3 2 4", "5 5 1\n1 3 1 2 1"], "sample_outputs": ["1", "2", "-1"], "notes": "NoteIn the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter."}, "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"} {"nl": {"description": "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_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u20091018, k\u2009\u2264\u2009n)\u00a0\u2014 the number of sticks drawn by Sasha and the number k\u00a0\u2014 the number of sticks to be crossed out on each turn.", "output_spec": "If Sasha wins, print \"YES\" (without quotes), otherwise print \"NO\" (without quotes). You can print each letter in arbitrary case (upper of lower).", "sample_inputs": ["1 1", "10 4"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn 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."}, "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"} {"nl": {"description": "The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: At least one participant should get a diploma. None of those with score equal to zero should get awarded. When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of participants. The next line contains a sequence of n integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u2009600)\u00a0\u2014 participants' scores. It's guaranteed that at least one participant has non-zero score.", "output_spec": "Print a single integer\u00a0\u2014 the desired number of ways.", "sample_inputs": ["4\n1 3 3 2", "3\n1 1 1", "4\n42 0 0 42"], "sample_outputs": ["3", "1", "1"], "notes": "NoteThere are three ways to choose a subset in sample case one. Only participants with 3 points will get diplomas. Participants with 2 or 3 points will get diplomas. Everyone will get a diploma! The only option in sample case two is to award everyone.Note that in sample case three participants with zero scores cannot get anything."}, "src_uid": "3b520c15ea9a11b16129da30dcfb5161"} {"nl": {"description": "Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track. Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers. Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L\u2009-\u20091, inclusively. Consider an example. Let L\u2009=\u20098, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence [2,\u20094,\u20096], and Sasha writes down [1,\u20095,\u20097]. There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks. Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction \u2014 counterclockwise, if you look on a track from above. ", "input_spec": "The first line contains two integers n and L (1\u2009\u2264\u2009n\u2009\u2264\u200950, n\u2009\u2264\u2009L\u2009\u2264\u2009100) \u2014 the number of barriers on a track and its length. The second line contains n distinct integers in the ascending order \u2014 the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to L\u2009-\u20091 inclusively. The second line contains n distinct integers in the ascending order \u2014 the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to L\u2009-\u20091 inclusively.", "output_spec": "Print \"YES\" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print \"NO\" (without quotes).", "sample_inputs": ["3 8\n2 4 6\n1 5 7", "4 9\n2 3 5 8\n0 1 3 6", "2 4\n1 3\n1 2"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteThe first test is analyzed in the statement."}, "src_uid": "3d931684ca11fe6141c6461e85d91d63"} {"nl": {"description": "In mathematics, the Pythagorean theorem \u2014 is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: \u007fIn any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:a2\u2009+\u2009b2\u2009=\u2009c2where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides. Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009c\u2009\u2264\u2009n.", "input_spec": "The only line contains one integer n\u00a0(1\u2009\u2264\u2009n\u2009\u2264\u2009104) as we mentioned above.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["5", "74"], "sample_outputs": ["1", "35"], "notes": null}, "src_uid": "36a211f7814e77339eb81dc132e115e1"} {"nl": {"description": "Cucumber boy is fan of Kyubeat, a famous music game.Kyubeat has 16 panels for playing arranged in 4\u2009\u00d7\u20094 table. When a panel lights up, he has to press that panel.Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.", "input_spec": "The first line contains a single integer k (1\u2009\u2264\u2009k\u2009\u2264\u20095) \u2014 the number of panels Cucumber boy can press with his one hand. Next 4 lines contain 4 characters each (digits from 1 to 9, or period) \u2014 table of panels. If a digit i was written on the panel, it means the boy has to press that panel in time i. If period was written on the panel, he doesn't have to press that panel.", "output_spec": "Output \"YES\" (without quotes), if he is able to press all the panels in perfect timing. If not, output \"NO\" (without quotes).", "sample_inputs": ["1\n.135\n1247\n3468\n5789", "5\n..1.\n1111\n..1.\n..1.", "1\n....\n12.1\n.2..\n.2.."], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteIn the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands."}, "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"} {"nl": {"description": "Mishka started participating in a programming contest. There are $$$n$$$ problems in the contest. Mishka's problem-solving skill is equal to $$$k$$$.Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.Mishka cannot solve a problem with difficulty greater than $$$k$$$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $$$1$$$. Mishka stops when he is unable to solve any problem from any end of the list.How many problems can Mishka solve?", "input_spec": "The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100$$$) \u2014 the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the difficulty of the $$$i$$$-th problem. The problems are given in order from the leftmost to the rightmost in the list.", "output_spec": "Print one integer \u2014 the maximum number of problems Mishka can solve.", "sample_inputs": ["8 4\n4 2 3 1 5 1 6 4", "5 2\n3 1 2 1 3", "5 100\n12 34 55 43 21"], "sample_outputs": ["5", "0", "5"], "notes": "NoteIn the first example, Mishka can solve problems in the following order: $$$[4, 2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6] \\rightarrow [3, 1, 5, 1, 6] \\rightarrow [1, 5, 1, 6] \\rightarrow [5, 1, 6]$$$, so the number of solved problems will be equal to $$$5$$$.In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $$$k$$$.In the third example, Mishka's solving skill is so amazing that he can solve all the problems."}, "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"nl": {"description": "HQ9+ is a joke programming language which has only four one-character instructions: \"H\" prints \"Hello, World!\", \"Q\" prints the source code of the program itself, \"9\" prints the lyrics of \"99 Bottles of Beer\" song, \"+\" increments the value stored in the internal accumulator.Instructions \"H\" and \"Q\" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.", "input_spec": "The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.", "output_spec": "Output \"YES\", if executing the program will produce any output, and \"NO\" otherwise.", "sample_inputs": ["Hi!", "Codeforces"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first case the program contains only one instruction \u2014 \"H\", which prints \"Hello, World!\".In the second case none of the program characters are language instructions."}, "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"} {"nl": {"description": "Little Elephant loves magic squares very much.A magic square is a 3\u2009\u00d7\u20093 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes.", "input_spec": "The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.", "output_spec": "Print three lines, in each line print three integers \u2014 the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions.", "sample_inputs": ["0 1 1\n1 0 1\n1 1 0", "0 3 6\n5 0 5\n4 7 0"], "sample_outputs": ["1 1 1\n1 1 1\n1 1 1", "6 3 6\n5 5 5\n4 7 4"], "notes": null}, "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"} {"nl": {"description": "Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.", "input_spec": "The first line of the input contains three integers d1, d2, d3 (1\u2009\u2264\u2009d1,\u2009d2,\u2009d3\u2009\u2264\u2009108)\u00a0\u2014 the lengths of the paths. d1 is the length of the path connecting Patrick's house and the first shop; d2 is the length of the path connecting Patrick's house and the second shop; d3 is the length of the path connecting both shops. ", "output_spec": "Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.", "sample_inputs": ["10 20 30", "1 1 5"], "sample_outputs": ["60", "4"], "notes": "NoteThe first sample is shown on the picture in the problem statement. One of the optimal routes is: house first shop second shop house.In the second sample one of the optimal routes is: house first shop house second shop house."}, "src_uid": "26cd7954a21866dbb2824d725473673e"} {"nl": {"description": "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_spec": "The only line contains 2 integers $$$u$$$ and $$$v$$$ $$$(0 \\le u,v \\le 10^{18})$$$.", "output_spec": "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.", "sample_inputs": ["2 4", "1 3", "8 5", "0 0"], "sample_outputs": ["2\n3 1", "3\n1 1 1", "-1", "0"], "notes": "NoteIn 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."}, "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"} {"nl": {"description": "When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? \u2014 That's right, using counting sticks! An here's our new task: An expression of counting sticks is an expression of type:[ A sticks][sign +][B sticks][sign =][C sticks] (1\u2009\u2264\u2009A,\u2009B,\u2009C). Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A\u2009+\u2009B\u2009=\u2009C.We've got an expression that looks like A\u2009+\u2009B\u2009=\u2009C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.We really aren't fabulous at arithmetics. Can you help us?", "input_spec": "The single line contains the initial expression. It is guaranteed that the expression looks like A\u2009+\u2009B\u2009=\u2009C, where 1\u2009\u2264\u2009A,\u2009B,\u2009C\u2009\u2264\u2009100.", "output_spec": "If there isn't a way to shift the stick so the expression becomes correct, print on a single line \"Impossible\" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.", "sample_inputs": ["||+|=|||||", "|||||+||=||", "|+|=||||||", "||||+||=||||||"], "sample_outputs": ["|||+|=||||", "Impossible", "Impossible", "||||+||=||||||"], "notes": "NoteIn the first sample we can shift stick from the third group of sticks to the first one.In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.There is no answer in the third sample because we cannot remove sticks from the expression.In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks."}, "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6"} {"nl": {"description": "Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.", "input_spec": "A single line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092000) \u2014 the number of buttons the lock has.", "output_spec": "In a single line print the number of times Manao has to push a button in the worst-case scenario.", "sample_inputs": ["2", "3"], "sample_outputs": ["3", "7"], "notes": "NoteConsider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes."}, "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"nl": {"description": "Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.", "input_spec": "The only line contains three integers n, a and b (0\u2009\u2264\u2009a,\u2009b\u2009<\u2009n\u2009\u2264\u2009100).", "output_spec": "Print the single number \u2014 the number of the sought positions.", "sample_inputs": ["3 1 1", "5 2 3"], "sample_outputs": ["2", "3"], "notes": "NoteThe possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).In the second sample they are 3, 4 and 5."}, "src_uid": "51a072916bff600922a77da0c4582180"} {"nl": {"description": "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_spec": "The only line contains positive integer number n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 number of candies Santa Claus has.", "output_spec": "Print to the first line integer number k \u2014 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.", "sample_inputs": ["5", "9", "2"], "sample_outputs": ["2\n2 3", "3\n3 5 1", "1\n2"], "notes": null}, "src_uid": "356a7bcebbbd354c268cddbb5454d5fc"} {"nl": {"description": "You have a set of $$$n$$$ weights. You know that their masses are $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ grams, but you don't know which of them has which mass. You can't distinguish the weights.However, your friend does know the mass of each weight. You can ask your friend to give you exactly $$$k$$$ weights with the total mass $$$m$$$ (both parameters $$$k$$$ and $$$m$$$ are chosen by you), and your friend will point to any valid subset of weights, if it is possible.You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of weights. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 100$$$)\u00a0\u2014 the masses of the weights.", "output_spec": "Print the maximum number of weights you can learn the masses for after making a single query.", "sample_inputs": ["4\n1 4 2 2", "6\n1 2 4 4 4 9"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first example we can ask for a subset of two weights with total mass being equal to $$$4$$$, and the only option is to get $$$\\{2, 2\\}$$$.Another way to obtain the same result is to ask for a subset of two weights with the total mass of $$$5$$$ and get $$$\\{1, 4\\}$$$. It is easy to see that the two remaining weights have mass of $$$2$$$ grams each.In the second example we can ask for a subset of two weights with total mass being $$$8$$$, and the only answer is $$$\\{4, 4\\}$$$. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here."}, "src_uid": "ccc4b27889598266e8efe73b8aa3666c"} {"nl": {"description": "ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?", "input_spec": "The first and only line of the input contains a single string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200950\u2009000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.", "output_spec": "If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print \u2009-\u20091 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.", "sample_inputs": ["ABC??FGHIJK???OPQR?TUVWXY?", "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO", "??????????????????????????", "AABCDEFGHIJKLMNOPQRSTUVW??M"], "sample_outputs": ["ABCDEFGHIJKLMNOPQRZTUVWXYS", "-1", "MNBVCXZLKJHGFDSAQPWOEIRUYT", "-1"], "notes": "NoteIn the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is \u2009-\u20091.In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer."}, "src_uid": "a249431a4b0b1ade652997fe0b82edf3"} {"nl": {"description": "Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips x\u2009-\u20091 consecutive bricks, then he paints the x-th one. That is, he'll paint bricks x, 2\u00b7x, 3\u00b7x and so on red. Similarly, Floyd skips y\u2009-\u20091 consecutive bricks, then he paints the y-th one. Hence he'll paint bricks y, 2\u00b7y, 3\u00b7y and so on pink.After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number a and Floyd has a lucky number b. Boys wonder how many bricks numbered no less than a and no greater than b are painted both red and pink. This is exactly your task: compute and print the answer to the question. ", "input_spec": "The input will have a single line containing four integers in this order: x, y, a, b. (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20091000, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7109, a\u2009\u2264\u2009b).", "output_spec": "Output a single integer \u2014 the number of bricks numbered no less than a and no greater than b that are painted both red and pink.", "sample_inputs": ["2 3 6 18"], "sample_outputs": ["3"], "notes": "NoteLet's look at the bricks from a to b (a\u2009=\u20096,\u2009b\u2009=\u200918). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. "}, "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"nl": {"description": "Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: \"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!\"Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.", "input_spec": "The single line contains the magic integer n, 0\u2009\u2264\u2009n. to get 20 points, you need to solve the problem with constraints: n\u2009\u2264\u2009106 (subproblem C1); to get 40 points, you need to solve the problem with constraints: n\u2009\u2264\u20091012 (subproblems C1+C2); to get 100 points, you need to solve the problem with constraints: n\u2009\u2264\u20091018 (subproblems C1+C2+C3). ", "output_spec": "Print a single integer \u2014 the minimum number of subtractions that turns the magic number to a zero.", "sample_inputs": ["24"], "sample_outputs": ["5"], "notes": "NoteIn the first test sample the minimum number of operations can be reached by the following sequence of subtractions: 24\u2009\u2192\u200920\u2009\u2192\u200918\u2009\u2192\u200910\u2009\u2192\u20099\u2009\u2192\u20090 "}, "src_uid": "fc5765b9bd18dc7555fa76e91530c036"} {"nl": {"description": "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\u2009>\u20091 such that a2 is a divisor of x. 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_spec": "The first and only line of input contains one integer, n (1\u2009\u2264\u2009n\u2009\u2264\u20091012).", "output_spec": "Print the answer in one line.", "sample_inputs": ["10", "12"], "sample_outputs": ["10", "6"], "notes": "NoteIn 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\u2009=\u200922, so 12 is not lovely, while 6 is indeed lovely."}, "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"} {"nl": {"description": "Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k\u2009>\u20091) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved. Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.", "input_spec": "The single line of input contains the integer m (1\u2009\u2264\u2009m\u2009\u2264\u20091015)\u00a0\u2014 the number of ways the thieves might steal the chocolates, as rumours say.", "output_spec": "Print the only integer n\u00a0\u2014 the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one. If there is no such n for a false-rumoured m, print \u2009-\u20091.", "sample_inputs": ["1", "8", "10"], "sample_outputs": ["8", "54", "-1"], "notes": "NoteIn the first sample case the smallest n that leads to exactly one way of stealing chocolates is n\u2009=\u20098, whereas the amounts of stealed chocolates are (1,\u20092,\u20094,\u20098) (the number of chocolates stolen by each of the thieves).In the second sample case the smallest n that leads to exactly 8 ways is n\u2009=\u200954 with the possibilities: (1,\u20092,\u20094,\u20098),\u2009\u2002(1,\u20093,\u20099,\u200927),\u2009\u2002(2,\u20094,\u20098,\u200916),\u2009\u2002(2,\u20096,\u200918,\u200954),\u2009\u2002(3,\u20096,\u200912,\u200924),\u2009\u2002(4,\u20098,\u200916,\u200932),\u2009\u2002(5,\u200910,\u200920,\u200940),\u2009\u2002(6,\u200912,\u200924,\u200948).There is no n leading to exactly 10 ways of stealing chocolates in the third sample case."}, "src_uid": "602deaad5c66e264997249457d555129"} {"nl": {"description": "The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. \"Do I give such a hard task?\" \u2014 the HR manager thought. \"Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions.\"Could you pass the interview in the machine vision company in IT City?", "input_spec": "The only line of the input contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u20092\u00b71018) \u2014 the power in which you need to raise number 5.", "output_spec": "Output the last two digits of 5n without spaces between them.", "sample_inputs": ["2"], "sample_outputs": ["25"], "notes": null}, "src_uid": "dcaff75492eafaf61d598779d6202c9d"} {"nl": {"description": "Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar. So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become and height of Abol will become where x1,\u2009y1,\u2009x2 and y2 are some integer numbers and denotes the remainder of a modulo b.Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.Mike has asked you for your help. Calculate the minimum time or say it will never happen.", "input_spec": "The first line of input contains integer m (2\u2009\u2264\u2009m\u2009\u2264\u2009106). The second line of input contains integers h1 and a1 (0\u2009\u2264\u2009h1,\u2009a1\u2009<\u2009m). The third line of input contains integers x1 and y1 (0\u2009\u2264\u2009x1,\u2009y1\u2009<\u2009m). The fourth line of input contains integers h2 and a2 (0\u2009\u2264\u2009h2,\u2009a2\u2009<\u2009m). The fifth line of input contains integers x2 and y2 (0\u2009\u2264\u2009x2,\u2009y2\u2009<\u2009m). It is guaranteed that h1\u2009\u2260\u2009a1 and h2\u2009\u2260\u2009a2.", "output_spec": "Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.", "sample_inputs": ["5\n4 2\n1 1\n0 1\n2 3", "1023\n1 2\n1 0\n1 2\n1 1"], "sample_outputs": ["3", "-1"], "notes": "NoteIn the first sample, heights sequences are following:Xaniar: Abol: "}, "src_uid": "7225266f663699ff7e16b726cadfe9ee"} {"nl": {"description": "You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.", "input_spec": "The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $$$-100$$$ and $$$100$$$.", "output_spec": "Print \"Yes\" if squares intersect, otherwise print \"No\". You can print each letter in any case (upper or lower).", "sample_inputs": ["0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example the second square lies entirely within the first square, so they do intersect.In the second sample squares do not have any points in common.Here are images corresponding to the samples: "}, "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a"} {"nl": {"description": "String can be called correct if it consists of characters \"0\" and \"1\" and there are no redundant leading zeroes. Here are some examples: \"0\", \"10\", \"1001\".You are given a correct string s.You can perform two different operations on this string: swap any pair of adjacent characters (for example, \"101\" \"110\"); replace \"11\" with \"1\" (for example, \"110\" \"10\"). Let val(s) be such a number that s is its binary representation.Correct string a is less than some other correct string b iff val(a)\u2009<\u2009val(b).Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).", "input_spec": "The first line contains integer number n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the length of string s. The second line contains the string s consisting of characters \"0\" and \"1\". It is guaranteed that the string s is correct.", "output_spec": "Print one string \u2014 the minimum correct string that you can obtain from the given one.", "sample_inputs": ["4\n1001", "1\n1"], "sample_outputs": ["100", "1"], "notes": "NoteIn the first example you can obtain the answer by the following sequence of operations: \"1001\" \"1010\" \"1100\" \"100\".In the second example you can't obtain smaller answer no matter what operations you use."}, "src_uid": "ac244791f8b648d672ed3de32ce0074d"} {"nl": {"description": "You're given a row with $$$n$$$ chairs. We call a seating of people \"maximal\" if the two following conditions hold: There are no neighbors adjacent to anyone seated. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ means that the corresponding seat is empty, $$$1$$$ \u2014 occupied). The goal is to determine whether this seating is \"maximal\".Note that the first and last seats are not adjacent (if $$$n \\ne 2$$$).", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 1000$$$)\u00a0\u2014 the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.", "output_spec": "Output \"Yes\" (without quotation marks) if the seating is \"maximal\". Otherwise print \"No\". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).", "sample_inputs": ["3\n101", "4\n1011", "5\n10001"], "sample_outputs": ["Yes", "No", "No"], "notes": "NoteIn sample case one the given seating is maximal.In sample case two the person at chair three has a neighbour to the right.In sample case three it is possible to seat yet another person into chair three."}, "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"} {"nl": {"description": "Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.", "input_spec": "The first line contains four integers n1,\u2009n2,\u2009k1,\u2009k2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.", "output_spec": "Output \"First\" if the first player wins and \"Second\" otherwise.", "sample_inputs": ["2 2 1 2", "2 1 1 1"], "sample_outputs": ["Second", "First"], "notes": "NoteConsider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely."}, "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"} {"nl": {"description": "Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of $$$n$$$ light bulbs in a single row. Each bulb has a number from $$$1$$$ to $$$n$$$ (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by $$$2$$$). For example, the complexity of 1 4 2 3 5 is $$$2$$$ and the complexity of 1 3 5 7 6 4 2 is $$$1$$$.No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of light bulbs on the garland. The second line contains $$$n$$$ integers $$$p_1,\\ p_2,\\ \\ldots,\\ p_n$$$ ($$$0 \\le p_i \\le n$$$)\u00a0\u2014 the number on the $$$i$$$-th bulb, or $$$0$$$ if it was removed.", "output_spec": "Output a single number\u00a0\u2014 the minimum complexity of the garland.", "sample_inputs": ["5\n0 5 0 2 3", "7\n1 0 0 5 0 0 2"], "sample_outputs": ["2", "1"], "notes": "NoteIn the first example, one should place light bulbs as 1 5 4 2 3. In that case, the complexity would be equal to 2, because only $$$(5, 4)$$$ and $$$(2, 3)$$$ are the pairs of adjacent bulbs that have different parity.In the second case, one of the correct answers is 1 7 3 5 6 4 2. "}, "src_uid": "90db6b6548512acfc3da162144169dba"} {"nl": {"description": "One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.Lesha is tired now so he asked you to split the array. Help Lesha!", "input_spec": "The first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of elements in the array A. The next line contains n integers a1,\u2009a2,\u2009...,\u2009an (\u2009-\u2009103\u2009\u2264\u2009ai\u2009\u2264\u2009103)\u00a0\u2014 the elements of the array A.", "output_spec": "If it is not possible to split the array A and satisfy all the constraints, print single line containing \"NO\" (without quotes). Otherwise in the first line print \"YES\" (without quotes). In the next line print single integer k\u00a0\u2014 the number of new arrays. In each of the next k lines print two integers li and ri which denote the subarray A[li... ri] of the initial array A being the i-th new array. Integers li, ri should satisfy the following conditions: l1\u2009=\u20091 rk\u2009=\u2009n ri\u2009+\u20091\u2009=\u2009li\u2009+\u20091 for each 1\u2009\u2264\u2009i\u2009<\u2009k. If there are multiple answers, print any of them.", "sample_inputs": ["3\n1 2 -3", "8\n9 -12 3 4 -4 -10 7 3", "1\n0", "4\n1 2 3 -5"], "sample_outputs": ["YES\n2\n1 2\n3 3", "YES\n2\n1 2\n3 8", "NO", "YES\n4\n1 1\n2 2\n3 3\n4 4"], "notes": null}, "src_uid": "3a9258070ff179daf33a4515def9897a"} {"nl": {"description": "Not so long ago as a result of combat operations the main Berland place of interest \u2014 the magic clock \u2014 was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: The picture shows only the central part of the clock. This coloring naturally extends to infinity.The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball.All the points located on the border of one of the areas have to be considered painted black.", "input_spec": "The first and single line contains two integers x and y \u2014 the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000.", "output_spec": "Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black.", "sample_inputs": ["-2 1", "2 1", "4 3"], "sample_outputs": ["white", "black", "black"], "notes": null}, "src_uid": "8c92aac1bef5822848a136a1328346c6"} {"nl": {"description": "Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.They also decided that there must be given at least min1 and at most max1 diplomas of the first degree, at least min2 and at most max2 diplomas of the second degree, and at least min3 and at most max3 diplomas of the third degree.After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all n participants of the Olympiad will receive a diploma of some degree.", "input_spec": "The first line of the input contains a single integer n (3\u2009\u2264\u2009n\u2009\u2264\u20093\u00b7106)\u00a0\u2014\u00a0the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers min1 and max1 (1\u2009\u2264\u2009min1\u2009\u2264\u2009max1\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers min2 and max2 (1\u2009\u2264\u2009min2\u2009\u2264\u2009max2\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. The next line of the input contains two integers min3 and max3 (1\u2009\u2264\u2009min3\u2009\u2264\u2009max3\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. It is guaranteed that min1\u2009+\u2009min2\u2009+\u2009min3\u2009\u2264\u2009n\u2009\u2264\u2009max1\u2009+\u2009max2\u2009+\u2009max3.", "output_spec": "In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.", "sample_inputs": ["6\n1 5\n2 6\n3 7", "10\n1 2\n1 3\n1 5", "6\n1 3\n2 2\n2 2"], "sample_outputs": ["1 2 3", "2 3 5", "2 2 2"], "notes": null}, "src_uid": "3cd092b6507079518cf206deab21cf97"} {"nl": {"description": "Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 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 k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.", "input_spec": "The only line of the input contains four integers k2, k3, k5 and k6\u00a0\u2014 the number of digits 2, 3, 5 and 6 respectively (0\u2009\u2264\u2009k2,\u2009k3,\u2009k5,\u2009k6\u2009\u2264\u20095\u00b7106).", "output_spec": "Print one integer\u00a0\u2014 maximum possible sum of Anton's favorite integers that can be composed using digits from the box.", "sample_inputs": ["5 1 3 4", "1 1 1 1"], "sample_outputs": ["800", "256"], "notes": "NoteIn 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\u2009+\u2009256\u2009+\u2009256\u2009+\u200932\u2009=\u2009800. 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."}, "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"} {"nl": {"description": "Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he read somewhere that customers are attracted by prices that say something like \"Special Offer! Super price 999 bourles!\". So Polycarpus decided to lower the price a little if it leads to the desired effect.Polycarpus agrees to lower the price by no more than d bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.Note, Polycarpus counts only the trailing nines in a price.", "input_spec": "The first line contains two integers p and d (1\u2009\u2264\u2009p\u2009\u2264\u20091018; 0\u2009\u2264\u2009d\u2009<\u2009p) \u2014 the initial price of scissors and the maximum possible price reduction. Please, do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specifier.", "output_spec": "Print the required price \u2014 the maximum price that ends with the largest number of nines and that is less than p by no more than d. The required number shouldn't have leading zeroes.", "sample_inputs": ["1029 102", "27191 17"], "sample_outputs": ["999", "27189"], "notes": null}, "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a"} {"nl": {"description": "Polycarp loves ciphers. He has invented his own cipher called Right-Left.Right-Left cipher is used for strings. To encrypt the string $$$s=s_{1}s_{2} \\dots s_{n}$$$ Polycarp uses the following algorithm: he writes down $$$s_1$$$, he appends the current word with $$$s_2$$$ (i.e. writes down $$$s_2$$$ to the right of the current result), he prepends the current word with $$$s_3$$$ (i.e. writes down $$$s_3$$$ to the left of the current result), he appends the current word with $$$s_4$$$ (i.e. writes down $$$s_4$$$ to the right of the current result), he prepends the current word with $$$s_5$$$ (i.e. writes down $$$s_5$$$ to the left of the current result), and so on for each position until the end of $$$s$$$. For example, if $$$s$$$=\"techno\" the process is: \"t\" $$$\\to$$$ \"te\" $$$\\to$$$ \"cte\" $$$\\to$$$ \"cteh\" $$$\\to$$$ \"ncteh\" $$$\\to$$$ \"ncteho\". So the encrypted $$$s$$$=\"techno\" is \"ncteho\".Given string $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. Your task is to decrypt it, i.e. find the string $$$s$$$.", "input_spec": "The only line of the input contains $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. It contains only lowercase Latin letters. The length of $$$t$$$ is between $$$1$$$ and $$$50$$$, inclusive.", "output_spec": "Print such string $$$s$$$ that after encryption it equals $$$t$$$.", "sample_inputs": ["ncteho", "erfdcoeocs", "z"], "sample_outputs": ["techno", "codeforces", "z"], "notes": null}, "src_uid": "992ae43e66f1808f19c86b1def1f6b41"} {"nl": {"description": "Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term \"equivalence relation\". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.A set \u03c1 of pairs (a,\u2009b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation \u03c1, if pair , in this case we use a notation .Binary relation is equivalence relation, if: It is reflexive (for any a it is true that ); It is symmetric (for any a, b it is true that if , then ); It is transitive (if and , than ).Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his \"proof\":Take any two elements, a and b. If , then (according to property (2)), which means (according to property (3)).It's very simple, isn't it? However, you noticed that Johnny's \"proof\" is wrong, and decided to show him a lot of examples that prove him wrong.Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109\u2009+\u20097.", "input_spec": "A single line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20094000).", "output_spec": "In a single line print the answer to the problem modulo 109\u2009+\u20097.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["1", "3", "10"], "notes": "NoteIf n\u2009=\u20091 there is only one such relation\u00a0\u2014 an empty one, i.e. . In other words, for a single element x of set A the following is hold: .If n\u2009=\u20092 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are , \u03c1\u2009=\u2009{(x,\u2009x)}, \u03c1\u2009=\u2009{(y,\u2009y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations."}, "src_uid": "aa2c3e94a44053a0d86f61da06681023"} {"nl": {"description": "There are $$$n$$$ benches in the Berland Central park. It is known that $$$a_i$$$ people are currently sitting on the $$$i$$$-th bench. Another $$$m$$$ people are coming to the park and each of them is going to have a seat on some bench out of $$$n$$$ available.Let $$$k$$$ be the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park. Calculate the minimum possible $$$k$$$ and the maximum possible $$$k$$$.Nobody leaves the taken seat during the whole process.", "input_spec": "The first line contains a single integer $$$n$$$ $$$(1 \\le n \\le 100)$$$ \u2014 the number of benches in the park. The second line contains a single integer $$$m$$$ $$$(1 \\le m \\le 10\\,000)$$$ \u2014 the number of people additionally coming to the park. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ $$$(1 \\le a_i \\le 100)$$$ \u2014 the initial number of people on the $$$i$$$-th bench.", "output_spec": "Print the minimum possible $$$k$$$ and the maximum possible $$$k$$$, where $$$k$$$ is the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park.", "sample_inputs": ["4\n6\n1\n1\n1\n1", "1\n10\n5", "3\n6\n1\n6\n5", "3\n7\n1\n6\n5"], "sample_outputs": ["3 7", "15 15", "6 12", "7 13"], "notes": "NoteIn the first example, each of four benches is occupied by a single person. The minimum $$$k$$$ is $$$3$$$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining \u2014 the fourth bench. The maximum $$$k$$$ is $$$7$$$. That requires all six new people to occupy the same bench.The second example has its minimum $$$k$$$ equal to $$$15$$$ and maximum $$$k$$$ equal to $$$15$$$, as there is just a single bench in the park and all $$$10$$$ people will occupy it."}, "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"} {"nl": {"description": "Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least $$$k$$$ subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one.Formally, a codeforces subsequence of a string $$$s$$$ is a subset of ten characters of $$$s$$$ that read codeforces from left to right. For example, codeforces contains codeforces a single time, while codeforcesisawesome contains codeforces four times: codeforcesisawesome, codeforcesisawesome, codeforcesisawesome, codeforcesisawesome.Help Karl find any shortest string that contains at least $$$k$$$ codeforces subsequences.", "input_spec": "The only line contains a single integer $$$k$$$ ($$$1 \\leq k \\leq 10^{16})$$$.", "output_spec": "Print a shortest string of lowercase English letters that contains at least $$$k$$$ codeforces subsequences. If there are several such strings, print any of them.", "sample_inputs": ["1", "3"], "sample_outputs": ["codeforces", "codeforcesss"], "notes": null}, "src_uid": "8001a7570766cadcc538217e941b3031"} {"nl": {"description": "You are given a positive integer $$$n$$$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.Determine the minimum number of operations that you need to consistently apply to the given integer $$$n$$$ to make from it the square of some positive integer or report that it is impossible.An integer $$$x$$$ is the square of some positive integer if and only if $$$x=y^2$$$ for some positive integer $$$y$$$.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^{9}$$$). The number is given without leading zeroes.", "output_spec": "If it is impossible to make the square of some positive integer from $$$n$$$, print -1. In the other case, print the minimal number of operations required to do it.", "sample_inputs": ["8314", "625", "333"], "sample_outputs": ["2", "0", "-1"], "notes": "NoteIn the first example we should delete from $$$8314$$$ the digits $$$3$$$ and $$$4$$$. After that $$$8314$$$ become equals to $$$81$$$, which is the square of the integer $$$9$$$.In the second example the given $$$625$$$ is the square of the integer $$$25$$$, so you should not delete anything. In the third example it is impossible to make the square from $$$333$$$, so the answer is -1."}, "src_uid": "fa4b1de79708329bb85437e1413e13df"} {"nl": {"description": "Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string\u00a0\u2014 concatenation of letters, which correspond to the stages.There are $$$n$$$ stages available. The rocket must contain exactly $$$k$$$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z'\u00a0\u2014 $$$26$$$ tons.Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.", "input_spec": "The first line of input contains two integers\u00a0\u2014 $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 50$$$)\u00a0\u2013 the number of available stages and the number of stages to use in the rocket. The second line contains string $$$s$$$, which consists of exactly $$$n$$$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.", "output_spec": "Print a single integer\u00a0\u2014 the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.", "sample_inputs": ["5 3\nxyabd", "7 4\nproblem", "2 2\nab", "12 1\nabaabbaaabbb"], "sample_outputs": ["29", "34", "-1", "1"], "notes": "NoteIn the first example, the following rockets satisfy the condition: \"adx\" (weight is $$$1+4+24=29$$$); \"ady\" (weight is $$$1+4+25=30$$$); \"bdx\" (weight is $$$2+4+24=30$$$); \"bdy\" (weight is $$$2+4+25=31$$$).Rocket \"adx\" has the minimal weight, so the answer is $$$29$$$.In the second example, target rocket is \"belo\". Its weight is $$$2+5+12+15=34$$$.In the third example, $$$n=k=2$$$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1."}, "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"} {"nl": {"description": "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.\u00a0e. a letter \"K\" right after a letter \"V\") in the resulting string.", "input_spec": "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_spec": "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.", "sample_inputs": ["VK", "VV", "V", "VKKKKKKKKKVVVVVVVVVK", "KVKV"], "sample_outputs": ["1", "1", "0", "3", "1"], "notes": "NoteFor 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."}, "src_uid": "578bae0fe6634882227ac371ebb38fc9"} {"nl": {"description": "Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly k months. He looked at the calendar and learned that at the moment is the month number s. Vasya immediately got interested in what month Codecraft III will appear. Help him understand that.All the twelve months in Vasya's calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December.", "input_spec": "The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer k (0\u2009\u2264\u2009k\u2009\u2264\u2009100) \u2014 the number of months left till the appearance of Codecraft III.", "output_spec": "Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.", "sample_inputs": ["November\n3", "May\n24"], "sample_outputs": ["February", "May"], "notes": null}, "src_uid": "a307b402b20554ce177a73db07170691"} {"nl": {"description": "Vasya likes to solve equations. Today he wants to solve $$$(x~\\mathrm{div}~k) \\cdot (x \\bmod k) = n$$$, where $$$\\mathrm{div}$$$ and $$$\\mathrm{mod}$$$ stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, $$$k$$$ and $$$n$$$ are positive integer parameters, and $$$x$$$ is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible $$$x$$$. Can you help him?", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\leq n \\leq 10^6$$$, $$$2 \\leq k \\leq 1000$$$).", "output_spec": "Print a single integer $$$x$$$\u00a0\u2014 the smallest positive integer solution to $$$(x~\\mathrm{div}~k) \\cdot (x \\bmod k) = n$$$. It is guaranteed that this equation has at least one positive integer solution.", "sample_inputs": ["6 3", "1 2", "4 6"], "sample_outputs": ["11", "3", "10"], "notes": "NoteThe result of integer division $$$a~\\mathrm{div}~b$$$ is equal to the largest integer $$$c$$$ such that $$$b \\cdot c \\leq a$$$. $$$a$$$ modulo $$$b$$$ (shortened $$$a \\bmod b$$$) is the only integer $$$c$$$ such that $$$0 \\leq c < b$$$, and $$$a - c$$$ is divisible by $$$b$$$.In the first sample, $$$11~\\mathrm{div}~3 = 3$$$ and $$$11 \\bmod 3 = 2$$$. Since $$$3 \\cdot 2 = 6$$$, then $$$x = 11$$$ is a solution to $$$(x~\\mathrm{div}~3) \\cdot (x \\bmod 3) = 6$$$. One can see that $$$19$$$ is the only other positive integer solution, hence $$$11$$$ is the smallest one."}, "src_uid": "ed0ebc1e484fcaea875355b5b7944c57"} {"nl": {"description": "A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.You are given user's friends' opinions about a list of items. You are also given a threshold T \u2014 the minimal number of \"likes\" necessary for an item to be recommended to the user.Output the number of items in the list liked by at least T of user's friends.", "input_spec": "The first line of the input will contain three space-separated integers: the number of friends F (1\u2009\u2264\u2009F\u2009\u2264\u200910), the number of items I (1\u2009\u2264\u2009I\u2009\u2264\u200910) and the threshold T (1\u2009\u2264\u2009T\u2009\u2264\u2009F). The following F lines of input contain user's friends' opinions. j-th character of i-th line is 'Y' if i-th friend likes j-th item, and 'N' otherwise.", "output_spec": "Output an integer \u2014 the number of items liked by at least T of user's friends.", "sample_inputs": ["3 3 2\nYYY\nNNN\nYNY", "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN"], "sample_outputs": ["2", "4"], "notes": null}, "src_uid": "4c978130187e8ae6ca013d3f781b064e"} {"nl": {"description": "Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty\u00a0\u2014 it's guaranteed that pi\u2009<\u2009pi\u2009+\u20091 and ti\u2009<\u2009ti\u2009+\u20091.A constant c is given too, representing the speed of loosing points. Then, submitting the i-th problem at time x (x minutes after the start of the contest) gives max(0,\u2009 pi\u2009-\u2009c\u00b7x) points.Limak is going to solve problems in order 1,\u20092,\u2009...,\u2009n (sorted increasingly by pi). Radewoosh is going to solve them in order n,\u2009n\u2009-\u20091,\u2009...,\u20091 (sorted decreasingly by pi). Your task is to predict the outcome\u00a0\u2014 print the name of the winner (person who gets more points at the end) or a word \"Tie\" in case of a tie.You may assume that the duration of the competition is greater or equal than the sum of all ti. That means both Limak and Radewoosh will accept all n problems.", "input_spec": "The first line contains two integers n and c (1\u2009\u2264\u2009n\u2009\u2264\u200950,\u20091\u2009\u2264\u2009c\u2009\u2264\u20091000)\u00a0\u2014 the number of problems and the constant representing the speed of loosing points. The second line contains n integers p1,\u2009p2,\u2009...,\u2009pn (1\u2009\u2264\u2009pi\u2009\u2264\u20091000,\u2009pi\u2009<\u2009pi\u2009+\u20091)\u00a0\u2014 initial scores. The third line contains n integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20091000,\u2009ti\u2009<\u2009ti\u2009+\u20091) where ti denotes the number of minutes one needs to solve the i-th problem.", "output_spec": "Print \"Limak\" (without quotes) if Limak will get more points in total. Print \"Radewoosh\" (without quotes) if Radewoosh will get more points in total. Print \"Tie\" (without quotes) if Limak and Radewoosh will get the same total number of points.", "sample_inputs": ["3 2\n50 85 250\n10 15 25", "3 6\n50 85 250\n10 15 25", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76"], "sample_outputs": ["Limak", "Radewoosh", "Tie"], "notes": "NoteIn the first sample, there are 3 problems. Limak solves them as follows: Limak spends 10 minutes on the 1-st problem and he gets 50\u2009-\u2009c\u00b710\u2009=\u200950\u2009-\u20092\u00b710\u2009=\u200930 points. Limak spends 15 minutes on the 2-nd problem so he submits it 10\u2009+\u200915\u2009=\u200925 minutes after the start of the contest. For the 2-nd problem he gets 85\u2009-\u20092\u00b725\u2009=\u200935 points. He spends 25 minutes on the 3-rd problem so he submits it 10\u2009+\u200915\u2009+\u200925\u2009=\u200950 minutes after the start. For this problem he gets 250\u2009-\u20092\u00b750\u2009=\u2009150 points. So, Limak got 30\u2009+\u200935\u2009+\u2009150\u2009=\u2009215 points.Radewoosh solves problem in the reversed order: Radewoosh solves 3-rd problem after 25 minutes so he gets 250\u2009-\u20092\u00b725\u2009=\u2009200 points. He spends 15 minutes on the 2-nd problem so he submits it 25\u2009+\u200915\u2009=\u200940 minutes after the start. He gets 85\u2009-\u20092\u00b740\u2009=\u20095 points for this problem. He spends 10 minutes on the 1-st problem so he submits it 25\u2009+\u200915\u2009+\u200910\u2009=\u200950 minutes after the start. He gets max(0,\u200950\u2009-\u20092\u00b750)\u2009=\u2009max(0,\u2009\u2009-\u200950)\u2009=\u20090 points. Radewoosh got 200\u2009+\u20095\u2009+\u20090\u2009=\u2009205 points in total. Limak has 215 points so Limak wins.In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250\u2009-\u20096\u00b725\u2009=\u2009100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2\u2009+\u20092\u2009=\u20094."}, "src_uid": "8c704de75ab85f9e2c04a926143c8b4a"} {"nl": {"description": "Reca company makes monitors, the most popular of their models is AB999 with the screen size a\u2009\u00d7\u2009b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x:\u2009y became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes x:\u2009y, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed.", "input_spec": "The first line of the input contains 4 integers \u2014 a, b, x and y (1\u2009\u2264\u2009a,\u2009b,\u2009x,\u2009y\u2009\u2264\u20092\u00b7109).", "output_spec": "If the answer exists, output 2 positive integers \u2014 screen parameters of the reduced size model. Output 0 0 otherwise.", "sample_inputs": ["800 600 4 3", "1920 1200 16 9", "1 1 1 2"], "sample_outputs": ["800 600", "1920 1080", "0 0"], "notes": null}, "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"} {"nl": {"description": "Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (a\u2009<\u2009b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (\u2009+\u2009) instead of division button (\u00f7) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals n. Help Petya deal with this problem. ", "input_spec": "In the only line of input there is an integer n (3\u2009\u2264\u2009n\u2009\u2264\u20091000), the sum of numerator and denominator of the fraction.", "output_spec": "Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.", "sample_inputs": ["3", "4", "12"], "sample_outputs": ["1 2", "1 3", "5 7"], "notes": null}, "src_uid": "0af3515ed98d9d01ce00546333e98e77"} {"nl": {"description": "Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.", "input_spec": "The only line contain two integers m and d (1\u2009\u2264\u2009m\u2009\u2264\u200912, 1\u2009\u2264\u2009d\u2009\u2264\u20097)\u00a0\u2014 the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).", "output_spec": "Print single integer: the number of columns the table should have.", "sample_inputs": ["1 7", "1 1", "11 6"], "sample_outputs": ["6", "5", "5"], "notes": "NoteThe first example corresponds to the January 2017 shown on the picture in the statements.In the second example 1-st January is Monday, so the whole month fits into 5 columns.In the third example 1-st November is Saturday and 5 columns is enough."}, "src_uid": "5b969b6f564df6f71e23d4adfb2ded74"} {"nl": {"description": "You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $$$8 \\times 8$$$, but it still is $$$N \\times N$$$. Each square has some number written on it, all the numbers are from $$$1$$$ to $$$N^2$$$ and all the numbers are pairwise distinct. The $$$j$$$-th square in the $$$i$$$-th row has a number $$$A_{ij}$$$ written on it.In your chess set you have only three pieces: a knight, a bishop and a rook. At first, you put one of them on the square with the number $$$1$$$ (you can choose which one). Then you want to reach square $$$2$$$ (possibly passing through some other squares in process), then square $$$3$$$ and so on until you reach square $$$N^2$$$. In one step you are allowed to either make a valid move with the current piece or replace it with some other piece. Each square can be visited arbitrary number of times.A knight can move to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. A bishop moves diagonally. A rook moves horizontally or vertically. The move should be performed to a different square from the one a piece is currently standing on.You want to minimize the number of steps of the whole traversal. Among all the paths to have the same number of steps you want to choose the one with the lowest number of piece replacements.What is the path you should take to satisfy all conditions?", "input_spec": "The first line contains a single integer $$$N$$$ ($$$3 \\le N \\le 10$$$) \u2014 the size of the chessboard. Each of the next $$$N$$$ lines contains $$$N$$$ integers $$$A_{i1}, A_{i2}, \\dots, A_{iN}$$$ ($$$1 \\le A_{ij} \\le N^2$$$) \u2014 the numbers written on the squares of the $$$i$$$-th row of the board. It is guaranteed that all $$$A_{ij}$$$ are pairwise distinct.", "output_spec": "The only line should contain two integers \u2014 the number of steps in the best answer and the number of replacement moves in it.", "sample_inputs": ["3\n1 9 3\n8 6 7\n4 2 5"], "sample_outputs": ["12 1"], "notes": "NoteHere are the steps for the first example (the starting piece is a knight): Move to $$$(3, 2)$$$ Move to $$$(1, 3)$$$ Move to $$$(3, 2)$$$ Replace the knight with a rook Move to $$$(3, 1)$$$ Move to $$$(3, 3)$$$ Move to $$$(3, 2)$$$ Move to $$$(2, 2)$$$ Move to $$$(2, 3)$$$ Move to $$$(2, 1)$$$ Move to $$$(1, 1)$$$ Move to $$$(1, 2)$$$ "}, "src_uid": "5fe44b6cd804e0766a0e993eca1846cd"} {"nl": {"description": "Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.Suppose the digital counter is showing number n. Malek calls an integer x (0\u2009\u2264\u2009x\u2009\u2264\u200999) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.", "input_spec": "The only line of input contains exactly two digits representing number n (0\u2009\u2264\u2009n\u2009\u2264\u200999). Note that n may have a leading zero.", "output_spec": "In the only line of the output print the number of good integers.", "sample_inputs": ["89", "00", "73"], "sample_outputs": ["2", "4", "15"], "notes": "NoteIn the first sample the counter may be supposed to show 88 or 89.In the second sample the good integers are 00, 08, 80 and 88.In the third sample the good integers are 03,\u200908,\u200909,\u200933,\u200938,\u200939,\u200973,\u200978,\u200979,\u200983,\u200988,\u200989,\u200993,\u200998,\u200999."}, "src_uid": "76c8bfa6789db8364a8ece0574cd31f5"} {"nl": {"description": "Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.In order to pass through a guardpost, one needs to bribe both guards.The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!", "input_spec": "The first line of the input contains integer n\u00a0(1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a,\u2009b,\u2009c,\u2009d\u00a0(1\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d\u2009\u2264\u2009105) \u2014 the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.", "output_spec": "In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line. The guardposts are numbered from 1 to 4 according to the order given in the input. If there are multiple solutions, you can print any of them.", "sample_inputs": ["10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9", "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8", "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3"], "sample_outputs": ["1 5 5", "3 4 6", "-1"], "notes": "NoteExplanation of the first example.The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.Explanation of the second example.Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard."}, "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"nl": {"description": "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_spec": "The only input line contains the integer $$$n$$$ ($$$1 \\le n \\le 2\\cdot10^9$$$).", "output_spec": "Print the maximum product of digits among all integers from $$$1$$$ to $$$n$$$.", "sample_inputs": ["390", "7", "1000000000"], "sample_outputs": ["216", "7", "387420489"], "notes": "NoteIn the first example the maximum product is achieved for $$$389$$$ (the product of digits is $$$3\\cdot8\\cdot9=216$$$).In the second example the maximum product is achieved for $$$7$$$ (the product of digits is $$$7$$$).In the third example the maximum product is achieved for $$$999999999$$$ (the product of digits is $$$9^9=387420489$$$)."}, "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"nl": {"description": "Polycarp knows that if the sum of the digits of a number is divisible by $$$3$$$, then the number itself is divisible by $$$3$$$. He assumes that the numbers, the sum of the digits of which is divisible by $$$4$$$, are also somewhat interesting. Thus, he considers a positive integer $$$n$$$ interesting if its sum of digits is divisible by $$$4$$$.Help Polycarp find the nearest larger or equal interesting number for the given number $$$a$$$. That is, find the interesting number $$$n$$$ such that $$$n \\ge a$$$ and $$$n$$$ is minimal.", "input_spec": "The only line in the input contains an integer $$$a$$$ ($$$1 \\le a \\le 1000$$$).", "output_spec": "Print the nearest greater or equal interesting number for the given number $$$a$$$. In other words, print the interesting number $$$n$$$ such that $$$n \\ge a$$$ and $$$n$$$ is minimal.", "sample_inputs": ["432", "99", "237", "42"], "sample_outputs": ["435", "103", "237", "44"], "notes": null}, "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"} {"nl": {"description": "The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to pass.Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.", "input_spec": "The first line contains two integers v1 and v2 (1\u2009\u2264\u2009v1,\u2009v2\u2009\u2264\u2009100) \u2014 the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers t (2\u2009\u2264\u2009t\u2009\u2264\u2009100) \u2014 the time when the car moves along the segment in seconds, d (0\u2009\u2264\u2009d\u2009\u2264\u200910) \u2014 the maximum value of the speed change between adjacent seconds. It is guaranteed that there is a way to complete the segment so that: the speed in the first second equals v1, the speed in the last second equals v2, the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d. ", "output_spec": "Print the maximum possible length of the path segment in meters. ", "sample_inputs": ["5 6\n4 2", "10 10\n10 0"], "sample_outputs": ["26", "100"], "notes": "NoteIn the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5\u2009+\u20097\u2009+\u20098\u2009+\u20096\u2009=\u200926 meters.In the second sample, as d\u2009=\u20090, the car covers the whole segment at constant speed v\u2009=\u200910. In t\u2009=\u200910 seconds it covers the distance of 100 meters."}, "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf"} {"nl": {"description": "Vanya got an important task \u2014 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_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 the number of books in the library.", "output_spec": "Print the number of digits needed to number all the books.", "sample_inputs": ["13", "4"], "sample_outputs": ["17", "4"], "notes": "NoteNote to the first test. The books get numbers 1,\u20092,\u20093,\u20094,\u20095,\u20096,\u20097,\u20098,\u20099,\u200910,\u200911,\u200912,\u200913, which totals to 17 digits.Note to the second sample. The books get numbers 1,\u20092,\u20093,\u20094, which totals to 4 digits."}, "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"nl": {"description": "The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches .Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.", "input_spec": "The only line contains two integers p and y (2\u2009\u2264\u2009p\u2009\u2264\u2009y\u2009\u2264\u2009109).", "output_spec": "Output the number of the highest suitable branch. If there are none, print -1 instead.", "sample_inputs": ["3 6", "3 4"], "sample_outputs": ["5", "-1"], "notes": "NoteIn the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.It immediately follows that there are no valid branches in second sample case."}, "src_uid": "b533203f488fa4caf105f3f46dd5844d"} {"nl": {"description": "Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:\"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away...\"More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens: m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). Sparrows come and eat grain. In the i-th day i sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing. Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!", "input_spec": "The only line of the input contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091018)\u00a0\u2014 the capacity of the barn and the number of grains that are brought every day.", "output_spec": "Output one integer\u00a0\u2014 the number of the day when the barn will become empty for the first time. Days are numbered starting with one.", "sample_inputs": ["5 2", "8 1"], "sample_outputs": ["4", "5"], "notes": "NoteIn the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens: At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. At the end of the first day one sparrow comes and eats one grain, so 5\u2009-\u20091\u2009=\u20094 grains remain. At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it. At the end of the second day two sparrows come. 5\u2009-\u20092\u2009=\u20093 grains remain. At the beginning of the third day two grains are brought. The barn becomes full again. At the end of the third day three sparrows come and eat grain. 5\u2009-\u20093\u2009=\u20092 grains remain. At the beginning of the fourth day grain is brought again. 2\u2009+\u20092\u2009=\u20094 grains remain. At the end of the fourth day four sparrows come and eat grain. 4\u2009-\u20094\u2009=\u20090 grains remain. The barn is empty. So the answer is 4, because by the end of the fourth day the barn becomes empty."}, "src_uid": "3b585ea852ffc41034ef6804b6aebbd8"} {"nl": {"description": "Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.", "input_spec": "The only line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018). Please do not use the %lld specificator to read or write 64-bit numbers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specificator.", "output_spec": "Print on the single line \"YES\" if n is a nearly lucky number. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["40047", "7747774", "1000000000000000000"], "sample_outputs": ["NO", "YES", "NO"], "notes": "NoteIn the first sample there are 3 lucky digits (first one and last two), so the answer is \"NO\".In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is \"YES\".In the third sample there are no lucky digits, so the answer is \"NO\"."}, "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"nl": {"description": "Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.In his pocket Polycarp has an unlimited number of \"10-burle coins\" and exactly one coin of r burles (1\u2009\u2264\u2009r\u2009\u2264\u20099).What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.", "input_spec": "The single line of input contains two integers k and r (1\u2009\u2264\u2009k\u2009\u2264\u20091000, 1\u2009\u2264\u2009r\u2009\u2264\u20099)\u00a0\u2014 the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from \"10-burle coins\". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.", "output_spec": "Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. ", "sample_inputs": ["117 3", "237 7", "15 2"], "sample_outputs": ["9", "1", "2"], "notes": "NoteIn the first example Polycarp can buy 9 shovels and pay 9\u00b7117\u2009=\u20091053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.In the second example it is enough for Polycarp to buy one shovel.In the third example Polycarp should buy two shovels and pay 2\u00b715\u2009=\u200930 burles. It is obvious that he can pay this sum without any change. "}, "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"} {"nl": {"description": "Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe. The figure shows a 4-output splitter Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.", "input_spec": "The first line contains two space-separated integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u20091018, 2\u2009\u2264\u2009k\u2009\u2264\u2009109). Please, do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print a single integer \u2014 the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.", "sample_inputs": ["4 3", "5 5", "8 4"], "sample_outputs": ["2", "1", "-1"], "notes": null}, "src_uid": "83bcfe32db302fbae18e8a95d89cf411"} {"nl": {"description": "Having problems with tram routes in the morning, Arkady decided to return home by metro. Fortunately for Arkady, there is only one metro line in the city.Unfortunately for Arkady, the line is circular. It means that the stations are enumerated from $$$1$$$ to $$$n$$$ and there is a tunnel between any pair of consecutive stations as well as between the station $$$1$$$ and the station $$$n$$$. Trains that go in clockwise direction visit the stations in order $$$1 \\to 2 \\to 3 \\to \\ldots \\to n \\to 1$$$ while the trains that go in the counter-clockwise direction visit the stations in the reverse order.The stations that have numbers from $$$1$$$ to $$$m$$$ have interior mostly in red colors while the stations that have numbers from $$$m + 1$$$ to $$$n$$$ have blue interior. Arkady entered the metro at station $$$s$$$ and decided to use the following algorithm to choose his way home. Initially he has a positive integer $$$t$$$ in his mind. If the current station has red interior, he takes a clockwise-directed train, otherwise he takes a counter-clockwise-directed train. He rides exactly $$$t$$$ stations on the train and leaves the train. He decreases $$$t$$$ by one. If $$$t$$$ is still positive, he returns to step $$$2$$$. Otherwise he exits the metro. You have already realized that this algorithm most probably won't bring Arkady home. Find the station he will exit the metro at so that you can continue helping him.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \\le n \\le 10^5$$$, $$$1 \\le m < n$$$)\u00a0\u2014 the total number of stations and the number of stations that have red interior. The second line contains two integers $$$s$$$ and $$$t$$$ ($$$1 \\le s \\le n$$$, $$$1 \\le t \\le 10^{12}$$$)\u00a0\u2014 the starting station and the initial value of $$$t$$$.", "output_spec": "Output the only integer\u00a0\u2014 the station where Arkady will exit the metro.", "sample_inputs": ["10 4\n3 1", "10 4\n3 5", "10543 437\n5492 1947349"], "sample_outputs": ["4", "4", "438"], "notes": "NoteConsider the first example. There are $$$10$$$ stations and the first $$$4$$$ of them are red. Arkady starts at station $$$3$$$ with value $$$t = 1$$$, so just rides $$$1$$$ station in clockwise direction and ends up on the station $$$4$$$.In the second example the metro is same as in the first example, but Arkady starts at station $$$3$$$ with value $$$t = 5$$$. It is a red station so he rides $$$5$$$ stations in clockwise direction and leaves the train at station $$$8$$$. It is a blue station, so he rides $$$4$$$ stations in counter-clockwise direction and leaves at station $$$4$$$. It is a red station, so he rides $$$3$$$ stations in clockwise direction and leaves at station $$$7$$$. It is a blue station, so he rides $$$2$$$ stations in counter-clockwise direction and leaves at station $$$5$$$. It is a blue station, so he rides $$$1$$$ station in counter-clockwise direction and leaves at station $$$4$$$. Now $$$t = 0$$$, so Arkady exits metro at the station $$$4$$$."}, "src_uid": "e743242f0cc9e17619e1fe4935d9fbd0"} {"nl": {"description": "Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.A sequence of l integers b1,\u2009b2,\u2009...,\u2009bl (1\u2009\u2264\u2009b1\u2009\u2264\u2009b2\u2009\u2264\u2009...\u2009\u2264\u2009bl\u2009\u2264\u2009n) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all i (1\u2009\u2264\u2009i\u2009\u2264\u2009l\u2009-\u20091).Given n and k find the number of good sequences of length k. As the answer can be rather large print it modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line of input contains two space-separated integers n,\u2009k\u00a0(1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u20092000).", "output_spec": "Output a single integer \u2014 the number of good sequences of length k modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["3 2", "6 4", "2 1"], "sample_outputs": ["5", "39", "2"], "notes": "NoteIn the first sample the good sequences are: [1,\u20091],\u2009[2,\u20092],\u2009[3,\u20093],\u2009[1,\u20092],\u2009[1,\u20093]."}, "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"} {"nl": {"description": "You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.", "input_spec": "The first line contains four integers n, l, r, x (1\u2009\u2264\u2009n\u2009\u2264\u200915, 1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109, 1\u2009\u2264\u2009x\u2009\u2264\u2009106) \u2014 the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1,\u2009c2,\u2009...,\u2009cn (1\u2009\u2264\u2009ci\u2009\u2264\u2009106) \u2014 the difficulty of each problem.", "output_spec": "Print the number of ways to choose a suitable problemset for the contest. ", "sample_inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20"], "sample_outputs": ["2", "2", "6"], "notes": "NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable \u2014 the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable."}, "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"nl": {"description": "After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus. Initially, there is a pile that contains x 100-yen coins and y 10-yen coins. They take turns alternatively. Ciel takes the first turn. In each turn, they must take exactly 220 yen from the pile. In Ciel's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 100-yen coins. In Hanako's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 10-yen coins. If Ciel or Hanako can't take exactly 220 yen from the pile, she loses. Determine the winner of the game.", "input_spec": "The first line contains two integers x (0\u2009\u2264\u2009x\u2009\u2264\u2009106) and y (0\u2009\u2264\u2009y\u2009\u2264\u2009106), separated by a single space.", "output_spec": "If Ciel wins, print \"Ciel\". Otherwise, print \"Hanako\".", "sample_inputs": ["2 2", "3 22"], "sample_outputs": ["Ciel", "Hanako"], "notes": "NoteIn the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose."}, "src_uid": "8ffee18bbc4bb281027f91193002b7f5"} {"nl": {"description": "Arkady and his friends love playing checkers on an $$$n \\times n$$$ field. The rows and the columns of the field are enumerated from $$$1$$$ to $$$n$$$.The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an old parable (but not its moral), Arkady wants to give to his friends one set of candies per each cell of the field: the set of candies for cell $$$(i, j)$$$ will have exactly $$$(i^2 + j^2)$$$ candies of unique type.There are $$$m$$$ friends who deserve the present. How many of these $$$n \\times n$$$ sets of candies can be split equally into $$$m$$$ parts without cutting a candy into pieces? Note that each set has to be split independently since the types of candies in different sets are different.", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 10^9$$$, $$$1 \\le m \\le 1000$$$)\u00a0\u2014 the size of the field and the number of parts to split the sets into.", "output_spec": "Print a single integer\u00a0\u2014 the number of sets that can be split equally.", "sample_inputs": ["3 3", "6 5", "1000000000 1"], "sample_outputs": ["1", "13", "1000000000000000000"], "notes": "NoteIn the first example, only the set for cell $$$(3, 3)$$$ can be split equally ($$$3^2 + 3^2 = 18$$$, which is divisible by $$$m=3$$$).In the second example, the sets for the following cells can be divided equally: $$$(1, 2)$$$ and $$$(2, 1)$$$, since $$$1^2 + 2^2 = 5$$$, which is divisible by $$$5$$$; $$$(1, 3)$$$ and $$$(3, 1)$$$; $$$(2, 4)$$$ and $$$(4, 2)$$$; $$$(2, 6)$$$ and $$$(6, 2)$$$; $$$(3, 4)$$$ and $$$(4, 3)$$$; $$$(3, 6)$$$ and $$$(6, 3)$$$; $$$(5, 5)$$$. In the third example, sets in all cells can be divided equally, since $$$m = 1$$$."}, "src_uid": "2ec9e7cddc634d7830575e14363a4657"} {"nl": {"description": "You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be of them.You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given N.", "input_spec": "The only input line contains a single integer N (1\u2009\u2264\u2009N\u2009\u2264\u2009100).", "output_spec": "Output a single integer - the minimal number of layers required to draw the segments for the given N.", "sample_inputs": ["2", "3", "4"], "sample_outputs": ["2", "4", "6"], "notes": "NoteAs an example, here are the segments and their optimal arrangement into layers for N\u2009=\u20094. "}, "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"nl": {"description": "Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make: The house consists of some non-zero number of floors. Each floor consists of a non-zero number of rooms and the ceiling. A room is two cards that are leaned towards each other. The rooms are made in a row, each two adjoining rooms share a ceiling made by another card. Each floor besides for the lowest one should contain less rooms than the floor below. Please note that the house may end by the floor with more than one room, and in this case they also must be covered by the ceiling. Also, the number of rooms on the adjoining floors doesn't have to differ by one, the difference may be more. While bears are practicing to put cards, Horace tries to figure out how many floors their house should consist of. The height of the house is the number of floors in it. It is possible that you can make a lot of different houses of different heights out of n cards. It seems that the elephant cannot solve this problem and he asks you to count the number of the distinct heights of the houses that they can make using exactly n cards.", "input_spec": "The single line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091012) \u2014 the number of cards.", "output_spec": "Print the number of distinct heights that the houses made of exactly n cards can have.", "sample_inputs": ["13", "6"], "sample_outputs": ["1", "0"], "notes": "NoteIn the first sample you can build only these two houses (remember, you must use all the cards): Thus, 13 cards are enough only for two floor houses, so the answer is 1.The six cards in the second sample are not enough to build any house."}, "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de"} {"nl": {"description": "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\u00b7m\u2009+\u20091 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_spec": "The only number in the input is n (1\u2009\u2264\u2009n\u2009\u2264\u20091000)\u00a0\u2014 number from the PolandBall's hypothesis. ", "output_spec": "Output such m that n\u00b7m\u2009+\u20091 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1\u2009\u2264\u2009m\u2009\u2264\u2009103. It is guaranteed the the answer exists.", "sample_inputs": ["3", "4"], "sample_outputs": ["1", "2"], "notes": "NoteA 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\u00b71\u2009+\u20091\u2009=\u20094. We can output 1.In the second sample testcase, 4\u00b71\u2009+\u20091\u2009=\u20095. We cannot output 1 because 5 is prime. However, m\u2009=\u20092 is okay since 4\u00b72\u2009+\u20091\u2009=\u20099, which is not a prime number."}, "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"nl": {"description": "Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like \"RYBGRYBGRY\", \"YBGRYBGRYBG\", \"BGRYB\", but can not look like \"BGRYG\", \"YBGRYBYGR\" or \"BGYBGY\". Letters denote colors: 'R'\u00a0\u2014 red, 'B'\u00a0\u2014 blue, 'Y'\u00a0\u2014 yellow, 'G'\u00a0\u2014 green.Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.", "input_spec": "The first and the only line contains the string s (4\u2009\u2264\u2009|s|\u2009\u2264\u2009100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland: 'R'\u00a0\u2014 the light bulb is red, 'B'\u00a0\u2014 the light bulb is blue, 'Y'\u00a0\u2014 the light bulb is yellow, 'G'\u00a0\u2014 the light bulb is green, '!'\u00a0\u2014 the light bulb is dead. The string s can not contain other symbols except those five which were described. It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'. It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line \"GRBY!!!B\" can not be in the input data. ", "output_spec": "In the only line print four integers kr,\u2009kb,\u2009ky,\u2009kg\u00a0\u2014 the number of dead light bulbs of red, blue, yellow and green colors accordingly.", "sample_inputs": ["RYBGRYBGR", "!RGYB", "!!!!YGRB", "!GB!RG!Y!"], "sample_outputs": ["0 0 0 0", "0 1 0 0", "1 1 1 1", "2 1 1 0"], "notes": "NoteIn the first example there are no dead light bulbs.In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements."}, "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"} {"nl": {"description": "As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!", "input_spec": "The first input line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Print \"YES\" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print \"NO\" (without the quotes).", "sample_inputs": ["256", "512"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample number .In the second sample number 512 can not be represented as a sum of two triangular numbers."}, "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"nl": {"description": "Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.Can you help Heidi estimate each village's population?", "input_spec": "Same as the easy version.", "output_spec": "Output one line per village, in the same order as provided in the input, containing your (integer) population estimate. Your answer is considered correct if it is an integer that falls into the interval , where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.", "sample_inputs": [], "sample_outputs": [], "notes": null}, "src_uid": "18bf2c587415f85df83fb090e16b8351"} {"nl": {"description": "Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1\u2009\u2264\u2009pi\u2009\u2264\u2009n).Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number x. Then he goes to the house whose number is written on the plaque of house x (that is, to house px), then he goes to the house whose number is written on the plaque of house px (that is, to house ppx), and so on.We know that: When the penguin starts walking from any house indexed from 1 to k, inclusive, he can walk to house number 1. When the penguin starts walking from any house indexed from k\u2009+\u20091 to n, inclusive, he definitely cannot walk to house number 1. When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house. You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109\u2009+\u20097).", "input_spec": "The single line contains two space-separated integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u20091000,\u20091\u2009\u2264\u2009k\u2009\u2264\u2009min(8,\u2009n)) \u2014 the number of the houses and the number k from the statement.", "output_spec": "In a single line print a single integer \u2014 the answer to the problem modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["5 2", "7 4"], "sample_outputs": ["54", "1728"], "notes": null}, "src_uid": "cc838bc14408f14f984a349fea9e9694"} {"nl": {"description": "Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.", "input_spec": "The input data consists of only one integer x (\u2009-\u2009109\u2009\u2264\u2009x\u2009\u2264\u2009109).", "output_spec": "Output the minimal number of jumps that Jack requires to reach x.", "sample_inputs": ["2", "6", "0"], "sample_outputs": ["3", "3", "0"], "notes": null}, "src_uid": "18644c9df41b9960594fdca27f1d2fec"} {"nl": {"description": "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_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.", "output_spec": "Output \"YES\", if the string is a pangram and \"NO\" otherwise.", "sample_inputs": ["12\ntoosmallword", "35\nTheQuickBrownFoxJumpsOverTheLazyDog"], "sample_outputs": ["NO", "YES"], "notes": null}, "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"nl": {"description": "Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the screen as possible and fits within it completely. Thus, he may have to zoom the movie in or out, but Manao will always change the frame proportionally in both dimensions.Calculate the ratio of empty screen (the part of the screen not occupied by the movie) to the total screen size. Print the answer as an irreducible fraction p\u2009/\u2009q.", "input_spec": "A single line contains four space-separated integers a, b, c, d (1\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d\u2009\u2264\u20091000).", "output_spec": "Print the answer to the problem as \"p/q\", where p is a non-negative integer, q is a positive integer and numbers p and q don't have a common divisor larger than 1.", "sample_inputs": ["1 1 3 2", "4 3 2 2"], "sample_outputs": ["1/3", "1/4"], "notes": "NoteSample 1. Manao's monitor has a square screen. The movie has 3:2 horizontal to vertical length ratio. Obviously, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. In this case, only 2/3 of the monitor will project the movie in the horizontal dimension: Sample 2. This time the monitor's width is 4/3 times larger than its height and the movie's frame is square. In this case, the picture must take up the whole monitor in the vertical dimension and only 3/4 in the horizontal dimension: "}, "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"} {"nl": {"description": "The circle line of the Roflanpolis subway has $$$n$$$ stations.There are two parallel routes in the subway. The first one visits stations in order $$$1 \\to 2 \\to \\ldots \\to n \\to 1 \\to 2 \\to \\ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x+1)$$$ if $$$x < n$$$ and $$$1$$$ otherwise). The second route visits stations in order $$$n \\to (n-1) \\to \\ldots \\to 1 \\to n \\to (n-1) \\to \\ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x-1)$$$ if $$$x>1$$$ and $$$n$$$ otherwise). All trains depart their stations simultaneously, and it takes exactly $$$1$$$ minute to arrive at the next station.Two toads live in this city, their names are Daniel and Vlad.Daniel is currently in a train of the first route at station $$$a$$$ and will exit the subway when his train reaches station $$$x$$$.Coincidentally, Vlad is currently in a train of the second route at station $$$b$$$ and he will exit the subway when his train reaches station $$$y$$$.Surprisingly, all numbers $$$a,x,b,y$$$ are distinct.Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.", "input_spec": "The first line contains five space-separated integers $$$n$$$, $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ ($$$4 \\leq n \\leq 100$$$, $$$1 \\leq a, x, b, y \\leq n$$$, all numbers among $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ are distinct)\u00a0\u2014 the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.", "output_spec": "Output \"YES\" if there is a time moment when Vlad and Daniel are at the same station, and \"NO\" otherwise. You can print each letter in any case (upper or lower).", "sample_inputs": ["5 1 4 3 2", "10 2 1 9 10"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example, Daniel and Vlad start at the stations $$$(1, 3)$$$. One minute later they are at stations $$$(2, 2)$$$. They are at the same station at this moment. Note that Vlad leaves the subway right after that.Consider the second example, let's look at the stations Vlad and Daniel are at. They are: initially $$$(2, 9)$$$, after $$$1$$$ minute $$$(3, 8)$$$, after $$$2$$$ minutes $$$(4, 7)$$$, after $$$3$$$ minutes $$$(5, 6)$$$, after $$$4$$$ minutes $$$(6, 5)$$$, after $$$5$$$ minutes $$$(7, 4)$$$, after $$$6$$$ minutes $$$(8, 3)$$$, after $$$7$$$ minutes $$$(9, 2)$$$, after $$$8$$$ minutes $$$(10, 1)$$$, after $$$9$$$ minutes $$$(1, 10)$$$. After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station."}, "src_uid": "5b889751f82c9f32f223cdee0c0095e4"} {"nl": {"description": "\"QAQ\" is a word to denote an expression of crying. Imagine \"Q\" as eyes with tears and \"A\" as a mouth.Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of \"QAQ\" in the string (Diamond is so cute!). illustration by \u732b\u5c4b https://twitter.com/nekoyaliu Bort wants to know how many subsequences \"QAQ\" are in the string Diamond has given. Note that the letters \"QAQ\" don't have to be consecutive, but the order of letters should be exact.", "input_spec": "The only line contains a string of length n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). It's guaranteed that the string only contains uppercase English letters.", "output_spec": "Print a single integer\u00a0\u2014 the number of subsequences \"QAQ\" in the string.", "sample_inputs": ["QAQAQYSYIOIWIN", "QAQQQZZYNOIWIN"], "sample_outputs": ["4", "3"], "notes": "NoteIn the first example there are 4 subsequences \"QAQ\": \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\"."}, "src_uid": "8aef4947322438664bd8610632fe0947"} {"nl": {"description": "Kavi has $$$2n$$$ points lying on the $$$OX$$$ axis, $$$i$$$-th of which is located at $$$x = i$$$.Kavi considers all ways to split these $$$2n$$$ points into $$$n$$$ pairs. Among those, he is interested in good pairings, which are defined as follows:Consider $$$n$$$ segments with ends at the points in correspondent pairs. The pairing is called good, if for every $$$2$$$ different segments $$$A$$$ and $$$B$$$ among those, at least one of the following holds: One of the segments $$$A$$$ and $$$B$$$ lies completely inside the other. $$$A$$$ and $$$B$$$ have the same length. Consider the following example: $$$A$$$ is a good pairing since the red segment lies completely inside the blue segment.$$$B$$$ is a good pairing since the red and the blue segment have the same length.$$$C$$$ is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size.Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo $$$998244353$$$.Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another.", "input_spec": "The single line of the input contains a single integer $$$n$$$ $$$(1\\le n \\le 10^6)$$$.", "output_spec": "Print the number of good pairings modulo $$$998244353$$$.", "sample_inputs": ["1", "2", "3", "100"], "sample_outputs": ["1", "3", "6", "688750769"], "notes": "NoteThe good pairings for the second example are: In the third example, the good pairings are: "}, "src_uid": "09be46206a151c237dc9912df7e0f057"} {"nl": {"description": "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). Alex asks you to compute the number of cells in a $$$n$$$-th order rhombus.", "input_spec": "The first and only input line contains integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 order of a rhombus whose numbers of cells should be computed.", "output_spec": "Print exactly one integer\u00a0\u2014 the number of cells in a $$$n$$$-th order rhombus.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["1", "5", "13"], "notes": "NoteImages of rhombus corresponding to the examples are given in the statement."}, "src_uid": "758d342c1badde6d0b4db81285be780c"} {"nl": {"description": "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 a1\u2009<\u2009j\u2009<\u2009a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200) \u2014 length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters.", "output_spec": "Print maximum number of elements in pretty set of positions for string s.", "sample_inputs": ["11\naaaaBaabAbA", "12\nzACaAbbaazzC", "3\nABC"], "sample_outputs": ["2", "3", "0"], "notes": "NoteIn 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."}, "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"nl": {"description": "There is a field of size $$$2 \\times 2$$$. Each cell of this field can either contain grass or be empty. The value $$$a_{i, j}$$$ is $$$1$$$ if the cell $$$(i, j)$$$ contains grass, or $$$0$$$ otherwise.In one move, you can choose one row and one column and cut all the grass in this row and this column. In other words, you choose the row $$$x$$$ and the column $$$y$$$, then you cut the grass in all cells $$$a_{x, i}$$$ and all cells $$$a_{i, y}$$$ for all $$$i$$$ from $$$1$$$ to $$$2$$$. After you cut the grass from a cell, it becomes empty (i.\u2009e. its value is replaced by $$$0$$$).Your task is to find the minimum number of moves required to cut the grass in all non-empty cells of the field (i.\u2009e. make all $$$a_{i, j}$$$ zeros).You have to answer $$$t$$$ independent test cases.", "input_spec": "The first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 16$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow. The test case consists of two lines, each of these lines contains two integers. The $$$j$$$-th integer in the $$$i$$$-th row is $$$a_{i, j}$$$. If $$$a_{i, j} = 0$$$ then the cell $$$(i, j)$$$ is empty, and if $$$a_{i, j} = 1$$$ the cell $$$(i, j)$$$ contains grass.", "output_spec": "For each test case, print one integer \u2014 the minimum number of moves required to cut the grass in all non-empty cells of the field (i.\u2009e. make all $$$a_{i, j}$$$ zeros) in the corresponding test case.", "sample_inputs": ["3\n\n0 0\n\n0 0\n\n1 0\n\n0 1\n\n1 1\n\n1 1"], "sample_outputs": ["0\n1\n2"], "notes": null}, "src_uid": "7336b8becd2438f0439240ee8f9610ec"} {"nl": {"description": "There are $$$b$$$ boys and $$$g$$$ girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and $$$n$$$ participants have accepted the invitation. The organizers do not know how many boys and girls are among them.Organizers are preparing red badges for girls and blue ones for boys.Vasya prepared $$$n+1$$$ decks of badges. The $$$i$$$-th (where $$$i$$$ is from $$$0$$$ to $$$n$$$, inclusive) deck contains $$$i$$$ blue badges and $$$n-i$$$ red ones. The total number of badges in any deck is exactly $$$n$$$.Determine the minimum number of decks among these $$$n+1$$$ that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.", "input_spec": "The first line contains an integer $$$b$$$ ($$$1 \\le b \\le 300$$$), the number of boys. The second line contains an integer $$$g$$$ ($$$1 \\le g \\le 300$$$), the number of girls. The third line contains an integer $$$n$$$ ($$$1 \\le n \\le b + g$$$), the number of the board games tournament participants.", "output_spec": "Output the only integer, the minimum number of badge decks that Vasya could take.", "sample_inputs": ["5\n6\n3", "5\n3\n5"], "sample_outputs": ["4", "4"], "notes": "NoteIn the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used."}, "src_uid": "9266a69e767df299569986151852e7b1"} {"nl": {"description": "The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N\u2009\u00d7\u2009N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information.Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out.", "input_spec": "The first line of the input contains one number N (1\u2009\u2264\u2009N\u2009\u2264\u200910) \u2013 the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format.", "output_spec": "The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations.", "sample_inputs": ["4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX", "2\nXX\nOO\nXO\nOX"], "sample_outputs": ["Yes", "No"], "notes": "NoteIn the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. "}, "src_uid": "2e793c9f476d03e8ba7df262db1c06e4"} {"nl": {"description": "Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: 'U': go up, (x, y) \u2009\u2192\u2009 (x, y+1); 'D': go down, (x, y) \u2009\u2192\u2009 (x, y-1); 'L': go left, (x, y) \u2009\u2192\u2009 (x-1, y); 'R': go right, (x, y) \u2009\u2192\u2009 (x+1, y). The robot will do the operations in s from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (a,\u2009b).", "input_spec": "The first line contains two integers a and b, (\u2009-\u2009109\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109). The second line contains a string s (1\u2009\u2264\u2009|s|\u2009\u2264\u2009100, s only contains characters 'U', 'D', 'L', 'R') \u2014 the command.", "output_spec": "Print \"Yes\" if the robot will be located at (a,\u2009b), and \"No\" otherwise.", "sample_inputs": ["2 2\nRU", "1 2\nRU", "-1 1000000000\nLRRLU", "0 0\nD"], "sample_outputs": ["Yes", "No", "Yes", "Yes"], "notes": "NoteIn the first and second test case, command string is \"RU\", so the robot will go right, then go up, then right, and then up and so on.The locations of its moves are (0, 0) \u2009\u2192\u2009 (1, 0) \u2009\u2192\u2009 (1, 1) \u2009\u2192\u2009 (2, 1) \u2009\u2192\u2009 (2, 2) \u2009\u2192\u2009 ...So it can reach (2, 2) but not (1, 2)."}, "src_uid": "5d6212e28c7942e9ff4d096938b782bf"} {"nl": {"description": "Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). The next line contains n integers x1,\u2009x2,\u2009...,\u2009xn (0\u2009\u2264\u2009xi\u2009\u2264\u2009100).", "output_spec": "Output a single integer \u2014 the minimal possible number of piles.", "sample_inputs": ["3\n0 0 10", "5\n0 1 2 3 4", "4\n0 0 0 0", "9\n0 1 0 2 0 1 1 2 10"], "sample_outputs": ["2", "1", "4", "3"], "notes": "NoteIn example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom)."}, "src_uid": "7c710ae68f27f140e7e03564492f7214"} {"nl": {"description": "Let's call a string a phone number if it has length 11 and fits the pattern \"8xxxxxxxxxx\", where each \"x\" is replaced by a digit.For example, \"80123456789\" and \"80000000000\" are phone numbers, while \"8012345678\" and \"79000000000\" are not.You have $$$n$$$ cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.", "input_spec": "The first line contains an integer $$$n$$$\u00a0\u2014 the number of cards with digits that you have ($$$1 \\leq n \\leq 100$$$). The second line contains a string of $$$n$$$ digits (characters \"0\", \"1\", ..., \"9\") $$$s_1, s_2, \\ldots, s_n$$$. The string will not contain any other characters, such as leading or trailing spaces.", "output_spec": "If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.", "sample_inputs": ["11\n00000000008", "22\n0011223344556677889988", "11\n31415926535"], "sample_outputs": ["1", "2", "0"], "notes": "NoteIn the first example, one phone number, \"8000000000\", can be made from these cards.In the second example, you can make two phone numbers from the cards, for example, \"80123456789\" and \"80123456789\".In the third example you can't make any phone number from the given cards."}, "src_uid": "259d01b81bef5536b969247ff2c2d776"} {"nl": {"description": "You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.Divisor of n is any such natural number, that n can be divided by it without remainder.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u20091015, 1\u2009\u2264\u2009k\u2009\u2264\u2009109).", "output_spec": "If n has less than k divisors, output -1. Otherwise, output the k-th smallest divisor of n.", "sample_inputs": ["4 2", "5 3", "12 5"], "sample_outputs": ["2", "-1", "6"], "notes": "NoteIn the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1."}, "src_uid": "6ba39b428a2d47b7d199879185797ffb"} {"nl": {"description": "Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.", "input_spec": "The input consists of three lines, each containing a pair of integer coordinates xi and yi (\u2009-\u20091000\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u20091000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.", "output_spec": "First print integer k\u00a0\u2014 the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices. Then print k lines, each containing a pair of integer\u00a0\u2014 possible coordinates of the fourth point.", "sample_inputs": ["0 0\n1 0\n0 1"], "sample_outputs": ["3\n1 -1\n-1 1\n1 1"], "notes": "NoteIf you need clarification of what parallelogram is, please check Wikipedia page:https://en.wikipedia.org/wiki/Parallelogram"}, "src_uid": "7725f9906a1b87bf4e866df03112f1e0"} {"nl": {"description": "Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m,\u20092m,\u20093m,\u2009...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?", "input_spec": "The single line contains two integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u2009100;\u00a02\u2009\u2264\u2009m\u2009\u2264\u2009100), separated by a space.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["2 2", "9 3"], "sample_outputs": ["3", "13"], "notes": "NoteIn the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day."}, "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"nl": {"description": "Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $$$360$$$ degrees and a pointer which initially points at zero: Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $$$n$$$ times. The $$$i$$$-th rotation should be $$$a_i$$$ degrees, either clockwise or counterclockwise, and after all $$$n$$$ rotations the pointer should again point at zero.This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $$$n$$$ rotations the pointer will point at zero again.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 15$$$) \u2014 the number of rotations. Each of the following $$$n$$$ lines contains one integer $$$a_i$$$ ($$$1 \\leq a_i \\leq 180$$$) \u2014 the angle of the $$$i$$$-th rotation in degrees.", "output_spec": "If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word \"YES\". Otherwise, print \"NO\". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower).", "sample_inputs": ["3\n10\n20\n30", "3\n10\n10\n10", "3\n120\n120\n120"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $$$360$$$ degrees clockwise and the pointer will point at zero again."}, "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"} {"nl": {"description": "A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i\u2009-\u20091 liters and costs ci roubles. The number of bottles of each type in the store can be considered infinite.You want to buy at least L liters of lemonade. How many roubles do you have to spend?", "input_spec": "The first line contains two integers n and L (1\u2009\u2264\u2009n\u2009\u2264\u200930; 1\u2009\u2264\u2009L\u2009\u2264\u2009109)\u00a0\u2014 the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c1,\u2009c2,\u2009...,\u2009cn (1\u2009\u2264\u2009ci\u2009\u2264\u2009109)\u00a0\u2014 the costs of bottles of different types.", "output_spec": "Output a single integer\u00a0\u2014 the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.", "sample_inputs": ["4 12\n20 30 70 90", "4 3\n10000 1000 100 10", "4 3\n10 100 1000 10000", "5 787787787\n123456789 234567890 345678901 456789012 987654321"], "sample_outputs": ["150", "10", "30", "44981600785557577"], "notes": "NoteIn the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles."}, "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"nl": {"description": "Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a \"crime\" and find out what is happening. He can ask any questions whatsoever that can be answered with \"Yes\" or \"No\". All the rest agree beforehand to answer the questions like that: if the question\u2019s last letter is a vowel, they answer \"Yes\" and if the last letter is a consonant, they answer \"No\". Of course, the sleuth knows nothing about it and his task is to understand that.Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That\u2019s why Vasya\u2019s friends ask you to write a program that would give answers instead of them.The English alphabet vowels are: A, E, I, O, U, YThe English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z", "input_spec": "The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line \u2014 as the last symbol and that the line contains at least one letter.", "output_spec": "Print answer for the question in a single line: YES if the answer is \"Yes\", NO if the answer is \"No\". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.", "sample_inputs": ["Is it a melon?", "Is it an apple?", "Is it a banana ?", "Is it an apple and a banana simultaneouSLY?"], "sample_outputs": ["NO", "YES", "YES", "YES"], "notes": null}, "src_uid": "dea7eb04e086a4c1b3924eff255b9648"} {"nl": {"description": "Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.The entire universe turned into an enormous clock face with three hands\u00a0\u2014 hour, minute, and second. Time froze, and clocks now show the time h hours, m minutes, s seconds.Last time Misha talked with the coordinator at t1 o'clock, so now he stands on the number t1 on the clock face. The contest should be ready by t2 o'clock. In the terms of paradox it means that Misha has to go to number t2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).Given the hands' positions, t1, and t2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from t1 to t2 by the clock face.", "input_spec": "Five integers h, m, s, t1, t2 (1\u2009\u2264\u2009h\u2009\u2264\u200912, 0\u2009\u2264\u2009m,\u2009s\u2009\u2264\u200959, 1\u2009\u2264\u2009t1,\u2009t2\u2009\u2264\u200912, t1\u2009\u2260\u2009t2). Misha's position and the target time do not coincide with the position of any hand.", "output_spec": "Print \"YES\" (quotes for clarity), if Misha can prepare the contest on time, and \"NO\" otherwise. You can print each character either upper- or lowercase (\"YeS\" and \"yes\" are valid when the answer is \"YES\").", "sample_inputs": ["12 30 45 3 11", "12 0 1 12 1", "3 47 0 4 9"], "sample_outputs": ["NO", "YES", "YES"], "notes": "NoteThe three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. "}, "src_uid": "912c8f557a976bdedda728ba9f916c95"} {"nl": {"description": "Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.Your problem is to print the minimum possible length of the sequence of moves after the replacements.", "input_spec": "The first line of the input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the length of the sequence. The second line contains the sequence consisting of n characters U and R.", "output_spec": "Print the minimum possible length of the sequence of moves after all replacements are done.", "sample_inputs": ["5\nRUURU", "17\nUUURRRRRUUURURUUU"], "sample_outputs": ["3", "13"], "notes": "NoteIn the first test the shortened sequence of moves may be DUD (its length is 3).In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13)."}, "src_uid": "986ae418ce82435badadb0bd5588f45b"} {"nl": {"description": "Let's write all the positive integer numbers one after another from $$$1$$$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...Your task is to print the $$$k$$$-th digit of this sequence.", "input_spec": "The first and only line contains integer $$$k$$$ ($$$1 \\le k \\le 10000$$$) \u2014 the position to process ($$$1$$$-based index).", "output_spec": "Print the $$$k$$$-th digit of the resulting infinite sequence.", "sample_inputs": ["7", "21"], "sample_outputs": ["7", "5"], "notes": null}, "src_uid": "1503d761dd4e129fb7c423da390544ff"} {"nl": {"description": "Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.", "input_spec": "The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol \"|\" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.", "output_spec": "If you cannot put all the weights on the scales so that the scales were in equilibrium, print string \"Impossible\". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.", "sample_inputs": ["AC|T\nL", "|ABC\nXYZ", "W|T\nF", "ABC|\nD"], "sample_outputs": ["AC|TL", "XYZ|ABC", "Impossible", "Impossible"], "notes": null}, "src_uid": "917f173b8523ddd38925238e5d2089b9"} {"nl": {"description": "Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i.\u00a0e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i.\u00a0e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. The picture illustrates the first and the second samples. Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!", "input_spec": "The only line contains three integers n, m and k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200910\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u20092nm)\u00a0\u2014 the number of lanes, the number of desks in each lane and the number of Santa Claus' place.", "output_spec": "Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be \"L\", if Santa Clause should sit on the left, and \"R\" if his place is on the right.", "sample_inputs": ["4 3 9", "4 3 24", "2 4 4"], "sample_outputs": ["2 2 L", "4 3 R", "1 2 R"], "notes": "NoteThe first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right."}, "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"nl": {"description": "Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (n\u2009-\u20091) friends. Determine if Sereja's friends can play the game so that nobody loses.", "input_spec": "The first line contains integers n and s (2\u2009\u2264\u2009n\u2009\u2264\u2009100;\u00a01\u2009\u2264\u2009s\u2009\u2264\u20091000) \u2014 the number of mugs and the volume of the cup. The next line contains n integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u200910). Number ai means the volume of the i-th mug.", "output_spec": "In a single line, print \"YES\" (without the quotes) if his friends can play in the described manner, and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["3 4\n1 1 1", "3 4\n3 1 3", "3 4\n4 4 4"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "496baae594b32c5ffda35b896ebde629"} {"nl": {"description": "Today an outstanding event is going to happen in the forest\u00a0\u2014 hedgehog Filya will come to his old fried Sonya!Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.Calculate the number of minutes they will be able to spend together.", "input_spec": "The only line of the input contains integers l1, r1, l2, r2 and k (1\u2009\u2264\u2009l1,\u2009r1,\u2009l2,\u2009r2,\u2009k\u2009\u2264\u20091018, l1\u2009\u2264\u2009r1, l2\u2009\u2264\u2009r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.", "output_spec": "Print one integer\u00a0\u2014 the number of minutes Sonya and Filya will be able to spend together.", "sample_inputs": ["1 10 9 20 1", "1 100 50 200 75"], "sample_outputs": ["2", "50"], "notes": "NoteIn the first sample, they will be together during minutes 9 and 10.In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100."}, "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"} {"nl": {"description": "Sasha is a very happy guy, that's why he is always on the move. There are $$$n$$$ cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from $$$1$$$ to $$$n$$$ in increasing order. The distance between any two adjacent cities is equal to $$$1$$$ kilometer. Since all roads in the country are directed, it's possible to reach the city $$$y$$$ from the city $$$x$$$ only if $$$x < y$$$. Once Sasha decided to go on a trip around the country and to visit all $$$n$$$ cities. He will move with the help of his car, Cheetah-2677. The tank capacity of this model is $$$v$$$ liters, and it spends exactly $$$1$$$ liter of fuel for $$$1$$$ kilometer of the way. At the beginning of the journey, the tank is empty. Sasha is located in the city with the number $$$1$$$ and wants to get to the city with the number $$$n$$$. There is a gas station in each city. In the $$$i$$$-th city, the price of $$$1$$$ liter of fuel is $$$i$$$ dollars. It is obvious that at any moment of time, the tank can contain at most $$$v$$$ liters of fuel.Sasha doesn't like to waste money, that's why he wants to know what is the minimum amount of money is needed to finish the trip if he can buy fuel in any city he wants. Help him to figure it out!", "input_spec": "The first line contains two integers $$$n$$$ and $$$v$$$ ($$$2 \\le n \\le 100$$$, $$$1 \\le v \\le 100$$$) \u00a0\u2014 the number of cities in the country and the capacity of the tank.", "output_spec": "Print one integer\u00a0\u2014 the minimum amount of money that is needed to finish the trip.", "sample_inputs": ["4 2", "7 6"], "sample_outputs": ["4", "6"], "notes": "NoteIn the first example, Sasha can buy $$$2$$$ liters for $$$2$$$ dollars ($$$1$$$ dollar per liter) in the first city, drive to the second city, spend $$$1$$$ liter of fuel on it, then buy $$$1$$$ liter for $$$2$$$ dollars in the second city and then drive to the $$$4$$$-th city. Therefore, the answer is $$$1+1+2=4$$$.In the second example, the capacity of the tank allows to fill the tank completely in the first city, and drive to the last city without stops in other cities."}, "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"nl": {"description": "As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that for some function . (This equation should hold for any integer x in the range 0 to p\u2009-\u20091, inclusive.)It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109\u2009+\u20097.", "input_spec": "The input consists of two space-separated integers p and k (3\u2009\u2264\u2009p\u2009\u2264\u20091\u2009000\u2009000, 0\u2009\u2264\u2009k\u2009\u2264\u2009p\u2009-\u20091) on a single line. It is guaranteed that p is an odd prime number.", "output_spec": "Print a single integer, the number of distinct functions f modulo 109\u2009+\u20097.", "sample_inputs": ["3 2", "5 4"], "sample_outputs": ["3", "25"], "notes": "NoteIn the first sample, p\u2009=\u20093 and k\u2009=\u20092. The following functions work: f(0)\u2009=\u20090, f(1)\u2009=\u20091, f(2)\u2009=\u20092. f(0)\u2009=\u20090, f(1)\u2009=\u20092, f(2)\u2009=\u20091. f(0)\u2009=\u2009f(1)\u2009=\u2009f(2)\u2009=\u20090. "}, "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e"} {"nl": {"description": "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_spec": "The first line contains the current time in the format hh:mm (0\u2009\u2264\u2009hh\u2009<\u200924,\u20090\u2009\u2264\u2009mm\u2009<\u200960). 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\u2009\u2264\u2009a\u2009\u2264\u2009104) \u2014 the number of the minutes passed.", "output_spec": "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.", "sample_inputs": ["23:59\n10", "20:20\n121", "10:10\n0"], "sample_outputs": ["00:09", "22:21", "10:10"], "notes": null}, "src_uid": "20c2d9da12d6b88f300977d74287a15d"} {"nl": {"description": "Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1 and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.", "input_spec": "The first line of the input contains four integers d, L, v1, v2 (1\u2009\u2264\u2009d,\u2009L,\u2009v1,\u2009v2\u2009\u2264\u200910\u2009000,\u2009d\u2009<\u2009L)\u00a0\u2014 Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.", "output_spec": "Print a single real value\u00a0\u2014 the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10\u2009-\u20096. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .", "sample_inputs": ["2 6 2 2", "1 9 1 2"], "sample_outputs": ["1.00000000000000000000", "2.66666666666666650000"], "notes": "NoteIn the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.In the second sample he needs to occupy the position . In this case both presses move to his edges at the same time."}, "src_uid": "f34f3f974a21144b9f6e8615c41830f5"} {"nl": {"description": "Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.", "input_spec": "The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team.", "output_spec": "Output \"TEAM 1 WINS\" if the first team won, \"TEAM 2 WINS\" if the second team won, and \"TIE\" if there was a tie.", "sample_inputs": ["[]()[]8<\n8<[]()8<", "8<8<()\n[]8<[]"], "sample_outputs": ["TEAM 2 WINS", "TIE"], "notes": null}, "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf"} {"nl": {"description": "Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.", "input_spec": "Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.", "output_spec": "If the first string is less than the second one, print \"-1\". If the second string is less than the first one, print \"1\". If the strings are equal, print \"0\". Note that the letters' case is not taken into consideration when the strings are compared.", "sample_inputs": ["aaaa\naaaA", "abs\nAbz", "abcdefg\nAbCdEfF"], "sample_outputs": ["0", "-1", "1"], "notes": "NoteIf you want more formal information about the lexicographical order (also known as the \"dictionary order\" or \"alphabetical order\"), you can visit the following site: http://en.wikipedia.org/wiki/Lexicographical_order"}, "src_uid": "ffeae332696a901813677bd1033cf01e"} {"nl": {"description": "There is a card game called \"Durak\", which means \"Fool\" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly \u2014 you can find them later yourselves if you want.To play durak you need a pack of 36 cards. Each card has a suit (\"S\", \"H\", \"D\" and \"C\") and a rank (in the increasing order \"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\" and \"A\"). At the beginning of the game one suit is arbitrarily chosen as trump. The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards\u2019 ranks are. In all other cases you can not beat the second card with the first one.You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.", "input_spec": "The first line contains the tramp suit. It is \"S\", \"H\", \"D\" or \"C\". The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank (\"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\" and \"A\"), and the second one stands for the suit (\"S\", \"H\", \"D\" and \"C\").", "output_spec": "Print \"YES\" (without the quotes) if the first cards beats the second one. Otherwise, print \"NO\" (also without the quotes).", "sample_inputs": ["H\nQH 9S", "S\n8D 6D", "C\n7H AS"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "da13bd5a335c7f81c5a963b030655c26"} {"nl": {"description": "Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through $$$n \\cdot k$$$ cities. The cities are numerated from $$$1$$$ to $$$n \\cdot k$$$, the distance between the neighboring cities is exactly $$$1$$$ km.Sergey does not like beetles, he loves burgers. Fortunately for him, there are $$$n$$$ fast food restaurants on the circle, they are located in the $$$1$$$-st, the $$$(k + 1)$$$-st, the $$$(2k + 1)$$$-st, and so on, the $$$((n-1)k + 1)$$$-st cities, i.e. the distance between the neighboring cities with fast food restaurants is $$$k$$$ km.Sergey began his journey at some city $$$s$$$ and traveled along the circle, making stops at cities each $$$l$$$ km ($$$l > 0$$$), until he stopped in $$$s$$$ once again. Sergey then forgot numbers $$$s$$$ and $$$l$$$, but he remembers that the distance from the city $$$s$$$ to the nearest fast food restaurant was $$$a$$$ km, and the distance from the city he stopped at after traveling the first $$$l$$$ km from $$$s$$$ to the nearest fast food restaurant was $$$b$$$ km. Sergey always traveled in the same direction along the circle, but when he calculated distances to the restaurants, he considered both directions.Now Sergey is interested in two integers. The first integer $$$x$$$ is the minimum number of stops (excluding the first) Sergey could have done before returning to $$$s$$$. The second integer $$$y$$$ is the maximum number of stops (excluding the first) Sergey could have done before returning to $$$s$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100\\,000$$$)\u00a0\u2014 the number of fast food restaurants on the circle and the distance between the neighboring restaurants, respectively. The second line contains two integers $$$a$$$ and $$$b$$$ ($$$0 \\le a, b \\le \\frac{k}{2}$$$)\u00a0\u2014 the distances to the nearest fast food restaurants from the initial city and from the city Sergey made the first stop at, respectively.", "output_spec": "Print the two integers $$$x$$$ and $$$y$$$.", "sample_inputs": ["2 3\n1 1", "3 2\n0 0", "1 10\n5 3"], "sample_outputs": ["1 6", "1 3", "5 5"], "notes": "NoteIn the first example the restaurants are located in the cities $$$1$$$ and $$$4$$$, the initial city $$$s$$$ could be $$$2$$$, $$$3$$$, $$$5$$$, or $$$6$$$. The next city Sergey stopped at could also be at cities $$$2, 3, 5, 6$$$. Let's loop through all possible combinations of these cities. If both $$$s$$$ and the city of the first stop are at the city $$$2$$$ (for example, $$$l = 6$$$), then Sergey is at $$$s$$$ after the first stop already, so $$$x = 1$$$. In other pairs Sergey needs $$$1, 2, 3$$$, or $$$6$$$ stops to return to $$$s$$$, so $$$y = 6$$$.In the second example Sergey was at cities with fast food restaurant both initially and after the first stop, so $$$l$$$ is $$$2$$$, $$$4$$$, or $$$6$$$. Thus $$$x = 1$$$, $$$y = 3$$$.In the third example there is only one restaurant, so the possible locations of $$$s$$$ and the first stop are: $$$(6, 8)$$$ and $$$(6, 4)$$$. For the first option $$$l = 2$$$, for the second $$$l = 8$$$. In both cases Sergey needs $$$x=y=5$$$ stops to go to $$$s$$$."}, "src_uid": "5bb4adff1b332f43144047955eefba0c"} {"nl": {"description": "Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below.", "input_spec": "Input will consist of a single integer A (1\u2009\u2264\u2009A\u2009\u2264\u2009105), the desired number of ways.", "output_spec": "In the first line print integers N and M (1\u2009\u2264\u2009N\u2009\u2264\u2009106,\u20091\u2009\u2264\u2009M\u2009\u2264\u200910), the amount of change to be made, and the number of denominations, respectively. Then print M integers D1,\u2009D2,\u2009...,\u2009DM (1\u2009\u2264\u2009Di\u2009\u2264\u2009106), the denominations of the coins. All denominations must be distinct: for any i\u2009\u2260\u2009j we must have Di\u2009\u2260\u2009Dj. If there are multiple tests, print any of them. You can print denominations in atbitrary order.", "sample_inputs": ["18", "3", "314"], "sample_outputs": ["30 4\n1 5 10 25", "20 2\n5 2", "183 4\n6 5 2 139"], "notes": null}, "src_uid": "5c000b4c82a8ecef764f53fda8cee541"} {"nl": {"description": "Berland Football Cup starts really soon! Commentators from all over the world come to the event.Organizers have already built $$$n$$$ commentary boxes. $$$m$$$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.If $$$n$$$ is not divisible by $$$m$$$, it is impossible to distribute the boxes to the delegations at the moment.Organizers can build a new commentary box paying $$$a$$$ burles and demolish a commentary box paying $$$b$$$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$)?", "input_spec": "The only line contains four integer numbers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$1 \\le n, m \\le 10^{12}$$$, $$$1 \\le a, b \\le 100$$$), where $$$n$$$ is the initial number of the commentary boxes, $$$m$$$ is the number of delegations to come, $$$a$$$ is the fee to build a box and $$$b$$$ is the fee to demolish a box.", "output_spec": "Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$). It is allowed that the final number of the boxes is equal to $$$0$$$.", "sample_inputs": ["9 7 3 8", "2 7 3 7", "30 6 17 19"], "sample_outputs": ["15", "14", "0"], "notes": "NoteIn the first example organizers can build $$$5$$$ boxes to make the total of $$$14$$$ paying $$$3$$$ burles for the each of them.In the second example organizers can demolish $$$2$$$ boxes to make the total of $$$0$$$ paying $$$7$$$ burles for the each of them.In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $$$5$$$ boxes."}, "src_uid": "c05d753b35545176ad468b99ff13aa39"} {"nl": {"description": "Let's define the permutation of length n as an array p\u2009=\u2009[p1,\u2009p2,\u2009...,\u2009pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a sequence of numbers such that each element of this sequence is being mapped into the next element of this sequence (and the last element of the cycle is being mapped into the first element of the cycle). The cyclic representation is a representation of p as a collection of cycles forming p. For example, permutation p\u2009=\u2009[4,\u20091,\u20096,\u20092,\u20095,\u20093] has a cyclic representation that looks like (142)(36)(5) because 1 is replaced by 4, 4 is replaced by 2, 2 is replaced by 1, 3 and 6 are swapped, and 5 remains in place. Permutation may have several cyclic representations, so Kyoya defines the standard cyclic representation of a permutation as follows. First, reorder the elements within each cycle so the largest element is first. Then, reorder all of the cycles so they are sorted by their first element. For our example above, the standard cyclic representation of [4,\u20091,\u20096,\u20092,\u20095,\u20093] is (421)(5)(63).Now, Kyoya notices that if we drop the parenthesis in the standard cyclic representation, we get another permutation! For instance, [4,\u20091,\u20096,\u20092,\u20095,\u20093] will become [4,\u20092,\u20091,\u20095,\u20096,\u20093].Kyoya notices that some permutations don't change after applying operation described above at all. He wrote all permutations of length n that do not change in a list in lexicographic order. Unfortunately, his friend Tamaki Suoh lost this list. Kyoya wishes to reproduce the list and he needs your help. Given the integers n and k, print the permutation that was k-th on Kyoya's list.", "input_spec": "The first line will contain two integers n, k (1\u2009\u2264\u2009n\u2009\u2264\u200950, 1\u2009\u2264\u2009k\u2009\u2264\u2009min{1018,\u2009l} where l is the length of the Kyoya's list).", "output_spec": "Print n space-separated integers, representing the permutation that is the answer for the question. ", "sample_inputs": ["4 3", "10 1"], "sample_outputs": ["1 3 2 4", "1 2 3 4 5 6 7 8 9 10"], "notes": "NoteThe standard cycle representation is (1)(32)(4), which after removing parenthesis gives us the original permutation. The first permutation on the list would be [1,\u20092,\u20093,\u20094], while the second permutation would be [1,\u20092,\u20094,\u20093]."}, "src_uid": "e03c6d3bb8cf9119530668765691a346"} {"nl": {"description": "Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106) \u2014 the n mentioned in the statement.", "output_spec": "Print a single integer \u2014 the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.", "sample_inputs": ["9", "7"], "sample_outputs": ["504", "210"], "notes": "NoteThe least common multiple of some positive integers is the least positive integer which is multiple for each of them.The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7\u00b76\u00b75\u2009=\u2009210. It is the maximum value we can get."}, "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e"} {"nl": {"description": "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\u2009=\u20094722 answer is 4720. If n\u2009=\u20095 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_spec": "The first line contains single integer n (0\u2009\u2264\u2009n\u2009\u2264\u2009109)\u00a0\u2014 number that Vasya has.", "output_spec": "Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.", "sample_inputs": ["5", "113", "1000000000", "5432359"], "sample_outputs": ["0", "110", "1000000000", "5432360"], "notes": "NoteIn the first example n\u2009=\u20095. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10."}, "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9"} {"nl": {"description": "What are you doing at the end of the world? Are you busy? Will you save us?Nephren is playing a game with little leprechauns.She gives them an infinite array of strings, f0... \u221e.f0 is \"What are you doing at the end of the world? Are you busy? Will you save us?\".She wants to let more people know about it, so she defines fi\u2009=\u2009 \"What are you doing while sending \"fi\u2009-\u20091\"? Are you busy? Will you send \"fi\u2009-\u20091\"?\" for all i\u2009\u2265\u20091.For example, f1 is\"What are you doing while sending \"What are you doing at the end of the world? Are you busy? Will you save us?\"? Are you busy? Will you send \"What are you doing at the end of the world? Are you busy? Will you save us?\"?\". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).Can you answer her queries?", "input_spec": "The first line contains one integer q (1\u2009\u2264\u2009q\u2009\u2264\u200910)\u00a0\u2014 the number of Nephren's questions. Each of the next q lines describes Nephren's question and contains two integers n and k (0\u2009\u2264\u2009n\u2009\u2264\u2009105,\u20091\u2009\u2264\u2009k\u2009\u2264\u20091018).", "output_spec": "One line containing q characters. The i-th character in it should be the answer for the i-th query.", "sample_inputs": ["3\n1 1\n1 2\n1 111111111111", "5\n0 69\n1 194\n1 139\n0 47\n1 66", "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474"], "sample_outputs": ["Wh.", "abdef", "Areyoubusy"], "notes": "NoteFor the first two examples, refer to f0 and f1 given in the legend."}, "src_uid": "da09a893a33f2bf8fd00e321e16ab149"} {"nl": {"description": "It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.", "input_spec": "The single line contains integer y (1000\u2009\u2264\u2009y\u2009\u2264\u20099000) \u2014 the year number.", "output_spec": "Print a single integer \u2014 the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.", "sample_inputs": ["1987", "2013"], "sample_outputs": ["2013", "2014"], "notes": null}, "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"nl": {"description": "A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled \"Special Olympics\". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two rings just fine.Let us remind you that a ring is a region located between two concentric circles with radii r and R (r\u2009<\u2009R). These radii are called internal and external, respectively. Concentric circles are circles with centers located at the same point.Soon a white canvas, which can be considered as an infinite Cartesian plane, had two perfect rings, painted with solid black paint. As Sasha is very impulsive, the rings could have different radii and sizes, they intersect and overlap with each other in any way. We know only one thing for sure: the centers of the pair of rings are not the same.When Sasha got tired and fell into a deep sleep, a girl called Ilona came into the room and wanted to cut a circle for the sake of good memories. To make the circle beautiful, she decided to cut along the contour.We'll consider a contour to be a continuous closed line through which there is transition from one color to another (see notes for clarification). If the contour takes the form of a circle, then the result will be cutting out a circle, which Iona wants.But the girl's inquisitive mathematical mind does not rest: how many ways are there to cut a circle out of the canvas?", "input_spec": "The input contains two lines. Each line has four space-separated integers xi, yi, ri, Ri, that describe the i-th ring; xi and yi are coordinates of the ring's center, ri and Ri are the internal and external radii of the ring correspondingly (\u2009-\u2009100\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009100;\u00a01\u2009\u2264\u2009ri\u2009<\u2009Ri\u2009\u2264\u2009100). It is guaranteed that the centers of the rings do not coinside.", "output_spec": "A single integer \u2014 the number of ways to cut out a circle from the canvas.", "sample_inputs": ["60 60 45 55\n80 80 8 32", "60 60 45 55\n80 60 15 25", "50 50 35 45\n90 50 35 45"], "sample_outputs": ["1", "4", "0"], "notes": "NoteFigures for test samples are given below. The possible cuts are marked with red dotted line. "}, "src_uid": "4c2865e4742a29460ca64860740b84f4"} {"nl": {"description": "Consider a playoff tournament where $$$2^n$$$ athletes compete. The athletes are numbered from $$$1$$$ to $$$2^n$$$.The tournament is held in $$$n$$$ stages. In each stage, the athletes are split into pairs in such a way that each athlete belongs exactly to one pair. In each pair, the athletes compete against each other, and exactly one of them wins. The winner of each pair advances to the next stage, the athlete who was defeated gets eliminated from the tournament.The pairs are formed as follows: in the first stage, athlete $$$1$$$ competes against athlete $$$2$$$; $$$3$$$ competes against $$$4$$$; $$$5$$$ competes against $$$6$$$, and so on; in the second stage, the winner of the match \"$$$1$$$\u2013$$$2$$$\" competes against the winner of the match \"$$$3$$$\u2013$$$4$$$\"; the winner of the match \"$$$5$$$\u2013$$$6$$$\" competes against the winner of the match \"$$$7$$$\u2013$$$8$$$\", and so on; the next stages are held according to the same rules. When athletes $$$x$$$ and $$$y$$$ compete, the winner is decided as follows: if $$$x+y$$$ is odd, the athlete with the lower index wins (i.\u2009e. if $$$x < y$$$, then $$$x$$$ wins, otherwise $$$y$$$ wins); if $$$x+y$$$ is even, the athlete with the higher index wins. The following picture describes the way the tournament with $$$n = 3$$$ goes. Your task is the following one: given the integer $$$n$$$, determine the index of the athlete who wins the tournament.", "input_spec": "The first line contains one integer $$$t$$$ ($$$1 \\le t \\le 30$$$) \u2014 the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \\le n \\le 30$$$).", "output_spec": "For each test case, print one integer \u2014 the index of the winner of the tournament.", "sample_inputs": ["2\n3\n1"], "sample_outputs": ["7\n1"], "notes": "NoteThe case $$$n = 3$$$ is shown in the picture from the statement.If $$$n = 1$$$, then there's only one match between athletes $$$1$$$ and $$$2$$$. Since $$$1 + 2 = 3$$$ is an odd number, the athlete with the lower index wins. So, the athlete $$$1$$$ is the winner."}, "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"nl": {"description": "Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.Two prime numbers are called neighboring if there are no other prime numbers between them.You are to help Nick, and find out if he is right or wrong.", "input_spec": "The first line of the input contains two integers n (2\u2009\u2264\u2009n\u2009\u2264\u20091000) and k (0\u2009\u2264\u2009k\u2009\u2264\u20091000).", "output_spec": "Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.", "sample_inputs": ["27 2", "45 7"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form."}, "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"} {"nl": {"description": "Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n\u2009/\u20092 digits) equals the sum of digits in the second half (the sum of the last n\u2009/\u20092 digits). Check if the given ticket is lucky.", "input_spec": "The first line contains an even integer n (2\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n \u2014 the ticket number. The number may contain leading zeros.", "output_spec": "On the first line print \"YES\" if the given ticket number is lucky. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["2\n47", "4\n4738", "4\n4774"], "sample_outputs": ["NO", "NO", "YES"], "notes": "NoteIn the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4\u2009\u2260\u20097).In the second sample the ticket number is not the lucky number."}, "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"nl": {"description": "Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.Two integers x, y are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the numbers, (x\u2009+\u2009y).What is the minimum number of such operations one has to perform in order to make the given pair of integers m-perfect?", "input_spec": "Single line of the input contains three integers x, y and m (\u2009-\u20091018\u2009\u2264\u2009x, y, m\u2009\u2264\u20091018). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print the minimum number of operations or \"-1\" (without quotes), if it is impossible to transform the given pair to the m-perfect one.", "sample_inputs": ["1 2 5", "-1 4 15", "0 -1 5"], "sample_outputs": ["2", "4", "-1"], "notes": "NoteIn the first sample the following sequence of operations is suitable: (1, 2) (3, 2) (5, 2).In the second sample: (-1, 4) (3, 4) (7, 4) (11, 4) (15, 4).Finally, in the third sample x, y cannot be made positive, hence there is no proper sequence of operations."}, "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821"} {"nl": {"description": "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_spec": "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_spec": "Output a single integer\u00a0\u2014 the maximum amount of bishwocks that can be placed onto the given board.", "sample_inputs": ["00\n00", "00X00X0XXX0\n0XXX0X00X00", "0X0X0\n0X0X0", "0XXX0\n00000"], "sample_outputs": ["1", "4", "0", "2"], "notes": null}, "src_uid": "e6b3e787919e96fc893a034eae233fc6"} {"nl": {"description": "Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for i\u2009\u2265\u20091). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and denotes the operation of taking the remainder of division.For example, if a\u2009=\u20092,\u2009b\u2009=\u20096,\u2009m\u2009=\u200912,\u2009r0\u2009=\u200911, the generated sequence will be: 4,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u2009....Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.Your task is to find the period of a sequence defined by the given values of a,\u2009b,\u2009m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i\u2009\u2265\u2009k: ri\u2009=\u2009ri\u2009+\u2009t.", "input_spec": "The single line of the input contains four integers a, b, m and r0 (1\u2009\u2264\u2009m\u2009\u2264\u2009105,\u20090\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20091000,\u20090\u2009\u2264\u2009r0\u2009<\u2009m), separated by single spaces.", "output_spec": "Print a single integer \u2014 the period of the sequence.", "sample_inputs": ["2 6 12 11", "2 3 5 1", "3 6 81 9"], "sample_outputs": ["2", "4", "1"], "notes": "NoteThe first sample is described above. In the second sample the sequence is (starting from the first element): 0,\u20093,\u20094,\u20091,\u20090,\u20093,\u20094,\u20091,\u20090,\u2009...In the third sample the sequence is (starting from the first element): 33,\u200924,\u200978,\u200978,\u200978,\u200978,\u2009..."}, "src_uid": "9137197ee1b781cd5cc77c46f50b9012"} {"nl": {"description": "You are given an integer number $$$n$$$. The following algorithm is applied to it: if $$$n = 0$$$, then end algorithm; find the smallest prime divisor $$$d$$$ of $$$n$$$; subtract $$$d$$$ from $$$n$$$ and go to step $$$1$$$. Determine the number of subtrations the algorithm will make.", "input_spec": "The only line contains a single integer $$$n$$$ ($$$2 \\le n \\le 10^{10}$$$).", "output_spec": "Print a single integer \u2014 the number of subtractions the algorithm will make.", "sample_inputs": ["5", "4"], "sample_outputs": ["1", "2"], "notes": "NoteIn the first example $$$5$$$ is the smallest prime divisor, thus it gets subtracted right away to make a $$$0$$$.In the second example $$$2$$$ is the smallest prime divisor at both steps."}, "src_uid": "a1e80ddd97026835a84f91bac8eb21e6"} {"nl": {"description": "You've got a 5\u2009\u00d7\u20095 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: Swap two neighboring matrix rows, that is, rows with indexes i and i\u2009+\u20091 for some integer i (1\u2009\u2264\u2009i\u2009<\u20095). Swap two neighboring matrix columns, that is, columns with indexes j and j\u2009+\u20091 for some integer j (1\u2009\u2264\u2009j\u2009<\u20095). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.", "input_spec": "The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.", "output_spec": "Print a single integer \u2014 the minimum number of moves needed to make the matrix beautiful.", "sample_inputs": ["0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0"], "sample_outputs": ["3", "1"], "notes": null}, "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"} {"nl": {"description": "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\u2009\u00d7\u2009j. 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_spec": "The single line contains numbers n and x (1\u2009\u2264\u2009n\u2009\u2264\u2009105, 1\u2009\u2264\u2009x\u2009\u2264\u2009109) \u2014 the size of the table and the number that we are looking for in the table.", "output_spec": "Print a single number: the number of times x occurs in the table.", "sample_inputs": ["10 5", "6 12", "5 13"], "sample_outputs": ["2", "4", "0"], "notes": "NoteA table for the second sample test is given below. The occurrences of number 12 are marked bold. "}, "src_uid": "c4b139eadca94201596f1305b2f76496"} {"nl": {"description": "Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.What is the minimum amount of rubles she should pay to buy such number of copybooks k that n\u2009+\u2009k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.", "input_spec": "The only line contains 4 integers n, a, b, c (1\u2009\u2264\u2009n,\u2009a,\u2009b,\u2009c\u2009\u2264\u2009109).", "output_spec": "Print the minimum amount of rubles she should pay to buy such number of copybooks k that n\u2009+\u2009k is divisible by 4.", "sample_inputs": ["1 1 3 4", "6 2 1 1", "4 4 4 4", "999999999 1000000000 1000000000 1000000000"], "sample_outputs": ["3", "1", "0", "1000000000"], "notes": "NoteIn the first example Alyona can buy 3 packs of 1 copybook for 3a\u2009=\u20093 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for b\u2009=\u20091 ruble. She will have 8 copybooks in total.In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.In the fourth example Alyona should buy one pack of one copybook."}, "src_uid": "c74537b7e2032c1d928717dfe15ccfb8"} {"nl": {"description": "The Duck songFor simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes.Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them happy, the following should happen: Andrew, Dmitry and Michal should eat at least $$$x$$$, $$$y$$$ and $$$z$$$ grapes, respectively. Andrew has an extreme affinity for green grapes, thus he will eat green grapes and green grapes only. On the other hand, Dmitry is not a fan of black grapes\u00a0\u2014 any types of grapes except black would do for him. In other words, Dmitry can eat green and purple grapes. Michal has a common taste\u00a0\u2014 he enjoys grapes in general and will be pleased with any types of grapes, as long as the quantity is sufficient.Knowing that his friends are so fond of grapes, Aki decided to host a grape party with them. He has prepared a box with $$$a$$$ green grapes, $$$b$$$ purple grapes and $$$c$$$ black grapes.However, Aki isn't sure if the box he prepared contains enough grapes to make everyone happy. Can you please find out whether it's possible to distribute grapes so that everyone is happy or Aki has to buy some more grapes?It is not required to distribute all the grapes, so it's possible that some of them will remain unused.", "input_spec": "The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$1 \\le x, y, z \\le 10^5$$$)\u00a0\u2014 the number of grapes Andrew, Dmitry and Michal want to eat. The second line contains three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \\le a, b, c \\le 10^5$$$)\u00a0\u2014 the number of green, purple and black grapes in the box.", "output_spec": "If there is a grape distribution that allows everyone to be happy, print \"YES\", otherwise print \"NO\".", "sample_inputs": ["1 6 2\n4 3 3", "5 1 1\n4 3 2"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example, there is only one possible distribution:Andrew should take $$$1$$$ green grape, Dmitry should take $$$3$$$ remaining green grapes and $$$3$$$ purple grapes, and Michal will take $$$2$$$ out of $$$3$$$ available black grapes.In the second test, there is no possible distribution, since Andrew is not be able to eat enough green grapes. :("}, "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"nl": {"description": "Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a ta minutes, and a bus from the city B departs every b minutes and arrives to the city A in a tb minutes.The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.You know the time when Simion departed from the city A to the city B. Calculate the number of buses Simion will meet to be sure in his counting.", "input_spec": "The first line contains two integers a,\u2009ta (1\u2009\u2264\u2009a,\u2009ta\u2009\u2264\u2009120) \u2014 the frequency of the buses from the city A to the city B and the travel time. Both values are given in minutes. The second line contains two integers b,\u2009tb (1\u2009\u2264\u2009b,\u2009tb\u2009\u2264\u2009120) \u2014 the frequency of the buses from the city B to the city A and the travel time. Both values are given in minutes. The last line contains the departure time of Simion from the city A in the format hh:mm. It is guaranteed that there are a bus from the city A at that time. Note that the hours and the minutes are given with exactly two digits.", "output_spec": "Print the only integer z \u2014 the number of buses Simion will meet on the way. Note that you should not count the encounters in cities A and B.", "sample_inputs": ["10 30\n10 35\n05:20", "60 120\n24 100\n13:00"], "sample_outputs": ["5", "9"], "notes": "NoteIn the first example Simion departs form the city A at 05:20 AM and arrives to the city B at 05:50 AM. He will meet the first 5 buses from the city B that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city B at 05:50 AM, but he will not count it.Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed)."}, "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7"} {"nl": {"description": "Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.", "input_spec": "The input file consists of three lines, each of them contains a pair of numbers \u2013\u2013 coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.", "output_spec": "Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.", "sample_inputs": ["0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000"], "sample_outputs": ["1.00000000"], "notes": null}, "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"} {"nl": {"description": "Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!", "input_spec": "The first line of input contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) denotes the number of cubes in the i-th column.", "output_spec": "Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.", "sample_inputs": ["4\n3 2 1 2", "3\n2 3 8"], "sample_outputs": ["1 2 2 3", "2 3 8"], "notes": "NoteThe first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.In the second example case the gravity switch does not change the heights of the columns."}, "src_uid": "ae20712265d4adf293e75d016b4b82d8"} {"nl": {"description": "Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200992)\u00a0\u2014 the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0\u2009\u2264\u2009ai\u2009\u2264\u200915)\u00a0\u2014 Vitya's records. It's guaranteed that the input data is consistent.", "output_spec": "If Vitya can be sure that the size of visible part of the moon on day n\u2009+\u20091 will be less than the size of the visible part on day n, then print \"DOWN\" at the only line of the output. If he might be sure that the size of the visible part will increase, then print \"UP\". If it's impossible to determine what exactly will happen with the moon, print -1.", "sample_inputs": ["5\n3 4 5 6 7", "7\n12 13 14 15 14 13 12", "1\n8"], "sample_outputs": ["UP", "DOWN", "-1"], "notes": "NoteIn the first sample, the size of the moon on the next day will be equal to 8, thus the answer is \"UP\".In the second sample, the size of the moon on the next day will be 11, thus the answer is \"DOWN\".In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1."}, "src_uid": "8330d9fea8d50a79741507b878da0a75"} {"nl": {"description": "Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a\u2009\u00d7\u2009b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1\u2009\u00d7\u2009n), which he wants to encrypt in the same way as in japanese crossword. The example of encrypting of a single row of japanese crossword. Help Adaltik find the numbers encrypting the row he drew.", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W'\u00a0\u2014 to white square in the row that Adaltik drew).", "output_spec": "The first line should contain a single integer k\u00a0\u2014 the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.", "sample_inputs": ["3\nBBW", "5\nBWBWB", "4\nWWWW", "4\nBBBB", "13\nWBBBBWWBWBBBW"], "sample_outputs": ["1\n2", "3\n1 1 1", "0", "1\n4", "3\n4 1 3"], "notes": "NoteThe last sample case correspond to the picture in the statement."}, "src_uid": "e4b3a2707ba080b93a152f4e6e983973"} {"nl": {"description": "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_spec": "The single line contains integer n (10\u2009\u2264\u2009|n|\u2009\u2264\u2009109) \u2014 the state of Ilya's bank account.", "output_spec": "In a single line print an integer \u2014 the maximum state of the bank account that Ilya can get. ", "sample_inputs": ["2230", "-10", "-100003"], "sample_outputs": ["2230", "0", "-10000"], "notes": "NoteIn 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."}, "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"nl": {"description": "In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8\u2009\u00d7\u20098): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone \u2014 neither any other statues, nor Anna, nor Maria.Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is \u2014 to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.", "input_spec": "You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one \u2014 for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is \".\". If a cell has Maria, then it is represented by character \"M\". If a cell has Anna, it is represented by the character \"A\". If a cell has a statue, then the cell is represented by character \"S\". It is guaranteed that the last character of the first row is always \"A\", the first character of the last line is always \"M\". The remaining characters are \".\" or \"S\".", "output_spec": "If Maria wins, print string \"WIN\". If the statues win, print string \"LOSE\".", "sample_inputs": [".......A\n........\n........\n........\n........\n........\n........\nM.......", ".......A\n........\n........\n........\n........\n........\nSS......\nM.......", ".......A\n........\n........\n........\n........\n.S......\nS.......\nMS......"], "sample_outputs": ["WIN", "LOSE", "LOSE"], "notes": null}, "src_uid": "f47e4ab041288ba9567c19930eb9a090"} {"nl": {"description": "There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3\u2009\u00d7\u20093 with digits from 1 to 9.Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.", "input_spec": "Input contains the matrix of three rows of three symbols each. Symbol \u00abX\u00bb means that the corresponding button was pressed, and \u00ab.\u00bb means that is was not pressed. The matrix may contain no \u00abX\u00bb, also it may contain no \u00ab.\u00bb.", "output_spec": "Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.", "sample_inputs": ["XX.\n...\n.XX", "X.X\nX..\n..."], "sample_outputs": ["YES", "NO"], "notes": "NoteIf you are not familiar with the term \u00abcentral symmetry\u00bb, you may look into http://en.wikipedia.org/wiki/Central_symmetry"}, "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"} {"nl": {"description": "One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.", "input_spec": "The only line contains n (1\u2009\u2264\u2009n\u2009\u2264\u200925) \u2014 the required sum of points.", "output_spec": "Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.", "sample_inputs": ["12", "20", "10"], "sample_outputs": ["4", "15", "0"], "notes": "NoteIn the first sample only four two's of different suits can earn the required sum of points.In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.In the third sample there is no card, that would add a zero to the current ten points."}, "src_uid": "5802f52caff6015f21b80872274ab16c"} {"nl": {"description": " \u2014 Thanks a lot for today.\u2014 I experienced so many great things.\u2014 You gave me memories like dreams... But I have to leave now...\u2014 One last request, can you...\u2014 Help me solve a Codeforces problem?\u2014 ......\u2014 What?Chtholly has been thinking about a problem for days:If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!", "input_spec": "The first line contains two integers k and p (1\u2009\u2264\u2009k\u2009\u2264\u2009105,\u20091\u2009\u2264\u2009p\u2009\u2264\u2009109).", "output_spec": "Output single integer\u00a0\u2014 answer to the problem.", "sample_inputs": ["2 100", "5 30"], "sample_outputs": ["33", "15"], "notes": "NoteIn the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.In the second example, ."}, "src_uid": "00e90909a77ce9e22bb7cbf1285b0609"} {"nl": {"description": "InputThe input contains a single integer a (10\u2009\u2264\u2009a\u2009\u2264\u2009999).OutputOutput 0 or 1.ExamplesInput13Output1Input927Output1Input48Output0", "input_spec": "The input contains a single integer a (10\u2009\u2264\u2009a\u2009\u2264\u2009999).", "output_spec": "Output 0 or 1.", "sample_inputs": ["13", "927", "48"], "sample_outputs": ["1", "1", "0"], "notes": null}, "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795"} {"nl": {"description": "Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n\u2009+\u2009m cubes). Petya moves first. Petya's task is to get as many pairs of neighbouring cubes of the same color as possible. Vasya's task is to get as many pairs of neighbouring cubes of different colors as possible. The number of Petya's points in the game is the number of pairs of neighboring cubes of the same color in the line, the number of Vasya's points in the game is the number of neighbouring cubes of the different color in the line. Your task is to calculate the score at the end of the game (Petya's and Vasya's points, correspondingly), if both boys are playing optimally well. To \"play optimally well\" first of all means to maximize the number of one's points, and second \u2014 to minimize the number of the opponent's points.", "input_spec": "The only line contains two space-separated integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105) \u2014 the number of red and blue cubes, correspondingly.", "output_spec": "On a single line print two space-separated integers \u2014 the number of Petya's and Vasya's points correspondingly provided that both players play optimally well.", "sample_inputs": ["3 1", "2 4"], "sample_outputs": ["2 1", "3 2"], "notes": "NoteIn the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point. If Petya would choose the red cube during his first move, then, provided that both boys play optimally well, Petya would get 1 point and Vasya would get 2 points."}, "src_uid": "c8378e6fcaab30d15469a55419f38b39"} {"nl": {"description": "Noora is a student of one famous high school. It's her final year in school\u00a0\u2014 she is going to study in university next year. However, she has to get an \u00abA\u00bb graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784\u00a0\u2014 to 8. For instance, if Noora has marks [8,\u20099], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,\u20098,\u20099], Noora will have graduation certificate with 8.To graduate with \u00abA\u00bb certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009k\u2009\u2264\u2009100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009k) denoting marks received by Noora before Leha's hack.", "output_spec": "Print a single integer\u00a0\u2014 minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.", "sample_inputs": ["2 10\n8 9", "3 5\n4 4 4"], "sample_outputs": ["4", "3"], "notes": "NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks\u00a0\u2014 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10,\u200910,\u200910,\u200910] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5,\u20095,\u20095] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate."}, "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900"} {"nl": {"description": "Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?Given an integer sequence a1,\u2009a2,\u2009...,\u2009an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.A subsegment is a contiguous slice of the whole sequence. For example, {3,\u20094,\u20095} and {1} are subsegments of sequence {1,\u20092,\u20093,\u20094,\u20095,\u20096}, while {1,\u20092,\u20094} and {7} are not.", "input_spec": "The first line of input contains a non-negative integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the length of the sequence. The second line contains n space-separated non-negative integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the elements of the sequence.", "output_spec": "Output \"Yes\" if it's possible to fulfill the requirements, and \"No\" otherwise. You can output each letter in any case (upper or lower).", "sample_inputs": ["3\n1 3 5", "5\n1 0 1 5 1", "3\n4 3 1", "4\n3 9 9 3"], "sample_outputs": ["Yes", "Yes", "No", "No"], "notes": "NoteIn the first example, divide the sequence into 1 subsegment: {1,\u20093,\u20095} and the requirements will be met.In the second example, divide the sequence into 3 subsegments: {1,\u20090,\u20091}, {5}, {1}.In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.In the fourth example, the sequence can be divided into 2 subsegments: {3,\u20099,\u20099}, {3}, but this is not a valid solution because 2 is an even number."}, "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"nl": {"description": "You are planning to build housing on a street. There are $$$n$$$ spots available on the street on which you can build a house. The spots are labeled from $$$1$$$ to $$$n$$$ from left to right. In each spot, you can build a house with an integer height between $$$0$$$ and $$$h$$$.In each spot, if a house has height $$$a$$$, you will gain $$$a^2$$$ dollars from it.The city has $$$m$$$ zoning restrictions. The $$$i$$$-th restriction says that the tallest house from spots $$$l_i$$$ to $$$r_i$$$ (inclusive) must be at most $$$x_i$$$.You would like to build houses to maximize your profit. Determine the maximum profit possible.", "input_spec": "The first line contains three integers $$$n$$$, $$$h$$$, and $$$m$$$ ($$$1 \\leq n,h,m \\leq 50$$$)\u00a0\u2014 the number of spots, the maximum height, and the number of restrictions. Each of the next $$$m$$$ lines contains three integers $$$l_i$$$, $$$r_i$$$, and $$$x_i$$$ ($$$1 \\leq l_i \\leq r_i \\leq n$$$, $$$0 \\leq x_i \\leq h$$$)\u00a0\u2014 left and right limits (inclusive) of the $$$i$$$-th restriction and the maximum possible height in that range.", "output_spec": "Print a single integer, the maximum profit you can make.", "sample_inputs": ["3 3 3\n1 1 1\n2 2 3\n3 3 2", "4 10 2\n2 3 8\n3 4 7"], "sample_outputs": ["14", "262"], "notes": "NoteIn the first example, there are $$$3$$$ houses, the maximum height of a house is $$$3$$$, and there are $$$3$$$ restrictions. The first restriction says the tallest house between $$$1$$$ and $$$1$$$ must be at most $$$1$$$. The second restriction says the tallest house between $$$2$$$ and $$$2$$$ must be at most $$$3$$$. The third restriction says the tallest house between $$$3$$$ and $$$3$$$ must be at most $$$2$$$.In this case, it is optimal to build houses with heights $$$[1, 3, 2]$$$. This fits within all the restrictions. The total profit in this case is $$$1^2 + 3^2 + 2^2 = 14$$$.In the second example, there are $$$4$$$ houses, the maximum height of a house is $$$10$$$, and there are $$$2$$$ restrictions. The first restriction says the tallest house from $$$2$$$ to $$$3$$$ must be at most $$$8$$$. The second restriction says the tallest house from $$$3$$$ to $$$4$$$ must be at most $$$7$$$.In this case, it's optimal to build houses with heights $$$[10, 8, 7, 7]$$$. We get a profit of $$$10^2+8^2+7^2+7^2 = 262$$$. Note that there are two restrictions on house $$$3$$$ and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house $$$1$$$, we must still limit its height to be at most $$$10$$$ ($$$h=10$$$)."}, "src_uid": "f22b6dab443f63fb8d2d288b702f20ad"} {"nl": {"description": "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_spec": "The first line contains a single binary number $$$s$$$ ($$$0 \\leq s < 2^{100}$$$) without leading zeroes.", "output_spec": "Output a single number\u00a0\u2014 the number of trains which have departed strictly before the time $$$s$$$.", "sample_inputs": ["100000000", "101", "10100"], "sample_outputs": ["4", "2", "3"], "notes": "NoteIn 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."}, "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"nl": {"description": "Bob and Alice are often participating in various programming competitions. Like many competitive programmers, Alice and Bob have good and bad days. They noticed, that their lucky and unlucky days are repeating with some period. For example, for Alice days $$$[l_a; r_a]$$$ are lucky, then there are some unlucky days: $$$[r_a + 1; l_a + t_a - 1]$$$, and then there are lucky days again: $$$[l_a + t_a; r_a + t_a]$$$ and so on. In other words, the day is lucky for Alice if it lies in the segment $$$[l_a + k t_a; r_a + k t_a]$$$ for some non-negative integer $$$k$$$.The Bob's lucky day have similar structure, however the parameters of his sequence are different: $$$l_b$$$, $$$r_b$$$, $$$t_b$$$. So a day is a lucky for Bob if it lies in a segment $$$[l_b + k t_b; r_b + k t_b]$$$, for some non-negative integer $$$k$$$.Alice and Bob want to participate in team competitions together and so they want to find out what is the largest possible number of consecutive days, which are lucky for both Alice and Bob.", "input_spec": "The first line contains three integers $$$l_a$$$, $$$r_a$$$, $$$t_a$$$ ($$$0 \\le l_a \\le r_a \\le t_a - 1, 2 \\le t_a \\le 10^9$$$) and describes Alice's lucky days. The second line contains three integers $$$l_b$$$, $$$r_b$$$, $$$t_b$$$ ($$$0 \\le l_b \\le r_b \\le t_b - 1, 2 \\le t_b \\le 10^9$$$) and describes Bob's lucky days. It is guaranteed that both Alice and Bob have some unlucky days.", "output_spec": "Print one integer: the maximum number of days in the row that are lucky for both Alice and Bob.", "sample_inputs": ["0 2 5\n1 3 5", "0 1 3\n2 3 6"], "sample_outputs": ["2", "1"], "notes": "NoteThe graphs below correspond to the two sample tests and show the lucky and unlucky days of Alice and Bob as well as the possible solutions for these tests."}, "src_uid": "faa75751c05c3ff919ddd148c6784910"} {"nl": {"description": "Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2\u2009\u00d7\u20092 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below: In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.", "input_spec": "The first two lines of the input consist of a 2\u2009\u00d7\u20092 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2\u2009\u00d7\u20092 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.", "output_spec": "Output \"YES\"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["AB\nXC\nXB\nAC", "AB\nXC\nAC\nBX"], "sample_outputs": ["YES", "NO"], "notes": "NoteThe solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all..."}, "src_uid": "46f051f58d626587a5ec449c27407771"} {"nl": {"description": "Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $$$n$$$ actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by $$$1$$$; the second option is to put candies in the box. In this case, Alya will put $$$1$$$ more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option.For example, one possible sequence of Alya's actions look as follows: put one candy into the box; put two candies into the box; eat one candy from the box; eat one candy from the box; put three candies into the box; eat one candy from the box; put four candies into the box; eat one candy from the box; put five candies into the box; This way she will perform $$$9$$$ actions, the number of candies at the end will be $$$11$$$, while Alya will eat $$$4$$$ candies in total.You know the total number of actions $$$n$$$ and the number of candies at the end $$$k$$$. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given $$$n$$$ and $$$k$$$ the answer always exists.Please note, that during an action of the first option, Alya takes out and eats exactly one candy.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 10^9$$$; $$$0 \\le k \\le 10^9$$$)\u00a0\u2014 the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given $$$n$$$ and $$$k$$$ the answer exists.", "output_spec": "Print a single integer\u00a0\u2014 the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers\u00a0\u2014 the answer is unique for any input data. ", "sample_inputs": ["1 1", "9 11", "5 0", "3 2"], "sample_outputs": ["0", "4", "3", "1"], "notes": "NoteIn the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate $$$0$$$ candies.In the second example the possible sequence of Alya's actions looks as follows: put $$$1$$$ candy, put $$$2$$$ candies, eat a candy, eat a candy, put $$$3$$$ candies, eat a candy, put $$$4$$$ candies, eat a candy, put $$$5$$$ candies. This way, she will make exactly $$$n=9$$$ actions and in the end the box will contain $$$1+2-1-1+3-1+4-1+5=11$$$ candies. The answer is $$$4$$$, since she ate $$$4$$$ candies in total."}, "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"} {"nl": {"description": "Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain \"some real funny stuff about swine influenza\". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: \"invalid login/password\".Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to \"H1N1\" and \"Infected\" correspondingly, and the \"Additional Information\" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. \"I've been hacked\" \u2014 thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.Help Igor K. restore his ISQ account by the encrypted password and encryption specification.", "input_spec": "The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.", "output_spec": "Print one line containing 8 characters \u2014 The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.", "sample_inputs": ["01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110", "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000"], "sample_outputs": ["12345678", "30234919"], "notes": null}, "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"nl": {"description": "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_spec": "The single line of the input contains a pair of integers m, s (1\u2009\u2264\u2009m\u2009\u2264\u2009100,\u20090\u2009\u2264\u2009s\u2009\u2264\u2009900) \u2014 the length and the sum of the digits of the required numbers.", "output_spec": "In the output print the pair of the required non-negative integer numbers \u2014 first the minimum possible number, then \u2014 the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers \"-1 -1\" (without the quotes).", "sample_inputs": ["2 15", "3 0"], "sample_outputs": ["69 96", "-1 -1"], "notes": null}, "src_uid": "75d062cece5a2402920d6706c655cad7"} {"nl": {"description": "In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take d minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get n cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.", "input_spec": "The only line contains four integers n, t, k, d (1\u2009\u2264\u2009n,\u2009t,\u2009k,\u2009d\u2009\u2264\u20091\u2009000)\u00a0\u2014 the number of cakes needed, the time needed for one oven to bake k cakes, the number of cakes baked at the same time, the time needed to build the second oven. ", "output_spec": "If it is reasonable to build the second oven, print \"YES\". Otherwise print \"NO\".", "sample_inputs": ["8 6 4 5", "8 6 4 6", "10 3 11 4", "4 2 1 4"], "sample_outputs": ["YES", "NO", "NO", "YES"], "notes": "NoteIn the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven."}, "src_uid": "32c866d3d394e269724b4930df5e4407"} {"nl": {"description": "There is a building consisting of $$$10~000$$$ apartments numbered from $$$1$$$ to $$$10~000$$$, inclusive.Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are $$$11, 2, 777, 9999$$$ and so on.Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone answers the call, in the following order: First he calls all apartments consisting of digit $$$1$$$, in increasing order ($$$1, 11, 111, 1111$$$). Next he calls all apartments consisting of digit $$$2$$$, in increasing order ($$$2, 22, 222, 2222$$$) And so on. The resident of the boring apartment $$$x$$$ answers the call, and our character stops calling anyone further.Our character wants to know how many digits he pressed in total and your task is to help him to count the total number of keypresses.For example, if the resident of boring apartment $$$22$$$ answered, then our character called apartments with numbers $$$1, 11, 111, 1111, 2, 22$$$ and the total number of digits he pressed is $$$1 + 2 + 3 + 4 + 1 + 2 = 13$$$.You have to answer $$$t$$$ independent test cases.", "input_spec": "The first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 36$$$) \u2014 the number of test cases. The only line of the test case contains one integer $$$x$$$ ($$$1 \\le x \\le 9999$$$) \u2014 the apartment number of the resident who answered the call. It is guaranteed that $$$x$$$ consists of the same digit.", "output_spec": "For each test case, print the answer: how many digits our character pressed in total.", "sample_inputs": ["4\n22\n9999\n1\n777"], "sample_outputs": ["13\n90\n1\n66"], "notes": null}, "src_uid": "289a55128be89bb86a002d218d31b57f"} {"nl": {"description": "The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $$$n$$$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $$$m$$$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?Could you help her with this curiosity?You can see the examples and their descriptions with pictures in the \"Note\" section.", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\leq n \\leq 1000$$$, $$$0 \\leq m \\leq n$$$)\u00a0\u2014 the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.", "output_spec": "Print a single integer\u00a0\u2014 the maximum number of groups of cats at the moment Katie observes.", "sample_inputs": ["7 4", "6 2", "3 0", "2 2"], "sample_outputs": ["3", "2", "1", "0"], "notes": "NoteIn the first example, originally there are $$$7$$$ cats sitting as shown below, creating a single group: At the observed moment, $$$4$$$ cats have left the table. Suppose the cats $$$2$$$, $$$3$$$, $$$5$$$ and $$$7$$$ have left, then there are $$$3$$$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining. In the second example, there are $$$6$$$ cats sitting as shown below: At the observed moment, $$$2$$$ cats have left the table. Suppose the cats numbered $$$3$$$ and $$$6$$$ left, then there will be $$$2$$$ groups remaining ($$$\\{1, 2\\}$$$ and $$$\\{4, 5\\}$$$). It is impossible to have more than $$$2$$$ groups of cats remaining. In the third example, no cats have left, so there is $$$1$$$ group consisting of all cats.In the fourth example, all cats have left the circle, so there are $$$0$$$ groups."}, "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"} {"nl": {"description": "Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.The first player wrote number a, the second player wrote number b. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?", "input_spec": "The single line contains two integers a and b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20096)\u00a0\u2014 the numbers written on the paper by the first and second player, correspondingly.", "output_spec": "Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.", "sample_inputs": ["2 5", "2 4"], "sample_outputs": ["3 0 3", "2 1 3"], "notes": "NoteThe dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.You can assume that number a is closer to number x than number b, if |a\u2009-\u2009x|\u2009<\u2009|b\u2009-\u2009x|."}, "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"} {"nl": {"description": "It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors.Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?You have a perfect binary tree of $$$2^k - 1$$$ nodes\u00a0\u2014 a binary tree where all vertices $$$i$$$ from $$$1$$$ to $$$2^{k - 1} - 1$$$ have exactly two children: vertices $$$2i$$$ and $$$2i + 1$$$. Vertices from $$$2^{k - 1}$$$ to $$$2^k - 1$$$ don't have any children. You want to color its vertices with the $$$6$$$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow).Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube. A picture of Rubik's cube and its 2D map. More formally: a white node can not be neighboring with white and yellow nodes; a yellow node can not be neighboring with white and yellow nodes; a green node can not be neighboring with green and blue nodes; a blue node can not be neighboring with green and blue nodes; a red node can not be neighboring with red and orange nodes; an orange node can not be neighboring with red and orange nodes; You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color.The answer may be too large, so output the answer modulo $$$10^9+7$$$.", "input_spec": "The first and only line contains the integers $$$k$$$ ($$$1 \\le k \\le 60$$$)\u00a0\u2014 the number of levels in the perfect binary tree you need to color.", "output_spec": "Print one integer\u00a0\u2014 the number of the different colorings modulo $$$10^9+7$$$.", "sample_inputs": ["3", "14"], "sample_outputs": ["24576", "934234"], "notes": "NoteIn the picture below, you can see one of the correct colorings of the first example. "}, "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"} {"nl": {"description": "You are given a positive integer $$$n$$$.Let $$$S(x)$$$ be sum of digits in base 10 representation of $$$x$$$, for example, $$$S(123) = 1 + 2 + 3 = 6$$$, $$$S(0) = 0$$$.Your task is to find two integers $$$a, b$$$, such that $$$0 \\leq a, b \\leq n$$$, $$$a + b = n$$$ and $$$S(a) + S(b)$$$ is the largest possible among all such pairs.", "input_spec": "The only line of input contains an integer $$$n$$$ $$$(1 \\leq n \\leq 10^{12})$$$.", "output_spec": "Print largest $$$S(a) + S(b)$$$ among all pairs of integers $$$a, b$$$, such that $$$0 \\leq a, b \\leq n$$$ and $$$a + b = n$$$.", "sample_inputs": ["35", "10000000000"], "sample_outputs": ["17", "91"], "notes": "NoteIn the first example, you can choose, for example, $$$a = 17$$$ and $$$b = 18$$$, so that $$$S(17) + S(18) = 1 + 7 + 1 + 8 = 17$$$. It can be shown that it is impossible to get a larger answer.In the second test example, you can choose, for example, $$$a = 5000000001$$$ and $$$b = 4999999999$$$, with $$$S(5000000001) + S(4999999999) = 91$$$. It can be shown that it is impossible to get a larger answer."}, "src_uid": "5c61b4a4728070b9de49d72831cd2329"} {"nl": {"description": "Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is c meters.For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.", "input_spec": "First line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 number of visits. Second line contains an integer a (1\u2009\u2264\u2009a\u2009\u2264\u2009100)\u00a0\u2014 distance between Rabbit's and Owl's houses. Third line contains an integer b (1\u2009\u2264\u2009b\u2009\u2264\u2009100)\u00a0\u2014 distance between Rabbit's and Eeyore's houses. Fourth line contains an integer c (1\u2009\u2264\u2009c\u2009\u2264\u2009100)\u00a0\u2014 distance between Owl's and Eeyore's houses.", "output_spec": "Output one number\u00a0\u2014 minimum distance in meters Winnie must go through to have a meal n times.", "sample_inputs": ["3\n2\n3\n1", "1\n2\n3\n5"], "sample_outputs": ["3", "0"], "notes": "NoteIn the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2\u2009+\u20091\u2009=\u20093.In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all."}, "src_uid": "6058529f0144c853e9e17ed7c661fc50"} {"nl": {"description": "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\u2009+\u20091, ..., b (a\u2009\u2264\u2009b). You want to find the minimum integer l (1\u2009\u2264\u2009l\u2009\u2264\u2009b\u2009-\u2009a\u2009+\u20091) such that for any integer x (a\u2009\u2264\u2009x\u2009\u2264\u2009b\u2009-\u2009l\u2009+\u20091) among l integers x, x\u2009+\u20091, ..., x\u2009+\u2009l\u2009-\u20091 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_spec": "A single line contains three space-separated integers a,\u2009b,\u2009k (1\u2009\u2264\u2009a,\u2009b,\u2009k\u2009\u2264\u2009106;\u00a0a\u2009\u2264\u2009b).", "output_spec": "In a single line print a single integer \u2014 the required minimum l. If there's no solution, print -1.", "sample_inputs": ["2 4 2", "6 13 1", "1 4 3"], "sample_outputs": ["3", "4", "-1"], "notes": null}, "src_uid": "3e1751a2990134f2132d743afe02a10e"} {"nl": {"description": "Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.Solve the problem to show that it's not a NP problem.", "input_spec": "The first line contains two integers l and r (2\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109).", "output_spec": "Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.", "sample_inputs": ["19 29", "3 6"], "sample_outputs": ["2", "3"], "notes": "NoteDefinition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.htmlThe first example: from 19 to 29 these numbers are divisible by 2: {20,\u200922,\u200924,\u200926,\u200928}.The second example: from 3 to 6 these numbers are divisible by 3: {3,\u20096}."}, "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"nl": {"description": "Theatre Square in the capital city of Berland has a rectangular shape with the size n\u2009\u00d7\u2009m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a\u2009\u00d7\u2009a.What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.", "input_spec": "The input contains three positive integer numbers in the first line: n,\u2009\u2009m and a (1\u2009\u2264\u2009\u2009n,\u2009m,\u2009a\u2009\u2264\u2009109).", "output_spec": "Write the needed number of flagstones.", "sample_inputs": ["6 6 4"], "sample_outputs": ["4"], "notes": null}, "src_uid": "ef971874d8c4da37581336284b688517"} {"nl": {"description": " When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside\u00a0\u2014 not tangerines, but blossoms instead.\"What a pity it's already late spring,\" sighs Mino with regret, \"one more drizzling night and they'd be gone.\"\"But these blends are at their best, aren't they?\" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.", "input_spec": "The first and only line of input contains a non-empty string $$$s$$$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($$$\\lvert s \\rvert \\leq 100$$$)\u00a0\u2014 denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.", "output_spec": "Output \"Yes\" if it's possible that all three colours appear in some cell, and \"No\" otherwise. You can print each letter in any case (upper or lower).", "sample_inputs": [".BAC.", "AA..CB"], "sample_outputs": ["Yes", "No"], "notes": "NoteIn the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell."}, "src_uid": "ba6ff507384570152118e2ab322dd11f"} {"nl": {"description": "A group of $$$n$$$ dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them \u2014 a black one, and for the rest the suit will be bought in the future.On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer's suit is the same as the color of the rightmost dancer's suit, the 2nd left is the same as 2nd right, and so on.The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it's possible, what's the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.", "input_spec": "The first line contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \\leq n \\leq 20$$$, $$$1 \\leq a, b \\leq 100$$$)\u00a0\u2014 the number of dancers, the cost of a white suit, and the cost of a black suit. The next line contains $$$n$$$ numbers $$$c_i$$$, $$$i$$$-th of which denotes the color of the suit of the $$$i$$$-th dancer. Number $$$0$$$ denotes the white color, $$$1$$$\u00a0\u2014 the black color, and $$$2$$$ denotes that a suit for this dancer is still to be bought.", "output_spec": "If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.", "sample_inputs": ["5 100 1\n0 1 2 1 2", "3 10 12\n1 2 0", "3 12 1\n0 1 0"], "sample_outputs": ["101", "-1", "0"], "notes": "NoteIn the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.In the second sample, the leftmost dancer's suit already differs from the rightmost dancer's suit so there is no way to obtain the desired coloring.In the third sample, all suits are already bought and their colors form a palindrome."}, "src_uid": "af07223819aeb5bd6ded4340c472b2b6"} {"nl": {"description": "You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties: Have positive area. With vertices at integer points. All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0,\u20090), (w,\u20090), (w,\u2009h), (0,\u2009h). In other words, for all vertices (xi,\u2009yi) of the rhombus the following conditions should fulfill: 0\u2009\u2264\u2009xi\u2009\u2264\u2009w and 0\u2009\u2264\u2009yi\u2009\u2264\u2009h. Its diagonals are parallel to the axis. Count the number of such rhombi.Let us remind you that a rhombus is a quadrilateral whose four sides all have the same length.", "input_spec": "The first line contains two integers w and h (1\u2009\u2264\u2009w,\u2009h\u2009\u2264\u20094000) \u2014 the rectangle's sizes.", "output_spec": "Print a single number \u2014 the number of sought rhombi. Please do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specifier.", "sample_inputs": ["2 2", "1 2"], "sample_outputs": ["1", "0"], "notes": "NoteIn the first example there exists only one such rhombus. Its vertices are located at points (1,\u20090), (2,\u20091), (1,\u20092), (0,\u20091)."}, "src_uid": "42454dcf7d073bf12030367eb094eb8c"} {"nl": {"description": "Tanechka is shopping in the toy shop. There are exactly $$$n$$$ toys in the shop for sale, the cost of the $$$i$$$-th toy is $$$i$$$ burles. She wants to choose two toys in such a way that their total cost is $$$k$$$ burles. How many ways to do that does she have?Each toy appears in the shop exactly once. Pairs $$$(a, b)$$$ and $$$(b, a)$$$ are considered equal. Pairs $$$(a, b)$$$, where $$$a=b$$$, are not allowed.", "input_spec": "The first line of the input contains two integers $$$n$$$, $$$k$$$ ($$$1 \\le n, k \\le 10^{14}$$$) \u2014 the number of toys and the expected total cost of the pair of toys.", "output_spec": "Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is $$$k$$$ burles.", "sample_inputs": ["8 5", "8 15", "7 20", "1000000000000 1000000000001"], "sample_outputs": ["2", "1", "0", "500000000000"], "notes": "NoteIn the first example Tanechka can choose the pair of toys ($$$1, 4$$$) or the pair of toys ($$$2, 3$$$).In the second example Tanechka can choose only the pair of toys ($$$7, 8$$$).In the third example choosing any pair of toys will lead to the total cost less than $$$20$$$. So the answer is 0.In the fourth example she can choose the following pairs: $$$(1, 1000000000000)$$$, $$$(2, 999999999999)$$$, $$$(3, 999999999998)$$$, ..., $$$(500000000000, 500000000001)$$$. The number of such pairs is exactly $$$500000000000$$$."}, "src_uid": "98624ab2fcd2a50a75788a29e04999ad"} {"nl": {"description": "You are given an integer sequence $$$1, 2, \\dots, n$$$. You have to divide it into two sets $$$A$$$ and $$$B$$$ in such a way that each element belongs to exactly one set and $$$|sum(A) - sum(B)|$$$ is minimum possible.The value $$$|x|$$$ is the absolute value of $$$x$$$ and $$$sum(S)$$$ is the sum of elements of the set $$$S$$$.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^9$$$).", "output_spec": "Print one integer \u2014 the minimum possible value of $$$|sum(A) - sum(B)|$$$ if you divide the initial sequence $$$1, 2, \\dots, n$$$ into two sets $$$A$$$ and $$$B$$$.", "sample_inputs": ["3", "5", "6"], "sample_outputs": ["0", "1", "1"], "notes": "NoteSome (not all) possible answers to examples:In the first example you can divide the initial sequence into sets $$$A = \\{1, 2\\}$$$ and $$$B = \\{3\\}$$$ so the answer is $$$0$$$.In the second example you can divide the initial sequence into sets $$$A = \\{1, 3, 4\\}$$$ and $$$B = \\{2, 5\\}$$$ so the answer is $$$1$$$.In the third example you can divide the initial sequence into sets $$$A = \\{1, 4, 5\\}$$$ and $$$B = \\{2, 3, 6\\}$$$ so the answer is $$$1$$$."}, "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"} {"nl": {"description": "Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,\u20092,\u20094} is 1 and the MEX of the set {1,\u20092,\u20093} is 0 .Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?", "input_spec": "The first line contains two integers n and x (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 0\u2009\u2264\u2009x\u2009\u2264\u2009100)\u00a0\u2014 the size of the set Dr. Evil owns, and the desired MEX. The second line contains n distinct non-negative integers not exceeding 100 that represent the set.", "output_spec": "The only line should contain one integer\u00a0\u2014 the minimal number of operations Dr. Evil should perform.", "sample_inputs": ["5 3\n0 4 5 6 7", "1 0\n0", "5 0\n1 2 3 4 5"], "sample_outputs": ["2", "1", "0"], "notes": "NoteFor the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.In the third test case the set is already evil."}, "src_uid": "21f579ba807face432a7664091581cd8"} {"nl": {"description": "There are five people playing a game called \"Generosity\". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.", "input_spec": "The input consists of a single line containing five integers c1,\u2009c2,\u2009c3,\u2009c4 and c5 \u2014 the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0\u2009\u2264\u2009c1,\u2009c2,\u2009c3,\u2009c4,\u2009c5\u2009\u2264\u2009100).", "output_spec": "Print the only line containing a single positive integer b \u2014 the number of coins in the initial bet of each player. If there is no such value of b, then print the only value \"-1\" (quotes for clarity).", "sample_inputs": ["2 5 4 0 4", "4 5 9 2 1"], "sample_outputs": ["3", "-1"], "notes": "NoteIn the first sample the following sequence of operations is possible: One coin is passed from the fourth player to the second player; One coin is passed from the fourth player to the fifth player; One coin is passed from the first player to the third player; One coin is passed from the fourth player to the second player. "}, "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"nl": {"description": "You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x\u2009\u2265\u20090) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x\u2009+\u20091 sections.You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.", "input_spec": "The first line contains four space-separated integers k, a, b, v (2\u2009\u2264\u2009k\u2009\u2264\u20091000; 1\u2009\u2264\u2009a,\u2009b,\u2009v\u2009\u2264\u20091000) \u2014 the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["3 10 3 3", "3 10 1 3", "100 100 1 1000"], "sample_outputs": ["2", "3", "1"], "notes": "NoteIn the first sample you can act like this: Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts. Do not put any divisors into the second box. Thus, the second box has one section for the last nut. In the end we've put all the ten nuts into boxes.The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each."}, "src_uid": "7cff20b1c63a694baca69bdf4bdb2652"} {"nl": {"description": "You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1,\u2009b2,\u2009...,\u2009bk (1\u2009\u2264\u2009b1\u2009<\u2009b2\u2009<\u2009...\u2009<\u2009bk\u2009\u2264\u2009n) in such a way that the value of is maximized. Chosen sequence can be empty.Print the maximum possible value of .", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u200935, 1\u2009\u2264\u2009m\u2009\u2264\u2009109). The second line contains n integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009109).", "output_spec": "Print the maximum possible value of .", "sample_inputs": ["4 4\n5 2 4 1", "3 20\n199 41 299"], "sample_outputs": ["3", "19"], "notes": "NoteIn the first example you can choose a sequence b\u2009=\u2009{1,\u20092}, so the sum is equal to 7 (and that's 3 after taking it modulo 4).In the second example you can choose a sequence b\u2009=\u2009{3}."}, "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a"} {"nl": {"description": "Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will \"hang up\" as the size of data to watch per second will be more than the size of downloaded data per second.The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.Let's suppose that video's length is c seconds and Valeric and Valerko wait t seconds before the watching. Then for any moment of time t0, t\u2009\u2264\u2009t0\u2009\u2264\u2009c\u2009+\u2009t, the following condition must fulfill: the size of data received in t0 seconds is not less than the size of data needed to watch t0\u2009-\u2009t seconds of the video.Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.", "input_spec": "The first line contains three space-separated integers a, b and c (1\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20091000,\u2009a\u2009>\u2009b). The first number (a) denotes the size of data needed to watch one second of the video. The second number (b) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (c) denotes the video's length in seconds.", "output_spec": "Print a single number \u2014 the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.", "sample_inputs": ["4 1 1", "10 3 2", "13 12 1"], "sample_outputs": ["3", "5", "1"], "notes": "NoteIn the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 \u00b7 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.In the second sample guys need 2 \u00b7 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary."}, "src_uid": "7dd098ec3ad5b29ad681787173eba341"} {"nl": {"description": "Giga Tower is the tallest and deepest building in Cyberland. There are 17\u2009777\u2009777\u2009777 floors, numbered from \u2009-\u20098\u2009888\u2009888\u2009888 to 8\u2009888\u2009888\u2009888. In particular, there is floor 0 between floor \u2009-\u20091 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number \"8\" is a lucky number (that's why Giga Tower has 8\u2009888\u2009888\u2009888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit \"8\". For example, 8,\u2009\u2009-\u2009180,\u2009808 are all lucky while 42,\u2009\u2009-\u200910 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number. ", "input_spec": "The only line of input contains an integer a (\u2009-\u2009109\u2009\u2264\u2009a\u2009\u2264\u2009109).", "output_spec": "Print the minimum b in a line.", "sample_inputs": ["179", "-1", "18"], "sample_outputs": ["1", "9", "10"], "notes": "NoteFor the first sample, he has to arrive at the floor numbered 180.For the second sample, he will arrive at 8.Note that b should be positive, so the answer for the third sample is 10, not 0."}, "src_uid": "4e57740be015963c190e0bfe1ab74cb9"} {"nl": {"description": "One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly n pages.Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.", "input_spec": "The first input line contains the single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 \u2014 those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.", "output_spec": "Print a single number \u2014 the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.", "sample_inputs": ["100\n15 20 20 15 10 30 45", "2\n1 0 0 0 0 0 0"], "sample_outputs": ["6", "1"], "notes": "NoteNote to the first sample:By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).Note to the second sample:On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book."}, "src_uid": "007a779d966e2e9219789d6d9da7002c"} {"nl": {"description": "On a chessboard with a width of $$$n$$$ and a height of $$$n$$$, rows are numbered from bottom to top from $$$1$$$ to $$$n$$$, columns are numbered from left to right from $$$1$$$ to $$$n$$$. Therefore, for each cell of the chessboard, you can assign the coordinates $$$(r,c)$$$, where $$$r$$$ is the number of the row, and $$$c$$$ is the number of the column.The white king has been sitting in a cell with $$$(1,1)$$$ coordinates for a thousand years, while the black king has been sitting in a cell with $$$(n,n)$$$ coordinates. They would have sat like that further, but suddenly a beautiful coin fell on the cell with coordinates $$$(x,y)$$$...Each of the monarchs wanted to get it, so they decided to arrange a race according to slightly changed chess rules:As in chess, the white king makes the first move, the black king makes the second one, the white king makes the third one, and so on. However, in this problem, kings can stand in adjacent cells or even in the same cell at the same time.The player who reaches the coin first will win, that is to say, the player who reaches the cell with the coordinates $$$(x,y)$$$ first will win.Let's recall that the king is such a chess piece that can move one cell in all directions, that is, if the king is in the $$$(a,b)$$$ cell, then in one move he can move from $$$(a,b)$$$ to the cells $$$(a + 1,b)$$$, $$$(a - 1,b)$$$, $$$(a,b + 1)$$$, $$$(a,b - 1)$$$, $$$(a + 1,b - 1)$$$, $$$(a + 1,b + 1)$$$, $$$(a - 1,b - 1)$$$, or $$$(a - 1,b + 1)$$$. Going outside of the field is prohibited.Determine the color of the king, who will reach the cell with the coordinates $$$(x,y)$$$ first, if the white king moves first.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 10^{18}$$$)\u00a0\u2014 the length of the side of the chess field. The second line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \\le x,y \\le n$$$)\u00a0\u2014 coordinates of the cell, where the coin fell.", "output_spec": "In a single line print the answer \"White\" (without quotes), if the white king will win, or \"Black\" (without quotes), if the black king will win. You can print each letter in any case (upper or lower).", "sample_inputs": ["4\n2 3", "5\n3 5", "2\n2 2"], "sample_outputs": ["White", "Black", "Black"], "notes": "NoteAn example of the race from the first sample where both the white king and the black king move optimally: The white king moves from the cell $$$(1,1)$$$ into the cell $$$(2,2)$$$. The black king moves form the cell $$$(4,4)$$$ into the cell $$$(3,3)$$$. The white king moves from the cell $$$(2,2)$$$ into the cell $$$(2,3)$$$. This is cell containing the coin, so the white king wins. An example of the race from the second sample where both the white king and the black king move optimally: The white king moves from the cell $$$(1,1)$$$ into the cell $$$(2,2)$$$. The black king moves form the cell $$$(5,5)$$$ into the cell $$$(4,4)$$$. The white king moves from the cell $$$(2,2)$$$ into the cell $$$(3,3)$$$. The black king moves from the cell $$$(4,4)$$$ into the cell $$$(3,5)$$$. This is the cell, where the coin fell, so the black king wins. In the third example, the coin fell in the starting cell of the black king, so the black king immediately wins. "}, "src_uid": "b8ece086b35a36ca873e2edecc674557"} {"nl": {"description": "The king's birthday dinner was attended by $$$k$$$ guests. The dinner was quite a success: every person has eaten several dishes (though the number of dishes was the same for every person) and every dish was served alongside with a new set of kitchen utensils.All types of utensils in the kingdom are numbered from $$$1$$$ to $$$100$$$. It is known that every set of utensils is the same and consist of different types of utensils, although every particular type may appear in the set at most once. For example, a valid set of utensils can be composed of one fork, one spoon and one knife.After the dinner was over and the guests were dismissed, the king wondered what minimum possible number of utensils could be stolen. Unfortunately, the king has forgotten how many dishes have been served for every guest but he knows the list of all the utensils left after the dinner. Your task is to find the minimum possible number of stolen utensils.", "input_spec": "The first line contains two integer numbers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 100, 1 \\le k \\le 100$$$) \u00a0\u2014 the number of kitchen utensils remaining after the dinner and the number of guests correspondingly. The next line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 100$$$) \u00a0\u2014 the types of the utensils remaining. Equal values stand for identical utensils while different values stand for different utensils.", "output_spec": "Output a single value \u2014 the minimum number of utensils that could be stolen by the guests.", "sample_inputs": ["5 2\n1 2 2 1 3", "10 3\n1 3 3 1 3 5 5 5 5 100"], "sample_outputs": ["1", "14"], "notes": "NoteIn the first example it is clear that at least one utensil of type $$$3$$$ has been stolen, since there are two guests and only one such utensil. But it is also possible that every person received only one dish and there were only six utensils in total, when every person got a set $$$(1, 2, 3)$$$ of utensils. Therefore, the answer is $$$1$$$.One can show that in the second example at least $$$2$$$ dishes should have been served for every guest, so the number of utensils should be at least $$$24$$$: every set contains $$$4$$$ utensils and every one of the $$$3$$$ guests gets two such sets. Therefore, at least $$$14$$$ objects have been stolen. Please note that utensils of some types (for example, of types $$$2$$$ and $$$4$$$ in this example) may be not present in the set served for dishes."}, "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f"} {"nl": {"description": "Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?For simplicity, the signature is represented as an $$$n\\times m$$$ grid, where every cell is either filled with ink or empty. Andrey's pen can fill a $$$3\\times3$$$ square without its central cell if it is completely contained inside the grid, as shown below. xxxx.xxxx Determine whether is it possible to forge the signature on an empty $$$n\\times m$$$ grid.", "input_spec": "The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$3 \\le n, m \\le 1000$$$). Then $$$n$$$ lines follow, each contains $$$m$$$ characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.", "output_spec": "If Andrey can forge the signature, output \"YES\". Otherwise output \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["3 3\n###\n#.#\n###", "3 3\n###\n###\n###", "4 3\n###\n###\n###\n###", "5 7\n.......\n.#####.\n.#.#.#.\n.#####.\n......."], "sample_outputs": ["YES", "NO", "YES", "YES"], "notes": "NoteIn the first sample Andrey can paint the border of the square with the center in $$$(2, 2)$$$.In the second sample the signature is impossible to forge.In the third sample Andrey can paint the borders of the squares with the centers in $$$(2, 2)$$$ and $$$(3, 2)$$$: we have a clear paper: ............ use the pen with center at $$$(2, 2)$$$. ####.####... use the pen with center at $$$(3, 2)$$$. ############ In the fourth sample Andrey can paint the borders of the squares with the centers in $$$(3, 3)$$$ and $$$(3, 5)$$$."}, "src_uid": "49e5eabe8d69b3d27a251cccc001ab25"} {"nl": {"description": "There exists an island called Arpa\u2019s land, some beautiful girls live there, as ugly ones do.Mehrdad wants to become minister of Arpa\u2019s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.", "input_spec": "The single line of input contains one integer n (0\u2009\u2009\u2264\u2009\u2009n\u2009\u2009\u2264\u2009\u2009109).", "output_spec": "Print single integer\u00a0\u2014 the last digit of 1378n.", "sample_inputs": ["1", "2"], "sample_outputs": ["8", "4"], "notes": "NoteIn the first example, last digit of 13781\u2009=\u20091378 is 8.In the second example, last digit of 13782\u2009=\u20091378\u00b71378\u2009=\u20091898884 is 4."}, "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"nl": {"description": "Today, Mezo is playing a game. Zoma, a character in that game, is initially at position $$$x = 0$$$. Mezo starts sending $$$n$$$ commands to Zoma. There are two possible commands: 'L' (Left) sets the position $$$x: =x - 1$$$; 'R' (Right) sets the position $$$x: =x + 1$$$. Unfortunately, Mezo's controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position $$$x$$$ doesn't change and Mezo simply proceeds to the next command.For example, if Mezo sends commands \"LRLR\", then here are some possible outcomes (underlined commands are sent successfully): \"LRLR\" \u2014 Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position $$$0$$$; \"LRLR\" \u2014 Zoma recieves no commands, doesn't move at all and ends up at position $$$0$$$ as well; \"LRLR\" \u2014 Zoma moves to the left, then to the left again and ends up in position $$$-2$$$. Mezo doesn't know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.", "input_spec": "The first line contains $$$n$$$ $$$(1 \\le n \\le 10^5)$$$ \u2014 the number of commands Mezo sends. The second line contains a string $$$s$$$ of $$$n$$$ commands, each either 'L' (Left) or 'R' (Right).", "output_spec": "Print one integer \u2014 the number of different positions Zoma may end up at.", "sample_inputs": ["4\nLRLR"], "sample_outputs": ["5"], "notes": "NoteIn the example, Zoma may end up anywhere between $$$-2$$$ and $$$2$$$."}, "src_uid": "098ade88ed90664da279fe8a5a54b5ba"} {"nl": {"description": "For a positive integer n let's define a function f:f(n)\u2009=\u2009\u2009-\u20091\u2009+\u20092\u2009-\u20093\u2009+\u2009..\u2009+\u2009(\u2009-\u20091)nn Your task is to calculate f(n) for a given integer n.", "input_spec": "The single line contains the positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091015).", "output_spec": "Print f(n) in a single line.", "sample_inputs": ["4", "5"], "sample_outputs": ["2", "-3"], "notes": "Notef(4)\u2009=\u2009\u2009-\u20091\u2009+\u20092\u2009-\u20093\u2009+\u20094\u2009=\u20092f(5)\u2009=\u2009\u2009-\u20091\u2009+\u20092\u2009-\u20093\u2009+\u20094\u2009-\u20095\u2009=\u2009\u2009-\u20093"}, "src_uid": "689e7876048ee4eb7479e838c981f068"} {"nl": {"description": "When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word \"tma\" (which now means \"too much to be counted\") used to stand for a thousand and \"tma tmyschaya\" (which literally means \"the tma of tmas\") used to stand for a million.Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2, petricium la petricium la petricium stands for k3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.", "input_spec": "The first input line contains integer number k, the second line contains integer number l (2\u2009\u2264\u2009k,\u2009l\u2009\u2264\u2009231\u2009-\u20091).", "output_spec": "You should print in the first line of the output \"YES\", if the number belongs to the set petriciumus cifera and otherwise print \"NO\". If the number belongs to the set, then print on the seconds line the only number \u2014 the importance of number l.", "sample_inputs": ["5\n25", "3\n8"], "sample_outputs": ["YES\n1", "NO"], "notes": null}, "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"nl": {"description": "Polycarp loves ciphers. He has invented his own cipher called repeating.Repeating cipher is used for strings. To encrypt the string $$$s=s_{1}s_{2} \\dots s_{m}$$$ ($$$1 \\le m \\le 10$$$), Polycarp uses the following algorithm: he writes down $$$s_1$$$ ones, he writes down $$$s_2$$$ twice, he writes down $$$s_3$$$ three times, ... he writes down $$$s_m$$$ $$$m$$$ times. For example, if $$$s$$$=\"bab\" the process is: \"b\" $$$\\to$$$ \"baa\" $$$\\to$$$ \"baabbb\". So the encrypted $$$s$$$=\"bab\" is \"baabbb\".Given string $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. Your task is to decrypt it, i.\u2009e. find the string $$$s$$$.", "input_spec": "The first line contains integer $$$n$$$ ($$$1 \\le n \\le 55$$$) \u2014 the length of the encrypted string. The second line of the input contains $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. It contains only lowercase Latin letters. The length of $$$t$$$ is exactly $$$n$$$. It is guaranteed that the answer to the test exists.", "output_spec": "Print such string $$$s$$$ that after encryption it equals $$$t$$$.", "sample_inputs": ["6\nbaabbb", "10\nooopppssss", "1\nz"], "sample_outputs": ["bab", "oops", "z"], "notes": null}, "src_uid": "08e8c0c37b223f6aae01d5609facdeaf"} {"nl": {"description": "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_spec": "The first line contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of letters in word s before the correction. The second line contains a string s consisting of exactly n lowercase Latin letters \u2014 the word before the correction.", "output_spec": "Output the word s after the correction.", "sample_inputs": ["5\nweird", "4\nword", "5\naaeaa"], "sample_outputs": ["werd", "word", "a"], "notes": "NoteExplanations of the examples: There is only one replace: weird werd; No replace needed since there are no two consecutive vowels; aaeaa aeaa aaa aa a. "}, "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"nl": {"description": "You are given a permutation p of numbers 1,\u20092,\u2009...,\u2009n. Let's define f(p) as the following sum:Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).", "input_spec": "The single line of input contains two integers n and m (1\u2009\u2264\u2009m\u2009\u2264\u2009cntn), where cntn is the number of permutations of length n with maximum possible value of f(p). The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. In subproblem B1 (3 points), the constraint 1\u2009\u2264\u2009n\u2009\u2264\u20098 will hold. In subproblem B2 (4 points), the constraint 1\u2009\u2264\u2009n\u2009\u2264\u200950 will hold. ", "output_spec": "Output n number forming the required permutation.", "sample_inputs": ["2 2", "3 2"], "sample_outputs": ["2 1", "1 3 2"], "notes": "NoteIn the first example, both permutations of numbers {1, 2} yield maximum possible f(p) which is equal to 4. Among them, (2,\u20091) comes second in lexicographical order."}, "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"} {"nl": {"description": "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,\u2009b\u2009+\u2009a,\u2009b\u2009+\u20092a,\u2009b\u2009+\u20093a,\u2009... and Morty screams at times d,\u2009d\u2009+\u2009c,\u2009d\u2009+\u20092c,\u2009d\u2009+\u20093c,\u2009.... 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_spec": "The first line of input contains two integers a and b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009100). The second line contains two integers c and d (1\u2009\u2264\u2009c,\u2009d\u2009\u2264\u2009100).", "output_spec": "Print the first time Rick and Morty will scream at the same time, or \u2009-\u20091 if they will never scream at the same time.", "sample_inputs": ["20 2\n9 19", "2 1\n16 12"], "sample_outputs": ["82", "-1"], "notes": "NoteIn 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."}, "src_uid": "158cb12d45f4ee3368b94b2b622693e7"} {"nl": {"description": "Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.See the examples for better understanding.", "input_spec": "The first line of input contains two integer numbers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009100) \u2014 the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.", "output_spec": "Print one integer number \u2014 the minimum number of hours required to water the garden.", "sample_inputs": ["3 6\n2 3 5", "6 7\n1 2 3 4 5 6"], "sample_outputs": ["2", "7"], "notes": "NoteIn the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.In the second test we can choose only the bucket that allows us to water the segment of length 1."}, "src_uid": "80520be9916045aca3a7de7bc925af1f"} {"nl": {"description": "Igor likes hexadecimal notation and considers positive integer in the hexadecimal notation interesting if each digit and each letter in it appears no more than t times. For example, if t\u2009=\u20093, then integers 13a13322, aaa, abcdef0123456789 are interesting, but numbers aaaa, abababab and 1000000 are not interesting.Your task is to find the k-th smallest interesting for Igor integer in the hexadecimal notation. The integer should not contain leading zeros.", "input_spec": "The first line contains the two integers k and t (1\u2009\u2264\u2009k\u2009\u2264\u20092\u00b7109, 1\u2009\u2264\u2009t\u2009\u2264\u200910) \u2014 the number of the required integer and the maximum number of times some integer or letter can appear in interesting integer. It can be shown that the answer always exists for such constraints.", "output_spec": "Print in the hexadecimal notation the only integer that is the k-th smallest interesting integer for Igor.", "sample_inputs": ["17 1", "1000000 2"], "sample_outputs": ["12", "fca2c"], "notes": "NoteThe first 20 interesting integers if t\u2009=\u20091: 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, 10, 12, 13, 14, 15. So the answer for the first example equals 12."}, "src_uid": "cbfc354cfa392cd021d9fe899a745f0e"} {"nl": {"description": "Stepan has a very big positive integer.Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203 and integers 20310 and 31020.Stepan wants to know the minimum remainder of the division by the given number m among all good shifts. Your task is to determine the minimum remainder of the division by m.", "input_spec": "The first line contains the integer which Stepan has. The length of Stepan's integer is between 2 and 200\u2009000 digits, inclusive. It is guaranteed that Stepan's integer does not contain leading zeros. The second line contains the integer m (2\u2009\u2264\u2009m\u2009\u2264\u2009108) \u2014 the number by which Stepan divides good shifts of his integer.", "output_spec": "Print the minimum remainder which Stepan can get if he divides all good shifts of his integer by the given number m.", "sample_inputs": ["521\n3", "1001\n5", "5678901234567890123456789\n10000"], "sample_outputs": ["2", "0", "123"], "notes": "NoteIn the first example all good shifts of the integer 521 (good shifts are equal to 521, 215 and 152) has same remainder 2 when dividing by 3.In the second example there are only two good shifts: the Stepan's integer itself and the shift by one position to the right. The integer itself is 1001 and the remainder after dividing it by 5 equals 1. The shift by one position to the right equals to 1100 and the remainder after dividing it by 5 equals 0, which is the minimum possible remainder."}, "src_uid": "d13c7b5b5fc5c433cc8f374ddb16ef79"} {"nl": {"description": "At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive. Help the university pick the passing rate in a way that meets these requirements.", "input_spec": "The first line contains integer m (2\u2009\u2264\u2009m\u2009\u2264\u2009100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0\u2009\u2264\u2009ci\u2009\u2264\u2009100). The third line contains two space-separated integers x and y (1\u2009\u2264\u2009x\u2009\u2264\u2009y\u2009\u2264\u200910000). At least one ci is greater than 0.", "output_spec": "If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m \u2014 the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.", "sample_inputs": ["5\n3 4 3 2 1\n6 8", "5\n0 3 3 4 2\n3 10", "2\n2 5\n3 6"], "sample_outputs": ["3", "4", "0"], "notes": "NoteIn the first sample the beginner group has 7 students, the intermediate group has 6 of them. In the second sample another correct answer is 3."}, "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"} {"nl": {"description": "A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings \"kek\", \"abacaba\", \"r\" and \"papicipap\" are palindromes, while the strings \"abb\" and \"iq\" are not.A substring $$$s[l \\ldots r]$$$ ($$$1\u2009\\leq\u2009l\u2009\\leq\u2009r\u2009\\leq\u2009|s|$$$) of a string $$$s\u2009=\u2009s_{1}s_{2} \\ldots s_{|s|}$$$ is the string $$$s_{l}s_{l\u2009+\u20091} \\ldots s_{r}$$$.Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $$$s$$$ is changed into its longest substring that is not a palindrome. If all the substrings of $$$s$$$ are palindromes, she skips the word at all.Some time ago Ann read the word $$$s$$$. What is the word she changed it into?", "input_spec": "The first line contains a non-empty string $$$s$$$ with length at most $$$50$$$ characters, containing lowercase English letters only.", "output_spec": "If there is such a substring in $$$s$$$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $$$0$$$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.", "sample_inputs": ["mew", "wuffuw", "qqqqqqqq"], "sample_outputs": ["3", "5", "0"], "notes": "Note\"mew\" is not a palindrome, so the longest substring of it that is not a palindrome, is the string \"mew\" itself. Thus, the answer for the first example is $$$3$$$.The string \"uffuw\" is one of the longest non-palindrome substrings (of length $$$5$$$) of the string \"wuffuw\", so the answer for the second example is $$$5$$$.All substrings of the string \"qqqqqqqq\" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $$$0$$$."}, "src_uid": "6c85175d334f811617e7030e0403f706"} {"nl": {"description": "Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don\u2019t want to use too many blocks, but they also want to be unique, so no two students\u2019 towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.", "input_spec": "The first line of the input contains two space-separated integers n and m (0\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091\u2009000\u2009000, n\u2009+\u2009m\u2009>\u20090)\u00a0\u2014 the number of students using two-block pieces and the number of students using three-block pieces, respectively.", "output_spec": "Print a single integer, denoting the minimum possible height of the tallest tower.", "sample_inputs": ["1 3", "3 2", "5 0"], "sample_outputs": ["9", "8", "10"], "notes": "NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks."}, "src_uid": "23f2c8cac07403899199abdcfd947a5a"} {"nl": {"description": "Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl,\u2009yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl,\u2009yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.", "input_spec": "First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character \"x\" (ASCII-code 120) means that the cell is occupied with chip of the first player, character \"o\" (ASCII-code 111) denotes a field occupied with chip of the second player, character \".\" (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20099). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with \"x\" or \"o\". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.", "output_spec": "Output the field in same format with characters \"!\" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.", "sample_inputs": ["... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4", "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4", "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5"], "sample_outputs": ["... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ...", "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!!", "o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!!"], "notes": "NoteIn the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable."}, "src_uid": "8f0fad22f629332868c39969492264d3"} {"nl": {"description": "You want to arrange n integers a1,\u2009a2,\u2009...,\u2009an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.More formally, let's denote some arrangement as a sequence of integers x1,\u2009x2,\u2009...,\u2009xn, where sequence x is a permutation of sequence a. The value of such an arrangement is (x1\u2009-\u2009x2)\u2009+\u2009(x2\u2009-\u2009x3)\u2009+\u2009...\u2009+\u2009(xn\u2009-\u20091\u2009-\u2009xn).Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence x that corresponds to an arrangement of the largest possible value.", "input_spec": "The first line of the input contains integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100). The second line contains n space-separated integers a1, a2, ..., an (|ai|\u2009\u2264\u20091000).", "output_spec": "Print the required sequence x1,\u2009x2,\u2009...,\u2009xn. Sequence x should be the lexicographically smallest permutation of a that corresponds to an arrangement of the largest possible value.", "sample_inputs": ["5\n100 -100 50 0 -50"], "sample_outputs": ["100 -50 0 50 -100"], "notes": "NoteIn the sample test case, the value of the output arrangement is (100\u2009-\u2009(\u2009-\u200950))\u2009+\u2009((\u2009-\u200950)\u2009-\u20090)\u2009+\u2009(0\u2009-\u200950)\u2009+\u2009(50\u2009-\u2009(\u2009-\u2009100))\u2009=\u2009200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.Sequence x1,\u2009x2,\u2009... ,\u2009xp is lexicographically smaller than sequence y1,\u2009y2,\u2009... ,\u2009yp if there exists an integer r (0\u2009\u2264\u2009r\u2009<\u2009p) such that x1\u2009=\u2009y1,\u2009x2\u2009=\u2009y2,\u2009... ,\u2009xr\u2009=\u2009yr and xr\u2009+\u20091\u2009<\u2009yr\u2009+\u20091."}, "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4"} {"nl": {"description": "Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (n\u2009-\u20091) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,\u20092,\u20091] after the first step, the sequence [1,\u20092,\u20091,\u20093,\u20091,\u20092,\u20091] after the second step.The task is to find the value of the element with index k (the elements are numbered from 1) in the obtained sequence, i.\u00a0e. after (n\u2009-\u20091) steps.Please help Chloe to solve the problem!", "input_spec": "The only line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u200950, 1\u2009\u2264\u2009k\u2009\u2264\u20092n\u2009-\u20091).", "output_spec": "Print single integer\u00a0\u2014 the integer at the k-th position in the obtained sequence.", "sample_inputs": ["3 2", "4 8"], "sample_outputs": ["2", "4"], "notes": "NoteIn the first sample the obtained sequence is [1,\u20092,\u20091,\u20093,\u20091,\u20092,\u20091]. The number on the second position is 2.In the second sample the obtained sequence is [1,\u20092,\u20091,\u20093,\u20091,\u20092,\u20091,\u20094,\u20091,\u20092,\u20091,\u20093,\u20091,\u20092,\u20091]. The number on the eighth position is 4."}, "src_uid": "0af400ea8e25b1a36adec4cc08912b71"} {"nl": {"description": "There are $$$n$$$ students in a school class, the rating of the $$$i$$$-th student on Codehorses is $$$a_i$$$. You have to form a team consisting of $$$k$$$ students ($$$1 \\le k \\le n$$$) such that the ratings of all team members are distinct.If it is impossible to form a suitable team, print \"NO\" (without quotes). Otherwise print \"YES\", and then print $$$k$$$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 100$$$) \u2014 the number of students and the size of the team you have to form. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the rating of $$$i$$$-th student.", "output_spec": "If it is impossible to form a suitable team, print \"NO\" (without quotes). Otherwise print \"YES\", and then print $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $$$1$$$ to $$$n$$$.", "sample_inputs": ["5 3\n15 13 15 15 12", "5 4\n15 13 15 15 12", "4 4\n20 10 40 30"], "sample_outputs": ["YES\n1 2 5", "NO", "YES\n1 2 3 4"], "notes": "NoteAll possible answers for the first example: {1 2 5} {2 3 5} {2 4 5} Note that the order does not matter."}, "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"nl": {"description": "Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't. Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of pieces in the chocolate bar. The second line contains n integers ai (0\u2009\u2264\u2009ai\u2009\u2264\u20091), where 0 represents a piece without the nut and 1 stands for a piece with the nut.", "output_spec": "Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.", "sample_inputs": ["3\n0 1 0", "5\n1 0 1 0 1"], "sample_outputs": ["1", "4"], "notes": "NoteIn the first sample there is exactly one nut, so the number of ways equals 1\u00a0\u2014 Bob shouldn't make any breaks.In the second sample you can break the bar in four ways:10|10|11|010|110|1|011|01|01"}, "src_uid": "58242665476f1c4fa723848ff0ecda98"} {"nl": {"description": "On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n\u2009-\u20091-st row, the n-th row, the n\u2009-\u20091-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row.", "input_spec": "The first and the only line contains five integers n, m, k, x and y (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009k\u2009\u2264\u20091018,\u20091\u2009\u2264\u2009x\u2009\u2264\u2009n,\u20091\u2009\u2264\u2009y\u2009\u2264\u2009m).", "output_spec": "Print three integers: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. ", "sample_inputs": ["1 3 8 1 1", "4 2 9 4 2", "5 5 25 4 3", "100 100 1000000000000000000 100 100"], "sample_outputs": ["3 2 3", "2 1 1", "1 1 1", "101010101010101 50505050505051 50505050505051"], "notes": "NoteThe order of asking pupils in the first test: the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; The order of asking pupils in the second test: the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table; "}, "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21"} {"nl": {"description": "Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches the sum of digits in its second half.But of course, not every ticket can be lucky. Far from it! Moreover, sometimes one look at a ticket can be enough to say right away that the ticket is not lucky. So, let's consider the following unluckiness criterion that can definitely determine an unlucky ticket. We'll say that a ticket is definitely unlucky if each digit from the first half corresponds to some digit from the second half so that each digit from the first half is strictly less than the corresponding digit from the second one or each digit from the first half is strictly more than the corresponding digit from the second one. Each digit should be used exactly once in the comparisons. In other words, there is such bijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns out strictly less than the corresponding digit of the second half or each digit of the first half turns out strictly more than the corresponding digit from the second half.For example, ticket 2421 meets the following unluckiness criterion and will not be considered lucky (the sought correspondence is 2\u2009>\u20091 and 4\u2009>\u20092), ticket 0135 also meets the criterion (the sought correspondence is 0\u2009<\u20093 and 1\u2009<\u20095), and ticket 3754 does not meet the criterion. You have a ticket in your hands, it contains 2n digits. Your task is to check whether it meets the unluckiness criterion.", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). The second line contains a string that consists of 2n digits and defines your ticket.", "output_spec": "In the first line print \"YES\" if the ticket meets the unluckiness criterion. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["2\n2421", "2\n0135", "2\n3754"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "e4419bca9d605dbd63f7884377e28769"} {"nl": {"description": "User ainta has a stack of n red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. While the top ball inside the stack is red, pop the ball from the top of the stack. Then replace the blue ball on the top with a red ball. And finally push some blue balls to the stack until the stack has total of n balls inside. \u00a0If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply.", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the number of balls inside the stack. The second line contains a string s (|s|\u2009=\u2009n) describing the initial state of the stack. The i-th character of the string s denotes the color of the i-th ball (we'll number the balls from top to bottom of the stack). If the character is \"R\", the color is red. If the character is \"B\", the color is blue.", "output_spec": "Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specifier.", "sample_inputs": ["3\nRBR", "4\nRBBR", "5\nRBBRR"], "sample_outputs": ["2", "6", "6"], "notes": "NoteThe first example is depicted below.The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball. The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red. From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2.The second example is depicted below. The blue arrow denotes a single operation. "}, "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"} {"nl": {"description": "You have $$$n$$$ coins, each of the same value of $$$1$$$.Distribute them into packets such that any amount $$$x$$$ ($$$1 \\leq x \\leq n$$$) can be formed using some (possibly one or all) number of these packets.Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single $$$x$$$, however it may be reused for the formation of other $$$x$$$'s.Find the minimum number of packets in such a distribution.", "input_spec": "The only line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^9$$$)\u00a0\u2014 the number of coins you have.", "output_spec": "Output a single integer\u00a0\u2014 the minimum possible number of packets, satisfying the condition above.", "sample_inputs": ["6", "2"], "sample_outputs": ["3", "2"], "notes": "NoteIn the first example, three packets with $$$1$$$, $$$2$$$ and $$$3$$$ coins can be made to get any amount $$$x$$$ ($$$1\\leq x\\leq 6$$$). To get $$$1$$$ use the packet with $$$1$$$ coin. To get $$$2$$$ use the packet with $$$2$$$ coins. To get $$$3$$$ use the packet with $$$3$$$ coins. To get $$$4$$$ use packets with $$$1$$$ and $$$3$$$ coins. To get $$$5$$$ use packets with $$$2$$$ and $$$3$$$ coins To get $$$6$$$ use all packets. In the second example, two packets with $$$1$$$ and $$$1$$$ coins can be made to get any amount $$$x$$$ ($$$1\\leq x\\leq 2$$$)."}, "src_uid": "95cb79597443461085e62d974d67a9a0"} {"nl": {"description": "Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.In this problem you should implement the similar functionality.You are given a string which only consists of: uppercase and lowercase English letters, underscore symbols (they are used as separators), parentheses (both opening and closing). It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching \"opening-closing\" pair, and such pairs can't be nested.For example, the following string is valid: \"_Hello_Vasya(and_Petya)__bye_(and_OK)\".Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: \"Hello\", \"Vasya\", \"and\", \"Petya\", \"bye\", \"and\" and \"OK\". Write a program that finds: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses). ", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009255)\u00a0\u2014 the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols. ", "output_spec": "Print two space-separated integers: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses). ", "sample_inputs": ["37\n_Hello_Vasya(and_Petya)__bye_(and_OK)", "37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__", "27\n(LoooonG)__shOrt__(LoooonG)", "5\n(___)"], "sample_outputs": ["5 4", "2 6", "5 2", "0 0"], "notes": "NoteIn the first sample, the words \"Hello\", \"Vasya\" and \"bye\" are outside any of the parentheses, and the words \"and\", \"Petya\", \"and\" and \"OK\" are inside. Note, that the word \"and\" is given twice and you should count it twice in the answer."}, "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"} {"nl": {"description": "Let's call a string good if and only if it consists of only two types of letters\u00a0\u2014 'a' and 'b' and every two consecutive letters are distinct. For example \"baba\" and \"aba\" are good strings and \"abb\" is a bad string.You have $$$a$$$ strings \"a\", $$$b$$$ strings \"b\" and $$$c$$$ strings \"ab\". You want to choose some subset of these strings and concatenate them in any arbitrarily order.What is the length of the longest good string you can obtain this way?", "input_spec": "The first line contains three positive integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \\leq a, b, c \\leq 10^9$$$)\u00a0\u2014 the number of strings \"a\", \"b\" and \"ab\" respectively.", "output_spec": "Print a single number\u00a0\u2014 the maximum possible length of the good string you can obtain.", "sample_inputs": ["1 1 1", "2 1 2", "3 5 2", "2 2 1", "1000000000 1000000000 1000000000"], "sample_outputs": ["4", "7", "11", "6", "4000000000"], "notes": "NoteIn the first example the optimal string is \"baba\".In the second example the optimal string is \"abababa\".In the third example the optimal string is \"bababababab\".In the fourth example the optimal string is \"ababab\"."}, "src_uid": "609f131325c13213aedcf8d55fc3ed77"} {"nl": {"description": "Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.The path consists of $$$n$$$ consecutive tiles, numbered from $$$1$$$ to $$$n$$$. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles with numbers $$$i$$$ and $$$j$$$, such that $$$|j - i|$$$ is a divisor of $$$n$$$ greater than $$$1$$$, they have the same color. Formally, the colors of two tiles with numbers $$$i$$$ and $$$j$$$ should be the same if $$$|i-j| > 1$$$ and $$$n \\bmod |i-j| = 0$$$ (where $$$x \\bmod y$$$ is the remainder when dividing $$$x$$$ by $$$y$$$).Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?", "input_spec": "The first line of input contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^{12}$$$), the length of the path.", "output_spec": "Output a single integer, the maximum possible number of colors that the path can be painted in.", "sample_inputs": ["4", "5"], "sample_outputs": ["2", "5"], "notes": "NoteIn the first sample, two colors is the maximum number. Tiles $$$1$$$ and $$$3$$$ should have the same color since $$$4 \\bmod |3-1| = 0$$$. Also, tiles $$$2$$$ and $$$4$$$ should have the same color since $$$4 \\bmod |4-2| = 0$$$.In the second sample, all five colors can be used. "}, "src_uid": "f553e89e267c223fd5acf0dd2bc1706b"} {"nl": {"description": "Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.", "input_spec": "The only line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009109).", "output_spec": "Print the smallest integer x\u2009>\u2009n, so it is divisible by the number k.", "sample_inputs": ["5 3", "25 13", "26 13"], "sample_outputs": ["6", "26", "39"], "notes": null}, "src_uid": "75f3835c969c871a609b978e04476542"} {"nl": {"description": "The only difference between easy and hard versions is the constraints.Polycarp has to write a coursework. The coursework consists of $$$m$$$ pages.Polycarp also has $$$n$$$ cups of coffee. The coffee in the $$$i$$$-th cup has $$$a_i$$$ caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.Let's consider some day of Polycarp's work. Consider Polycarp drinks $$$k$$$ cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are $$$a_{i_1}, a_{i_2}, \\dots, a_{i_k}$$$. Then the first cup he drinks gives him energy to write $$$a_{i_1}$$$ pages of coursework, the second cup gives him energy to write $$$max(0, a_{i_2} - 1)$$$ pages, the third cup gives him energy to write $$$max(0, a_{i_3} - 2)$$$ pages, ..., the $$$k$$$-th cup gives him energy to write $$$max(0, a_{i_k} - k + 1)$$$ pages.If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le m \\le 10^4$$$) \u2014 the number of cups of coffee and the number of pages in the coursework. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the caffeine dosage of coffee in the $$$i$$$-th cup.", "output_spec": "If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.", "sample_inputs": ["5 8\n2 3 1 1 2", "7 10\n1 3 4 2 1 4 2", "5 15\n5 5 5 5 5", "5 16\n5 5 5 5 5", "5 26\n5 5 5 5 5"], "sample_outputs": ["4", "2", "1", "2", "-1"], "notes": "NoteIn the first example Polycarp can drink fourth cup during first day (and write $$$1$$$ page), first and second cups during second day (and write $$$2 + (3 - 1) = 4$$$ pages), fifth cup during the third day (and write $$$2$$$ pages) and third cup during the fourth day (and write $$$1$$$ page) so the answer is $$$4$$$. It is obvious that there is no way to write the coursework in three or less days in this test.In the second example Polycarp can drink third, fourth and second cups during first day (and write $$$4 + (2 - 1) + (3 - 2) = 6$$$ pages) and sixth cup during second day (and write $$$4$$$ pages) so the answer is $$$2$$$. It is obvious that Polycarp cannot write the whole coursework in one day in this test.In the third example Polycarp can drink all cups of coffee during first day and write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15$$$ pages of coursework.In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) = 14$$$ pages of coursework and during second day he will write $$$5$$$ pages of coursework. This is enough to complete it.In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1."}, "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"} {"nl": {"description": "Drazil is playing a math game with Varda.Let's define for positive integer x as a product of factorials of its digits. For example, .First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:1. x doesn't contain neither digit 0 nor digit 1.2. = .Help friends find such number.", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u200915) \u2014 the number of digits in a. The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.", "output_spec": "Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.", "sample_inputs": ["4\n1234", "3\n555"], "sample_outputs": ["33222", "555"], "notes": "NoteIn the first case, "}, "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"nl": {"description": "Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i\u2009-\u20091)-th man in the line (for the current moment) talks with the (2i)-th one. Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.We know that if students i and j talk, then the i-th student's happiness increases by gij and the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.", "input_spec": "The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0\u2009\u2264\u2009gij\u2009\u2264\u2009105). It is guaranteed that gii\u2009=\u20090 for all i. Assume that the students are numbered from 1 to 5.", "output_spec": "Print a single integer \u2014 the maximum possible total happiness of the students.", "sample_inputs": ["0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0", "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0"], "sample_outputs": ["32", "620"], "notes": "NoteIn the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:(g23\u2009+\u2009g32\u2009+\u2009g15\u2009+\u2009g51)\u2009+\u2009(g13\u2009+\u2009g31\u2009+\u2009g54\u2009+\u2009g45)\u2009+\u2009(g15\u2009+\u2009g51)\u2009+\u2009(g54\u2009+\u2009g45)\u2009=\u200932."}, "src_uid": "be6d4df20e9a48d183dd8f34531df246"} {"nl": {"description": "Petya studies at university. The current academic year finishes with $$$n$$$ special days. Petya needs to pass $$$m$$$ exams in those special days. The special days in this problem are numbered from $$$1$$$ to $$$n$$$.There are three values about each exam: $$$s_i$$$ \u2014 the day, when questions for the $$$i$$$-th exam will be published, $$$d_i$$$ \u2014 the day of the $$$i$$$-th exam ($$$s_i < d_i$$$), $$$c_i$$$ \u2014 number of days Petya needs to prepare for the $$$i$$$-th exam. For the $$$i$$$-th exam Petya should prepare in days between $$$s_i$$$ and $$$d_i-1$$$, inclusive. There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the $$$i$$$-th exam in day $$$j$$$, then $$$s_i \\le j < d_i$$$.It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days.Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ $$$(2 \\le n \\le 100, 1 \\le m \\le n)$$$ \u2014 the number of days and the number of exams. Each of the following $$$m$$$ lines contains three integers $$$s_i$$$, $$$d_i$$$, $$$c_i$$$ $$$(1 \\le s_i < d_i \\le n, 1 \\le c_i \\le n)$$$ \u2014 the day, when questions for the $$$i$$$-th exam will be given, the day of the $$$i$$$-th exam, number of days Petya needs to prepare for the $$$i$$$-th exam. Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given.", "output_spec": "If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $$$n$$$ integers, where the $$$j$$$-th number is: $$$(m + 1)$$$, if the $$$j$$$-th day is a day of some exam (recall that in each day no more than one exam is conducted), zero, if in the $$$j$$$-th day Petya will have a rest, $$$i$$$ ($$$1 \\le i \\le m$$$), if Petya will prepare for the $$$i$$$-th exam in the day $$$j$$$ (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).Assume that the exams are numbered in order of appearing in the input, starting from $$$1$$$.If there are multiple schedules, print any of them.", "sample_inputs": ["5 2\n1 3 1\n1 5 1", "3 2\n1 3 1\n1 2 1", "10 3\n4 7 2\n1 10 3\n8 9 1"], "sample_outputs": ["1 2 3 0 3", "-1", "2 2 2 1 1 0 4 3 4 4"], "notes": "NoteIn the first example Petya can, for example, prepare for exam $$$1$$$ in the first day, prepare for exam $$$2$$$ in the second day, pass exam $$$1$$$ in the third day, relax in the fourth day, and pass exam $$$2$$$ in the fifth day. So, he can prepare and pass all exams.In the second example, there are three days and two exams. So, Petya can prepare in only one day (because in two other days he should pass exams). Then Petya can not prepare and pass all exams."}, "src_uid": "02d8d403eb60ae77756ff96f71b662d3"} {"nl": {"description": "Let's introduce some definitions that will be needed later.Let $$$prime(x)$$$ be the set of prime divisors of $$$x$$$. For example, $$$prime(140) = \\{ 2, 5, 7 \\}$$$, $$$prime(169) = \\{ 13 \\}$$$.Let $$$g(x, p)$$$ be the maximum possible integer $$$p^k$$$ where $$$k$$$ is an integer such that $$$x$$$ is divisible by $$$p^k$$$. For example: $$$g(45, 3) = 9$$$ ($$$45$$$ is divisible by $$$3^2=9$$$ but not divisible by $$$3^3=27$$$), $$$g(63, 7) = 7$$$ ($$$63$$$ is divisible by $$$7^1=7$$$ but not divisible by $$$7^2=49$$$). Let $$$f(x, y)$$$ be the product of $$$g(y, p)$$$ for all $$$p$$$ in $$$prime(x)$$$. For example: $$$f(30, 70) = g(70, 2) \\cdot g(70, 3) \\cdot g(70, 5) = 2^1 \\cdot 3^0 \\cdot 5^1 = 10$$$, $$$f(525, 63) = g(63, 3) \\cdot g(63, 5) \\cdot g(63, 7) = 3^2 \\cdot 5^0 \\cdot 7^1 = 63$$$. You have integers $$$x$$$ and $$$n$$$. Calculate $$$f(x, 1) \\cdot f(x, 2) \\cdot \\ldots \\cdot f(x, n) \\bmod{(10^{9} + 7)}$$$.", "input_spec": "The only line contains integers $$$x$$$ and $$$n$$$ ($$$2 \\le x \\le 10^{9}$$$, $$$1 \\le n \\le 10^{18}$$$)\u00a0\u2014 the numbers used in formula.", "output_spec": "Print the answer.", "sample_inputs": ["10 2", "20190929 1605", "947 987654321987654321"], "sample_outputs": ["2", "363165664", "593574252"], "notes": "NoteIn the first example, $$$f(10, 1) = g(1, 2) \\cdot g(1, 5) = 1$$$, $$$f(10, 2) = g(2, 2) \\cdot g(2, 5) = 2$$$.In the second example, actual value of formula is approximately $$$1.597 \\cdot 10^{171}$$$. Make sure you print the answer modulo $$$(10^{9} + 7)$$$.In the third example, be careful about overflow issue."}, "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"nl": {"description": "Rock... Paper!After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x1,\u2009x2,\u2009...,\u2009xn and y1,\u2009y2,\u2009...,\u2009yn respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.Then they count the number of ordered pairs (i,\u2009j) (1\u2009\u2264\u2009i,\u2009j\u2009\u2264\u2009n) such that the value xi xor yj equals to one of the 2n integers. Here xor means the bitwise exclusive or operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.", "input_spec": "The first line of input contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092\u2009000) \u2014 the length of both sequences. The second line contains n space-separated integers x1,\u2009x2,\u2009...,\u2009xn (1\u2009\u2264\u2009xi\u2009\u2264\u20092\u00b7106) \u2014 the integers finally chosen by Koyomi. The third line contains n space-separated integers y1,\u2009y2,\u2009...,\u2009yn (1\u2009\u2264\u2009yi\u2009\u2264\u20092\u00b7106) \u2014 the integers finally chosen by Karen. Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i,\u2009j) (1\u2009\u2264\u2009i,\u2009j\u2009\u2264\u2009n) exists such that one of the following holds: xi\u2009=\u2009yj; i\u2009\u2260\u2009j and xi\u2009=\u2009xj; i\u2009\u2260\u2009j and yi\u2009=\u2009yj.", "output_spec": "Output one line \u2014 the name of the winner, that is, \"Koyomi\" or \"Karen\" (without quotes). Please be aware of the capitalization.", "sample_inputs": ["3\n1 2 3\n4 5 6", "5\n2 4 6 8 10\n9 7 5 3 1"], "sample_outputs": ["Karen", "Karen"], "notes": "NoteIn the first example, there are 6 pairs satisfying the constraint: (1,\u20091), (1,\u20092), (2,\u20091), (2,\u20093), (3,\u20092) and (3,\u20093). Thus, Karen wins since 6 is an even number.In the second example, there are 16 such pairs, and Karen wins again."}, "src_uid": "1649d2592eadaa8f8d076eae2866cffc"} {"nl": {"description": "\u2014 This is not playing but duty as allies of justice, Nii-chan!\u2014 Not allies but justice itself, Onii-chan!With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters\u00a0\u2014 Karen and Tsukihi\u00a0\u2014 is heading for somewhere they've never reached\u00a0\u2014 water-surrounded islands!There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998\u2009244\u2009353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.", "input_spec": "The first and only line of input contains three space-separated integers a, b and c (1\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20095\u2009000)\u00a0\u2014 the number of islands in the red, blue and purple clusters, respectively.", "output_spec": "Output one line containing an integer\u00a0\u2014 the number of different ways to build bridges, modulo 998\u2009244\u2009353.", "sample_inputs": ["1 1 1", "1 2 2", "1 3 5", "6 2 9"], "sample_outputs": ["8", "63", "3264", "813023575"], "notes": "NoteIn the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23\u2009=\u20098.In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively. "}, "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"} {"nl": {"description": "Masha has three sticks of length $$$a$$$, $$$b$$$ and $$$c$$$ centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.", "input_spec": "The only line contains tree integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \\leq a, b, c \\leq 100$$$)\u00a0\u2014 the lengths of sticks Masha possesses.", "output_spec": "Print a single integer\u00a0\u2014 the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.", "sample_inputs": ["3 4 5", "2 5 3", "100 10 10"], "sample_outputs": ["0", "1", "81"], "notes": "NoteIn the first example, Masha can make a triangle from the sticks without increasing the length of any of them.In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length $$$2$$$ centimeter stick by one and after that form a triangle with sides $$$3$$$, $$$3$$$ and $$$5$$$ centimeters.In the third example, Masha can take $$$33$$$ minutes to increase one of the $$$10$$$ centimeters sticks by $$$33$$$ centimeters, and after that take $$$48$$$ minutes to increase another $$$10$$$ centimeters stick by $$$48$$$ centimeters. This way she can form a triangle with lengths $$$43$$$, $$$58$$$ and $$$100$$$ centimeters in $$$81$$$ minutes. One can show that it is impossible to get a valid triangle faster."}, "src_uid": "3dc56bc08606a39dd9ca40a43c452f09"} {"nl": {"description": "Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.", "input_spec": "The only line of the input contains two integers: n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009109, 0\u2009\u2264\u2009k\u2009\u2264\u2009n).", "output_spec": "Print the minimum possible and the maximum possible number of apartments good for Maxim.", "sample_inputs": ["6 3"], "sample_outputs": ["1 3"], "notes": "NoteIn the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good."}, "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"} {"nl": {"description": "We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: ? Here operation means bitwise AND (in Pascal it is equivalent to and, in C/C++/Java/Python it is equivalent to &), operation means bitwise OR (in Pascal it is equivalent to , in C/C++/Java/Python it is equivalent to |). Because the answer can be quite large, calculate it modulo m. This time GukiZ hasn't come up with solution, and needs you to help him!", "input_spec": "First and the only line of input contains four integers n, k, l, m (2\u2009\u2264\u2009n\u2009\u2264\u20091018, 0\u2009\u2264\u2009k\u2009\u2264\u20091018, 0\u2009\u2264\u2009l\u2009\u2264\u200964, 1\u2009\u2264\u2009m\u2009\u2264\u2009109\u2009+\u20097).", "output_spec": "In the single line print the number of arrays satisfying the condition above modulo m.", "sample_inputs": ["2 1 2 10", "2 1 1 3", "3 3 2 10"], "sample_outputs": ["3", "1", "9"], "notes": "NoteIn the first sample, satisfying arrays are {1,\u20091},\u2009{3,\u20091},\u2009{1,\u20093}.In the second sample, only satisfying array is {1,\u20091}.In the third sample, satisfying arrays are {0,\u20093,\u20093},\u2009{1,\u20093,\u20092},\u2009{1,\u20093,\u20093},\u2009{2,\u20093,\u20091},\u2009{2,\u20093,\u20093},\u2009{3,\u20093,\u20090},\u2009{3,\u20093,\u20091},\u2009{3,\u20093,\u20092},\u2009{3,\u20093,\u20093}."}, "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e"} {"nl": {"description": "Nauuo is a girl who loves writing comments.One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.It's known that there were $$$x$$$ persons who would upvote, $$$y$$$ persons who would downvote, and there were also another $$$z$$$ persons who would vote, but you don't know whether they would upvote or downvote. Note that each of the $$$x+y+z$$$ people would vote exactly one time.There are three different results: if there are more people upvote than downvote, the result will be \"+\"; if there are more people downvote than upvote, the result will be \"-\"; otherwise the result will be \"0\".Because of the $$$z$$$ unknown persons, the result may be uncertain (i.e. there are more than one possible results). More formally, the result is uncertain if and only if there exist two different situations of how the $$$z$$$ persons vote, that the results are different in the two situations.Tell Nauuo the result or report that the result is uncertain.", "input_spec": "The only line contains three integers $$$x$$$, $$$y$$$, $$$z$$$ ($$$0\\le x,y,z\\le100$$$), corresponding to the number of persons who would upvote, downvote or unknown.", "output_spec": "If there is only one possible result, print the result : \"+\", \"-\" or \"0\". Otherwise, print \"?\" to report that the result is uncertain.", "sample_inputs": ["3 7 0", "2 0 1", "1 1 0", "0 0 1"], "sample_outputs": ["-", "+", "0", "?"], "notes": "NoteIn the first example, Nauuo would definitely get three upvotes and seven downvotes, so the only possible result is \"-\".In the second example, no matter the person unknown downvotes or upvotes, Nauuo would get more upvotes than downvotes. So the only possible result is \"+\".In the third example, Nauuo would definitely get one upvote and one downvote, so the only possible result is \"0\".In the fourth example, if the only one person upvoted, the result would be \"+\", otherwise, the result would be \"-\". There are two possible results, so the result is uncertain."}, "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"nl": {"description": "Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protocol> can equal either \"http\" (without the quotes) or \"ftp\" (without the quotes), <domain> is a non-empty string, consisting of lowercase English letters, the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character \"/\" isn't written. Thus, the address has either two characters \"/\" (the ones that go before the domain), or three (an extra one in front of the context).When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters \":\", \"/\", \".\".Help Vasya to restore the possible address of the recorded Internet resource.", "input_spec": "The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above.", "output_spec": "Print a single line \u2014 the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them.", "sample_inputs": ["httpsunrux", "ftphttprururu"], "sample_outputs": ["http://sun.ru/x", "ftp://http.ru/ruru"], "notes": "NoteIn the second sample there are two more possible answers: \"ftp://httpruru.ru\" and \"ftp://httpru.ru/ru\"."}, "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"nl": {"description": "Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.", "input_spec": "The first line contains single integer n (3\u2009\u2264\u2009n\u2009\u2264\u2009105)\u00a0\u2014 the number of line segments Mahmoud has. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009109)\u00a0\u2014 the lengths of line segments Mahmoud has.", "output_spec": "In the only line print \"YES\" if he can choose exactly three line segments and form a non-degenerate triangle with them, and \"NO\" otherwise.", "sample_inputs": ["5\n1 5 3 2 4", "3\n4 1 2"], "sample_outputs": ["YES", "NO"], "notes": "NoteFor the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle."}, "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"nl": {"description": "Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1,\u2009b2,\u2009...,\u2009bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.Please, help Mashmokh, print these indices.", "input_spec": "The first line of the input contains two space-separated integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1,\u2009b2,\u2009...,\u2009bm\u00a0(1\u2009\u2264\u2009bi\u2009\u2264\u2009n). It is guaranteed that all lights will be turned off after pushing all buttons.", "output_spec": "Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.", "sample_inputs": ["5 4\n4 3 1 2", "5 5\n5 4 3 2 1"], "sample_outputs": ["1 1 3 4 4", "1 2 3 4 5"], "notes": "NoteIn the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off."}, "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"} {"nl": {"description": "Andrey received a postcard from Irina. It contained only the words \"Hello, Andrey!\", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times.For example, consider the following string: This string can encode the message \u00abhappynewyear\u00bb. For this, candy canes and snowflakes should be used as follows: candy cane 1: remove the letter w, snowflake 1: repeat the letter p twice, candy cane 2: leave the letter n, snowflake 2: remove the letter w, snowflake 3: leave the letter e. Please note that the same string can encode different messages. For example, the string above can encode \u00abhayewyar\u00bb, \u00abhapppppynewwwwwyear\u00bb, and other messages.Andrey knows that messages from Irina usually have a length of $$$k$$$ letters. Help him to find out if a given string can encode a message of $$$k$$$ letters, and if so, give an example of such a message.", "input_spec": "The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters \u00ab*\u00bb and \u00ab?\u00bb, meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed $$$200$$$. The second line contains an integer number $$$k$$$ ($$$1 \\leq k \\leq 200$$$), the required message length.", "output_spec": "Print any message of length $$$k$$$ that the given string can encode, or \u00abImpossible\u00bb if such a message does not exist.", "sample_inputs": ["hw?ap*yn?eww*ye*ar\n12", "ab?a\n2", "ab?a\n3", "ababb\n5", "ab?a\n1"], "sample_outputs": ["happynewyear", "aa", "aba", "ababb", "Impossible"], "notes": null}, "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"nl": {"description": "Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called \"Mau-Mau\".To play Mau-Mau, you need a pack of $$$52$$$ cards. Each card has a suit (Diamonds \u2014 D, Clubs \u2014 C, Spades \u2014 S, or Hearts \u2014 H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.", "input_spec": "The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand. Each string is two characters long. The first character denotes the rank and belongs to the set $$$\\{{\\tt 2}, {\\tt 3}, {\\tt 4}, {\\tt 5}, {\\tt 6}, {\\tt 7}, {\\tt 8}, {\\tt 9}, {\\tt T}, {\\tt J}, {\\tt Q}, {\\tt K}, {\\tt A}\\}$$$. The second character denotes the suit and belongs to the set $$$\\{{\\tt D}, {\\tt C}, {\\tt S}, {\\tt H}\\}$$$. All the cards in the input are different.", "output_spec": "If it is possible to play a card from your hand, print one word \"YES\". Otherwise, print \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["AS\n2H 4C TH JH AD", "2H\n3D 4C AC KD AS", "4D\nAS AC AD AH 5H"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.In the second example, you cannot play any card.In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table."}, "src_uid": "699444eb6366ad12bc77e7ac2602d74b"} {"nl": {"description": "The final match of the Berland Football Cup has been held recently. The referee has shown $$$n$$$ yellow cards throughout the match. At the beginning of the match there were $$$a_1$$$ players in the first team and $$$a_2$$$ players in the second team.The rules of sending players off the game are a bit different in Berland football. If a player from the first team receives $$$k_1$$$ yellow cards throughout the match, he can no longer participate in the match \u2014 he's sent off. And if a player from the second team receives $$$k_2$$$ yellow cards, he's sent off. After a player leaves the match, he can no longer receive any yellow cards. Each of $$$n$$$ yellow cards was shown to exactly one player. Even if all players from one team (or even from both teams) leave the match, the game still continues.The referee has lost his records on who has received each yellow card. Help him to determine the minimum and the maximum number of players that could have been thrown out of the game.", "input_spec": "The first line contains one integer $$$a_1$$$ $$$(1 \\le a_1 \\le 1\\,000)$$$ \u2014 the number of players in the first team. The second line contains one integer $$$a_2$$$ $$$(1 \\le a_2 \\le 1\\,000)$$$ \u2014 the number of players in the second team. The third line contains one integer $$$k_1$$$ $$$(1 \\le k_1 \\le 1\\,000)$$$ \u2014 the maximum number of yellow cards a player from the first team can receive (after receiving that many yellow cards, he leaves the game). The fourth line contains one integer $$$k_2$$$ $$$(1 \\le k_2 \\le 1\\,000)$$$ \u2014 the maximum number of yellow cards a player from the second team can receive (after receiving that many yellow cards, he leaves the game). The fifth line contains one integer $$$n$$$ $$$(1 \\le n \\le a_1 \\cdot k_1 + a_2 \\cdot k_2)$$$ \u2014 the number of yellow cards that have been shown during the match.", "output_spec": "Print two integers \u2014 the minimum and the maximum number of players that could have been thrown out of the game.", "sample_inputs": ["2\n3\n5\n1\n8", "3\n1\n6\n7\n25", "6\n4\n9\n10\n89"], "sample_outputs": ["0 4", "4 4", "5 9"], "notes": "NoteIn the first example it could be possible that no player left the game, so the first number in the output is $$$0$$$. The maximum possible number of players that could have been forced to leave the game is $$$4$$$ \u2014 one player from the first team, and three players from the second.In the second example the maximum possible number of yellow cards has been shown $$$(3 \\cdot 6 + 1 \\cdot 7 = 25)$$$, so in any case all players were sent off."}, "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"} {"nl": {"description": "Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without water again, so right now he's really messed up and can't think.Your task is to help him by telling him what to type.", "input_spec": "The first and only line of input contains an integer s (0\u2009\u2264\u2009s\u2009\u2264\u200999), Tavas's score. ", "output_spec": "In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.", "sample_inputs": ["6", "99", "20"], "sample_outputs": ["six", "ninety-nine", "twenty"], "notes": "NoteYou can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals ."}, "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"} {"nl": {"description": "You are given three integers $$$a$$$, $$$b$$$ and $$$x$$$. Your task is to construct a binary string $$$s$$$ of length $$$n = a + b$$$ such that there are exactly $$$a$$$ zeroes, exactly $$$b$$$ ones and exactly $$$x$$$ indices $$$i$$$ (where $$$1 \\le i < n$$$) such that $$$s_i \\ne s_{i + 1}$$$. It is guaranteed that the answer always exists.For example, for the string \"01010\" there are four indices $$$i$$$ such that $$$1 \\le i < n$$$ and $$$s_i \\ne s_{i + 1}$$$ ($$$i = 1, 2, 3, 4$$$). For the string \"111001\" there are two such indices $$$i$$$ ($$$i = 3, 5$$$).Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.", "input_spec": "The first line of the input contains three integers $$$a$$$, $$$b$$$ and $$$x$$$ ($$$1 \\le a, b \\le 100, 1 \\le x < a + b)$$$.", "output_spec": "Print only one string $$$s$$$, where $$$s$$$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.", "sample_inputs": ["2 2 1", "3 3 3", "5 3 6"], "sample_outputs": ["1100", "101100", "01010100"], "notes": "NoteAll possible answers for the first example: 1100; 0011. All possible answers for the second example: 110100; 101100; 110010; 100110; 011001; 001101; 010011; 001011. "}, "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"} {"nl": {"description": "You have a rectangular board of size $$$n\\times m$$$ ($$$n$$$ rows, $$$m$$$ columns). The $$$n$$$ rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and the $$$m$$$ columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The cell at the intersection of row $$$i$$$ and column $$$j$$$ contains the number $$$i^j$$$ ($$$i$$$ raised to the power of $$$j$$$). For example, if $$$n=3$$$ and $$$m=3$$$ the board is as follows: Find the number of distinct integers written on the board.", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1\\le n,m\\le 10^6$$$)\u00a0\u2014 the number of rows and columns of the board.", "output_spec": "Print one integer, the number of distinct integers on the board.", "sample_inputs": ["3 3", "2 4", "4 2"], "sample_outputs": ["7", "5", "6"], "notes": "NoteThe statement shows the board for the first test case. In this case there are $$$7$$$ distinct integers: $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$8$$$, $$$9$$$, and $$$27$$$.In the second test case, the board is as follows: There are $$$5$$$ distinct numbers: $$$1$$$, $$$2$$$, $$$4$$$, $$$8$$$ and $$$16$$$.In the third test case, the board is as follows: There are $$$6$$$ distinct numbers: $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$9$$$ and $$$16$$$."}, "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead"} {"nl": {"description": "Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.One of the popular pranks on Vasya is to force him to compare $$$x^y$$$ with $$$y^x$$$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.Please help Vasya! Write a fast program to compare $$$x^y$$$ with $$$y^x$$$ for Vasya, maybe then other androids will respect him.", "input_spec": "On the only line of input there are two integers $$$x$$$ and $$$y$$$ ($$$1 \\le x, y \\le 10^{9}$$$).", "output_spec": "If $$$x^y < y^x$$$, then print '<' (without quotes). If $$$x^y > y^x$$$, then print '>' (without quotes). If $$$x^y = y^x$$$, then print '=' (without quotes).", "sample_inputs": ["5 8", "10 3", "6 6"], "sample_outputs": [">", "<", "="], "notes": "NoteIn the first example $$$5^8 = 5 \\cdot 5 \\cdot 5 \\cdot 5 \\cdot 5 \\cdot 5 \\cdot 5 \\cdot 5 = 390625$$$, and $$$8^5 = 8 \\cdot 8 \\cdot 8 \\cdot 8 \\cdot 8 = 32768$$$. So you should print '>'.In the second example $$$10^3 = 1000 < 3^{10} = 59049$$$.In the third example $$$6^6 = 46656 = 6^6$$$."}, "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"} {"nl": {"description": "A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for t minutes, the minutes are numbered starting from zero. The first problem had the initial cost of a points, and every minute its cost reduced by da points. The second problem had the initial cost of b points, and every minute this cost reduced by db points. Thus, as soon as the zero minute of the contest is over, the first problem will cost a\u2009-\u2009da points, and the second problem will cost b\u2009-\u2009db points. It is guaranteed that at any moment of the contest each problem has a non-negative cost.Arkady asks you to find out whether Valera could have got exactly x points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number t\u2009-\u20091. Please note that Valera can't submit a solution exactly t minutes after the start of the contest or later.", "input_spec": "The single line of the input contains six integers x,\u2009t,\u2009a,\u2009b,\u2009da,\u2009db (0\u2009\u2264\u2009x\u2009\u2264\u2009600;\u00a01\u2009\u2264\u2009t,\u2009a,\u2009b,\u2009da,\u2009db\u2009\u2264\u2009300) \u2014 Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly. It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, a\u2009-\u2009i\u00b7da\u2009\u2265\u20090 and b\u2009-\u2009i\u00b7db\u2009\u2265\u20090 for all 0\u2009\u2264\u2009i\u2009\u2264\u2009t\u2009-\u20091.", "output_spec": "If Valera could have earned exactly x points at a contest, print \"YES\", otherwise print \"NO\" (without the quotes).", "sample_inputs": ["30 5 20 20 3 5", "10 4 100 5 5 1"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem \u2014 at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points."}, "src_uid": "f98168cdd72369303b82b5a7ac45c3af"} {"nl": {"description": "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\u010dkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vi\u010dkopolis. 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!,\u2009B!). 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!\u2009=\u20091\u00b72\u00b73\u00b7...\u00b7(x\u2009-\u20091)\u00b7x. For example 4!\u2009=\u20091\u00b72\u00b73\u00b74\u2009=\u200924. Recall that GCD(x,\u2009y) 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_spec": "The first and single line contains two integers A and B (1\u2009\u2264\u2009A,\u2009B\u2009\u2264\u2009109,\u2009min(A,\u2009B)\u2009\u2264\u200912).", "output_spec": "Print a single integer denoting the greatest common divisor of integers A! and B!.", "sample_inputs": ["4 3"], "sample_outputs": ["6"], "notes": "NoteConsider the sample.4!\u2009=\u20091\u00b72\u00b73\u00b74\u2009=\u200924. 3!\u2009=\u20091\u00b72\u00b73\u2009=\u20096. The greatest common divisor of integers 24 and 6 is exactly 6."}, "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"} {"nl": {"description": "Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings \"z\", \"aaa\", \"aba\", \"abccba\" are palindromes, but strings \"codeforces\", \"reality\", \"ab\" are not.", "input_spec": "The first and single line contains string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200915).", "output_spec": "Print \"YES\" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or \"NO\" (without quotes) otherwise. ", "sample_inputs": ["abccaa", "abbcca", "abcda"], "sample_outputs": ["YES", "NO", "YES"], "notes": null}, "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"} {"nl": {"description": "Petya is having a party soon, and he has decided to invite his $$$n$$$ friends.He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with $$$k$$$ sheets. That is, each notebook contains $$$k$$$ sheets of either red, green, or blue.Find the minimum number of notebooks that Petya needs to buy to invite all $$$n$$$ of his friends.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\\leq n, k\\leq 10^8$$$)\u00a0\u2014 the number of Petya's friends and the number of sheets in each notebook respectively.", "output_spec": "Print one number\u00a0\u2014 the minimum number of notebooks that Petya needs to buy.", "sample_inputs": ["3 5", "15 6"], "sample_outputs": ["10", "38"], "notes": "NoteIn the first example, we need $$$2$$$ red notebooks, $$$3$$$ green notebooks, and $$$5$$$ blue notebooks.In the second example, we need $$$5$$$ red notebooks, $$$13$$$ green notebooks, and $$$20$$$ blue notebooks."}, "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"} {"nl": {"description": "You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.", "input_spec": "First line contains an integer n (6\u2009\u2264\u2009n\u2009\u2264\u20098) \u2013 the length of the string. Next line contains a string consisting of n characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).", "output_spec": "Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).", "sample_inputs": ["7\nj......", "7\n...feon", "7\n.l.r.o."], "sample_outputs": ["jolteon", "leafeon", "flareon"], "notes": "NoteHere's a set of names in a form you can paste into your solution:[\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"]{\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"}"}, "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"nl": {"description": "Jeff loves regular bracket sequences.Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of nm brackets. Let's number all brackets of this sequence from 0 to nm - 1 from left to right. Jeff knows that he is going to spend ai mod n liters of ink on the i-th bracket of the sequence if he paints it opened and bi mod n liters if he paints it closed.You've got sequences a, b and numbers n, m. What minimum amount of ink will Jeff need to paint a regular bracket sequence of length nm?Operation x mod y means taking the remainder after dividing number x by number y.", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u200920;\u00a01\u2009\u2264\u2009m\u2009\u2264\u2009107; m is even). The next line contains n integers: a0, a1, ..., an\u2009-\u20091 (1\u2009\u2264\u2009ai\u2009\u2264\u200910). The next line contains n integers: b0, b1, ..., bn\u2009-\u20091 (1\u2009\u2264\u2009bi\u2009\u2264\u200910). The numbers are separated by spaces.", "output_spec": "In a single line print the answer to the problem \u2014 the minimum required amount of ink in liters.", "sample_inputs": ["2 6\n1 2\n2 1", "1 10000000\n2\n3"], "sample_outputs": ["12", "25000000"], "notes": "NoteIn the first test the optimal sequence is: ()()()()()(), the required number of ink liters is 12."}, "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601"} {"nl": {"description": "You are given a string s consisting of |s| small english letters.In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.", "input_spec": "The only one line of the input consisting of the string s consisting of |s| (1\u2009\u2264\u2009|s|\u2009\u2264\u2009105) small english letters.", "output_spec": "If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print \u00ab-1\u00bb (without quotes).", "sample_inputs": ["aacceeggiikkmmooqqssuuwwyy", "thereisnoanswer"], "sample_outputs": ["abcdefghijklmnopqrstuvwxyz", "-1"], "notes": null}, "src_uid": "f8ad543d499bcc0da0121a71a26db854"} {"nl": {"description": "One day a highly important task was commissioned to Vasya \u2014 writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ...The expression is regarded as the integral part from dividing number a by number b.The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.Vasya is wondering, what minimum allowable value v can take to let him write not less than n lines of code before he falls asleep.", "input_spec": "The input consists of two integers n and k, separated by spaces \u2014 the size of the program in lines and the productivity reduction coefficient, 1\u2009\u2264\u2009n\u2009\u2264\u2009109, 2\u2009\u2264\u2009k\u2009\u2264\u200910.", "output_spec": "Print the only integer \u2014 the minimum value of v that lets Vasya write the program in one night.", "sample_inputs": ["7 2", "59 9"], "sample_outputs": ["4", "54"], "notes": "NoteIn the first sample the answer is v\u2009=\u20094. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4\u2009+\u20092\u2009+\u20091\u2009=\u20097 lines in a night and complete the task.In the second sample the answer is v\u2009=\u200954. Vasya writes the code in the following portions: 54, 6. The total sum is 54\u2009+\u20096\u2009=\u200960, that's even more than n\u2009=\u200959."}, "src_uid": "41dfc86d341082dd96e089ac5433dc04"} {"nl": {"description": "There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name \"snookah\")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: this list contains all Jinotega's flights in this year (in arbitrary order), Jinotega has only flown from his hometown to a snooker contest and back, after each competition Jinotega flies back home (though they may attend a competition in one place several times), and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location!", "input_spec": "In the first line of input there is a single integer n: the number of Jinotega's flights (1\u2009\u2264\u2009n\u2009\u2264\u2009100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form \"XXX->YYY\", where \"XXX\" is the name of departure airport \"YYY\" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.", "output_spec": "If Jinotega is now at home, print \"home\" (without quotes), otherwise print \"contest\".", "sample_inputs": ["4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP"], "sample_outputs": ["home", "contest"], "notes": "NoteIn the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list."}, "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"nl": {"description": "After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers\u00a0\u2014 the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.Formally, Alyona wants to count the number of pairs of integers (x,\u2009y) such that 1\u2009\u2264\u2009x\u2009\u2264\u2009n, 1\u2009\u2264\u2009y\u2009\u2264\u2009m and equals 0.As usual, Alyona has some troubles and asks you to help.", "input_spec": "The only line of the input contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091\u2009000\u2009000).", "output_spec": "Print the only integer\u00a0\u2014 the number of pairs of integers (x,\u2009y) such that 1\u2009\u2264\u2009x\u2009\u2264\u2009n, 1\u2009\u2264\u2009y\u2009\u2264\u2009m and (x\u2009+\u2009y) is divisible by 5.", "sample_inputs": ["6 12", "11 14", "1 5", "3 8", "5 7", "21 21"], "sample_outputs": ["14", "31", "1", "5", "7", "88"], "notes": "NoteFollowing pairs are suitable in the first sample case: for x\u2009=\u20091 fits y equal to 4 or 9; for x\u2009=\u20092 fits y equal to 3 or 8; for x\u2009=\u20093 fits y equal to 2, 7 or 12; for x\u2009=\u20094 fits y equal to 1, 6 or 11; for x\u2009=\u20095 fits y equal to 5 or 10; for x\u2009=\u20096 fits y equal to 4 or 9. Only the pair (1,\u20094) is suitable in the third sample case."}, "src_uid": "df0879635b59e141c839d9599abd77d2"} {"nl": {"description": "A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).Your task is to find out if a given integer is a triangular number.", "input_spec": "The first line contains the single number n (1\u2009\u2264\u2009n\u2009\u2264\u2009500) \u2014 the given integer.", "output_spec": "If the given integer is a triangular number output YES, otherwise output NO.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["YES", "NO", "YES"], "notes": null}, "src_uid": "587d4775dbd6a41fc9e4b81f71da7301"} {"nl": {"description": "Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n\u2009-\u20091, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m\u2009-\u20091. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.Note that to display number 0 section of the watches is required to have at least one place.Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.", "input_spec": "The first line of the input contains two integers, given in the decimal notation, n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009109)\u00a0\u2014 the number of hours in one day and the number of minutes in one hour, respectively.", "output_spec": "Print one integer in decimal notation\u00a0\u2014 the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.", "sample_inputs": ["2 3", "8 2"], "sample_outputs": ["4", "5"], "notes": "NoteIn the first sample, possible pairs are: (0:\u20091), (0:\u20092), (1:\u20090), (1:\u20092).In the second sample, possible pairs are: (02:\u20091), (03:\u20091), (04:\u20091), (05:\u20091), (06:\u20091)."}, "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c"} {"nl": {"description": "A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011\u00a0\u2014 are quasibinary and numbers 2, 12, 900 are not.You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106).", "output_spec": "In the first line print a single integer k\u00a0\u2014 the minimum number of numbers in the representation of number n as a sum of quasibinary numbers. In the second line print k numbers \u2014 the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.", "sample_inputs": ["9", "32"], "sample_outputs": ["9\n1 1 1 1 1 1 1 1 1", "3\n10 11 11"], "notes": null}, "src_uid": "033068c5e16d25f09039e29c88474275"} {"nl": {"description": "The Little Elephant loves numbers. He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations. Help the Little Elephant to find the described number.", "input_spec": "A single line contains a single integer x (1\u2009\u2264\u2009x\u2009\u2264\u2009109).", "output_spec": "In a single line print an integer \u2014 the answer to the problem.", "sample_inputs": ["1", "10"], "sample_outputs": ["1", "2"], "notes": null}, "src_uid": "ada94770281765f54ab264b4a1ef766e"} {"nl": {"description": "There is an infinite board of square tiles. Initially all tiles are white.Vova has a red marker and a blue marker. Red marker can color $$$a$$$ tiles. Blue marker can color $$$b$$$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should be exactly $$$a$$$ red tiles and exactly $$$b$$$ blue tiles across the board.Vova wants to color such a set of tiles that: they would form a rectangle, consisting of exactly $$$a+b$$$ colored tiles; all tiles of at least one color would also form a rectangle. Here are some examples of correct colorings: Here are some examples of incorrect colorings: Among all correct colorings Vova wants to choose the one with the minimal perimeter. What is the minimal perimeter Vova can obtain?It is guaranteed that there exists at least one correct coloring.", "input_spec": "A single line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^{14}$$$) \u2014 the number of tiles red marker should color and the number of tiles blue marker should color, respectively.", "output_spec": "Print a single integer \u2014 the minimal perimeter of a colored rectangle Vova can obtain by coloring exactly $$$a$$$ tiles red and exactly $$$b$$$ tiles blue. It is guaranteed that there exists at least one correct coloring.", "sample_inputs": ["4 4", "3 9", "9 3", "3 6", "506 2708"], "sample_outputs": ["12", "14", "14", "12", "3218"], "notes": "NoteThe first four examples correspond to the first picture of the statement.Note that for there exist multiple correct colorings for all of the examples.In the first example you can also make a rectangle with sides $$$1$$$ and $$$8$$$, though its perimeter will be $$$18$$$ which is greater than $$$8$$$.In the second example you can make the same resulting rectangle with sides $$$3$$$ and $$$4$$$, but red tiles will form the rectangle with sides $$$1$$$ and $$$3$$$ and blue tiles will form the rectangle with sides $$$3$$$ and $$$3$$$."}, "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1"} {"nl": {"description": "$$$k$$$ people want to split $$$n$$$ candies between them. Each candy should be given to exactly one of them or be thrown away.The people are numbered from $$$1$$$ to $$$k$$$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $$$x$$$ and then give the first $$$x$$$ candies to himself, the next $$$x$$$ candies to the second person, the next $$$x$$$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $$$x$$$) will be thrown away.Arkady can't choose $$$x$$$ greater than $$$M$$$ as it is considered greedy. Also, he can't choose such a small $$$x$$$ that some person will receive candies more than $$$D$$$ times, as it is considered a slow splitting.Please find what is the maximum number of candies Arkady can receive by choosing some valid $$$x$$$.", "input_spec": "The only line contains four integers $$$n$$$, $$$k$$$, $$$M$$$ and $$$D$$$ ($$$2 \\le n \\le 10^{18}$$$, $$$2 \\le k \\le n$$$, $$$1 \\le M \\le n$$$, $$$1 \\le D \\le \\min{(n, 1000)}$$$, $$$M \\cdot D \\cdot k \\ge n$$$)\u00a0\u2014 the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.", "output_spec": "Print a single integer\u00a0\u2014 the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $$$x$$$.", "sample_inputs": ["20 4 5 2", "30 9 4 1"], "sample_outputs": ["8", "4"], "notes": "NoteIn the first example Arkady should choose $$$x = 4$$$. He will give $$$4$$$ candies to himself, $$$4$$$ candies to the second person, $$$4$$$ candies to the third person, then $$$4$$$ candies to the fourth person and then again $$$4$$$ candies to himself. No person is given candies more than $$$2$$$ times, and Arkady receives $$$8$$$ candies in total.Note that if Arkady chooses $$$x = 5$$$, he will receive only $$$5$$$ candies, and if he chooses $$$x = 3$$$, he will receive only $$$3 + 3 = 6$$$ candies as well as the second person, the third and the fourth persons will receive $$$3$$$ candies, and $$$2$$$ candies will be thrown away. He can't choose $$$x = 1$$$ nor $$$x = 2$$$ because in these cases he will receive candies more than $$$2$$$ times.In the second example Arkady has to choose $$$x = 4$$$, because any smaller value leads to him receiving candies more than $$$1$$$ time."}, "src_uid": "ac2e795cd44061db8da13e3947ba791b"} {"nl": {"description": "Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words \"WUB\" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including \"WUB\", in one string and plays the song at the club.For example, a song with words \"I AM X\" can transform into a dubstep remix as \"WUBWUBIWUBAMWUBWUBX\" and cannot transform into \"WUBWUBIAMWUBX\".Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.", "input_spec": "The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring \"WUB\" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.", "output_spec": "Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.", "sample_inputs": ["WUBWUBABCWUB", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB"], "sample_outputs": ["ABC", "WE ARE THE CHAMPIONS MY FRIEND"], "notes": "NoteIn the first sample: \"WUBWUBABCWUB\" = \"WUB\" + \"WUB\" + \"ABC\" + \"WUB\". That means that the song originally consisted of a single word \"ABC\", and all words \"WUB\" were added by Vasya.In the second sample Vasya added a single word \"WUB\" between all neighbouring words, in the beginning and in the end, except for words \"ARE\" and \"THE\" \u2014 between them Vasya added two \"WUB\"."}, "src_uid": "edede580da1395fe459a480f6a0a548d"} {"nl": {"description": "Bizon the Champion isn't just a bison. He also is a favorite of the \"Bizons\" team.At a competition the \"Bizons\" got the following problem: \"You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t\". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more. Bizon the Champion wonders whether the \"Bizons\" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.", "input_spec": "The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.", "output_spec": "In the single line print the answer to the problem. Print \"need tree\" (without the quotes) if word s cannot be transformed into word t even with use of both suffix array and suffix automaton. Print \"automaton\" (without the quotes) if you need only the suffix automaton to solve the problem. Print \"array\" (without the quotes) if you need only the suffix array to solve the problem. Print \"both\" (without the quotes), if you need both data structures to solve the problem. It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.", "sample_inputs": ["automaton\ntomat", "array\narary", "both\nhot", "need\ntree"], "sample_outputs": ["automaton", "array", "both", "need tree"], "notes": "NoteIn the third sample you can act like that: first transform \"both\" into \"oth\" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get \"hot\"."}, "src_uid": "edb9d51e009a59a340d7d589bb335c14"} {"nl": {"description": "Polycarpus has got n candies and m friends (n\u2009\u2265\u2009m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.", "input_spec": "The single line of the input contains a pair of space-separated positive integers n, m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100;n\u2009\u2265\u2009m) \u2014 the number of candies and the number of Polycarpus's friends.", "output_spec": "Print the required sequence a1,\u2009a2,\u2009...,\u2009am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.", "sample_inputs": ["12 3", "15 4", "18 7"], "sample_outputs": ["4 4 4", "3 4 4 4", "2 2 2 3 3 3 3"], "notes": "NotePrint ai in any order, separate the numbers by spaces."}, "src_uid": "0b2c1650979a9931e00ffe32a70e3c23"} {"nl": {"description": "Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:\u20092:\u20094. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits\u00a0\u2014 lemons, apples and pears\u00a0\u2014 should be put in the compote as whole fruits.Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. ", "input_spec": "The first line contains the positive integer a (1\u2009\u2264\u2009a\u2009\u2264\u20091000)\u00a0\u2014 the number of lemons Nikolay has. The second line contains the positive integer b (1\u2009\u2264\u2009b\u2009\u2264\u20091000)\u00a0\u2014 the number of apples Nikolay has. The third line contains the positive integer c (1\u2009\u2264\u2009c\u2009\u2264\u20091000)\u00a0\u2014 the number of pears Nikolay has.", "output_spec": "Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.", "sample_inputs": ["2\n5\n7", "4\n7\n13", "2\n3\n2"], "sample_outputs": ["7", "21", "0"], "notes": "NoteIn the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1\u2009+\u20092\u2009+\u20094\u2009=\u20097.In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3\u2009+\u20096\u2009+\u200912\u2009=\u200921.In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. "}, "src_uid": "82a4a60eac90765fb62f2a77d2305c01"} {"nl": {"description": "Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that: 1\u2009\u2264\u2009a\u2009\u2264\u2009n. If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?", "input_spec": "The only line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109), the number at the beginning of the game.", "output_spec": "Output \"Mahmoud\" (without quotes) if Mahmoud wins and \"Ehab\" (without quotes) otherwise.", "sample_inputs": ["1", "2"], "sample_outputs": ["Ehab", "Mahmoud"], "notes": "NoteIn the first sample, Mahmoud can't choose any integer a initially because there is no positive even integer less than or equal to 1 so Ehab wins.In the second sample, Mahmoud has to choose a\u2009=\u20092 and subtract it from n. It's Ehab's turn and n\u2009=\u20090. There is no positive odd integer less than or equal to 0 so Mahmoud wins."}, "src_uid": "5e74750f44142624e6da41d4b35beb9a"} {"nl": {"description": "On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k\u2009=\u20091 the grasshopper can jump to a neighboring cell only, and if k\u2009=\u20092 the grasshopper can jump over a single cell.Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.", "input_spec": "The first line of the input contains two integers n and k (2\u2009\u2264\u2009n\u2009\u2264\u2009100, 1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009-\u20091)\u00a0\u2014 the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.", "output_spec": "If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print \"YES\" (without quotes) in the only line of the input. Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["5 2\n#G#T#", "6 1\nT....G", "7 3\nT..#..G", "6 2\n..GT.."], "sample_outputs": ["YES", "YES", "NO", "NO"], "notes": "NoteIn the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free\u00a0\u2014 he can get there by jumping left 5 times.In the third sample, the grasshopper can't make a single jump.In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect."}, "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"nl": {"description": "Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word \"hello\". For example, if Vasya types the word \"ahhellllloou\", it will be considered that he said hello, and if he types \"hlelo\", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.", "input_spec": "The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.", "output_spec": "If Vasya managed to say hello, print \"YES\", otherwise print \"NO\".", "sample_inputs": ["ahhellllloou", "hlelo"], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"nl": {"description": "A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs Wr grams and each blue candy weighs Wb grams. Eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.", "input_spec": "The single line contains five integers C,\u2009Hr,\u2009Hb,\u2009Wr,\u2009Wb (1\u2009\u2264\u2009C,\u2009Hr,\u2009Hb,\u2009Wr,\u2009Wb\u2009\u2264\u2009109).", "output_spec": "Print a single integer \u2014 the maximum number of joy units that Om Nom can get.", "sample_inputs": ["10 3 5 2 3"], "sample_outputs": ["16"], "notes": "NoteIn the sample test Om Nom can eat two candies of each type and thus get 16 joy units."}, "src_uid": "eb052ca12ca293479992680581452399"} {"nl": {"description": "A new delivery of clothing has arrived today to the clothing store. This delivery consists of $$$a$$$ ties, $$$b$$$ scarves, $$$c$$$ vests and $$$d$$$ jackets.The store does not sell single clothing items \u2014 instead, it sells suits of two types: a suit of the first type consists of one tie and one jacket; a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs $$$e$$$ coins, and each suit of the second type costs $$$f$$$ coins.Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).", "input_spec": "The first line contains one integer $$$a$$$ $$$(1 \\le a \\le 100\\,000)$$$ \u2014 the number of ties. The second line contains one integer $$$b$$$ $$$(1 \\le b \\le 100\\,000)$$$ \u2014 the number of scarves. The third line contains one integer $$$c$$$ $$$(1 \\le c \\le 100\\,000)$$$ \u2014 the number of vests. The fourth line contains one integer $$$d$$$ $$$(1 \\le d \\le 100\\,000)$$$ \u2014 the number of jackets. The fifth line contains one integer $$$e$$$ $$$(1 \\le e \\le 1\\,000)$$$ \u2014 the cost of one suit of the first type. The sixth line contains one integer $$$f$$$ $$$(1 \\le f \\le 1\\,000)$$$ \u2014 the cost of one suit of the second type.", "output_spec": "Print one integer \u2014 the maximum total cost of some set of suits that can be composed from the delivered items. ", "sample_inputs": ["4\n5\n6\n3\n1\n2", "12\n11\n13\n20\n4\n6", "17\n14\n5\n21\n15\n17"], "sample_outputs": ["6", "102", "325"], "notes": "NoteIt is possible to compose three suits of the second type in the first example, and their total cost will be $$$6$$$. Since all jackets will be used, it's impossible to add anything to this set.The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $$$9 \\cdot 4 + 11 \\cdot 6 = 102$$$."}, "src_uid": "84d9e7e9c9541d997e6573edb421ae0a"} {"nl": {"description": "Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP \u2014 with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.", "input_spec": "The first line contains a word s \u2014 it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.", "output_spec": "Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.", "sample_inputs": ["HoUse", "ViP", "maTRIx"], "sample_outputs": ["house", "VIP", "matrix"], "notes": null}, "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"nl": {"description": "In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n\u2009\u00d7\u2009m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.Nobody wins the game \u2014 Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.", "input_spec": "The first and only line contains three integers: n,\u2009m,\u2009k (1\u2009\u2264\u2009n,\u2009m,\u2009k\u2009\u2264\u20091000).", "output_spec": "Print the single number \u2014 the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["3 3 1", "4 4 1", "6 7 2"], "sample_outputs": ["1", "9", "75"], "notes": "NoteTwo ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.In the first sample Anna, who performs her first and only move, has only one possible action plan \u2014 insert a 1\u2009\u00d7\u20091 square inside the given 3\u2009\u00d7\u20093 square.In the second sample Anna has as much as 9 variants: 4 ways to paint a 1\u2009\u00d7\u20091 square, 2 ways to insert a 1\u2009\u00d7\u20092 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2\u2009\u00d7\u20092 square."}, "src_uid": "309d2d46086d526d160292717dfef308"} {"nl": {"description": "As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.", "input_spec": "The first line of input contains single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of days. The second line contains a string of length n consisting of only capital 'S' and 'F' letters. If the i-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.", "output_spec": "Print \"YES\" if you flew more times from Seattle to San Francisco, and \"NO\" otherwise. You can print each letter in any case (upper or lower).", "sample_inputs": ["4\nFSSF", "2\nSF", "10\nFFFFFFFFFF", "10\nSSFFSFFSFF"], "sample_outputs": ["NO", "YES", "NO", "YES"], "notes": "NoteIn the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is \"NO\".In the second example you just flew from Seattle to San Francisco, so the answer is \"YES\".In the third example you stayed the whole period in San Francisco, so the answer is \"NO\".In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of \u03c0 in binary representation. Not very useful information though."}, "src_uid": "ab8a2070ea758d118b3c09ee165d9517"} {"nl": {"description": "Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if and , where k is some integer number in range [1,\u2009a].By we denote the quotient of integer division of x and y. By we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.The answer may be large, so please print its remainder modulo 1\u2009000\u2009000\u2009007 (109\u2009+\u20097). Can you compute it faster than Dreamoon?", "input_spec": "The single line of the input contains two integers a, b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009107).", "output_spec": "Print a single integer representing the answer modulo 1\u2009000\u2009000\u2009007 (109\u2009+\u20097).", "sample_inputs": ["1 1", "2 2"], "sample_outputs": ["0", "8"], "notes": "NoteFor the first sample, there are no nice integers because is always zero.For the second sample, the set of nice integers is {3,\u20095}."}, "src_uid": "cd351d1190a92d094b2d929bf1e5c44f"} {"nl": {"description": "Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.For example, if Polycarp has got six coins represented as an array $$$a = [1, 2, 4, 3, 3, 2]$$$, he can distribute the coins into two pockets as follows: $$$[1, 2, 3], [2, 3, 4]$$$.Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of coins. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$) \u2014 values of coins.", "output_spec": "Print only one integer \u2014 the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.", "sample_inputs": ["6\n1 2 4 3 3 2", "1\n100"], "sample_outputs": ["2", "1"], "notes": null}, "src_uid": "f30329023e84b4c50b1b118dc98ae73c"} {"nl": {"description": "The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).", "input_spec": "The first line contains the chessboard coordinates of square s, the second line \u2014 of square t. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.", "output_spec": "In the first line print n \u2014 minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. ", "sample_inputs": ["a8\nh1"], "sample_outputs": ["7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"], "notes": null}, "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"nl": {"description": "Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest. Formally, for a given integer n you have to find the number of such triples (a,\u2009b,\u2009c), that: 1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009c\u2009\u2264\u2009n; , where denotes the bitwise xor of integers x and y. (a,\u2009b,\u2009c) form a non-degenerate (with strictly positive area) triangle. ", "input_spec": "The only line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092500).", "output_spec": "Print the number of xorangles of order n.", "sample_inputs": ["6", "10"], "sample_outputs": ["1", "2"], "notes": "NoteThe only xorangle in the first sample is (3,\u20095,\u20096)."}, "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"nl": {"description": "Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?", "input_spec": "The single line contains two space separated integers n, m (0\u2009<\u2009n\u2009\u2264\u200910000,\u20091\u2009<\u2009m\u2009\u2264\u200910).", "output_spec": "Print a single integer \u2014 the minimal number of moves being a multiple of m. If there is no way he can climb satisfying condition print \u2009-\u20091 instead.", "sample_inputs": ["10 2", "3 5"], "sample_outputs": ["6", "-1"], "notes": "NoteFor the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5."}, "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"} {"nl": {"description": "Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.Ari draws a regular convex polygon on the floor and numbers it's vertices 1,\u20092,\u2009...,\u2009n in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,\u20093,\u2009...,\u2009n (in this particular order). And then she puts a walnut in each region inside the polygon. Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?", "input_spec": "The first and only line of the input contains a single integer n (3\u2009\u2264\u2009n\u2009\u2264\u200954321) - the number of vertices of the regular polygon drawn by Ari.", "output_spec": "Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.", "sample_inputs": ["5", "3"], "sample_outputs": ["9", "1"], "notes": "NoteOne of the possible solutions for the first sample is shown on the picture above."}, "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"} {"nl": {"description": "Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations.", "input_spec": "First line contains four integers separated by space: 0\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d\u2009\u2264\u20091000 \u2014 the original numbers. Second line contains three signs ('+' or '*' each) separated by space \u2014 the sequence of the operations in the order of performing. ('+' stands for addition, '*' \u2014 multiplication)", "output_spec": "Output one integer number \u2014 the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).", "sample_inputs": ["1 1 1 1\n+ + *", "2 2 2 2\n* * +", "1 2 3 4\n* + +"], "sample_outputs": ["3", "8", "9"], "notes": null}, "src_uid": "7a66fae63d9b27e444d84447012e484c"} {"nl": {"description": "Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print \u2009-\u20091.", "input_spec": "The single line contains two numbers, n and t (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 2\u2009\u2264\u2009t\u2009\u2264\u200910) \u2014 the length of the number and the number it should be divisible by.", "output_spec": "Print one such positive number without leading zeroes, \u2014 the answer to the problem, or \u2009-\u20091, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.", "sample_inputs": ["3 2"], "sample_outputs": ["712"], "notes": null}, "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"nl": {"description": "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_spec": "The first line contains single integer $$$n$$$ ($$$3 \\le n \\le 500$$$) \u2014 the number of vertices in the regular polygon.", "output_spec": "Print one integer \u2014 the minimum weight among all triangulations of the given polygon.", "sample_inputs": ["3", "4"], "sample_outputs": ["6", "18"], "notes": "NoteAccording to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $$$P$$$ into a set of triangles, i.\u2009e., 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$$$."}, "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"nl": {"description": "Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D\u00a0mod\u00a0M[i]\u2009=\u2009R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo. ", "input_spec": "The first line of input contains a single integer N (1\u2009\u2264\u2009N\u2009\u2264\u200916). The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i]\u2009<\u2009M[i].", "output_spec": "Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10\u2009-\u20094.", "sample_inputs": ["1\n2\n0", "2\n2 3\n1 0"], "sample_outputs": ["0.500000", "0.666667"], "notes": null}, "src_uid": "14b69f42bc192ea472e82f3a3209f1c1"} {"nl": {"description": "One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.", "input_spec": "Input data contains the only number n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Output the only number \u2014 answer to the problem.", "sample_inputs": ["10"], "sample_outputs": ["2"], "notes": "NoteFor n = 10 the answer includes numbers 1 and 10."}, "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"} {"nl": {"description": "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_spec": "The first line of the input contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7109) \u2014 the length of Pasha's stick.", "output_spec": "The output should contain a single integer\u00a0\u2014 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. ", "sample_inputs": ["6", "20"], "sample_outputs": ["1", "4"], "notes": "NoteThere 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."}, "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"} {"nl": {"description": "Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can show his parents a timetable s\u0441hedule with d numbers, where each number s\u0441hedulei stands for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should equal to sumTime.", "input_spec": "The first input line contains two integer numbers d,\u2009sumTime (1\u2009\u2264\u2009d\u2009\u2264\u200930,\u20090\u2009\u2264\u2009sumTime\u2009\u2264\u2009240) \u2014 the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbers minTimei,\u2009maxTimei (0\u2009\u2264\u2009minTimei\u2009\u2264\u2009maxTimei\u2009\u2264\u20098), separated by a space \u2014 minimum and maximum amount of hours that Peter could spent in the i-th day.", "output_spec": "In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers \u2014 amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.", "sample_inputs": ["1 48\n5 7", "2 5\n0 1\n3 5"], "sample_outputs": ["NO", "YES\n1 4"], "notes": null}, "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"} {"nl": {"description": "Panic is rising in the committee for doggo standardization\u00a0\u2014 the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color $$$x$$$ such that there are currently at least two puppies of color $$$x$$$ and recolor all puppies of the color $$$x$$$ into some arbitrary color $$$y$$$. Luckily, this operation can be applied multiple times (including zero).For example, if the number of puppies is $$$7$$$ and their colors are represented as the string \"abababc\", then in one operation Slava can get the results \"zbzbzbc\", \"bbbbbbc\", \"aaaaaac\", \"acacacc\" and others. However, if the current color sequence is \"abababc\", then he can't choose $$$x$$$='c' right now, because currently only one puppy has the color 'c'.Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$)\u00a0\u2014 the number of puppies. The second line contains a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters, where the $$$i$$$-th symbol denotes the $$$i$$$-th puppy's color.", "output_spec": "If it's possible to recolor all puppies into one color, print \"Yes\". Otherwise print \"No\". Output the answer without quotation signs.", "sample_inputs": ["6\naabddc", "3\nabc", "3\njjj"], "sample_outputs": ["Yes", "No", "Yes"], "notes": "NoteIn the first example Slava can perform the following steps: take all puppies of color 'a' (a total of two) and recolor them into 'b'; take all puppies of color 'd' (a total of two) and recolor them into 'c'; take all puppies of color 'b' (three puppies for now) and recolor them into 'c'. In the second example it's impossible to recolor any of the puppies.In the third example all the puppies' colors are the same; thus there's no need to recolor anything."}, "src_uid": "6b22e93f7e429693dcfe3c099346dcda"} {"nl": {"description": "Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers.Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 12$$$) \u2014 the number of pairs the first participant communicated to the second and vice versa. The second line contains $$$n$$$ pairs of integers, each between $$$1$$$ and $$$9$$$, \u2014 pairs of numbers communicated from first participant to the second. The third line contains $$$m$$$ pairs of integers, each between $$$1$$$ and $$$9$$$, \u2014 pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair $$$(1,2)$$$, there will be no pair $$$(2,1)$$$ within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number.", "output_spec": "If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print $$$0$$$. Otherwise print $$$-1$$$.", "sample_inputs": ["2 2\n1 2 3 4\n1 5 3 4", "2 2\n1 2 3 4\n1 5 6 4", "2 3\n1 2 4 5\n1 2 1 3 2 3"], "sample_outputs": ["1", "0", "-1"], "notes": "NoteIn the first example the first participant communicated pairs $$$(1,2)$$$ and $$$(3,4)$$$, and the second communicated $$$(1,5)$$$, $$$(3,4)$$$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $$$(3,4)$$$. Thus, the first participant has $$$(1,2)$$$ and the second has $$$(1,5)$$$, and at this point you already know the shared number is $$$1$$$.In the second example either the first participant has $$$(1,2)$$$ and the second has $$$(1,5)$$$, or the first has $$$(3,4)$$$ and the second has $$$(6,4)$$$. In the first case both of them know the shared number is $$$1$$$, in the second case both of them know the shared number is $$$4$$$. You don't have enough information to tell $$$1$$$ and $$$4$$$ apart.In the third case if the first participant was given $$$(1,2)$$$, they don't know what the shared number is, since from their perspective the second participant might have been given either $$$(1,3)$$$, in which case the shared number is $$$1$$$, or $$$(2,3)$$$, in which case the shared number is $$$2$$$. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is $$$-1$$$."}, "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"} {"nl": {"description": "A divisor tree is a rooted tree that meets the following conditions: Each vertex of the tree contains a positive integer number. The numbers written in the leaves of the tree are prime numbers. For any inner vertex, the number within it is equal to the product of the numbers written in its children. Manao has n distinct integers a1,\u2009a2,\u2009...,\u2009an. He tries to build a divisor tree which contains each of these numbers. That is, for each ai, there should be at least one vertex in the tree which contains ai. Manao loves compact style, but his trees are too large. Help Manao determine the minimum possible number of vertices in the divisor tree sought.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20098). The second line contains n distinct space-separated integers ai (2\u2009\u2264\u2009ai\u2009\u2264\u20091012).", "output_spec": "Print a single integer \u2014 the minimum number of vertices in the divisor tree that contains each of the numbers ai.", "sample_inputs": ["2\n6 10", "4\n6 72 8 4", "1\n7"], "sample_outputs": ["7", "12", "1"], "notes": "NoteSample 1. The smallest divisor tree looks this way: Sample 2. In this case you can build the following divisor tree: Sample 3. Note that the tree can consist of a single vertex."}, "src_uid": "52b8b6c68518d5129272b8c56e5b7662"} {"nl": {"description": "One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.", "input_spec": "The first (and the only) input line contains integer number w (1\u2009\u2264\u2009w\u2009\u2264\u2009100) \u2014 the weight of the watermelon bought by the boys.", "output_spec": "Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.", "sample_inputs": ["8"], "sample_outputs": ["YES"], "notes": "NoteFor example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant \u2014 two parts of 4 and 4 kilos)."}, "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"} {"nl": {"description": "Mislove had an array $$$a_1$$$, $$$a_2$$$, $$$\\cdots$$$, $$$a_n$$$ of $$$n$$$ positive integers, but he has lost it. He only remembers the following facts about it: The number of different numbers in the array is not less than $$$l$$$ and is not greater than $$$r$$$; For each array's element $$$a_i$$$ either $$$a_i = 1$$$ or $$$a_i$$$ is even and there is a number $$$\\dfrac{a_i}{2}$$$ in the array.For example, if $$$n=5$$$, $$$l=2$$$, $$$r=3$$$ then an array could be $$$[1,2,2,4,4]$$$ or $$$[1,1,1,1,2]$$$; but it couldn't be $$$[1,2,2,4,8]$$$ because this array contains $$$4$$$ different numbers; it couldn't be $$$[1,2,2,3,3]$$$ because $$$3$$$ is odd and isn't equal to $$$1$$$; and it couldn't be $$$[1,1,2,2,16]$$$ because there is a number $$$16$$$ in the array but there isn't a number $$$\\frac{16}{2} = 8$$$.According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array. ", "input_spec": "The only input line contains three integers $$$n$$$, $$$l$$$ and $$$r$$$ ($$$1 \\leq n \\leq 1\\,000$$$, $$$1 \\leq l \\leq r \\leq \\min(n, 20)$$$)\u00a0\u2014 an array's size, the minimal number and the maximal number of distinct elements in an array.", "output_spec": "Output two numbers\u00a0\u2014 the minimal and the maximal possible sums of all elements in an array.", "sample_inputs": ["4 2 2", "5 1 5"], "sample_outputs": ["5 7", "5 31"], "notes": "NoteIn the first example, an array could be the one of the following: $$$[1,1,1,2]$$$, $$$[1,1,2,2]$$$ or $$$[1,2,2,2]$$$. In the first case the minimal sum is reached and in the last case the maximal sum is reached.In the second example, the minimal sum is reached at the array $$$[1,1,1,1,1]$$$, and the maximal one is reached at the array $$$[1,2,4,8,16]$$$."}, "src_uid": "ce220726392fb0cacf0ec44a7490084a"} {"nl": {"description": "There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number n.The presenter has m chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number i gets i chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given n and m how many chips the presenter will get in the end.", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u200950, 1\u2009\u2264\u2009m\u2009\u2264\u2009104) \u2014 the number of walruses and the number of chips correspondingly.", "output_spec": "Print the number of chips the presenter ended up with.", "sample_inputs": ["4 11", "17 107", "3 8"], "sample_outputs": ["0", "2", "1"], "notes": "NoteIn the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip."}, "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"} {"nl": {"description": "Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action \u2014 multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix k.", "input_spec": "The first line contains a single integer k (2\u2009\u2264\u2009k\u2009\u2264\u200910) \u2014 the radix of the system.", "output_spec": "Output the multiplication table for the system of notations with the radix k. The table must contain k\u2009-\u20091 rows and k\u2009-\u20091 columns. The element on the crossing of the i-th row and the j-th column is equal to the product of i and j in the system of notations with the radix k. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity).", "sample_inputs": ["10", "3"], "sample_outputs": ["1 2 3 4 5 6 7 8 9\n2 4 6 8 10 12 14 16 18\n3 6 9 12 15 18 21 24 27\n4 8 12 16 20 24 28 32 36\n5 10 15 20 25 30 35 40 45\n6 12 18 24 30 36 42 48 54\n7 14 21 28 35 42 49 56 63\n8 16 24 32 40 48 56 64 72\n9 18 27 36 45 54 63 72 81", "1 2\n2 11"], "notes": null}, "src_uid": "a705144ace798d6b41068aa284d99050"} {"nl": {"description": "After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known \"Heroes of Might & Magic\". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. ", "input_spec": "The only line of the input contains one integer n (0\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Output one integer \u2014 the number of hexagons situated not farther than n cells away from a given cell.", "sample_inputs": ["2"], "sample_outputs": ["19"], "notes": null}, "src_uid": "c046895a90f2e1381a7c1867020453bd"} {"nl": {"description": "Reziba has many magic gems. Each magic gem can be split into $$$M$$$ normal gems. The amount of space each magic (and normal) gem takes is $$$1$$$ unit. A normal gem cannot be split.Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is $$$N$$$ units. If a magic gem is chosen and split, it takes $$$M$$$ units of space (since it is split into $$$M$$$ gems); if a magic gem is not split, it takes $$$1$$$ unit.How many different configurations of the resulting set of gems can Reziba have, such that the total amount of space taken is $$$N$$$ units? Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$). Two configurations are considered different if the number of magic gems Reziba takes to form them differs, or the indices of gems Reziba has to split differ.", "input_spec": "The input contains a single line consisting of $$$2$$$ integers $$$N$$$ and $$$M$$$ ($$$1 \\le N \\le 10^{18}$$$, $$$2 \\le M \\le 100$$$).", "output_spec": "Print one integer, the total number of configurations of the resulting set of gems, given that the total amount of space taken is $$$N$$$ units. Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$).", "sample_inputs": ["4 2", "3 2"], "sample_outputs": ["5", "3"], "notes": "NoteIn the first example each magic gem can split into $$$2$$$ normal gems, and we know that the total amount of gems are $$$4$$$.Let $$$1$$$ denote a magic gem, and $$$0$$$ denote a normal gem.The total configurations you can have is: $$$1 1 1 1$$$ (None of the gems split); $$$0 0 1 1$$$ (First magic gem splits into $$$2$$$ normal gems); $$$1 0 0 1$$$ (Second magic gem splits into $$$2$$$ normal gems); $$$1 1 0 0$$$ (Third magic gem splits into $$$2$$$ normal gems); $$$0 0 0 0$$$ (First and second magic gems split into total $$$4$$$ normal gems). Hence, answer is $$$5$$$."}, "src_uid": "e7b9eec21d950f5d963ff50619c6f119"} {"nl": {"description": "In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Arkady's choice) by ai. Each extension can't be used more than once, the extensions can be used in any order.Now Arkady's field has size h\u2009\u00d7\u2009w. He wants to enlarge it so that it is possible to place a rectangle of size a\u2009\u00d7\u2009b on it (along the width or along the length, with sides parallel to the field sides). Find the minimum number of extensions needed to reach Arkady's goal.", "input_spec": "The first line contains five integers a, b, h, w and n (1\u2009\u2264\u2009a,\u2009b,\u2009h,\u2009w,\u2009n\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (2\u2009\u2264\u2009ai\u2009\u2264\u2009100\u2009000), where ai equals the integer a side multiplies by when the i-th extension is applied.", "output_spec": "Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.", "sample_inputs": ["3 3 2 4 4\n2 5 4 10", "3 3 3 3 5\n2 3 5 4 2", "5 5 1 2 3\n2 2 3", "3 4 1 1 3\n2 3 2"], "sample_outputs": ["1", "0", "-1", "3"], "notes": "NoteIn the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field."}, "src_uid": "18cb436618b2b85c3f5dc348c80882d5"} {"nl": {"description": "On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings\u00a0\u2014 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.", "input_spec": "The first line of the input contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091\u2009000\u2009000)\u00a0\u2014 the number of days in a year on Mars.", "output_spec": "Print two integers\u00a0\u2014 the minimum possible and the maximum possible number of days off per year on Mars.", "sample_inputs": ["14", "2"], "sample_outputs": ["4 4", "0 2"], "notes": "NoteIn the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off."}, "src_uid": "8152daefb04dfa3e1a53f0a501544c35"} {"nl": {"description": "Polycarp is going to participate in the contest. It starts at $$$h_1:m_1$$$ and ends at $$$h_2:m_2$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \\% 2 = m_2 \\% 2$$$, where $$$x \\% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from $$$10:00$$$ to $$$11:00$$$ then the answer is $$$10:30$$$, if the contest lasts from $$$11:10$$$ to $$$11:12$$$ then the answer is $$$11:11$$$.", "input_spec": "The first line of the input contains two integers $$$h_1$$$ and $$$m_1$$$ in the format hh:mm. The second line of the input contains two integers $$$h_2$$$ and $$$m_2$$$ in the same format (hh:mm). It is guaranteed that $$$0 \\le h_1, h_2 \\le 23$$$ and $$$0 \\le m_1, m_2 \\le 59$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \\% 2 = m_2 \\% 2$$$, where $$$x \\% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.", "output_spec": "Print two integers $$$h_3$$$ and $$$m_3$$$ ($$$0 \\le h_3 \\le 23, 0 \\le m_3 \\le 59$$$) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.", "sample_inputs": ["10:00\n11:00", "11:10\n11:12", "01:02\n03:02"], "sample_outputs": ["10:30", "11:11", "02:02"], "notes": null}, "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"} {"nl": {"description": "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_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 500$$$) \u2014 the length of string $$$s$$$. The second line contains the string $$$s$$$ ($$$|s| = n$$$) consisting of lowercase Latin letters.", "output_spec": "Output a single integer \u2014 the minimal number of operation to delete string $$$s$$$.", "sample_inputs": ["5\nabaca", "8\nabcddcba"], "sample_outputs": ["3", "4"], "notes": null}, "src_uid": "516a89f4d1ae867fc1151becd92471e6"} {"nl": {"description": "In Berland each high school student is characterized by academic performance \u2014 integer value between 1 and 5.In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known \u2014 integer value between 1 and 5.The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.", "input_spec": "The first line of the input contains integer number n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 number of students in both groups. The second line contains sequence of integer numbers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u20095), where ai is academic performance of the i-th student of the group A. The third line contains sequence of integer numbers b1,\u2009b2,\u2009...,\u2009bn (1\u2009\u2264\u2009bi\u2009\u2264\u20095), where bi is academic performance of the i-th student of the group B.", "output_spec": "Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.", "sample_inputs": ["4\n5 4 4 4\n5 5 4 5", "6\n1 1 1 1 1 1\n5 5 5 5 5 5", "1\n5\n3", "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1"], "sample_outputs": ["1", "3", "-1", "4"], "notes": null}, "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"} {"nl": {"description": "One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: \"Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people\"Igor just couldn't get why the required minimum is 6 people. \"Well, that's the same for five people, too!\" \u2014 he kept on repeating in his mind. \u2014 \"Let's take, say, Max, Ilya, Vova \u2014 here, they all know each other! And now let's add Dima and Oleg to Vova \u2014 none of them is acquainted with each other! Now, that math is just rubbish!\"Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people.", "input_spec": "The first line contains an integer m (0\u2009\u2264\u2009m\u2009\u2264\u200910), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u20095;ai\u2009\u2260\u2009bi), where (ai,\u2009bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x.", "output_spec": "Print \"FAIL\", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print \"WIN\".", "sample_inputs": ["4\n1 3\n2 3\n1 4\n5 3", "5\n1 2\n2 3\n3 4\n4 5\n5 1"], "sample_outputs": ["WIN", "FAIL"], "notes": null}, "src_uid": "2bc18799c85ecaba87564a86a94e0322"} {"nl": {"description": "Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string \"ACTG\".Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string $$$s$$$ consisting of uppercase letters and length of at least $$$4$$$, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string $$$s$$$ with the next or previous in the alphabet. For example, for the letter \"D\" the previous one will be \"C\", and the next\u00a0\u2014 \"E\". In this problem, we assume that for the letter \"A\", the previous one will be the letter \"Z\", and the next one will be \"B\", and for the letter \"Z\", the previous one is the letter \"Y\", and the next one is the letter \"A\".Help Maxim solve the problem that the teacher gave him.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$4 \\leq n \\leq 50$$$)\u00a0\u2014 the length of the string $$$s$$$. The second line contains the string $$$s$$$, consisting of exactly $$$n$$$ uppercase letters of the Latin alphabet.", "output_spec": "Output the minimum number of operations that need to be applied to the string $$$s$$$ so that the genome appears as a substring in it.", "sample_inputs": ["4\nZCTH", "5\nZDATG", "6\nAFBAKC"], "sample_outputs": ["2", "5", "16"], "notes": "NoteIn the first example, you should replace the letter \"Z\" with \"A\" for one operation, the letter \"H\"\u00a0\u2014 with the letter \"G\" for one operation. You will get the string \"ACTG\", in which the genome is present as a substring.In the second example, we replace the letter \"A\" with \"C\" for two operations, the letter \"D\"\u00a0\u2014 with the letter \"A\" for three operations. You will get the string \"ZACTG\", in which there is a genome."}, "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"} {"nl": {"description": "Greatest common divisor GCD(a,\u2009b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a,\u2009b), for example, Euclid algorithm. Formally, find the biggest integer d, such that all integers a,\u2009a\u2009+\u20091,\u2009a\u2009+\u20092,\u2009...,\u2009b are divisible by d. To make the problem even more complicated we allow a and b to be up to googol, 10100\u00a0\u2014 such number do not fit even in 64-bit integer type!", "input_spec": "The only line of the input contains two integers a and b (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u200910100).", "output_spec": "Output one integer\u00a0\u2014 greatest common divisor of all integers from a to b inclusive.", "sample_inputs": ["1 2", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576"], "sample_outputs": ["1", "61803398874989484820458683436563811772030917980576"], "notes": null}, "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"nl": {"description": "Can you imagine our life if we removed all zeros from it? For sure we will have many problems.In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation a\u2009+\u2009b\u2009=\u2009c, where a and b are positive integers, and c is the sum of a and b. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?For example if the equation is 101\u2009+\u2009102\u2009=\u2009203, if we removed all zeros it will be 11\u2009+\u200912\u2009=\u200923 which is still a correct equation.But if the equation is 105\u2009+\u2009106\u2009=\u2009211, if we removed all zeros it will be 15\u2009+\u200916\u2009=\u2009211 which is not a correct equation.", "input_spec": "The input will consist of two lines, the first line will contain the integer a, and the second line will contain the integer b which are in the equation as described above (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109). There won't be any leading zeros in both. The value of c should be calculated as c\u2009=\u2009a\u2009+\u2009b.", "output_spec": "The output will be just one line, you should print \"YES\" if the equation will remain correct after removing all zeros, and print \"NO\" otherwise.", "sample_inputs": ["101\n102", "105\n106"], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "ac6971f4feea0662d82da8e0862031ad"} {"nl": {"description": "Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.", "input_spec": "The first line of the input contains two positive integers a1 and a2 (1\u2009\u2264\u2009a1,\u2009a2\u2009\u2264\u2009100), the initial charge level of first and second joystick respectively.", "output_spec": "Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.", "sample_inputs": ["3 5", "4 4"], "sample_outputs": ["6", "5"], "notes": "NoteIn the first sample game lasts for 6 minute by using the following algorithm: at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped."}, "src_uid": "ba0f9f5f0ad4786b9274c829be587961"} {"nl": {"description": "Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English letters, string s is lexicographically smaller than string t. Vitaly wondered if there is such string that is lexicographically larger than string s and at the same is lexicographically smaller than string t. This string should also consist of lowercase English letters and have the length equal to the lengths of strings s and t. Let's help Vitaly solve this easy problem!", "input_spec": "The first line contains string s (1\u2009\u2264\u2009|s|\u2009\u2264\u2009100), consisting of lowercase English letters. Here, |s| denotes the length of the string. The second line contains string t (|t|\u2009=\u2009|s|), consisting of lowercase English letters. It is guaranteed that the lengths of strings s and t are the same and string s is lexicographically less than string t.", "output_spec": "If the string that meets the given requirements doesn't exist, print a single string \"No such string\" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them.", "sample_inputs": ["a\nc", "aaa\nzzz", "abcdefg\nabcdefh"], "sample_outputs": ["b", "kkk", "No such string"], "notes": "NoteString s\u2009=\u2009s1s2... sn is said to be lexicographically smaller than t\u2009=\u2009t1t2... tn, if there exists such i, that s1\u2009=\u2009t1,\u2009s2\u2009=\u2009t2,\u2009... si\u2009-\u20091\u2009=\u2009ti\u2009-\u20091,\u2009si\u2009<\u2009ti."}, "src_uid": "47618510d2a17b1cc1e6a688201d51a3"} {"nl": {"description": "Your friend has n cards.You know that each card has a lowercase English letter on one side and a digit on the other.Currently, your friend has laid out the cards on a table so only one side of each card is visible.You would like to know if the following statement is true for cards that your friend owns: \"If a card has a vowel on one side, then it has an even digit on the other side.\" More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.", "input_spec": "The first and only line of input will contain a string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200950), denoting the sides of the cards that you can see on the table currently. Each character of s is either a lowercase English letter or a digit.", "output_spec": "Print a single integer, the minimum number of cards you must turn over to verify your claim.", "sample_inputs": ["ee", "z", "0ay1"], "sample_outputs": ["2", "0", "2"], "notes": "NoteIn the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.In the third sample, we need to flip the second and fourth cards."}, "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"} {"nl": {"description": "Today, Osama gave Fadi an integer $$$X$$$, and Fadi was wondering about the minimum possible value of $$$max(a, b)$$$ such that $$$LCM(a, b)$$$ equals $$$X$$$. Both $$$a$$$ and $$$b$$$ should be positive integers.$$$LCM(a, b)$$$ is the smallest positive integer that is divisible by both $$$a$$$ and $$$b$$$. For example, $$$LCM(6, 8) = 24$$$, $$$LCM(4, 12) = 12$$$, $$$LCM(2, 3) = 6$$$.Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?", "input_spec": "The first and only line contains an integer $$$X$$$ ($$$1 \\le X \\le 10^{12}$$$).", "output_spec": "Print two positive integers, $$$a$$$ and $$$b$$$, such that the value of $$$max(a, b)$$$ is minimum possible and $$$LCM(a, b)$$$ equals $$$X$$$. If there are several possible such pairs, you can print any.", "sample_inputs": ["2", "6", "4", "1"], "sample_outputs": ["1 2", "2 3", "1 4", "1 1"], "notes": null}, "src_uid": "e504a04cefef3da093573f9df711bcea"} {"nl": {"description": "Little Petya very much likes computers. Recently he has received a new \"Ternatron IV\" as a gift from his mother. Unlike other modern computers, \"Ternatron IV\" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it).It turned out that the operation does exist (however, it is called tor) and it works like this. Suppose that we need to calculate the value of the expression a tor b. Both numbers a and b are written in the ternary notation one under the other one (b under a). If they have a different number of digits, then leading zeroes are added to the shorter number until the lengths are the same. Then the numbers are summed together digit by digit. The result of summing each two digits is calculated modulo 3. Note that there is no carry between digits (i. e. during this operation the digits aren't transferred). For example: 1410 tor 5010\u2009=\u200901123 tor 12123\u2009=\u200910213\u2009=\u20093410.Petya wrote numbers a and c on a piece of paper. Help him find such number b, that a tor b\u2009=\u2009c. If there are several such numbers, print the smallest one.", "input_spec": "The first line contains two integers a and c (0\u2009\u2264\u2009a,\u2009c\u2009\u2264\u2009109). Both numbers are written in decimal notation.", "output_spec": "Print the single integer b, such that a tor b\u2009=\u2009c. If there are several possible numbers b, print the smallest one. You should print the number in decimal notation.", "sample_inputs": ["14 34", "50 34", "387420489 225159023", "5 5"], "sample_outputs": ["50", "14", "1000000001", "0"], "notes": null}, "src_uid": "5fb635d52ddccf6a4d5103805da02a88"} {"nl": {"description": "John Doe has recently found a \"Free Market\" in his city \u2014 that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that each item is one of a kind and that means that you cannot exchange set {a,\u2009b} for set {v,\u2009a}. However, you can always exchange set x for any set y, unless there is item p, such that p occurs in x and p occurs in y.For each item, John knows its value ci. John's sense of justice doesn't let him exchange a set of items x for a set of items y, if s(x)\u2009+\u2009d\u2009<\u2009s(y) (s(x) is the total price of items in the set x). During one day John can exchange only one set of items for something else. Initially, he has no items. John wants to get a set of items with the maximum total price. Find the cost of such set and the minimum number of days John can get it in. ", "input_spec": "The first line contains two space-separated integers n, d (1\u2009\u2264\u2009n\u2009\u2264\u200950, 1\u2009\u2264\u2009d\u2009\u2264\u2009104) \u2014 the number of items on the market and John's sense of justice value, correspondingly. The second line contains n space-separated integers ci (1\u2009\u2264\u2009ci\u2009\u2264\u2009104).", "output_spec": "Print two space-separated integers: the maximum possible price in the set of items John can get and the minimum number of days needed to get such set.", "sample_inputs": ["3 2\n1 3 10", "3 5\n1 2 3", "10 10000\n10000 9999 1 10000 10000 10000 1 2 3 4"], "sample_outputs": ["4 3", "6 2", "50010 6"], "notes": "NoteIn the first sample John can act like this: Take the first item (1\u2009-\u20090\u2009\u2264\u20092). Exchange the first item for the second one (3\u2009-\u20091\u2009\u2264\u20092). Take the first item (1\u2009-\u20090\u2009\u2264\u20092). "}, "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f"} {"nl": {"description": "Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1\u2009-\u2009p), paralyzed by his fear of escalators and making the whole queue wait behind him.Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i\u2009-\u20091 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task.", "input_spec": "The first line of the input contains three numbers n,\u2009p,\u2009t (1\u2009\u2264\u2009n,\u2009t\u2009\u2264\u20092000, 0\u2009\u2264\u2009p\u2009\u2264\u20091). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.", "output_spec": "Print a single real number \u2014 the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10\u2009-\u20096.", "sample_inputs": ["1 0.50 1", "1 0.50 4", "4 0.20 2"], "sample_outputs": ["0.5", "0.9375", "0.4"], "notes": null}, "src_uid": "20873b1e802c7aa0e409d9f430516c1e"} {"nl": {"description": "At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.More formally, the guys take turns giving each other one candy more than they received in the previous turn.This continued until the moment when one of them couldn\u2019t give the right amount of candy. Candies, which guys got from each other, they don\u2019t consider as their own. You need to know, who is the first who can\u2019t give the right amount of candy.", "input_spec": "Single line of input data contains two space-separated integers a, b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109) \u2014 number of Vladik and Valera candies respectively.", "output_spec": "Pring a single line \"Vladik\u2019\u2019 in case, if Vladik first who can\u2019t give right amount of candy, or \"Valera\u2019\u2019 otherwise.", "sample_inputs": ["1 1", "7 6"], "sample_outputs": ["Valera", "Vladik"], "notes": "NoteIllustration for first test case:Illustration for second test case:"}, "src_uid": "87e37a82be7e39e433060fd8cdb03270"} {"nl": {"description": "Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a \"Double Cola\" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.Write a program that will print the name of a man who will drink the n-th can.Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.", "input_spec": "The input data consist of a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.", "output_spec": "Print the single line \u2014 the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: \"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\" (without the quotes). In that order precisely the friends are in the queue initially.", "sample_inputs": ["1", "6", "1802"], "sample_outputs": ["Sheldon", "Sheldon", "Penny"], "notes": null}, "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"nl": {"description": "Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size n\u2009\u00d7\u2009m. Each cell in this grid was either empty, containing one little pig, or containing one wolf.A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs.They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf.What is the maximum number of little pigs that may be eaten by the wolves?", "input_spec": "The first line contains integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200910) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow n lines containing m characters each \u2014 that is the grid description. \".\" means that this cell is empty. \"P\" means that this cell contains a little pig. \"W\" means that this cell contains a wolf. It is guaranteed that there will be at most one wolf adjacent to any little pig.", "output_spec": "Print a single number \u2014 the maximal number of little pigs that may be eaten by the wolves.", "sample_inputs": ["2 3\nPPW\nW.P", "3 3\nP.W\n.P.\nW.P"], "sample_outputs": ["2", "0"], "notes": "NoteIn the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows. "}, "src_uid": "969b24ed98d916184821b2b2f8fd3aac"} {"nl": {"description": "\u00abOne dragon. Two dragon. Three dragon\u00bb, \u2014 the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?", "input_spec": "Input data contains integer numbers k,\u2009l,\u2009m,\u2009n and d, each number in a separate line (1\u2009\u2264\u2009k,\u2009l,\u2009m,\u2009n\u2009\u2264\u200910, 1\u2009\u2264\u2009d\u2009\u2264\u2009105).", "output_spec": "Output the number of damaged dragons.", "sample_inputs": ["1\n2\n3\n4\n12", "2\n3\n4\n5\n24"], "sample_outputs": ["12", "17"], "notes": "NoteIn the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed."}, "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"} {"nl": {"description": "Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.Please help Ciel to find this minimal sum.", "input_spec": "The first line contains an integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100). Then the second line contains n integers: x1, x2, ..., xn (1\u2009\u2264\u2009xi\u2009\u2264\u2009100).", "output_spec": "Output a single integer \u2014 the required minimal sum.", "sample_inputs": ["2\n1 2", "3\n2 4 6", "2\n12 18", "5\n45 12 27 30 18"], "sample_outputs": ["2", "6", "12", "15"], "notes": "NoteIn the first example the optimal way is to do the assignment: x2 = x2 - x1.In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1."}, "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"} {"nl": {"description": "Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1\u2009+\u20092\u2009=\u20093 cubes, the third level must have 1\u2009+\u20092\u2009+\u20093\u2009=\u20096 cubes, and so on. Thus, the i-th level of the pyramid must have 1\u2009+\u20092\u2009+\u2009...\u2009+\u2009(i\u2009-\u20091)\u2009+\u2009i cubes.Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009104) \u2014 the number of cubes given to Vanya.", "output_spec": "Print the maximum possible height of the pyramid in the single line.", "sample_inputs": ["1", "25"], "sample_outputs": ["1", "4"], "notes": "NoteIllustration to the second sample: "}, "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"nl": {"description": "Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n\u2009-\u20091. For all 0\u2009\u2264\u2009u\u2009<\u2009v\u2009<\u2009n, vertex u and vertex v are connected with an undirected edge that has weight (where is the bitwise-xor operation). Can you find the weight of the minimum spanning tree of that graph?You can read about complete graphs in https://en.wikipedia.org/wiki/Complete_graphYou can read about the minimum spanning tree in https://en.wikipedia.org/wiki/Minimum_spanning_treeThe weight of the minimum spanning tree is the sum of the weights on the edges included in it.", "input_spec": "The only line contains an integer n (2\u2009\u2264\u2009n\u2009\u2264\u20091012), the number of vertices in the graph.", "output_spec": "The only line contains an integer x, the weight of the graph's minimum spanning tree.", "sample_inputs": ["4"], "sample_outputs": ["4"], "notes": "NoteIn the first sample: The weight of the minimum spanning tree is 1+2+1=4."}, "src_uid": "a98f0d924ea52cafe0048f213f075891"} {"nl": {"description": " ", "input_spec": "The input contains two integers a,\u2009b (1\u2009\u2264\u2009a\u2009\u2264\u200910,\u20090\u2009\u2264\u2009b\u2009\u2264\u200922\u00b7a\u2009-\u20091) separated by a single space.", "output_spec": "Output two integers separated by a single space.", "sample_inputs": ["1 0", "2 15", "4 160"], "sample_outputs": ["0 0", "3 0", "12 12"], "notes": null}, "src_uid": "879ac20ae5d3e7f1002afe907d9887df"} {"nl": {"description": "Dwarfs have planted a very interesting plant, which is a triangle directed \"upwards\". This plant has an amusing feature. After one year a triangle plant directed \"upwards\" divides into four triangle plants: three of them will point \"upwards\" and one will point \"downwards\". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. Help the dwarfs find out how many triangle plants that point \"upwards\" will be in n years.", "input_spec": "The first line contains a single integer n (0\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specifier.", "output_spec": "Print a single integer \u2014 the remainder of dividing the number of plants that will point \"upwards\" in n years by 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1", "2"], "sample_outputs": ["3", "10"], "notes": "NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one."}, "src_uid": "782b819eb0bfc86d6f96f15ac09d5085"} {"nl": {"description": "There are $$$n$$$ students in a university. The number of students is even. The $$$i$$$-th student has programming skill equal to $$$a_i$$$. The coach wants to form $$$\\frac{n}{2}$$$ teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).Students can solve problems to increase their skill. One solved problem increases the skill by one.The coach wants to know the minimum total number of problems students should solve to form exactly $$$\\frac{n}{2}$$$ teams (i.e. each pair of students should form a team). Your task is to find this number.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of students. It is guaranteed that $$$n$$$ is even. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student.", "output_spec": "Print one number \u2014 the minimum total number of problems students should solve to form exactly $$$\\frac{n}{2}$$$ teams.", "sample_inputs": ["6\n5 10 2 3 14 5", "2\n1 100"], "sample_outputs": ["5", "99"], "notes": "NoteIn the first example the optimal teams will be: $$$(3, 4)$$$, $$$(1, 6)$$$ and $$$(2, 5)$$$, where numbers in brackets are indices of students. Then, to form the first team the third student should solve $$$1$$$ problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve $$$4$$$ problems so the answer is $$$1 + 4 = 5$$$.In the second example the first student should solve $$$99$$$ problems to form a team with the second one."}, "src_uid": "55485fe203a114374f0aae93006278d3"} {"nl": {"description": "One day, Hongcow goes to the store and sees a brand new deck of n special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store.This game takes some number of turns to complete. On a turn, Hongcow may do one of two things: Collect tokens. Hongcow collects 1 red token and 1 blue token by choosing this option (thus, 2 tokens in total per one operation). Buy a card. Hongcow chooses some card and spends tokens to purchase it as specified below. The i-th card requires ri red resources and bi blue resources. Suppose Hongcow currently has A red cards and B blue cards. Then, the i-th card will require Hongcow to spend max(ri\u2009-\u2009A,\u20090) red tokens, and max(bi\u2009-\u2009B,\u20090) blue tokens. Note, only tokens disappear, but the cards stay with Hongcow forever. Each card can be bought only once.Given a description of the cards and their costs determine the minimum number of turns Hongcow needs to purchase all cards.", "input_spec": "The first line of input will contain a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200916). The next n lines of input will contain three tokens ci, ri and bi. ci will be 'R' or 'B', denoting the color of the card as red or blue. ri will be an integer denoting the amount of red resources required to obtain the card, and bi will be an integer denoting the amount of blue resources required to obtain the card (0\u2009\u2264\u2009ri,\u2009bi\u2009\u2264\u2009107).", "output_spec": "Output a single integer, denoting the minimum number of turns needed to acquire all the cards.", "sample_inputs": ["3\nR 0 1\nB 1 0\nR 1 1", "3\nR 3 0\nR 2 0\nR 1 0"], "sample_outputs": ["4", "6"], "notes": "NoteFor the first sample, Hongcow's four moves are as follows: Collect tokens Buy card 1 Buy card 2 Buy card 3 Note, at the fourth step, Hongcow is able to buy card 3 because Hongcow already has one red and one blue card, so we don't need to collect tokens.For the second sample, one optimal strategy is as follows: Collect tokens Collect tokens Buy card 2 Collect tokens Buy card 3 Buy card 1 At the fifth step, even though Hongcow has a red token, Hongcow doesn't actually need to spend it, since Hongcow has a red card already."}, "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969"} {"nl": {"description": "Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c\u2009<\u2009b) rubles back, but you cannot return plastic bottles.Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.", "input_spec": "First line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018)\u00a0\u2014 the number of rubles Kolya has at the beginning. Then follow three lines containing integers a, b and c (1\u2009\u2264\u2009a\u2009\u2264\u20091018, 1\u2009\u2264\u2009c\u2009<\u2009b\u2009\u2264\u20091018)\u00a0\u2014 the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.", "output_spec": "Print the only integer\u00a0\u2014 maximum number of liters of kefir, that Kolya can drink.", "sample_inputs": ["10\n11\n9\n8", "10\n5\n6\n1"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir."}, "src_uid": "0ee9abec69230eab25de51aef0984f8f"} {"nl": {"description": "Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1,\u2009a2,\u2009...,\u2009an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times.Greg now only does three types of exercises: \"chest\" exercises, \"biceps\" exercises and \"back\" exercises. Besides, his training is cyclic, that is, the first exercise he does is a \"chest\" one, the second one is \"biceps\", the third one is \"back\", the fourth one is \"chest\", the fifth one is \"biceps\", and so on to the n-th exercise.Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200920). The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u200925) \u2014 the number of times Greg repeats the exercises.", "output_spec": "Print word \"chest\" (without the quotes), if the chest gets the most exercise, \"biceps\" (without the quotes), if the biceps gets the most exercise and print \"back\" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.", "sample_inputs": ["2\n2 8", "3\n5 1 10", "7\n3 3 2 7 9 6 8"], "sample_outputs": ["biceps", "back", "chest"], "notes": "NoteIn the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise."}, "src_uid": "579021de624c072f5e0393aae762117e"} {"nl": {"description": "Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t\u2009+\u2009s, t\u2009+\u2009s\u2009+\u20091, t\u2009+\u20092s, t\u2009+\u20092s\u2009+\u20091, etc. Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.", "input_spec": "The first and only line of input contains three integers t, s and x (0\u2009\u2264\u2009t,\u2009x\u2009\u2264\u2009109, 2\u2009\u2264\u2009s\u2009\u2264\u2009109)\u00a0\u2014 the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.", "output_spec": "Print a single \"YES\" (without quotes) if the pineapple will bark at time x or a single \"NO\" (without quotes) otherwise in the only line of output.", "sample_inputs": ["3 10 4", "3 10 3", "3 8 51", "3 8 52"], "sample_outputs": ["NO", "YES", "YES", "YES"], "notes": "NoteIn the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52."}, "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"nl": {"description": "Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and the contest is not carried out; on this day the gym is closed and the contest is carried out; on this day the gym is open and the contest is not carried out; on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has \u2014 he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.", "input_spec": "The first line contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of days of Vasya's vacations. The second line contains the sequence of integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u20093) separated by space, where: ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.", "output_spec": "Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: to do sport on any two consecutive days, to write the contest on any two consecutive days. ", "sample_inputs": ["4\n1 3 2 0", "7\n1 3 3 2 1 2 3", "2\n2 2"], "sample_outputs": ["2", "0", "1"], "notes": "NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day."}, "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"nl": {"description": "Tokitsukaze is one of the characters in the game \"Kantai Collection\". In this game, every character has a common attribute\u00a0\u2014 health points, shortened to HP.In general, different values of HP are grouped into $$$4$$$ categories: Category $$$A$$$ if HP is in the form of $$$(4 n + 1)$$$, that is, when divided by $$$4$$$, the remainder is $$$1$$$; Category $$$B$$$ if HP is in the form of $$$(4 n + 3)$$$, that is, when divided by $$$4$$$, the remainder is $$$3$$$; Category $$$C$$$ if HP is in the form of $$$(4 n + 2)$$$, that is, when divided by $$$4$$$, the remainder is $$$2$$$; Category $$$D$$$ if HP is in the form of $$$4 n$$$, that is, when divided by $$$4$$$, the remainder is $$$0$$$. The above-mentioned $$$n$$$ can be any integer.These $$$4$$$ categories ordered from highest to lowest as $$$A > B > C > D$$$, which means category $$$A$$$ is the highest and category $$$D$$$ is the lowest.While playing the game, players can increase the HP of the character. Now, Tokitsukaze wants you to increase her HP by at most $$$2$$$ (that is, either by $$$0$$$, $$$1$$$ or $$$2$$$). How much should she increase her HP so that it has the highest possible category?", "input_spec": "The only line contains a single integer $$$x$$$ ($$$30 \\leq x \\leq 100$$$)\u00a0\u2014 the value Tokitsukaze's HP currently.", "output_spec": "Print an integer $$$a$$$ ($$$0 \\leq a \\leq 2$$$) and an uppercase letter $$$b$$$ ($$$b \\in \\lbrace A, B, C, D \\rbrace$$$), representing that the best way is to increase her HP by $$$a$$$, and then the category becomes $$$b$$$. Note that the output characters are case-sensitive.", "sample_inputs": ["33", "98"], "sample_outputs": ["0 A", "1 B"], "notes": "NoteFor the first example, the category of Tokitsukaze's HP is already $$$A$$$, so you don't need to enhance her ability.For the second example: If you don't increase her HP, its value is still $$$98$$$, which equals to $$$(4 \\times 24 + 2)$$$, and its category is $$$C$$$. If you increase her HP by $$$1$$$, its value becomes $$$99$$$, which equals to $$$(4 \\times 24 + 3)$$$, and its category becomes $$$B$$$. If you increase her HP by $$$2$$$, its value becomes $$$100$$$, which equals to $$$(4 \\times 25)$$$, and its category becomes $$$D$$$. Therefore, the best way is to increase her HP by $$$1$$$ so that the category of her HP becomes $$$B$$$."}, "src_uid": "488e809bd0c55531b0b47f577996627e"} {"nl": {"description": "Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2\u00b7n people in the group (including Vadim), and they have exactly n\u2009-\u20091 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. i-th person's weight is wi, and weight is an important matter in kayaking \u2014 if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.Help the party to determine minimum possible total instability! ", "input_spec": "The first line contains one number n (2\u2009\u2264\u2009n\u2009\u2264\u200950). The second line contains 2\u00b7n integer numbers w1, w2, ..., w2n, where wi is weight of person i (1\u2009\u2264\u2009wi\u2009\u2264\u20091000).", "output_spec": "Print minimum possible total instability.", "sample_inputs": ["2\n1 2 3 4", "4\n1 3 4 6 3 4 100 200"], "sample_outputs": ["1", "5"], "notes": null}, "src_uid": "76659c0b7134416452585c391daadb16"} {"nl": {"description": "You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.", "input_spec": "The single line contains three integers r, g and b (0\u2009\u2264\u2009r,\u2009g,\u2009b\u2009\u2264\u20092\u00b7109) \u2014 the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.", "output_spec": "Print a single integer t \u2014 the maximum number of tables that can be decorated in the required manner.", "sample_inputs": ["5 4 3", "1 1 1", "2 3 3"], "sample_outputs": ["4", "1", "2"], "notes": "NoteIn the first sample you can decorate the tables with the following balloon sets: \"rgg\", \"gbb\", \"brr\", \"rrg\", where \"r\", \"g\" and \"b\" represent the red, green and blue balls, respectively."}, "src_uid": "bae7cbcde19114451b8712d6361d2b01"} {"nl": {"description": "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\u2009=\u20090, then Vasya prefers to walk beside his entrance. Illustration for n\u2009=\u20096, a\u2009=\u20092, b\u2009=\u2009\u2009-\u20095. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.", "input_spec": "The single line of the input contains three space-separated integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009a\u2009\u2264\u2009n,\u2009\u2009-\u2009100\u2009\u2264\u2009b\u2009\u2264\u2009100)\u00a0\u2014 the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.", "output_spec": "Print a single integer k (1\u2009\u2264\u2009k\u2009\u2264\u2009n)\u00a0\u2014 the number of the entrance where Vasya will be at the end of his walk.", "sample_inputs": ["6 2 -5", "5 1 3", "3 2 7"], "sample_outputs": ["3", "4", "3"], "notes": "NoteThe first example is illustrated by the picture in the statements."}, "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"} {"nl": {"description": "In order to make the \"Sea Battle\" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of $$$w_1$$$ and a height of $$$h_1$$$, while the second rectangle has a width of $$$w_2$$$ and a height of $$$h_2$$$, where $$$w_1 \\ge w_2$$$. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field.The rectangles are placed on field in the following way: the second rectangle is on top the first rectangle; they are aligned to the left, i.e. their left sides are on the same line; the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue.Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates $$$(1, 1)$$$, the rightmost top cell of the first rectangle has coordinates $$$(w_1, h_1)$$$, the leftmost bottom cell of the second rectangle has coordinates $$$(1, h_1 + 1)$$$ and the rightmost top cell of the second rectangle has coordinates $$$(w_2, h_1 + h_2)$$$.After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green.Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction.", "input_spec": "Four lines contain integers $$$w_1, h_1, w_2$$$ and $$$h_2$$$ ($$$1 \\leq w_1, h_1, w_2, h_2 \\leq 10^8$$$, $$$w_1 \\ge w_2$$$)\u00a0\u2014 the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles.", "output_spec": "Print exactly one integer\u00a0\u2014 the number of cells, which should be marked after the ship is destroyed.", "sample_inputs": ["2 1 2 1", "2 2 1 2"], "sample_outputs": ["12", "16"], "notes": "NoteIn the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): In the second example the field looks as: "}, "src_uid": "b5d44e0041053c996938aadd1b3865f6"} {"nl": {"description": "Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing successively one after another, or there are strictly more than k2 horsemen standing successively one after another. Find the number of beautiful arrangements of the soldiers. Note that all n1\u2009+\u2009n2 warriors should be present at each arrangement. All footmen are considered indistinguishable among themselves. Similarly, all horsemen are considered indistinguishable among themselves.", "input_spec": "The only line contains four space-separated integers n1, n2, k1, k2 (1\u2009\u2264\u2009n1,\u2009n2\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009k1,\u2009k2\u2009\u2264\u200910) which represent how many footmen and horsemen there are and the largest acceptable number of footmen and horsemen standing in succession, correspondingly.", "output_spec": "Print the number of beautiful arrangements of the army modulo 100000000 (108). That is, print the number of such ways to line up the soldiers, that no more than k1 footmen stand successively, and no more than k2 horsemen stand successively.", "sample_inputs": ["2 1 1 10", "2 3 1 2", "2 4 1 1"], "sample_outputs": ["1", "5", "0"], "notes": "NoteLet's mark a footman as 1, and a horseman as 2.In the first sample the only beautiful line-up is: 121In the second sample 5 beautiful line-ups exist: 12122, 12212, 21212, 21221, 22121"}, "src_uid": "63aabef26fe008e4c6fc9336eb038289"} {"nl": {"description": "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_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20095). Next n lines contain four integers each, describing a single rectangle: x1, y1, x2, y2 (0\u2009\u2264\u2009x1\u2009<\u2009x2\u2009\u2264\u200931400,\u20090\u2009\u2264\u2009y1\u2009<\u2009y2\u2009\u2264\u200931400) \u2014 x1 and x2 are x-coordinates of the left and right edges of the rectangle, and y1 and y2 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_spec": "In a single line print \"YES\", if the given rectangles form a square, or \"NO\" otherwise.", "sample_inputs": ["5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5"], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "f63fc2d97fd88273241fce206cc217f2"} {"nl": {"description": "Iahub got bored, so he invented a game to be played on paper. He writes n integers a1,\u2009a2,\u2009...,\u2009an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1\u2009\u2264\u2009i\u2009\u2264\u2009j\u2009\u2264\u2009n) and flips all values ak for which their positions are in range [i,\u2009j] (that is i\u2009\u2264\u2009k\u2009\u2264\u2009j). Flip the value of x means to apply operation x\u2009=\u20091 - x.The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.", "input_spec": "The first line of the input contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). In the second line of the input there are n integers: a1,\u2009a2,\u2009...,\u2009an. It is guaranteed that each of those n values is either 0 or 1.", "output_spec": "Print an integer \u2014 the maximal number of 1s that can be obtained after exactly one move. ", "sample_inputs": ["5\n1 0 0 1 0", "4\n1 0 0 1"], "sample_outputs": ["4", "4"], "notes": "NoteIn the first case, flip the segment from 2 to 5 (i\u2009=\u20092,\u2009j\u2009=\u20095). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].In the second case, flipping only the second and the third element (i\u2009=\u20092,\u2009j\u2009=\u20093) will turn all numbers into 1."}, "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"nl": {"description": "Limak is a little polar bear. He has n balls, the i-th ball has size ti.Limak wants to give one ball to each of his three friends. Giving gifts isn't easy\u00a0\u2014 there are two rules Limak must obey to make friends happy: No two friends can get balls of the same size. No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).Your task is to check whether Limak can choose three balls that satisfy conditions above.", "input_spec": "The first line of the input contains one integer n (3\u2009\u2264\u2009n\u2009\u2264\u200950)\u00a0\u2014 the number of balls Limak has. The second line contains n integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20091000) where ti denotes the size of the i-th ball.", "output_spec": "Print \"YES\" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["4\n18 55 16 17", "6\n40 41 43 44 44 44", "8\n5 972 3 4 1 4 970 971"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.In the second sample, there is no way to give gifts to three friends without breaking the rules.In the third sample, there is even more than one way to choose balls: Choose balls with sizes 3, 4 and 5. Choose balls with sizes 972, 970, 971. "}, "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"nl": {"description": "Given a positive integer $$$m$$$, we say that a sequence $$$x_1, x_2, \\dots, x_n$$$ of positive integers is $$$m$$$-cute if for every index $$$i$$$ such that $$$2 \\le i \\le n$$$ it holds that $$$x_i = x_{i - 1} + x_{i - 2} + \\dots + x_1 + r_i$$$ for some positive integer $$$r_i$$$ satisfying $$$1 \\le r_i \\le m$$$.You will be given $$$q$$$ queries consisting of three positive integers $$$a$$$, $$$b$$$ and $$$m$$$. For each query you must determine whether or not there exists an $$$m$$$-cute sequence whose first term is $$$a$$$ and whose last term is $$$b$$$. If such a sequence exists, you must additionally find an example of it.", "input_spec": "The first line contains an integer number $$$q$$$ ($$$1 \\le q \\le 10^3$$$)\u00a0\u2014 the number of queries. Each of the following $$$q$$$ lines contains three integers $$$a$$$, $$$b$$$, and $$$m$$$ ($$$1 \\le a, b, m \\le 10^{14}$$$, $$$a \\leq b$$$), describing a single query.", "output_spec": "For each query, if no $$$m$$$-cute sequence whose first term is $$$a$$$ and whose last term is $$$b$$$ exists, print $$$-1$$$. Otherwise print an integer $$$k$$$ ($$$1 \\le k \\leq 50$$$), followed by $$$k$$$ integers $$$x_1, x_2, \\dots, x_k$$$ ($$$1 \\le x_i \\le 10^{14}$$$). These integers must satisfy $$$x_1 = a$$$, $$$x_k = b$$$, and that the sequence $$$x_1, x_2, \\dots, x_k$$$ is $$$m$$$-cute. It can be shown that under the problem constraints, for each query either no $$$m$$$-cute sequence exists, or there exists one with at most $$$50$$$ terms. If there are multiple possible sequences, you may print any of them.", "sample_inputs": ["2\n5 26 2\n3 9 1"], "sample_outputs": ["4 5 6 13 26\n-1"], "notes": "NoteConsider the sample. In the first query, the sequence $$$5, 6, 13, 26$$$ is valid since $$$6 = 5 + \\bf{\\color{blue} 1}$$$, $$$13 = 6 + 5 + {\\bf\\color{blue} 2}$$$ and $$$26 = 13 + 6 + 5 + {\\bf\\color{blue} 2}$$$ have the bold values all between $$$1$$$ and $$$2$$$, so the sequence is $$$2$$$-cute. Other valid sequences, such as $$$5, 7, 13, 26$$$ are also accepted.In the second query, the only possible $$$1$$$-cute sequence starting at $$$3$$$ is $$$3, 4, 8, 16, \\dots$$$, which does not contain $$$9$$$."}, "src_uid": "c9d646762e2e78064bc0670ec7c173c6"} {"nl": {"description": "Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: Four sticks represent the animal's legs, these sticks should have the same length. Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.", "input_spec": "The single line contains six space-separated integers li (1\u2009\u2264\u2009li\u2009\u2264\u20099) \u2014 the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.", "output_spec": "If you can make a bear from the given set, print string \"Bear\" (without the quotes). If you can make an elephant, print string \"Elephant\" (w\u0131thout the quotes). If you can make neither a bear nor an elephant, print string \"Alien\" (without the quotes).", "sample_inputs": ["4 2 5 4 4 4", "4 4 5 4 4 5", "1 2 3 4 5 6"], "sample_outputs": ["Bear", "Elephant", "Alien"], "notes": "NoteIf you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. "}, "src_uid": "43308fa25e8578fd9f25328e715d4dd6"} {"nl": {"description": "After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20094)\u00a0\u2014 the number of vertices that were not erased by Wilbur's friend. Each of the following n lines contains two integers xi and yi (\u2009-\u20091000\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u20091000)\u00a0\u2014the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order. It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.", "output_spec": "Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print \u2009-\u20091. ", "sample_inputs": ["2\n0 0\n1 1", "1\n1 1"], "sample_outputs": ["1", "-1"], "notes": "NoteIn the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area."}, "src_uid": "ba49b6c001bb472635f14ec62233210e"}