{"nl": {"description": "The princess is going to escape the dragon's cave, and she needs to plan it carefully.The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend f hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is c miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the castle before the dragon reached her, and doesn't need an extra bijou to hold him off.", "input_spec": "The input data contains integers vp,\u2009vd,\u2009t,\u2009f and c, one per line (1\u2009\u2264\u2009vp,\u2009vd\u2009\u2264\u2009100, 1\u2009\u2264\u2009t,\u2009f\u2009\u2264\u200910, 1\u2009\u2264\u2009c\u2009\u2264\u20091000).", "output_spec": "Output the minimal number of bijous required for the escape to succeed.", "sample_inputs": ["1\n2\n1\n1\n10", "1\n2\n1\n1\n8"], "sample_outputs": ["2", "1"], "notes": "NoteIn the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this she will reach the castle without any further trouble.The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou."}, "src_uid": "c9c03666278acec35f0e273691fe0fff"} {"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": "For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree.Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to search his whole tree to determine this; Jacob knows that she will examine the first k nodes in a DFS-order traversal of the tree. She will then assign Jacob a grade equal to the minimum ai she finds among those k nodes.Though Jacob does not have enough time to rebuild his model, he can choose the root node that his teacher starts from. Furthermore, he can rearrange the list of neighbors of each node in any order he likes. Help Jacob find the best grade he can get on this assignment.A DFS-order traversal is an ordering of the nodes of a rooted tree, built by a recursive DFS-procedure initially called on the root of the tree. When called on a given node v, the procedure does the following: Print v. Traverse the list of neighbors of the node v in order and iteratively call DFS-procedure on each one. Do not call DFS-procedure on node u if you came to node v directly from u. ", "input_spec": "The first line of the input contains two positive integers, n and k (2\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u2009n)\u00a0\u2014 the number of balls in Jacob's tree and the number of balls the teacher will inspect. The second line contains n integers, ai (1\u2009\u2264\u2009ai\u2009\u2264\u20091\u2009000\u2009000), the time Jacob used to build the i-th ball. Each of the next n\u2009-\u20091 lines contains two integers ui, vi (1\u2009\u2264\u2009ui,\u2009vi\u2009\u2264\u2009n, ui\u2009\u2260\u2009vi) representing a connection in Jacob's tree between balls ui and vi.", "output_spec": "Print a single integer\u00a0\u2014 the maximum grade Jacob can get by picking the right root of the tree and rearranging the list of neighbors.", "sample_inputs": ["5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3", "4 2\n1 5 5 5\n1 2\n1 3\n1 4"], "sample_outputs": ["3", "1"], "notes": "NoteIn the first sample, Jacob can root the tree at node 2 and order 2's neighbors in the order 4, 1, 5 (all other nodes have at most two neighbors). The resulting preorder traversal is 2, 4, 1, 3, 5, and the minimum ai of the first 3 nodes is 3.In the second sample, it is clear that any preorder traversal will contain node 1 as either its first or second node, so Jacob cannot do better than a grade of 1."}, "src_uid": "4fb83b890e472f86045981e1743ddaac"} {"nl": {"description": "A chip was placed on a field with coordinate system onto point (0,\u20090).Every second the chip moves randomly. If the chip is currently at a point (x,\u2009y), after a second it moves to the point (x\u2009-\u20091,\u2009y) with probability p1, to the point (x,\u2009y\u2009-\u20091) with probability p2, to the point (x\u2009+\u20091,\u2009y) with probability p3 and to the point (x,\u2009y\u2009+\u20091) with probability p4. It's guaranteed that p1\u2009+\u2009p2\u2009+\u2009p3\u2009+\u2009p4\u2009=\u20091. The moves are independent.Find out the expected time after which chip will move away from origin at a distance greater than R (i.e. will be satisfied).", "input_spec": "First line contains five integers R,\u2009a1,\u2009a2,\u2009a3 and a4 (0\u2009\u2264\u2009R\u2009\u2264\u200950,\u20091\u2009\u2264\u2009a1,\u2009a2,\u2009a3,\u2009a4\u2009\u2264\u20091000). Probabilities pi can be calculated using formula .", "output_spec": "It can be shown that answer for this problem is always a rational number of form , where . Print P\u00b7Q\u2009-\u20091 modulo 109\u2009+\u20097. ", "sample_inputs": ["0 1 1 1 1", "1 1 1 1 1", "1 1 2 1 2"], "sample_outputs": ["1", "666666674", "538461545"], "notes": "NoteIn the first example initially the chip is located at a distance 0 from origin. In one second chip will move to distance 1 is some direction, so distance to origin will become 1.Answers to the second and the third tests: and ."}, "src_uid": "bd6bcb5bffd039de93f217b02f5eae17"} {"nl": {"description": "Arpa is taking a geometry exam. Here is the last problem of the exam.You are given three points a,\u2009b,\u2009c.Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.", "input_spec": "The only line contains six integers ax,\u2009ay,\u2009bx,\u2009by,\u2009cx,\u2009cy (|ax|,\u2009|ay|,\u2009|bx|,\u2009|by|,\u2009|cx|,\u2009|cy|\u2009\u2264\u2009109). It's guaranteed that the points are distinct.", "output_spec": "Print \"Yes\" if the problem has a solution, \"No\" otherwise. You can print each letter in any case (upper or lower).", "sample_inputs": ["0 1 1 1 1 0", "1 1 0 0 1000 1000"], "sample_outputs": ["Yes", "No"], "notes": "NoteIn the first sample test, rotate the page around (0.5,\u20090.5) by .In the second sample test, you can't find any solution."}, "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"} {"nl": {"description": "To AmShZ, all arrays are equal, but some arrays are more-equal than others. Specifically, the arrays consisting of $$$n$$$ elements from $$$1$$$ to $$$n$$$ that can be turned into permutations of numbers from $$$1$$$ to $$$n$$$ by adding a non-negative integer to each element.Mashtali who wants to appear in every problem statement thinks that an array $$$b$$$ consisting of $$$k$$$ elements is compatible with a more-equal array $$$a$$$ consisting of $$$n$$$ elements if for each $$$1 \\le i \\le k$$$ we have $$$1 \\le b_i \\le n$$$ and also $$$a_{b_1} = a_{b_2} = \\ldots = a_{b_k}$$$.Find the number of pairs of arrays $$$a$$$ and $$$b$$$ such that $$$a$$$ is a more-equal array consisting of $$$n$$$ elements and $$$b$$$ is an array compatible with $$$a$$$ consisting of $$$k$$$ elements modulo $$$998244353$$$.Note that the elements of $$$b$$$ are not necessarily distinct, same holds for $$$a$$$.", "input_spec": "The first line of input contains two integers $$$n$$$ and $$$k$$$ $$$(1 \\le n \\le 10^9 , 1 \\le k \\le 10^5)$$$.", "output_spec": "Print a single integer \u2014 the answer to the problem modulo $$$998244353$$$.", "sample_inputs": ["1 1", "2 2", "5 4", "20 100", "10000000 10000"], "sample_outputs": ["1", "8", "50400", "807645526", "883232350"], "notes": "NoteThere are eight possible pairs for the second example: $$$a = \\{1, 1\\}, b = \\{1, 1\\}$$$ $$$a = \\{1, 1\\}, b = \\{1, 2\\}$$$ $$$a = \\{1, 1\\}, b = \\{2, 1\\}$$$ $$$a = \\{1, 1\\}, b = \\{2, 2\\}$$$ $$$a = \\{1, 2\\}, b = \\{1, 1\\}$$$ $$$a = \\{1, 2\\}, b = \\{2, 2\\}$$$ $$$a = \\{2, 1\\}, b = \\{1, 1\\}$$$ $$$a = \\{2, 1\\}, b = \\{2, 2\\}$$$ "}, "src_uid": "bc57a69c39c6e74d6d81a9c504104809"} {"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": "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": "Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x\u2009>\u20090 exist such that: Decimal representation of x (without leading zeroes) consists of exactly n digits; There exists some integer y\u2009>\u20090 such that: ; decimal representation of y is a suffix of decimal representation of x. As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.Can you help Amr escape this embarrassing situation?", "input_spec": "Input consists of three integers n,\u2009k,\u2009m (1\u2009\u2264\u2009n\u2009\u2264\u20091000, 1\u2009\u2264\u2009k\u2009\u2264\u2009100, 1\u2009\u2264\u2009m\u2009\u2264\u2009109).", "output_spec": "Print the required number modulo m.", "sample_inputs": ["1 2 1000", "2 2 1000", "5 3 1103"], "sample_outputs": ["4", "45", "590"], "notes": "NoteA suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S."}, "src_uid": "656bf8df1e79499aa2ab2c28712851f0"} {"nl": {"description": "You have a map as a rectangle table. Each cell of the table is either an obstacle, or a treasure with a certain price, or a bomb, or an empty cell. Your initial position is also given to you.You can go from one cell of the map to a side-adjacent one. At that, you are not allowed to go beyond the borders of the map, enter the cells with treasures, obstacles and bombs. To pick the treasures, you need to build a closed path (starting and ending in the starting cell). The closed path mustn't contain any cells with bombs inside. Let's assume that the sum of the treasures' values that are located inside the closed path equals v, and besides, you've made k single moves (from one cell to another) while you were going through the path, then such path brings you the profit of v\u2009-\u2009k rubles.Your task is to build a closed path that doesn't contain any bombs and brings maximum profit.Note that the path can have self-intersections. In order to determine if a cell lies inside a path or not, use the following algorithm: Assume that the table cells are points on the plane (the table cell on the intersection of the i-th column and the j-th row is point (i,\u2009j)). And the given path is a closed polyline that goes through these points. You need to find out if the point p of the table that is not crossed by the polyline lies inside the polyline. Let's draw a ray that starts from point p and does not intersect other points of the table (such ray must exist). Let's count the number of segments of the polyline that intersect the painted ray. If this number is odd, we assume that point p (and consequently, the table cell) lie inside the polyline (path). Otherwise, we assume that it lies outside. ", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200920) \u2014 the sizes of the table. Next n lines each contains m characters \u2014 the description of the table. The description means the following: character \"B\" is a cell with a bomb; character \"S\" is the starting cell, you can assume that it's empty; digit c (1-8) is treasure with index c; character \".\" is an empty cell; character \"#\" is an obstacle. Assume that the map has t treasures. Next t lines contain the prices of the treasures. The i-th line contains the price of the treasure with index i, vi (\u2009-\u2009200\u2009\u2264\u2009vi\u2009\u2264\u2009200). It is guaranteed that the treasures are numbered from 1 to t. It is guaranteed that the map has not more than 8 objects in total. Objects are bombs and treasures. It is guaranteed that the map has exactly one character \"S\".", "output_spec": "Print a single integer \u2014 the maximum possible profit you can get.", "sample_inputs": ["4 4\n....\n.S1.\n....\n....\n10", "7 7\n.......\n.1###2.\n.#...#.\n.#.B.#.\n.3...4.\n..##...\n......S\n100\n100\n100\n100", "7 8\n........\n........\n....1B..\n.S......\n....2...\n3.......\n........\n100\n-100\n100", "1 1\nS"], "sample_outputs": ["2", "364", "0", "0"], "notes": "NoteIn the first example the answer will look as follows. In the second example the answer will look as follows. In the third example you cannot get profit.In the fourth example you cannot get profit as you cannot construct a closed path with more than one cell."}, "src_uid": "624a0d6cf305fcf67d3f1cdc1c5fef8d"} {"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": "Petya collects beautiful matrix.A matrix of size $$$n \\times n$$$ is beautiful if: All elements of the matrix are integers between $$$1$$$ and $$$n$$$; For every row of the matrix, all elements of this row are different; For every pair of vertically adjacent elements, these elements are different. Today Petya bought a beautiful matrix $$$a$$$ of size $$$n \\times n$$$, and now he wants to determine its rarity.The rarity of the matrix is its index in the list of beautiful matrices of size $$$n \\times n$$$, sorted in lexicographical order. Matrix comparison is done row by row. (The index of lexicographically smallest matrix is zero).Since the number of beautiful matrices may be huge, Petya wants you to calculate the rarity of the matrix $$$a$$$ modulo $$$998\\,244\\,353$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 2000$$$) \u2014 the number of rows and columns in $$$a$$$. Each of the next $$$n$$$ lines contains $$$n$$$ integers $$$a_{i,j}$$$ ($$$1 \\le a_{i,j} \\le n$$$) \u2014 the elements of $$$a$$$. It is guaranteed that $$$a$$$ is a beautiful matrix.", "output_spec": "Print one integer \u2014 the rarity of matrix $$$a$$$, taken modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["2\n2 1\n1 2", "3\n1 2 3\n2 3 1\n3 1 2", "3\n1 2 3\n3 1 2\n2 3 1"], "sample_outputs": ["1", "1", "3"], "notes": "NoteThere are only $$$2$$$ beautiful matrices of size $$$2 \\times 2$$$: There are the first $$$5$$$ beautiful matrices of size $$$3 \\times 3$$$ in lexicographical order: "}, "src_uid": "46253becfda9a45ce670dc7d835beaf3"} {"nl": {"description": "Dima came to the horse land. There are n horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the number of enemies of each horse is at most 3.Right now the horse land is going through an election campaign. So the horses trusted Dima to split them into two parts. At that the horses want the following condition to hold: a horse shouldn't have more than one enemy in its party.Help Dima split the horses into parties. Note that one of the parties can turn out to be empty.", "input_spec": "The first line contains two integers n,\u2009m \u2014 the number of horses in the horse land and the number of enemy pairs. Next m lines define the enemy pairs. The i-th line contains integers ai,\u2009bi (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u2009n;\u00a0ai\u2009\u2260\u2009bi), which mean that horse ai is the enemy of horse bi. Consider the horses indexed in some way from 1 to n. It is guaranteed that each horse has at most three enemies. No pair of enemies occurs more than once in the input.", "output_spec": "Print a line, consisting of n characters: the i-th character of the line must equal \"0\", if the horse number i needs to go to the first party, otherwise this character should equal \"1\". If there isn't a way to divide the horses as required, print -1.", "sample_inputs": ["3 3\n1 2\n3 2\n3 1", "2 1\n2 1", "10 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4"], "sample_outputs": ["100", "00", "0110000000"], "notes": null}, "src_uid": "7017f2c81d5aed716b90e46480f96582"} {"nl": {"description": "There is a binary string $$$t$$$ of length $$$10^{100}$$$, and initally all of its bits are $$$\\texttt{0}$$$. You are given a binary string $$$s$$$, and perform the following operation some times: Select some substring of $$$t$$$, and replace it with its XOR with $$$s$$$.$$$^\\dagger$$$ After several operations, the string $$$t$$$ has exactly two bits $$$\\texttt{1}$$$; that is, there are exactly two distinct indices $$$p$$$ and $$$q$$$ such that the $$$p$$$-th and $$$q$$$-th bits of $$$t$$$ are $$$\\texttt{1}$$$, and the rest of the bits are $$$\\texttt{0}$$$. Find the lexicographically largest$$$^\\ddagger$$$ string $$$t$$$ satisfying these constraints, or report that no such string exists.$$$^\\dagger$$$ Formally, choose an index $$$i$$$ such that $$$0 \\leq i \\leq 10^{100}-|s|$$$. For all $$$1 \\leq j \\leq |s|$$$, if $$$s_j = \\texttt{1}$$$, then toggle $$$t_{i+j}$$$. That is, if $$$t_{i+j}=\\texttt{0}$$$, set $$$t_{i+j}=\\texttt{1}$$$. Otherwise if $$$t_{i+j}=\\texttt{1}$$$, set $$$t_{i+j}=\\texttt{0}$$$.$$$^\\ddagger$$$ A binary string $$$a$$$ is lexicographically larger than a binary string $$$b$$$ of the same length if in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a bit $$$\\texttt{1}$$$ and the corresponding bit in $$$b$$$ is $$$\\texttt{0}$$$.", "input_spec": "The only line of each test contains a single binary string $$$s$$$ ($$$1 \\leq |s| \\leq 35$$$).", "output_spec": "If no string $$$t$$$ exists as described in the statement, output -1. Otherwise, output the integers $$$p$$$ and $$$q$$$ ($$$1 \\leq p < q \\leq 10^{100}$$$) such that the $$$p$$$-th and $$$q$$$-th bits of the lexicographically maximal $$$t$$$ are $$$\\texttt{1}$$$.", "sample_inputs": ["1", "001", "1111", "00000", "00000111110000011111000001111101010"], "sample_outputs": ["1 2", "3 4", "1 5", "-1", "6 37452687"], "notes": "NoteIn the first test, you can perform the following operations. $$$$$$\\texttt{00000}\\ldots \\to \\color{red}{\\texttt{1}}\\texttt{0000}\\ldots \\to \\texttt{1}\\color{red}{\\texttt{1}}\\texttt{000}\\ldots$$$$$$In the second test, you can perform the following operations. $$$$$$\\texttt{00000}\\ldots \\to \\color{red}{\\texttt{001}}\\texttt{00}\\ldots \\to \\texttt{0}\\color{red}{\\texttt{011}}\\texttt{0}\\ldots$$$$$$In the third test, you can perform the following operations. $$$$$$\\texttt{00000}\\ldots \\to \\color{red}{\\texttt{1111}}\\texttt{0}\\ldots \\to \\texttt{1}\\color{red}{\\texttt{0001}}\\ldots$$$$$$It can be proven that these strings $$$t$$$ are the lexicographically largest ones.In the fourth test, you can't make a single bit $$$\\texttt{1}$$$, so it is impossible."}, "src_uid": "6bf798edef30db7d0ce2130e40084e6b"} {"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": "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": "Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and began to perform the following operations: to take two adjacent characters and replace the second character with the first one, to take two adjacent characters and replace the first character with the second one To understand these actions better, let's take a look at a string \u00ababc\u00bb. All of the following strings can be obtained by performing one of the described operations on \u00ababc\u00bb: \u00abbbc\u00bb, \u00ababb\u00bb, \u00abacc\u00bb. Let's denote the frequency of a character for each of the characters a, b and c as the number of occurrences of this character in the string. For example, for string \u00ababc\u00bb: |a| = 1, |b| = 1, |c| = 1, and for string \u00abbbc\u00bb: |a| = 0, |b| = 2, |c| = 1. While performing the described operations, Nick sometimes got balanced strings. Let's say that a string is balanced, if the frequencies of each character differ by at most 1. That is \u2009-\u20091\u2009\u2264\u2009|a|\u2009-\u2009|b|\u2009\u2264\u20091, \u2009-\u20091\u2009\u2264\u2009|a|\u2009-\u2009|c|\u2009\u2264\u20091 \u0438 \u2009-\u20091\u2009\u2264\u2009|b|\u2009-\u2009|c|\u2009\u2264\u20091. Would you help Nick find the number of different balanced strings that can be obtained by performing the operations described above, perhaps multiple times, on the given string s. This number should be calculated modulo 51123987.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009150) \u2014 the length of the given string s. Next line contains the given string s. The initial string can be balanced as well, in this case it should be counted too. The given string s consists only of characters a, b and c.", "output_spec": "Output the only number \u2014 the number of different balanced strings that can be obtained by performing the described operations, perhaps multiple times, on the given string s, modulo 51123987.", "sample_inputs": ["4\nabca", "4\nabbc", "2\nab"], "sample_outputs": ["7", "3", "1"], "notes": "NoteIn the first sample it is possible to get 51 different strings through the described operations, but only 7 of them are balanced: \u00ababca\u00bb, \u00abbbca\u00bb, \u00abbcca\u00bb, \u00abbcaa\u00bb, \u00ababcc\u00bb, \u00ababbc\u00bb, \u00abaabc\u00bb. In the second sample: \u00ababbc\u00bb, \u00abaabc\u00bb, \u00ababcc\u00bb. In the third sample there is only one balanced string \u2014 \u00abab\u00bb itself."}, "src_uid": "64fada10630906e052ff05f2afbf337e"} {"nl": {"description": "You've got a positive integer sequence a1,\u2009a2,\u2009...,\u2009an. All numbers in the sequence are distinct. Let's fix the set of variables b1,\u2009b2,\u2009...,\u2009bm. Initially each variable bi (1\u2009\u2264\u2009i\u2009\u2264\u2009m) contains the value of zero. Consider the following sequence, consisting of n operations.The first operation is assigning the value of a1 to some variable bx (1\u2009\u2264\u2009x\u2009\u2264\u2009m). Each of the following n\u2009-\u20091 operations is assigning to some variable by the value that is equal to the sum of values that are stored in the variables bi and bj (1\u2009\u2264\u2009i,\u2009j,\u2009y\u2009\u2264\u2009m). At that, the value that is assigned on the t-th operation, must equal at. For each operation numbers y,\u2009i,\u2009j are chosen anew.Your task is to find the minimum number of variables m, such that those variables can help you perform the described sequence of operations.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200923). The second line contains n space-separated integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ak\u2009\u2264\u2009109). It is guaranteed that all numbers in the sequence are distinct.", "output_spec": "In a single line print a single number \u2014 the minimum number of variables m, such that those variables can help you perform the described sequence of operations. If you cannot perform the sequence of operations at any m, print -1.", "sample_inputs": ["5\n1 2 3 6 8", "3\n3 6 5", "6\n2 4 8 6 10 18"], "sample_outputs": ["2", "-1", "3"], "notes": "NoteIn the first sample, you can use two variables b1 and b2 to perform the following sequence of operations. b1 := 1; b2 := b1\u2009+\u2009b1; b1 := b1\u2009+\u2009b2; b1 := b1\u2009+\u2009b1; b1 := b1\u2009+\u2009b2. "}, "src_uid": "359f5d1264ce16c5c5293fd59db95628"} {"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 may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the \"decider\" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?", "input_spec": "Input will begin with an integer N (1\u2009\u2264\u2009N\u2009\u2264\u200950), the number of slices of pie. Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.", "output_spec": "Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.", "sample_inputs": ["3\n141 592 653", "5\n10 21 10 21 10"], "sample_outputs": ["653 733", "31 41"], "notes": "NoteIn the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself."}, "src_uid": "414540223db9d4cfcec6a973179a0216"} {"nl": {"description": "International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.You are given a list of abbreviations. For each of them determine the year it stands for.", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000)\u00a0\u2014 the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.", "output_spec": "For each abbreviation given in the input, find the year of the corresponding Olympiad.", "sample_inputs": ["5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0", "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999"], "sample_outputs": ["2015\n12015\n1991\n1989\n1990", "1989\n1999\n2999\n9999"], "notes": null}, "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21"} {"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": "Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i\u2009-\u20091,\u2009a) or to the tab min(i\u2009+\u20091,\u2009b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a,\u2009i\u2009-\u20091] or from segment [i\u2009+\u20091,\u2009b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a\u2009=\u20093, b\u2009=\u20096.What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?", "input_spec": "The only line of input contains four integer numbers n, pos, l, r (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 1\u2009\u2264\u2009pos\u2009\u2264\u2009n, 1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n) \u2014 the number of the tabs, the cursor position and the segment which Luba needs to leave opened.", "output_spec": "Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l,\u2009r].", "sample_inputs": ["6 3 2 4", "6 3 1 3", "5 2 1 5"], "sample_outputs": ["5", "1", "0"], "notes": "NoteIn the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.In the second test she only needs to close all the tabs to the right of the current position of the cursor.In the third test Luba doesn't need to do anything."}, "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"nl": {"description": "Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.", "input_spec": "The first line of the input contains four space-separated positive integer numbers not exceeding 100 \u2014 lengthes of the sticks.", "output_spec": "Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.", "sample_inputs": ["4 2 1 3", "7 2 2 4", "3 5 9 1"], "sample_outputs": ["TRIANGLE", "SEGMENT", "IMPOSSIBLE"], "notes": null}, "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"nl": {"description": "Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1,\u20090) and (x2,\u20090) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009103). The second line contains n distinct integers x1,\u2009x2,\u2009...,\u2009xn (\u2009-\u2009106\u2009\u2264\u2009xi\u2009\u2264\u2009106) \u2014 the i-th point has coordinates (xi,\u20090). The points are not necessarily sorted by their x coordinate.", "output_spec": "In the single line print \"yes\" (without the quotes), if the line has self-intersections. Otherwise, print \"no\" (without the quotes).", "sample_inputs": ["4\n0 10 5 15", "4\n0 15 5 10"], "sample_outputs": ["yes", "no"], "notes": "NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right."}, "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"} {"nl": {"description": "You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.For example, f(\"ab\", \"ba\") = \"aa\", and f(\"nzwzl\", \"zizez\") = \"niwel\".You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x,\u2009z)\u2009=\u2009y, or print -1 if no such string z exists.", "input_spec": "The first line of input contains the string x. The second line of input contains the string y. Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.", "output_spec": "If there is no string z such that f(x,\u2009z)\u2009=\u2009y, print -1. Otherwise, print a string z such that f(x,\u2009z)\u2009=\u2009y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.", "sample_inputs": ["ab\naa", "nzwzl\nniwel", "ab\nba"], "sample_outputs": ["ba", "xiyez", "-1"], "notes": "NoteThe first case is from the statement.Another solution for the second case is \"zizez\"There is no solution for the third case. That is, there is no z such that f(\"ab\", z)\u2009=\u2009 \"ba\"."}, "src_uid": "ce0cb995e18501f73e34c76713aec182"} {"nl": {"description": "Copying large hexadecimal (base 16) strings by hand can be error prone, but that doesn't stop people from doing it. You've discovered a bug in the code that was likely caused by someone making a mistake when copying such a string. You suspect that whoever copied the string did not change any of the digits in the string, nor the length of the string, but may have permuted the digits arbitrarily. For example, if the original string was 0abc they may have changed it to a0cb or 0bca, but not abc or 0abb.Unfortunately you don't have access to the original string nor the copied string, but you do know the length of the strings and their numerical absolute difference. You will be given this difference as a hexadecimal string S, which has been zero-extended to be equal in length to the original and copied strings. Determine the smallest possible numerical value of the original string.", "input_spec": "Input will contain a hexadecimal string S consisting only of digits 0 to 9 and lowercase English letters from a to f, with length at most 14. At least one of the characters is non-zero.", "output_spec": "If it is not possible, print \"NO\" (without quotes). Otherwise, print the lowercase hexadecimal string corresponding to the smallest possible numerical value, including any necessary leading zeros for the length to be correct.", "sample_inputs": ["f1e", "0f1e", "12d2c"], "sample_outputs": ["NO", "00f1", "00314"], "notes": "NoteThe numerical value of a hexadecimal string is computed by multiplying each digit by successive powers of 16, starting with the rightmost digit, which is multiplied by 160. Hexadecimal digits representing values greater than 9 are represented by letters: a\u2009=\u200910,\u2009b\u2009=\u200911,\u2009c\u2009=\u200912,\u2009d\u2009=\u200913,\u2009e\u2009=\u200914,\u2009f\u2009=\u200915.For example, the numerical value of 0f1e is 0\u00b7163\u2009+\u200915\u00b7162\u2009+\u20091\u00b7161\u2009+\u200914\u00b7160\u2009=\u20093870, the numerical value of 00f1 is 0\u00b7163\u2009+\u20090\u00b7162\u2009+\u200915\u00b7161\u2009+\u20091\u00b7160\u2009=\u2009241, and the numerical value of 100f is 1\u00b7163\u2009+\u20090\u00b7162\u2009+\u20090\u00b7161\u2009+\u200915\u00b7160\u2009=\u20094111. Since 3870\u2009+\u2009241\u2009=\u20094111 and 00f1 is a permutation of 100f, 00f1 is a valid answer to the second test case."}, "src_uid": "7fab93f1307159262fcc6044ecba6284"} {"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": "A sequence of non-negative integers a1,\u2009a2,\u2009...,\u2009an of length n is called a wool sequence if and only if there exists two integers l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n) such that . In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0.The expression means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as \"^\", in Pascal \u2014 as \"xor\".In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m\u2009-\u20091 that are not a wool sequence. You should print this number modulo 1000000009 (109\u2009+\u20099).", "input_spec": "The only line of input contains two space-separated integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105).", "output_spec": "Print the required number of sequences modulo 1000000009 (109\u2009+\u20099) on the only line of output.", "sample_inputs": ["3 2"], "sample_outputs": ["6"], "notes": "NoteSequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3)."}, "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8"} {"nl": {"description": "Vasya plays Robot Bicorn Attack.The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.", "input_spec": "The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.", "output_spec": "Print the only number \u2014 the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.", "sample_inputs": ["1234", "9000", "0009"], "sample_outputs": ["37", "90", "-1"], "notes": "NoteIn the first example the string must be split into numbers 1, 2 and 34.In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes."}, "src_uid": "bf4e72636bd1998ad3d034ad72e63097"} {"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": "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": "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": "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": "Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. A sequence of positive integers bi is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence bi which minimizes the following expression:You are given sequence ai, help Princess Twilight to find the key.", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of elements of the sequences a and b. The next line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u200930).", "output_spec": "Output the key \u2014 sequence bi that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them.", "sample_inputs": ["5\n1 1 1 1 1", "5\n1 6 4 2 8"], "sample_outputs": ["1 1 1 1 1", "1 5 3 1 8"], "notes": null}, "src_uid": "f26c74f27bbc723efd69c38ad0e523c6"} {"nl": {"description": "Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored A\u00b7B\u00b7C hay blocks and stored them in a barn as a rectangular parallelepiped A layers high. Each layer had B rows and each row had C blocks.At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (A\u2009-\u20091)\u2009\u00d7\u2009(B\u2009-\u20092)\u2009\u00d7\u2009(C\u2009-\u20092) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1\u2009\u00d7\u20091\u2009\u00d7\u20091 blocks and scattered them around the barn. After the theft Sam counted n hay blocks in the barn but he forgot numbers A, B \u0438 C.Given number n, find the minimally possible and maximally possible number of stolen hay blocks.", "input_spec": "The only line contains integer n from the problem's statement (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specificator.", "sample_inputs": ["4", "7", "12"], "sample_outputs": ["28 41", "47 65", "48 105"], "notes": "NoteLet's consider the first sample test. If initially Sam has a parallelepiped consisting of 32\u2009=\u20092\u2009\u00d7\u20094\u2009\u00d7\u20094 hay blocks in his barn, then after the theft the barn has 4\u2009=\u2009(2\u2009-\u20091)\u2009\u00d7\u2009(4\u2009-\u20092)\u2009\u00d7\u2009(4\u2009-\u20092) hay blocks left. Thus, the thieves could have stolen 32\u2009-\u20094\u2009=\u200928 hay blocks. If Sam initially had a parallelepiped consisting of 45\u2009=\u20095\u2009\u00d7\u20093\u2009\u00d7\u20093 hay blocks in his barn, then after the theft the barn has 4\u2009=\u2009(5\u2009-\u20091)\u2009\u00d7\u2009(3\u2009-\u20092)\u2009\u00d7\u2009(3\u2009-\u20092) hay blocks left. Thus, the thieves could have stolen 45\u2009-\u20094\u2009=\u200941 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks."}, "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7"} {"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": "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": "Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x\u00b7a\u2009+\u2009y\u00b7b\u2009=\u2009n or tell that it's impossible.", "input_spec": "First line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200910\u2009000\u2009000)\u00a0\u2014 amount of money, that Vasya has. Second line contains single integer a (1\u2009\u2264\u2009a\u2009\u2264\u200910\u2009000\u2009000)\u00a0\u2014 cost of one bottle of Ber-Cola. Third line contains single integer b (1\u2009\u2264\u2009b\u2009\u2264\u200910\u2009000\u2009000)\u00a0\u2014 cost of one Bars bar.", "output_spec": "If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print \u00abNO\u00bb (without quotes). Otherwise in first line print \u00abYES\u00bb (without quotes). In second line print two non-negative integers x and y\u00a0\u2014 number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x\u00b7a\u2009+\u2009y\u00b7b\u2009=\u2009n. If there are multiple answers print any of them. Any of numbers x and y can be equal 0.", "sample_inputs": ["7\n2\n3", "100\n25\n10", "15\n4\n8", "9960594\n2551\n2557"], "sample_outputs": ["YES\n2 1", "YES\n0 10", "NO", "YES\n1951 1949"], "notes": "NoteIn first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2\u00b72\u2009+\u20091\u00b73\u2009=\u20097 burles.In second example Vasya can spend exactly n burles multiple ways: buy two bottles of Ber-Cola and five Bars bars; buy four bottles of Ber-Cola and don't buy Bars bars; don't buy Ber-Cola and buy 10 Bars bars. In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles."}, "src_uid": "b031daf3b980e03218167f40f39e7b01"} {"nl": {"description": "Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a,\u2009b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points. After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20095\u00b7105) \u2014 the number of elements in the array. The next line contains n integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009106) \u2014 the values of the array elements.", "output_spec": "In a single line print a single integer \u2014 the maximum number of points Artem can get.", "sample_inputs": ["5\n3 1 5 2 6", "5\n1 2 3 4 5", "5\n1 100 101 100 1"], "sample_outputs": ["11", "6", "102"], "notes": null}, "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1"} {"nl": {"description": "Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppose that Masha's phone number is 12345. After that one should write her favorite digit from 0 to 9 under the first digit of her number. That will be the first digit of the needed number. For example, Masha's favorite digit is 9. The second digit is determined as a half sum of the second digit of Masha's number and the already written down first digit from her beloved one's number. In this case the arithmetic average equals to (2\u2009+\u20099)\u2009/\u20092\u2009=\u20095.5. Masha can round the number up or down, depending on her wishes. For example, she chooses the digit 5. Having written down the resulting digit under the second digit of her number, Masha moves to finding the third digit in the same way, i.e. finding the half sum the the third digit of her number and the second digit of the new number. The result is (5\u2009+\u20093)\u2009/\u20092\u2009=\u20094. In this case the answer is unique. Thus, every i-th digit is determined as an arithmetic average of the i-th digit of Masha's number and the i\u2009-\u20091-th digit of her true love's number. If needed, the digit can be rounded up or down. For example, Masha can get: 12345 95444 Unfortunately, when Masha tried dialing the number, she got disappointed: as it turned out, the number was unavailable or outside the coverage area. But Masha won't give up. Perhaps, she rounded to a wrong digit or chose the first digit badly. That's why she keeps finding more and more new numbers and calling them. Count the number of numbers Masha calls. Masha calls all the possible numbers that can be found by the described means of arithmancy, except for, perhaps, her own one.", "input_spec": "The first line contains nonempty sequence consisting of digits from 0 to 9 \u2014 Masha's phone number. The sequence length does not exceed 50.", "output_spec": "Output the single number \u2014 the number of phone numbers Masha will dial.", "sample_inputs": ["12345", "09"], "sample_outputs": ["48", "15"], "notes": null}, "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b"} {"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": "Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good. Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, m icons can fit in a horizontal row in any window.Igor K.'s computer contains n folders in the D: disk's root catalog. The folders are numbered from 1 to n in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from a to b inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from a to b and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.", "input_spec": "The only line contains four integers n, m, a, b (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009109, 1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009n). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.", "output_spec": "Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from a to b.", "sample_inputs": ["11 4 3 9", "20 5 2 20"], "sample_outputs": ["3", "2"], "notes": "NoteThe images below illustrate statement tests.The first test:In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.The second test:In this test we can first select all folders in the first row (2, 3, 4, 5), then \u2014 all other ones."}, "src_uid": "f256235c0b2815aae85a6f9435c69dac"} {"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": "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": "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": "As we all know, Dart is some kind of creature from Upside Down world. For simplicity, we call their kind pollywogs. Dart and x\u2009-\u20091 other pollywogs are playing a game. There are n stones in a row, numbered from 1 through n from left to right. At most 1 pollywog may be sitting on each stone at a time. Initially, the pollywogs are sitting on the first x stones (one pollywog on each stone). Dart and his friends want to end up on the last x stones. At each second, the leftmost pollywog should jump to the right. A pollywog can jump at most k stones; more specifically, a pollywog can jump from stone number i to stones i\u2009+\u20091,\u2009i\u2009+\u20092,\u2009... i\u2009+\u2009k. A pollywog can't jump on an occupied stone. Jumping a distance i takes ci amounts of energy from the pollywog. Also, q stones are special Each time landing on a special stone p, takes wp amounts of energy (in addition to the energy for jump) from the pollywog. wp could be negative, in this case, it means the pollywog absorbs |wp| amounts of energy.Pollywogs want to spend as little energy as possible (this value could be negative). They're just pollywogs, so they asked for your help. Tell them the total change in their energy, in case they move optimally.", "input_spec": "The first line of input contains four integers, x,\u2009k,\u2009n and q (1\u2009\u2264\u2009x\u2009\u2264\u2009k\u2009\u2264\u20098, k\u2009\u2264\u2009n\u2009\u2264\u2009108, 0\u2009\u2264\u2009q\u2009\u2264\u2009min(25,\u2009n\u2009-\u2009x))\u00a0\u2014 the number of pollywogs, the maximum length of jump, the number of stones and the number of special stones. The next line contains k integers, c1,\u2009c2,\u2009... ck, separated by spaces (1\u2009\u2264\u2009ci\u2009\u2264\u2009109)\u00a0\u2014 the energetic costs of jumps. The next q lines contain description of the special stones. Each line contains two integers p and wp (x\u2009+\u20091\u2009\u2264\u2009p\u2009\u2264\u2009n, |wp|\u2009\u2264\u2009109). All p are distinct.", "output_spec": "Print the minimum amount of energy they need, in the first and only line of output.", "sample_inputs": ["2 3 10 2\n1 2 3\n5 -10\n6 1000", "4 7 85 3\n17 5 28 4 52 46 6\n59 -76\n33 -69\n19 2018"], "sample_outputs": ["6", "135"], "notes": null}, "src_uid": "e3dd409ceeba2a21890d35ceab9607eb"} {"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": "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": "The elections to Berland parliament are happening today. Voting is in full swing!Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1\u2009\u2264\u2009k\u2009\u2264\u2009n) top candidates will take seats in the parliament.After the end of the voting the number of votes for each candidate is calculated. In the resulting table the candidates are ordered by the number of votes. In case of tie (equal number of votes) they are ordered by the time of the last vote given. The candidate with ealier last vote stands higher in the resulting table.So in the resulting table candidates are sorted by the number of votes (more votes stand for the higher place) and if two candidates have equal number of votes they are sorted by the time of last vote (earlier last vote stands for the higher place).There is no way for a candidate with zero votes to take a seat in the parliament. So it is possible that less than k candidates will take a seat in the parliament.In Berland there are m citizens who can vote. Each of them will vote for some candidate. Each citizen will give a vote to exactly one of n candidates. There is no option \"against everyone\" on the elections. It is not accepted to spoil bulletins or not to go to elections. So each of m citizens will vote for exactly one of n candidates.At the moment a citizens have voted already (1\u2009\u2264\u2009a\u2009\u2264\u2009m). This is an open election, so for each citizen it is known the candidate for which the citizen has voted. Formally, the j-th citizen voted for the candidate gj. The citizens who already voted are numbered in chronological order; i.e. the (j\u2009+\u20091)-th citizen voted after the j-th.The remaining m\u2009-\u2009a citizens will vote before the end of elections, each of them will vote for one of n candidates.Your task is to determine for each of n candidates one of the three possible outcomes: a candidate will be elected to the parliament regardless of votes of the remaining m\u2009-\u2009a citizens; a candidate has chance to be elected to the parliament after all n citizens have voted; a candidate has no chances to be elected to the parliament regardless of votes of the remaining m\u2009-\u2009a citizens. ", "input_spec": "The first line contains four integers n, k, m and a (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009100, 1\u2009\u2264\u2009m\u2009\u2264\u2009100, 1\u2009\u2264\u2009a\u2009\u2264\u2009m) \u2014 the number of candidates, the number of seats in the parliament, the number of Berland citizens and the number of citizens who already have voted. The second line contains a sequence of a integers g1,\u2009g2,\u2009...,\u2009ga (1\u2009\u2264\u2009gj\u2009\u2264\u2009n), where gj is the candidate for which the j-th citizen has voted. Citizens who already voted are numbered in increasing order of voting times.", "output_spec": "Print the sequence consisting of n integers r1,\u2009r2,\u2009...,\u2009rn where: ri\u2009=\u20091 means that the i-th candidate is guaranteed to take seat in the parliament regardless of votes of the remaining m\u2009-\u2009a citizens; ri\u2009=\u20092 means that the i-th candidate has a chance to take a seat in the parliament, i.e. the remaining m\u2009-\u2009a citizens can vote in such a way that the candidate will take a seat in the parliament; ri\u2009=\u20093 means that the i-th candidate will not take a seat in the parliament regardless of votes of the remaining m\u2009-\u2009a citizens. ", "sample_inputs": ["3 1 5 4\n1 2 1 3", "3 1 5 3\n1 3 1", "3 2 5 3\n1 3 1"], "sample_outputs": ["1 3 3", "2 3 2", "1 2 2"], "notes": null}, "src_uid": "81a890bd542963bbcec7a041dde5c247"} {"nl": {"description": "It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n\u2009\u00d7\u2009m centimeters (each cell is 1\u2009\u00d7\u20091 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.The flea can count the amount of cells that she can reach from the starting position (x,\u2009y). Let's denote this amount by dx,\u2009y. Your task is to find the number of such starting positions (x,\u2009y), which have the maximum possible value of dx,\u2009y.", "input_spec": "The first line contains three integers n, m, s (1\u2009\u2264\u2009n,\u2009m,\u2009s\u2009\u2264\u2009106) \u2014 length of the board, width of the board and length of the flea's jump.", "output_spec": "Output the only integer \u2014 the number of the required starting positions of the flea.", "sample_inputs": ["2 3 1000000", "3 3 2"], "sample_outputs": ["6", "4"], "notes": null}, "src_uid": "e853733fb2ed87c56623ff9a5ac09c36"} {"nl": {"description": "It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as pi the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i,\u2009j) such that i\u2009<\u2009j and pi\u2009>\u2009pj.", "input_spec": "The first line of the input contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the number of cows and the length of Farmer John's nap, respectively.", "output_spec": "Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps. ", "sample_inputs": ["5 2", "1 10"], "sample_outputs": ["10", "0"], "notes": "NoteIn the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.In the second sample, there is only one cow, so the maximum possible messiness is 0."}, "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"} {"nl": {"description": "In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side.One example of a grid path is (0,\u20090)\u2009\u2192\u2009(0,\u20091)\u2009\u2192\u2009(0,\u20092)\u2009\u2192\u2009(1,\u20092)\u2009\u2192\u2009(1,\u20091)\u2009\u2192\u2009(0,\u20091)\u2009\u2192\u2009(\u2009-\u20091,\u20091). Note that squares in this sequence might be repeated, i.e. path has self intersections.Movement within a grid path is restricted to adjacent squares within the sequence. That is, from the i-th square, one can only move to the (i\u2009-\u20091)-th or (i\u2009+\u20091)-th squares of this path. Note that there is only a single valid move from the first and last squares of a grid path. Also note, that even if there is some j-th square of the path that coincides with the i-th square, only moves to (i\u2009-\u20091)-th and (i\u2009+\u20091)-th squares are available. For example, from the second square in the above sequence, one can only move to either the first or third squares.To ensure that movement is not ambiguous, the two grid paths will not have an alternating sequence of three squares. For example, a contiguous subsequence (0,\u20090)\u2009\u2192\u2009(0,\u20091)\u2009\u2192\u2009(0,\u20090) cannot occur in a valid grid path.One marble is placed on the first square of each grid path. Genos wants to get both marbles to the last square of each grid path. However, there is a catch. Whenever he moves one marble, the other marble will copy its movement if possible. For instance, if one marble moves east, then the other marble will try and move east as well. By try, we mean if moving east is a valid move, then the marble will move east.Moving north increases the second coordinate by 1, while moving south decreases it by 1. Similarly, moving east increases first coordinate by 1, while moving west decreases it.Given these two valid grid paths, Genos wants to know if it is possible to move both marbles to the ends of their respective paths. That is, if it is possible to move the marbles such that both marbles rest on the last square of their respective paths.", "input_spec": "The first line of the input contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u20091\u2009000\u2009000)\u00a0\u2014 the length of the paths. The second line of the input contains a string consisting of n\u2009-\u20091 characters (each of which is either 'N', 'E', 'S', or 'W')\u00a0\u2014 the first grid path. The characters can be thought of as the sequence of moves needed to traverse the grid path. For example, the example path in the problem statement can be expressed by the string \"NNESWW\". The third line of the input contains a string of n\u2009-\u20091 characters (each of which is either 'N', 'E', 'S', or 'W')\u00a0\u2014 the second grid path.", "output_spec": "Print \"YES\" (without quotes) if it is possible for both marbles to be at the end position at the same time. Print \"NO\" (without quotes) otherwise. In both cases, the answer is case-insensitive.", "sample_inputs": ["7\nNNESWW\nSWSWSW", "3\nNN\nSS"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample, the first grid path is the one described in the statement. Moreover, the following sequence of moves will get both marbles to the end: NNESWWSWSW.In the second sample, no sequence of moves can get both marbles to the end."}, "src_uid": "85f43628bec7e9b709273c34b894df6b"} {"nl": {"description": "Golorps are mysterious creatures who feed on variables. Golorp's name is a program in some programming language. Some scientists believe that this language is Befunge; golorps are tantalizingly silent.Variables consumed by golorps can take values from 0 to 9, inclusive. For each golorp its daily diet is defined by its name. Some golorps are so picky that they can't be fed at all. Besides, all golorps are very health-conscious and try to eat as little as possible. Given a choice of several valid sequences of variable values, each golorp will choose lexicographically smallest one.For the purposes of this problem you can assume that a golorp consists of jaws and a stomach. The number of variables necessary to feed a golorp is defined by the shape of its jaws. Variables can get to the stomach only via the jaws.A hungry golorp is visiting you. You know its name; feed it or figure out that it's impossible.", "input_spec": "The input is a single string (between 13 and 1024 characters long) \u2014 the name of the visiting golorp. All names are similar and will resemble the ones given in the samples. The name is guaranteed to be valid.", "output_spec": "Output lexicographically smallest sequence of variable values fit for feeding this golorp. Values should be listed in the order in which they get into the jaws. If the golorp is impossible to feed, output \"false\".", "sample_inputs": ["?(_-_/___*__):-___>__.", "?(__-_+_/_____):-__>__,_____<__.", "?(______________________/____+_______*__-_____*______-___):-__<___,___<____,____<_____,_____<______,______<_______.", "?(__+___+__-___):-___>__."], "sample_outputs": ["0010", "false", "0250341", "0101"], "notes": null}, "src_uid": "390a0b72c77ebe5881b656830fbfae02"} {"nl": {"description": "Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.", "input_spec": "The first line contains four space-separated integers s1,\u2009s2,\u2009s3,\u2009s4 (1\u2009\u2264\u2009s1,\u2009s2,\u2009s3,\u2009s4\u2009\u2264\u2009109) \u2014 the colors of horseshoes Valera has. Consider all possible colors indexed with integers.", "output_spec": "Print a single integer \u2014 the minimum number of horseshoes Valera needs to buy.", "sample_inputs": ["1 7 3 3", "7 7 7 7"], "sample_outputs": ["1", "3"], "notes": null}, "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"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": "There is a computer network consisting of n nodes numbered 1 through n. There are links in the network that connect pairs of nodes. A pair of nodes may have multiple links between them, but no node has a link to itself.Each link supports unlimited bandwidth (in either direction), however a link may only transmit in a single direction at any given time. The cost of sending data across a link is proportional to the square of the bandwidth. Specifically, each link has a positive weight, and the cost of sending data across the link is the weight times the square of the bandwidth.The network is connected (there is a series of links from any node to any other node), and furthermore designed to remain connected in the event of any single node failure.You needed to send data from node 1 to node n at a bandwidth of some positive number k. That is, you wish to assign a bandwidth to each link so that the bandwidth into a node minus the bandwidth out of a node is \u2009-\u2009k for node 1, k for node n, and 0 for all other nodes. The individual bandwidths do not need to be integers.Wishing to minimize the total cost, you drew a diagram of the network, then gave the task to an intern to solve. The intern claimed to have solved the task and written the optimal bandwidths on your diagram, but then spilled coffee on it, rendering much of it unreadable (including parts of the original diagram, and the value of k).From the information available, determine if the intern's solution may have been optimal. That is, determine if there exists a valid network, total bandwidth, and optimal solution which is a superset of the given information. Furthermore, determine the efficiency of the intern's solution (if possible), where efficiency is defined as total cost divided by total bandwidth.", "input_spec": "Input will begin with two integers n and m (2\u2009\u2264\u2009n\u2009\u2264\u2009200000; 0\u2009\u2264\u2009m\u2009\u2264\u2009200000), the number of nodes and number of known links in the network, respectively. Following this are m lines with four integers each: f, t, w, b (1\u2009\u2264\u2009f\u2009\u2264\u2009n;\u00a01\u2009\u2264\u2009t\u2009\u2264\u2009n;\u00a0f\u2009\u2260\u2009t;\u00a01\u2009\u2264\u2009w\u2009\u2264\u2009100;\u00a00\u2009\u2264\u2009b\u2009\u2264\u2009100). This indicates there is a link between nodes f and t with weight w and carrying b bandwidth. The direction of bandwidth is from f to t.", "output_spec": "If the intern's solution is definitely not optimal, print \"BAD x\", where x is the first link in the input that violates the optimality of the solution. If the intern's solution may be optimal, print the efficiency of the solution if it can be determined rounded to the nearest integer, otherwise print \"UNKNOWN\".", "sample_inputs": ["4 5\n1 2 1 2\n1 3 4 1\n2 3 2 1\n2 4 4 1\n3 4 1 2", "5 5\n2 3 1 1\n3 4 1 1\n4 2 1 1\n1 5 1 1\n1 5 100 100", "6 4\n1 3 31 41\n1 5 59 26\n2 6 53 58\n4 6 97 93", "7 5\n1 7 2 1\n2 3 1 1\n4 5 1 0\n6 1 10 0\n1 3 1 1"], "sample_outputs": ["6", "BAD 3", "UNKNOWN", "BAD 4"], "notes": "NoteAlthough the known weights and bandwidths happen to always be integers, the weights and bandwidths of the remaining links are not restricted to integers."}, "src_uid": "b047916b7d99bc34a64ad41f43a37bf0"} {"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": "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": "The Prodiggers are quite a cool band and for this reason, they have been the surprise guest at the ENTER festival for the past 80 years. At the beginning of their careers, they weren\u2019t so successful, so they had to spend time digging channels to earn money; hence the name. Anyway, they like to tour a lot and have surprising amounts of energy to do extremely long tours. However, they hate spending two consecutive days without having a concert, so they would like to avoid it.A tour is defined by a sequence of concerts and days-off. You need to count in how many ways The Prodiggers can select k different tours of the same length between l and r.For example if k\u2009=\u20092, l\u2009=\u20091 and r\u2009=\u20092, if we define concert day as {1} and day-off as {0}, here are all possible tours: {0}, {1}, {00}, {01}, {10}, {11}. But tour 00 can not be selected because it has 2 days-off in a row. Now, we need to count in how many ways we can select k\u2009=\u20092 tours of the same length in range [1;2]. Here they are: {0,1}; {01,10}; {01,11}; {10,11}.Since their schedule is quite busy, they want you to tell them in how many ways can do that, modulo 1\u2009000\u2009000\u2009007 (109\u2009+\u20097).", "input_spec": "The first line of the input contains three integers k, l and r (1\u2009\u2264\u2009k\u2009\u2264\u2009200, 1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20091018).", "output_spec": "Output a single number: the number of ways to select k different tours of the same length, modulo 1\u2009000\u2009000\u2009007.", "sample_inputs": ["1 1 2"], "sample_outputs": ["5"], "notes": null}, "src_uid": "dee552588e1281c2523868cd4090b46f"} {"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": "In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong \u2014 the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure \u2014 and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus \u2014 Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem \u00abheight\u00bb stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?", "input_spec": "The input data contains two space-separated positive integer numbers n and h (n\u2009\u2264\u200935, h\u2009\u2264\u2009n).", "output_spec": "Output one number \u2014 the answer to the problem. It is guaranteed that it does not exceed 9\u00b71018.", "sample_inputs": ["3 2", "3 3"], "sample_outputs": ["5", "4"], "notes": null}, "src_uid": "faf12a603d0c27f8be6bf6b02531a931"} {"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": "You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.Your task is to find such minimum number v, that you can form presents using numbers from a set 1,\u20092,\u2009...,\u2009v. Of course you may choose not to present some numbers at all.A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.", "input_spec": "The only line contains four positive integers cnt1, cnt2, x, y (1\u2009\u2264\u2009cnt1,\u2009cnt2\u2009<\u2009109; cnt1\u2009+\u2009cnt2\u2009\u2264\u2009109; 2\u2009\u2264\u2009x\u2009<\u2009y\u2009\u2264\u20093\u00b7104)\u00a0\u2014 the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["3 1 2 3", "1 3 2 3"], "sample_outputs": ["5", "4"], "notes": "NoteIn the first sample you give the set of numbers {1,\u20093,\u20095} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1,\u20093,\u20095} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend. In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1,\u20092,\u20094} to the second friend. Thus, the answer to the problem is 4."}, "src_uid": "ff3c39b759a049580a6e96c66c904fdc"} {"nl": {"description": "There is a square box 6\u2009\u00d7\u20096 in size. It contains 36 chips 1\u2009\u00d7\u20091 in size. Those chips contain 36 different characters \u2014 \"0\"-\"9\" and \"A\"-\"Z\". There is exactly one chip with each character.You are allowed to make the following operations: you may choose one of 6 rows or one of 6 columns and cyclically shift the chips there to one position to the left or to the right (for the row) or upwards or downwards (for the column). Those operations are allowed to perform several times. To solve the puzzle is to shift the chips using the above described operations so that they were written in the increasing order (exactly equal to the right picture). An example of solving the puzzle is shown on a picture below. Write a program that finds the sequence of operations that solves the puzzle. That sequence should not necessarily be shortest, but you should not exceed the limit of 10000 operations. It is guaranteed that the solution always exists.", "input_spec": "The input data are represented by 6 lines containing 6 characters each. They are the puzzle's initial position. Those lines contain each character from the string \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\" exactly once.", "output_spec": "On the first line print number n, which is the number of operations. On the next n lines print the sequence of operations one per line. An operation is described by a word consisting of two characters. The first character shows the direction where the row or the column will be shifted. The possible directions are \"L\", \"R\" (to the left, to the right correspondingly, we shift a row), \"U\", \"D\" (upwards, downwards correspondingly, we shift a column). The second character is the number of the row (or the column), it is an integer from \"1\" to \"6\". The rows are numbered from the top to the bottom, the columns are numbered from the left to the right. The number of operations should not exceed 104. If there are several solutions, print any of them.", "sample_inputs": ["01W345\n729AB6\nCD8FGH\nIJELMN\nOPKRST\nUVQXYZ"], "sample_outputs": ["2\nR2\nU3"], "notes": null}, "src_uid": "10b2c1c53580dd382c41a56f7413e709"} {"nl": {"description": "You are given two integers $$$n$$$ and $$$k$$$.You need to construct $$$k$$$ regular polygons having same circumcircle, with distinct number of sides $$$l$$$ between $$$3$$$ and $$$n$$$. Illustration for the first example. You can rotate them to minimize the total number of distinct points on the circle. Find the minimum number of such points.", "input_spec": "The only line of input contains two integers $$$n$$$ and $$$k$$$ ($$$3 \\le n \\le 10^{6}$$$, $$$1 \\le k \\le n-2$$$), the maximum number of sides of a polygon and the number of polygons to construct, respectively.", "output_spec": "Print a single integer \u2014 the minimum number of points required for $$$k$$$ polygons.", "sample_inputs": ["6 2", "200 50"], "sample_outputs": ["6", "708"], "notes": "NoteIn the first example, we have $$$n = 6$$$ and $$$k = 2$$$. So, we have $$$4$$$ polygons with number of sides $$$3$$$, $$$4$$$, $$$5$$$ and $$$6$$$ to choose from and if we choose the triangle and the hexagon, then we can arrange them as shown in the picture in the statement.Hence, the minimum number of points required on the circle is $$$6$$$, which is also the minimum overall possible sets."}, "src_uid": "c2f7012082c84d773c2f4b1858c17110"} {"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": "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 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": "You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than ai times; the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. ", "input_spec": "The first line of the input contains a single integer n (2\u2009\u2009\u2264\u2009\u2009n\u2009\u2009\u2264\u2009\u200926)\u00a0\u2014 the number of letters in the alphabet. The next line contains n integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009109)\u00a0\u2014 i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.", "output_spec": "Print a single integer \u2014 the maximum length of the string that meets all the requirements.", "sample_inputs": ["3\n2 5 5", "3\n1 1 2"], "sample_outputs": ["11", "3"], "notes": "NoteFor convenience let's consider an alphabet consisting of three letters: \"a\", \"b\", \"c\". In the first sample, some of the optimal strings are: \"cccaabbccbb\", \"aabcbcbcbcb\". In the second sample some of the optimal strings are: \"acc\", \"cbc\"."}, "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"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 social website with n fanpages, numbered 1 through n. There are also n companies, and the i-th company owns the i-th fanpage.Recently, the website created a feature called following. Each fanpage must choose exactly one other fanpage to follow.The website doesn\u2019t allow a situation where i follows j and at the same time j follows i. Also, a fanpage can't follow itself.Let\u2019s say that fanpage i follows some other fanpage j0. Also, let\u2019s say that i is followed by k other fanpages j1,\u2009j2,\u2009...,\u2009jk. Then, when people visit fanpage i they see ads from k\u2009+\u20092 distinct companies: i,\u2009j0,\u2009j1,\u2009...,\u2009jk. Exactly ti people subscribe (like) the i-th fanpage, and each of them will click exactly one add. For each of k\u2009+\u20091 companies j0,\u2009j1,\u2009...,\u2009jk, exactly people will click their ad. Remaining people will click an ad from company i (the owner of the fanpage).The total income of the company is equal to the number of people who click ads from this copmany.Limak and Radewoosh ask you for help. Initially, fanpage i follows fanpage fi. Your task is to handle q queries of three types: 1 i j\u00a0\u2014 fanpage i follows fanpage j from now. It's guaranteed that i didn't follow j just before the query. Note an extra constraint for the number of queries of this type (below, in the Input section). 2 i\u00a0\u2014 print the total income of the i-th company. 3\u00a0\u2014 print two integers: the smallest income of one company and the biggest income of one company. ", "input_spec": "The first line of the input contains two integers n and q (3\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000, 1\u2009\u2264\u2009q\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the number of fanpages and the number of queries, respectively. The second line contains n integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20091012) where ti denotes the number of people subscribing the i-th fanpage. The third line contains n integers f1,\u2009f2,\u2009...,\u2009fn (1\u2009\u2264\u2009fi\u2009\u2264\u2009n). Initially, fanpage i follows fanpage fi. Then, q lines follow. The i-th of them describes the i-th query. The first number in the line is an integer typei (1\u2009\u2264\u2009typei\u2009\u2264\u20093)\u00a0\u2014 the type of the query. There will be at most 50\u2009000 queries of the first type. There will be at least one query of the second or the third type (so, the output won't be empty). It's guaranteed that at each moment a fanpage doesn't follow itself, and that no two fanpages follow each other.", "output_spec": "For each query of the second type print one integer in a separate line - the total income of the given company. For each query of the third type print two integers in a separate line - the minimum and the maximum total income, respectively.", "sample_inputs": ["5 12\n10 20 30 40 50\n2 3 4 5 2\n2 1\n2 2\n2 3\n2 4\n2 5\n1 4 2\n2 1\n2 2\n2 3\n2 4\n2 5\n3"], "sample_outputs": ["10\n36\n28\n40\n36\n9\n57\n27\n28\n29\n9 57"], "notes": "Note In the sample test, there are 5 fanpages. The i-th of them has i\u00b710 subscribers.On drawings, numbers of subscribers are written in circles. An arrow from A to B means that A follows B.The left drawing shows the initial situation. The first company gets income from its own fanpage, and gets income from the 2-nd fanpage. So, the total income is 5\u2009+\u20095\u2009=\u200910. After the first query (\"2 1\") you should print 10.The right drawing shows the situation after a query \"1 4 2\" (after which fanpage 4 follows fanpage 2). Then, the first company still gets income 5 from its own fanpage, but now it gets only from the 2-nd fanpage. So, the total income is 5\u2009+\u20094\u2009=\u20099 now."}, "src_uid": "6a17d93dad158f70a36905206aa0ba3b"} {"nl": {"description": "You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.", "input_spec": "The only line contains three integers l, r and a (0\u2009\u2264\u2009l,\u2009r,\u2009a\u2009\u2264\u2009100) \u2014 the number of left-handers, the number of right-handers and the number of ambidexters at the training. ", "output_spec": "Print a single even integer\u00a0\u2014 the maximum number of players in the team. It is possible that the team can only have zero number of players.", "sample_inputs": ["1 4 2", "5 5 5", "0 2 0"], "sample_outputs": ["6", "14", "0"], "notes": "NoteIn the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand."}, "src_uid": "e8148140e61baffd0878376ac5f3857c"} {"nl": {"description": "You are given an undirected graph where each edge has one of two colors: black or red.Your task is to assign a real number to each node so that: for each black edge the sum of values at its endpoints is $$$1$$$; for each red edge the sum of values at its endpoints is $$$2$$$; the sum of the absolute values of all assigned numbers is the smallest possible. Otherwise, if it is not possible, report that there is no feasible assignment of the numbers.", "input_spec": "The first line contains two integers $$$N$$$ ($$$1 \\leq N \\leq 100\\,000$$$) and $$$M$$$ ($$$0 \\leq M \\leq 200\\,000$$$): the number of nodes and the number of edges, respectively. The nodes are numbered by consecutive integers: $$$1, 2, \\ldots, N$$$. The next $$$M$$$ lines describe the edges. Each line contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ denoting that there is an edge between nodes $$$a$$$ and $$$b$$$ ($$$1 \\leq a, b \\leq N$$$) with color $$$c$$$ ($$$1$$$ denotes black, $$$2$$$ denotes red).", "output_spec": "If there is a solution, the first line should contain the word \"YES\" and the second line should contain $$$N$$$ space-separated numbers. For each $$$i$$$ ($$$1 \\le i \\le N$$$), the $$$i$$$-th number should be the number assigned to the node $$$i$$$. Output should be such that: the sum of the numbers at the endpoints of each edge differs from the precise value by less than $$$10^{-6}$$$; the sum of the absolute values of all assigned numbers differs from the smallest possible by less than $$$10^{-6}$$$. If there are several valid solutions, output any of them. If there is no solution, the only line should contain the word \"NO\".", "sample_inputs": ["4 4\n1 2 1\n2 3 2\n1 3 2\n3 4 1", "2 1\n1 2 1", "3 2\n1 2 2\n2 3 2", "3 4\n1 2 2\n2 2 1\n2 1 1\n1 2 2"], "sample_outputs": ["YES\n0.5 0.5 1.5 -0.5", "YES\n0.3 0.7", "YES\n0 2 0", "NO"], "notes": "NoteNote that in the second example the solution is not unique."}, "src_uid": "791cbe2700b11e9dd9a442de3ef913f8"} {"nl": {"description": "You successfully found poor Arkady near the exit of the station you've perfectly predicted. You sent him home on a taxi and suddenly came up with a question.There are $$$n$$$ crossroads in your city and several bidirectional roads connecting some of them. A taxi ride is a path from some crossroads to another one without passing the same crossroads twice. You have a collection of rides made by one driver and now you wonder if this driver can be a robot or they are definitely a human.You think that the driver can be a robot if for every two crossroads $$$a$$$ and $$$b$$$ the driver always chooses the same path whenever he drives from $$$a$$$ to $$$b$$$. Note that $$$a$$$ and $$$b$$$ here do not have to be the endpoints of a ride and that the path from $$$b$$$ to $$$a$$$ can be different. On the contrary, if the driver ever has driven two different paths from $$$a$$$ to $$$b$$$, they are definitely a human.Given the system of roads and the description of all rides available to you, determine if the driver can be a robot or not.", "input_spec": "Each test contains one or more test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 3 \\cdot 10^5$$$)\u00a0\u2014 the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 3 \\cdot 10^5$$$)\u00a0\u2014 the number of crossroads in the city. The next line contains a single integer $$$q$$$ ($$$1 \\le q \\le 3 \\cdot 10^5$$$)\u00a0\u2014 the number of rides available to you. Each of the following $$$q$$$ lines starts with a single integer $$$k$$$ ($$$2 \\le k \\le n$$$)\u00a0\u2014 the number of crossroads visited by the driver on this ride. It is followed by $$$k$$$ integers $$$c_1$$$, $$$c_2$$$, ..., $$$c_k$$$ ($$$1 \\le c_i \\le n$$$)\u00a0\u2014 the crossroads in the order the driver visited them. It is guaranteed that all crossroads in one ride are distinct. It is guaranteed that the sum of values $$$k$$$ among all rides of all test cases does not exceed $$$3 \\cdot 10^5$$$. It is guaranteed that the sum of values $$$n$$$ and the sum of values $$$q$$$ doesn't exceed $$$3 \\cdot 10^5$$$ among all test cases.", "output_spec": "Output a single line for each test case. If the driver can be a robot, output \"Robot\" in a single line. Otherwise, output \"Human\". You can print each letter in any case (upper or lower).", "sample_inputs": ["1\n5\n2\n4 1 2 3 5\n3 1 4 3", "1\n4\n4\n3 1 2 3\n3 2 3 4\n3 3 4 1\n3 4 1 2"], "sample_outputs": ["Human", "Robot"], "notes": "NoteIn the first example it is clear that the driver used two different ways to get from crossroads $$$1$$$ to crossroads $$$3$$$. It must be a human.In the second example the driver always drives the cycle $$$1 \\to 2 \\to 3 \\to 4 \\to 1$$$ until he reaches destination."}, "src_uid": "d742933184ce1cad098fcb8a264df630"} {"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": "You are given two positive integers $$$x$$$ and $$$y$$$. You can perform the following operation with $$$x$$$: write it in its binary form without leading zeros, add $$$0$$$ or $$$1$$$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $$$x$$$.For example: $$$34$$$ can be turned into $$$81$$$ via one operation: the binary form of $$$34$$$ is $$$100010$$$, if you add $$$1$$$, reverse it and remove leading zeros, you will get $$$1010001$$$, which is the binary form of $$$81$$$. $$$34$$$ can be turned into $$$17$$$ via one operation: the binary form of $$$34$$$ is $$$100010$$$, if you add $$$0$$$, reverse it and remove leading zeros, you will get $$$10001$$$, which is the binary form of $$$17$$$. $$$81$$$ can be turned into $$$69$$$ via one operation: the binary form of $$$81$$$ is $$$1010001$$$, if you add $$$0$$$, reverse it and remove leading zeros, you will get $$$1000101$$$, which is the binary form of $$$69$$$. $$$34$$$ can be turned into $$$69$$$ via two operations: first you turn $$$34$$$ into $$$81$$$ and then $$$81$$$ into $$$69$$$. Your task is to find out whether $$$x$$$ can be turned into $$$y$$$ after a certain number of operations (possibly zero).", "input_spec": "The only line of the input contains two integers $$$x$$$ and $$$y$$$ ($$$1 \\le x, y \\le 10^{18}$$$).", "output_spec": "Print YES if you can make $$$x$$$ equal to $$$y$$$ and NO if you can't.", "sample_inputs": ["3 3", "7 4", "2 8", "34 69", "8935891487501725 71487131900013807"], "sample_outputs": ["YES", "NO", "NO", "YES", "YES"], "notes": "NoteIn the first example, you don't even need to do anything.The fourth example is described in the statement."}, "src_uid": "9f39a3c160087beb0efab2e3cb510e89"} {"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": "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": "You are given a tree with n vertexes and n points on a plane, no three points lie on one straight line.Your task is to paint the given tree on a plane, using the given points as vertexes. That is, you should correspond each vertex of the tree to exactly one point and each point should correspond to a vertex. If two vertexes of the tree are connected by an edge, then the corresponding points should have a segment painted between them. The segments that correspond to non-adjacent edges, should not have common points. The segments that correspond to adjacent edges should have exactly one common point.", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091500) \u2014 the number of vertexes on a tree (as well as the number of chosen points on the plane). Each of the next n\u2009-\u20091 lines contains two space-separated integers ui and vi (1\u2009\u2264\u2009ui,\u2009vi\u2009\u2264\u2009n, ui\u2009\u2260\u2009vi) \u2014 the numbers of tree vertexes connected by the i-th edge. Each of the next n lines contain two space-separated integers xi and yi (\u2009-\u2009109\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009109) \u2014 the coordinates of the i-th point on the plane. No three points lie on one straight line. It is guaranteed that under given constraints problem has a solution.", "output_spec": "Print n distinct space-separated integers from 1 to n: the i-th number must equal the number of the vertex to place at the i-th point (the points are numbered in the order, in which they are listed in the input). If there are several solutions, print any of them.", "sample_inputs": ["3\n1 3\n2 3\n0 0\n1 1\n2 0", "4\n1 2\n2 3\n1 4\n-1 -2\n3 5\n-3 3\n2 0"], "sample_outputs": ["1 3 2", "4 2 1 3"], "notes": "NoteThe possible solutions for the sample are given below. "}, "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba"} {"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": "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": "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": "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": "You're trying to set the record on your favorite video game. The game consists of N levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower. Specifically, you will complete the i-th level in either Fi seconds or Si seconds, where Fi\u2009<\u2009Si, and there's a Pi percent chance of completing it in Fi seconds. After completing a level, you may decide to either continue the game and play the next level, or reset the game and start again from the first level. Both the decision and the action are instant.Your goal is to complete all the levels sequentially in at most R total seconds. You want to minimize the expected amount of time playing before achieving that goal. If you continue and reset optimally, how much total time can you expect to spend playing?", "input_spec": "The first line of input contains integers N and R , the number of levels and number of seconds you want to complete the game in, respectively. N lines follow. The ith such line contains integers Fi,\u2009Si,\u2009Pi (1\u2009\u2264\u2009Fi\u2009<\u2009Si\u2009\u2264\u2009100,\u200980\u2009\u2264\u2009Pi\u2009\u2264\u200999), the fast time for level i, the slow time for level i, and the probability (as a percentage) of completing level i with the fast time.", "output_spec": "Print the total expected time. Your answer must be correct within an absolute or relative error of 10\u2009-\u20099. Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if .", "sample_inputs": ["1 8\n2 8 81", "2 30\n20 30 80\n3 9 85", "4 319\n63 79 89\n79 97 91\n75 87 88\n75 90 83"], "sample_outputs": ["3.14", "31.4", "314.159265358"], "notes": "NoteIn the first example, you never need to reset. There's an 81% chance of completing the level in 2 seconds and a 19% chance of needing 8 seconds, both of which are within the goal time. The expected time is 0.81\u00b72\u2009+\u20090.19\u00b78\u2009=\u20093.14.In the second example, you should reset after the first level if you complete it slowly. On average it will take 0.25 slow attempts before your first fast attempt. Then it doesn't matter whether you complete the second level fast or slow. The expected time is 0.25\u00b730\u2009+\u200920\u2009+\u20090.85\u00b73\u2009+\u20090.15\u00b79\u2009=\u200931.4."}, "src_uid": "b461bb51eab4ff8088460c1980dacb93"} {"nl": {"description": "There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.The game is played on a square field consisting of n\u2009\u00d7\u2009n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.", "input_spec": "The only line of the input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the size of the field.", "output_spec": "Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.", "sample_inputs": ["1", "2"], "sample_outputs": ["1", "2"], "notes": null}, "src_uid": "816ec4cd9736f3113333ef05405b8e81"} {"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": "A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tubes equals e. Volume of each vessel equals v liters. Of course, the amount of the water in any vessel cannot exceed v liters in the process of transfusions.Given the initial amounts ai of water in the vessels and the desired amounts bi find a sequence of transfusions that deals with the task. Total number of transfusions must not exceed 2\u00b7n2.", "input_spec": "First line of the input contains integers n, v, e (1\u2009\u2264\u2009n\u2009\u2264\u2009300, 1\u2009\u2264\u2009v\u2009\u2264\u2009109, 0\u2009\u2264\u2009e\u2009\u2264\u200950000). Next two lines contain n integers each: initial ai and the desired amounts bi of water in corresponding vessels (0\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u2009v). Next e lines describe one tube each in the format x y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009n,\u2009x\u2009\u2260\u2009y) for a tube between vessels number x and y. There might be multiple tubes between two vessels. You may assume that vessels are numbered from 1 to n in some way.", "output_spec": "Print \"NO\" (without quotes), if such sequence of transfusions does not exist. Otherwise print any suitable sequence in the following format. On the first line print the total number of transfusions k (k should not exceed 2\u00b7n2). In the following k lines print transfusions in the format x\u00a0y\u00a0d (transfusion of d liters from the vessel number x to the vessel number y, x and y must be distinct). For all transfusions d must be a non-negative integer.", "sample_inputs": ["2 10 1\n1 9\n5 5\n1 2", "2 10 0\n5 2\n4 2", "2 10 0\n4 2\n4 2"], "sample_outputs": ["1\n2 1 4", "NO", "0"], "notes": null}, "src_uid": "0939354d9bad8301efb79a1a934ded30"} {"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": "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": "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": "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": "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": "You are given an $$$n \\times m$$$ grid. Each grid cell is filled with a unique integer from $$$1$$$ to $$$nm$$$ so that each integer appears exactly once.In one operation, you can choose an arbitrary cycle of the grid and move all integers along that cycle one space over. Here, a cycle is any sequence that satisfies the following conditions: There are at least four squares. Each square appears at most once. Every pair of adjacent squares, and also the first and last squares, share an edge. For example, if we had the following grid: We can choose an arbitrary cycle like this one: To get the following grid: In this particular case, the chosen cycle can be represented as the sequence $$$[1, 2, 3, 6, 5, 8, 7, 4]$$$, the numbers are in the direction that we want to rotate them in.Find any sequence of operations to sort the grid so that the array created by concatenating the rows from the highest to the lowest is sorted (look at the first picture above).Note you do not need to minimize number of operations or sum of cycle lengths. The only constraint is that the sum of all cycles lengths must not be greater than $$$10^5$$$. We can show that an answer always exists under the given constraints. Output any valid sequence of moves that will sort the grid.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \\leq n,m \\leq 20$$$)\u00a0\u2014 the dimensions of the grid. Each of the next $$$n$$$ lines contains $$$m$$$ integers $$$x_{i,1}, x_{i,2}, \\ldots, x_{i, m}$$$ ($$$1 \\leq x_{i,j} \\leq nm$$$), denoting the values of the block in row $$$i$$$ and column $$$j$$$. It is guaranteed that all $$$x_{i,j}$$$ are distinct.", "output_spec": "First, print a single integer $$$k$$$, the number of operations ($$$k \\geq 0$$$). On each of the next $$$k$$$ lines, print a cycle as follows: $$$$$$s\\ y_1\\ y_2\\ \\ldots\\ y_s$$$$$$ Here, $$$s$$$ is the number of blocks to move ($$$s \\geq 4$$$). Here we have block $$$y_1$$$ moving to where block $$$y_2$$$ is, block $$$y_2$$$ moving to where block $$$y_3$$$ is, and so on with block $$$y_s$$$ moving to where block $$$y_1$$$ is. The sum of $$$s$$$ over all operations must be at most $$$10^5$$$.", "sample_inputs": ["3 3\n4 1 2\n7 6 3\n8 5 9", "3 5\n1 2 3 5 10\n11 6 4 14 9\n12 7 8 13 15"], "sample_outputs": ["1\n8 1 4 7 8 5 6 3 2", "3\n4 4 14 13 8\n4 5 10 9 4\n4 12 7 6 11"], "notes": "NoteThe first sample is the case in the statement. Here, we can use the cycle in reverse order to sort the grid."}, "src_uid": "476afa2d8208ec933617c97637b65aff"} {"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": "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": "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": "Everything red frightens Nian the monster. So do red paper and... you, red on Codeforces, potential or real.Big Banban has got a piece of paper with endless lattice points, where lattice points form squares with the same area. His most favorite closed shape is the circle because of its beauty and simplicity. Once he had obtained this piece of paper, he prepares it for paper-cutting. He drew n concentric circles on it and numbered these circles from 1 to n such that the center of each circle is the same lattice point and the radius of the k-th circle is times the length of a lattice edge.Define the degree of beauty of a lattice point as the summation of the indices of circles such that this lattice point is inside them, or on their bounds. Banban wanted to ask you the total degree of beauty of all the lattice points, but changed his mind.Defining the total degree of beauty of all the lattice points on a piece of paper with n circles as f(n), you are asked to figure out .", "input_spec": "The first line contains one integer m (1\u2009\u2264\u2009m\u2009\u2264\u20091012).", "output_spec": "In the first line print one integer representing .", "sample_inputs": ["5", "233"], "sample_outputs": ["387", "788243189"], "notes": "NoteA piece of paper with 5 circles is shown in the following. There are 5 types of lattice points where the degree of beauty of each red point is 1\u2009+\u20092\u2009+\u20093\u2009+\u20094\u2009+\u20095\u2009=\u200915, the degree of beauty of each orange point is 2\u2009+\u20093\u2009+\u20094\u2009+\u20095\u2009=\u200914, the degree of beauty of each green point is 4\u2009+\u20095\u2009=\u20099, the degree of beauty of each blue point is 5 and the degree of beauty of each gray point is 0. Therefore, f(5)\u2009=\u20095\u00b715\u2009+\u20094\u00b714\u2009+\u20094\u00b79\u2009+\u20098\u00b75\u2009=\u2009207.Similarly, f(1)\u2009=\u20095,\u2009f(2)\u2009=\u200923,\u2009f(3)\u2009=\u200950,\u2009f(4)\u2009=\u2009102 and consequently ."}, "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48"} {"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": "The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance.They take turns drawing a mouse from a bag which initially contains w white and b black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning?If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.", "input_spec": "The only line of input data contains two integers w and b (0\u2009\u2264\u2009w,\u2009b\u2009\u2264\u20091000).", "output_spec": "Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10\u2009-\u20099.", "sample_inputs": ["1 3", "5 5"], "sample_outputs": ["0.500000000", "0.658730159"], "notes": "NoteLet's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag \u2014 one black and one white; one of them jumps out, and the other is drawn by the princess on her second turn. If the princess' mouse is white, she wins (probability is 1/2 * 1/2 = 1/4), otherwise nobody gets the white mouse, so according to the rule the dragon wins."}, "src_uid": "7adb8bf6879925955bf187c3d05fde8c"} {"nl": {"description": "Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.Neko has two integers $$$a$$$ and $$$b$$$. His goal is to find a non-negative integer $$$k$$$ such that the least common multiple of $$$a+k$$$ and $$$b+k$$$ is the smallest possible. If there are multiple optimal integers $$$k$$$, he needs to choose the smallest one.Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?", "input_spec": "The only line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^9$$$).", "output_spec": "Print the smallest non-negative integer $$$k$$$ ($$$k \\ge 0$$$) such that the lowest common multiple of $$$a+k$$$ and $$$b+k$$$ is the smallest possible. If there are many possible integers $$$k$$$ giving the same value of the least common multiple, print the smallest one.", "sample_inputs": ["6 10", "21 31", "5 10"], "sample_outputs": ["2", "9", "0"], "notes": "NoteIn the first test, one should choose $$$k = 2$$$, as the least common multiple of $$$6 + 2$$$ and $$$10 + 2$$$ is $$$24$$$, which is the smallest least common multiple possible."}, "src_uid": "414149fadebe25ab6097fc67663177c3"} {"nl": {"description": "Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement.Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve.A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely.", "input_spec": "The first line of input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u20093), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r (\u2009-\u200910\u2009\u2264\u2009x,\u2009y\u2009\u2264\u200910, 1\u2009\u2264\u2009r\u2009\u2264\u200910), describing a circle whose center is (x,\u2009y) and the radius is r. No two circles have the same x, y and r at the same time.", "output_spec": "Print a single integer\u00a0\u2014 the number of regions on the plane.", "sample_inputs": ["3\n0 0 1\n2 0 1\n4 0 1", "3\n0 0 2\n3 0 2\n6 0 2", "3\n0 0 2\n2 0 2\n1 1 2"], "sample_outputs": ["4", "6", "8"], "notes": "NoteFor the first example, For the second example, For the third example, "}, "src_uid": "bda5879e94a82c6fd499796f258c4691"} {"nl": {"description": "Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $$$1$$$ to $$$9$$$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $$$\\ldots$$$, 9m, 1p, 2p, $$$\\ldots$$$, 9p, 1s, 2s, $$$\\ldots$$$, 9s.In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.Do you know the minimum number of extra suited tiles she needs to draw so that she can win?Here are some useful definitions in this game: A mentsu, also known as meld, is formed by a koutsu or a shuntsu; A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: [2m, 3p, 2s, 4m, 1s, 2s, 4s] \u2014 it contains no koutsu or shuntsu, so it includes no mentsu; [4s, 3m, 3p, 4s, 5p, 4s, 5p] \u2014 it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] \u2014 it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.", "input_spec": "The only line contains three strings\u00a0\u2014 the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $$$1$$$ to $$$9$$$ and the second character is m, p or s.", "output_spec": "Print a single integer\u00a0\u2014 the minimum number of extra suited tiles she needs to draw.", "sample_inputs": ["1s 2s 3s", "9m 9m 9m", "3p 9m 2p"], "sample_outputs": ["0", "0", "1"], "notes": "NoteIn the first example, Tokitsukaze already has a shuntsu.In the second example, Tokitsukaze already has a koutsu.In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile\u00a0\u2014 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]."}, "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"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": "We are given a permutation sequence a1,\u2009a2,\u2009...,\u2009an of numbers from 1 to n. Let's assume that in one second, we can choose some disjoint pairs (u1,\u2009v1),\u2009(u2,\u2009v2),\u2009...,\u2009(uk,\u2009vk) and swap all aui and avi for every i at the same time (1\u2009\u2264\u2009ui\u2009<\u2009vi\u2009\u2264\u2009n). The pairs are disjoint if every ui and vj are different from each other.We want to sort the sequence completely in increasing order as fast as possible. Given the initial permutation, calculate the number of ways to achieve this. Two ways are different if and only if there is a time t, such that the set of pairs used for swapping at that time are different as sets (so ordering of pairs doesn't matter). If the given permutation is already sorted, it takes no time to sort, so the number of ways to sort it is 1.To make the problem more interesting, we have k holes inside the permutation. So exactly k numbers of a1,\u2009a2,\u2009...,\u2009an are not yet determined. For every possibility of filling the holes, calculate the number of ways, and print the total sum of these values modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line contains two integers n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) and k (0\u2009\u2264\u2009k\u2009\u2264\u200912). The second line contains the permutation sequence a1,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u2009n). If a number is not yet determined, it is denoted as 0. There are exactly k zeroes. All the numbers ai that aren't equal to zero are distinct.", "output_spec": "Print the total sum of the number of ways modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["5 0\n1 5 2 4 3", "5 2\n1 0 2 4 0"], "sample_outputs": ["6", "7"], "notes": null}, "src_uid": "3467cbf1f1bf689096841b91405a9651"} {"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": "The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a\u2009\u00d7\u2009b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that there must be at least 6 square meters per student in a room (that is, the room for n students must have the area of at least 6n square meters). The caretaker can enlarge any (possibly both) side of the room by an arbitrary positive integer of meters. Help him change the room so as all n students could live in it and the total area of the room was as small as possible.", "input_spec": "The first line contains three space-separated integers n, a and b (1\u2009\u2264\u2009n,\u2009a,\u2009b\u2009\u2264\u2009109) \u2014 the number of students and the sizes of the room.", "output_spec": "Print three integers s, a1 and b1 (a\u2009\u2264\u2009a1;\u00a0b\u2009\u2264\u2009b1) \u2014 the final area of the room and its sizes. If there are multiple optimal solutions, print any of them.", "sample_inputs": ["3 3 5", "2 4 4"], "sample_outputs": ["18\n3 6", "16\n4 4"], "notes": null}, "src_uid": "6a2a584d36008151d18e5080aea5029c"} {"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": "You are given a binary string s (each character of this string is either 0 or 1).Let's denote the cost of string t as the number of occurences of s in t. For example, if s is 11 and t is 111011, then the cost of t is 3.Let's also denote the Fibonacci strings sequence as follows: F(0) is 0; F(1) is 1; F(i)\u2009=\u2009F(i\u2009-\u20091)\u2009+\u2009F(i\u2009-\u20092) if i\u2009>\u20091, where \u2009+\u2009 means the concatenation of two strings.Your task is to calculate the sum of costs of all subsequences of the string F(x). Since answer may be large, calculate it modulo 109\u2009+\u20097.", "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) \u2014 the length of s and the index of a Fibonacci string you are interested in, respectively. The second line contains s \u2014 a string consisting of n characters. Each of these characters is either 0 or 1.", "output_spec": "Print the only integer \u2014 the sum of costs of all subsequences of the string F(x), taken modulo 109\u2009+\u20097. ", "sample_inputs": ["2 4\n11", "10 100\n1010101010"], "sample_outputs": ["14", "553403224"], "notes": null}, "src_uid": "52c6aa73ff4460799402c646c6263630"} {"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": "Once Vasya needed to transport m goats and m wolves from riverbank to the other as quickly as possible. The boat can hold n animals and Vasya, in addition, he is permitted to put less than n animals in the boat. If in one place (on one of the banks or in the boat) the wolves happen to strictly outnumber the goats, then the wolves eat the goats and Vasya gets upset. When Vasya swims on the boat from one shore to the other, he must take at least one animal to accompany him, otherwise he will get bored and he will, yet again, feel upset. When the boat reaches the bank, first all the animals get off simultaneously, and then the animals chosen by Vasya simultaneously get on the boat. That means that at the moment when the animals that have just arrived have already got off and the animals that are going to leave haven't yet got on, somebody might eat someone. Vasya needs to transport all the animals from one river bank to the other so that nobody eats anyone and Vasya doesn't get upset. What is the minimal number of times he will have to cross the river?", "input_spec": "The first line contains two space-separated numbers m and n (1\u2009\u2264\u2009m,\u2009n\u2009\u2264\u2009105) \u2014 the number of animals and the boat's capacity.", "output_spec": "If it is impossible to transport all the animals so that no one got upset, and all the goats survived, print -1. Otherwise print the single number \u2014 how many times Vasya will have to cross the river.", "sample_inputs": ["3 2", "33 3"], "sample_outputs": ["11", "-1"], "notes": "NoteThe first sample match to well-known problem for children."}, "src_uid": "83f1d50a1802e08dd154d4c9778e3d80"} {"nl": {"description": "A very tense moment: n cowboys stand in a circle and each one points his colt at a neighbor. Each cowboy can point the colt to the person who follows or precedes him in clockwise direction. Human life is worthless, just like in any real western.The picture changes each second! Every second the cowboys analyse the situation and, if a pair of cowboys realize that they aim at each other, they turn around. In a second all such pairs of neighboring cowboys aiming at each other turn around. All actions happen instantaneously and simultaneously in a second.We'll use character \"A\" to denote a cowboy who aims at his neighbour in the clockwise direction, and character \"B\" for a cowboy who aims at his neighbour in the counter clockwise direction. Then a string of letters \"A\" and \"B\" will denote the circle of cowboys, the record is made from the first of them in a clockwise direction.For example, a circle that looks like \"ABBBABBBA\" after a second transforms into \"BABBBABBA\" and a circle that looks like \"BABBA\" transforms into \"ABABB\". This picture illustrates how the circle \"BABBA\" transforms into \"ABABB\" A second passed and now the cowboys' position is described by string s. Your task is to determine the number of possible states that lead to s in a second. Two states are considered distinct if there is a cowboy who aims at his clockwise neighbor in one state and at his counter clockwise neighbor in the other state.", "input_spec": "The input data consists of a single string s. Its length is from 3 to 100 characters, inclusive. Line s consists of letters \"A\" and \"B\".", "output_spec": "Print the sought number of states.", "sample_inputs": ["BABBBABBA", "ABABB", "ABABAB"], "sample_outputs": ["2", "2", "4"], "notes": "NoteIn the first sample the possible initial states are \"ABBBABBAB\" and \"ABBBABBBA\".In the second sample the possible initial states are \"AABBB\" and \"BABBA\"."}, "src_uid": "ad27d991516054ea473b384bb2563b38"} {"nl": {"description": "Sereja adores trees. Today he came up with a revolutionary new type of binary root trees.His new tree consists of n levels, each vertex is indexed by two integers: the number of the level and the number of the vertex on the current level. The tree root is at level 1, its index is (1,\u20091). Here is a pseudo code of tree construction.//the global data are integer arrays cnt[], left[][], right[][]cnt[1] = 1;fill arrays left[][], right[][] with values -1;for(level = 1; level < n; level = level + 1){ cnt[level + 1] = 0; for(position = 1; position <= cnt[level]; position = position + 1){ if(the value of position is a power of two){ // that is, 1, 2, 4, 8... left[level][position] = cnt[level + 1] + 1; right[level][position] = cnt[level + 1] + 2; cnt[level + 1] = cnt[level + 1] + 2; }else{ right[level][position] = cnt[level + 1] + 1; cnt[level + 1] = cnt[level + 1] + 1; } }}After the pseudo code is run, cell cnt[level] contains the number of vertices on level level. Cell left[level][position] contains the number of the vertex on the level level\u2009+\u20091, which is the left child of the vertex with index (level,\u2009position), or it contains -1, if the vertex doesn't have a left child. Similarly, cell right[level][position] is responsible for the right child. You can see how the tree with n\u2009=\u20094 looks like in the notes.Serja loves to make things complicated, so he first made a tree and then added an empty set A(level,\u2009position) for each vertex. Then Sereja executes m operations. Each operation is of one of the two following types: The format of the operation is \"1 t l r x\". For all vertices level,\u2009position (level\u2009=\u2009t;\u00a0l\u2009\u2264\u2009position\u2009\u2264\u2009r) add value x to set A(level,\u2009position). The format of the operation is \"2 t v\". For vertex level,\u2009position (level\u2009=\u2009t,\u2009position\u2009=\u2009v), find the union of all sets of vertices that are in the subtree of vertex (level,\u2009position). Print the size of the union of these sets. Help Sereja execute the operations. In this problem a set contains only distinct values like std::set in C++.", "input_spec": "The first line contains integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20097000). Next m lines contain the descriptions of the operations. The operation of the first type is given by five integers: 1 t l r x (1\u2009\u2264\u2009t\u2009\u2264\u2009n;\u00a01\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009cnt[t];\u00a01\u2009\u2264\u2009x\u2009\u2264\u2009106). The operation of the second type is given by three integers: 2 t v (1\u2009\u2264\u2009t\u2009\u2264\u2009n;\u00a01\u2009\u2264\u2009v\u2009\u2264\u2009cnt[t]).", "output_spec": "For each operation of the second type, print the answer on a single line.", "sample_inputs": ["4 5\n1 4 4 7 1\n1 3 1 2 2\n2 1 1\n2 4 1\n2 3 3"], "sample_outputs": ["2\n0\n1"], "notes": "NoteYou can find the definitions that are used while working with root trees by this link: http://en.wikipedia.org/wiki/Tree_(graph_theory)You can see an example of a constructed tree at n\u2009=\u20094 below. "}, "src_uid": "9f239cfd29c1a2652a065bfe5c15476a"} {"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": "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": "It's Piegirl's birthday soon, and Pieguy has decided to buy her a bouquet of flowers and a basket of chocolates.The flower shop has F different types of flowers available. The i-th type of flower always has exactly pi petals. Pieguy has decided to buy a bouquet consisting of exactly N flowers. He may buy the same type of flower multiple times. The N flowers are then arranged into a bouquet. The position of the flowers within a bouquet matters. You can think of a bouquet as an ordered list of flower types.The chocolate shop sells chocolates in boxes. There are B different types of boxes available. The i-th type of box contains ci pieces of chocolate. Pieguy can buy any number of boxes, and can buy the same type of box multiple times. He will then place these boxes into a basket. The position of the boxes within the basket matters. You can think of the basket as an ordered list of box types.Pieguy knows that Piegirl likes to pluck a petal from a flower before eating each piece of chocolate. He would like to ensure that she eats the last piece of chocolate from the last box just after plucking the last petal from the last flower. That is, the total number of petals on all the flowers in the bouquet should equal the total number of pieces of chocolate in all the boxes in the basket.How many different bouquet+basket combinations can Pieguy buy? The answer may be very large, so compute it modulo 1000000007\u2009=\u2009109\u2009+\u20097.", "input_spec": "The first line of input will contain integers F, B, and N (1\u2009\u2264\u2009F\u2009\u2264\u200910,\u20091\u2009\u2264\u2009B\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009N\u2009\u2264\u20091018), the number of types of flowers, the number of types of boxes, and the number of flowers that must go into the bouquet, respectively. The second line of input will contain F integers p1,\u2009p2,\u2009...,\u2009pF (1\u2009\u2264\u2009pi\u2009\u2264\u2009109), the numbers of petals on each of the flower types. The third line of input will contain B integers c1,\u2009c2,\u2009...,\u2009cB (1\u2009\u2264\u2009ci\u2009\u2264\u2009250), the number of pieces of chocolate in each of the box types.", "output_spec": "Print the number of bouquet+basket combinations Pieguy can buy, modulo 1000000007\u2009=\u2009109\u2009+\u20097.", "sample_inputs": ["2 3 3\n3 5\n10 3 7", "6 5 10\n9 3 3 4 9 9\n9 9 1 6 4"], "sample_outputs": ["17", "31415926"], "notes": "NoteIn the first example, there is 1 way to make a bouquet with 9 petals (3\u2009+\u20093\u2009+\u20093), and 1 way to make a basket with 9 pieces of chocolate (3\u2009+\u20093\u2009+\u20093), for 1 possible combination. There are 3 ways to make a bouquet with 13 petals (3\u2009+\u20095\u2009+\u20095,\u20095\u2009+\u20093\u2009+\u20095,\u20095\u2009+\u20095\u2009+\u20093), and 5 ways to make a basket with 13 pieces of chocolate (3\u2009+\u200910,\u200910\u2009+\u20093,\u20093\u2009+\u20093\u2009+\u20097,\u20093\u2009+\u20097\u2009+\u20093,\u20097\u2009+\u20093\u2009+\u20093), for 15 more combinations. Finally there is 1 way to make a bouquet with 15 petals (5\u2009+\u20095\u2009+\u20095) and 1 way to make a basket with 15 pieces of chocolate (3\u2009+\u20093\u2009+\u20093\u2009+\u20093\u2009+\u20093), for 1 more combination.Note that it is possible for multiple types of flowers to have the same number of petals. Such types are still considered different. Similarly different types of boxes may contain the same number of pieces of chocolate, but are still considered different."}, "src_uid": "c3a4c109080f49b88be5fb13157d1af0"} {"nl": {"description": "The finalists of the \"Russian Code Cup\" competition in 2214 will be the participants who win in one of the elimination rounds.The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.As a result of all elimination rounds at least n\u00b7m people should go to the finals. You need to organize elimination rounds in such a way, that at least n\u00b7m people go to the finals, and the total amount of used problems in all rounds is as small as possible.", "input_spec": "The first line contains two integers c and d (1\u2009\u2264\u2009c,\u2009d\u2009\u2264\u2009100)\u00a0\u2014 the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100). Finally, the third line contains an integer k (1\u2009\u2264\u2009k\u2009\u2264\u2009100)\u00a0\u2014 the number of the pre-chosen winners. ", "output_spec": "In the first line, print a single integer \u2014 the minimum number of problems the jury needs to prepare.", "sample_inputs": ["1 10\n7 2\n1", "2 2\n2 1\n2"], "sample_outputs": ["2", "0"], "notes": null}, "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb"} {"nl": {"description": "You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x,\u2009y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1,\u20091), that is top left corner of the matrix. Then she goes down all the way to cell (n,\u20091) \u2014 the bottom left corner. Then she starts moving in the snake fashion \u2014 all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1,\u20092).Lara has already moved to a neighbouring cell k times. Can you determine her current position?", "input_spec": "The only line contains three integers n, m and k (2\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009109, n is always even, 0\u2009\u2264\u2009k\u2009<\u2009n\u00b7m). Note that k doesn't fit into 32-bit integer type!", "output_spec": "Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.", "sample_inputs": ["4 3 0", "4 3 11", "4 3 7"], "sample_outputs": ["1 1", "1 2", "3 2"], "notes": "NoteHere is her path on matrix 4 by 3: "}, "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"nl": {"description": "While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used).Suppose the cache may store no more than k objects. At the beginning of the workflow the cache is empty. When some object is queried we check if it is present in the cache and move it here if it's not. If there are more than k objects in the cache after this, the least recently used one should be removed. In other words, we remove the object that has the smallest time of the last query.Consider there are n videos being stored on the server, all of the same size. Cache can store no more than k videos and caching algorithm described above is applied. We know that any time a user enters the server he pick the video i with probability pi. The choice of the video is independent to any events before.The goal of this problem is to count for each of the videos the probability it will be present in the cache after 10100 queries.", "input_spec": "The first line of the input contains two integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u200920)\u00a0\u2014 the number of videos and the size of the cache respectively. Next line contains n real numbers pi (0\u2009\u2264\u2009pi\u2009\u2264\u20091), each of them is given with no more than two digits after decimal point. It's guaranteed that the sum of all pi is equal to 1.", "output_spec": "Print n real numbers, the i-th of them should be equal to the probability that the i-th video will be present in the cache after 10100 queries. You 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": ["3 1\n0.3 0.2 0.5", "2 1\n0.0 1.0", "3 2\n0.3 0.2 0.5", "3 3\n0.2 0.3 0.5"], "sample_outputs": ["0.3 0.2 0.5", "0.0 1.0", "0.675 0.4857142857142857 0.8392857142857143", "1.0 1.0 1.0"], "notes": null}, "src_uid": "ad290c29e7587561391cefab73026171"} {"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": "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": "Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q\u2009-\u20091 seconds of the track.Tell Lesha, for how many times he will start the song, including the very first start.", "input_spec": "The single line contains three integers T,\u2009S,\u2009q (2\u2009\u2264\u2009q\u2009\u2264\u2009104, 1\u2009\u2264\u2009S\u2009<\u2009T\u2009\u2264\u2009105).", "output_spec": "Print a single integer\u00a0\u2014 the number of times the song will be restarted.", "sample_inputs": ["5 2 2", "5 4 7", "6 2 3"], "sample_outputs": ["2", "1", "1"], "notes": "NoteIn the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.In the second test, the song is almost downloaded, and Lesha will start it only once.In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case."}, "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"} {"nl": {"description": "Many people are aware of DMCA \u2013 Digital Millennium Copyright Act. But another recently proposed DMCA \u2013 Digital Millennium Calculation Act \u2013 is much less known.In this problem you need to find a root of a number according to this new DMCA law.", "input_spec": "The input contains a single integer $$$a$$$ ($$$1 \\le a \\le 1000000$$$).", "output_spec": "Output the result \u2013 an integer number.", "sample_inputs": ["1", "81"], "sample_outputs": ["1", "9"], "notes": null}, "src_uid": "477a67877367dc68b3bf5143120ff45d"} {"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": "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": "Polycarp plays \"Game 23\". Initially he has a number $$$n$$$ and his goal is to transform it to $$$m$$$. In one move, he can multiply $$$n$$$ by $$$2$$$ or multiply $$$n$$$ by $$$3$$$. He can perform any number of moves.Print the number of moves needed to transform $$$n$$$ to $$$m$$$. Print -1 if it is impossible to do so.It is easy to prove that any way to transform $$$n$$$ to $$$m$$$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le m \\le 5\\cdot10^8$$$).", "output_spec": "Print the number of moves to transform $$$n$$$ to $$$m$$$, or -1 if there is no solution.", "sample_inputs": ["120 51840", "42 42", "48 72"], "sample_outputs": ["7", "0", "-1"], "notes": "NoteIn the first example, the possible sequence of moves is: $$$120 \\rightarrow 240 \\rightarrow 720 \\rightarrow 1440 \\rightarrow 4320 \\rightarrow 12960 \\rightarrow 25920 \\rightarrow 51840.$$$ The are $$$7$$$ steps in total.In the second example, no moves are needed. Thus, the answer is $$$0$$$.In the third example, it is impossible to transform $$$48$$$ to $$$72$$$."}, "src_uid": "3f9980ad292185f63a80bce10705e806"} {"nl": {"description": "Vasya and Petya are playing an online game. As most online games, it has hero progress system that allows players to gain experience that make their heroes stronger. Of course, Vasya would like to get as many experience points as possible. After careful study of experience points allocation, he found out that if he plays the game alone, he gets one experience point each second. However, if two players are playing together, and their current experience values differ by at most C points, they can boost their progress, and each of them gets 2 experience points each second.Since Vasya and Petya are middle school students, their parents don't allow them to play all the day around. Each of the friends has his own schedule: Vasya can only play during intervals [a1;b1],\u2009[a2;b2],\u2009...,\u2009[an;bn], and Petya can only play during intervals [c1;d1],\u2009[c2;d2],\u2009...,\u2009[cm;dm]. All time periods are given in seconds from the current moment. Vasya is good in math, so he has noticed that sometimes it can be profitable not to play alone, because experience difference could become too big, and progress would not be boosted even when played together.Now they would like to create such schedule of playing that Vasya's final experience was greatest possible. The current players experience is the same. Petya is not so concerned about his experience, so he is ready to cooperate and play when needed to maximize Vasya's experience.", "input_spec": "The first line of input data contains integers n, m and C \u2014 the number of intervals when Vasya can play, the number of intervals when Petya can play, and the maximal difference in experience level when playing together still gives a progress boost (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20092\u00b7105, 0\u2009\u2264\u2009C\u2009\u2264\u20091018). The following n lines contain two integers each: ai,\u2009bi\u00a0\u2014 intervals when Vasya can play (0\u2009\u2264\u2009ai\u2009<\u2009bi\u2009\u2264\u20091018, bi\u2009<\u2009ai\u2009+\u20091). The following m lines contain two integers each: ci,\u2009di\u00a0\u2014 intervals when Petya can play (0\u2009\u2264\u2009ci\u2009<\u2009di\u2009\u2264\u20091018, di\u2009<\u2009ci\u2009+\u20091).", "output_spec": "Output one integer\u00a0\u2014 the maximal experience that Vasya can have in the end, if both players try to maximize this value.", "sample_inputs": ["2 1 5\n1 7\n10 20\n10 20", "1 2 5\n0 100\n20 60\n85 90"], "sample_outputs": ["25", "125"], "notes": null}, "src_uid": "fa9a0d500220905af7dcbe80740da62a"} {"nl": {"description": "Petya wrote a programme on C++ that calculated a very interesting function f(n). Petya ran the program with a certain value of n and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had the result. However while Petya was drinking tea, a sly virus managed to destroy the input file so that Petya can't figure out for which value of n the program was run. Help Petya, carry out the inverse function!Mostly, the program consists of a function in C++ with the following simplified syntax: function ::= int f(int n) {operatorSequence} operatorSequence ::= operator\u00a0|\u00a0operator\u00a0operatorSequence operator ::= return arithmExpr; | if (logicalExpr) return arithmExpr; logicalExpr ::= arithmExpr\u2009>\u2009arithmExpr | arithmExpr\u2009<\u2009arithmExpr | arithmExpr == arithmExpr arithmExpr ::= sum sum ::= product | sum\u2009+\u2009product | sum\u2009-\u2009product product ::= multiplier | product\u2009*\u2009multiplier | product\u2009/\u2009multiplier multiplier ::= n | number | f(arithmExpr) number ::= 0|1|2|... |32767 The whitespaces in a operatorSequence are optional.Thus, we have a function, in which body there are two kinds of operators. There is the operator \"return arithmExpr;\" that returns the value of the expression as the value of the function, and there is the conditional operator \"if (logicalExpr) return arithmExpr;\" that returns the value of the arithmetical expression when and only when the logical expression is true. Guaranteed that no other constructions of C++ language \u2014 cycles, assignment operators, nested conditional operators etc, and other variables except the n parameter are used in the function. All the constants are integers in the interval [0..32767].The operators are performed sequentially. After the function has returned a value other operators in the sequence are not performed. Arithmetical expressions are performed taking into consideration the standard priority of the operations. It means that first all the products that are part of the sum are calculated. During the calculation of the products the operations of multiplying and division are performed from the left to the right. Then the summands are summed, and the addition and the subtraction are also performed from the left to the right. Operations \">\" (more), \"<\" (less) and \"==\" (equals) also have standard meanings.Now you've got to pay close attention! The program is compiled with the help of 15-bit Berland C++ compiler invented by a Berland company BerSoft, that's why arithmetical operations are performed in a non-standard way. Addition, subtraction and multiplication are performed modulo 32768 (if the result of subtraction is negative, then 32768 is added to it until the number belongs to the interval [0..32767]). Division \"/\" is a usual integer division where the remainder is omitted.Examples of arithmetical operations: Guaranteed that for all values of n from 0 to 32767 the given function is performed correctly. That means that:1. Division by 0 never occures.2. When performing a function for the value n\u2009=\u2009N recursive calls of the function f may occur only for the parameter value of 0,\u20091,\u2009...,\u2009N\u2009-\u20091. Consequently, the program never has an infinite recursion.3. As the result of the sequence of the operators, the function always returns a value.We have to mention that due to all the limitations the value returned by the function f is independent from either global variables or the order of performing the calculations of arithmetical expressions as part of the logical one, or from anything else except the value of n parameter. That's why the f function can be regarded as a function in its mathematical sense, i.e. as a unique correspondence between any value of n from the interval [0..32767] and a value of f(n) from the same interval.Given the value of f(n), and you should find n. If the suitable n value is not unique, you should find the maximal one (from the interval [0..32767]).", "input_spec": "The first line has an integer f(n) from the interval [0..32767]. The next lines have the description of the function f. In the description can be found extra spaces and line breaks (see the examples) which, of course, can\u2019t break key words int, if, return and numbers. The size of input data can\u2019t exceed 100 bytes.", "output_spec": "Output a single number \u2014 the answer to the problem. If there\u2019s no answer, output \"-1\" (without quotes).", "sample_inputs": ["17\nint f(int n)\n{\nif (n < 100) return 17;\nif (n > 99) return 27;\n}", "13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}", "144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nreturn f(n - 1) + f(n - 2);\n}"], "sample_outputs": ["99", "13", "24588"], "notes": null}, "src_uid": "698c5a87f9adbe6af60d9f70519c9672"} {"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": "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": "Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.Note that the game consisted of several complete sets.", "input_spec": "The first line contains three space-separated integers k, a and b (1\u2009\u2264\u2009k\u2009\u2264\u2009109, 0\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109, a\u2009+\u2009b\u2009>\u20090).", "output_spec": "If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.", "sample_inputs": ["11 11 5", "11 2 3"], "sample_outputs": ["1", "-1"], "notes": "NoteNote that the rules of the game in this problem differ from the real table tennis game, for example, the rule of \"balance\" (the winning player has to be at least two points ahead to win a set) has no power within the present problem."}, "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"nl": {"description": "Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.", "input_spec": "The only line contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u200910100000). This number doesn't have leading zeroes.", "output_spec": "Output the least super lucky number that is more than or equal to n.", "sample_inputs": ["4500", "47"], "sample_outputs": ["4747", "47"], "notes": null}, "src_uid": "77b5f83cdadf4b0743618a46b646a849"} {"nl": {"description": "The cows have just learned what a primitive root is! Given a prime p, a primitive root is an integer x (1\u2009\u2264\u2009x\u2009<\u2009p) such that none of integers x\u2009-\u20091,\u2009x2\u2009-\u20091,\u2009...,\u2009xp\u2009-\u20092\u2009-\u20091 are divisible by p, but xp\u2009-\u20091\u2009-\u20091 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots .", "input_spec": "The input contains a single line containing an integer p (2\u2009\u2264\u2009p\u2009<\u20092000). It is guaranteed that p is a prime.", "output_spec": "Output on a single line the number of primitive roots .", "sample_inputs": ["3", "5"], "sample_outputs": ["1", "2"], "notes": "NoteThe only primitive root is 2.The primitive roots are 2 and 3."}, "src_uid": "3bed682b6813f1ddb54410218c233cff"} {"nl": {"description": "A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is\u00a0not the next prime number for 2.One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m\u2009>\u2009n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?", "input_spec": "The first and only input line contains two positive integers \u2014 n and m (2\u2009\u2264\u2009n\u2009<\u2009m\u2009\u2264\u200950). It is guaranteed that n is prime. Pretests contain all the cases with restrictions 2\u2009\u2264\u2009n\u2009<\u2009m\u2009\u2264\u20094.", "output_spec": "Print YES, if m is the next prime number after n, or NO otherwise.", "sample_inputs": ["3 5", "7 11", "7 9"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"nl": {"description": "This problem differs from the previous problem only in constraints.Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusual.Initially, there were $$$n$$$ different countries on the land that is now Berland. Each country had its own territory that was represented as a rectangle on the map. The sides of the rectangle were parallel to the axes, and the corners were located at points with integer coordinates. Territories of no two countries intersected, but it was possible that some territories touched each other. As time passed, sometimes two countries merged into one. It only happened if the union of their territories was also a rectangle. In the end only one country remained\u00a0\u2014 Byteland.Initially, each country had a rectangular castle inside its territory. Its sides were parallel to the axes and its corners had integer coordinates. Some castles might touch the border of the corresponding country and sides or other castles. Miraculously, after all the unions the castles are still intact. Unfortunately, their locations are the only information we have to restore the initial territories of the countries. The possible formation of Byteland. The castles are shown in blue. Petya wonders why no information about the initial countries remained. He suspected that the whole story is a fake. You were recommended to him as a smart person. Please check whether or not there exists a possible set of initial territories that could make the story true.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100\\,000$$$)\u00a0\u2014 the number of countries and castles. Each of the next $$$n$$$ lines contains four integers $$$a_i, b_i, c_i, d_i$$$ ($$$0 \\leq a_i < c_i \\leq 10^9$$$, $$$0 \\leq b_i < d_i \\leq 10^9$$$)\u00a0\u2014 the coordinates of the $$$i$$$-th castle, where $$$(a_i, b_i)$$$ are the coordinates of the lower left corner and $$$(c_i, d_i)$$$ are the coordinates of the upper right corner. It is guaranteed that no two castles intersect, however, they may touch.", "output_spec": "If there exists a possible set of territories that satisfies the story, print \"YES\", otherwise print \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["4\n0 0 1 2\n0 2 1 3\n1 0 2 1\n1 1 2 3", "4\n0 0 2 1\n1 2 3 3\n2 0 3 2\n0 1 1 3"], "sample_outputs": ["YES", "NO"], "notes": "NoteThe castles in the first and second examples are shown on the pictures below. \u00a0 "}, "src_uid": "5bfb165b4efe081d6a8c4843f7769a37"} {"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": "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": "BubbleSquare social network is celebrating $$$13^{th}$$$ anniversary and it is rewarding its members with special edition BubbleSquare tokens. Every member receives one personal token. Also, two additional tokens are awarded to each member for every friend they have on the network. Yet, there is a twist \u2013 everyone should end up with different number of tokens from all their friends. Each member may return one received token. Also, each two friends may agree to each return one or two tokens they have obtained on behalf of their friendship.", "input_spec": "First line of input contains two integer numbers $$$n$$$ and $$$k$$$ ($$$2$$$ $$$\\leq$$$ $$$n$$$ $$$\\leq$$$ $$$12500$$$, $$$1$$$ $$$\\leq$$$ $$$k$$$ $$$\\leq$$$ $$$1000000$$$) - number of members in network and number of friendships. Next $$$k$$$ lines contain two integer numbers $$$a_i$$$ and $$$b_i$$$ ($$$1$$$ $$$\\leq$$$ $$$a_i$$$, $$$b_i$$$ $$$\\leq$$$ $$$n$$$, $$$a_i$$$ $$$\\neq$$$ $$$b_i$$$) - meaning members $$$a_i$$$ and $$$b_i$$$ are friends.", "output_spec": "First line of output should specify the number of members who are keeping their personal token. The second line should contain space separated list of members who are keeping their personal token. Each of the following $$$k$$$ lines should contain three space separated numbers, representing friend pairs and number of tokens each of them gets on behalf of their friendship.", "sample_inputs": ["2 1\n1 2", "3 3\n1 2\n1 3\n2 3"], "sample_outputs": ["1\n1 \n1 2 0", "0\n1 2 0\n2 3 1\n1 3 2"], "notes": "NoteIn the first test case, only the first member will keep its personal token and no tokens will be awarded for friendship between the first and the second member.In the second test case, none of the members will keep their personal token. The first member will receive two tokens (for friendship with the third member), the second member will receive one token (for friendship with the third member) and the third member will receive three tokens (for friendships with the first and the second member)."}, "src_uid": "6e184abbbc3ca323c8c092ef727cc7a1"} {"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": "Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters \u2014 its significance ci and width wi.Stepan decided to expose some of his cups on a shelf with width d in such a way, that: there is at least one Physics cup and at least one Informatics cup on the shelf, the total width of the exposed cups does not exceed d, from each subjects (Physics and Informatics) some of the most significant cups are exposed (i. e. if a cup for some subject with significance x is exposed, then all the cups for this subject with significance greater than x must be exposed too). Your task is to determine the maximum possible total significance, which Stepan can get when he exposes cups on the shelf with width d, considering all the rules described above. The total significance is the sum of significances of all the exposed cups.", "input_spec": "The first line contains three integers n, m and d (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100\u2009000, 1\u2009\u2264\u2009d\u2009\u2264\u2009109) \u2014 the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf. Each of the following n lines contains two integers ci and wi (1\u2009\u2264\u2009ci,\u2009wi\u2009\u2264\u2009109) \u2014 significance and width of the i-th cup for Physics olympiads. Each of the following m lines contains two integers cj and wj (1\u2009\u2264\u2009cj,\u2009wj\u2009\u2264\u2009109) \u2014 significance and width of the j-th cup for Informatics olympiads.", "output_spec": "Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width d, considering all the rules described in the statement. If there is no way to expose cups on the shelf, then print 0.", "sample_inputs": ["3 1 8\n4 2\n5 5\n4 2\n3 2", "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "2 2 2\n5 3\n6 3\n4 2\n8 1"], "sample_outputs": ["8", "11", "0"], "notes": "NoteIn the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most significant cup for Physics (its significance equals 5). After that Stepan can not expose more cups on the shelf, because there is no enough free space. Thus, the maximum total significance of exposed cups equals to 8."}, "src_uid": "da573a39459087ed7c42f70bc1d0e8ff"} {"nl": {"description": "Mr. Chanek wants to knit a batik, a traditional cloth from Indonesia. The cloth forms a grid $$$a$$$ with size $$$n \\times m$$$. There are $$$k$$$ colors, and each cell in the grid can be one of the $$$k$$$ colors.Define a sub-rectangle as an ordered pair of two cells $$$((x_1, y_1), (x_2, y_2))$$$, denoting the top-left cell and bottom-right cell (inclusively) of a sub-rectangle in $$$a$$$. Two sub-rectangles $$$((x_1, y_1), (x_2, y_2))$$$ and $$$((x_3, y_3), (x_4, y_4))$$$ have the same pattern if and only if the following holds: they have the same width ($$$x_2 - x_1 = x_4 - x_3$$$); they have the same height ($$$y_2 - y_1 = y_4 - y_3$$$); for every pair $$$(i, j)$$$ where $$$0 \\leq i \\leq x_2 - x_1$$$ and $$$0 \\leq j \\leq y_2 - y_1$$$, the color of cells $$$(x_1 + i, y_1 + j)$$$ and $$$(x_3 + i, y_3 + j)$$$ are equal. Count the number of possible batik color combinations, such that the subrectangles $$$((a_x, a_y),(a_x + r - 1, a_y + c - 1))$$$ and $$$((b_x, b_y),(b_x + r - 1, b_y + c - 1))$$$ have the same pattern.Output the answer modulo $$$10^9 + 7$$$.", "input_spec": "The first line contains five integers $$$n$$$, $$$m$$$, $$$k$$$, $$$r$$$, and $$$c$$$ ($$$1 \\leq n, m \\leq 10^9$$$, $$$1 \\leq k \\leq 10^9$$$, $$$1 \\leq r \\leq \\min(10^6, n)$$$, $$$1 \\leq c \\leq \\min(10^6, m)$$$) \u2014 the size of the batik, the number of colors, and size of the sub-rectangle. The second line contains four integers $$$a_x$$$, $$$a_y$$$, $$$b_x$$$, and $$$b_y$$$ ($$$1 \\leq a_x, b_x \\leq n$$$, $$$1 \\leq a_y, b_y \\leq m$$$) \u2014 the top-left corners of the first and second sub-rectangle. Both of the sub-rectangles given are inside the grid ($$$1 \\leq a_x + r - 1$$$, $$$b_x + r - 1 \\leq n$$$, $$$1 \\leq a_y + c - 1$$$, $$$b_y + c - 1 \\leq m$$$).", "output_spec": "Output an integer denoting the number of possible batik color combinations modulo $$$10^9 + 7$$$.", "sample_inputs": ["3 3 2 2 2\n1 1 2 2", "4 5 170845 2 2\n1 4 3 1"], "sample_outputs": ["32", "756680455"], "notes": "NoteThe following are all $$$32$$$ possible color combinations in the first example. "}, "src_uid": "3478e6a4ff2415508fd517413d40c13a"} {"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": "Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.She precisely remembers she had n buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is p (the number p is even).Print the total money grandma should have at the end of the day to check if some buyers cheated her.", "input_spec": "The first line contains two integers n and p (1\u2009\u2264\u2009n\u2009\u2264\u200940,\u20092\u2009\u2264\u2009p\u2009\u2264\u20091000) \u2014 the number of the buyers and the cost of one apple. It is guaranteed that the number p is even. The next n lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.", "output_spec": "Print the only integer a \u2014 the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "sample_inputs": ["2 10\nhalf\nhalfplus", "3 10\nhalfplus\nhalfplus\nhalfplus"], "sample_outputs": ["15", "55"], "notes": "NoteIn the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer."}, "src_uid": "6330891dd05bb70241e2a052f5bf5a58"} {"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": "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": "Berland traffic is very different from traffic in other countries. The capital of Berland consists of n junctions and m roads. Each road connects a pair of junctions. There can be multiple roads between a pair of junctions. For each road we know its capacity: value ci is the maximum number of cars that can drive along a road in any direction per a unit of time. For each road, the cars can drive along it in one of two direction. That it, the cars can't simultaneously move in both directions. A road's traffic is the number of cars that goes along it per a unit of time. For road (ai,\u2009bi) this value is negative, if the traffic moves from bi to ai. A road's traffic can be a non-integer number.The capital has two special junctions \u2014 the entrance to the city (junction 1) and the exit from the city (junction n). For all other junctions it is true that the traffic is not lost there. That is, for all junctions except for 1 and n the incoming traffic sum equals the outgoing traffic sum.Traffic has an unusual peculiarity in the capital of Berland \u2014 for any pair of junctions (x,\u2009y) the sum of traffics along any path from x to y doesn't change depending on the choice of the path. Such sum includes traffic along all roads on the path (possible with the \"minus\" sign, if the traffic along the road is directed against the direction of the road on the path from x to y).Your task is to find the largest traffic that can pass trough the city per one unit of time as well as the corresponding traffic for each road. ", "input_spec": "The first line contains a positive integer n \u2014 the number of junctions (2\u2009\u2264\u2009n\u2009\u2264\u2009100). The second line contains integer m (1\u2009\u2264\u2009m\u2009\u2264\u20095000) \u2014 the number of roads. Next m lines contain the roads' descriptions. Each road contains a group of three numbers ai, bi, ci, where ai,\u2009bi are the numbers of junctions, connected by the given road, and ci (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u2009n; ai\u2009\u2260\u2009bi; 0\u2009\u2264\u2009ci\u2009\u2264\u200910000) is the largest permissible traffic along this road.", "output_spec": "In the first line print the required largest traffic across the city. Then print m lines, on each line print the speed, at which the traffic moves along the corresponding road. If the direction doesn't match the order of the junctions, given in the input, then print the traffic with the minus sign. Print the numbers with accuracy of at least five digits after the decimal point. If there are many optimal solutions, print any of them.", "sample_inputs": ["2\n3\n1 2 2\n1 2 4\n2 1 1000", "7\n11\n1 2 7\n1 2 7\n1 3 7\n1 4 7\n2 3 7\n2 5 7\n3 6 7\n4 7 7\n5 4 7\n5 6 7\n6 7 7"], "sample_outputs": ["6.00000\n2.00000\n2.00000\n-2.00000", "13.00000\n2.00000\n2.00000\n3.00000\n6.00000\n1.00000\n3.00000\n4.00000\n7.00000\n1.00000\n2.00000\n6.00000"], "notes": null}, "src_uid": "93fa614f174816d241c0fa302c6476e2"} {"nl": {"description": "You are given a weighted undirected tree on $$$n$$$ vertices and a list of $$$q$$$ updates. Each update changes the weight of one edge. The task is to output the diameter of the tree after each update.(The distance between two vertices is the sum of the weights on the unique simple path that connects them. The diameter is the largest of all those distances.)", "input_spec": "The first line contains three space-separated integers $$$n$$$, $$$q$$$ and $$$w$$$\u00a0($$$2 \\leq n \\leq 100,000, 1 \\leq q \\leq 100,000$$$, $$$1 \\leq w \\leq 20,000,000,000,000$$$) \u2013 the number of vertices in the tree, the number of updates and the limit on the weights of edges. The vertices are numbered $$$1$$$ through $$$n$$$. Next, $$$n-1$$$ lines describing the initial tree follow. The $$$i$$$-th of these lines contains three space-separated integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$\u00a0($$$1 \\leq a_i, b_i \\leq n$$$, $$$0 \\leq c_i < w$$$) meaning that initially, there is an edge between vertices $$$a_i$$$ and $$$b_i$$$ with weight $$$c_i$$$. It is guaranteed that these $$$n-1$$$ lines describe a tree. Finally, $$$q$$$ lines describing queries follow. The $$$j$$$-th of these lines contains two space-separated integers $$$d_j$$$, $$$e_j$$$\u00a0($$$0 \\leq d_j < n - 1, 0 \\leq e_j < w$$$). These two integers are then transformed according to the following scheme: $$$d'_j = (d_j + last) \\bmod (n - 1)$$$ $$$e'_j = (e_j + last) \\bmod w$$$ ", "output_spec": "Output $$$q$$$ lines. For each $$$i$$$, line $$$i$$$ should contain the diameter of the tree after the $$$i$$$-th update.", "sample_inputs": ["4 3 2000\n1 2 100\n2 3 1000\n2 4 1000\n2 1030\n1 1020\n1 890", "10 10 10000\n1 9 1241\n5 6 1630\n10 5 1630\n2 6 853\n10 1 511\n5 3 760\n8 3 1076\n4 10 1483\n7 10 40\n8 2051\n5 6294\n5 4168\n7 1861\n0 5244\n6 5156\n3 3001\n8 5267\n5 3102\n8 3623"], "sample_outputs": ["2030\n2080\n2050", "6164\n7812\n8385\n6737\n6738\n7205\n6641\n7062\n6581\n5155"], "notes": "NoteThe first sample is depicted in the figure below. The left-most picture shows the initial state of the graph. Each following picture depicts the situation after an update. The weight of the updated edge is painted green, and the diameter is red.The first query changes the weight of the $$$3$$$rd edge, i.e. $$$\\{2, 4\\}$$$, to $$$1030$$$. The largest distance between any pair of vertices is $$$2030$$$ \u2013 the distance between $$$3$$$ and $$$4$$$.As the answer is $$$2030$$$, the second query is $$$$$$d'_2 = (1 + 2030) \\bmod 3 = 0$$$$$$ $$$$$$e'_2 = (1020 + 2030) \\bmod 2000 = 1050$$$$$$ Hence the weight of the edge $$$\\{1, 2\\}$$$ is changed to $$$1050$$$. This causes the pair $$$\\{1, 4\\}$$$ to be the pair with the greatest distance, namely $$$2080$$$.The third query is decoded as $$$$$$d'_3 = (1 + 2080) \\bmod 3 = 2$$$$$$ $$$$$$e'_3 = (890 + 2080) \\bmod 2000 = 970$$$$$$ As the weight of the edge $$$\\{2, 4\\}$$$ decreases to $$$970$$$, the most distant pair is suddenly $$$\\{1, 3\\}$$$ with $$$2050$$$."}, "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c"} {"nl": {"description": "Limak is a smart brown bear who loves chemistry, reactions and transforming elements.In Bearland (Limak's home) there are n elements, numbered 1 through n. There are also special machines, that can transform elements. Each machine is described by two integers ai,\u2009bi representing two elements, not necessarily distinct. One can use a machine either to transform an element ai to bi or to transform bi to ai. Machines in Bearland aren't very resistant and each of them can be used at most once. It is possible that ai\u2009=\u2009bi and that many machines have the same pair ai,\u2009bi.Radewoosh is Limak's biggest enemy and rival. He wants to test Limak in the chemistry. They will meet tomorrow and both of them will bring all their machines. Limak has m machines but he doesn't know much about his enemy. They agreed Radewoosh will choose two distinct elements, let's denote them as x and y. Limak will be allowed to use both his and Radewoosh's machines. He may use zero or more (maybe even all) machines to achieve the goal, each machine at most once. Limak will start from an element x and his task will be to first get an element y and then to again get an element x\u00a0\u2014 then we say that he succeeds. After that Radewoosh would agree that Limak knows the chemistry (and Radewoosh would go away).Radewoosh likes some particular non-empty set of favorite elements and he will choose x,\u2009y from that set. Limak doesn't know exactly which elements are in the set and also he doesn't know what machines Radewoosh has. Limak has heard q gossips (queries) though and each of them consists of Radewoosh's machines and favorite elements. For each gossip Limak wonders if he would be able to succeed tomorrow for every pair x,\u2009y chosen from the set of favorite elements. If yes then print \"YES\" (without the quotes). But if there exists a pair (x,\u2009y) from the given set that Limak wouldn't be able to succeed then you should print \"NO\" (without the quotes).", "input_spec": "The first line contains three integers n, m and q (1\u2009\u2264\u2009n,\u2009q\u2009\u2264\u2009300\u2009000,\u20090\u2009\u2264\u2009m\u2009\u2264\u2009300\u2009000)\u00a0\u2014 the number of elements, the number of Limak's machines and the number of gossips, respectively. Each of the next m lines contains two integers ai and bi (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u2009n) describing one of Limak's machines. Then, the description of q gossips follows. The first line of the description of the i-th gossip contains two integers ni and mi (1\u2009\u2264\u2009ni\u2009\u2264\u2009300\u2009000,\u20090\u2009\u2264\u2009mi\u2009\u2264\u2009300\u2009000). The second line contains ni distinct integers xi,\u20091,\u2009xi,\u20092,\u2009...,\u2009xi,\u2009ni (1\u2009\u2264\u2009xi,\u2009j\u2009\u2264\u2009n)\u00a0\u2014 Radewoosh's favorite elements in the i-th gossip. Note that ni\u2009=\u20091 is allowed, in this case there are no pairs of distinct elements, so Limak automatically wins (the answer is \"YES\"). Then mi lines follow, each containing two integers ai,\u2009j,\u2009bi,\u2009j (1\u2009\u2264\u2009ai,\u2009j,\u2009bi,\u2009j) describing one of Radewoosh's machines in the i-th gossip. The sum of ni over all gossips won't exceed 300\u2009000. Also, the sum of mi over all gossips won't exceed 300\u2009000. Important: Because we want you to process the gossips online, in order to know the elements in Radewoosh's favorite set and elements that his machines can transform, for on each number that denotes them in the input you should use following function: int rotate(int element){ element=(element+R)%n; if (element==0) { element=n; } return element;} where R is initially equal to 0 and is increased by the number of the query any time the answer is \"YES\". Queries are numbered starting with 1 in the order they appear in the input.", "output_spec": "You should print q lines. The i-th of them should contain \"YES\" (without quotes) if for the i-th gossip for each pair of elements x and y (in the set xi,\u20091,\u2009xi,\u20092,\u2009...,\u2009xi,\u2009ni) Limak is able to succeed. Otherwise you should print \"NO\" (without quotes).", "sample_inputs": ["6 5 4\n1 2\n2 3\n3 4\n2 4\n5 6\n2 0\n4 2\n2 1\n6 2\n3 4\n3 2\n6 3 4\n2 5\n4 6\n2 1\n1 2\n1 2", "7 6 2\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n7 2\n1 2 3 4 5 6 7\n4 5\n6 7\n7 2\n1 2 3 4 5 6 7\n4 6\n5 7"], "sample_outputs": ["YES\nNO\nYES\nYES", "NO\nYES"], "notes": "NoteLets look at first sample:In first gossip Radewoosh's favorite set is {4,\u20092} and he has no machines. Limak can tranform element 4 into 2 (so half of a task is complete) and then 2 into 3, and 3 into 4. Answer is \"YES\", so R is increased by 1.In second gossip set in the input is denoted by {6,\u20092} and machine by (3,\u20094), but R is equal to 1, so set is {1,\u20093} and machine is (4,\u20095). Answer is \"NO\", so R isn't changed.In third gossip set {6,\u20094,\u20093} and machines (2,\u20095) and (4,\u20096) are deciphered to be {1,\u20095,\u20094}, (3,\u20096) and (5,\u20091).Consider Radewoosh's choices: If he chooses elements 1 and 5, then Limak is able to transform 1 into 5, then 6 into 3, 3 into 2 and 2 into 1. If he chooses elements 5 and 4, then Limak is able to transform 5 into 6, 6 into 3, 3 into 4 (half way already behind him), 4 into 2, 2 into 1, 1 into 5. If he chooses elements 1 and 4, then Limak is able to transform 1 into 2, 2 into 4, 4 into 3, 3 into 6, 6 into 5 and 5 into 1. So Limak is able to execute task. Answer is \"YES\" and R is increased by 3 (it's equal to 4 now).In last gossip {1,\u20092} and (1,\u20092) are deciphered to be {5,\u20096} and (5,\u20096). Now there are 2 machines (5,\u20096) so Limak is able to execute task again."}, "src_uid": "53f64841886b32816eadce278e636bbc"} {"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": "InputThe input contains a single integer a (0\u2009\u2264\u2009a\u2009\u2264\u200935).OutputOutput a single integer.ExamplesInput3Output8Input10Output1024", "input_spec": "The input contains a single integer a (0\u2009\u2264\u2009a\u2009\u2264\u200935).", "output_spec": "Output a single integer.", "sample_inputs": ["3", "10"], "sample_outputs": ["8", "1024"], "notes": null}, "src_uid": "76f6ebfaeea789952c931d65c6a5fdff"} {"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": "Cold winter evenings in Tomsk are very boring \u2014 nobody wants be on the streets at such a time. Residents of Tomsk while away the time sitting in warm apartments, inventing a lot of different games. One of such games is 'Colored Jenga'.This game requires wooden blocks of three colors: red, green and blue. A tower of n levels is made from them. Each level consists of three wooden blocks. The blocks in each level can be of arbitrary colors, but they are always located close and parallel to each other. An example of such a tower is shown in the figure. The game is played by exactly one person. Every minute a player throws a special dice which has six sides. Two sides of the dice are green, two are blue, one is red and one is black. The dice shows each side equiprobably.If the dice shows red, green or blue, the player must take any block of this color out of the tower at this minute so that the tower doesn't fall. If this is not possible, the player waits until the end of the minute, without touching the tower. He also has to wait until the end of the minute without touching the tower if the dice shows the black side. It is not allowed to take blocks from the top level of the tower (whether it is completed or not).Once a player got a block out, he must put it on the top of the tower so as to form a new level or finish the upper level consisting of previously placed blocks. The newly constructed levels should have all the same properties as the initial levels. If the upper level is not completed, starting the new level is prohibited.For the tower not to fall, in each of the levels except for the top, there should be at least one block. Moreover, if at some of these levels there is exactly one block left and this block is not the middle block, the tower falls.The game ends at the moment when there is no block in the tower that you can take out so that the tower doesn't fall.Here is a wonderful game invented by the residents of the city of Tomsk. I wonder for how many minutes can the game last if the player acts optimally well? If a player acts optimally well, then at any moment he tries to choose the block he takes out so as to minimize the expected number of the game duration.Your task is to write a program that determines the expected number of the desired amount of minutes.", "input_spec": "The first line of the input contains the only integer n (2\u2009\u2264\u2009n\u2009\u2264\u20096) \u2014 the number of levels in the tower. Then n lines follow, describing the levels of the tower from the bottom to the top (the first line is the top of the tower). Each level is described by three characters, the first and the third of them set the border blocks of the level and the second one is the middle block. The character that describes the block has one of the following values 'R' (a red block), 'G' (a green block) and 'B' (a blue block).", "output_spec": "In the only line of the output print the sought mathematical expectation value. The answer will be considered correct if its relative or absolute error doesn't exceed 10\u2009-\u20096.", "sample_inputs": ["6\nRGB\nGRG\nBBB\nGGR\nBRG\nBRB"], "sample_outputs": ["17.119213696601992"], "notes": null}, "src_uid": "bdcefa26de49e0e9d4d10d138443aa8a"} {"nl": {"description": "After playing Neo in the legendary \"Matrix\" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For example, 1, 101, 0000 are good, while 01, 1001, and 111000 are not good.We are given a string $$$s$$$ of length $$$n$$$ consisting of only zeroes and ones. We need to cut $$$s$$$ into minimal possible number of substrings $$$s_1, s_2, \\ldots, s_k$$$ such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings $$$s_1, s_2, \\ldots, s_k$$$ such that their concatenation (joining) equals $$$s$$$, i.e. $$$s_1 + s_2 + \\dots + s_k = s$$$.For example, cuttings 110010 into 110 and 010 or into 11 and 0010 are valid, as 110, 010, 11, 0010 are all good, and we can't cut 110010 to the smaller number of substrings as 110010 isn't good itself. At the same time, cutting of 110010 into 1100 and 10 isn't valid as both strings aren't good. Also, cutting of 110010 into 1, 1, 0010 isn't valid, as it isn't minimal, even though all $$$3$$$ strings are good.Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.", "input_spec": "The first line of the input contains a single integer $$$n$$$ ($$$1\\le n \\le 100$$$)\u00a0\u2014 the length of the string $$$s$$$. The second line contains the string $$$s$$$ of length $$$n$$$ consisting only from zeros and ones.", "output_spec": "In the first line, output a single integer $$$k$$$ ($$$1\\le k$$$)\u00a0\u2014 a minimal number of strings you have cut $$$s$$$ into. In the second line, output $$$k$$$ strings $$$s_1, s_2, \\ldots, s_k$$$ separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to $$$s$$$ and all of them have to be good. If there are multiple answers, print any.", "sample_inputs": ["1\n1", "2\n10", "6\n100011"], "sample_outputs": ["1\n1", "2\n1 0", "2\n100 011"], "notes": "NoteIn the first example, the string 1 wasn't cut at all. As it is good, the condition is satisfied.In the second example, 1 and 0 both are good. As 10 isn't good, the answer is indeed minimal.In the third example, 100 and 011 both are good. As 100011 isn't good, the answer is indeed minimal."}, "src_uid": "4ebed264d40a449602a26ceef2e849d1"} {"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": "After some programming contest Roma decided to try himself in tourism. His home country Uzhlyandia is a Cartesian plane. He wants to walk along each of the Main Straight Lines in Uzhlyandia. It is known that each of these lines is a straight line parallel to one of the axes (i.e. it is described with the equation x\u2009=\u2009a or y\u2009=\u2009a, where a is integer called the coordinate of this line).Roma lost his own map, so he should find out the coordinates of all lines at first. Uncle Anton agreed to help him, using the following rules: Initially Roma doesn't know the number of vertical and horizontal lines and their coordinates; Roma can announce integer coordinates of some point in Uzhlandia, and Anton then will tell him the minimum among the distances from the chosen point to each of the lines. However, since the coordinates of the lines don't exceed 108 by absolute value, Roma can't choose a point with coordinates exceeding 108 by absolute value. Uncle Anton is in a hurry to the UOI (Uzhlandian Olympiad in Informatics), so he can only answer no more than 3\u00b7105 questions.The problem is that Roma doesn't know how to find out the coordinates of the lines. Write a program that plays Roma's role and finds the coordinates.", "input_spec": "There is no input initially. Your program should make queries to get information. It is guaranteed that the number of horizontal and vertical lines is at least 1 and less than or equal to 104 for each type.", "output_spec": null, "sample_inputs": ["1\n1\n3\n2"], "sample_outputs": ["0 1 2\n0 -2 -2\n0 5 6\n0 -2 2\n1 1 2\n2\n0 -3"], "notes": "NoteThe example test is 1 220 -3The minimum distances are: from (1,\u20092) to x\u2009=\u20092; from (\u2009-\u20092,\u2009\u2009-\u20092) to y\u2009=\u2009\u2009-\u20093; from (5,\u20096) to x\u2009=\u20092; from (\u2009-\u20092,\u20092) to y\u2009=\u20090. "}, "src_uid": "583cd1e553133b297f99fd52e5ad355b"} {"nl": {"description": "Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number \u2014 the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number. Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.", "input_spec": "The single line of the input contains three space-separated integers a, b and c (1\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u2009106) \u2014 the valence numbers of the given atoms.", "output_spec": "If such a molecule can be built, print three space-separated integers \u2014 the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print \"Impossible\" (without the quotes).", "sample_inputs": ["1 1 2", "3 4 5", "4 1 1"], "sample_outputs": ["0 1 1", "1 3 2", "Impossible"], "notes": "NoteThe first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.The configuration in the fourth figure is impossible as each atom must have at least one atomic bond."}, "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"} {"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": "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": "Your friend recently gave you some slimes for your birthday. You have a very large amount of slimes with value 1 and 2, and you decide to invent a game using these slimes.You initialize a row with n empty spaces. You also choose a number p to be used in the game. Then, you will perform the following steps while the last space is empty. With probability , you will choose a slime with value 1, and with probability , you will choose a slime with value 2. You place the chosen slime on the last space of the board. You will push the slime to the left as far as possible. If it encounters another slime, and they have the same value v, you will merge the slimes together to create a single slime with value v\u2009+\u20091. This continues on until the slime reaches the end of the board, or encounters a slime with a different value than itself. You have played the game a few times, but have gotten bored of it. You are now wondering, what is the expected sum of all values of the slimes on the board after you finish the game.", "input_spec": "The first line of the input will contain two integers n,\u2009p (1\u2009\u2264\u2009n\u2009\u2264\u2009109,\u20091\u2009\u2264\u2009p\u2009<\u2009109).", "output_spec": "Print the expected sum of all slimes on the board after the game finishes. Your answer will be considered correct if its absolute or relative error does not exceed 10\u2009-\u20094. 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 500000000", "10 1", "100 123456789"], "sample_outputs": ["3.562500000000000", "64.999983360007620", "269.825611298854770"], "notes": "NoteIn the first sample, we have a board with two squares, and there is a 0.5 probability of a 1 appearing and a 0.5 probability of a 2 appearing.Our final board states can be 1 2 with probability 0.25, 2 1 with probability 0.375, 3 2 with probability 0.1875, 3 1 with probability 0.1875. The expected value is thus (1\u2009+\u20092)\u00b70.25\u2009+\u2009(2\u2009+\u20091)\u00b70.375\u2009+\u2009(3\u2009+\u20092)\u00b70.1875\u2009+\u2009(3\u2009+\u20091)\u00b70.1875\u2009=\u20093.5625."}, "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66"} {"nl": {"description": "Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor\u2019s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up \u2014 who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that\u2019s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.", "input_spec": "The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic\u2019s gesture. ", "output_spec": "Print \"F\" (without quotes) if Uncle Fyodor wins. Print \"M\" if Matroskin wins and \"S\" if Sharic wins. If it is impossible to find the winner, print \"?\".", "sample_inputs": ["rock\nrock\nrock", "paper\nrock\nrock", "scissors\nrock\nrock", "scissors\npaper\nrock"], "sample_outputs": ["?", "F", "?", "?"], "notes": null}, "src_uid": "072c7d29a1b338609a72ab6b73988282"} {"nl": {"description": "There is a string of length $$$n+1$$$ of characters 'A' and 'B'. The first character and last character of the string are equal to 'A'.You are given $$$m$$$ indices $$$p_1, p_2, \\ldots, p_m$$$ ($$$0$$$-indexation) denoting the other indices of characters 'A' in the string. Let's denote the minimum distance between two neighboring 'A' as $$$l$$$, and maximum distance between neighboring 'A' as $$$r$$$.For example, $$$(l,r)$$$ of string \"ABBAABBBA\" is $$$(1,4)$$$.And let's denote the balance degree of a string as the value of $$$r-l$$$.Now Dreamoon wants to change exactly $$$k$$$ characters from 'B' to 'A', and he wants to make the balance degree of the string as small as possible.Please calculate the required minimum possible value of balance degree.", "input_spec": "The first line contains one integer $$$t$$$ denoting the number of test cases ($$$1 \\leq t \\leq 400\\,000$$$). For each test case, the first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \\leq n \\leq 10^{15}, 0 \\leq m \\leq 400\\,000, 0 \\leq k < n - m$$$). The second line contains $$$m$$$ integers $$$p_1, p_2, \\ldots, p_m$$$, ($$$0 < p_1 < p_2 < \\ldots < p_m < n$$$). The total sum of $$$m$$$ is at most $$$400\\,000$$$.", "output_spec": "For each test case, print one integer: the smallest possible value of balance degree after $$$k$$$ changes of 'B' to 'A'.", "sample_inputs": ["5\n80 3 5\n11 24 50\n81 7 12\n4 10 17 26 37 48 61\n25 10 14\n3 4 7 12 13 15 17 19 21 23\n1 0 0\n\n10 2 0\n2 4"], "sample_outputs": ["5\n2\n0\n0\n4"], "notes": null}, "src_uid": "37d912c36aedea1b8f8e78a849062d90"} {"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": "JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $$$n$$$, you can perform the following operations zero or more times: mul $$$x$$$: multiplies $$$n$$$ by $$$x$$$ (where $$$x$$$ is an arbitrary positive integer). sqrt: replaces $$$n$$$ with $$$\\sqrt{n}$$$ (to apply this operation, $$$\\sqrt{n}$$$ must be an integer). You can perform these operations as many times as you like. What is the minimum value of $$$n$$$, that can be achieved and what is the minimum number of operations, to achieve that minimum value?Apparently, no one in the class knows the answer to this problem, maybe you can help them?", "input_spec": "The only line of the input contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$)\u00a0\u2014 the initial number.", "output_spec": "Print two integers: the minimum integer $$$n$$$ that can be achieved using the described operations and the minimum number of operations required.", "sample_inputs": ["20", "5184"], "sample_outputs": ["10 2", "6 4"], "notes": "NoteIn the first example, you can apply the operation mul $$$5$$$ to get $$$100$$$ and then sqrt to get $$$10$$$.In the second example, you can first apply sqrt to get $$$72$$$, then mul $$$18$$$ to get $$$1296$$$ and finally two more sqrt and you get $$$6$$$.Note, that even if the initial value of $$$n$$$ is less or equal $$$10^6$$$, it can still become greater than $$$10^6$$$ after applying one or more operations."}, "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"nl": {"description": "InputThe input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.OutputOutput \"YES\" or \"NO\".ExamplesInput\nNEAT\nOutput\nYES\nInput\nWORD\nOutput\nNO\nInput\nCODER\nOutput\nNO\nInput\nAPRILFOOL\nOutput\nNO\nInput\nAI\nOutput\nYES\nInput\nJUROR\nOutput\nYES\nInput\nYES\nOutput\nNO\n", "input_spec": "The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.", "output_spec": "Output \"YES\" or \"NO\".", "sample_inputs": ["NEAT", "WORD", "CODER", "APRILFOOL", "AI", "JUROR", "YES"], "sample_outputs": ["YES", "NO", "NO", "NO", "YES", "YES", "NO"], "notes": null}, "src_uid": "15008dcb8dc8506c39aef0e3d8fca70c"} {"nl": {"description": "Ivan Anatolyevich's agency is starting to become famous in the town. They have already ordered and made n TV commercial videos. Each video is made in a special way: the colors and the soundtrack are adjusted to the time of the day and the viewers' mood. That's why the i-th video can only be shown within the time range of [li,\u2009ri] (it is not necessary to use the whole segment but the broadcast time should be within this segment).Now it's time to choose a TV channel to broadcast the commercial. Overall, there are m TV channels broadcasting in the city, the j-th one has cj viewers, and is ready to sell time [aj,\u2009bj] to broadcast the commercial.Ivan Anatolyevich is facing a hard choice: he has to choose exactly one video i and exactly one TV channel j to broadcast this video and also a time range to broadcast [x,\u2009y]. At that the time range should be chosen so that it is both within range [li,\u2009ri] and within range [aj,\u2009bj].Let's define the efficiency of the broadcast as value (y\u2009-\u2009x)\u00b7cj \u2014 the total sum of time that all the viewers of the TV channel are going to spend watching the commercial. Help Ivan Anatolyevich choose the broadcast with the maximum efficiency!", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20092\u00b7105)\u00a0\u2014 the number of commercial videos and channels, respectively. Each of the following n lines contains two integers li, ri (0\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u2009109)\u00a0\u2014 the segment of time when it is possible to show the corresponding video. Each of the following m lines contains three integers aj, bj, cj (0\u2009\u2264\u2009aj\u2009\u2264\u2009bj\u2009\u2264\u2009109, 1\u2009\u2264\u2009cj\u2009\u2264\u2009109), characterizing the TV channel.", "output_spec": "In the first line print an integer \u2014 the maximum possible efficiency of the broadcast. If there is no correct way to get a strictly positive efficiency, print a zero. If the maximum efficiency is strictly positive, in the second line also print the number of the video i (1\u2009\u2264\u2009i\u2009\u2264\u2009n) and the number of the TV channel j (1\u2009\u2264\u2009j\u2009\u2264\u2009m) in the most effective broadcast. If there are multiple optimal answers, you can print any of them.", "sample_inputs": ["2 3\n7 9\n1 4\n2 8 2\n0 4 1\n8 9 3", "1 1\n0 0\n1 1 10"], "sample_outputs": ["4\n2 1", "0"], "notes": "NoteIn the first sample test the most optimal solution is to show the second commercial using the first TV channel at time [2,\u20094]. The efficiency of such solution is equal to (4\u2009-\u20092)\u00b72\u2009=\u20094.In the second sample test Ivan Anatolievich's wish does not meet the options of the TV channel, the segments do not intersect, so the answer is zero."}, "src_uid": "af518bd91bddecb77772277341420fa2"} {"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": "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": "Sarah has always been a lover of nature, and a couple of years ago she saved up enough money to travel the world and explore all the things built by nature over its lifetime on earth. During this time she visited some truly special places which were left untouched for centuries, from watching icebergs in freezing weather to scuba-diving in oceans and admiring the sea life, residing unseen. These experiences were enhanced with breathtaking views built by mountains over time and left there for visitors to see for years on end. Over time, all these expeditions took a toll on Sarah and culminated in her decision to settle down in the suburbs and live a quiet life. However, as Sarah's love for nature never faded, she started growing flowers in her garden in an attempt to stay connected with nature. At the beginning she planted only blue orchids, but over time she started using different flower types to add variety to her collection of flowers. This collection of flowers can be represented as an array of $$$N$$$ flowers and the $$$i$$$-th of them has a type associated with it, denoted as $$$A_i$$$. Each resident, passing by her collection and limited by the width of his view, can only see $$$K$$$ contiguous flowers at each moment in time. To see the whole collection, the resident will look at the first $$$K$$$ contiguous flowers $$$A_1, A_2, ..., A_K$$$, then shift his view by one flower and look at the next section of K contiguous flowers $$$A_2, A_3, ..., A_{K+1}$$$ and so on until they scan the whole collection, ending with section $$$A_{N-K+1}, ..., A_{N-1}, A_N$$$.Each resident determines the beautiness of a section of $$$K$$$ flowers as the number of distinct flower types in that section. Furthermore, the beautiness of the whole collection is calculated by summing the beautiness values of each contiguous section. Formally, beautiness $$$B_i$$$ of a section starting at the $$$i$$$-th position is calculated as $$$B_i = distinct(A_i, A_{i+1}, ..., A_{i+K-1})$$$, and beautiness of the collection $$$B$$$ is calculated as $$$B=B_1 + B_2 + ... + B_{N-K+1}$$$.In addition, as Sarah wants to keep her collection of flowers have a fresh feel, she can also pick two points $$$L$$$ and $$$R$$$, dispose flowers between those two points and plant new flowers, all of them being the same type.You will be given $$$Q$$$ queries and each of those queries will be of the following two types: You will be given three integers $$$L, R, X$$$ describing that Sarah has planted flowers of type $$$X$$$ between positions $$$L$$$ and $$$R$$$ inclusive. Formally collection is changed such that $$$A[i]=X$$$ for all $$$i$$$ in range $$$[L.. R]$$$. You will be given integer $$$K$$$, width of the resident's view and you have to determine the beautiness value $$$B$$$ resident has associated with the collection For each query of second type print the result \u2013 beautiness $$$B$$$ of the collection.", "input_spec": "First line contains two integers $$$N$$$ and $$$Q \\;(1 \\leq N, Q \\leq 10^5)\\,$$$ \u2014 number of flowers and the number of queries, respectively. The second line contains $$$N$$$ integers $$$A_1, A_2, ..., A_N\\;(1 \\leq A_i \\leq 10^9)\\,$$$ \u2014 where $$$A_i$$$ represents type of the $$$i$$$-th flower. Each of the next $$$Q$$$ lines describe queries and start with integer $$$T\\in\\{1, 2\\}$$$. If $$$T = 1$$$, there will be three more integers in the line $$$L, R, X\\;(1 \\leq L, R \\leq N;\\; 1 \\leq X \\leq 10^9)\\,$$$ \u2014 $$$L$$$ and $$$R$$$ describing boundaries and $$$X$$$ describing the flower type If $$$T = 2$$$, there will be one more integer in the line $$$K\\;(1 \\leq K \\leq N)\\,$$$ \u2014 resident's width of view ", "output_spec": "For each query of the second type print the beautiness $$$B$$$ of the collection.", "sample_inputs": ["5 5\n1 2 3 4 5\n2 3\n1 1 2 5\n2 4\n1 2 4 5\n2 2"], "sample_outputs": ["9\n6\n4"], "notes": "NoteLet's look at the example.Initially the collection is $$$[1, 2, 3, 4, 5]$$$. In the first query $$$K = 3$$$, we consider sections of three flowers with the first being $$$[1, 2, 3]$$$. Since beautiness of the section is the number of distinct flower types in that section, $$$B_1 = 3$$$. Second section is $$$[2, 3, 4]$$$ and $$$B_2 = 3$$$. Third section is $$$[3, 4, 5]$$$ and $$$B_3 = 3$$$, since the flower types are all distinct. The beautiness value resident has associated with the collection is $$$B = B_1 + B_2 + B_3 = 3 + 3 + 3 = 9$$$.After the second query, the collection becomes $$$[5, 5, 3, 4, 5]$$$. For the third query $$$K = 4$$$, so we consider sections of four flowers with the first being $$$[5, 5, 3, 4]$$$. There are three distinct flower types $$$[5, 3, 4]$$$ in this section, so $$$B_1 = 3$$$. Second section $$$[5, 3, 4, 5]$$$ also has $$$3$$$ distinct flower types, so $$$B_2 = 3$$$. The beautiness value resident has associated with the collection is $$$B = B_1 + B_2 = 3 + 3 = 6$$$After the fourth query, the collection becomes $$$[5, 5, 5, 5, 5]$$$.For the fifth query $$$K = 2$$$ and in this case all the four sections are same with each of them being $$$[5, 5]$$$. Beautiness of $$$[5, 5]$$$ is $$$1$$$ since there is only one distinct element in this section $$$[5]$$$. Beautiness of the whole collection is $$$B = B_1 + B_2 + B_3 + B_4 = 1 + 1 + 1 + 1 = 4$$$"}, "src_uid": "ac85e953ff1cce050834f4e793ec1f02"} {"nl": {"description": "Dima and Anya love playing different games. Now Dima has imagined a new game that he wants to play with Anya.Dima writes n pairs of integers on a piece of paper (li,\u2009ri) (1\u2009\u2264\u2009li\u2009<\u2009ri\u2009\u2264\u2009p). Then players take turns. On his turn the player can do the following actions: choose the number of the pair i (1\u2009\u2264\u2009i\u2009\u2264\u2009n), such that ri\u2009-\u2009li\u2009>\u20092; replace pair number i by pair or by pair . Notation \u230ax\u230b means rounding down to the closest integer. The player who can't make a move loses.Of course, Dima wants Anya, who will move first, to win. That's why Dima should write out such n pairs of integers (li,\u2009ri) (1\u2009\u2264\u2009li\u2009<\u2009ri\u2009\u2264\u2009p), that if both players play optimally well, the first one wins. Count the number of ways in which Dima can do it. Print the remainder after dividing the answer by number 1000000007\u00a0(109\u2009+\u20097).Two ways are considered distinct, if the ordered sequences of the written pairs are distinct.", "input_spec": "The first line contains two integers n, p (1\u2009\u2264\u2009n\u2009\u2264\u20091000,\u20091\u2009\u2264\u2009p\u2009\u2264\u2009109). The numbers are separated by a single space.", "output_spec": "In a single line print the remainder after dividing the answer to the problem by number 1000000007\u00a0(109\u2009+\u20097).", "sample_inputs": ["2 2", "4 4", "100 1000"], "sample_outputs": ["0", "520", "269568947"], "notes": null}, "src_uid": "c03b6379e9d186874ac3d97c6968fbd0"} {"nl": {"description": "Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.In this problem you are given n (1\u2009\u2264\u2009n\u2009\u2264\u200924) integers a1,\u2009a2,\u2009...,\u2009an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.", "input_spec": "The first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200924) \u2014 the number of integers. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (28\u2009\u2264\u2009ai\u2009\u2264\u200931) \u2014 the numbers you are to check.", "output_spec": "If there are several consecutive months that fit the sequence, print \"YES\" (without quotes). Otherwise, print \"NO\" (without quotes). You can print each letter in arbitrary case (small or large).", "sample_inputs": ["4\n31 31 30 31", "2\n30 30", "5\n29 31 30 31 30", "3\n31 28 30", "3\n31 31 28"], "sample_outputs": ["Yes", "No", "Yes", "No", "Yes"], "notes": "NoteIn the first example the integers can denote months July, August, September and October.In the second example the answer is no, because there are no two consecutive months each having 30 days.In the third example the months are: February (leap year) \u2014 March \u2014 April \u2013 May \u2014 June.In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.In the fifth example the months are: December \u2014 January \u2014 February (non-leap year)."}, "src_uid": "d60c8895cebcc5d0c6459238edbdb945"} {"nl": {"description": "You are given a sequence $$$a_1, a_2, \\dots, a_n$$$ consisting of $$$n$$$ integers.You can choose any non-negative integer $$$D$$$ (i.e. $$$D \\ge 0$$$), and for each $$$a_i$$$ you can: add $$$D$$$ (only once), i.\u2009e. perform $$$a_i := a_i + D$$$, or subtract $$$D$$$ (only once), i.\u2009e. perform $$$a_i := a_i - D$$$, or leave the value of $$$a_i$$$ unchanged. It is possible that after an operation the value $$$a_i$$$ becomes negative.Your goal is to choose such minimum non-negative integer $$$D$$$ and perform changes in such a way, that all $$$a_i$$$ are equal (i.e. $$$a_1=a_2=\\dots=a_n$$$).Print the required $$$D$$$ or, if it is impossible to choose such value $$$D$$$, print -1.For example, for array $$$[2, 8]$$$ the value $$$D=3$$$ is minimum possible because you can obtain the array $$$[5, 5]$$$ if you will add $$$D$$$ to $$$2$$$ and subtract $$$D$$$ from $$$8$$$. And for array $$$[1, 4, 7, 7]$$$ the value $$$D=3$$$ is also minimum possible. You can add it to $$$1$$$ and subtract it from $$$7$$$ and obtain the array $$$[4, 4, 4, 4]$$$.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$) \u2014 the sequence $$$a$$$.", "output_spec": "Print one integer \u2014 the minimum non-negative integer value $$$D$$$ such that if you add this value to some $$$a_i$$$, subtract this value from some $$$a_i$$$ and leave some $$$a_i$$$ without changes, all obtained values become equal. If it is impossible to choose such value $$$D$$$, print -1.", "sample_inputs": ["6\n1 4 4 7 4 1", "5\n2 2 5 2 5", "4\n1 3 3 7", "2\n2 8"], "sample_outputs": ["3", "3", "-1", "3"], "notes": null}, "src_uid": "d486a88939c132848a7efdf257b9b066"} {"nl": {"description": "Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+\u20131. Help him to find the least number of digits 1 in such sum.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009<\u20091015).", "output_spec": "Print expected minimal number of digits 1.", "sample_inputs": ["121"], "sample_outputs": ["6"], "notes": null}, "src_uid": "1b17a7b3b41077843ee1d6e0607720d6"} {"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": "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": "The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose \u2014 to show the developer the imperfection of their protection.The found algorithm looks the following way. At first the digits of the number are shuffled in the following order <first digit><third digit><fifth digit><fourth digit><second digit>. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455\u00a0422\u00a0043\u00a0125\u00a0550\u00a0171\u00a0232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232.Vasya is going to write a keygen program implementing this algorithm. Can you do the same?", "input_spec": "The only line of the input contains a positive integer five digit number for which the activation code should be found.", "output_spec": "Output exactly 5 digits without spaces between them \u2014 the found activation code of the program.", "sample_inputs": ["12345"], "sample_outputs": ["71232"], "notes": null}, "src_uid": "51b1c216948663fff721c28d131bf18f"} {"nl": {"description": "Anya loves to fold and stick. Today she decided to do just that.Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes.Anya can stick an exclamation mark on the cube and get the factorial of the number written on the cube. For example, if a cube reads 5, then after the sticking it reads 5!, which equals 120.You need to help Anya count how many ways there are to choose some of the cubes and stick on some of the chosen cubes at most k exclamation marks so that the sum of the numbers written on the chosen cubes after the sticking becomes equal to S. Anya can stick at most one exclamation mark on each cube. Can you do it?Two ways are considered the same if they have the same set of chosen cubes and the same set of cubes with exclamation marks.", "input_spec": "The first line of the input contains three space-separated integers n, k and S (1\u2009\u2264\u2009n\u2009\u2264\u200925, 0\u2009\u2264\u2009k\u2009\u2264\u2009n, 1\u2009\u2264\u2009S\u2009\u2264\u20091016)\u00a0\u2014\u00a0the number of cubes and the number of stickers that Anya has, and the sum that she needs to get. The second line contains n positive integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009109)\u00a0\u2014\u00a0the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one. Multiple cubes can contain the same numbers.", "output_spec": "Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number S.", "sample_inputs": ["2 2 30\n4 3", "2 2 7\n4 3", "3 1 1\n1 1 1"], "sample_outputs": ["1", "1", "6"], "notes": "NoteIn the first sample the only way is to choose both cubes and stick an exclamation mark on each of them.In the second sample the only way is to choose both cubes but don't stick an exclamation mark on any of them.In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six."}, "src_uid": "2821a11066dffc7e8f6a60a8751cea37"} {"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": "Yaroslav calls an array of r integers a1,\u2009a2,\u2009...,\u2009ar good, if it meets the following conditions: |a1\u2009-\u2009a2|\u2009=\u20091,\u2009|a2\u2009-\u2009a3|\u2009=\u20091,\u2009...,\u2009|ar\u2009-\u20091\u2009-\u2009ar|\u2009=\u20091,\u2009|ar\u2009-\u2009a1|\u2009=\u20091, at that . An array of integers b1,\u2009b2,\u2009...,\u2009br is called great, if it meets the following conditions: The elements in it do not decrease (bi\u2009\u2264\u2009bi\u2009+\u20091). If the inequalities 1\u2009\u2264\u2009r\u2009\u2264\u2009n and 1\u2009\u2264\u2009bi\u2009\u2264\u2009m hold. If we can rearrange its elements and get at least one and at most k distinct good arrays. Yaroslav has three integers n,\u2009m,\u2009k. He needs to count the number of distinct great arrays. Help Yaroslav! As the answer may be rather large, print the remainder after dividing it by 1000000007 (109\u2009+\u20097).Two arrays are considered distinct if there is a position in which they have distinct numbers.", "input_spec": "The single line contains three integers n, m, k (1\u2009\u2264\u2009n,\u2009m,\u2009k\u2009\u2264\u2009100).", "output_spec": "In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1 1 1", "3 3 3"], "sample_outputs": ["0", "2"], "notes": null}, "src_uid": "c6d275b1e1d5c9e39e2cf990a635fa6b"} {"nl": {"description": "Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai,\u2009j.Let's call matrix A clear if no two cells containing ones have a common side.Let's call matrix A symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (i,\u2009j) (1\u2009\u2264\u2009i,\u2009j\u2009\u2264\u2009n) both of the following conditions must be met: Ai,\u2009j\u2009=\u2009An\u2009-\u2009i\u2009+\u20091,\u2009j and Ai,\u2009j\u2009=\u2009Ai,\u2009n\u2009-\u2009j\u2009+\u20091.Let's define the sharpness of matrix A as the number of ones in it.Given integer x, your task is to find the smallest positive integer n such that there exists a clear symmetrical matrix A with side n and sharpness x.", "input_spec": "The only line contains a single integer x (1\u2009\u2264\u2009x\u2009\u2264\u2009100) \u2014 the required sharpness of the matrix.", "output_spec": "Print a single number \u2014 the sought value of n.", "sample_inputs": ["4", "9"], "sample_outputs": ["3", "5"], "notes": "NoteThe figure below shows the matrices that correspond to the samples: "}, "src_uid": "01eccb722b09a0474903b7e5abc4c47a"} {"nl": {"description": "Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $$$1$$$, $$$5$$$, $$$10$$$ and $$$50$$$ respectively. The use of other roman digits is not allowed.Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.For example, the number XXXV evaluates to $$$35$$$ and the number IXI\u00a0\u2014 to $$$12$$$.Pay attention to the difference to the traditional roman system\u00a0\u2014 in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $$$11$$$, not $$$9$$$.One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $$$n$$$ roman digits I, V, X, L.", "input_spec": "The only line of the input file contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$)\u00a0\u2014 the number of roman digits to use.", "output_spec": "Output a single integer\u00a0\u2014 the number of distinct integers which can be represented using $$$n$$$ roman digits exactly.", "sample_inputs": ["1", "2", "10"], "sample_outputs": ["4", "10", "244"], "notes": "NoteIn the first sample there are exactly $$$4$$$ integers which can be represented\u00a0\u2014 I, V, X and L.In the second sample it is possible to represent integers $$$2$$$ (II), $$$6$$$ (VI), $$$10$$$ (VV), $$$11$$$ (XI), $$$15$$$ (XV), $$$20$$$ (XX), $$$51$$$ (IL), $$$55$$$ (VL), $$$60$$$ (XL) and $$$100$$$ (LL)."}, "src_uid": "75ec99318736a8a1b62a8d51efd95355"} {"nl": {"description": "Nezzar buys his favorite snack\u00a0\u2014 $$$n$$$ chocolate bars with lengths $$$l_1,l_2,\\ldots,l_n$$$. However, chocolate bars might be too long to store them properly! In order to solve this problem, Nezzar designs an interesting process to divide them into small pieces. Firstly, Nezzar puts all his chocolate bars into a black box. Then, he will perform the following operation repeatedly until the maximum length over all chocolate bars does not exceed $$$k$$$. Nezzar picks a chocolate bar from the box with probability proportional to its length $$$x$$$. After step $$$1$$$, Nezzar uniformly picks a real number $$$r \\in (0,x)$$$ and divides the chosen chocolate bar into two chocolate bars with lengths $$$r$$$ and $$$x-r$$$. Lastly, he puts those two new chocolate bars into the black box. Nezzar now wonders, what is the expected number of operations he will perform to divide his chocolate bars into small pieces.It can be shown that the answer can be represented as $$$\\frac{P}{Q}$$$, where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \\not \\equiv 0$$$ ($$$\\bmod 998\\,244\\,353$$$). Print the value of $$$P\\cdot Q^{-1} \\mod 998\\,244\\,353$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 50, 1 \\le k \\le 2000$$$). The second line contains $$$n$$$ integers $$$l_1, l_2, \\ldots, l_n$$$ ($$$1 \\le l_i$$$, $$$\\sum_{i=1}^{n} l_i \\le 2000$$$).", "output_spec": "Print a single integer \u2014 the expected number of operations Nezzar will perform to divide his chocolate bars into small pieces modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["1 1\n2", "1 1\n1", "1 5\n1234", "2 1\n2 3", "10 33\n10 20 30 40 50 60 70 80 90 100"], "sample_outputs": ["4", "0", "15630811", "476014684", "675105648"], "notes": null}, "src_uid": "26d565c193a5920b042c783109496b4c"} {"nl": {"description": "How horrible! The empire of galactic chickens tries to conquer a beautiful city \"Z\", they have built a huge incubator that produces millions of chicken soldiers a day, and fenced it around. The huge incubator looks like a polygon on the plane Oxy with n vertices. Naturally, DravDe can't keep still, he wants to destroy the chicken empire. For sure, he will start with the incubator.DravDe is strictly outside the incubator's territory in point A(xa,\u2009ya), and wants to get inside and kill all the chickens working there. But it takes a lot of doing! The problem is that recently DravDe went roller skating and has broken both his legs. He will get to the incubator's territory in his jet airplane LEVAP-41.LEVAP-41 flies at speed V(xv,\u2009yv,\u2009zv). DravDe can get on the plane in point A, fly for some time, and then air drop himself. DravDe is very heavy, that's why he falls vertically at speed Fdown, but in each point of his free fall DravDe can open his parachute, and from that moment he starts to fall at the wind speed U(xu,\u2009yu,\u2009zu) until he lands. Unfortunately, DravDe isn't good at mathematics. Would you help poor world's saviour find such an air dropping plan, that allows him to land on the incubator's territory? If the answer is not unique, DravDe wants to find the plan with the minimum time of his flight on the plane. If the answers are still multiple, he wants to find the one with the minimum time of his free fall before opening his parachute", "input_spec": "The first line contains the number n (3\u2009\u2264\u2009n\u2009\u2264\u2009104) \u2014 the amount of vertices of the fence. Then there follow n lines containing the coordinates of these vertices (two integer numbers xi,\u2009yi) in clockwise or counter-clockwise order. It's guaranteed, that the fence does not contain self-intersections. The following four lines contain coordinates of point A(xa,\u2009ya), speeds V(xv,\u2009yv,\u2009zv), Fdown and speed U(xu,\u2009yu,\u2009zu). All the input numbers are integer. All the coordinates don't exceed 104 in absolute value. It's guaranteed, that zv\u2009>\u20090 and Fdown,\u2009zu\u2009<\u20090, and point A is strictly outside the incubator's territory.", "output_spec": "In the first line output two numbers t1,\u2009t2 such, that if DravDe air drops at time t1 (counting from the beginning of the flight), he lands on the incubator's territory (landing on the border is regarder as landing on the territory). If DravDe doesn't open his parachute, the second number should be equal to the duration of DravDe's falling down. If it's impossible for DravDe to get to the incubator's territory, output -1 -1. If the answer is not unique, output the answer with the minimum t1. If the answers are still multiple, output the answer with the minimum t2. Your answer must have an absolute or relative error less than 10\u2009-\u20096.", "sample_inputs": ["4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 0 1\n-1\n0 1 -1", "4\n0 0\n0 1\n1 1\n1 0\n0 -1\n-1 -1 1\n-1\n0 1 -1", "4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 1 1\n-1\n1 1 -1"], "sample_outputs": ["1.00000000 0.00000000", "-1.00000000 -1.00000000", "0.50000000 0.00000000"], "notes": null}, "src_uid": "d6afa6a515fc0adde11891e81cb179d7"} {"nl": {"description": "You have a root tree containing n vertexes. Let's number the tree vertexes with integers from 1 to n. The tree root is in the vertex 1.Each vertex (except fot the tree root) v has a direct ancestor pv. Also each vertex v has its integer value sv. Your task is to perform following queries: P v u (u\u2009\u2260\u2009v). If u isn't in subtree of v, you must perform the assignment pv\u2009=\u2009u. Otherwise you must perform assignment pu\u2009=\u2009v. Note that after this query the graph continues to be a tree consisting of n vertexes. V v t. Perform assignment sv\u2009=\u2009t. Your task is following. Before starting performing queries and after each query you have to calculate expected value written on the lowest common ancestor of two equiprobably selected vertices i and j. Here lowest common ancestor of i and j is the deepest vertex that lies on the both of the path from the root to vertex i and the path from the root to vertex j. Please note that the vertices i and j can be the same (in this case their lowest common ancestor coincides with them).", "input_spec": "The first line of the input contains integer n (2\u2009\u2264\u2009n\u2009\u2264\u20095\u00b7104) \u2014 the number of the tree vertexes. The second line contains n\u2009-\u20091 integer p2,\u2009p3,\u2009...,\u2009pn (1\u2009\u2264\u2009pi\u2009\u2264\u2009n) \u2014 the description of the tree edges. It is guaranteed that those numbers form a tree. The third line contains n integers \u2014 s1,\u2009s2,\u2009... sn (0\u2009\u2264\u2009si\u2009\u2264\u2009106) \u2014 the values written on each vertex of the tree. The next line contains integer q (1\u2009\u2264\u2009q\u2009\u2264\u20095\u00b7104) \u2014 the number of queries. Each of the following q lines contains the description of the query in the format described in the statement. It is guaranteed that query arguments u and v lie between 1 and n. It is guaranteed that argument t in the queries of type V meets limits 0\u2009\u2264\u2009t\u2009\u2264\u2009106.", "output_spec": "Print q\u2009+\u20091 number \u2014 the corresponding expected values. Your answer will be considered correct if its absolute or relative error doesn't exceed 10\u2009-\u20099.", "sample_inputs": ["5\n1 2 2 1\n1 2 3 4 5\n5\nP 3 4\nP 4 5\nV 2 3\nP 5 2\nP 1 4"], "sample_outputs": ["1.640000000\n1.800000000\n2.280000000\n2.320000000\n2.800000000\n1.840000000"], "notes": "NoteNote that in the query P v u if u lies in subtree of v you must perform assignment pu\u2009=\u2009v. An example of such case is the last query in the sample."}, "src_uid": "013df41c0042f752a995bdcf16b28c7e"} {"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": "Vasya plays the Power Defence. He must pass the last level of the game. In order to do this he must kill the Main Villain, who moves in a straight line at speed 1 meter per second from the point (\u2009-\u2009\u221e,\u20090) to the point (\u2009+\u2009\u221e,\u20090) of the game world. In the points (x,\u20091) and (x,\u2009\u2009-\u20091), where x is an integer number, Vasya can build towers of three types: fire-tower, electric-tower or freezing-tower. However, it is not allowed to build two towers at the same point. Towers of each type have a certain action radius and the value of damage per second (except freezing-tower). If at some point the Main Villain is in the range of action of k freezing towers then his speed is decreased by k\u2009+\u20091 times.The allowed number of towers of each type is known. It is necessary to determine the maximum possible damage we can inflict on the Main Villain.All distances in the problem are given in meters. The size of the Main Villain and the towers are so small, that they can be considered as points on the plane. The Main Villain is in the action radius of a tower if the distance between him and tower is less than or equal to the action radius of the tower.", "input_spec": "The first line contains three integer numbers nf,\u2009ne and ns \u2014 the maximum number of fire-towers, electric-towers and freezing-towers that can be built (0\u2009\u2264\u2009nf,\u2009ne,\u2009ns\u2009\u2264\u200920,\u20091\u2009\u2264\u2009nf\u2009+\u2009ne\u2009+\u2009ns\u2009\u2264\u200920). The numbers are separated with single spaces. The second line contains three integer numbers rf,\u2009re and rs (1\u2009\u2264\u2009rf,\u2009re,\u2009rs\u2009\u2264\u20091000) \u2014 the action radii of fire-towers, electric-towers and freezing-towers. The numbers are separated with single spaces. The third line contains two integer numbers df and de (1\u2009\u2264\u2009df,\u2009de\u2009\u2264\u20091000) \u2014 the damage a fire-tower and an electronic-tower can inflict on the Main Villain per second (in the case when the Main Villain is in the action radius of the tower). The numbers are separated with single space.", "output_spec": "Print the only real number \u2014 the maximum possible damage to the Main Villain with absolute or relative error not more than 10\u2009-\u20096.", "sample_inputs": ["1 0 0\n10 10 10\n100 100", "1 0 1\n10 10 10\n100 100"], "sample_outputs": ["1989.97487421", "3979.94974843"], "notes": "NoteIn the first sample we've got one fire-tower that always inflicts the same damage, independently of its position. In the second sample we've got another freezing-tower of the same action radius. If we build the two towers opposite each other, then the Main Villain's speed will be two times lower, whenever he enters the fire-tower's action radius. That means that the enemy will be inflicted with twice more damage."}, "src_uid": "de5a42225714552cc5422d8a45734d58"} {"nl": {"description": "Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral.Vasya believes that if the average temperatures over the last n days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (n\u2009+\u20091)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (n\u2009+\u20091)-th day will be equal to the temperature of the n-th day.Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (n\u2009+\u20091)-th day.", "input_spec": "The first line contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of days for which the average air temperature is known. The second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (\u2009-\u20091000\u2009\u2264\u2009ti\u2009\u2264\u20091000)\u00a0\u2014 where ti is the average temperature in the i-th day.", "output_spec": "Print the average air temperature in the (n\u2009+\u20091)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.", "sample_inputs": ["5\n10 5 0 -5 -10", "4\n1 1 1 1", "3\n5 1 -5", "2\n900 1000"], "sample_outputs": ["-15", "1", "-5", "1100"], "notes": "NoteIn the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is \u2009-\u200910\u2009-\u20095\u2009=\u2009\u2009-\u200915.In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to \u2009-\u20095.In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000\u2009+\u2009100\u2009=\u20091100."}, "src_uid": "d04fa4322a1b300bdf4a56f09681b17f"} {"nl": {"description": "Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L'\u00a0\u2014 instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.", "input_spec": "The first line of the input contains a single positive integer, n (1\u2009\u2264\u2009n\u2009\u2264\u2009200)\u00a0\u2014 the number of commands. The next line contains n characters, each either 'U', 'R', 'D', or 'L'\u00a0\u2014 Calvin's source code.", "output_spec": "Print a single integer\u00a0\u2014 the number of contiguous substrings that Calvin can execute and return to his starting square.", "sample_inputs": ["6\nURLLDR", "4\nDLUU", "7\nRLRLRLR"], "sample_outputs": ["2", "0", "12"], "notes": "NoteIn the first case, the entire source code works, as well as the \"RL\" substring in the second and third characters.Note that, in the third case, the substring \"LR\" appears three times, and is therefore counted three times to the total result."}, "src_uid": "7bd5521531950e2de9a7b0904353184d"} {"nl": {"description": "SmallR likes a game called \"Deleting Substrings\". In the game you are given a sequence of integers w, you can modify the sequence and get points. The only type of modification you can perform is (unexpected, right?) deleting substrings. More formally, you can choose several contiguous elements of w and delete them from the sequence. Let's denote the sequence of chosen elements as wl,\u2009wl\u2009+\u20091,\u2009...,\u2009wr. They must meet the conditions: the equality |wi\u2009-\u2009wi\u2009+\u20091|\u2009=\u20091 must hold for all i (l\u2009\u2264\u2009i\u2009<\u2009r); the inequality 2\u00b7wi\u2009-\u2009wi\u2009+\u20091\u2009-\u2009wi\u2009-\u20091\u2009\u2265\u20090 must hold for all i (l\u2009<\u2009i\u2009<\u2009r). After deleting the chosen substring of w, you gain vr\u2009-\u2009l\u2009+\u20091 points. You can perform the described operation again and again while proper substrings exist. Also you can end the game at any time. Your task is to calculate the maximum total score you can get in the game.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009400) \u2014 the initial length of w. The second line contains n integers v1,\u2009v2,\u2009...,\u2009vn (0\u2009\u2264\u2009|vi|\u2009\u2264\u20092000) \u2014 the costs of operations. The next line contains n integers w1,\u2009w2,\u2009...,\u2009wn (1\u2009\u2264\u2009wi\u2009\u2264\u2009109) \u2014 the initial w.", "output_spec": "Print a single integer \u2014 the maximum total score you can get.", "sample_inputs": ["3\n0 0 3\n1 2 1", "6\n1 4 5 6 7 1000\n2 1 1 2 2 3"], "sample_outputs": ["3", "12"], "notes": null}, "src_uid": "32fa5dbac37abe197a267a0fc7fe4006"} {"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": "Vasya and Petya wrote down all integers from 1 to n to play the \"powers\" game (n can be quite large; however, Vasya and Petya are not confused by this fact).Players choose numbers in turn (Vasya chooses first). If some number x is chosen at the current turn, it is forbidden to choose x or all of its other positive integer powers (that is, x2, x3, ...) at the next turns. For instance, if the number 9 is chosen at the first turn, one cannot choose 9 or 81 later, while it is still allowed to choose 3 or 27. The one who cannot make a move loses.Who wins if both Vasya and Petya play optimally?", "input_spec": "Input contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Print the name of the winner \u2014 \"Vasya\" or \"Petya\" (without quotes).", "sample_inputs": ["1", "2", "8"], "sample_outputs": ["Vasya", "Petya", "Petya"], "notes": "NoteIn the first sample Vasya will choose 1 and win immediately.In the second sample no matter which number Vasya chooses during his first turn, Petya can choose the remaining number and win."}, "src_uid": "0e22093668319217b7946e62afe32195"} {"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": "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": "The only difference between easy and hard versions is the length of the string.You are given a string $$$s$$$ and a string $$$t$$$, both consisting only of lowercase Latin letters. It is guaranteed that $$$t$$$ can be obtained from $$$s$$$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $$$s$$$ without changing order of remaining characters (in other words, it is guaranteed that $$$t$$$ is a subsequence of $$$s$$$).For example, the strings \"test\", \"tst\", \"tt\", \"et\" and \"\" are subsequences of the string \"test\". But the strings \"tset\", \"se\", \"contest\" are not subsequences of the string \"test\".You want to remove some substring (contiguous subsequence) from $$$s$$$ of maximum possible length such that after removing this substring $$$t$$$ will remain a subsequence of $$$s$$$.If you want to remove the substring $$$s[l;r]$$$ then the string $$$s$$$ will be transformed to $$$s_1 s_2 \\dots s_{l-1} s_{r+1} s_{r+2} \\dots s_{|s|-1} s_{|s|}$$$ (where $$$|s|$$$ is the length of $$$s$$$).Your task is to find the maximum possible length of the substring you can remove so that $$$t$$$ is still a subsequence of $$$s$$$.", "input_spec": "The first line of the input contains one string $$$s$$$ consisting of at least $$$1$$$ and at most $$$200$$$ lowercase Latin letters. The second line of the input contains one string $$$t$$$ consisting of at least $$$1$$$ and at most $$$200$$$ lowercase Latin letters. It is guaranteed that $$$t$$$ is a subsequence of $$$s$$$.", "output_spec": "Print one integer \u2014 the maximum possible length of the substring you can remove so that $$$t$$$ is still a subsequence of $$$s$$$.", "sample_inputs": ["bbaba\nbb", "baaba\nab", "abcde\nabcde", "asdfasdf\nfasd"], "sample_outputs": ["3", "2", "0", "3"], "notes": null}, "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"} {"nl": {"description": "There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines.You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other.", "input_spec": "The first line contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 the number of shovels in Polycarp's shop.", "output_spec": "Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n\u2009\u2264\u2009109 the answer doesn't exceed 2\u00b7109.", "sample_inputs": ["7", "14", "50"], "sample_outputs": ["3", "9", "1"], "notes": "NoteIn the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: 2 and 7; 3 and 6; 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: 1 and 8; 2 and 7; 3 and 6; 4 and 5; 5 and 14; 6 and 13; 7 and 12; 8 and 11; 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n\u2009=\u200950."}, "src_uid": "c20744c44269ae0779c5f549afd2e3f2"} {"nl": {"description": "You have a rectangular n\u2009\u00d7\u2009m-cell board. Some cells are already painted some of k colors. You need to paint each uncolored cell one of the k colors so that any path from the upper left square to the lower right one doesn't contain any two cells of the same color. The path can go only along side-adjacent cells and can only go down or right.Print the number of possible paintings modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line contains three integers n,\u2009m,\u2009k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091000,\u20091\u2009\u2264\u2009k\u2009\u2264\u200910). The next n lines contain m integers each \u2014 the board. The first of them contains m uppermost cells of the board from the left to the right and the second one contains m cells from the second uppermost row and so on. If a number in a line equals 0, then the corresponding cell isn't painted. Otherwise, this number represents the initial color of the board cell \u2014 an integer from 1 to k. Consider all colors numbered from 1 to k in some manner.", "output_spec": "Print the number of possible paintings modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["2 2 4\n0 0\n0 0", "2 2 4\n1 2\n2 1", "5 6 10\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0", "2 6 10\n1 2 3 4 5 6\n0 0 0 0 0 0"], "sample_outputs": ["48", "0", "3628800", "4096"], "notes": null}, "src_uid": "5bb21f49d976cfa16a239593a95c53b5"} {"nl": {"description": "Once, during a lesson, Sasha got bored and decided to talk with his friends. Suddenly, he saw Kefa. Since we can talk endlessly about Kefa, we won't even start doing that. The conversation turned to graphs. Kefa promised Sasha to tell him about one interesting fact from graph theory if Sasha helps Kefa to count the number of beautiful trees. In this task, a tree is a weighted connected graph, consisting of $$$n$$$ vertices and $$$n-1$$$ edges, and weights of edges are integers from $$$1$$$ to $$$m$$$. Kefa determines the beauty of a tree as follows: he finds in the tree his two favorite vertices\u00a0\u2014 vertices with numbers $$$a$$$ and $$$b$$$, and counts the distance between them. The distance between two vertices $$$x$$$ and $$$y$$$ is the sum of weights of edges on the simple path from $$$x$$$ to $$$y$$$. If the distance between two vertices $$$a$$$ and $$$b$$$ is equal to $$$m$$$, then the tree is beautiful.Sasha likes graph theory, and even more, Sasha likes interesting facts, that's why he agreed to help Kefa. Luckily, Sasha is familiar with you the best programmer in Byteland. Help Sasha to count the number of beautiful trees for Kefa. Two trees are considered to be distinct if there is an edge that occurs in one of them and doesn't occur in the other one. Edge's weight matters.Kefa warned Sasha, that there can be too many beautiful trees, so it will be enough to count the number modulo $$$10^9 + 7$$$.", "input_spec": "The first line contains four integers $$$n$$$, $$$m$$$, $$$a$$$, $$$b$$$ ($$$2 \\le n \\le 10^6$$$, $$$1 \\le m \\le 10^6$$$, $$$1 \\le a, b \\le n$$$, $$$a \\neq b$$$)\u00a0\u2014 the number of vertices in the tree, the maximum weight of an edge and two Kefa's favorite vertices.", "output_spec": "Print one integer\u00a0\u2014 the number of beautiful trees modulo $$$10^9+7$$$.", "sample_inputs": ["3 2 1 3", "3 1 1 2", "5 15 1 5"], "sample_outputs": ["5", "2", "345444"], "notes": "NoteThere are $$$5$$$ beautiful trees in the first example:In the second example the following trees are beautiful:"}, "src_uid": "728fe302b8b18e33f15f6e702e332cde"} {"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": "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": "Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.After how many full years will Limak become strictly larger (strictly heavier) than Bob?", "input_spec": "The only line of the input contains two integers a and b (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u200910)\u00a0\u2014 the weight of Limak and the weight of Bob respectively.", "output_spec": "Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.", "sample_inputs": ["4 7", "4 9", "1 1"], "sample_outputs": ["2", "3", "1"], "notes": "NoteIn the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4\u00b73\u2009=\u200912 and 7\u00b72\u2009=\u200914 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then."}, "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"nl": {"description": "Let's introduce the designation , where x is a string, n is a positive integer and operation \"\u2009+\u2009\" is the string concatenation operation. For example, [abc,\u20092]\u2009=\u2009abcabc.We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, strings ab and a\u0441ba can be obtained from string xacbac, and strings bx and aaa cannot be obtained from it.Sereja has two strings, w\u2009=\u2009[a,\u2009b] and q\u2009=\u2009[c,\u2009d]. He wants to find such maximum integer p (p\u2009>\u20090), that [q,\u2009p] can be obtained from string w.", "input_spec": "The first line contains two integers b, d (1\u2009\u2264\u2009b,\u2009d\u2009\u2264\u2009107). The second line contains string a. The third line contains string c. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed 100.", "output_spec": "In a single line print an integer \u2014 the largest number p. If the required value of p doesn't exist, print 0.", "sample_inputs": ["10 3\nabab\nbab"], "sample_outputs": ["3"], "notes": null}, "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa"} {"nl": {"description": "Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: the Euclidean distance between A and B is one unit and neither A nor B is blocked; or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B. Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick?", "input_spec": "The first line contains an integer n (0\u2009\u2264\u2009n\u2009\u2264\u20094\u00b7107).", "output_spec": "Print a single integer \u2014 the minimum number of points that should be blocked.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["4", "8", "16"], "notes": null}, "src_uid": "d87ce09acb8401e910ca6ef3529566f4"} {"nl": {"description": "There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission. Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.", "input_spec": "The first line of the input contains n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) and m (1\u2009\u2264\u2009m\u2009\u2264\u2009n). The second line contains n integers in the range {1,\u20092,\u2009...,\u2009m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1,\u2009k2,\u2009...,\u2009km (with ) \u2013 the desired counts of lightsabers of each color from 1 to m.", "output_spec": "Output YES if an interval with prescribed color counts exists, or output NO if there is none.", "sample_inputs": ["5 2\n1 1 2 2 1\n1 2"], "sample_outputs": ["YES"], "notes": null}, "src_uid": "59f40d9f35e5fe402112214b42b682b5"} {"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": "InputThe input contains a single integer $$$a$$$ ($$$0 \\le a \\le 63$$$).OutputOutput a single number.ExamplesInput\n2\nOutput\n2\nInput\n5\nOutput\n24\nInput\n35\nOutput\n50\n", "input_spec": "The input contains a single integer $$$a$$$ ($$$0 \\le a \\le 63$$$).", "output_spec": "Output a single number.", "sample_inputs": ["2", "5", "35"], "sample_outputs": ["2", "24", "50"], "notes": null}, "src_uid": "db5e54f466e1f3d69a51ea0b346e667c"} {"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": "Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.", "input_spec": "The first line contains two integers n and k (2\u2009\u2264\u2009n\u2009\u2264\u2009100000, 1\u2009\u2264\u2009k\u2009\u2264\u200920).", "output_spec": "If it's impossible to find the representation of n as a product of k numbers, print -1. Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.", "sample_inputs": ["100000 2", "100000 20", "1024 5"], "sample_outputs": ["2 50000", "-1", "2 64 2 2 2"], "notes": null}, "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"} {"nl": {"description": "You are given two integers $$$l$$$ and $$$r$$$.Let's call an integer $$$x$$$ modest, if $$$l \\le x \\le r$$$.Find a string of length $$$n$$$, consisting of digits, which has the largest possible number of substrings, which make a modest integer. Substring having leading zeros are not counted. If there are many answers, find lexicographically smallest one.If some number occurs multiple times as a substring, then in the counting of the number of modest substrings it is counted multiple times as well.", "input_spec": "The first line contains one integer $$$l$$$ ($$$1 \\le l \\le 10^{800}$$$). The second line contains one integer $$$r$$$ ($$$l \\le r \\le 10^{800}$$$). The third line contains one integer $$$n$$$ ($$$1 \\le n \\le 2\\,000$$$).", "output_spec": "In the first line, print the maximum possible number of modest substrings. In the second line, print a string of length $$$n$$$ having exactly that number of modest substrings. If there are multiple such strings, print the lexicographically smallest of them.", "sample_inputs": ["1\n10\n3", "1\n11\n3", "12345\n12346\n6"], "sample_outputs": ["3\n101", "5\n111", "1\n012345"], "notes": "NoteIn the first example, string \u00ab101\u00bb has modest substrings \u00ab1\u00bb, \u00ab10\u00bb, \u00ab1\u00bb.In the second example, string \u00ab111\u00bb has modest substrings \u00ab1\u00bb ($$$3$$$ times) and \u00ab11\u00bb ($$$2$$$ times)."}, "src_uid": "2e79c95bf4c2b7de8a4741b24a880829"} {"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": "Once Petya and Vasya invented a new game and called it \"Smart Boy\". They located a certain set of words \u2014 the dictionary \u2014 for the game. It is admissible for the dictionary to contain similar words. The rules of the game are as follows: first the first player chooses any letter (a word as long as 1) from any word from the dictionary and writes it down on a piece of paper. The second player adds some other letter to this one's initial or final position, thus making a word as long as 2, then it's the first player's turn again, he adds a letter in the beginning or in the end thus making a word as long as 3 and so on. But the player mustn't break one condition: the newly created word must be a substring of a word from a dictionary. The player who can't add a letter to the current word without breaking the condition loses.Also if by the end of a turn a certain string s is written on paper, then the player, whose turn it just has been, gets a number of points according to the formula:where is a sequence number of symbol c in Latin alphabet, numbered starting from 1. For example, , and . is the number of words from the dictionary where the line s occurs as a substring at least once. Your task is to learn who will win the game and what the final score will be. Every player plays optimally and most of all tries to win, then \u2014 to maximize the number of his points, then \u2014 to minimize the number of the points of the opponent.", "input_spec": "The first input line contains an integer n which is the number of words in the located dictionary (1\u2009\u2264\u2009n\u2009\u2264\u200930). The n lines contain the words from the dictionary \u2014 one word is written on one line. Those lines are nonempty, consisting of Latin lower-case characters no longer than 30 characters. Equal words can be in the list of words.", "output_spec": "On the first output line print a line \"First\" or \"Second\" which means who will win the game. On the second line output the number of points of the first player and the number of points of the second player after the game ends. Separate the numbers by a single space.", "sample_inputs": ["2\naba\nabac", "3\nartem\nnik\nmax"], "sample_outputs": ["Second\n29 35", "First\n2403 1882"], "notes": null}, "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9"} {"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": "Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x,\u2009y) to (x\u2009-\u20091,\u2009y) or (x,\u2009y\u2009-\u20091). Vasiliy can move his pawn from (x,\u2009y) to one of cells: (x\u2009-\u20091,\u2009y),\u2009(x\u2009-\u20091,\u2009y\u2009-\u20091) and (x,\u2009y\u2009-\u20091). Both players are also allowed to skip move. There are some additional restrictions \u2014 a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0,\u20090). You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.", "input_spec": "The first line contains four integers: xp,\u2009yp,\u2009xv,\u2009yv (0\u2009\u2264\u2009xp,\u2009yp,\u2009xv,\u2009yv\u2009\u2264\u2009105) \u2014 Polycarp's and Vasiliy's starting coordinates. It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0,\u20090).", "output_spec": "Output the name of the winner: \"Polycarp\" or \"Vasiliy\".", "sample_inputs": ["2 1 2 2", "4 7 7 4"], "sample_outputs": ["Polycarp", "Vasiliy"], "notes": "NoteIn the first sample test Polycarp starts in (2,\u20091) and will move to (1,\u20091) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1,\u20090) and finally to (0,\u20090) in the third turn."}, "src_uid": "2637d57f7809ff8f922549c617709074"} {"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": "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": "Furik loves painting stars. A star is a shape that results if we take a regular pentagon and paint all diagonals in it. Recently he decided to teach Rubik to paint stars. After many years of training Rubik could paint stars easily. But now Furik decided to test Rubik and complicated the task. Rubik must paint n stars, observing the following rules: all stars must be painted in a single move (i.e. it is forbidden to take the pen away from the paper); it is forbidden to paint the same segment of non-zero length more than once; the stars can intersect only in their vertexes; the length of a side of the regular pentagon, in which Rubik paints each star, must equal 10. Help Rubik to cope with this hard task.", "input_spec": "A single line contains an integer (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of stars to paint.", "output_spec": "On the first line print an integer m (1\u2009\u2264\u2009m\u2009\u2264\u20095\u00b7n). On the next m lines print coordinates of m distinct points with accuracy of at least 9 and at most 100 digits after decimal point. All coordinates should not exceed 5000 in their absolute value. On each of the next n lines print 5 integers \u2014 the indexes of the points that form the given star in the clockwise or counterclockwise order. On the next line print 5\u00b7n\u2009+\u20091 integers \u2014 the numbers of points in the order, in which Rubik paints stars. That is, if number with index i is ai, and number with index i\u2009+\u20091 is ai\u2009+\u20091, then points with indexes ai and ai\u2009+\u20091 will have a segment painted between them. You can consider all m printed points indexed from 1 to m in the order, in which they occur in the output. Separate the numbers on the lines with whitespaces. Note that the answer has an imprecise validation. Try to obtain as accurate a solution as possible. The validator performs all calculations considering that the absolute error of a participant's answer is not more than 10\u2009-\u20098.", "sample_inputs": ["1"], "sample_outputs": ["5\n3.830127018922193 3.366025403784439\n-3.601321235851749 10.057331467373021\n0.466045194906253 19.192786043799030\n10.411264148588986 18.147501411122495\n12.490381056766580 8.366025403784439\n1 2 3 4 5\n1 3 5 2 4 1"], "notes": "NoteThe initial position of points in the sample is: The order in which Rubik can paint segments is: "}, "src_uid": "db263b866e93e3a97731e11102923902"} {"nl": {"description": "At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector \u0410: Turn the vector by 90 degrees clockwise. Add to the vector a certain vector C.Operations could be performed in any order any number of times.Can Gerald cope with the task?", "input_spec": "The first line contains integers x1 \u0438 y1 \u2014 the coordinates of the vector A (\u2009-\u2009108\u2009\u2264\u2009x1,\u2009y1\u2009\u2264\u2009108). The second and the third line contain in the similar manner vectors B and C (their coordinates are integers; their absolute value does not exceed 108).", "output_spec": "Print \"YES\" (without the quotes) if it is possible to get vector B using the given operations. Otherwise print \"NO\" (without the quotes).", "sample_inputs": ["0 0\n1 1\n0 1", "0 0\n1 1\n1 1", "0 0\n1 1\n2 2"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "cc8a8af1ba2b19bf081e379139542883"} {"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": "You are given a tree with each vertex coloured white, black or grey. You can remove elements from the tree by selecting a subset of vertices in a single connected component and removing them and their adjacent edges from the graph. The only restriction is that you are not allowed to select a subset containing a white and a black vertex at once.What is the minimum number of removals necessary to remove all vertices from the tree?", "input_spec": "Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 100\\,000$$$), denoting the number of test cases, followed by a description of the test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 200\\,000$$$): the number of vertices in the tree. The second line of each test case contains $$$n$$$ integers $$$a_v$$$ ($$$0 \\le a_v \\le 2$$$): colours of vertices. Gray vertices have $$$a_v=0$$$, white have $$$a_v=1$$$, black have $$$a_v=2$$$. Each of the next $$$n-1$$$ lines contains two integers $$$u, v$$$ ($$$1 \\le u, v \\le n$$$): tree edges. The sum of all $$$n$$$ throughout the test is guaranteed to not exceed $$$200\\,000$$$.", "output_spec": "For each test case, print one integer: the minimum number of operations to solve the problem.", "sample_inputs": ["4\n2\n1 1\n1 2\n4\n1 2 1 2\n1 2\n2 3\n3 4\n5\n1 1 0 1 2\n1 2\n2 3\n3 4\n3 5\n8\n1 2 1 2 2 2 1 2\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n5 8"], "sample_outputs": ["1\n3\n2\n3"], "notes": "NoteIn the first test case, both vertices are white, so you can remove them at the same time.In the second test case, three operations are enough. First, we need to remove both black vertices (2 and 4), then separately remove vertices 1 and 3. We can't remove them together because they end up in different connectivity components after vertex 2 is removed.In the third test case, we can remove vertices 1, 2, 3, 4 at the same time, because three of them are white and one is grey. After that, we can remove vertex 5.In the fourth test case, three operations are enough. One of the ways to solve the problem is to remove all black vertices at once, then remove white vertex 7, and finally, remove connected white vertices 1 and 3."}, "src_uid": "7c5ae79eeff98960fb52416541dd6528"} {"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": "As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.", "input_spec": "The first line contains two lowercase English letters\u00a0\u2014 the password on the phone. The second line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of words Kashtanka knows. The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.", "output_spec": "Print \"YES\" if Kashtanka can bark several words in a line forming a string containing the password, and \"NO\" otherwise. You can print each letter in arbitrary case (upper or lower).", "sample_inputs": ["ya\n4\nah\noy\nto\nha", "hp\n2\nht\ntp", "ah\n1\nha"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example the password is \"ya\", and Kashtanka can bark \"oy\" and then \"ah\", and then \"ha\" to form the string \"oyahha\" which contains the password. So, the answer is \"YES\".In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark \"ht\" and then \"tp\" producing \"http\", but it doesn't contain the password \"hp\" as a substring.In the third example the string \"hahahaha\" contains \"ah\" as a substring."}, "src_uid": "cad8283914da16bc41680857bd20fe9f"} {"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": "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": "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": "The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy \"GAGA: Go And Go Again\". The gameplay is as follows. There are two armies on the playing field each of which consists of n men (n is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore. The game \"GAGA\" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends. You are asked to calculate the maximum total number of soldiers that may be killed during the game. ", "input_spec": "The input data consist of a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009108, n is even). Please note that before the game starts there are 2n soldiers on the fields. ", "output_spec": "Print a single number \u2014 a maximum total number of soldiers that could be killed in the course of the game in three turns.", "sample_inputs": ["2", "4"], "sample_outputs": ["3", "6"], "notes": "NoteThe first sample test:1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.2) Arcady's soldier 2 shoots at Valera's soldier 1.3) Valera's soldier 1 shoots at Arcady's soldier 2.There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2."}, "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"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": "The map of Bertown can be represented as a set of $$$n$$$ intersections, numbered from $$$1$$$ to $$$n$$$ and connected by $$$m$$$ one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection $$$v$$$ to another intersection $$$u$$$ is the path that starts in $$$v$$$, ends in $$$u$$$ and has the minimum length among all such paths.Polycarp lives near the intersection $$$s$$$ and works in a building near the intersection $$$t$$$. Every day he gets from $$$s$$$ to $$$t$$$ by car. Today he has chosen the following path to his workplace: $$$p_1$$$, $$$p_2$$$, ..., $$$p_k$$$, where $$$p_1 = s$$$, $$$p_k = t$$$, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from $$$s$$$ to $$$t$$$.Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection $$$s$$$, the system chooses some shortest path from $$$s$$$ to $$$t$$$ and shows it to Polycarp. Let's denote the next intersection in the chosen path as $$$v$$$. If Polycarp chooses to drive along the road from $$$s$$$ to $$$v$$$, then the navigator shows him the same shortest path (obviously, starting from $$$v$$$ as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection $$$w$$$ instead, the navigator rebuilds the path: as soon as Polycarp arrives at $$$w$$$, the navigation system chooses some shortest path from $$$w$$$ to $$$t$$$ and shows it to Polycarp. The same process continues until Polycarp arrives at $$$t$$$: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path $$$[1, 2, 3, 4]$$$ ($$$s = 1$$$, $$$t = 4$$$): Check the picture by the link http://tk.codeforces.com/a.png When Polycarp starts at $$$1$$$, the system chooses some shortest path from $$$1$$$ to $$$4$$$. There is only one such path, it is $$$[1, 5, 4]$$$; Polycarp chooses to drive to $$$2$$$, which is not along the path chosen by the system. When Polycarp arrives at $$$2$$$, the navigator rebuilds the path by choosing some shortest path from $$$2$$$ to $$$4$$$, for example, $$$[2, 6, 4]$$$ (note that it could choose $$$[2, 3, 4]$$$); Polycarp chooses to drive to $$$3$$$, which is not along the path chosen by the system. When Polycarp arrives at $$$3$$$, the navigator rebuilds the path by choosing the only shortest path from $$$3$$$ to $$$4$$$, which is $$$[3, 4]$$$; Polycarp arrives at $$$4$$$ along the road chosen by the navigator, so the system does not have to rebuild anything. Overall, we get $$$2$$$ rebuilds in this scenario. Note that if the system chose $$$[2, 3, 4]$$$ instead of $$$[2, 6, 4]$$$ during the second step, there would be only $$$1$$$ rebuild (since Polycarp goes along the path, so the system maintains the path $$$[3, 4]$$$ during the third step).The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le m \\le 2 \\cdot 10^5$$$) \u2014 the number of intersections and one-way roads in Bertown, respectively. Then $$$m$$$ lines follow, each describing a road. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \\le u, v \\le n$$$, $$$u \\ne v$$$) denoting a road from intersection $$$u$$$ to intersection $$$v$$$. All roads in Bertown are pairwise distinct, which means that each ordered pair $$$(u, v)$$$ appears at most once in these $$$m$$$ lines (but if there is a road $$$(u, v)$$$, the road $$$(v, u)$$$ can also appear). The following line contains one integer $$$k$$$ ($$$2 \\le k \\le n$$$) \u2014 the number of intersections in Polycarp's path from home to his workplace. The last line contains $$$k$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_k$$$ ($$$1 \\le p_i \\le n$$$, all these integers are pairwise distinct) \u2014 the intersections along Polycarp's path in the order he arrived at them. $$$p_1$$$ is the intersection where Polycarp lives ($$$s = p_1$$$), and $$$p_k$$$ is the intersection where Polycarp's workplace is situated ($$$t = p_k$$$). It is guaranteed that for every $$$i \\in [1, k - 1]$$$ the road from $$$p_i$$$ to $$$p_{i + 1}$$$ exists, so the path goes along the roads of Bertown. ", "output_spec": "Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.", "sample_inputs": ["6 9\n1 5\n5 4\n1 2\n2 3\n3 4\n4 1\n2 6\n6 4\n4 2\n4\n1 2 3 4", "7 7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n7\n1 2 3 4 5 6 7", "8 13\n8 7\n8 6\n7 5\n7 4\n6 5\n6 4\n5 3\n5 2\n4 3\n4 2\n3 1\n2 1\n1 8\n5\n8 7 5 2 1"], "sample_outputs": ["1 2", "0 0", "0 3"], "notes": null}, "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a"} {"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": "Neko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire bag of catnip into the toys...It took Neko an entire day to turn back to normal. Neko reported to Aki that he saw a lot of weird things, including a trie of all correct bracket sequences of length $$$2n$$$.The definition of correct bracket sequence is as follows: The empty sequence is a correct bracket sequence, If $$$s$$$ is a correct bracket sequence, then $$$(\\,s\\,)$$$ is a correct bracket sequence, If $$$s$$$ and $$$t$$$ are a correct bracket sequence, then $$$st$$$ is also a correct bracket sequence. For example, the strings \"(())\", \"()()\" form a correct bracket sequence, while \")(\" and \"((\" not.Aki then came up with an interesting problem: What is the size of the maximum matching (the largest set of edges such that there are no two edges with a common vertex) in this trie? Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.", "input_spec": "The only line contains a single integer $$$n$$$ ($$$1 \\le n \\le 1000$$$).", "output_spec": "Print exactly one integer\u00a0\u2014 the size of the maximum matching in the trie. Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["1", "3", "9"], "notes": "NoteThe pictures below illustrate tries in the first two examples (for clarity, the round brackets are replaced with angle brackets). The maximum matching is highlighted with blue. \u00a0 "}, "src_uid": "8218255989e5eab73ac7107072c3b2af"} {"nl": {"description": "You are given a tree (a connected non-oriented graph without cycles) with vertices numbered from 1 to n, and the length of the i-th edge is wi. In the vertex s there is a policeman, in the vertices x1,\u2009x2,\u2009...,\u2009xm (xj\u2009\u2260\u2009s) m criminals are located.The policeman can walk along the edges with speed 1, the criminals can move with arbitrary large speed. If a criminal at some moment is at the same point as the policeman, he instantly gets caught by the policeman. Determine the time needed for the policeman to catch all criminals, assuming everybody behaves optimally (i.e. the criminals maximize that time, the policeman minimizes that time). Everybody knows positions of everybody else at any moment of time.", "input_spec": "The first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950)\u00a0\u2014 the number of vertices in the tree. The next n\u2009-\u20091 lines contain three integers each: ui, vi, wi (1\u2009\u2264\u2009ui,\u2009vi\u2009\u2264\u2009n, 1\u2009\u2264\u2009wi\u2009\u2264\u200950) denoting edges and their lengths. It is guaranteed that the given graph is a tree. The next line contains single integer s (1\u2009\u2264\u2009s\u2009\u2264\u2009n)\u00a0\u2014 the number of vertex where the policeman starts. The next line contains single integer m (1\u2009\u2264\u2009m\u2009\u2264\u200950)\u00a0\u2014 the number of criminals. The next line contains m integers x1,\u2009x2,\u2009...,\u2009xm (1\u2009\u2264\u2009xj\u2009\u2264\u2009n, xj\u2009\u2260\u2009s)\u00a0\u2014 the number of vertices where the criminals are located. xj are not necessarily distinct.", "output_spec": "If the policeman can't catch criminals, print single line \"Terrorists win\" (without quotes). Otherwise, print single integer\u00a0\u2014 the time needed to catch all criminals.", "sample_inputs": ["4\n1 2 2\n1 3 1\n1 4 1\n2\n4\n3 1 4 1", "6\n1 2 3\n2 3 5\n3 4 1\n3 5 4\n2 6 3\n2\n3\n1 3 5"], "sample_outputs": ["8", "21"], "notes": "NoteIn the first example one of the optimal scenarios is the following. The criminal number 2 moves to vertex 3, the criminal 4\u00a0\u2014 to vertex 4. The policeman goes to vertex 4 and catches two criminals. After that the criminal number 1 moves to the vertex 2. The policeman goes to vertex 3 and catches criminal 2, then goes to the vertex 2 and catches the remaining criminal."}, "src_uid": "34b926f903c2412fe76f912ccb8a00dd"} {"nl": {"description": "The stardate is 2015, and Death Stars are bigger than ever! This time, two rebel spies have yet again given Heidi two maps with the possible locations of the Death Stars.Heidi has now received two maps with possible locations of N Death Stars. She knows that each of the maps is possibly corrupted, and may contain some stars that are not Death Stars. Furthermore, each of the maps was created from a different point of view. Hence, stars that are shown in one of the maps are rotated and translated with respect to the other map. Now Heidi wants to find out which of the stars shown in both maps are actually Death Stars, and the correspondence between the Death Stars on the two maps. ", "input_spec": "The first line of the input contains an integer N (1000\u2009\u2264\u2009N\u2009\u2264\u200950000) \u2013 the number of Death Stars. The second line of the input contains an integer N1 (N\u2009\u2264\u2009N1\u2009\u2264\u20091.5\u00b7N) \u2013 the number of stars in the first map. The next N1 lines specify the coordinates of the stars in the first map. The i-th line contains two space-separated floating-point numbers xi and yi with two decimal digits of precision each, representing the coordinates of the i-th star in the first map. The next line of the input contains an integer N2 (N\u2009\u2264\u2009N2\u2009\u2264\u20091.5\u00b7N) \u2013 the number of stars in the second map. The next N2 lines contain locations of the stars in the second map, given in the same format as for the first map. ", "output_spec": "You should output exactly N lines, each containing a space-separated pair of integers i1 and i2. Each such line should indicate that the star numbered i1 in the first map corresponds to the star numbered i2 in the second map. Your answer will be considered correct if over 90% of the distinct pairs listed in your output are indeed correct.", "sample_inputs": [], "sample_outputs": [], "notes": "NoteThe tests are generated in the following way: The number of Death Stars N is pre-selected in some way. The numbers of stars on the first and on the second map, N1 and N2, are selected uniformly at random between 1.0\u2009\u00d7\u2009N and 1.5\u2009\u00d7\u2009N. N Death Stars are generated at random, with coordinates between \u2009-\u200910000 and 10000. Additional N1\u2009-\u2009N and N2\u2009-\u2009N stars for the first and for the second map respectively are generated in the same way. A translation vector (dx,\u2009dy) is generated, with dx and dy selected uniformly at random between \u2009-\u200910000 and 10000. Each point in the first map is translated by (dx,\u2009dy). A rotation angle \u03b8 is generated, with \u03b8 selected uniformly at random between 0 and 2\u03c0. Each point in the first map is rotated by an angle of \u03b8 around the origin. Translations and rotations for the second map are generated and applied in the same way. The order of points is randomly permuted for both maps. The test case is saved, with each point written with two decimal digits of precision. "}, "src_uid": "fc238a230bb556c9ffecf343989b988a"} {"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": "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": "Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109\u2009+\u20099).", "input_spec": "The single line contains three space-separated integers n, m and k (2\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009109;\u00a00\u2009\u2264\u2009m\u2009\u2264\u2009n).", "output_spec": "Print a single integer \u2014 the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109\u2009+\u20099).", "sample_inputs": ["5 3 2", "5 4 2"], "sample_outputs": ["3", "6"], "notes": "NoteSample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000\u00a0mod\u00a01000000009, even though 2000000020\u00a0mod\u00a01000000009 is a smaller number."}, "src_uid": "9cc1aecd70ed54400821c290e2c8018e"} {"nl": {"description": "Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains n positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single space.", "output_spec": "In a single line print the answer to the problem.", "sample_inputs": ["1\n1", "1\n2", "2\n3 5"], "sample_outputs": ["3", "2", "3"], "notes": "NoteIn the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.In the second sample Dima can show 2 or 4 fingers."}, "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"nl": {"description": "A bus moves along the coordinate line Ox from the point x\u2009=\u20090 to the point x\u2009=\u2009a. After starting from the point x\u2009=\u20090, it reaches the point x\u2009=\u2009a, immediately turns back and then moves to the point x\u2009=\u20090. After returning to the point x\u2009=\u20090 it immediately goes back to the point x\u2009=\u2009a and so on. Thus, the bus moves from x\u2009=\u20090 to x\u2009=\u2009a and back. Moving from the point x\u2009=\u20090 to x\u2009=\u2009a or from the point x\u2009=\u2009a to x\u2009=\u20090 is called a bus journey. In total, the bus must make k journeys.The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.There is a gas station in point x\u2009=\u2009f. This point is between points x\u2009=\u20090 and x\u2009=\u2009a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline.What is the minimum number of times the bus needs to refuel at the point x\u2009=\u2009f to make k journeys? The first journey starts in the point x\u2009=\u20090.", "input_spec": "The first line contains four integers a, b, f, k (0\u2009<\u2009f\u2009<\u2009a\u2009\u2264\u2009106, 1\u2009\u2264\u2009b\u2009\u2264\u2009109, 1\u2009\u2264\u2009k\u2009\u2264\u2009104) \u2014 the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.", "output_spec": "Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.", "sample_inputs": ["6 9 2 4", "6 10 2 4", "6 5 4 3"], "sample_outputs": ["4", "2", "-1"], "notes": "NoteIn the first example the bus needs to refuel during each journey.In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling."}, "src_uid": "283aff24320c6518e8518d4b045e1eca"} {"nl": {"description": "Lavrenty, a baker, is going to make several buns with stuffings and sell them.Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-th stuffing. It takes exactly bi grams of stuffing i and ci grams of dough to cook a bun with the i-th stuffing. Such bun can be sold for di tugriks.Also he can make buns without stuffings. Each of such buns requires c0 grams of dough and it can be sold for d0 tugriks. So Lavrenty can cook any number of buns with different stuffings or without it unless he runs out of dough and the stuffings. Lavrenty throws away all excess material left after baking.Find the maximum number of tugriks Lavrenty can earn.", "input_spec": "The first line contains 4 integers n, m, c0 and d0 (1\u2009\u2264\u2009n\u2009\u2264\u20091000, 1\u2009\u2264\u2009m\u2009\u2264\u200910, 1\u2009\u2264\u2009c0,\u2009d0\u2009\u2264\u2009100). Each of the following m lines contains 4 integers. The i-th line contains numbers ai, bi, ci and di (1\u2009\u2264\u2009ai,\u2009bi,\u2009ci,\u2009di\u2009\u2264\u2009100).", "output_spec": "Print the only number \u2014 the maximum number of tugriks Lavrenty can earn.", "sample_inputs": ["10 2 2 1\n7 3 2 100\n12 3 1 10", "100 1 25 50\n15 5 20 10"], "sample_outputs": ["241", "200"], "notes": "NoteTo get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing.In the second sample Lavrenty should cook 4 buns without stuffings."}, "src_uid": "4e166b8b44427b1227e0f811161d3a6f"} {"nl": {"description": "The Bubble Cup hypothesis stood unsolved for $$$130$$$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem:Given a number $$$m$$$, how many polynomials $$$P$$$ with coefficients in set $$${\\{0,1,2,3,4,5,6,7\\}}$$$ have: $$$P(2)=m$$$?Help Jerry Mao solve the long standing problem!", "input_spec": "The first line contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 5\\cdot 10^5)$$$ - number of test cases. On next line there are $$$t$$$ numbers, $$$m_i$$$ $$$(1 \\leq m_i \\leq 10^{18})$$$ - meaning that in case $$$i$$$ you should solve for number $$$m_i$$$.", "output_spec": "For each test case $$$i$$$, print the answer on separate lines: number of polynomials $$$P$$$ as described in statement such that $$$P(2)=m_i$$$, modulo $$$10^9 + 7$$$.", "sample_inputs": ["2\n2 4"], "sample_outputs": ["2\n4"], "notes": "NoteIn first case, for $$$m=2$$$, polynomials that satisfy the constraint are $$$x$$$ and $$$2$$$.In second case, for $$$m=4$$$, polynomials that satisfy the constraint are $$$x^2$$$, $$$x + 2$$$, $$$2x$$$ and $$$4$$$."}, "src_uid": "24f4bd10ae714f957920afd47ac0c558"} {"nl": {"description": "George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample). ", "input_spec": "The first line contains current time s as a string in the format \"hh:mm\". The second line contains time t in the format \"hh:mm\" \u2014 the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00\u2009\u2264\u2009hh\u2009\u2264\u200923, 00\u2009\u2264\u2009mm\u2009\u2264\u200959.", "output_spec": "In the single line print time p \u2014 the time George went to bed in the format similar to the format of the time in the input.", "sample_inputs": ["05:50\n05:44", "00:00\n01:00", "00:01\n00:00"], "sample_outputs": ["00:06", "23:00", "00:01"], "notes": "NoteIn the first sample George went to bed at \"00:06\". Note that you should print the time only in the format \"00:06\". That's why answers \"0:06\", \"00:6\" and others will be considered incorrect. In the second sample, George went to bed yesterday.In the third sample, George didn't do to bed at all."}, "src_uid": "595c4a628c261104c8eedad767e85775"} {"nl": {"description": "You are given a piece of paper in the shape of a simple polygon $$$S$$$. Your task is to turn it into a simple polygon $$$T$$$ that has the same area as $$$S$$$.You can use two tools: scissors and tape. Scissors can be used to cut any polygon into smaller polygonal pieces. Tape can be used to combine smaller pieces into larger polygons. You can use each tool multiple times, in any order. The polygons given in the input have integer coordinates, but you are allowed to produce shapes with non-integer coordinates in your output.A formal definition of the task follows.A shape $$$Q=(Q_0,\\dots,Q_{n-1})$$$ is a sequence of three or more points in the plane such that: The closed polyline $$$Q_0Q_1Q_2\\dots Q_{n-1}Q_0$$$ never touches or intersects itself, and therefore it forms the boundary of a simple polygon. The polyline goes around the boundary of the polygon in the counter-clockwise direction. The polygon whose boundary is the shape $$$Q$$$ will be denoted $$$P(Q)$$$.Two shapes are called equivalent if one can be translated and/or rotated to become identical with the other.Note that mirroring a shape is not allowed. Also note that the order of points matters: the shape $$$(Q_1,\\dots,Q_{n-1},Q_0)$$$ is not necessarily equivalent to the shape $$$(Q_0,\\dots,Q_{n-1})$$$.In the figure on the left: Shapes $$$U$$$ and $$$V$$$ are equivalent. Shape $$$W$$$ is not equivalent with them because the points of $$$W$$$ are given in a different order. Regardless of the order of points, the fourth shape is not equivalent with the previous ones either as flipping a shape is not allowed.In both input and output, a shape with $$$n$$$ points is represented as a single line that contains $$$2n+1$$$ space-separated numbers: the number $$$n$$$ followed by the coordinates of the points: $$$Q_{0,x}$$$, $$$Q_{0,y}$$$, $$$Q_{1,x}$$$, ...Shapes have identification numbers (IDs). The given shape $$$S$$$ has ID 0, the shapes you produce in your solutions are given IDs 1, 2, 3, ..., in the order in which they are produced.Shapes $$$B_1,\\dots,B_k$$$ form a subdivision of shape $$$A$$$ if: The union of all $$$P(B_i)$$$ is exactly $$$P(A)$$$. For each $$$i\\neq j$$$, the area of the intersection of $$$P(B_i)$$$ and $$$P(B_j)$$$ is zero. The scissors operation destroys one existing shape $$$A$$$ and produces one or more shapes $$$B_1,\\dots,B_k$$$ that form a subdivision of $$$A$$$.In the figure: Shape $$$A$$$ (square) subdivided into shapes $$$B_1$$$, $$$B_2$$$, $$$B_3$$$ (the three triangles). One valid way to describe one of the $$$B_i$$$ is \"3 3 1 6 1 5.1 4\".The tape operation destroys one or more existing shapes $$$A_1,\\dots,A_k$$$ and produces one new shape $$$B$$$. In order to perform this operation, you must first specify shapes $$$C_1,\\dots,C_k$$$ and only then the final shape $$$B$$$. These shapes must satisfy the following: For each $$$i$$$, the shape $$$C_i$$$ is equivalent to the shape $$$A_i$$$. The shapes $$$C_1,\\dots,C_k$$$ form a subdivision of the shape $$$B$$$. Informally, you choose the shape $$$B$$$ and show how to move each of the existing $$$A_i$$$ to its correct location $$$C_i$$$ within $$$B$$$. Note that only the shape $$$B$$$ gets a new ID, the shapes $$$C_i$$$ do not.", "input_spec": "The first line contains the source shape $$$S$$$. The second line contains the target shape $$$T$$$. Each shape has between 3 and 10 points, inclusive. Both shapes are given in the format specified above. All coordinates in the input are integers between $$$-10^6$$$ and $$$10^6$$$, inclusive. In each shape, no three points form an angle smaller than 3 degrees. (This includes non-consecutive points and implies that no three points are collinear.) The polygons $$$P(S)$$$ and $$$P(T)$$$ have the same area.", "output_spec": "Whenever you use the scissors operation, output a block of lines of the form: scissorsid(A) kB_1B_2...B_k where $$$id(A)$$$ is the ID of the shape you want to destroy, $$$k$$$ is the number of new shapes you want to produce, and $$$B_1,\\dots,B_k$$$ are those shapes. Whenever you use the tape operation, output a block of lines of the form: tapek id(A_1) ... id(A_k)C_1C_2...C_kB where $$$k$$$ is the number of shapes you want to tape together, $$$id(A_1),\\dots,id(A_k)$$$ are their IDs, $$$C_1,\\dots,C_k$$$ are equivalent shapes showing their position within $$$B$$$, and $$$B$$$ is the final shape obtained by taping them together. It is recommended to output coordinates of points to at least 10 decimal places. The output must satisfy the following: All coordinates of points in the output must be between $$$-10^7$$$ and $$$10^7$$$, inclusive. Each shape in the output must have at most $$$100$$$ points. In each operation the number $$$k$$$ of shapes must be between $$$1$$$ and $$$100$$$, inclusive. The number of operations must not exceed $$$2000$$$. The total number of points in all shapes in the output must not exceed $$$20000$$$. In the end, there must be exactly one shape (that hasn't been destroyed), and that shape must be equivalent to $$$T$$$. All operations must be valid according to the checker. Solutions with small rounding errors will be accepted. (Internally, all comparisons check for absolute or relative error up to $$$10^{-3}$$$ when verifying each condition.) ", "sample_inputs": ["6 0 0 6 0 6 4 5 4 5 9 0 9\n4 0 0 7 0 7 7 0 7", "4 0 0 3 0 3 3 0 3\n4 7 -1 10 -1 11 2 8 2", "4 0 0 9 0 9 1 0 1\n4 0 0 3 0 3 3 0 3"], "sample_outputs": ["scissors\n0 5\n3 0 0 3 0 3 4\n3 3 4 0 4 0 0\n3 3 0 6 0 6 4\n3 6 4 3 4 3 0\n4 0 4 5 4 5 9 0 9\ntape\n5 1 2 5 3 4\n3 0 3 0 0 4 0\n3 4 0 7 0 7 4\n4 0 3 4 0 7 4 3 7\n3 7 4 7 7 3 7\n3 3 7 0 7 0 3\n4 0 0 7 0 7 7 0 7", "scissors\n0 2\n3 0 0 1 3 0 3\n4 1 3 0 0 3 0 3 3\ntape\n2 1 2\n3 110 -1 111 2 110 2\n4 108 2 107 -1 110 -1 110 2\n4 107 -1 110 -1 111 2 108 2", "scissors\n0 2\n4 1.470000000 0 9 0 9 1 1.470000000 1\n4 0 0 1.470000000 0 1.470000000 1 0 1\nscissors\n1 2\n4 1.470000000 0 6 0 6 1 1.470000000 1\n4 9 0 9 1 6 1 6 0\ntape\n2 4 3\n4 3 2 3 1 6 1 6 2\n4 6 1 1.470000000 1 1.470000000 0 6 0\n6 1.470000000 0 6 0 6 2 3 2 3 1 1.470000000 1\nscissors\n5 4\n4 1.470000000 0 3 0 3 1 1.470000000 1\n4 3 0 4 0 4 2 3 2\n4 4 2 4 0 5 0 5 2\n4 5 0 6 0 6 2 5 2\ntape\n5 2 6 7 8 9\n4 0 0 1.470000000 0 1.470000000 1 0 1\n4 1.470000000 0 3 0 3 1 1.470000000 1\n4 0 2 0 1 2 1 2 2\n4 0 2 2 2 2 3 0 3\n4 3 3 2 3 2 1 3 1\n4 0 0 3 0 3 3 0 3"], "notes": "NoteThe figure below shows the first example output. On the left is the original figure after using the scissors, on the right are the corresponding $$$C_i$$$ when we tape those pieces back together.In the second example output, note that it is sufficient if the final shape is equivalent to the target one, they do not have to be identical.The figure below shows three stages of the third example output. First, we cut the input rectangle into two smaller rectangles, then we cut the bigger of those two rectangles into two more. State after these cuts is shown in the top left part of the figure.Continuing, we tape the two new rectangles together to form a six-sided polygon, and then we cut that polygon into three 2-by-1 rectangles and one smaller rectangle. This is shown in the bottom left part of the figure.Finally, we take the rectangle we still have from the first step and the four new rectangles and we assemble them into the desired 3-by-3 square."}, "src_uid": "375b83d1b7a911c1ca67d5209d39adb4"} {"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": "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": "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": "It is the year 2969. 1000 years have passed from the moon landing. Meanwhile, the humanity colonized the Hyperspace\u2122 and lived in harmony.Until we realized that we were not alone.Not too far away from the Earth, the massive fleet of aliens' spaceships is preparing to attack the Earth. For the first time in a while, the humanity is in real danger. Crisis and panic are everywhere. The scientists from all around the solar system have met and discussed the possible solutions. However, no progress has been made.The Earth's last hope is YOU!Fortunately, the Earth is equipped with very powerful defense systems made by MDCS. There are $$$N$$$ aliens' spaceships which form the line. The defense system consists of three types of weapons: SQL rockets \u2013 every SQL rocket can destroy at most one spaceship in the given set. Cognition beams \u2013 every Cognition beam has an interval $$$[l,r]$$$ and can destroy at most one spaceship in that interval. OMG bazooka \u2013 every OMG bazooka has three possible targets, however, each bazooka can destroy either zero or exactly two spaceships. In addition, due to the smart targeting system, the sets of the three possible targets of any two different OMG bazookas are disjoint (that means that every ship is targeted with at most one OMG bazooka). Your task is to make a plan of the attack which will destroy the largest possible number of spaceships. Every destroyed spaceship should be destroyed with exactly one weapon.", "input_spec": "The first line contains two integers: the number of your weapons $$$N$$$ $$$(1\\leq N\\leq 5000)$$$ and the number of spaceships $$$M$$$ $$$(1\\leq M\\leq 5000)$$$. In the next $$$N$$$ lines, each line starts with one integer that represents type (either 0, 1 or 2). If the type is 0, then the weapon is SQL rocket, the rest of the line contains strictly positive number $$$K$$$ $$$(\\sum{K} \\leq 100 000)$$$ and array $$$k_i$$$ $$$(1\\leq k_i\\leq M)$$$ of $$$K$$$ integers. If the type is 1, then the weapon is Cognition beam, the rest of the line contains integers $$$l$$$ and $$$r$$$ $$$(1\\leq l\\leq r\\leq M)$$$. If the type is 2 then the weapon is OMG bazooka, the rest of the line contains distinct numbers $$$a$$$, $$$b$$$ and $$$c$$$ $$$ (1 \\leq a,b,c \\leq M)$$$.", "output_spec": "The first line should contain the maximum number of destroyed spaceships \u2014 $$$X$$$. In the next $$$X$$$ lines, every line should contain two numbers $$$A$$$ and $$$B$$$, where $$$A$$$ is an index of the weapon and $$$B$$$ is an index of the spaceship which was destroyed by the weapon $$$A$$$.", "sample_inputs": ["3 5\n0 1 4\n2 5 4 1\n1 1 4"], "sample_outputs": ["4\n2 1\n3 2\n1 4\n2 5"], "notes": "NoteSQL rocket can destroy only 4th spaceship. OMG Bazooka can destroy two of 1st, 4th or 5th spaceship, and Cognition beam can destroy any spaceship from the interval $$$[1,4]$$$. The maximum number of destroyed spaceship is 4, and one possible plan is that SQL rocket should destroy 4th spaceship, OMG bazooka should destroy 1st and 5th spaceship and Cognition beam should destroy 2nd spaceship."}, "src_uid": "429a94c8e3f28100c8c532e948cc36e3"} {"nl": {"description": "You generate real numbers s1,\u2009s2,\u2009...,\u2009sn as follows: s0\u2009=\u20090; si\u2009=\u2009si\u2009-\u20091\u2009+\u2009ti, where ti is a real number chosen independently uniformly at random between 0 and 1, inclusive. You are given real numbers x1,\u2009x2,\u2009...,\u2009xn. You are interested in the probability that si\u2009\u2264\u2009xi is true for all i simultaneously.It can be shown that this can be represented as , where P and Q are coprime integers, and . Print the value of P\u00b7Q\u2009-\u20091 modulo 998244353.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200930). The next n lines contain real numbers x1,\u2009x2,\u2009...,\u2009xn, given with at most six digits after the decimal point (0\u2009<\u2009xi\u2009\u2264\u2009n).", "output_spec": "Print a single integer, the answer to the problem.", "sample_inputs": ["4\n1.00\n2\n3.000000\n4.0", "1\n0.50216", "2\n0.5\n1.0", "6\n0.77\n1.234567\n2.1\n1.890\n2.9999\n3.77"], "sample_outputs": ["1", "342677322", "623902721", "859831967"], "notes": "NoteIn the first example, the sought probability is 1 since the sum of i real numbers which don't exceed 1 doesn't exceed i.In the second example, the probability is x1 itself.In the third example, the sought probability is 3\u2009/\u20098."}, "src_uid": "fed8173bf7731f3d663467cc0131d788"} {"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": "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": "zscoder has a deck of $$$n+m$$$ custom-made cards, which consists of $$$n$$$ cards labelled from $$$1$$$ to $$$n$$$ and $$$m$$$ jokers. Since zscoder is lonely, he wants to play a game with himself using those cards. Initially, the deck is shuffled uniformly randomly and placed on the table. zscoder has a set $$$S$$$ which is initially empty. Every second, zscoder draws the top card from the deck. If the card has a number $$$x$$$ written on it, zscoder removes the card and adds $$$x$$$ to the set $$$S$$$. If the card drawn is a joker, zscoder places all the cards back into the deck and reshuffles (uniformly randomly) the $$$n+m$$$ cards to form a new deck (hence the new deck now contains all cards from $$$1$$$ to $$$n$$$ and the $$$m$$$ jokers). Then, if $$$S$$$ currently contains all the elements from $$$1$$$ to $$$n$$$, the game ends. Shuffling the deck doesn't take time at all. What is the expected number of seconds before the game ends? We can show that the answer can be written in the form $$$\\frac{P}{Q}$$$ where $$$P, Q$$$ are relatively prime integers and $$$Q \\neq 0 \\bmod 998244353$$$. Output the value of $$$(P \\cdot Q^{-1})$$$ modulo $$$998244353$$$.", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 2 \\cdot 10^{6}$$$).", "output_spec": "Output a single integer, the value of $$$(P \\cdot Q^{-1})$$$ modulo $$$998244353$$$.", "sample_inputs": ["2 1", "3 2", "14 9"], "sample_outputs": ["5", "332748127", "969862773"], "notes": "NoteFor the first sample, it can be proven that the expected time before the game ends is $$$5$$$ seconds.For the second sample, it can be proven that the expected time before the game ends is $$$\\frac{28}{3}$$$ seconds."}, "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613"} {"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": "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": "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"} {"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": "InputThe input contains two integers $$$N$$$, $$$M$$$ ($$$1 \\le N \\le 1024, 2 \\le M \\le 16$$$), separated by a single space.OutputOutput \"YES\" or \"NO\".ExamplesInput\n2 3\nOutput\nYES\nInput\n3 2\nOutput\nNO\nInput\n33 16\nOutput\nYES\nInput\n26 5\nOutput\nNO\n", "input_spec": "The input contains two integers $$$N$$$, $$$M$$$ ($$$1 \\le N \\le 1024, 2 \\le M \\le 16$$$), separated by a single space.", "output_spec": "Output \"YES\" or \"NO\".", "sample_inputs": ["2 3", "3 2", "33 16", "26 5"], "sample_outputs": ["YES", "NO", "YES", "NO"], "notes": null}, "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f"} {"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": "Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically \u00a0\u2014 he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student\u00a0\u2014 $$$4.5$$$ would be rounded up to $$$5$$$ (as in example 3), but $$$4.4$$$ would be rounded down to $$$4$$$.This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $$$5$$$ (maybe even the dreaded $$$2$$$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $$$5$$$ for the course. Of course, Vasya will get $$$5$$$ for the lab works he chooses to redo.Help Vasya\u00a0\u2014 calculate the minimum amount of lab works Vasya has to redo.", "input_spec": "The first line contains a single integer $$$n$$$\u00a0\u2014 the number of Vasya's grades ($$$1 \\leq n \\leq 100$$$). The second line contains $$$n$$$ integers from $$$2$$$ to $$$5$$$\u00a0\u2014 Vasya's grades for his lab works.", "output_spec": "Output a single integer\u00a0\u2014 the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $$$5$$$.", "sample_inputs": ["3\n4 4 4", "4\n5 4 5 5", "4\n5 3 3 5"], "sample_outputs": ["2", "0", "1"], "notes": "NoteIn the first sample, it is enough to redo two lab works to make two $$$4$$$s into $$$5$$$s.In the second sample, Vasya's average is already $$$4.75$$$ so he doesn't have to redo anything to get a $$$5$$$.In the second sample Vasya has to redo one lab work to get rid of one of the $$$3$$$s, that will make the average exactly $$$4.5$$$ so the final grade would be $$$5$$$."}, "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"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": "Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.Vasiliy's car is not new \u2014 it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a\u2009<\u2009b).Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.", "input_spec": "The first line contains 5 positive integers d,\u2009k,\u2009a,\u2009b,\u2009t (1\u2009\u2264\u2009d\u2009\u2264\u20091012; 1\u2009\u2264\u2009k,\u2009a,\u2009b,\u2009t\u2009\u2264\u2009106; a\u2009<\u2009b), where: d \u2014 the distance from home to the post office; k \u2014 the distance, which car is able to drive before breaking; a \u2014 the time, which Vasiliy spends to drive 1 kilometer on his car; b \u2014 the time, which Vasiliy spends to walk 1 kilometer on foot; t \u2014 the time, which Vasiliy spends to repair his car. ", "output_spec": "Print the minimal time after which Vasiliy will be able to reach the post office.", "sample_inputs": ["5 2 1 4 10", "5 2 1 4 5"], "sample_outputs": ["14", "13"], "notes": "NoteIn the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds.In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds."}, "src_uid": "359ddf1f1aed9b3256836e5856fe3466"} {"nl": {"description": "Seven boys and seven girls from Athens were brought before King Minos. The evil king laughed and said \"I hope you enjoy your stay in Crete\".With a loud clang, the doors behind them shut, and darkness reigned. The terrified children huddled together. In the distance they heard a bellowing, unholy roar.Bravely, they advanced forward, to their doom.", "input_spec": "$$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the dimensions of the labyrinth. Each of the next $$$n$$$ lines contains a string of lowercase English letters of length $$$n$$$.", "output_spec": null, "sample_inputs": ["10\natzxcodera\nmzhappyayc\nmineodteri\ntrxesonaac\nmtollexcxc\nhjikeoutlc\neascripsni\nrgvymnjcxm\nonzazwswwg\ngeothermal"], "sample_outputs": ["YES"], "notes": null}, "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0"} {"nl": {"description": "This problem is split into two tasks. In this task, you are required to find the maximum possible answer. In the task Village (Minimum) you are required to find the minimum possible answer. Each task is worth $$$50$$$ points.There are $$$N$$$ houses in a certain village. A single villager lives in each of the houses. The houses are connected by roads. Each road connects two houses and is exactly $$$1$$$ kilometer long. From each house it is possible to reach any other using one or several consecutive roads. In total there are $$$N-1$$$ roads in the village.One day all villagers decided to move to different houses \u2014 that is, after moving each house should again have a single villager living in it, but no villager should be living in the same house as before. We would like to know the largest possible total length in kilometers of the shortest paths between the old and the new houses for all villagers. Example village with seven houses For example, if there are seven houses connected by roads as shown on the figure, the largest total length is $$$18$$$ km (this can be achieved by moving $$$1 \\to 7$$$, $$$2 \\to 3$$$, $$$3 \\to 4$$$, $$$4 \\to 1$$$, $$$5 \\to 2$$$, $$$6 \\to 5$$$, $$$7 \\to 6$$$).Write a program that finds the largest total length of the shortest paths in kilometers and an example assignment of the new houses to the villagers.", "input_spec": "The first line contains an integer $$$N$$$ ($$$1 < N \\le 10^5$$$). Houses are numbered by consecutive integers $$$1, 2, \\ldots, N$$$. Then $$$N-1$$$ lines follow that describe the roads. Each line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le N$$$, $$$a \\neq b$$$) denoting that there is a road connecting houses $$$a$$$ and $$$b$$$.", "output_spec": "In the first line output the largest total length of the shortest paths in kilometers. In the second line describe one valid assignment of the new houses with the largest total length: $$$N$$$ space-separated distinct integers $$$v_1, v_2, \\ldots, v_N$$$. For each $$$i$$$, $$$v_i$$$ is the house number where villager from the house $$$i$$$ should move ($$$v_i \\neq i$$$). If there are several valid assignments, output any of those.", "sample_inputs": ["4\n1 2\n2 3\n3 4", "7\n4 2\n5 7\n3 4\n6 3\n1 3\n4 5"], "sample_outputs": ["8\n4 3 2 1", "18\n2 7 4 1 3 5 6"], "notes": null}, "src_uid": "343dbacbc6bb4981a062dda5a1a13656"} {"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": "You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S\u2009=\u2009{x1,\u2009x2,\u2009...,\u2009xk} (1\u2009\u2264\u2009xi\u2009\u2264\u2009n, 0\u2009<\u2009k\u2009<\u2009n) the sums of elements on that positions in a and b are different, i.\u00a0e. ", "input_spec": "The first line contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u200922)\u00a0\u2014 the size of the array. The second line contains n space-separated distinct integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u2009109)\u00a0\u2014 the elements of the array.", "output_spec": "If there is no such array b, print -1. Otherwise in the only line print n space-separated integers b1,\u2009b2,\u2009...,\u2009bn. Note that b must be a permutation of a. If there are multiple answers, print any of them.", "sample_inputs": ["2\n1 2", "4\n1000 100 10 1"], "sample_outputs": ["2 1", "100 1 1000 10"], "notes": "NoteAn array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.Note that the empty subset and the subset containing all indices are not counted."}, "src_uid": "e314642ca1f82be8f223e2eba00b5531"} {"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": "Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name \"dot\" with the following rules: On the checkered paper a coordinate system is drawn. A dot is initially put in the position (x,\u2009y). A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line y\u2009=\u2009x. Anton and Dasha take turns. Anton goes first. The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses. Help them to determine the winner.", "input_spec": "The first line of the input file contains 4 integers x, y, n, d (\u2009-\u2009200\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009200,\u20091\u2009\u2264\u2009d\u2009\u2264\u2009200,\u20091\u2009\u2264\u2009n\u2009\u2264\u200920) \u2014 the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (0\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009200) \u2014 the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.", "output_spec": "You should print \"Anton\", if the winner is Anton in case of both players play the game optimally, and \"Dasha\" otherwise.", "sample_inputs": ["0 0 2 3\n1 1\n1 2", "0 0 2 4\n1 1\n1 2"], "sample_outputs": ["Anton", "Dasha"], "notes": "NoteIn the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move \u2014 to reflect relatively to the line y\u2009=\u2009x. Dasha will respond to it with the same move and return the dot in position (2;3)."}, "src_uid": "645a6ca9a8dda6946c2cc055a4beb08f"} {"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": "This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be n noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1\u2009/\u2009n). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task.", "input_spec": "The first line contains a single integer n from the problem's statement (1\u2009\u2264\u2009n\u2009\u2264\u200910000).", "output_spec": "Print the sought expected number of tosses as an irreducible fraction in the following form: \"a/b\" (without the quotes) without leading zeroes.", "sample_inputs": ["2", "3", "4"], "sample_outputs": ["1/1", "8/3", "2/1"], "notes": null}, "src_uid": "5491b4a27991153a61ac4a2618b2cd0e"} {"nl": {"description": "There is an airplane which has n rows from front to back. There will be m people boarding this airplane.This airplane has an entrance at the very front and very back of the plane.Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the plane one by one starting with person 1. Each person can independently choose either the front entrance or back entrance to enter the plane.When a person walks into the plane, they walk directly to their assigned seat and will try to sit in it. If it is occupied, they will continue walking in the direction they walked in until they are at empty seat - they will take the earliest empty seat that they can find. If they get to the end of the row without finding a seat, they will be angry.Find the number of ways to assign tickets to the passengers and board the plane without anyone getting angry. Two ways are different if there exists a passenger who chose a different entrance in both ways, or the assigned seat is different. Print this count modulo 109\u2009+\u20097.", "input_spec": "The first line of input will contain two integers n,\u2009m (1\u2009\u2264\u2009m\u2009\u2264\u2009n\u2009\u2264\u20091\u2009000\u2009000), the number of seats, and the number of passengers, respectively.", "output_spec": "Print a single number, the number of ways, modulo 109\u2009+\u20097.", "sample_inputs": ["3 3"], "sample_outputs": ["128"], "notes": "NoteHere, we will denote a passenger by which seat they were assigned, and which side they came from (either \"F\" or \"B\" for front or back, respectively).For example, one valid way is 3B, 3B, 3B (i.e. all passengers were assigned seat 3 and came from the back entrance). Another valid way would be 2F, 1B, 3F.One invalid way would be 2B, 2B, 2B, since the third passenger would get to the front without finding a seat."}, "src_uid": "4f9711197e699c0fd0c4e9db8323cac7"} {"nl": {"description": "Mike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai\u2009<\u2009ai\u2009+\u20091 for all i from 1 to n\u2009-\u20091; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.Today Mike decided to cover the track with holds hanging on heights a1, ..., an. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,\u20092,\u20093,\u20094,\u20095) and remove the third element from it, we obtain the sequence (1,\u20092,\u20094,\u20095)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.Help Mike determine the minimum difficulty of the track after removing one hold.", "input_spec": "The first line contains a single integer n (3\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of holds. The next line contains n space-separated integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u20091000), where ai is the height where the hold number i hangs. The sequence ai is increasing (i.e. each element except for the first one is strictly larger than the previous one).", "output_spec": "Print a single number \u2014 the minimum difficulty of the track after removing a single hold.", "sample_inputs": ["3\n1 4 6", "5\n1 2 3 4 5", "5\n1 2 3 7 8"], "sample_outputs": ["5", "2", "4"], "notes": "NoteIn the first sample you can remove only the second hold, then the sequence looks like (1,\u20096), the maximum difference of the neighboring elements equals 5.In the second test after removing every hold the difficulty equals 2.In the third test you can obtain sequences (1,\u20093,\u20097,\u20098), (1,\u20092,\u20097,\u20098), (1,\u20092,\u20093,\u20098), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer \u2014 4."}, "src_uid": "8a8013f960814040ac4bf229a0bd5437"} {"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": "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": "You are given a mysterious language (codenamed \"Secret\") available in \"Custom Test\" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language.", "input_spec": "This program has only one test, and it's empty (it doesn't give your program anything to read).", "output_spec": "Output the name of the mysterious language.", "sample_inputs": [], "sample_outputs": [], "notes": null}, "src_uid": "ef8239a0f77c538d2d9b246b86be63fe"} {"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": "You all know the Dirichlet principle, the point of which is that if n boxes have no less than n\u2009+\u20091 items, that leads to the existence of a box in which there are at least two items.Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.Who loses if both players play optimally and Stas's turn is first?", "input_spec": "The only input line has three integers a,\u2009b,\u2009n (1\u2009\u2264\u2009a\u2009\u2264\u200910000, 1\u2009\u2264\u2009b\u2009\u2264\u200930, 2\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.", "output_spec": "Output \"Stas\" if Masha wins. Output \"Masha\" if Stas wins. In case of a draw, output \"Missing\".", "sample_inputs": ["2 2 10", "5 5 16808", "3 1 4", "1 4 10"], "sample_outputs": ["Masha", "Masha", "Stas", "Missing"], "notes": "NoteIn the second example the initial number of ways is equal to 3125. If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat. But if Stas increases the number of items, then any Masha's move will be losing. "}, "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b"} {"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": "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": "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": "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": "This problem is same as the previous one, but has larger constraints.Aki is playing a new video game. In the video game, he will control Neko, the giant cat, to fly between planets in the Catniverse.There are $$$n$$$ planets in the Catniverse, numbered from $$$1$$$ to $$$n$$$. At the beginning of the game, Aki chooses the planet where Neko is initially located. Then Aki performs $$$k - 1$$$ moves, where in each move Neko is moved from the current planet $$$x$$$ to some other planet $$$y$$$ such that: Planet $$$y$$$ is not visited yet. $$$1 \\leq y \\leq x + m$$$ (where $$$m$$$ is a fixed constant given in the input) This way, Neko will visit exactly $$$k$$$ different planets. Two ways of visiting planets are called different if there is some index $$$i$$$ such that, the $$$i$$$-th planet visited in the first way is different from the $$$i$$$-th planet visited in the second way.What is the total number of ways to visit $$$k$$$ planets this way? Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.", "input_spec": "The only line contains three integers $$$n$$$, $$$k$$$ and $$$m$$$ ($$$1 \\le n \\le 10^9$$$, $$$1 \\le k \\le \\min(n, 12)$$$, $$$1 \\le m \\le 4$$$)\u00a0\u2014 the number of planets in the Catniverse, the number of planets Neko needs to visit and the said constant $$$m$$$.", "output_spec": "Print exactly one integer\u00a0\u2014 the number of different ways Neko can visit exactly $$$k$$$ planets. Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.", "sample_inputs": ["3 3 1", "4 2 1", "5 5 4", "100 1 2"], "sample_outputs": ["4", "9", "120", "100"], "notes": "NoteIn the first example, there are $$$4$$$ ways Neko can visit all the planets: $$$1 \\rightarrow 2 \\rightarrow 3$$$ $$$2 \\rightarrow 3 \\rightarrow 1$$$ $$$3 \\rightarrow 1 \\rightarrow 2$$$ $$$3 \\rightarrow 2 \\rightarrow 1$$$ In the second example, there are $$$9$$$ ways Neko can visit exactly $$$2$$$ planets: $$$1 \\rightarrow 2$$$ $$$2 \\rightarrow 1$$$ $$$2 \\rightarrow 3$$$ $$$3 \\rightarrow 1$$$ $$$3 \\rightarrow 2$$$ $$$3 \\rightarrow 4$$$ $$$4 \\rightarrow 1$$$ $$$4 \\rightarrow 2$$$ $$$4 \\rightarrow 3$$$ In the third example, with $$$m = 4$$$, Neko can visit all the planets in any order, so there are $$$5! = 120$$$ ways Neko can visit all the planets.In the fourth example, Neko only visit exactly $$$1$$$ planet (which is also the planet he initially located), and there are $$$100$$$ ways to choose the starting planet for Neko."}, "src_uid": "87931a8ae9a76d85bd2a2b4bba93303d"} {"nl": {"description": "Alex studied well and won the trip to student camp Alushta, located on the seashore. Unfortunately, it's the period of the strong winds now and there is a chance the camp will be destroyed! Camp building can be represented as the rectangle of n\u2009+\u20092 concrete blocks height and m blocks width.Every day there is a breeze blowing from the sea. Each block, except for the blocks of the upper and lower levers, such that there is no block to the left of it is destroyed with the probability . Similarly, each night the breeze blows in the direction to the sea. Thus, each block (again, except for the blocks of the upper and lower levers) such that there is no block to the right of it is destroyed with the same probability p. Note, that blocks of the upper and lower level are indestructible, so there are only n\u00b7m blocks that can be destroyed.The period of the strong winds will last for k days and k nights. If during this period the building will split in at least two connected components, it will collapse and Alex will have to find another place to spend summer.Find the probability that Alex won't have to look for other opportunities and will be able to spend the summer in this camp.", "input_spec": "The first line of the input contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091500) that define the size of the destructible part of building. The second line of the input contains two integers a and b (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009109) that define the probability p. It's guaranteed that integers a and b are coprime. The third line contains a single integer k (0\u2009\u2264\u2009k\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the number of days and nights strong wind will blow for.", "output_spec": "Consider the answer as an irreducible fraction is equal to . Print one integer equal to . It's guaranteed that within the given constraints .", "sample_inputs": ["2 2\n1 2\n1", "5 1\n3 10\n1", "3 3\n1 10\n5"], "sample_outputs": ["937500007", "95964640", "927188454"], "notes": "NoteIn the first sample, each of the four blocks is destroyed with the probability . There are 7 scenarios that result in building not collapsing, and the probability we are looking for is equal to , so you should print "}, "src_uid": "33b6b0d3a6af273f22b703491bd17289"} {"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": "Two players play a game. The game is played on a rectangular board with n\u2009\u00d7\u2009m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.We'll describe the rules of the game in more detail.The players move in turns. The first player begins.With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible \u2014 he can always spread the glue on the square from which the first player has just moved the chip.We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.", "input_spec": "The first line contains six integers n, m, x1, y1, x2, y2 \u2014 the board sizes and the coordinates of the first and second chips, correspondingly (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100; 2\u2009\u2264\u2009n\u2009\u00d7\u2009m; 1\u2009\u2264\u2009x1,\u2009x2\u2009\u2264\u2009n; 1\u2009\u2264\u2009y1,\u2009y2\u2009\u2264\u2009m). The numbers in the line are separated by single spaces. It is guaranteed that the chips are located in different squares.", "output_spec": "If the first player wins, print \"First\" without the quotes. Otherwise, print \"Second\" without the quotes.", "sample_inputs": ["1 6 1 2 1 6", "6 5 4 3 2 1", "10 10 1 1 10 10"], "sample_outputs": ["First", "First", "Second"], "notes": null}, "src_uid": "41f6f90b7307d2383495441114fa8ea2"} {"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": "Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation $$$a + 1 = b$$$ with positive integers $$$a$$$ and $$$b$$$, but Kolya forgot the numbers $$$a$$$ and $$$b$$$. He does, however, remember that the first (leftmost) digit of $$$a$$$ was $$$d_a$$$, and the first (leftmost) digit of $$$b$$$ was $$$d_b$$$.Can you reconstruct any equation $$$a + 1 = b$$$ that satisfies this property? It may be possible that Kolya misremembers the digits, and there is no suitable equation, in which case report so.", "input_spec": "The only line contains two space-separated digits $$$d_a$$$ and $$$d_b$$$ ($$$1 \\leq d_a, d_b \\leq 9$$$).", "output_spec": "If there is no equation $$$a + 1 = b$$$ with positive integers $$$a$$$ and $$$b$$$ such that the first digit of $$$a$$$ is $$$d_a$$$, and the first digit of $$$b$$$ is $$$d_b$$$, print a single number $$$-1$$$. Otherwise, print any suitable $$$a$$$ and $$$b$$$ that both are positive and do not exceed $$$10^9$$$. It is guaranteed that if a solution exists, there also exists a solution with both numbers not exceeding $$$10^9$$$.", "sample_inputs": ["1 2", "4 4", "5 7", "6 2"], "sample_outputs": ["199 200", "412 413", "-1", "-1"], "notes": null}, "src_uid": "3eff6f044c028146bea5f0dfd2870d23"} {"nl": {"description": "In a simplified version of a \"Mini Metro\" game, there is only one subway line, and all the trains go in the same direction. There are $$$n$$$ stations on the line, $$$a_i$$$ people are waiting for the train at the $$$i$$$-th station at the beginning of the game. The game starts at the beginning of the $$$0$$$-th hour. At the end of each hour (couple minutes before the end of the hour), $$$b_i$$$ people instantly arrive to the $$$i$$$-th station. If at some moment, the number of people at the $$$i$$$-th station is larger than $$$c_i$$$, you lose.A player has several trains which he can appoint to some hours. The capacity of each train is $$$k$$$ passengers. In the middle of the appointed hour, the train goes from the $$$1$$$-st to the $$$n$$$-th station, taking as many people at each station as it can accommodate. A train can not take people from the $$$i$$$-th station if there are people at the $$$i-1$$$-th station.If multiple trains are appointed to the same hour, their capacities are being added up and they are moving together.The player wants to stay in the game for $$$t$$$ hours. Determine the minimum number of trains he will need for it.", "input_spec": "The first line contains three integers $$$n$$$, $$$t$$$, and $$$k$$$ ($$$1 \\leq n, t \\leq 200, 1 \\leq k \\leq 10^9$$$)\u00a0\u2014 the number of stations on the line, hours we want to survive, and capacity of each train respectively. Each of the next $$$n$$$ lines contains three integers $$$a_i$$$, $$$b_i$$$, and $$$c_i$$$ ($$$0 \\leq a_i, b_i \\leq c_i \\leq 10^9$$$)\u00a0\u2014 number of people at the $$$i$$$-th station in the beginning of the game, number of people arriving to $$$i$$$-th station in the end of each hour and maximum number of people at the $$$i$$$-th station allowed respectively.", "output_spec": "Output a single integer number\u00a0\u2014 the answer to the problem.", "sample_inputs": ["3 3 10\n2 4 10\n3 3 9\n4 2 8", "4 10 5\n1 1 1\n1 0 1\n0 5 8\n2 7 100"], "sample_outputs": ["2", "12"], "notes": "NoteLet's look at the sample. There are three stations, on the first, there are initially 2 people, 3 people on the second, and 4 people on the third. Maximal capacities of the stations are 10, 9, and 8 respectively.One of the winning strategies is to appoint two trains to the first and the third hours. Then on the first hour, the train takes all of the people from the stations, and at the end of the hour, 4 people arrive at the first station, 3 on the second, and 2 on the third.In the second hour there are no trains appointed, and at the end of it, the same amount of people are arriving again.In the third hour, the train first takes 8 people from the first station, and when it arrives at the second station, it takes only 2 people because it can accommodate no more than 10 people. Then it passes by the third station because it is already full. After it, people arrive at the stations once more, and the game ends.As there was no such moment when the number of people at a station exceeded maximal capacity, we won using two trains."}, "src_uid": "feee94b7e802fc8e3758350f551b7142"} {"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": "Let's denote (yet again) the sequence of Fibonacci strings:$$$F(0) = $$$ 0, $$$F(1) = $$$ 1, $$$F(i) = F(i - 2) + F(i - 1)$$$, where the plus sign denotes the concatenation of two strings.Let's denote the lexicographically sorted sequence of suffixes of string $$$F(i)$$$ as $$$A(F(i))$$$. For example, $$$F(4)$$$ is 01101, and $$$A(F(4))$$$ is the following sequence: 01, 01101, 1, 101, 1101. Elements in this sequence are numbered from $$$1$$$.Your task is to print $$$m$$$ first characters of $$$k$$$-th element of $$$A(F(n))$$$. If there are less than $$$m$$$ characters in this suffix, then output the whole suffix.", "input_spec": "The only line of the input contains three numbers $$$n$$$, $$$k$$$ and $$$m$$$ ($$$1 \\le n, m \\le 200$$$, $$$1 \\le k \\le 10^{18}$$$) denoting the index of the Fibonacci string you have to consider, the index of the element of $$$A(F(n))$$$ and the number of characters you have to output, respectively. It is guaranteed that $$$k$$$ does not exceed the length of $$$F(n)$$$.", "output_spec": "Output $$$m$$$ first characters of $$$k$$$-th element of $$$A(F(n))$$$, or the whole element if its length is less than $$$m$$$.", "sample_inputs": ["4 5 3", "4 3 3"], "sample_outputs": ["110", "1"], "notes": null}, "src_uid": "7b4a057efee5264bfaaf60d50fccb92b"} {"nl": {"description": "There are $$$n$$$ cities in the kingdom $$$X$$$, numbered from $$$1$$$ through $$$n$$$. People travel between cities by some one-way roads. As a passenger, JATC finds it weird that from any city $$$u$$$, he can't start a trip in it and then return back to it using the roads of the kingdom. That is, the kingdom can be viewed as an acyclic graph.Being annoyed by the traveling system, JATC decides to meet the king and ask him to do something. In response, the king says that he will upgrade some cities to make it easier to travel. Because of the budget, the king will only upgrade those cities that are important or semi-important. A city $$$u$$$ is called important if for every city $$$v \\neq u$$$, there is either a path from $$$u$$$ to $$$v$$$ or a path from $$$v$$$ to $$$u$$$. A city $$$u$$$ is called semi-important if it is not important and we can destroy exactly one city $$$v \\neq u$$$ so that $$$u$$$ becomes important.The king will start to act as soon as he finds out all those cities. Please help him to speed up the process.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le 300\\,000$$$, $$$1 \\le m \\le 300\\,000$$$)\u00a0\u2014 the number of cities and the number of one-way roads. Next $$$m$$$ lines describe the road system of the kingdom. Each of them contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \\le u_i, v_i \\le n$$$, $$$u_i \\neq v_i$$$), denoting one-way road from $$$u_i$$$ to $$$v_i$$$. It is guaranteed, that the kingdoms' roads make an acyclic graph, which doesn't contain multiple edges and self-loops.", "output_spec": "Print a single integer\u00a0\u2014 the number of cities that the king has to upgrade.", "sample_inputs": ["7 7\n1 2\n2 3\n3 4\n4 7\n2 5\n5 4\n6 4", "6 7\n1 2\n2 3\n3 4\n1 5\n5 3\n2 6\n6 4"], "sample_outputs": ["4", "4"], "notes": "NoteIn the first example: Starting at the city $$$1$$$ we can reach all the other cities, except for the city $$$6$$$. Also, from the city $$$6$$$ we cannot reach the city $$$1$$$. Therefore, if we destroy the city $$$6$$$ then the city $$$1$$$ will become important. So $$$1$$$ is a semi-important city. For city $$$2$$$, the set of cities that cannot reach $$$2$$$ and cannot be reached by $$$2$$$ is $$$\\{6\\}$$$. Therefore, destroying city $$$6$$$ will make the city $$$2$$$ important. So city $$$2$$$ is also semi-important. For city $$$3$$$, the set is $$$\\{5, 6\\}$$$. As you can see, destroying either city $$$5$$$ or $$$6$$$ will not make the city $$$3$$$ important. Therefore, it is neither important nor semi-important. For city $$$4$$$, the set is empty. So $$$4$$$ is an important city. The set for city $$$5$$$ is $$$\\{3, 6\\}$$$ and the set for city $$$6$$$ is $$$\\{3, 5\\}$$$. Similarly to city $$$3$$$, both of them are not important nor semi-important. The city $$$7$$$ is important since we can reach it from all other cities. So we have two important cities ($$$4$$$ and $$$7$$$) and two semi-important cities ($$$1$$$ and $$$2$$$).In the second example, the important cities are $$$1$$$ and $$$4$$$. The semi-important cities are $$$2$$$ and $$$3$$$."}, "src_uid": "be26e93ca7aef1235e96e10467a6417e"} {"nl": {"description": "Given an integer $$$x$$$. Your task is to find out how many positive integers $$$n$$$ ($$$1 \\leq n \\leq x$$$) satisfy $$$$$$n \\cdot a^n \\equiv b \\quad (\\textrm{mod}\\;p),$$$$$$ where $$$a, b, p$$$ are all known constants.", "input_spec": "The only line contains four integers $$$a,b,p,x$$$ ($$$2 \\leq p \\leq 10^6+3$$$, $$$1 \\leq a,b < p$$$, $$$1 \\leq x \\leq 10^{12}$$$). It is guaranteed that $$$p$$$ is a prime.", "output_spec": "Print a single integer: the number of possible answers $$$n$$$.", "sample_inputs": ["2 3 5 8", "4 6 7 13", "233 233 10007 1"], "sample_outputs": ["2", "1", "1"], "notes": "NoteIn the first sample, we can see that $$$n=2$$$ and $$$n=8$$$ are possible answers."}, "src_uid": "4b9f470e5889da29affae6376f6c9f6a"} {"nl": {"description": "Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen. There is an n\u2009\u00d7\u2009n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r,\u2009c). The square (1,\u20091) contains the white queen and the square (1,\u2009n) contains the black queen. All other squares contain green pawns that don't belong to anyone.The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move. Help Vasya determine who wins if both players play with an optimal strategy on the board n\u2009\u00d7\u2009n.", "input_spec": "The input contains a single number n (2\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 the size of the board.", "output_spec": "On the first line print the answer to problem \u2014 string \"white\" or string \"black\", depending on who wins if the both players play optimally. If the answer is \"white\", then you should also print two integers r and c representing the cell (r,\u2009c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.", "sample_inputs": ["2", "3"], "sample_outputs": ["white\n1 2", "black"], "notes": "NoteIn the first sample test the white queen can capture the black queen at the first move, so the white player wins.In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2,\u20091). Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2,\u20093), otherwise if it goes to the middle vertical line, it will be captured by the white queen.During the next move the same thing happens \u2014 neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3,\u20091), and the black queen ends up on square (3,\u20093). In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins."}, "src_uid": "52e07d176aa1d370788f94ee2e61df93"} {"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": "This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points.Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined, there were n contestants in the tournament, numbered from 1 to n. Each of them had already obtained some amount of tournament points, namely the i-th fighter had pi points.Manao is going to engage in a single fight against each contestant. Each of Manao's fights ends in either a win or a loss. A win grants Manao one point, and a loss grants Manao's opponent one point. For each i, Manao estimated the amount of effort ei he needs to invest to win against the i-th contestant. Losing a fight costs no effort.After Manao finishes all of his fights, the ranklist will be determined, with 1 being the best rank and n\u2009+\u20091 being the worst. The contestants will be ranked in descending order of their tournament points. The contestants with the same number of points as Manao will be ranked better than him if they won the match against him and worse otherwise. The exact mechanism of breaking ties for other fighters is not relevant here.Manao's objective is to have rank k or better. Determine the minimum total amount of effort he needs to invest in order to fulfill this goal, if it is possible.", "input_spec": "The first line contains a pair of integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009+\u20091). The i-th of the following n lines contains two integers separated by a single space \u2014 pi and ei (0\u2009\u2264\u2009pi,\u2009ei\u2009\u2264\u2009200000). The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. In subproblem C1 (4 points), the constraint 1\u2009\u2264\u2009n\u2009\u2264\u200915 will hold. In subproblem C2 (4 points), the constraint 1\u2009\u2264\u2009n\u2009\u2264\u2009100 will hold. In subproblem C3 (8 points), the constraint 1\u2009\u2264\u2009n\u2009\u2264\u2009200000 will hold. ", "output_spec": "Print a single number in a single line \u2014 the minimum amount of effort Manao needs to use to rank in the top k. If no amount of effort can earn Manao such a rank, output number -1.", "sample_inputs": ["3 2\n1 1\n1 4\n2 2", "2 1\n3 2\n4 0", "5 2\n2 10\n2 10\n1 1\n3 1\n3 1"], "sample_outputs": ["3", "-1", "12"], "notes": "NoteConsider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters 1 and 3, after which Manao, fighter 2, and fighter 3 will all have 2 points. Manao will rank better than fighter 3 and worse than fighter 2, thus finishing in second place.Consider the second test case. Even if Manao wins against both opponents, he will still rank third."}, "src_uid": "19a098cef100fc3652c59abf7c373814"} {"nl": {"description": "The only difference between this problem and D2 is that you don't have to provide the way to construct the answer in this problem, but you have to do it in D2.There's a table of $$$n \\times m$$$ cells ($$$n$$$ rows and $$$m$$$ columns). The value of $$$n \\cdot m$$$ is even.A domino is a figure that consists of two cells having a common side. It may be horizontal (one of the cells is to the right of the other) or vertical (one of the cells is above the other).You need to find out whether it is possible to place $$$\\frac{nm}{2}$$$ dominoes on the table so that exactly $$$k$$$ of them are horizontal and all the other dominoes are vertical. The dominoes cannot overlap and must fill the whole table.", "input_spec": "The first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of a single line. The line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \\le n,m \\le 100$$$, $$$0 \\le k \\le \\frac{nm}{2}$$$, $$$n \\cdot m$$$ is even) \u2014 the number of rows, columns and horizontal dominoes, respectively.", "output_spec": "For each test case output \"YES\", if it is possible to place dominoes in the desired way, or \"NO\" otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).", "sample_inputs": ["8\n4 4 2\n2 3 0\n3 2 3\n1 2 0\n2 4 2\n5 2 2\n2 17 16\n2 1 1"], "sample_outputs": ["YES\nYES\nYES\nNO\nYES\nNO\nYES\nNO"], "notes": null}, "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"} {"nl": {"description": "You have been hired to supervise the project of a new amusement park. The park will have a special gimmick: directed slides that can get customers from one attraction to another quickly and in an entertaining way.The park owner has given you the current project: a list of planned attractions and a list of slides that should be built between them. However, him being a businessman, he casually envisioned the impossible: among other things, he projected a slide coming from the Haunted Castle to the Roller Coaster, another from the Roller Coaster to the Drop Tower, and a third from the Drop Tower to the Haunted Castle. As the slides can only go downhill, it is evident why this is a problem. You don't have the luxury of ignoring the laws of physics when building the park, so you have to request changes in the project. Maybe he would accept reversing the slide between the Drop Tower and the Haunted Castle?Formally: The project is a list of attractions and a list of directed slides. Each slide starts at one attraction and ends at another attraction. A proposal is obtained from the project by reversing the directions of some slides (possibly none or all of them). A proposal is legal if there is a way to assign an elevation to each attraction in such a way that every slide goes downhill. The cost of a proposal is the number of slides whose directions were reversed. For a given project, find and report the sum of costs all legal proposals. Since this number may be large, output it modulo $$$998,244,353$$$.", "input_spec": "The first line contains two space-separated integers $$$n$$$, $$$m$$$ ($$$1 \\leq n \\leq 18$$$, $$$0 \\leq m \\leq n(n-1)/2$$$) \u2013 the number of attractions and the number of slides, respectively. The attractions are numbered $$$1$$$ through $$$n$$$. Then, $$$m$$$ lines follow. The $$$i$$$-th of these lines contains two space-separated integers $$$a_i$$$, $$$b_i$$$ ($$$1 \\leq a_i, b_i \\leq n$$$) denoting a slide from $$$a_i$$$ to $$$b_i$$$. You may assume that: There are no self-loops. (For each $$$i$$$: $$$a_i \\neq b_i$$$.) No slide appears twice. (For all $$$i \\neq j$$$: $$$a_i \\neq a_j$$$ or $$$b_i \\neq b_j$$$.) No pair of attractions is connected in both directions. (The unordered pairs $$$\\{a_i, b_i\\}$$$ are distinct.) ", "output_spec": "Output one line with a single integer, the sum of costs of all legal proposals modulo $$$998,244,353$$$.", "sample_inputs": ["2 1\n1 2", "3 3\n1 2\n2 3\n1 3"], "sample_outputs": ["1", "9"], "notes": "NoteIn the first example, there are two proposals: The slide direction is not flipped. This proposal has cost $$$0$$$. The slide direction is flipped. This proposal has cost $$$1$$$. As both proposals are valid, the answer is $$$0 + 1 = 1$$$.In the second example, there are eight proposals with the slide directions as follows: $$$1 \\rightarrow 2$$$, $$$2 \\rightarrow 3$$$, $$$1 \\rightarrow 3$$$ (cost $$$0$$$) $$$1 \\rightarrow 2$$$, $$$2 \\rightarrow 3$$$, $$$3 \\rightarrow 1$$$ (cost $$$1$$$) $$$1 \\rightarrow 2$$$, $$$3 \\rightarrow 2$$$, $$$1 \\rightarrow 3$$$ (cost $$$1$$$) $$$1 \\rightarrow 2$$$, $$$3 \\rightarrow 2$$$, $$$3 \\rightarrow 1$$$ (cost $$$2$$$) $$$2 \\rightarrow 1$$$, $$$2 \\rightarrow 3$$$, $$$1 \\rightarrow 3$$$ (cost $$$1$$$) $$$2 \\rightarrow 1$$$, $$$2 \\rightarrow 3$$$, $$$3 \\rightarrow 1$$$ (cost $$$2$$$) $$$2 \\rightarrow 1$$$, $$$3 \\rightarrow 2$$$, $$$1 \\rightarrow 3$$$ (cost $$$2$$$) $$$2 \\rightarrow 1$$$, $$$3 \\rightarrow 2$$$, $$$3 \\rightarrow 1$$$ (cost $$$3$$$) The second proposal is not legal, as there is a slide sequence $$$1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 1$$$. This means that the attraction $$$1$$$ has to be strictly higher than ifself, which is clearly impossible. Similarly, the seventh proposal is not legal. The answer is thus $$$0 + 1 + 2 + 1 + 2 + 3 = 9$$$."}, "src_uid": "ed962f0ef1a1a92cdaeee06c508f8c10"} {"nl": {"description": "Your friend has recently learned about coprime numbers. A pair of numbers {a,\u2009b} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (a,\u2009b) is coprime and the pair (b,\u2009c) is coprime, then the pair (a,\u2009c) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a,\u2009b,\u2009c), for which the statement is false, and the numbers meet the condition l\u2009\u2264\u2009a\u2009<\u2009b\u2009<\u2009c\u2009\u2264\u2009r. More specifically, you need to find three numbers (a,\u2009b,\u2009c), such that l\u2009\u2264\u2009a\u2009<\u2009b\u2009<\u2009c\u2009\u2264\u2009r, pairs (a,\u2009b) and (b,\u2009c) are coprime, and pair (a,\u2009c) is not coprime.", "input_spec": "The single line contains two positive space-separated integers l, r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20091018; r\u2009-\u2009l\u2009\u2264\u200950).", "output_spec": "Print three positive space-separated integers a, b, c\u00a0\u2014 three distinct numbers (a,\u2009b,\u2009c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.", "sample_inputs": ["2 4", "10 11", "900000000000000009 900000000000000029"], "sample_outputs": ["2 3 4", "-1", "900000000000000009 900000000000000010 900000000000000021"], "notes": "NoteIn the first sample pair (2,\u20094) is not coprime and pairs (2,\u20093) and (3,\u20094) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. "}, "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"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": "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": "You have a grid with n rows and n columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X').Two empty cells are directly connected if they share a side. Two cells (r1,\u2009c1) (located in the row r1 and column c1) and (r2,\u2009c2) are connected if there exists a sequence of empty cells that starts with (r1,\u2009c1), finishes with (r2,\u2009c2), and any two consecutive cells in this sequence are directly connected. A connected component is a set of empty cells such that any two cells in the component are connected, and there is no cell in this set that is connected to some cell not in this set.Your friend Limak is a big grizzly bear. He is able to destroy any obstacles in some range. More precisely, you can choose a square of size k\u2009\u00d7\u2009k in the grid and Limak will transform all blocked cells there to empty ones. However, you can ask Limak to help only once.The chosen square must be completely inside the grid. It's possible that Limak won't change anything because all cells are empty anyway.You like big connected components. After Limak helps you, what is the maximum possible size of the biggest connected component in the grid?", "input_spec": "The first line of the input contains two integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009500)\u00a0\u2014 the size of the grid and Limak's range, respectively. Each of the next n lines contains a string with n characters, denoting the i-th row of the grid. Each character is '.' or 'X', denoting an empty cell or a blocked one, respectively.", "output_spec": "Print the maximum possible size (the number of cells) of the biggest connected component, after using Limak's help.", "sample_inputs": ["5 2\n..XXX\nXX.XX\nX.XXX\nX...X\nXXXX.", "5 3\n.....\n.XXX.\n.XXX.\n.XXX.\n....."], "sample_outputs": ["10", "25"], "notes": "NoteIn the first sample, you can choose a square of size 2\u2009\u00d7\u20092. It's optimal to choose a square in the red frame on the left drawing below. Then, you will get a connected component with 10 cells, marked blue in the right drawing. "}, "src_uid": "d575f9bbdf625202807db59490c5c327"} {"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": "Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.", "input_spec": "The first line of input contains three integers: n (1\u2009\u2264\u2009n\u2009\u2264\u2009100), k (1\u2009\u2264\u2009k\u2009\u2264\u2009100) and x (1\u2009\u2264\u2009x\u2009\u2264\u2009k). The next line contains n space-separated integers c1,\u2009c2,\u2009...,\u2009cn (1\u2009\u2264\u2009ci\u2009\u2264\u2009k). Number ci means that the i-th ball in the row has color ci. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color. ", "output_spec": "Print a single integer \u2014 the maximum number of balls Iahub can destroy.", "sample_inputs": ["6 2 2\n1 1 2 2 1 1", "1 1 1\n1"], "sample_outputs": ["6", "0"], "notes": null}, "src_uid": "d73d9610e3800817a3109314b1e6f88c"} {"nl": {"description": "Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.Note that she can paint tiles in any order she wants.Given the required information, find the maximum\u00a0number of chocolates Joty can get.", "input_spec": "The only line contains five integers n, a, b, p and q (1\u2009\u2264\u2009n,\u2009a,\u2009b,\u2009p,\u2009q\u2009\u2264\u2009109).", "output_spec": "Print the only integer s \u2014 the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "sample_inputs": ["5 2 3 12 15", "20 2 3 3 5"], "sample_outputs": ["39", "51"], "notes": null}, "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769"} {"nl": {"description": "Little Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game for two players.Each game is set in one of the N maps, each having different terrain configuration. First phase of each game decides on which map the game will be played. The game system randomly selects three maps and shows them to the players. Each player must pick one of those three maps to be discarded. The game system then randomly selects one of the maps that were not picked by any of the players and starts the game.Johnny is deeply enthusiastic about the game and wants to spend some time studying maps, thus increasing chances to win games played on those maps. However, he also needs to do his homework, so he does not have time to study all the maps. That is why he asked himself the following question: \"What is the minimum number of maps I have to study, so that the probability to play one of those maps is at least $$$P$$$\"?Can you help Johnny find the answer for this question? You can assume Johnny's opponents do not know him, and they will randomly pick maps.", "input_spec": "The first line contains two integers $$$N$$$ ($$$3$$$ $$$\\leq$$$ $$$N$$$ $$$\\leq$$$ $$$10^{3}$$$) and $$$P$$$ ($$$0$$$ $$$\\leq$$$ $$$P$$$ $$$\\leq$$$ $$$1$$$) \u2013 total number of maps in the game and probability to play map Johnny has studied. $$$P$$$ will have at most four digits after the decimal point.", "output_spec": "Output contains one integer number \u2013 minimum number of maps Johnny has to study.", "sample_inputs": ["7 1.0000"], "sample_outputs": ["6"], "notes": null}, "src_uid": "788ed59a964264bd0e755e155a37e14d"} {"nl": {"description": "The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the \u00abtranslation\u00bb. Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.", "input_spec": "The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.", "output_spec": "If the word t is a word s, written reversely, print YES, otherwise print NO.", "sample_inputs": ["code\nedoc", "abb\naba", "code\ncode"], "sample_outputs": ["YES", "NO", "NO"], "notes": null}, "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"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": "\"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": "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": "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": "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": " \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": "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": "In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, each garden they plant must have the exact same arrangement of flowers. Initially, Farmer John has n different species of flowers he can plant, with ai flowers of the i-th species.On each of the next q days, Farmer John will receive a batch of flowers of a new species. On day j, he will receive cj flowers of the same species, but of a different species from those Farmer John already has. Farmer John, knowing the right balance between extravagance and minimalism, wants exactly k species of flowers to be used. Furthermore, to reduce waste, each flower of the k species Farmer John chooses must be planted in some garden. And each of the gardens must be identical; that is to say that each of the k chosen species should have an equal number of flowers in each garden. As Farmer John is a proponent of national equality, he would like to create the greatest number of gardens possible.After receiving flowers on each of these q days, Farmer John would like to know the sum, over all possible choices of k species, of the maximum number of gardens he could create. Since this could be a large number, you should output your result modulo 109\u2009+\u20097.", "input_spec": "The first line of the input contains three integers n, k and q (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000, 1\u2009\u2264\u2009q\u2009\u2264\u2009100\u2009000). The i-th (1\u2009\u2264\u2009i\u2009\u2264\u2009n) of the next n lines of the input contains an integer ai (1\u2009\u2264\u2009ai\u2009\u2264\u20091\u2009000\u2009000), the number of flowers of species i Farmer John has initially. The j-th (1\u2009\u2264\u2009j\u2009\u2264\u2009q) of the next q lines of the input contains an integer cj (1\u2009\u2264\u2009cj\u2009\u2264\u20091\u2009000\u2009000), the number of flowers of a new species Farmer John receives on day j.", "output_spec": "After each of the q days, output the sum of the maximum possible number of gardens, where the sum is taken over all possible choices of k species, modulo 109\u2009+\u20097.", "sample_inputs": ["3 3 2\n4\n6\n9\n8\n6", "4 1 2\n6\n5\n4\n3\n2\n1"], "sample_outputs": ["5\n16", "20\n21"], "notes": "NoteIn the first sample case, after the first day Farmer John has (4,\u20096,\u20099,\u20098) of each type of flower, and k\u2009=\u20093.Choosing (4,\u20096,\u20098) lets him make 2 gardens, each with (2,\u20093,\u20094) of each flower, respectively. Choosing (4,\u20096,\u20099), (4,\u20099,\u20098) and (6,\u20099,\u20098) each only let him make one garden, since there is no number of gardens that each species can be evenly split into. So the sum over all choices of k\u2009=\u20093 flowers is 2\u2009+\u20091\u2009+\u20091\u2009+\u20091\u2009=\u20095.After the second day, Farmer John has (4,\u20096,\u20099,\u20098,\u20096) of each flower. The sum over all choices is 1\u2009+\u20092\u2009+\u20092\u2009+\u20091\u2009+\u20091\u2009+\u20092\u2009+\u20092\u2009+\u20093\u2009+\u20091\u2009+\u20091\u2009=\u200916.In the second sample case, k\u2009=\u20091. With x flowers Farmer John can make x gardens. So the answers to the queries are 6\u2009+\u20095\u2009+\u20094\u2009+\u20093\u2009+\u20092\u2009=\u200920 and 6\u2009+\u20095\u2009+\u20094\u2009+\u20093\u2009+\u20092\u2009+\u20091\u2009=\u200921."}, "src_uid": "edf8b780f4e3c610fd6a5ba041a7799c"} {"nl": {"description": "Given an n\u2009\u00d7\u2009n table T consisting of lowercase English letters. We'll consider some string s good if the table contains a correct path corresponding to the given string. In other words, good strings are all strings we can obtain by moving from the left upper cell of the table only to the right and down. Here's the formal definition of correct paths:Consider rows of the table are numbered from 1 to n from top to bottom, and columns of the table are numbered from 1 to n from left to the right. Cell (r,\u2009c) is a cell of table T on the r-th row and in the c-th column. This cell corresponds to letter Tr,\u2009c.A path of length k is a sequence of table cells [(r1,\u2009c1),\u2009(r2,\u2009c2),\u2009...,\u2009(rk,\u2009ck)]. The following paths are correct: There is only one correct path of length 1, that is, consisting of a single cell: [(1,\u20091)]; Let's assume that [(r1,\u2009c1),\u2009...,\u2009(rm,\u2009cm)] is a correct path of length m, then paths [(r1,\u2009c1),\u2009...,\u2009(rm,\u2009cm),\u2009(rm\u2009+\u20091,\u2009cm)] and [(r1,\u2009c1),\u2009...,\u2009(rm,\u2009cm),\u2009(rm,\u2009cm\u2009+\u20091)] are correct paths of length m\u2009+\u20091. We should assume that a path [(r1,\u2009c1),\u2009(r2,\u2009c2),\u2009...,\u2009(rk,\u2009ck)] corresponds to a string of length k: Tr1,\u2009c1\u2009+\u2009Tr2,\u2009c2\u2009+\u2009...\u2009+\u2009Trk,\u2009ck.Two players play the following game: initially they have an empty string. Then the players take turns to add a letter to the end of the string. After each move (adding a new letter) the resulting string must be good. The game ends after 2n\u2009-\u20091 turns. A player wins by the following scenario: If the resulting string has strictly more letters \"a\" than letters \"b\", then the first player wins; If the resulting string has strictly more letters \"b\" than letters \"a\", then the second player wins; If the resulting string has the same number of letters \"a\" and \"b\", then the players end the game with a draw. Your task is to determine the result of the game provided that both players played optimally well.", "input_spec": "The first line contains a single number n (1\u2009\u2264\u2009n\u2009\u2264\u200920). Next n lines contain n lowercase English letters each \u2014 table T.", "output_spec": "In a single line print string \"FIRST\", if the first player wins, \"SECOND\", if the second player wins and \"DRAW\", if the game ends with a draw.", "sample_inputs": ["2\nab\ncd", "2\nxa\nay", "3\naab\nbcb\nbac"], "sample_outputs": ["DRAW", "FIRST", "DRAW"], "notes": "NoteConsider the first sample:Good strings are strings: a, ab, ac, abd, acd.The first player moves first and adds letter a to the string, as there is only one good string of length 1. Then the second player can add b or c and the game will end with strings abd or acd, correspondingly. In the first case it will be a draw (the string has one a and one b), in the second case the first player wins. Naturally, in this case the second player prefers to choose letter b and end the game with a draw.Consider the second sample:Good strings are: x, xa, xay.We can see that the game will end with string xay and the first player wins."}, "src_uid": "d803fe167a96656f8debdc21edd988e4"} {"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": "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": "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": "Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are $$$n$$$ parties, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th party has received $$$a_i$$$ seats in the parliament.Alice's party has number $$$1$$$. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil: The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has $$$200$$$ (or $$$201$$$) seats, then the majority is $$$101$$$ or more seats. Alice's party must have at least $$$2$$$ times more seats than any other party in the coalition. For example, to invite a party with $$$50$$$ seats, Alice's party must have at least $$$100$$$ seats. For example, if $$$n=4$$$ and $$$a=[51, 25, 99, 25]$$$ (note that Alice'a party has $$$51$$$ seats), then the following set $$$[a_1=51, a_2=25, a_4=25]$$$ can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition: $$$[a_2=25, a_3=99, a_4=25]$$$ since Alice's party is not there; $$$[a_1=51, a_2=25]$$$ since coalition should have a strict majority; $$$[a_1=51, a_2=25, a_3=99]$$$ since Alice's party should have at least $$$2$$$ times more seats than any other party in the coalition. Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice's party has enough people to create a coalition on her own, she can invite no parties.Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.Find and print any suitable coalition.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$)\u00a0\u2014 the number of parties. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 100$$$)\u00a0\u2014 the number of seats the $$$i$$$-th party has.", "output_spec": "If no coalition satisfying both conditions is possible, output a single line with an integer $$$0$$$. Otherwise, suppose there are $$$k$$$ ($$$1 \\leq k \\leq n$$$) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are $$$c_1, c_2, \\dots, c_k$$$ ($$$1 \\leq c_i \\leq n$$$). Output two lines, first containing the integer $$$k$$$, and the second the space-separated indices $$$c_1, c_2, \\dots, c_k$$$. You may print the parties in any order. Alice's party (number $$$1$$$) must be on that list. If there are multiple solutions, you may print any of them.", "sample_inputs": ["3\n100 50 50", "3\n80 60 60", "2\n6 5", "4\n51 25 99 25"], "sample_outputs": ["2\n1 2", "0", "1\n1", "3\n1 2 4"], "notes": "NoteIn the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because $$$100$$$ is not a strict majority out of $$$200$$$.In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.In the third example, Alice already has the majority. The fourth example is described in the problem statement."}, "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"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": "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": "This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either\u00a0\u2014 although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all.In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number $$$n$$$.In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could \"see\" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too.Given $$$n$$$, determine the total number of possible bus number variants.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 10^{18}$$$)\u00a0\u2014 the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $$$0$$$.", "output_spec": "Output a single integer\u00a0\u2014 the amount of possible variants of the real bus number.", "sample_inputs": ["97", "2028"], "sample_outputs": ["2", "13"], "notes": "NoteIn the first sample, only variants $$$97$$$ and $$$79$$$ are possible.In the second sample, the variants (in the increasing order) are the following: $$$208$$$, $$$280$$$, $$$802$$$, $$$820$$$, $$$2028$$$, $$$2082$$$, $$$2208$$$, $$$2280$$$, $$$2802$$$, $$$2820$$$, $$$8022$$$, $$$8202$$$, $$$8220$$$."}, "src_uid": "7f4e533f49b73cc2b96b4c56847295f2"} {"nl": {"description": "Joker returns to Gotham City to execute another evil plan. In Gotham City, there are $$$N$$$ street junctions (numbered from $$$1$$$ to $$$N$$$) and $$$M$$$ streets (numbered from $$$1$$$ to $$$M$$$). Each street connects two distinct junctions, and two junctions are connected by at most one street.For his evil plan, Joker needs to use an odd number of streets that together form a cycle. That is, for a junction $$$S$$$ and an even positive integer $$$k$$$, there is a sequence of junctions $$$S, s_1, \\ldots, s_k, S$$$ such that there are streets connecting (a) $$$S$$$ and $$$s_1$$$, (b) $$$s_k$$$ and $$$S$$$, and (c) $$$s_{i-1}$$$ and $$$s_i$$$ for each $$$i = 2, \\ldots, k$$$.However, the police are controlling the streets of Gotham City. On each day $$$i$$$, they monitor a different subset of all streets with consecutive numbers $$$j$$$: $$$l_i \\leq j \\leq r_i$$$. These monitored streets cannot be a part of Joker's plan, of course. Unfortunately for the police, Joker has spies within the Gotham City Police Department; they tell him which streets are monitored on which day. Now Joker wants to find out, for some given number of days, whether he can execute his evil plan. On such a day there must be a cycle of streets, consisting of an odd number of streets which are not monitored on that day.", "input_spec": "The first line of the input contains three integers $$$N$$$, $$$M$$$, and $$$Q$$$ ($$$1 \\leq N, M, Q \\leq 200\\,000$$$): the number of junctions, the number of streets, and the number of days to be investigated. The following $$$M$$$ lines describe the streets. The $$$j$$$-th of these lines ($$$1 \\le j \\le M$$$) contains two junction numbers $$$u$$$ and $$$v$$$ ($$$u \\neq v$$$), saying that street $$$j$$$ connects these two junctions. It is guaranteed that any two junctions are connected by at most one street. The following $$$Q$$$ lines contain two integers $$$l_i$$$ and $$$r_i$$$, saying that all streets $$$j$$$ with $$$l_i \\leq j \\leq r_i$$$ are checked by the police on day $$$i$$$ ($$$1 \\leq i \\leq Q$$$).", "output_spec": "Your output is to contain $$$Q$$$ lines. Line $$$i$$$ ($$$1 \\leq i \\leq Q$$$) contains \"YES\" if Joker can execute his plan on day $$$i$$$, or \"NO\" otherwise.", "sample_inputs": ["6 8 2\n1 3\n1 5\n1 6\n2 5\n2 6\n3 4\n3 5\n5 6\n4 8\n4 7"], "sample_outputs": ["NO\nYES"], "notes": "NoteThe graph in the example test: "}, "src_uid": "57ad95bb938906f7550f7eb6422130f7"} {"nl": {"description": "Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1\u2009\u00d7\u2009b1 rectangle, the paintings have shape of a a2\u2009\u00d7\u2009b2 and a3\u2009\u00d7\u2009b3 rectangles.Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?", "input_spec": "The first line contains two space-separated numbers a1 and b1 \u2014 the sides of the board. Next two lines contain numbers a2,\u2009b2,\u2009a3 and b3 \u2014 the sides of the paintings. All numbers ai,\u2009bi in the input are integers and fit into the range from 1 to 1000.", "output_spec": "If the paintings can be placed on the wall, print \"YES\" (without the quotes), and if they cannot, print \"NO\" (without the quotes).", "sample_inputs": ["3 2\n1 3\n2 1", "5 5\n3 3\n3 3", "4 2\n2 3\n1 2"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteThat's how we can place the pictures in the first test:And that's how we can do it in the third one."}, "src_uid": "2ff30d9c4288390fd7b5b37715638ad9"} {"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": "Emuskald is an innovative musician and always tries to push the boundaries of music production. Now he has come up with an idea for a revolutionary musical instrument \u2014 a rectangular harp.A rectangular harp is a rectangle n\u2009\u00d7\u2009m consisting of n rows and m columns. The rows are numbered 1 to n from top to bottom. Similarly the columns are numbered 1 to m from left to right. String pins are spaced evenly across every side, one per unit. Thus there are n pins on the left and right sides of the harp and m pins on its top and bottom. The harp has exactly n\u2009+\u2009m different strings, each string connecting two different pins, each on a different side of the harp.Emuskald has ordered his apprentice to construct the first ever rectangular harp. However, he didn't mention that no two strings can cross, otherwise it would be impossible to play the harp. Two strings cross if the segments connecting their pins intersect. To fix the harp, Emuskald can perform operations of two types: pick two different columns and swap their pins on each side of the harp, not changing the pins that connect each string; pick two different rows and swap their pins on each side of the harp, not changing the pins that connect each string; In the following example, he can fix the harp by swapping two columns: Help Emuskald complete his creation and find the permutations how the rows and columns of the harp need to be rearranged, or tell that it is impossible to do so. He can detach and reattach each string to its pins, so the physical layout of the strings doesn't matter.", "input_spec": "The first line of input contains two space-separated integers numbers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105), the height and width of the harp in units. Each of the following n\u2009+\u2009m lines contains 4 space-separated tokens, describing a single string: two symbols ai, bi and two integer numbers pi, qi. The pair ai, pi describes the first pin, and the pair bi, qi describes the second pin of the string; A pair s, x describes the position of a single pin in a following way: s is equal to one of the symbols \"L\", \"T\", \"R\" or \"B\" (without quotes), which means that the pin is positioned on the left, top, right or bottom side of the harp accordingly; x is equal to the number of the row, if the pin is on the left or right border of the harp, and to the number of the column, if the pin is on the top or bottom border of the harp. It is guaranteed that no two different strings are connected to the same pin.", "output_spec": "If it is possible to rearrange the rows and columns to fix the harp, on the first line output n space-separated integers \u2014 the old numbers of rows now placed from top to bottom in the fixed harp. On the second line, output m space-separated integers \u2014 the old numbers of columns now placed from left to right in the fixed harp. If it is impossible to rearrange the rows and columns to fix the harp, output \"No solution\" (without quotes).", "sample_inputs": ["3 4\nL T 1 3\nL B 2 2\nL B 3 3\nT R 1 2\nT B 2 1\nT R 4 1\nB R 4 3", "3 3\nL T 1 1\nT R 3 1\nR B 3 3\nB L 1 3\nL R 2 2\nT B 2 2"], "sample_outputs": ["1 2 3 \n3 2 1 4", "No solution"], "notes": null}, "src_uid": "2ecce827acf880fd6b7692a4a3dffdf5"} {"nl": {"description": "Arkady the air traffic controller is now working with n planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The i-th plane, small enough to be represented by a point, currently has a coordinate of xi and is moving with speed vi. It's guaranteed that xi\u00b7vi\u2009<\u20090, i.e., all planes are moving towards the station.Occasionally, the planes are affected by winds. With a wind of speed vwind (not necessarily positive or integral), the speed of the i-th plane becomes vi\u2009+\u2009vwind.According to weather report, the current wind has a steady speed falling inside the range [\u2009-\u2009w,\u2009w] (inclusive), but the exact value cannot be measured accurately since this value is rather small \u2014 smaller than the absolute value of speed of any plane.Each plane should contact Arkady at the exact moment it passes above his station. And you are to help Arkady count the number of pairs of planes (i,\u2009j) (i\u2009<\u2009j) there are such that there is a possible value of wind speed, under which planes i and j contact Arkady at the same moment. This value needn't be the same across different pairs.The wind speed is the same for all planes. You may assume that the wind has a steady speed and lasts arbitrarily long.", "input_spec": "The first line contains two integers n and w (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000, 0\u2009\u2264\u2009w\u2009<\u2009105)\u00a0\u2014 the number of planes and the maximum wind speed. The i-th of the next n lines contains two integers xi and vi (1\u2009\u2264\u2009|xi|\u2009\u2264\u2009105, w\u2009+\u20091\u2009\u2264\u2009|vi|\u2009\u2264\u2009105, xi\u00b7vi\u2009<\u20090)\u00a0\u2014 the initial position and speed of the i-th plane. Planes are pairwise distinct, that is, no pair of (i,\u2009j) (i\u2009<\u2009j) exists such that both xi\u2009=\u2009xj and vi\u2009=\u2009vj.", "output_spec": "Output a single integer\u00a0\u2014 the number of unordered pairs of planes that can contact Arkady at the same moment.", "sample_inputs": ["5 1\n-3 2\n-3 3\n-1 2\n1 -3\n3 -5", "6 1\n-3 2\n-2 2\n-1 2\n1 -2\n2 -2\n3 -2"], "sample_outputs": ["3", "9"], "notes": "NoteIn the first example, the following 3 pairs of planes satisfy the requirements: (2,\u20095) passes the station at time 3\u2009/\u20094 with vwind\u2009=\u20091; (3,\u20094) passes the station at time 2\u2009/\u20095 with vwind\u2009=\u20091\u2009/\u20092; (3,\u20095) passes the station at time 4\u2009/\u20097 with vwind\u2009=\u2009\u2009-\u20091\u2009/\u20094. In the second example, each of the 3 planes with negative coordinates can form a valid pair with each of the other 3, totaling 9 pairs."}, "src_uid": "d073d41f7e184e9bc4a12219d86e7184"} {"nl": {"description": "Little girl Masha likes winter sports, today she's planning to take part in slalom skiing.The track is represented as a grid composed of n\u2009\u00d7\u2009m squares. There are rectangular obstacles at the track, composed of grid squares. Masha must get from the square (1,\u20091) to the square (n,\u2009m). She can move from a square to adjacent square: either to the right, or upwards. If the square is occupied by an obstacle, it is not allowed to move to that square.One can see that each obstacle can actually be passed in two ways: either it is to the right of Masha's path, or to the left. Masha likes to try all ways to do things, so she would like to know how many ways are there to pass the track. Two ways are considered different if there is an obstacle such that it is to the right of the path in one way, and to the left of the path in the other way.Help Masha to find the number of ways to pass the track. The number of ways can be quite big, so Masha would like to know it modulo 109\u2009+\u20097.The pictures below show different ways to pass the track in sample tests. ", "input_spec": "The first line of input data contains three positive integers: n, m and k (3\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009106, 0\u2009\u2264\u2009k\u2009\u2264\u2009105)\u00a0\u2014 the size of the track and the number of obstacles. The following k lines contain four positive integers each: x1, y1, x2, y2 (1\u2009\u2264\u2009x1\u2009\u2264\u2009x2\u2009\u2264\u2009n, 1\u2009\u2264\u2009y1\u2009\u2264\u2009y2\u2009\u2264\u2009m)\u00a0\u2014 coordinates of bottom left, and top right squares of the obstacle. It is guaranteed that there are no obstacles at squares (1,\u20091) and (n,\u2009m), and no obstacles overlap (but some of them may touch).", "output_spec": "Output one integer\u00a0\u2014 the number of ways to pass the track modulo 109\u2009+\u20097.", "sample_inputs": ["3 3 0", "4 5 1\n2 2 3 4", "5 5 3\n2 2 2 3\n4 2 5 2\n4 4 4 4"], "sample_outputs": ["1", "2", "3"], "notes": null}, "src_uid": "294ee0db72d759792d797b6259a83406"} {"nl": {"description": "When Igor K. was a freshman, his professor strictly urged him, as well as all other freshmen, to solve programming Olympiads. One day a problem called \"Flags\" from a website called Timmy's Online Judge caught his attention. In the problem one had to find the number of three-colored flags that would satisfy the condition... actually, it doesn't matter. Igor K. quickly found the formula and got the so passionately desired Accepted.However, the professor wasn't very much impressed. He decided that the problem represented on Timmy's Online Judge was very dull and simple: it only had three possible colors of flag stripes and only two limitations. He suggested a complicated task to Igor K. and the fellow failed to solve it. Of course, we won't tell anybody that the professor couldn't solve it as well.And how about you? Can you solve the problem?The flags consist of one or several parallel stripes of similar width. The stripes can be one of the following colors: white, black, red or yellow. You should find the number of different flags with the number of stripes from L to R, if: a flag cannot have adjacent stripes of one color; a flag cannot have adjacent white and yellow stripes; a flag cannot have adjacent red and black stripes; a flag cannot have the combination of black, white and red stripes following one after another in this or reverse order; symmetrical flags (as, for example, a WB and a BW flag, where W and B stand for the white and black colors) are considered the same. ", "input_spec": "The only line contains two integers L and R (1\u2009\u2264\u2009L\u2009\u2264\u2009R\u2009\u2264\u2009109). They are the lower and upper borders of the number of stripes on the flag.", "output_spec": "Print a single number \u2014 the number of different flags that would satisfy the condition of the problem and would have from L to R stripes, modulo 1000000007.", "sample_inputs": ["3 4", "5 6"], "sample_outputs": ["23", "64"], "notes": "NoteIn the first test the following flags exist (they are listed in the lexicographical order, the letters B, R, W, Y stand for Black, Red, White and Yellow correspondingly):3 stripes: BWB, BYB, BYR, RWR, RYR, WBW, WBY, WRW, WRY, YBY, YRY (overall 11 flags).4 stripes: BWBW, BWBY, BYBW, BYBY, BYRW, BYRY, RWRW, RWRY, RYBW, RYBY, RYRW, RYRY (12 flags).That's why the answer to test 1 is equal to 11\u2009+\u200912\u2009=\u200923."}, "src_uid": "e04b6957d9c1659e9d2460410cb57f10"} {"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": "Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into n consecutive segments, each segment needs to be painted in one of the colours.Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.", "input_spec": "The first line contains a single positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the length of the canvas. The second line contains a string s of n characters, the i-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).", "output_spec": "If there are at least two different ways of painting, output \"Yes\"; otherwise output \"No\" (both without quotes). You can print each character in any case (upper or lower).", "sample_inputs": ["5\nCY??Y", "5\nC?C?Y", "5\n?CYC?", "5\nC??MM", "3\nMMY"], "sample_outputs": ["Yes", "Yes", "Yes", "No", "No"], "notes": "NoteFor the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example."}, "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"nl": {"description": "Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: multiply the current number by 2 (that is, replace the number x by 2\u00b7x); append the digit 1 to the right of current number (that is, replace the number x by 10\u00b7x\u2009+\u20091). You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.", "input_spec": "The first line contains two positive integers a and b (1\u2009\u2264\u2009a\u2009<\u2009b\u2009\u2264\u2009109)\u00a0\u2014 the number which Vasily has and the number he wants to have.", "output_spec": "If there is no way to get b from a, print \"NO\" (without quotes). Otherwise print three lines. On the first line print \"YES\" (without quotes). The second line should contain single integer k\u00a0\u2014 the length of the transformation sequence. On the third line print the sequence of transformations x1,\u2009x2,\u2009...,\u2009xk, where: x1 should be equal to a, xk should be equal to b, xi should be obtained from xi\u2009-\u20091 using any of two described operations (1\u2009<\u2009i\u2009\u2264\u2009k). If there are multiple answers, print any of them.", "sample_inputs": ["2 162", "4 42", "100 40021"], "sample_outputs": ["YES\n5\n2 4 8 81 162", "NO", "YES\n5\n100 200 2001 4002 40021"], "notes": null}, "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"nl": {"description": "You've got an n\u2009\u00d7\u2009n\u2009\u00d7\u2009n cube, split into unit cubes. Your task is to number all unit cubes in this cube with positive integers from 1 to n3 so that: each number was used as a cube's number exactly once; for each 1\u2009\u2264\u2009i\u2009<\u2009n3, unit cubes with numbers i and i\u2009+\u20091 were neighbouring (that is, shared a side); for each 1\u2009\u2264\u2009i\u2009<\u2009n there were at least two different subcubes with sizes i\u2009\u00d7\u2009i\u2009\u00d7\u2009i, made from unit cubes, which are numbered with consecutive numbers. That is, there are such two numbers x and y, that the unit cubes of the first subcube are numbered by numbers x, x\u2009+\u20091, ..., x\u2009+\u2009i3\u2009-\u20091, and the unit cubes of the second subcube are numbered by numbers y, y\u2009+\u20091, ..., y\u2009+\u2009i3\u2009-\u20091. Find and print the required numeration of unit cubes of the cube.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the size of the cube, whose unit cubes need to be numbered.", "output_spec": "Print all layers of the cube as n n\u2009\u00d7\u2009n matrices. Separate them with new lines. Print the layers in the order in which they follow in the cube. See the samples for clarifications. It is guaranteed that there always is a solution that meets the conditions given in the problem statement.", "sample_inputs": ["3"], "sample_outputs": ["1 4 17 \n2 3 18 \n27 26 19 \n\n8 5 16 \n7 6 15 \n24 25 20 \n\n9 12 13 \n10 11 14 \n23 22 21"], "notes": "NoteIn the sample the cubes with sizes 2\u2009\u00d7\u20092\u2009\u00d7\u20092 are numbered with integers 1,\u2009...,\u20098 and 5,\u2009...,\u200912."}, "src_uid": "e652ba0901b39f0d01ac152babc06b88"} {"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": "Numbers k-bonacci (k is integer, k\u2009>\u20091) are a generalization of Fibonacci numbers and are determined as follows: F(k,\u2009n)\u2009=\u20090, for integer n, 1\u2009\u2264\u2009n\u2009<\u2009k; F(k,\u2009k)\u2009=\u20091; F(k,\u2009n)\u2009=\u2009F(k,\u2009n\u2009-\u20091)\u2009+\u2009F(k,\u2009n\u2009-\u20092)\u2009+\u2009...\u2009+\u2009F(k,\u2009n\u2009-\u2009k), for integer n, n\u2009>\u2009k. Note that we determine the k-bonacci numbers, F(k,\u2009n), only for integer values of n and k.You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. ", "input_spec": "The first line contains two integers s and k (1\u2009\u2264\u2009s,\u2009k\u2009\u2264\u2009109;\u00a0k\u2009>\u20091).", "output_spec": "In the first line print an integer m (m\u2009\u2265\u20092) that shows how many numbers are in the found representation. In the second line print m distinct integers a1,\u2009a2,\u2009...,\u2009am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them.", "sample_inputs": ["5 2", "21 5"], "sample_outputs": ["3\n0 2 3", "3\n4 1 16"], "notes": null}, "src_uid": "da793333b977ed179fdba900aa604b52"} {"nl": {"description": "Find the minimum number with the given sum of digits $$$s$$$ such that all digits in it are distinct (i.e. all digits are unique).For example, if $$$s=20$$$, then the answer is $$$389$$$. This is the minimum number in which all digits are different and the sum of the digits is $$$20$$$ ($$$3+8+9=20$$$).For the given $$$s$$$ print the required number.", "input_spec": "The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 45$$$) \u2014 the number of test cases. Each test case is specified by a line that contains the only integer $$$s$$$ ($$$1 \\le s \\le 45$$$).", "output_spec": "Print $$$t$$$ integers \u2014 the answers to the given test cases.", "sample_inputs": ["4\n\n20\n\n8\n\n45\n\n10"], "sample_outputs": ["389\n8\n123456789\n19"], "notes": null}, "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f"} {"nl": {"description": "A monster is attacking the Cyberland!Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).During the battle, every second the monster's HP decrease by max(0,\u2009ATKY\u2009-\u2009DEFM), while Yang's HP decreases by max(0,\u2009ATKM\u2009-\u2009DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP\u2009\u2264\u20090 and the same time Master Yang's HP\u2009>\u20090, Master Yang wins.Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF.Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.", "input_spec": "The first line contains three integers HPY,\u2009ATKY,\u2009DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang. The second line contains three integers HPM,\u2009ATKM,\u2009DEFM, separated by a space, denoting the HP, ATK and DEF of the monster. The third line contains three integers h,\u2009a,\u2009d, separated by a space, denoting the price of 1\u00a0HP, 1\u00a0ATK and 1\u00a0DEF. All numbers in input are integer and lie between 1 and 100 inclusively.", "output_spec": "The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.", "sample_inputs": ["1 2 1\n1 100 1\n1 100 100", "100 100 100\n1 1 1\n1 1 1"], "sample_outputs": ["99", "0"], "notes": "NoteFor the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything."}, "src_uid": "bf8a133154745e64a547de6f31ddc884"} {"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": "Assume that sk(n) equals the sum of digits of number n in the k-based notation. For example, s2(5)\u2009=\u2009s2(1012)\u2009=\u20091\u2009+\u20090\u2009+\u20091\u2009=\u20092, s3(14)\u2009=\u2009s3(1123)\u2009=\u20091\u2009+\u20091\u2009+\u20092\u2009=\u20094.The sequence of integers a0,\u2009...,\u2009an\u2009-\u20091 is defined as . Your task is to calculate the number of distinct subsequences of sequence a0,\u2009...,\u2009an\u2009-\u20091. Calculate the answer modulo 109\u2009+\u20097.Sequence a1,\u2009...,\u2009ak is called to be a subsequence of sequence b1,\u2009...,\u2009bl, if there is a sequence of indices 1\u2009\u2264\u2009i1\u2009<\u2009...\u2009<\u2009ik\u2009\u2264\u2009l, such that a1\u2009=\u2009bi1, ..., ak\u2009=\u2009bik. In particular, an empty sequence (i.e. the sequence consisting of zero elements) is a subsequence of any sequence.", "input_spec": "The first line contains two space-separated numbers n and k (1\u2009\u2264\u2009n\u2009\u2264\u20091018, 2\u2009\u2264\u2009k\u2009\u2264\u200930).", "output_spec": "In a single line print the answer to the problem modulo 109\u2009+\u20097.", "sample_inputs": ["4 2", "7 7"], "sample_outputs": ["11", "128"], "notes": "NoteIn the first sample the sequence ai looks as follows: (0,\u20091,\u20091,\u20090). All the possible subsequences are: (),\u2009(0),\u2009(0,\u20090),\u2009(0,\u20091),\u2009(0,\u20091,\u20090),\u2009(0,\u20091,\u20091),\u2009(0,\u20091,\u20091,\u20090),\u2009(1),\u2009(1,\u20090),\u2009(1,\u20091),\u2009(1,\u20091,\u20090).In the second sample the sequence ai looks as follows: (0,\u20091,\u20092,\u20093,\u20094,\u20095,\u20096). The subsequences of this sequence are exactly all increasing sequences formed from numbers from 0 to 6. It is easy to see that there are 27\u2009=\u2009128 such sequences."}, "src_uid": "175ce134da7cc5af9c8457e7bd9a40a2"} {"nl": {"description": "Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [\u2009-\u2009k;k] (i.e. one integer among \u2009-\u2009k,\u2009\u2009-\u2009k\u2009+\u20091,\u2009\u2009-\u2009k\u2009+\u20092,\u2009...,\u2009\u2009-\u20092,\u2009\u2009-\u20091,\u20090,\u20091,\u20092,\u2009...,\u2009k\u2009-\u20091,\u2009k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k\u2009+\u20091)2t games in total. Since the answer can be very large, you should print it modulo 109\u2009+\u20097. Please solve this problem for Memory.", "input_spec": "The first and only line of input contains the four integers a, b, k, and t (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009100, 1\u2009\u2264\u2009k\u2009\u2264\u20091000, 1\u2009\u2264\u2009t\u2009\u2264\u2009100)\u00a0\u2014 the amount Memory and Lexa start with, the number k, and the number of turns respectively.", "output_spec": "Print the number of possible games satisfying the conditions modulo 1\u2009000\u2009000\u2009007 (109\u2009+\u20097) in one line.", "sample_inputs": ["1 2 2 1", "1 1 1 2", "2 12 3 1"], "sample_outputs": ["6", "31", "0"], "notes": "NoteIn the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks \u2009-\u20092, Memory can pick 0, 1, or 2 to win. If Lexa picks \u2009-\u20091, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3\u2009+\u20092\u2009+\u20091\u2009=\u20096 possible games in which Memory wins."}, "src_uid": "8b8327512a318a5b5afd531ff7223bd0"} {"nl": {"description": "You won't find this sequence on OEIS.", "input_spec": "One integer $$$r$$$ ($$$-45 \\le r \\le 2999$$$).", "output_spec": "One integer.", "sample_inputs": ["2999"], "sample_outputs": ["3000"], "notes": null}, "src_uid": "22725effa6dc68b9c2a499d148e613c2"} {"nl": {"description": "The Bytelandian Institute for Biological Research (BIBR) is investigating the properties of two species of bacteria, named simply 0 and 1. Even under a microscope, bacteria of those two species are very difficult to distinguish. In fact, the only thing the scientists possess that is able to differentiate between them is a plant called Formurosa.If the scientists place a sample of colonies of bacteria on each on Formurosa's leaves, it will activate a complicated nutrition process. During that process color of Formurosa changes to reflect the result of a \u2014 possibly very complicated \u2014 logical formula on the species of bacteria, involving constants and the operators | (OR), & (AND) and ^ (XOR). If it is 0, the plant will turn red, otherwise \u2014 it will turn blue.For example, if the nutrition process of Formurosa is described by the formula: (((?^?)|?)&(1^?)); then Formurosa has four leaves (the \"?\" signs denote the leaves). If we place 0,\u20091,\u20090,\u20090 on the respective leaves, the result of the nutrition process will be (((0^1)|0)&(1^0))\u2009=\u20091, therefore the plant will turn blue.The scientists have n colonies of bacteria. They do not know their types; the only thing they know for sure is that not all colonies are of the same type. They want to attempt to determine the bacteria's species by repeated evaluations with Formurosa. During each evaluation they must place exactly one sample on every leaf of the plant. However, they may use multiple samples of one colony during a single evaluation; they can even cover the whole plant with bacteria from one colony!Is it possible for them to always determine the species of each colony, no matter what they are (assuming they are not all the same)?", "input_spec": "The first line of input contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009106) \u2014 the number of colonies of bacteria. The second line contains the formula describing the nutrition process of Formurosa. This line contains only characters \u00ab0\u00bb, \u00ab1\u00bb, \u00ab?\u00bb, \u00ab|\u00bb, \u00ab&\u00bb, \u00ab^\u00bb, \u00ab(\u00bb, \u00ab)\u00bb and complies with the following grammar: s\u2009\u2192\u20090|1|?|(s|s)|(s&s)|(s^s) The formula consists of no more than 106 characters.", "output_spec": "If it is always possible to determine the species of each colony, output \"YES\" (without quotes). Otherwise, output \"NO\" (without quotes).", "sample_inputs": ["2\n(?^?)", "10\n?", "2\n((?^?)&?)"], "sample_outputs": ["NO", "YES", "YES"], "notes": null}, "src_uid": "e060d26dc3b9ffb628f2380781d1cbe9"} {"nl": {"description": "One Khanate had a lot of roads and very little wood. Riding along the roads was inconvenient, because the roads did not have road signs indicating the direction to important cities.The Han decided that it's time to fix the issue, and ordered to put signs on every road. The Minister of Transport has to do that, but he has only k signs. Help the minister to solve his problem, otherwise the poor guy can lose not only his position, but also his head.More formally, every road in the Khanate is a line on the Oxy plane, given by an equation of the form Ax\u2009+\u2009By\u2009+\u2009C\u2009=\u20090 (A and B are not equal to 0 at the same time). You are required to determine whether you can put signs in at most k points so that each road had at least one sign installed.", "input_spec": "The input starts with two positive integers n, k (1\u2009\u2264\u2009n\u2009\u2264\u2009105,\u20091\u2009\u2264\u2009k\u2009\u2264\u20095) Next n lines contain three integers each, Ai,\u2009Bi,\u2009Ci, the coefficients of the equation that determines the road (|Ai|,\u2009|Bi|,\u2009|Ci|\u2009\u2264\u2009105, Ai2\u2009+\u2009Bi2\u2009\u2260\u20090). It is guaranteed that no two roads coincide.", "output_spec": "If there is no solution, print \"NO\" in the single line (without the quotes). Otherwise, print in the first line \"YES\" (without the quotes). In the second line print a single number m (m\u2009\u2264\u2009k) \u2014 the number of used signs. In the next m lines print the descriptions of their locations. Description of a location of one sign is two integers v,\u2009u. If u and v are two distinct integers between 1 and n, we assume that sign is at the point of intersection of roads number v and u. If u\u2009=\u2009\u2009-\u20091, and v is an integer between 1 and n, then the sign is on the road number v in the point not lying on any other road. In any other case the description of a sign will be assumed invalid and your answer will be considered incorrect. In case if v\u2009=\u2009u, or if v and u are the numbers of two non-intersecting roads, your answer will also be considered incorrect. The roads are numbered starting from 1 in the order in which they follow in the input.", "sample_inputs": ["3 1\n1 0 0\n0 -1 0\n7 -93 0", "3 1\n1 0 0\n0 1 0\n1 1 3", "2 3\n3 4 5\n5 6 7"], "sample_outputs": ["YES\n1\n1 2", "NO", "YES\n2\n1 -1\n2 -1"], "notes": "NoteNote that you do not have to minimize m, but it shouldn't be more than k.In the first test all three roads intersect at point (0,0).In the second test all three roads form a triangle and there is no way to place one sign so that it would stand on all three roads at once."}, "src_uid": "dea5c9eded04f1a900c37571d20b34e2"} {"nl": {"description": "Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000).", "output_spec": "Output the smallest positive integer with exactly n divisors.", "sample_inputs": ["4", "6"], "sample_outputs": ["6", "12"], "notes": null}, "src_uid": "62db589bad3b7023418107de05b7a8ee"} {"nl": {"description": " Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays\u00a0\u2013 caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.", "input_spec": "There are two characters in the first string\u00a0\u2013 the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number n is given (0\u2009\u2264\u2009n\u2009\u2264\u2009109)\u00a0\u2013 the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.", "output_spec": "Output cw, if the direction is clockwise, ccw\u00a0\u2013 if counter-clockwise, and undefined otherwise.", "sample_inputs": ["^ >\n1", "< ^\n3", "^ v\n6"], "sample_outputs": ["cw", "ccw", "undefined"], "notes": null}, "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"nl": {"description": "Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a letter, either 'A', or the letter 'B'. Then they began to remove the cards one by one from left to right, every time they removed a card with the letter 'A', Alice gave Bob all the fruits she had at that moment and took out of the bag as many apples and as many oranges as she had before. Thus the number of oranges and apples Alice had, did not change. If the card had written letter 'B', then Bob did the same, that is, he gave Alice all the fruit that he had, and took from the bag the same set of fruit. After the last card way removed, all the fruit in the bag were over.You know how many oranges and apples was in the bag at first. Your task is to find any sequence of cards that Alice and Bob could have played with.", "input_spec": "The first line of the input contains two integers, x,\u2009y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20091018,\u2009xy\u2009>\u20091) \u2014 the number of oranges and apples that were initially in the bag.", "output_spec": "Print any sequence of cards that would meet the problem conditions as a compressed string of characters 'A' and 'B. That means that you need to replace the segments of identical consecutive characters by the number of repetitions of the characters and the actual character. For example, string AAABAABBB should be replaced by string 3A1B2A3B, but cannot be replaced by 2A1A1B2A3B or by 3AB2A3B. See the samples for clarifications of the output format. The string that you print should consist of at most 106 characters. It is guaranteed that if the answer exists, its compressed representation exists, consisting of at most 106 characters. If there are several possible answers, you are allowed to print any of them. If the sequence of cards that meet the problem statement does not not exist, print a single word Impossible.", "sample_inputs": ["1 4", "2 2", "3 2"], "sample_outputs": ["3B", "Impossible", "1A1B"], "notes": "NoteIn the first sample, if the row contained three cards with letter 'B', then Bob should give one apple to Alice three times. So, in the end of the game Alice has one orange and three apples, and Bob has one apple, in total it is one orange and four apples.In second sample, there is no answer since one card is not enough for game to finish, and two cards will produce at least three apples or three oranges.In the third sample, cards contain letters 'AB', so after removing the first card Bob has one orange and one apple, and after removal of second card Alice has two oranges and one apple. So, in total it is three oranges and two apples."}, "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671"} {"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": "Polycarp is preparing the first programming contest for robots. There are $$$n$$$ problems in it, and a lot of robots are going to participate in it. Each robot solving the problem $$$i$$$ gets $$$p_i$$$ points, and the score of each robot in the competition is calculated as the sum of $$$p_i$$$ over all problems $$$i$$$ solved by it. For each problem, $$$p_i$$$ is an integer not less than $$$1$$$.Two corporations specializing in problem-solving robot manufacturing, \"Robo-Coder Inc.\" and \"BionicSolver Industries\", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results \u2014 or manipulating them. For some reason (which absolutely cannot involve bribing), Polycarp wants the \"Robo-Coder Inc.\" robot to outperform the \"BionicSolver Industries\" robot in the competition. Polycarp wants to set the values of $$$p_i$$$ in such a way that the \"Robo-Coder Inc.\" robot gets strictly more points than the \"BionicSolver Industries\" robot. However, if the values of $$$p_i$$$ will be large, it may look very suspicious \u2014 so Polycarp wants to minimize the maximum value of $$$p_i$$$ over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of problems. The second line contains $$$n$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_n$$$ ($$$0 \\le r_i \\le 1$$$). $$$r_i = 1$$$ means that the \"Robo-Coder Inc.\" robot will solve the $$$i$$$-th problem, $$$r_i = 0$$$ means that it won't solve the $$$i$$$-th problem. The third line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$0 \\le b_i \\le 1$$$). $$$b_i = 1$$$ means that the \"BionicSolver Industries\" robot will solve the $$$i$$$-th problem, $$$b_i = 0$$$ means that it won't solve the $$$i$$$-th problem.", "output_spec": "If \"Robo-Coder Inc.\" robot cannot outperform the \"BionicSolver Industries\" robot by any means, print one integer $$$-1$$$. Otherwise, print the minimum possible value of $$$\\max \\limits_{i = 1}^{n} p_i$$$, if all values of $$$p_i$$$ are set in such a way that the \"Robo-Coder Inc.\" robot gets strictly more points than the \"BionicSolver Industries\" robot.", "sample_inputs": ["5\n1 1 1 0 0\n0 1 1 1 1", "3\n0 0 0\n0 0 0", "4\n1 1 1 1\n1 1 1 1", "8\n1 0 0 0 0 0 0 0\n0 1 1 0 1 1 1 1"], "sample_outputs": ["3", "-1", "-1", "7"], "notes": "NoteIn the first example, one of the valid score assignments is $$$p = [3, 1, 3, 1, 1]$$$. Then the \"Robo-Coder\" gets $$$7$$$ points, the \"BionicSolver\" \u2014 $$$6$$$ points.In the second example, both robots get $$$0$$$ points, and the score distribution does not matter.In the third example, both robots solve all problems, so their points are equal."}, "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07"} {"nl": {"description": "The only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includes $$$n$$$ pictures.When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The $$$i$$$-th picture has a non-negative weight $$$w_i$$$, and the probability of the $$$i$$$-th picture being displayed is $$$\\frac{w_i}{\\sum_{j=1}^nw_j}$$$. That is to say, the probability of a picture to be displayed is proportional to its weight.However, Nauuo discovered that some pictures she does not like were displayed too often. To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add $$$1$$$ to its weight; otherwise, she would subtract $$$1$$$ from its weight.Nauuo will visit the website $$$m$$$ times. She wants to know the expected weight of each picture after all the $$$m$$$ visits modulo $$$998244353$$$. Can you help her?The expected weight of the $$$i$$$-th picture can be denoted by $$$\\frac {q_i} {p_i}$$$ where $$$\\gcd(p_i,q_i)=1$$$, you need to print an integer $$$r_i$$$ satisfying $$$0\\le r_i<998244353$$$ and $$$r_i\\cdot p_i\\equiv q_i\\pmod{998244353}$$$. It can be proved that such $$$r_i$$$ exists and is unique.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\\le n\\le 2\\cdot 10^5$$$, $$$1\\le m\\le 3000$$$) \u2014 the number of pictures and the number of visits to the website. The second line contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$a_i$$$ is either $$$0$$$ or $$$1$$$) \u2014 if $$$a_i=0$$$ , Nauuo does not like the $$$i$$$-th picture; otherwise Nauuo likes the $$$i$$$-th picture. It is guaranteed that there is at least one picture which Nauuo likes. The third line contains $$$n$$$ positive integers $$$w_1,w_2,\\ldots,w_n$$$ ($$$w_i \\geq 1$$$) \u2014 the initial weights of the pictures. It is guaranteed that the sum of all the initial weights does not exceed $$$998244352-m$$$.", "output_spec": "The output contains $$$n$$$ integers $$$r_1,r_2,\\ldots,r_n$$$ \u2014 the expected weights modulo $$$998244353$$$.", "sample_inputs": ["2 1\n0 1\n2 1", "1 2\n1\n1", "3 3\n0 1 1\n4 3 5"], "sample_outputs": ["332748119\n332748119", "3", "160955686\n185138929\n974061117"], "notes": "NoteIn the first example, if the only visit shows the first picture with a probability of $$$\\frac 2 3$$$, the final weights are $$$(1,1)$$$; if the only visit shows the second picture with a probability of $$$\\frac1 3$$$, the final weights are $$$(2,2)$$$.So, both expected weights are $$$\\frac2 3\\cdot 1+\\frac 1 3\\cdot 2=\\frac4 3$$$ .Because $$$332748119\\cdot 3\\equiv 4\\pmod{998244353}$$$, you need to print $$$332748119$$$ instead of $$$\\frac4 3$$$ or $$$1.3333333333$$$.In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, $$$w_1$$$ will be increased by $$$1$$$.So, the expected weight is $$$1+2=3$$$.Nauuo is very naughty so she didn't give you any hint of the third example."}, "src_uid": "ba9c136f84375cd317f0f8b53e3939c7"} {"nl": {"description": "All bus tickets in Berland have their numbers. A number consists of $$$n$$$ digits ($$$n$$$ is even). Only $$$k$$$ decimal digits $$$d_1, d_2, \\dots, d_k$$$ can be used to form ticket numbers. If $$$0$$$ is among these digits, then numbers may have leading zeroes. For example, if $$$n = 4$$$ and only digits $$$0$$$ and $$$4$$$ can be used, then $$$0000$$$, $$$4004$$$, $$$4440$$$ are valid ticket numbers, and $$$0002$$$, $$$00$$$, $$$44443$$$ are not.A ticket is lucky if the sum of first $$$n / 2$$$ digits is equal to the sum of remaining $$$n / 2$$$ digits. Calculate the number of different lucky tickets in Berland. Since the answer may be big, print it modulo $$$998244353$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \\le n \\le 2 \\cdot 10^5, 1 \\le k \\le 10)$$$ \u2014 the number of digits in each ticket number, and the number of different decimal digits that may be used. $$$n$$$ is even. The second line contains a sequence of pairwise distinct integers $$$d_1, d_2, \\dots, d_k$$$ $$$(0 \\le d_i \\le 9)$$$ \u2014 the digits that may be used in ticket numbers. The digits are given in arbitrary order.", "output_spec": "Print the number of lucky ticket numbers, taken modulo $$$998244353$$$.", "sample_inputs": ["4 2\n1 8", "20 1\n6", "10 5\n6 1 4 0 3", "1000 7\n5 4 0 1 8 3 2"], "sample_outputs": ["6", "1", "569725", "460571165"], "notes": "NoteIn the first example there are $$$6$$$ lucky ticket numbers: $$$1111$$$, $$$1818$$$, $$$1881$$$, $$$8118$$$, $$$8181$$$ and $$$8888$$$.There is only one ticket number in the second example, it consists of $$$20$$$ digits $$$6$$$. This ticket number is lucky, so the answer is $$$1$$$."}, "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf"} {"nl": {"description": "Alice and Bob play 5-in-a-row game. They have a playing field of size 10\u2009\u00d7\u200910. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.", "input_spec": "You are given matrix 10\u2009\u00d7\u200910 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won.", "output_spec": "Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.", "sample_inputs": ["XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n.........."], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "d5541028a2753c758322c440bdbf9ec6"} {"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": "Bob is about to take a hot bath. There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can transmit from 0 to x2 water units per second.If y1 water units per second flow through the first tap and y2 water units per second flow through the second tap, then the resulting bath water temperature will be:Bob wants to open both taps so that the bath water temperature was not less than t0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.Determine how much each tap should be opened so that Bob was pleased with the result in the end.", "input_spec": "You are given five integers t1, t2, x1, x2 and t0 (1\u2009\u2264\u2009t1\u2009\u2264\u2009t0\u2009\u2264\u2009t2\u2009\u2264\u2009106, 1\u2009\u2264\u2009x1,\u2009x2\u2009\u2264\u2009106).", "output_spec": "Print two space-separated integers y1 and y2 (0\u2009\u2264\u2009y1\u2009\u2264\u2009x1, 0\u2009\u2264\u2009y2\u2009\u2264\u2009x2).", "sample_inputs": ["10 70 100 100 25", "300 500 1000 1000 300", "143 456 110 117 273"], "sample_outputs": ["99 33", "1000 0", "76 54"], "notes": "NoteIn the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible."}, "src_uid": "87a500829c1935ded3ef6e4e47096b9f"} {"nl": {"description": "In this problem, we will consider complete undirected graphs consisting of $$$n$$$ vertices with weighted edges. The weight of each edge is an integer from $$$1$$$ to $$$k$$$.An undirected graph is considered beautiful if the sum of weights of all edges incident to vertex $$$1$$$ is equal to the weight of MST in the graph. MST is the minimum spanning tree\u00a0\u2014 a tree consisting of $$$n-1$$$ edges of the graph, which connects all $$$n$$$ vertices and has the minimum sum of weights among all such trees; the weight of MST is the sum of weights of all edges in it.Calculate the number of complete beautiful graphs having exactly $$$n$$$ vertices and the weights of edges from $$$1$$$ to $$$k$$$. Since the answer might be large, print it modulo $$$998244353$$$.", "input_spec": "The only line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 250$$$; $$$1 \\le k \\le 250$$$).", "output_spec": "Print one integer\u00a0\u2014 the number of complete beautiful graphs having exactly $$$n$$$ vertices and the weights of edges from $$$1$$$ to $$$k$$$. Since the answer might be large, print it modulo $$$998244353$$$.", "sample_inputs": ["3 2", "4 4", "6 9", "42 13"], "sample_outputs": ["5", "571", "310640163", "136246935"], "notes": null}, "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62"} {"nl": {"description": "The Fat Rat and his friend \u0421erealguy have had a bet whether at least a few oats are going to descend to them by some clever construction. The figure below shows the clever construction. A more formal description of the clever construction is as follows. The clever construction consists of n rows with scales. The first row has n scales, the second row has (n\u2009-\u20091) scales, the i-th row has (n\u2009-\u2009i\u2009+\u20091) scales, the last row has exactly one scale. Let's number the scales in each row from the left to the right, starting from 1. Then the value of wi,\u2009k in kilograms (1\u2009\u2264\u2009i\u2009\u2264\u2009n;\u00a01\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009-\u2009i\u2009+\u20091) is the weight capacity parameter of the k-th scale in the i-th row. If a body whose mass is not less than wi,\u2009k falls on the scale with weight capacity wi,\u2009k, then the scale breaks. At that anything that the scale has on it, either falls one level down to the left (if possible) or one level down to the right (if possible). In other words, if the scale wi,\u2009k (i\u2009<\u2009n) breaks, then there are at most two possible variants in which the contents of the scale's pan can fall out: all contents of scale wi,\u2009k falls either on scale wi\u2009+\u20091,\u2009k\u2009-\u20091 (if it exists), or on scale wi\u2009+\u20091,\u2009k (if it exists). If scale wn,\u20091 breaks, then all its contents falls right in the Fat Rat's claws. Please note that the scales that are the first and the last in a row, have only one variant of dropping the contents.Initially, oats are simultaneously put on all scales of the first level. The i-th scale has ai kilograms of oats put on it. After that the scales start breaking and the oats start falling down in some way. You can consider everything to happen instantly. That is, the scale breaks instantly and the oats also fall instantly.The Fat Rat is sure that whatever happens, he will not get the oats from the first level. Cerealguy is sure that there is such a scenario, when the rat gets at least some number of the oats. Help the Fat Rat and the Cerealguy. Determine, which one is right.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the number of rows with scales. The next line contains n space-separated integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009106) \u2014 the masses of the oats in kilograms. The next n lines contain descriptions of the scales: the i-th line contains (n\u2009-\u2009i\u2009+\u20091) space-separated integers wi,\u2009k (1\u2009\u2264\u2009wi,\u2009k\u2009\u2264\u2009106) \u2014 the weight capacity parameters for the scales that stand on the i-th row, in kilograms.", "output_spec": "Print \"Fat Rat\" if the Fat Rat is right, otherwise print \"Cerealguy\".", "sample_inputs": ["1\n1\n2", "2\n2 2\n1 2\n4", "2\n2 2\n1 2\n5"], "sample_outputs": ["Fat Rat", "Cerealguy", "Fat Rat"], "notes": "NoteNotes to the examples: The first example: the scale with weight capacity 2 gets 1. That means that the lower scale don't break. The second sample: all scales in the top row obviously break. Then the oats fall on the lower row. Their total mass is 4,and that's exactly the weight that the lower scale can \"nearly endure\". So, as 4 \u2009\u2265\u2009 4, the scale breaks."}, "src_uid": "0a77937c01ac69490f8b478eae77de1d"} {"nl": {"description": "Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, \"noon\", \"testset\" and \"a\" are all palindromes, while \"test\" and \"kitayuta\" are not.You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print \"NA\" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.", "input_spec": "The only line of the input contains a string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200910). Each character in s is a lowercase English letter.", "output_spec": "If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print \"NA\" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. ", "sample_inputs": ["revive", "ee", "kitayuta"], "sample_outputs": ["reviver", "eye", "NA"], "notes": "NoteFor the first sample, insert 'r' to the end of \"revive\" to obtain a palindrome \"reviver\".For the second sample, there is more than one solution. For example, \"eve\" will also be accepted.For the third sample, it is not possible to turn \"kitayuta\" into a palindrome by just inserting one letter."}, "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b"} {"nl": {"description": "Berland.Taxi is a new taxi company with k cars which started operating in the capital of Berland just recently. The capital has n houses on a straight line numbered from 1 (leftmost) to n (rightmost), and the distance between any two neighboring houses is the same.You have to help the company schedule all the taxi rides which come throughout the day according to the following rules: All cars are available for picking up passengers. Initially the j-th car is located next to the house with the number xj at time 0. All cars have the same speed. It takes exactly 1 minute for any car to travel between neighboring houses i and i\u2009+\u20091. The i-th request for taxi ride comes at the time ti, asking for a passenger to be picked up at the house ai and dropped off at the house bi. All requests for taxi rides are given in the increasing order of ti. All ti are distinct. When a request for taxi ride is received at time ti, Berland.Taxi operator assigns a car to it as follows: Out of cars which are currently available, operator assigns the car which is the closest to the pick up spot ai. Needless to say, if a car is already on a ride with a passenger, it won't be available for any rides until that passenger is dropped off at the corresponding destination. If there are several such cars, operator will pick one of them which has been waiting the most since it became available. If there are several such cars, operator will pick one of them which has the lowest number. After a car gets assigned to the taxi ride request: The driver immediately starts driving from current position to the house ai. Once the car reaches house ai, the passenger is immediately picked up and the driver starts driving to house bi. Once house bi is reached, the passenger gets dropped off and the car becomes available for new rides staying next to the house bi. It is allowed for multiple cars to be located next to the same house at the same point in time, while waiting for ride requests or just passing by. If there are no available cars at time ti when a request for taxi ride comes, then: The i-th passenger will have to wait for a car to become available. When a car becomes available, operator will immediately assign it to this taxi ride request. If multiple cars become available at once while the passenger is waiting, operator will pick a car out of them according to the rules described above. Operator processes taxi ride requests one by one. So if multiple passengers are waiting for the cars to become available, operator will not move on to processing the (i\u2009+\u20091)-th ride request until the car gets assigned to the i-th ride request.Your task is to write a program that will process the given list of m taxi ride requests. For each request you have to find out which car will get assigned to it, and how long the passenger will have to wait for a car to arrive. Note, if there is already car located at the house ai, then the corresponding wait time will be 0.", "input_spec": "The first line of input contains integers n, k and m (2\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009k,\u2009m\u2009\u2264\u20092\u00b7105) \u2014 number of houses, number of cars, and number of taxi ride requests. The second line contains integers x1,\u2009x2,\u2009...,\u2009xk (1\u2009\u2264\u2009xi\u2009\u2264\u2009n) \u2014 initial positions of cars. xi is a house number at which the i-th car is located initially. It's allowed for more than one car to be located next to the same house. The following m lines contain information about ride requests. Each ride request is represented by integers tj, aj and bj (1\u2009\u2264\u2009tj\u2009\u2264\u20091012, 1\u2009\u2264\u2009aj,\u2009bj\u2009\u2264\u2009n, aj\u2009\u2260\u2009bj), where tj is time in minutes when a request is made, aj is a house where passenger needs to be picked up, and bj is a house where passenger needs to be dropped off. All taxi ride requests are given in the increasing order of tj. All tj are distinct.", "output_spec": "Print m lines: the j-th line should contain two integer numbers, the answer for the j-th ride request \u2014 car number assigned by the operator and passenger wait time.", "sample_inputs": ["10 1 2\n3\n5 2 8\n9 10 3", "5 2 1\n1 5\n10 3 5", "5 2 2\n1 5\n10 3 5\n20 4 1"], "sample_outputs": ["1 1\n1 5", "1 2", "1 2\n2 1"], "notes": "NoteIn the first sample test, a request comes in at time 5 and the car needs to get from house 3 to house 2 to pick up the passenger. Therefore wait time will be 1 and the ride will be completed at time 5\u2009+\u20091\u2009+\u20096\u2009=\u200912. The second request comes in at time 9, so the passenger will have to wait for the car to become available at time 12, and then the car needs another 2 minutes to get from house 8 to house 10. So the total wait time is 3\u2009+\u20092\u2009=\u20095. In the second sample test, cars 1 and 2 are located at the same distance from the first passenger and have the same \"wait time since it became available\". Car 1 wins a tiebreaker according to the rules because it has the lowest number. It will come to house 3 at time 3, so the wait time will be 2."}, "src_uid": "cbfed699fd3d4eacfe36e1c064a4448c"} {"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": "You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly $$$k\\ \\%$$$ magic essence and $$$(100 - k)\\ \\%$$$ water.In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.A small reminder: if you pour $$$e$$$ liters of essence and $$$w$$$ liters of water ($$$e + w > 0$$$) into the cauldron, then it contains $$$\\frac{e}{e + w} \\cdot 100\\ \\%$$$ (without rounding) magic essence and $$$\\frac{w}{e + w} \\cdot 100\\ \\%$$$ water.", "input_spec": "The first line contains the single $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases. The first and only line of each test case contains a single integer $$$k$$$ ($$$1 \\le k \\le 100$$$)\u00a0\u2014 the percentage of essence in a good potion.", "output_spec": "For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.", "sample_inputs": ["3\n3\n100\n25"], "sample_outputs": ["100\n1\n4"], "notes": "NoteIn the first test case, you should pour $$$3$$$ liters of magic essence and $$$97$$$ liters of water into the cauldron to get a potion with $$$3\\ \\%$$$ of magic essence.In the second test case, you can pour only $$$1$$$ liter of essence to get a potion with $$$100\\ \\%$$$ of magic essence.In the third test case, you can pour $$$1$$$ liter of magic essence and $$$3$$$ liters of water."}, "src_uid": "19a2bcb727510c729efe442a13c2ff7c"} {"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.One day Petya came across an interval of numbers [a,\u2009a\u2009+\u2009l\u2009-\u20091]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a\u2009<\u2009b) such, that F(a) = F(b), F(a\u2009+\u20091) = F(b\u2009+\u20091), ..., F(a\u2009+\u2009l\u2009-\u20091) = F(b\u2009+\u2009l\u2009-\u20091).", "input_spec": "The single line contains two integers a and l (1\u2009\u2264\u2009a,\u2009l\u2009\u2264\u2009109) \u2014 the interval's first number and the interval's length correspondingly.", "output_spec": "On the single line print number b \u2014 the answer to the problem.", "sample_inputs": ["7 4", "4 7"], "sample_outputs": ["17", "14"], "notes": "NoteConsider that [a,\u2009b] denotes an interval of integers; this interval includes the boundaries. That is, "}, "src_uid": "649e9f477b97c1f72b05d409b4a99d59"} {"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": "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": "Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are \"a\", \"o\", \"u\", \"i\", and \"e\". Other letters are consonant.In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant \"n\"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words \"harakiri\", \"yupie\", \"man\", and \"nbo\" are Berlanese while the words \"horse\", \"king\", \"my\", and \"nz\" are not.Help Vitya find out if a word $$$s$$$ is Berlanese.", "input_spec": "The first line of the input contains the string $$$s$$$ consisting of $$$|s|$$$ ($$$1\\leq |s|\\leq 100$$$) lowercase Latin letters.", "output_spec": "Print \"YES\" (without quotes) if there is a vowel after every consonant except \"n\", otherwise print \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["sumimasen", "ninja", "codeforces"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteIn the first and second samples, a vowel goes after each consonant except \"n\", so the word is Berlanese.In the third sample, the consonant \"c\" goes after the consonant \"r\", and the consonant \"s\" stands on the end, so the word is not Berlanese."}, "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"} {"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": "This is a harder version of the problem. In this version, $$$n \\le 7$$$.Marek is working hard on creating strong test cases to his new algorithmic problem. Do you want to know what it is? Nah, we're not telling you. However, we can tell you how he generates test cases.Marek chooses an integer $$$n$$$ and $$$n^2$$$ integers $$$p_{ij}$$$ ($$$1 \\le i \\le n$$$, $$$1 \\le j \\le n$$$). He then generates a random bipartite graph with $$$2n$$$ vertices. There are $$$n$$$ vertices on the left side: $$$\\ell_1, \\ell_2, \\dots, \\ell_n$$$, and $$$n$$$ vertices on the right side: $$$r_1, r_2, \\dots, r_n$$$. For each $$$i$$$ and $$$j$$$, he puts an edge between vertices $$$\\ell_i$$$ and $$$r_j$$$ with probability $$$p_{ij}$$$ percent.It turns out that the tests will be strong only if a perfect matching exists in the generated graph. What is the probability that this will occur?It can be shown that this value can be represented as $$$\\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \\not\\equiv 0 \\pmod{10^9+7}$$$. Let $$$Q^{-1}$$$ be an integer for which $$$Q \\cdot Q^{-1} \\equiv 1 \\pmod{10^9+7}$$$. Print the value of $$$P \\cdot Q^{-1}$$$ modulo $$$10^9+7$$$.", "input_spec": "The first line of the input contains a single integer $$$n$$$ ($$$\\mathbf{1 \\le n \\le 7}$$$). The following $$$n$$$ lines describe the probabilities of each edge appearing in the graph. The $$$i$$$-th of the lines contains $$$n$$$ integers $$$p_{i1}, p_{i2}, \\dots, p_{in}$$$ ($$$0 \\le p_{ij} \\le 100$$$); $$$p_{ij}$$$ denotes the probability, in percent, of an edge appearing between $$$\\ell_i$$$ and $$$r_j$$$.", "output_spec": "Print a single integer \u2014 the probability that the perfect matching exists in the bipartite graph, written as $$$P \\cdot Q^{-1} \\pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.", "sample_inputs": ["2\n50 50\n50 50", "3\n3 1 4\n1 5 9\n2 6 5"], "sample_outputs": ["937500007", "351284554"], "notes": "NoteIn the first sample test, each of the $$$16$$$ graphs below is equally probable. Out of these, $$$7$$$ have a perfect matching: Therefore, the probability is equal to $$$\\frac{7}{16}$$$. As $$$16 \\cdot 562\\,500\\,004 = 1 \\pmod{10^9+7}$$$, the answer to the testcase is $$$7 \\cdot 562\\,500\\,004 \\mod{(10^9+7)} = 937\\,500\\,007$$$."}, "src_uid": "ccfa3251dbf956761609f1e5ed771e58"} {"nl": {"description": "You are given n distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing.You consider several coinciding straight lines as a single one. How many distinct pictures you can get? Print the answer modulo 109\u2009+\u20097.", "input_spec": "The first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105)\u00a0\u2014 the number of points. n lines follow. The (i\u2009+\u20091)-th of these lines contains two integers xi, yi (\u2009-\u2009109\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009109)\u00a0\u2014 coordinates of the i-th point. It is guaranteed that all points are distinct.", "output_spec": "Print the number of possible distinct pictures modulo 109\u2009+\u20097.", "sample_inputs": ["4\n1 1\n1 2\n2 1\n2 2", "2\n-1 -1\n0 1"], "sample_outputs": ["16", "9"], "notes": "NoteIn the first example there are two vertical and two horizontal lines passing through the points. You can get pictures with any subset of these lines. For example, you can get the picture containing all four lines in two ways (each segment represents a line containing it). The first way: The second way: In the second example you can work with two points independently. The number of pictures is 32\u2009=\u20099."}, "src_uid": "8781003d9eea51a509145bc6db8b609c"} {"nl": {"description": "Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of n, containing only integers from 1 to n. He is not good at math, that's why some simple things drive him crazy. For example, yesterday he grew keen on counting how many different beautiful arrays there are. Chris thinks that an array is beautiful if it meets one of the two conditions: each elements, starting from the second one, is no more than the preceding one each element, starting from the second one, is no less than the preceding one Having got absolutely mad at himself and at math, Chris came to Stewie and Brian to ask them for help. However, they only laughed at him and said that the answer is too simple and not interesting. Help Chris the Rabbit to find the answer at last.", "input_spec": "The single line contains an integer n which is the size of the array (1\u2009\u2264\u2009n\u2009\u2264\u2009105).", "output_spec": "You must print the answer on a single line. As it can be rather long, you should print it modulo 1000000007.", "sample_inputs": ["2", "3"], "sample_outputs": ["4", "17"], "notes": null}, "src_uid": "13a9ffe5acaa79d97df88a069fc520b9"} {"nl": {"description": "Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?", "input_spec": "The first line contains integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting.", "output_spec": "In the first line, print a single integer \u2014 the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.", "sample_inputs": ["4\nxxXx", "2\nXX", "6\nxXXxXx"], "sample_outputs": ["1\nXxXx", "1\nxX", "0\nxXXxXx"], "notes": null}, "src_uid": "fa6311c72d90d8363d97854b903f849d"} {"nl": {"description": "Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for n plates.", "input_spec": "The first line contains three integers n, R and r (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 1\u2009\u2264\u2009r,\u2009R\u2009\u2264\u20091000) \u2014 the number of plates, the radius of the table and the plates' radius.", "output_spec": "Print \"YES\" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print \"NO\". Remember, that each plate must touch the edge of the table. ", "sample_inputs": ["4 10 4", "5 10 4", "1 10 10"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteThe possible arrangement of the plates for the first sample is: "}, "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"} {"nl": {"description": "Yasin has an array a containing n integers. Yasin is a 5 year old, so he loves ultimate weird things.Yasin denotes weirdness of an array as maximum gcd(ai,\u2009\u2009aj) value among all 1\u2009\u2264\u2009i\u2009<\u2009j\u2009\u2264\u2009n. For n\u2009\u2264\u20091 weirdness is equal to 0, gcd(x,\u2009\u2009y) is the greatest common divisor of integers x and y.He also defines the ultimate weirdness of an array. Ultimate weirdness is where f(i,\u2009\u2009j) is weirdness of the new array a obtained by removing all elements between i and j inclusive, so new array is [a1... ai\u2009-\u20091,\u2009aj\u2009+\u20091... an].Since 5 year old boys can't code, Yasin asks for your help to find the value of ultimate weirdness of the given array a!", "input_spec": "The first line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000)\u00a0\u2014 the number of elements in a. The next line contains n integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009200\u2009000), where the i-th number is equal to the i-th element of the array a. It is guaranteed that all ai are distinct.", "output_spec": "Print a single line containing the value of ultimate weirdness of the array a. ", "sample_inputs": ["3\n2 6 3"], "sample_outputs": ["6"], "notes": "NoteConsider the first sample. f(1,\u2009\u20091) is equal to 3. f(2,\u2009\u20092) is equal to 1. f(3,\u2009\u20093) is equal to 2. f(1,\u2009\u20092), f(1,\u2009\u20093) and f(2,\u2009\u20093) are equal to 0. Thus the answer is 3\u2009+\u20090\u2009+\u20090\u2009+\u20091\u2009+\u20090\u2009+\u20092\u2009=\u20096."}, "src_uid": "deb3938a6d3f13c4ab8a0765bf0e94b0"} {"nl": {"description": "Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams. So the professor began: \"Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has al fingers on her left hand and ar fingers on the right one. The boy correspondingly has bl and br fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable.\"The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa.", "input_spec": "The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.", "output_spec": "Print YES or NO, that is, the answer to Petr Palych's question.", "sample_inputs": ["5 1\n10 5", "4 5\n3 3", "1 2\n11 6"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteThe boy and the girl don't really care who goes to the left."}, "src_uid": "36b7478e162be6e985613b2dad0974dd"} {"nl": {"description": "\u0415\u0441\u0442\u044c n-\u043f\u043e\u0434\u044a\u0435\u0437\u0434\u043d\u044b\u0439 \u0434\u043e\u043c, \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 \u043f\u043e m \u044d\u0442\u0430\u0436\u0435\u0439, \u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u044d\u0442\u0430\u0436\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u0440\u043e\u0432\u043d\u043e k \u043a\u0432\u0430\u0440\u0442\u0438\u0440. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u0434\u043e\u043c\u0435 \u0432\u0441\u0435\u0433\u043e n\u00b7m\u00b7k \u043a\u0432\u0430\u0440\u0442\u0438\u0440. \u041e\u043d\u0438 \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u044b \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u0442 1 \u0434\u043e n\u00b7m\u00b7k, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u0436\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 1, \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0430 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u044d\u0442\u0430\u0436\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 k\u2009+\u20091 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043a\u0440\u0443\u0433\u043b\u044b\u0439. \u0422\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0435, \u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u043d\u043e\u043c\u0435\u0440 1 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u0434\u044a\u0435\u0437\u0434 \u043d\u043e\u043c\u0435\u0440 2, \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u0434\u044a\u0435\u0437\u0434 \u043d\u043e\u043c\u0435\u0440 3 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435 \u0434\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u043d\u043e\u043c\u0435\u0440 n. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u043d\u043e\u043c\u0435\u0440 n \u0441\u043d\u043e\u0432\u0430 \u0438\u0434\u0451\u0442 \u043f\u043e\u0434\u044a\u0435\u0437\u0434 \u043d\u043e\u043c\u0435\u0440 1.\u042d\u0434\u0432\u0430\u0440\u0434 \u0436\u0438\u0432\u0451\u0442 \u0432 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0435 \u043d\u043e\u043c\u0435\u0440 a, \u0430 \u041d\u0430\u0442\u0430\u0448\u0430\u00a0\u2014 \u0432 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0435 \u043d\u043e\u043c\u0435\u0440 b. \u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 1 \u044d\u0442\u0430\u0436 \u0432\u0432\u0435\u0440\u0445 \u0438\u043b\u0438 \u0432\u043d\u0438\u0437 \u043f\u043e \u043b\u0435\u0441\u0442\u043d\u0438\u0446\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 5 \u0441\u0435\u043a\u0443\u043d\u0434, \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043e\u0442 \u0434\u0432\u0435\u0440\u0438 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u043a \u0434\u0432\u0435\u0440\u0438 \u0441\u043e\u0441\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430\u00a0\u2014 15 \u0441\u0435\u043a\u0443\u043d\u0434, \u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u0442\u0430\u0436\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e. \u0422\u0430\u043a\u0436\u0435 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 \u0434\u043e\u043c\u0430 \u0435\u0441\u0442\u044c \u043b\u0438\u0444\u0442. \u041e\u043d \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u043e\u043d \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0435\u0437\u0436\u0430\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0447\u0435\u0440\u0435\u0437 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430, \u0430 \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430 \u043d\u0430 \u043e\u0434\u0438\u043d \u044d\u0442\u0430\u0436 \u0432\u0432\u0435\u0440\u0445 \u0438\u043b\u0438 \u0432\u043d\u0438\u0437, \u043b\u0438\u0444\u0442 \u0442\u0440\u0430\u0442\u0438\u0442 \u0440\u043e\u0432\u043d\u043e 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443. \u041f\u043e\u0441\u0430\u0434\u043a\u0430 \u0438 \u0432\u044b\u0441\u0430\u0434\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e.\u041f\u043e\u043c\u043e\u0433\u0438\u0442\u0435 \u042d\u0434\u0432\u0430\u0440\u0434\u0443 \u043d\u0430\u0439\u0442\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u044b \u041d\u0430\u0442\u0430\u0448\u0438. \u0421\u0447\u0438\u0442\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u042d\u0434\u0432\u0430\u0440\u0434 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0439\u0442\u0438 \u0438\u0437 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u044d\u0442\u0430\u0436\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 (\u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e). \u0415\u0441\u043b\u0438 \u042d\u0434\u0432\u0430\u0440\u0434 \u0441\u0442\u043e\u0438\u0442 \u043f\u0435\u0440\u0435\u0434 \u0434\u0432\u0435\u0440\u044c\u044e \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0439\u0442\u0438 \u0432 \u043d\u0435\u0433\u043e \u0438 \u0441\u0440\u0430\u0437\u0443 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u0436\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 (\u044d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e). \u042d\u0434\u0432\u0430\u0440\u0434 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0438\u0434\u0442\u0438 \u0432\u043e\u043a\u0440\u0443\u0433 \u0434\u043e\u043c\u0430.", "input_spec": "\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0442\u0440\u0438 \u0447\u0438\u0441\u043b\u0430 n, m, k (1\u2009\u2264\u2009n,\u2009m,\u2009k\u2009\u2264\u20091000)\u00a0\u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u043e\u0432 \u0432 \u0434\u043e\u043c\u0435, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u0430\u0436\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0432\u0430\u0440\u0442\u0438\u0440 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u044d\u0442\u0430\u0436\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430 a \u0438 b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009n\u00b7m\u00b7k)\u00a0\u2014 \u043d\u043e\u043c\u0435\u0440\u0430 \u043a\u0432\u0430\u0440\u0442\u0438\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0436\u0438\u0432\u0443\u0442 \u042d\u0434\u0432\u0430\u0440\u0434 \u0438 \u041d\u0430\u0442\u0430\u0448\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u0438 \u043d\u043e\u043c\u0435\u0440\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b. ", "output_spec": "\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\u00a0\u2014 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f (\u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445), \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u042d\u0434\u0432\u0430\u0440\u0434 \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u0432\u043e\u0435\u0439 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u044b \u0434\u043e \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u044b \u041d\u0430\u0442\u0430\u0448\u0438.", "sample_inputs": ["4 10 5\n200 6", "3 1 5\n7 2"], "sample_outputs": ["39", "15"], "notes": "\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u042d\u0434\u0432\u0430\u0440\u0434 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 4 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 \u043d\u0430 10 \u044d\u0442\u0430\u0436\u0435, \u0430 \u041d\u0430\u0442\u0430\u0448\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 1 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 \u043d\u0430 2 \u044d\u0442\u0430\u0436\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u042d\u0434\u0432\u0430\u0440\u0434\u0443 \u0432\u044b\u0433\u043e\u0434\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043f\u0443\u0441\u0442\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043b\u0438\u0444\u0442\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u0436 (\u043d\u0430 \u044d\u0442\u043e \u043e\u043d \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442 19 \u0441\u0435\u043a\u0443\u043d\u0434, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 10\u00a0\u2014 \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0438 9\u00a0\u2014 \u043d\u0430 \u043f\u043e\u0435\u0437\u0434\u043a\u0443 \u043d\u0430 \u043b\u0438\u0444\u0442\u0435), \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u043e\u0439\u0442\u0438 \u0434\u043e\u043c \u043f\u0440\u043e\u0442\u0438\u0432 \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u0434\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 \u043d\u043e\u043c\u0435\u0440 1 (\u043d\u0430 \u044d\u0442\u043e \u043e\u043d \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442 15 \u0441\u0435\u043a\u0443\u043d\u0434), \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0434\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e \u043b\u0435\u0441\u0442\u043d\u0438\u0446\u0435 \u043d\u0430 \u044d\u0442\u0430\u0436 \u043d\u043e\u043c\u0435\u0440 2 (\u043d\u0430 \u044d\u0442\u043e \u043e\u043d \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442 5 \u0441\u0435\u043a\u0443\u043d\u0434). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u0442\u0432\u0435\u0442 \u0440\u0430\u0432\u0435\u043d 19\u2009+\u200915\u2009+\u20095\u2009=\u200939.\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u042d\u0434\u0432\u0430\u0440\u0434 \u0436\u0438\u0432\u0451\u0442 \u0432 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 2 \u043d\u0430 \u044d\u0442\u0430\u0436\u0435 1, \u0430 \u041d\u0430\u0442\u0430\u0448\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0435 1 \u043d\u0430 \u044d\u0442\u0430\u0436\u0435 1. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u042d\u0434\u0432\u0430\u0440\u0434\u0443 \u0432\u044b\u0433\u043e\u0434\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u0434\u043e\u043c \u043f\u043e \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0435 \u0434\u043e \u043f\u043e\u0434\u044a\u0435\u0437\u0434\u0430 1, \u043d\u0430 \u044d\u0442\u043e \u043e\u043d \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442 15 \u0441\u0435\u043a\u0443\u043d\u0434."}, "src_uid": "c37b46851abcf7eb472869bd1ab9f793"} {"nl": {"description": "There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmost digit of A and appends it to his or her number Si. After that this leftmost digit is erased from A. Initially the numbers of both players (S1 and S2) are \u00abempty\u00bb. Leading zeroes in numbers A,\u2009S1,\u2009S2 are allowed. In the end of the game the first player gets S1 dollars, and the second gets S2 dollars.One day Homer and Marge came to play the game. They managed to know the number A beforehand. They want to find such sequence of their moves that both of them makes exactly n moves and which maximizes their total prize. Help them.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200918). The second line contains integer A consisting of exactly 2n digits. This number can have leading zeroes.", "output_spec": "Output the line of 2n characters \u00abH\u00bb and \u00abM\u00bb \u2014 the sequence of moves of Homer and Marge, which gives them maximum possible total prize. Each player must make exactly n moves. If there are several solutions, output any of them.", "sample_inputs": ["2\n1234", "2\n9911"], "sample_outputs": ["HHMM", "HMHM"], "notes": null}, "src_uid": "98489fe54488dcfb45f8ae7b5c473d88"} {"nl": {"description": "Petya likes horse racing very much. Horses numbered from l to r take part in the races. Petya wants to evaluate the probability of victory; for some reason, to do that he needs to know the amount of nearly lucky horses' numbers. A nearly lucky number is an integer number that has at least two lucky digits the distance between which does not exceed k. Petya learned from some of his mates from Lviv that lucky digits are digits 4 and 7. The distance between the digits is the absolute difference between their positions in the number of a horse. For example, if k\u2009=\u20092, then numbers 412395497, 404, 4070400000070004007 are nearly lucky and numbers 4, 4123954997, 4007000040070004007 are not.Petya prepared t intervals [li,\u2009ri] and invented number k, common for all of them. Your task is to find how many nearly happy numbers there are in each of these segments. Since the answers can be quite large, output them modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line contains two integers t and k (1\u2009\u2264\u2009t,\u2009k\u2009\u2264\u20091000) \u2014 the number of segments and the distance between the numbers correspondingly. Next t lines contain pairs of integers li and ri (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009101000). All numbers are given without the leading zeroes. Numbers in each line are separated by exactly one space character.", "output_spec": "Output t lines. In each line print one integer \u2014 the answer for the corresponding segment modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1 2\n1 100", "1 2\n70 77", "2 1\n1 20\n80 100"], "sample_outputs": ["4", "2", "0\n0"], "notes": "NoteIn the first sample, the four nearly lucky numbers are 44, 47, 74, 77.In the second sample, only 74 and 77 are in the given segment."}, "src_uid": "5517efa2fc9362fdf342d32adac889f4"} {"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": "\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": "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": "A breakthrough among computer games, \"Civilization XIII\", is striking in its scale and elaborate details. Let's take a closer look at one of them.The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite. Let's take a look at the battle unit called an \"Archer\". Each archer has a parameter \"shot range\". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archer\u2019s fire if and only if all points of this cell, including border points are located inside the circle or on its border.The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A. Find the number of cells that are under fire for some archer.", "input_spec": "The first and only line of input contains a single positive integer k \u2014 the archer's shot range (1\u2009\u2264\u2009k\u2009\u2264\u2009106).", "output_spec": "Print the single number, the number of cells that are under fire. Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).", "sample_inputs": ["3", "4", "5"], "sample_outputs": ["7", "13", "19"], "notes": null}, "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13"} {"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": "The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8\u2009\u00d7\u20098 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).For example, if the first line of the board looks like that \"BBBBBBWW\" (the white cells of the line are marked with character \"W\", the black cells are marked with character \"B\"), then after one cyclic shift it will look like that \"WBBBBBBW\".Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.", "input_spec": "The input consists of exactly eight lines. Each line contains exactly eight characters \"W\" or \"B\" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character \"W\" stands for the white color, character \"B\" stands for the black color. Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns \u2014 from 1 to 8 from left to right. The given board can initially be a proper chessboard.", "output_spec": "In a single line print \"YES\" (without the quotes), if we can make the board a proper chessboard and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.In the second sample there is no way you can achieve the goal."}, "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"nl": {"description": "You get to work and turn on the computer. You start coding and give little thought to the RAM role in the whole process. In this problem your task is to solve one of the problems you encounter in your computer routine.We'll consider the RAM as a sequence of cells that can contain data. Some cells already contain some data, some are empty. The empty cells form the so-called memory clusters. Thus, a memory cluster is a sequence of some consecutive empty memory cells. You have exactly n memory clusters, the i-th cluster consists of ai cells. You need to find memory for m arrays in your program. The j-th array takes 2bj consecutive memory cells. There possibly isn't enough memory for all m arrays, so your task is to determine what maximum number of arrays can be located in the available memory clusters. Of course, the arrays cannot be divided between the memory clusters. Also, no cell can belong to two arrays.", "input_spec": "The first line of the input contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009106). The next line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009109). The next line contains m integers b1,\u2009b2,\u2009...,\u2009bm (1\u2009\u2264\u20092bi\u2009\u2264\u2009109).", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["5 3\n8 4 3 2 2\n3 2 2", "10 6\n1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0"], "sample_outputs": ["2", "6"], "notes": "NoteIn the first example you are given memory clusters with sizes 8, 4, 3, 2, 2 and arrays with sizes 8, 4, 4. There are few ways to obtain an answer equals 2: you can locate array with size 8 to the cluster with size 8, and one of the arrays with size 4 to the cluster with size 4. Another way is to locate two arrays with size 4 to the one cluster with size 8.In the second example you are given 10 memory clusters with size 1 and 6 arrays with size 1. You can choose any 6 clusters and locate all given arrays to them."}, "src_uid": "e95fb7d4309747834b37d4bc3468afb7"} {"nl": {"description": "You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 1 from the end of half-line, i. e. 1, 2, 3 and so on. The distance between the positions is the absolute difference between the respective numbers. Laharl, Etna and Flonne occupy some positions on the half-line and they want to get to the position with the largest possible number. They are originally placed in different positions. Each of the characters can perform each of the following actions no more than once: Move a certain distance. Grab another character and lift him above the head. Throw the lifted character a certain distance. Each character has a movement range parameter. They can only move to free positions, assuming that distance between those positions doesn't exceed the movement range. One character can lift another character if the distance between the two characters equals 1, and no one already holds that another character. We can assume that the lifted character moves to the same position as the person who has lifted him, and the position in which he stood before becomes free. A lifted character cannot perform any actions and the character that holds him cannot walk. Also, each character has a throwing range parameter. It is the distance at which this character can throw the one lifted above his head. He can only throw a character to a free position, and only when there is a lifted character. We accept the situation when one person grabs another one who in his turn has the third character in his hands. This forms a \"column\" of three characters. For example, Laharl can hold Etna while Etna holds Flonne. In this case, Etna and the Flonne cannot perform any actions, and Laharl can only throw Etna (together with Flonne) at some distance. Laharl, Etna and Flonne perform actions in any order. They perform actions in turns, that is no two of them can do actions at the same time.Determine the maximum number of position at least one of the characters can reach. That is, such maximal number x so that one of the characters can reach position x.", "input_spec": "The first line contains three integers: Laharl's position, his movement range and throwing range. The second and the third lines describe Etna's and Flonne's parameters correspondingly in the similar form. It is guaranteed that the three characters occupy distinct positions. All numbers in the input are between 1 and 10, inclusive.", "output_spec": "Print a single number \u2014 the maximum ordinal number of position which either Laharl, Etna or Flonne can reach.", "sample_inputs": ["9 3 3\n4 3 1\n2 3 3"], "sample_outputs": ["15"], "notes": "NoteLet us explain how to reach position 15 in the sample.Initially Laharl occupies position 9, Etna \u2014 position 4 and Flonne \u2014 position 2.First Laharl moves to position 6.Then Flonne moves to position 5 and grabs Etna.Laharl grabs Flonne and throws to position 9.Flonne throws Etna to position 12.Etna moves to position 15."}, "src_uid": "a14739b86d1fd62a030226263cdc1afc"} {"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": "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": "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": "The Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the \"Beaver's Calculator 1.0\". It is very peculiar and it is planned to be used in a variety of scientific problems.To test it, the Smart Beaver invited n scientists, numbered from 1 to n. The i-th scientist brought ki calculating problems for the device developed by the Smart Beaver from ABBYY. The problems of the i-th scientist are numbered from 1 to ki, and they must be calculated sequentially in the described order, since calculating each problem heavily depends on the results of calculating of the previous ones.Each problem of each of the n scientists is described by one integer ai,\u2009j, where i (1\u2009\u2264\u2009i\u2009\u2264\u2009n) is the number of the scientist, j (1\u2009\u2264\u2009j\u2009\u2264\u2009ki) is the number of the problem, and ai,\u2009j is the number of resource units the calculating device needs to solve this problem.The calculating device that is developed by the Smart Beaver is pretty unusual. It solves problems sequentially, one after another. After some problem is solved and before the next one is considered, the calculating device allocates or frees resources.The most expensive operation for the calculating device is freeing resources, which works much slower than allocating them. It is therefore desirable that each next problem for the calculating device requires no less resources than the previous one.You are given the information about the problems the scientists offered for the testing. You need to arrange these problems in such an order that the number of adjacent \"bad\" pairs of problems in this list is minimum possible. We will call two consecutive problems in this list a \"bad pair\" if the problem that is performed first requires more resources than the one that goes after it. Do not forget that the problems of the same scientist must be solved in a fixed order.", "input_spec": "The first line contains integer n \u2014 the number of scientists. To lessen the size of the input, each of the next n lines contains five integers ki, ai,\u20091, xi, yi, mi (0\u2009\u2264\u2009ai,\u20091\u2009<\u2009mi\u2009\u2264\u2009109, 1\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009109) \u2014 the number of problems of the i-th scientist, the resources the first problem requires and three parameters that generate the subsequent values of ai,\u2009j. For all j from 2 to ki, inclusive, you should calculate value ai,\u2009j by formula ai,\u2009j\u2009=\u2009(ai,\u2009j\u2009-\u20091\u2009*\u2009xi\u2009+\u2009yi) mod mi, where a mod b is the operation of taking the remainder of division of number a by number b. To get the full points for the first group of tests it is sufficient to solve the problem with n\u2009=\u20092, 1\u2009\u2264\u2009ki\u2009\u2264\u20092000. To get the full points for the second group of tests it is sufficient to solve the problem with n\u2009=\u20092, 1\u2009\u2264\u2009ki\u2009\u2264\u2009200000. To get the full points for the third group of tests it is sufficient to solve the problem with 1\u2009\u2264\u2009n\u2009\u2264\u20095000, 1\u2009\u2264\u2009ki\u2009\u2264\u20095000.", "output_spec": "On the first line print a single number \u2014 the number of \"bad\" pairs in the optimal order. If the total number of problems does not exceed 200000, also print lines \u2014 the optimal order of the problems. On each of these lines print two integers separated by a single space \u2014 the required number of resources for the problem and the number of the scientist who offered this problem, respectively. The scientists are numbered from 1 to n in the order of input.", "sample_inputs": ["2\n2 1 1 1 10\n2 3 1 1 10", "2\n3 10 2 3 1000\n3 100 1 999 1000"], "sample_outputs": ["0\n1 1\n2 1\n3 2\n4 2", "2\n10 1\n23 1\n49 1\n100 2\n99 2\n98 2"], "notes": "NoteIn the first sample n\u2009=\u20092, k1\u2009=\u20092, a1,\u20091\u2009=\u20091, a1,\u20092\u2009=\u20092, k2\u2009=\u20092, a2,\u20091\u2009=\u20093, a2,\u20092\u2009=\u20094. We've got two scientists, each of them has two calculating problems. The problems of the first scientist require 1 and 2 resource units, the problems of the second one require 3 and 4 resource units. Let's list all possible variants of the calculating order (each problem is characterized only by the number of resource units it requires): (1,\u20092,\u20093,\u20094), (1,\u20093,\u20092,\u20094), (3,\u20091,\u20092,\u20094), (1,\u20093,\u20094,\u20092), (3,\u20094,\u20091,\u20092), (3,\u20091,\u20094,\u20092).Sequence of problems (1,\u20093,\u20092,\u20094) has one \"bad\" pair (3 and 2), (3,\u20091,\u20094,\u20092) has two \"bad\" pairs (3 and 1, 4 and 2), and (1,\u20092,\u20093,\u20094) has no \"bad\" pairs."}, "src_uid": "15ba633cb33854bd4c0ee40847bb173c"} {"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": "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": "There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees.Find the value of the sum modulo 109\u2009+\u20097 (so you should find the remainder after dividing the answer by the value 109\u2009+\u20097).", "input_spec": "The only line contains two integers n,\u2009k (1\u2009\u2264\u2009n\u2009\u2264\u2009109,\u20090\u2009\u2264\u2009k\u2009\u2264\u2009106).", "output_spec": "Print the only integer a \u2014 the remainder after dividing the value of the sum by the value 109\u2009+\u20097.", "sample_inputs": ["4 1", "4 2", "4 3", "4 0"], "sample_outputs": ["10", "30", "100", "4"], "notes": null}, "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c"} {"nl": {"description": "As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n\u2009-\u20091. The same holds for each member of NFC.One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a,\u2009b) such that member a from MDC dances with member b from NFC.The complexity of a pairs' assignment is the number of pairs of dancing pairs (a,\u2009b) and (c,\u2009d) such that a\u2009<\u2009c and b\u2009>\u2009d.You are given a binary number of length n named x. We know that member i from MDC dances with member from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109\u2009+\u20097).Expression denotes applying \u00abXOR\u00bb to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as \u00ab^\u00bb, in Pascal \u2014 \u00abxor\u00bb.", "input_spec": "The first line of input contains a binary number x of lenght n, (1\u2009\u2264\u2009n\u2009\u2264\u2009100). This number may contain leading zeros.", "output_spec": "Print the complexity of the given dance assignent modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["11", "01", "1"], "sample_outputs": ["6", "2", "1"], "notes": null}, "src_uid": "89b51a31e00424edd1385f2120028b9d"} {"nl": {"description": "Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema.However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume that yuan is a kind of currency in Regulu Ere.)There are three types of customers: some of them bring exactly a 50-yuan note; some of them bring a 100-yuan note and Nephren needs to give a 50-yuan note back to him/her; some of them bring VIP cards so that they don't need to pay for the ticket.Now n customers are waiting outside in queue. Nephren wants to know how many possible queues are there that they are able to run smoothly (i.e. every customer can receive his/her change), and that the number of 50-yuan notes they have after selling tickets to all these customers is between l and r, inclusive. Two queues are considered different if there exists a customer whose type is different in two queues. As the number can be large, please output the answer modulo p.", "input_spec": "One line containing four integers n (1\u2009\u2264\u2009n\u2009\u2264\u2009105), p (1\u2009\u2264\u2009p\u2009\u2264\u20092\u00b7109), l and r (0\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n). ", "output_spec": "One line indicating the answer modulo p.", "sample_inputs": ["4 97 2 3", "4 100 0 4"], "sample_outputs": ["13", "35"], "notes": "NoteWe use A, B and C to indicate customers with 50-yuan notes, customers with 100-yuan notes and customers with VIP cards respectively.For the first sample, the different possible queues that there are 2 50-yuan notes left are AAAB, AABA, ABAA, AACC, ACAC, ACCA, CAAC, CACA and CCAA, and the different possible queues that there are 3 50-yuan notes left are AAAC, AACA, ACAA and CAAA. So there are 13 different queues satisfying the first sample. Similarly, there are 35 different queues satisfying the second sample."}, "src_uid": "6ddc487029785738679007443fc08463"} {"nl": {"description": "If an integer a is divisible by another integer b, then b is called the divisor of a.For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12.Let\u2019s define a function D(n) \u2014 number of integers between 1 and n (inclusive) which has exactly four positive divisors.Between 1 and 10 only the integers 6, 8 and 10 has exactly four positive divisors. So, D(10)\u2009=\u20093.You are given an integer n. You have to calculate D(n).", "input_spec": "The only line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091011) \u2014 the parameter from the problem statement.", "output_spec": "Print the only integer c \u2014 the number of integers between 1 and n with exactly four divisors.", "sample_inputs": ["10", "20"], "sample_outputs": ["3", "5"], "notes": null}, "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d"} {"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": "We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit should belong to exactly one subset after the split.There are n queries for you. Each query is described with three integers l, r and k, which mean that you are asked how many integers x between l and r (inclusive) are k-beautiful.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20095\u00b7104), indicating the number of queries. Each of the next n lines describes a query, containing three integers l, r and k (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20091018, 0\u2009\u2264\u2009k\u2009\u2264\u20099).", "output_spec": "For each query print a single number\u00a0\u2014 the answer to the query.", "sample_inputs": ["10\n1 100 0\n1 100 1\n1 100 2\n1 100 3\n1 100 4\n1 100 5\n1 100 6\n1 100 7\n1 100 8\n1 100 9", "10\n1 1000 0\n1 1000 1\n1 1000 2\n1 1000 3\n1 1000 4\n1 1000 5\n1 1000 6\n1 1000 7\n1 1000 8\n1 1000 9"], "sample_outputs": ["9\n28\n44\n58\n70\n80\n88\n94\n98\n100", "135\n380\n573\n721\n830\n906\n955\n983\n996\n1000"], "notes": "NoteIf 1\u2009\u2264\u2009x\u2009\u2264\u20099, integer x is k-beautiful if and only if x\u2009\u2264\u2009k.If 10\u2009\u2264\u2009x\u2009\u2264\u200999, integer x\u2009=\u200910a\u2009+\u2009b is k-beautiful if and only if |a\u2009-\u2009b|\u2009\u2264\u2009k, where a and b are integers between 0 and 9, inclusive.100 is k-beautiful if and only if k\u2009\u2265\u20091."}, "src_uid": "db0e3ef630cb381724697a1ac5152611"} {"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": "The year 2015 is almost over.Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system\u00a0\u2014 201510\u2009=\u2009111110111112. Note that he doesn't care about the number of zeros in the decimal representation.Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?Assume that all positive integers are always written without leading zeros.", "input_spec": "The only line of the input contains two integers a and b (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u20091018)\u00a0\u2014 the first year and the last year in Limak's interval respectively.", "output_spec": "Print one integer\u00a0\u2013 the number of years Limak will count in his chosen interval.", "sample_inputs": ["5 10", "2015 2015", "100 105", "72057594000000000 72057595000000000"], "sample_outputs": ["2", "1", "0", "26"], "notes": "NoteIn the first sample Limak's interval contains numbers 510\u2009=\u20091012, 610\u2009=\u20091102, 710\u2009=\u20091112, 810\u2009=\u200910002, 910\u2009=\u200910012 and 1010\u2009=\u200910102. Two of them (1012 and 1102) have the described property."}, "src_uid": "581f61b1f50313bf4c75833cefd4d022"} {"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": "Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.", "input_spec": "The first and only line of the input starts with a string with the format \"HH:MM\" where \"HH\" is from \"00\" to \"23\" and \"MM\" is from \"00\" to \"59\". Both \"HH\" and \"MM\" have exactly two digits.", "output_spec": "Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.", "sample_inputs": ["12:21", "23:59"], "sample_outputs": ["13:31", "00:00"], "notes": null}, "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"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": "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": "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": "Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.A block with side a has volume a3. A tower consisting of blocks with sides a1,\u2009a2,\u2009...,\u2009ak has the total volume a13\u2009+\u2009a23\u2009+\u2009...\u2009+\u2009ak3.Limak is going to build a tower. First, he asks you to tell him a positive integer X\u00a0\u2014 the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X\u2009\u2264\u2009m that results this number of blocks.", "input_spec": "The only line of the input contains one integer m (1\u2009\u2264\u2009m\u2009\u2264\u20091015), meaning that Limak wants you to choose X between 1 and m, inclusive.", "output_spec": "Print two integers\u00a0\u2014 the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.", "sample_inputs": ["48", "6"], "sample_outputs": ["9 42", "6 6"], "notes": "NoteIn the first sample test, there will be 9 blocks if you choose X\u2009=\u200923 or X\u2009=\u200942. Limak wants to maximize X secondarily so you should choose 42.In more detail, after choosing X\u2009=\u200942 the process of building a tower is: Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42\u2009-\u200927\u2009=\u200915. The second added block has side 2, so the remaining volume is 15\u2009-\u20098\u2009=\u20097. Finally, Limak adds 7 blocks with side 1, one by one. So, there are 9 blocks in the tower. The total volume is is 33\u2009+\u200923\u2009+\u20097\u00b713\u2009=\u200927\u2009+\u20098\u2009+\u20097\u2009=\u200942."}, "src_uid": "385cf3c40c96f0879788b766eeb25139"} {"nl": {"description": "Manao is working for a construction company. Recently, an order came to build wall bars in a children's park. Manao was commissioned to develop a plan of construction, which will enable the company to save the most money.After reviewing the formal specifications for the wall bars, Manao discovered a number of controversial requirements and decided to treat them to the company's advantage. His resulting design can be described as follows: Let's introduce some unit of length. The construction center is a pole of height n. At heights 1,\u20092,\u2009...,\u2009n exactly one horizontal bar sticks out from the pole. Each bar sticks in one of four pre-fixed directions. A child can move from one bar to another if the distance between them does not exceed h and they stick in the same direction. If a child is on the ground, he can climb onto any of the bars at height between 1 and h. In Manao's construction a child should be able to reach at least one of the bars at heights n\u2009-\u2009h\u2009+\u20091,\u2009n\u2009-\u2009h\u2009+\u20092,\u2009...,\u2009n if he begins at the ground. The figure to the left shows what a common set of wall bars looks like. The figure to the right shows Manao's construction Manao is wondering how many distinct construction designs that satisfy his requirements exist. As this number can be rather large, print the remainder after dividing it by 1000000009\u00a0(109\u2009+\u20099). Two designs are considered distinct if there is such height i, that the bars on the height i in these designs don't stick out in the same direction.", "input_spec": "A single line contains two space-separated integers, n and h (1\u2009\u2264\u2009n\u2009\u2264\u20091000, 1\u2009\u2264\u2009h\u2009\u2264\u2009min(n,\u200930)).", "output_spec": "In a single line print the remainder after dividing the number of designs by 1000000009\u00a0(109\u2009+\u20099).", "sample_inputs": ["5 1", "4 2", "4 3", "5 2"], "sample_outputs": ["4", "148", "256", "376"], "notes": "NoteConsider several designs for h\u2009=\u20092. A design with the first bar sticked out in direction d1, the second \u2014 in direction d2 and so on (1\u2009\u2264\u2009di\u2009\u2264\u20094) is denoted as string d1d2...dn.Design \"1231\" (the first three bars are sticked out in different directions, the last one \u2014 in the same as first). A child can reach neither the bar at height 3 nor the bar at height 4.Design \"414141\". A child can reach the bar at height 5. To do this, he should first climb at the first bar, then at the third and then at the fifth one. He can also reach bar at height 6 by the route second \u2009\u2192\u2009 fourth \u2009\u2192\u2009 sixth bars.Design \"123333\". The child can't reach the upper two bars.Design \"323323\". The bar at height 6 can be reached by the following route: first \u2009\u2192\u2009 third \u2009\u2192\u2009 fourth \u2009\u2192\u2009 sixth bars."}, "src_uid": "9fe9658db35076c0bddc8b7ddce11013"} {"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": "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": "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": "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": "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": "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": "In Bubbleland a group of special programming forces gets a top secret job to calculate the number of potentially infected people by a new unknown virus. The state has a population of $$$n$$$ people and every day there is new information about new contacts between people. The job of special programming forces is to calculate how many contacts in the last $$$k$$$ days a given person had. The new virus has an incubation period of $$$k$$$ days, and after that time people consider as non-infectious. Because the new virus is an extremely dangerous, government mark as suspicious everybody who had direct or indirect contact in the last $$$k$$$ days, independently of the order of contacts.This virus is very strange, and people can't get durable immunity.You need to help special programming forces to calculate the number of suspicious people for a given person (number of people who had contact with a given person).There are 3 given inputs on beginning $$$n$$$ where $$$n$$$ is population, $$$q$$$ number of queries, $$$k$$$ virus incubation time in days. Each query is one of three types: ($$$x$$$, $$$y$$$) person $$$x$$$ and person $$$y$$$ met that day ($$$x \\neq y$$$). ($$$z$$$) return the number of people in contact with $$$z$$$, counting himself. The end of the current day moves on to the next day. ", "input_spec": "The first line of input contains three integers $$$n$$$ ($$$1 \\le n\\le 10^5$$$) the number of people in the state, $$$q$$$ ($$$1 \\le q\\le 5\u00d710^5$$$) number of queries and $$$k$$$ ($$$1 \\le k\\le 10^5$$$) virus incubation time in days. Each of the next $$$q$$$ lines starts with an integer $$$t$$$ ($$$1 \\le t\\le 3$$$) the type of the query. A pair of integers $$$x$$$ and $$$y$$$ ($$$1 \\le x, y \\le n$$$) follows in the query of the first type ($$$x \\neq y$$$). An integer $$$i$$$ ($$$1 \\le i\\le n$$$) follows in the query of the second type. Query of third type does not have the following number.", "output_spec": "For the queries of the second type print on a separate line the current number of people in contact with a given person.", "sample_inputs": ["5 12 1\n1 1 2\n1 1 3\n1 3 4\n2 4\n2 5\n3\n2 1\n1 1 2\n1 3 2\n2 1\n3\n2 1", "5 12 2\n1 1 2\n1 1 3\n1 3 4\n2 4\n2 5\n3\n2 1\n1 1 2\n1 3 2\n2 1\n3\n2 1", "10 25 2\n1 9 3\n2 5\n1 1 3\n1 3 1\n2 2\n1 8 3\n1 5 6\n3\n1 9 2\n1 8 3\n2 9\n1 3 1\n2 5\n1 6 4\n3\n3\n2 4\n3\n1 10 9\n1 1 7\n3\n2 2\n3\n1 5 6\n1 1 4"], "sample_outputs": ["4\n1\n1\n3\n1", "4\n1\n4\n4\n3", "1\n1\n5\n2\n1\n1"], "notes": "NotePay attention if persons $$$1$$$ and $$$2$$$ had contact first day and next day persons $$$1$$$ and $$$3$$$ had contact, for $$$k$$$>$$$1$$$ number of contacts of person $$$3$$$ is $$$3$$$(persons:1,2,3)."}, "src_uid": "417788298ec54dd5fd7616ab8c5ce246"} {"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": "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 50$$$), $$$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 50, 1 \\le T \\le 2500$$$) \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 50, 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": "ed5f913afe829c65792b54233a256757"} {"nl": {"description": "One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution...", "input_spec": "The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive.", "output_spec": "Reproduce the output of the reference solution, including the bug.", "sample_inputs": ["8-7+6-5+4-3+2-1-0", "2+2", "112-37"], "sample_outputs": ["4", "-46", "375"], "notes": null}, "src_uid": "db85fa18f00e560b58cfa7bab2fa957d"} {"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": "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": "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": "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": "The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one. In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.", "input_spec": "The only line of input contains integer k, (0\u2009\u2264\u2009k\u2009\u2264\u200934), denoting the number of participants.", "output_spec": "Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.", "sample_inputs": ["9", "20"], "sample_outputs": ["+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+", "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"], "notes": null}, "src_uid": "075f83248f6d4d012e0ca1547fc67993"} {"nl": {"description": "A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforces\u03c9 that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.", "input_spec": "The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.", "output_spec": "Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).", "sample_inputs": ["CODEWAITFORITFORCES", "BOTTOMCODER", "DECODEFORCES", "DOGEFORCES"], "sample_outputs": ["YES", "NO", "YES", "NO"], "notes": null}, "src_uid": "bda4b15827c94b526643dfefc4bc36e7"} {"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": "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": "When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked $$$n$$$ people about their opinions. Each person answered whether this problem is easy or hard.If at least one of these $$$n$$$ people has answered that the problem is hard, the coordinator decides to change the problem. For the given responses, check if the problem is easy enough.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of people who were asked to give their opinions. The second line contains $$$n$$$ integers, each integer is either $$$0$$$ or $$$1$$$. If $$$i$$$-th integer is $$$0$$$, then $$$i$$$-th person thinks that the problem is easy; if it is $$$1$$$, then $$$i$$$-th person thinks that the problem is hard.", "output_spec": "Print one word: \"EASY\" if the problem is easy according to all responses, or \"HARD\" if there is at least one person who thinks the problem is hard. You may print every letter in any register: \"EASY\", \"easy\", \"EaSY\" and \"eAsY\" all will be processed correctly.", "sample_inputs": ["3\n0 0 1", "1\n0"], "sample_outputs": ["HARD", "EASY"], "notes": "NoteIn the first example the third person says it's a hard problem, so it should be replaced.In the second example the problem easy for the only person, so it doesn't have to be replaced."}, "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"nl": {"description": "Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?", "input_spec": "The single line contains four space-separated integers n, m, a, b (1\u2009\u2264\u2009n,\u2009m,\u2009a,\u2009b\u2009\u2264\u20091000) \u2014 the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket. ", "output_spec": "Print a single integer \u2014 the minimum sum in rubles that Ann will need to spend.", "sample_inputs": ["6 2 1 2", "5 2 2 3"], "sample_outputs": ["6", "8"], "notes": "NoteIn the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets."}, "src_uid": "faa343ad6028c5a069857a38fa19bb24"} {"nl": {"description": "Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.", "input_spec": "The first line contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009360) \u00a0\u2014 the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009360) \u00a0\u2014 the angles of the sectors into which the pizza was cut. The sum of all ai is 360.", "output_spec": "Print one integer \u00a0\u2014 the minimal difference between angles of sectors that will go to Vasya and Petya.", "sample_inputs": ["4\n90 90 90 90", "3\n100 100 160", "1\n360", "4\n170 30 150 10"], "sample_outputs": ["0", "40", "360", "0"], "notes": "NoteIn first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90\u2009+\u200990)\u2009-\u2009(90\u2009+\u200990)|\u2009=\u20090.In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360\u2009-\u20090|\u2009=\u2009360.In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170\u2009+\u200910)\u2009-\u2009(30\u2009+\u2009150)|\u2009=\u20090.Picture explaning fourth sample:Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector."}, "src_uid": "1b6a6aff81911865356ec7cbf6883e82"} {"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": "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": "There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules: Red-green tower is consisting of some number of levels; Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level \u2014 of n\u2009-\u20091 blocks, the third one \u2014 of n\u2009-\u20092 blocks, and so on \u2014 the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one; Each level of the red-green tower should contain blocks of the same color. Let h be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks.Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.You are to write a program that will find the number of different red-green towers of height h modulo\u00a0109\u2009+\u20097.", "input_spec": "The only line of input contains two integers r and g, separated by a single space \u2014 the number of available red and green blocks respectively (0\u2009\u2264\u2009r,\u2009g\u2009\u2264\u20092\u00b7105, r\u2009+\u2009g\u2009\u2265\u20091).", "output_spec": "Output the only integer \u2014 the number of different possible red-green towers of height h modulo\u00a0109\u2009+\u20097.", "sample_inputs": ["4 6", "9 7", "1 1"], "sample_outputs": ["2", "6", "2"], "notes": "NoteThe image in the problem statement shows all possible red-green towers for the first sample."}, "src_uid": "34b6286350e3531c1fbda6b0c184addc"} {"nl": {"description": "A never-ending, fast-changing and dream-like world unfolds, as the secret door opens.A world is an unordered graph G, in whose vertex set V(G) there are two special vertices s(G) and t(G). An initial world has vertex set {s(G),\u2009t(G)} and an edge between them.A total of n changes took place in an initial world. In each change, a new vertex w is added into V(G), an existing edge (u,\u2009v) is chosen, and two edges (u,\u2009w) and (v,\u2009w) are added into E(G). Note that it's possible that some edges are chosen in more than one change.It's known that the capacity of the minimum s-t cut of the resulting graph is m, that is, at least m edges need to be removed in order to make s(G) and t(G) disconnected.Count the number of non-similar worlds that can be built under the constraints, modulo 109\u2009+\u20097. We define two worlds similar, if they are isomorphic and there is isomorphism in which the s and t vertices are not relabelled. Formally, two worlds G and H are considered similar, if there is a bijection between their vertex sets , such that: f(s(G))\u2009=\u2009s(H); f(t(G))\u2009=\u2009t(H); Two vertices u and v of G are adjacent in G if and only if f(u) and f(v) are adjacent in H. ", "input_spec": "The first and only line of input contains two space-separated integers n, m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200950) \u2014 the number of operations performed and the minimum cut, respectively.", "output_spec": "Output one integer \u2014 the number of non-similar worlds that can be built, modulo 109\u2009+\u20097.", "sample_inputs": ["3 2", "4 4", "7 3", "31 8"], "sample_outputs": ["6", "3", "1196", "64921457"], "notes": "NoteIn the first example, the following 6 worlds are pairwise non-similar and satisfy the constraints, with s(G) marked in green, t(G) marked in blue, and one of their minimum cuts in light blue. In the second example, the following 3 worlds satisfy the constraints. "}, "src_uid": "aca6148effff8b893c961b1ee465e4e4"} {"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": "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": "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": "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": "Harry Potter lost his Invisibility Cloak, running from the school caretaker Filch. Finding an invisible object is not an easy task. Fortunately, Harry has friends who are willing to help. Hermione Granger had read \"The Invisibility Cloaks, and Everything about Them\", as well as six volumes of \"The Encyclopedia of Quick Search of Shortest Paths in Graphs, Network Flows, the Maximal Increasing Subsequences and Other Magical Objects\". She has already developed a search algorithm for the invisibility cloak in complex dynamic systems (Hogwarts is one of them).Hogwarts consists of n floors, numbered by integers from 1 to n. Some pairs of floors are connected by staircases. The staircases may change its position, moving exactly one end. Formally the situation is like this: if a staircase connects the floors a and b, then in one move it may modify its position so as to connect the floors a and c or b and c, where c is any floor different from a and b. Under no circumstances the staircase can connect a floor with itself. At the same time there can be multiple stairs between a pair of floors.Initially, Harry is on the floor with the number 1. He does not remember on what floor he has lost the cloak and wants to look for it on each of the floors. Therefore, his goal is to visit each of n floors at least once. Harry can visit the floors in any order and finish the searching at any floor.Nowadays the staircases move quite rarely. However, Ron and Hermione are willing to put a spell on any of them to help Harry find the cloak. To cause less suspicion, the three friends plan to move the staircases one by one, and no more than once for each staircase. In between shifting the staircases Harry will be able to move about the floors, reachable at the moment from the staircases, and look for his Invisibility Cloak. It is assumed that during all this time the staircases will not move spontaneously.Help the three friends to compose a searching plan. If there are several variants to solve the problem, any valid option (not necessarily the optimal one) will be accepted.", "input_spec": "The first line contains integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u2009100000, 0\u2009\u2264\u2009m\u2009\u2264\u2009200000), which are the number of floors and staircases in Hogwarts, respectively. The following m lines contain pairs of floors connected by staircases at the initial moment of time.", "output_spec": "In the first line print \"YES\" (without the quotes) if Harry is able to search all the floors, and \"NO\" otherwise. If the answer is positive, then print on the second line the number of staircases that Ron and Hermione will have to shift. Further output should look like this: Harry's moves a staircase's move Harry's moves a staircase's move ... a staircase's move Harry's moves Each \"Harry's move\" should be represented as a list of floors in the order in which they have been visited. The total amount of elements of these lists must not exceed 106. When you print each list, first print the number of elements in it, and then in the same line print the actual space-separated elements. The first number in the first list should be the number 1 (the floor, from which Harry begins to search). Any list except the first one might contain the zero number of elements. Note that Harry can visit some floors again, but must visit all n floors at least once. Two consecutively visited floors must be directly connected by a staircase (at the time Harry goes from one of them to the other one). No two floors that are visited consequtively can be equal. In the description of a \"staircase's move\" indicate the number of staircase (the staircases are numbered from 1 to m in the order in which they are given in the input data) and its new location (two numbers of the connected floors in any order). Any staircase can be moved at most once. If there are several solutions, output any.", "sample_inputs": ["6 4\n1 2\n1 3\n2 3\n4 5", "4 1\n1 2", "5 5\n1 2\n1 3\n3 4\n3 5\n4 5"], "sample_outputs": ["YES\n2\n3 1 2 3\n2 3 5\n3 5 4 5\n4 5 6\n3 6 5 3", "NO", "YES\n0\n6 1 2 1 3 4 5"], "notes": null}, "src_uid": "35a3513c8fe730a64f30c5daec27df05"} {"nl": {"description": "Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n\u2009-\u20091, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0\u2009\u2264\u2009i\u2009<\u2009n) such that ai\u2009+\u2009ai\u2009+\u2009n\u2009+\u2009ai\u2009+\u20092n\u2009\u2260\u20096, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109\u2009+\u20097. Two ways, a and b, are considered distinct if there is index i (0\u2009\u2264\u2009i\u2009<\u20093n), such that ai\u2009\u2260\u2009bi (that is, some gnome got different number of coins in these two ways).", "input_spec": "A single line contains number n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of the gnomes divided by three.", "output_spec": "Print a single number \u2014 the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109\u2009+\u20097.", "sample_inputs": ["1", "2"], "sample_outputs": ["20", "680"], "notes": "Note20 ways for n\u2009=\u20091 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): "}, "src_uid": "eae87ec16c284f324d86b7e65fda093c"} {"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": "A little girl loves problems on bitwise operations very much. Here's one of them.You are given two integers l and r. Let's consider the values of for all pairs of integers a and b (l\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009r). Your task is to find the maximum value among all considered ones.Expression means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as \"^\", in Pascal \u2014 as \"xor\".", "input_spec": "The single line contains space-separated integers l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20091018). 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": "In a single line print a single integer \u2014 the maximum value of for all pairs of integers a, b (l\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009r).", "sample_inputs": ["1 2", "8 16", "1 1"], "sample_outputs": ["3", "31", "0"], "notes": null}, "src_uid": "d90e99d539b16590c17328d79a5921e0"} {"nl": {"description": "Two boys decided to compete in text typing on the site \"Key races\". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. Right after that he starts to type it. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.Given the length of the text and the information about participants, determine the result of the game.", "input_spec": "The first line contains five integers s, v1, v2, t1, t2 (1\u2009\u2264\u2009s,\u2009v1,\u2009v2,\u2009t1,\u2009t2\u2009\u2264\u20091000)\u00a0\u2014 the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.", "output_spec": "If the first participant wins, print \"First\". If the second participant wins, print \"Second\". In case of a draw print \"Friendship\".", "sample_inputs": ["5 1 2 1 2", "3 3 1 1 1", "4 5 3 1 5"], "sample_outputs": ["First", "Second", "Friendship"], "notes": "NoteIn the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant\u00a0\u2014 in 14 milliseconds. So, the first wins.In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant\u00a0\u2014 in 5 milliseconds. So, the second wins.In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant\u00a0\u2014 in 22 milliseconds. So, it is be a draw."}, "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"nl": {"description": "Meg the Rabbit decided to do something nice, specifically \u2014 to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse \u2014 as a square of side n. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0,\u20090), (n,\u20090), (0,\u2009n) and (n,\u2009n).", "input_spec": "The single line contains 5 space-separated integers: n,\u2009x1,\u2009y1,\u2009x2,\u2009y2 (1\u2009\u2264\u2009n\u2009\u2264\u20091000,\u20090\u2009\u2264\u2009x1,\u2009y1,\u2009x2,\u2009y2\u2009\u2264\u2009n) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.", "output_spec": "You must print on a single line the shortest distance between the points.", "sample_inputs": ["2 0 0 1 0", "2 0 1 2 1", "100 0 0 100 100"], "sample_outputs": ["1", "4", "200"], "notes": null}, "src_uid": "685fe16c217b5b71eafdb4198822250e"} {"nl": {"description": "Nauuo is a girl who loves traveling.One day she went to a tree, Old Driver Tree, literally, a tree with an old driver on it.The tree is a connected graph consisting of $$$n$$$ nodes and $$$n-1$$$ edges. Each node has a color, and Nauuo will visit the ODT through a simple path on the tree in the old driver's car.Nauuo wants to visit see more different colors in her journey, but she doesn't know which simple path she will be traveling on. So, she wants to calculate the sum of the numbers of different colors on all different paths. Can you help her?What's more, the ODT is being redecorated, so there will be $$$m$$$ modifications, each modification will change a single node's color. Nauuo wants to know the answer after each modification too.Note that in this problem, we consider the simple path from $$$u$$$ to $$$v$$$ and the simple path from $$$v$$$ to $$$u$$$ as two different simple paths if and only if $$$u\\ne v$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2\\le n\\le 4\\cdot 10^5$$$, $$$1\\le m\\le 4\\cdot 10^5$$$) \u2014 the number of nodes and the number of modifications. The second line contains $$$n$$$ integers $$$c_1,c_2,\\ldots,c_n$$$ ($$$1\\le c_i\\le n$$$), where $$$c_i$$$ is the initial color of node $$$i$$$. Each of the next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1\\le u,v\\le n$$$), denoting there is an edge between $$$u$$$ and $$$v$$$. It is guaranteed that the given edges form a tree. Each of the next $$$m$$$ lines contains two integers $$$u$$$ and $$$x$$$ ($$$1\\le u,x\\le n$$$), which means a modification that changes the color of node $$$u$$$ into $$$x$$$.", "output_spec": "The output contains $$$m+1$$$ integers \u2014 the first integer is the answer at the beginning, the rest integers are the answers after every modification in the given order.", "sample_inputs": ["5 3\n1 2 1 2 3\n1 2\n1 3\n3 4\n3 5\n3 3\n4 1\n4 3", "6 1\n1 1 1 1 1 1\n1 2\n2 3\n3 4\n4 5\n5 6\n1 2"], "sample_outputs": ["47\n51\n49\n45", "36\n46"], "notes": "NoteExample 1The number of colors on each simple path at the beginning:"}, "src_uid": "5879aa95ed79dc2c97667dc16ca73a8c"} {"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": "One day Vasya was lying in bed watching his electronic clock to fall asleep quicker.Vasya lives in a strange country, where days have h hours, and every hour has m minutes. Clock shows time in decimal number system, in format H:M, where the string H always has a fixed length equal to the number of digits in the decimal representation of number h\u2009-\u20091. To achieve this, leading zeros are added if necessary. The string M has a similar format, and its length is always equal to the number of digits in the decimal representation of number m\u2009-\u20091. For example, if h\u2009=\u200917, m\u2009=\u20091000, then time equal to 13 hours and 75 minutes will be displayed as \"13:075\".Vasya had been watching the clock from h1 hours m1 minutes to h2 hours m2 minutes inclusive, and then he fell asleep. Now he asks you to count how many times he saw the moment at which at least k digits changed on the clock simultaneously.For example, when switching 04:19 \u2009\u2192\u2009 04:20 two digits change. When switching 23:59 \u2009\u2192\u2009 00:00, four digits change.Consider that Vasya has been watching the clock for strictly less than one day. Note that the last time Vasya saw on the clock before falling asleep was \"h2:m2\". That is, Vasya didn't see the moment at which time \"h2:m2\" switched to the next value.", "input_spec": "The first line of the input file contains three space-separated integers h, m and k (2\u2009\u2264\u2009h,\u2009m\u2009\u2264\u2009109, 1\u2009\u2264\u2009k\u2009\u2264\u200920). The second line contains space-separated integers h1, m1 (0\u2009\u2264\u2009h1\u2009<\u2009h, 0\u2009\u2264\u2009m1\u2009<\u2009m). The third line contains space-separated integers h2, m2 (0\u2009\u2264\u2009h2\u2009<\u2009h, 0\u2009\u2264\u2009m2\u2009<\u2009m).", "output_spec": "Print a single number \u2014 the number of times Vasya saw the moment of changing at least k digits simultaneously. Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin stream (also you may use the %I64d specificator).", "sample_inputs": ["5 5 2\n4 4\n2 1", "24 60 1\n0 0\n23 59", "24 60 3\n23 59\n23 59"], "sample_outputs": ["3", "1439", "0"], "notes": "NoteIn the first example Vasya will see the following moments of time: 4:4 0:0 \u2009\u2192\u2009 0:1 \u2009\u2192\u2009 0:2 \u2009\u2192\u2009 0:3 \u2009\u2192\u2009 0:4 1:0 \u2009\u2192\u2009 1:1 \u2009\u2192\u2009 1:2 \u2009\u2192\u2009 1:3 \u2009\u2192\u2009 1:4 2:0 \u2009\u2192\u2009 2:1 \u2009\u2192\u2009 2:2 \u2009\u2192\u2009 2:3 \u2009\u2192\u2009 2:4. Double arrow () marks the sought moments of time (in this example \u2014 when Vasya sees two numbers changing simultaneously).In the second example k\u2009=\u20091. Any switching time can be accepted, since during switching of the clock at least one digit is changed. Total switching equals to 24\u00b760\u2009=\u20091440, but Vasya have not seen one of them \u2014 the switching of 23:59 00:00.In the third example Vasya fell asleep immediately after he began to look at the clock, so he did not see any change."}, "src_uid": "e2782743229645ad3a0f8e815d86dc5f"} {"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": "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": "n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n\u2009\u2264\u2009m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?", "input_spec": "The only line contain three integers n, m and k (1\u2009\u2264\u2009n\u2009\u2264\u2009m\u2009\u2264\u2009109, 1\u2009\u2264\u2009k\u2009\u2264\u2009n)\u00a0\u2014 the number of hobbits, the number of pillows and the number of Frodo's bed.", "output_spec": "Print single integer\u00a0\u2014 the maximum number of pillows Frodo can have so that no one is hurt.", "sample_inputs": ["4 6 2", "3 10 3", "3 6 1"], "sample_outputs": ["2", "4", "3"], "notes": "NoteIn the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.In the second example Frodo can take at most four pillows, giving three pillows to each of the others.In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed."}, "src_uid": "da9ddd00f46021e8ee9db4a8deed017c"} {"nl": {"description": "You have $$$n \\times n$$$ square grid and an integer $$$k$$$. Put an integer in each cell while satisfying the conditions below. All numbers in the grid should be between $$$1$$$ and $$$k$$$ inclusive. Minimum number of the $$$i$$$-th row is $$$1$$$ ($$$1 \\le i \\le n$$$). Minimum number of the $$$j$$$-th column is $$$1$$$ ($$$1 \\le j \\le n$$$). Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo $$$(10^{9} + 7)$$$. These are the examples of valid and invalid grid when $$$n=k=2$$$. ", "input_spec": "The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 250$$$, $$$1 \\le k \\le 10^{9}$$$).", "output_spec": "Print the answer modulo $$$(10^{9} + 7)$$$.", "sample_inputs": ["2 2", "123 456789"], "sample_outputs": ["7", "689974806"], "notes": "NoteIn the first example, following $$$7$$$ cases are possible. In the second example, make sure you print the answer modulo $$$(10^{9} + 7)$$$."}, "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93"} {"nl": {"description": "There are n people, sitting in a line at the table. For each person we know that he always tells either the truth or lies.Little Serge asked them: how many of you always tell the truth? Each of the people at the table knows everything (who is an honest person and who is a liar) about all the people at the table. The honest people are going to say the correct answer, the liars are going to say any integer from 1 to n, which is not the correct answer. Every liar chooses his answer, regardless of the other liars, so two distinct liars may give distinct answer.Serge does not know any information about the people besides their answers to his question. He took a piece of paper and wrote n integers a1,\u2009a2,\u2009...,\u2009an, where ai is the answer of the i-th person in the row. Given this sequence, Serge determined that exactly k people sitting at the table apparently lie.Serge wonders, how many variants of people's answers (sequences of answers a of length n) there are where one can say that exactly k people sitting at the table apparently lie. As there can be rather many described variants of answers, count the remainder of dividing the number of the variants by 777777777.", "input_spec": "The first line contains two integers n, k, (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u200928). It is guaranteed that n \u2014 is the power of number 2.", "output_spec": "Print a single integer \u2014 the answer to the problem modulo 777777777.", "sample_inputs": ["1 1", "2 1"], "sample_outputs": ["0", "2"], "notes": null}, "src_uid": "cfe19131644e5925e32084a581e23286"} {"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": "A boy named Vasya wants to play an old Russian solitaire called \"Accordion\". In this solitaire, the player must observe the following rules: A deck of n cards is carefully shuffled, then all n cards are put on the table in a line from left to right; Before each move the table has several piles of cards lying in a line (initially there are n piles, each pile has one card). Let's number the piles from left to right, from 1 to x. During one move, a player can take the whole pile with the maximum number x (that is the rightmost of remaining) and put it on the top of pile x\u2009-\u20091 (if it exists) or on the top of pile x\u2009-\u20093 (if it exists). The player can put one pile on top of another one only if the piles' top cards have the same suits or values. Please note that if pile x goes on top of pile y, then the top card of pile x becomes the top card of the resulting pile. Also note that each move decreases the total number of piles by 1; The solitaire is considered completed if all cards are in the same pile. Vasya has already shuffled the cards and put them on the table, help him understand whether completing this solitaire is possible or not. ", "input_spec": "The first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200952) \u2014 the number of cards in Vasya's deck. The next line contains n space-separated strings c1,\u2009c2,\u2009...,\u2009cn, where string ci describes the i-th card on the table. Each string ci consists of exactly two characters, the first one represents the card's value, the second one represents its suit. Cards on the table are numbered from left to right. A card's value is specified by one of these characters: \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\", \"A\". A card's suit is specified by one of these characters: \"S\", \"D\", \"H\", \"C\". It is not guaranteed that the deck has all possible cards. Also, the cards in Vasya's deck can repeat.", "output_spec": "On a single line print the answer to the problem: string \"YES\" (without the quotes) if completing the solitaire is possible, string \"NO\" (without the quotes) otherwise.", "sample_inputs": ["4\n2S 2S 2C 2C", "2\n3S 2C"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample you can act like that: put the 4-th pile on the 1-st one; put the 3-rd pile on the 2-nd one; put the 2-nd pile on the 1-st one. In the second sample there is no way to complete the solitaire."}, "src_uid": "1805771e194d323edacf2526a1eb6768"} {"nl": {"description": "A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.", "input_spec": "The first line of input contains two space-separated positive integers n (2\u2009\u2264\u2009n\u2009\u2264\u2009100) and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n) \u2014 the lengths of sequence a and b respectively. The second line contains n space-separated integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u2009200) \u2014 Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1,\u2009b2,\u2009...,\u2009bk (1\u2009\u2264\u2009bi\u2009\u2264\u2009200) \u2014 the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.", "output_spec": "Output \"Yes\" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and \"No\" otherwise.", "sample_inputs": ["4 2\n11 0 0 14\n5 4", "6 1\n2 3 0 8 9 10\n5", "4 1\n8 94 0 4\n89", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7"], "sample_outputs": ["Yes", "No", "Yes", "Yes"], "notes": "NoteIn the first sample: Sequence a is 11,\u20090,\u20090,\u200914. Two of the elements are lost, and the candidates in b are 5 and 4. There are two possible resulting sequences: 11,\u20095,\u20094,\u200914 and 11,\u20094,\u20095,\u200914, both of which fulfill the requirements. Thus the answer is \"Yes\". In the second sample, the only possible resulting sequence is 2,\u20093,\u20095,\u20098,\u20099,\u200910, which is an increasing sequence and therefore invalid."}, "src_uid": "40264e84c041fcfb4f8c0af784df102a"} {"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": "A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1\u2009\u2264\u2009i\u2009<\u2009n condition, that api\u00b7api\u2009+\u20091 is not perfect square, holds. Leha wants to find number of right permutations modulo 109\u2009+\u20097.", "input_spec": "First line of input data contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009300) \u2014 length of the array. Next line contains n integers a1,\u2009a2,\u2009... ,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009109) \u2014 found array.", "output_spec": "Output single integer \u2014 number of right permutations modulo 109\u2009+\u20097.", "sample_inputs": ["3\n1 2 4", "7\n5 2 4 2 4 1 1"], "sample_outputs": ["2", "144"], "notes": "NoteFor first example:[1,\u20092,\u20094] \u2014 right permutation, because 2 and 8 are not perfect squares.[1,\u20094,\u20092] \u2014 wrong permutation, because 4 is square of 2.[2,\u20091,\u20094] \u2014 wrong permutation, because 4 is square of 2.[2,\u20094,\u20091] \u2014 wrong permutation, because 4 is square of 2.[4,\u20091,\u20092] \u2014 wrong permutation, because 4 is square of 2.[4,\u20092,\u20091] \u2014 right permutation, because 8 and 2 are not perfect squares."}, "src_uid": "e00c5fde478d36c90b17f5df18fb3ed1"} {"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": "Marcin is a coach in his university. There are $$$n$$$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.Let's focus on the students. They are indexed with integers from $$$1$$$ to $$$n$$$. Each of them can be described with two integers $$$a_i$$$ and $$$b_i$$$; $$$b_i$$$ is equal to the skill level of the $$$i$$$-th student (the higher, the better). Also, there are $$$60$$$ known algorithms, which are numbered with integers from $$$0$$$ to $$$59$$$. If the $$$i$$$-th student knows the $$$j$$$-th algorithm, then the $$$j$$$-th bit ($$$2^j$$$) is set in the binary representation of $$$a_i$$$. Otherwise, this bit is not set.Student $$$x$$$ thinks that he is better than student $$$y$$$ if and only if $$$x$$$ knows some algorithm which $$$y$$$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 7000$$$) \u2014 the number of students interested in the camp. The second line contains $$$n$$$ integers. The $$$i$$$-th of them is $$$a_i$$$ ($$$0 \\leq a_i < 2^{60}$$$). The third line contains $$$n$$$ integers. The $$$i$$$-th of them is $$$b_i$$$ ($$$1 \\leq b_i \\leq 10^9$$$).", "output_spec": "Output one integer which denotes the maximum sum of $$$b_i$$$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.", "sample_inputs": ["4\n3 2 3 6\n2 8 5 10", "3\n1 2 3\n1 2 3", "1\n0\n1"], "sample_outputs": ["15", "0", "0"], "notes": "NoteIn the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $$$b_i$$$.In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset."}, "src_uid": "9404ec14922a69082f3573bbaf78ccf0"} {"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": "Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x\u2009=\u2009A\u2009\u00d7\u200910B is true. In our case A is between 0 and 9 and B is non-negative.Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.", "input_spec": "The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0\u2009\u2264\u2009a\u2009\u2264\u20099,\u20090\u2009\u2264\u2009d\u2009<\u200910100,\u20090\u2009\u2264\u2009b\u2009\u2264\u2009100)\u00a0\u2014 the scientific notation of the desired distance value. a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.", "output_spec": "Print the only real number x (the desired distance value) in the only line in its decimal notation. Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).", "sample_inputs": ["8.549e2", "8.549e3", "0.33e0"], "sample_outputs": ["854.9", "8549", "0.33"], "notes": null}, "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"nl": {"description": "Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games.BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They've got a sequence of n non-negative integers a1,\u2009a2,\u2009...,\u2009an. The players make moves in turns. BitLGM moves first. Each player can and must do one of the two following actions in his turn: Take one of the integers (we'll denote it as ai). Choose integer x (1\u2009\u2264\u2009x\u2009\u2264\u2009ai). And then decrease ai by x, that is, apply assignment: ai\u2009=\u2009ai\u2009-\u2009x. Choose integer x . And then decrease all ai by x, that is, apply assignment: ai\u2009=\u2009ai\u2009-\u2009x, for all i. The player who cannot make a move loses.You're given the initial sequence a1,\u2009a2,\u2009...,\u2009an. Determine who wins, if both players plays optimally well and if BitLGM and BitAryo start playing the described game in this sequence.", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u20093). The next line contains n integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009<\u2009300).", "output_spec": "Write the name of the winner (provided that both players play optimally well). Either \"BitLGM\" or \"BitAryo\" (without the quotes).", "sample_inputs": ["2\n1 1", "2\n1 2", "3\n1 2 1"], "sample_outputs": ["BitLGM", "BitAryo", "BitLGM"], "notes": null}, "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7"} {"nl": {"description": "The \"Bulls and Cows\" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format \"x bulls y cows\". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply \"1 bull 2 cows\" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be \"2 bulls 1 cow\" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one). When the guesser is answered \"4 bulls 0 cows\", the game is over.Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.", "input_spec": "The first input line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u200910) which represents the number of already made guesses. Then follow n lines in the form of \"ai bi ci\", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1\u2009\u2264\u2009i\u2009\u2264\u2009n, 0\u2009\u2264\u2009bi,\u2009ci,\u2009bi\u2009+\u2009ci\u2009\u2264\u20094). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer \"4 bulls 0 cows\" is not present.", "output_spec": "If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print \"Need more data\" without the quotes. If the thinker happens to have made a mistake in his replies, print \"Incorrect data\" without the quotes.", "sample_inputs": ["2\n1263 1 2\n8103 2 1", "2\n1234 2 2\n1256 0 2", "2\n0123 1 1\n4567 1 2"], "sample_outputs": ["Need more data", "2134", "Incorrect data"], "notes": null}, "src_uid": "142e5f2f08724e53c234fc2379216b4c"} {"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": "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": "Serge, the chef of the famous restaurant \"Salt, Pepper & Garlic\" is trying to obtain his first Michelin star. He has been informed that a secret expert plans to visit his restaurant this evening.Even though the expert's name hasn't been disclosed, Serge is certain he knows which dish from the menu will be ordered as well as what the taste preferences of the expert are. Namely, the expert requires an extremely precise proportion of salt, pepper and garlic powder in his dish.Serge keeps a set of bottles with mixtures of salt, pepper and garlic powder on a special shelf in the kitchen. For each bottle, he knows the exact amount of each of the ingredients in kilograms. Serge can combine any number of bottled mixtures (or just use one of them directly) to get a mixture of particular proportions needed for a certain dish.Luckily, the absolute amount of a mixture that needs to be added to a dish is so small that you can assume that the amounts in the bottles will always be sufficient. However, the numeric values describing the proportions may be quite large.Serge would like to know whether it is possible to obtain the expert's favourite mixture from the available bottles, and if so\u2014what is the smallest possible number of bottles needed to achieve that.Furthermore, the set of bottles on the shelf may change over time as Serge receives new ones or lends his to other chefs. So he would like to answer this question after each such change.For example, assume that expert's favorite mixture is $$$1:1:1$$$ and there are three bottles of mixtures on the shelf: $$$$$$ \\begin{array}{cccc} \\hline \\text{Mixture} & \\text{Salt} & \\text{Pepper} & \\text{Garlic powder} \\\\ \\hline 1 & 10 & 20 & 30 \\\\ 2 & 300 & 200 & 100 \\\\ 3 & 12 & 15 & 27 \\\\ \\hline \\end{array} $$$$$$ Amount of ingredient in the bottle, kg To obtain the desired mixture it is enough to use an equivalent amount of mixtures from bottles 1 and 2. If bottle 2 is removed, then it is no longer possible to obtain it.Write a program that helps Serge to solve this task!", "input_spec": "The first row contains three non-negative integers $$$S_f$$$, $$$P_f$$$ and $$$G_f$$$ ($$$0 \\leq S_f, P_f, G_f$$$; $$$0 < S_f+P_f+G_f \\leq 10^6$$$) describing the amount of salt, pepper and garlic powder in the expert's favourite mixture. For any real $$$\\alpha>0$$$, $$$(\\alpha{S_f}, \\alpha{P_f}, \\alpha{G_f})$$$ also is an expert's favourite mixture. In the second row, there is a positive integer $$$N$$$ (number of changes on the shelf, $$$N \\leq 100\\,000$$$). You should assume that initially the shelf is empty. Each of the next $$$N$$$ rows describes a single change on the shelf: If a new bottle is added, the row contains capital letter $$$A$$$ followed by three non-negative integers $$$S_i$$$, $$$P_i$$$ and $$$G_i$$$ ($$$0 \\leq S_i, P_i, G_i$$$; $$$0 < S_i+P_i+G_i \\leq 10^6$$$) describing the amount of salt, pepper and garlic powder in the added bottle. Added bottles are numbered consecutively by unique integers starting from $$$1$$$, that is, the $$$i$$$-th bottle corresponds to the $$$i$$$-th added bottle in the input data. If a particular bottle is removed from the shelf, the row contains capital letter $$$R$$$ followed by the integer\u2014the bottle number $$$r_i$$$. All values $$$r_i$$$ in the removals are unique, $$$r_i$$$ never exceeds total number of bottles added thus far. ", "output_spec": "Output $$$N$$$ rows. The $$$j$$$-th row ($$$1 \\leq j \\leq N$$$) should contain the number $$$x_j$$$, the smallest number of bottles needed to prepare a mixture with the expert's favourite proportions of salt, pepper and garlic powder using the bottles available after the first $$$j$$$ changes on the shelf, or $$$0$$$ if it is not possible.", "sample_inputs": ["1 2 3\n6\nA 5 6 7\nA 3 10 17\nR 1\nA 15 18 21\nA 5 10 15\nR 3"], "sample_outputs": ["0\n2\n0\n2\n1\n1"], "notes": "NotePay attention that in the example, bottles $$$1$$$ and $$$3$$$ contain the same proportions of salt, pepper and garlic powder."}, "src_uid": "ea995d5c5fe84cd175cda0d0e2f01889"} {"nl": {"description": "A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions \u2014 moving or idle. Every minute the players move.The controller's move is as follows. The controller has the movement direction \u2014 to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move.The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back.Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train.If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again.At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner.", "input_spec": "The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2\u2009\u2264\u2009n\u2009\u2264\u200950, 1\u2009\u2264\u2009m,\u2009k\u2009\u2264\u2009n, m\u2009\u2260\u2009k). The second line contains the direction in which a controller moves. \"to head\" means that the controller moves to the train's head and \"to tail\" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail. The third line has the length from 1 to 200 and consists of symbols \"0\" and \"1\". The i-th symbol contains information about the train's state at the i-th minute of time. \"0\" means that in this very minute the train moves and \"1\" means that the train in this very minute stands idle. The last symbol of the third line is always \"1\" \u2014 that's the terminal train station.", "output_spec": "If the stowaway wins, print \"Stowaway\" without quotes. Otherwise, print \"Controller\" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught.", "sample_inputs": ["5 3 2\nto head\n0001001", "3 2 1\nto tail\n0001"], "sample_outputs": ["Stowaway", "Controller 2"], "notes": null}, "src_uid": "2222ce16926fdc697384add731819f75"} {"nl": {"description": "Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1\u2009=\u2009a, another one is in the point x2\u2009=\u2009b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third\u00a0\u2014 by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1\u2009+\u20092\u2009+\u20093\u2009=\u20096.The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.", "input_spec": "The first line contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u20091000) \u2014 the initial position of the first friend. The second line contains a single integer b (1\u2009\u2264\u2009b\u2009\u2264\u20091000) \u2014 the initial position of the second friend. It is guaranteed that a\u2009\u2260\u2009b.", "output_spec": "Print the minimum possible total tiredness if the friends meet in the same point.", "sample_inputs": ["3\n4", "101\n99", "5\n10"], "sample_outputs": ["1", "2", "9"], "notes": "NoteIn the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1\u2009+\u20091\u2009=\u20092.In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend \u2014 two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1\u2009+\u20092\u2009+\u20093\u2009+\u20091\u2009+\u20092\u2009=\u20099."}, "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"} {"nl": {"description": "Jzzhu has invented a kind of sequences, they meet the following property:You are given x and y, please calculate fn modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line contains two integers x and y (|x|,\u2009|y|\u2009\u2264\u2009109). The second line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7109).", "output_spec": "Output a single integer representing fn modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["2 3\n3", "0 -1\n2"], "sample_outputs": ["1", "1000000006"], "notes": "NoteIn the first sample, f2\u2009=\u2009f1\u2009+\u2009f3, 3\u2009=\u20092\u2009+\u2009f3, f3\u2009=\u20091.In the second sample, f2\u2009=\u2009\u2009-\u20091; \u2009-\u20091 modulo (109\u2009+\u20097) equals (109\u2009+\u20096)."}, "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"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": "You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B\u2009-\u2009C?", "input_spec": "The first line contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of elements in a. The second line contains n integers a1, a2, ..., an (\u2009-\u2009100\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the elements of sequence a.", "output_spec": "Print the maximum possible value of B\u2009-\u2009C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.", "sample_inputs": ["3\n1 -2 0", "6\n16 23 16 15 42 8"], "sample_outputs": ["3", "120"], "notes": "NoteIn the first example we may choose b\u2009=\u2009{1,\u20090}, c\u2009=\u2009{\u2009-\u20092}. Then B\u2009=\u20091, C\u2009=\u2009\u2009-\u20092, B\u2009-\u2009C\u2009=\u20093.In the second example we choose b\u2009=\u2009{16,\u200923,\u200916,\u200915,\u200942,\u20098}, c\u2009=\u2009{} (an empty sequence). Then B\u2009=\u2009120, C\u2009=\u20090, B\u2009-\u2009C\u2009=\u2009120."}, "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"nl": {"description": "\u041f\u0430\u043c\u044f\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 n \u044f\u0447\u0435\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0432 \u0440\u044f\u0434. \u041f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u0443\u0435\u043c \u044f\u0447\u0435\u0439\u043a\u0438 \u043e\u0442 1 \u0434\u043e n \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e. \u041f\u0440\u043e \u043a\u0430\u0436\u0434\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430 \u043e\u043d\u0430 \u0438\u043b\u0438 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u0430\u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 (\u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442).\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0435\u043c\u0443 \u044f\u0447\u0435\u0439\u043a\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u0438\u0434\u0430 \u00ab\u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0437\u0430\u043d\u044f\u0442\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e, \u0430 \u0437\u0430\u043d\u044f\u0442\u0443\u044e \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439\u00bb \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u044f\u0447\u0435\u0439\u043a\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043b\u044e\u0431\u0430\u044f \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0430\u0432\u0435\u0435 (\u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u043d\u043e\u043c\u0435\u0440) \u043b\u044e\u0431\u043e\u0439 \u0437\u0430\u043d\u044f\u0442\u043e\u0439.\u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e, \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u044f\u0447\u0435\u0435\u043a \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0430\u043c\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u044f\u0447\u0435\u0439\u043a\u0438, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 i, \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0445 \u044f\u0447\u0435\u0435\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 j, \u0442\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0439 \u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f.\u0421\u0447\u0438\u0442\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u043d\u043e\u043c\u0435\u0440\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b, \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0437\u0430\u043d\u044f\u0442\u0430 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c.", "input_spec": "\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0447\u0438\u0441\u043b\u043e n (1\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000)\u00a0\u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044f\u0447\u0435\u0435\u043a \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 n \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009n), \u0433\u0434\u0435 ai \u0440\u0430\u0432\u043d\u043e \u043b\u0438\u0431\u043e 0 (\u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e i-\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430), \u043b\u0438\u0431\u043e \u043d\u043e\u043c\u0435\u0440\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 i-\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 ai \u043d\u0435 \u0440\u0430\u0432\u043d\u043e 0. \u041f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u044b \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043e\u0442 1 \u0434\u043e n \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438.", "output_spec": "\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\u00a0\u2014 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0435\u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438.", "sample_inputs": ["4\n0 2 2 1", "8\n0 8 8 8 0 4 4 2"], "sample_outputs": ["2", "4"], "notes": "\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0432\u0443\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439: \u041f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434: 2\u00a02\u00a00\u00a01. \u041f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u0432 \u0442\u0440\u0435\u0442\u044c\u044e. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434: 2\u00a02\u00a01\u00a00. "}, "src_uid": "9135c7243431debb049f640e9600bc6e"} {"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": "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": "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": "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": "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": "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": "In Berland prime numbers are fashionable \u2014 the respectable citizens dwell only on the floors with numbers that are prime numbers. The numismatists value particularly high the coins with prime nominal values. All the prime days are announced holidays!Yet even this is not enough to make the Berland people happy. On the main street of the capital stand n houses, numbered from 1 to n. The government decided to paint every house a color so that the sum of the numbers of the houses painted every color is a prime number.However it turned out that not all the citizens approve of this decision \u2014 many of them protest because they don't want many colored houses on the capital's main street. That's why it is decided to use the minimal possible number of colors. The houses don't have to be painted consecutively, but every one of n houses should be painted some color. The one-colored houses should not stand consecutively, any way of painting is acceptable.There are no more than 5 hours left before the start of painting, help the government find the way when the sum of house numbers for every color is a prime number and the number of used colors is minimal. ", "input_spec": "The single input line contains an integer n (2\u2009\u2264\u2009n\u2009\u2264\u20096000) \u2014 the number of houses on the main streets of the capital.", "output_spec": "Print the sequence of n numbers, where the i-th number stands for the number of color for house number i. Number the colors consecutively starting from 1. Any painting order is allowed. If there are several solutions to that problem, print any of them. If there's no such way of painting print the single number -1.", "sample_inputs": ["8"], "sample_outputs": ["1 2 2 1 1 1 1 2"], "notes": null}, "src_uid": "94ef0d901f21e1945849fd5bfc2d1449"} {"nl": {"description": "While most students still sit their exams, the tractor college has completed the summer exam session. In fact, students study only one subject at this college \u2014 the Art of Operating a Tractor. Therefore, at the end of a term a student gets only one mark, a three (satisfactory), a four (good) or a five (excellent). Those who score lower marks are unfortunately expelled.The college has n students, and oddly enough, each of them can be on scholarship. The size of the scholarships varies each term. Since the end-of-the-term exam has just ended, it's time to determine the size of the scholarship to the end of next term.The monthly budget for the scholarships of the Tractor college is s rubles. To distribute the budget optimally, you must follow these rules: The students who received the same mark for the exam, should receive the same scholarship; Let us denote the size of the scholarship (in roubles) for students who have received marks 3, 4 and 5 for the exam, as k3, k4 and k5, respectively. The values k3, k4 and k5 must be integers and satisfy the inequalities 0\u2009\u2264\u2009k3\u2009\u2264\u2009k4\u2009\u2264\u2009k5; Let's assume that c3, c4, c5 show how many students received marks 3, 4 and 5 for the exam, respectively. The budget of the scholarship should be fully spent on them, that is, c3\u00b7k3\u2009+\u2009c4\u00b7k4\u2009+\u2009c5\u00b7k5\u2009=\u2009s; Let's introduce function \u2014 the value that shows how well the scholarships are distributed between students. In the optimal distribution function f(k3,\u2009k4,\u2009k5) takes the minimum possible value. Given the results of the exam, and the budget size s, you have to find the optimal distribution of the scholarship.", "input_spec": "The first line has two integers n, s (3\u2009\u2264\u2009n\u2009\u2264\u2009300,\u20091\u2009\u2264\u2009s\u2009\u2264\u20093\u00b7105) \u2014 the number of students and the budget size for the scholarship, respectively. The second line contains n integers, where the i-th number represents the mark that the i-th student got for the exam. It is guaranteed that at each mark was given to at least one student.", "output_spec": "On a single line print three integers k3, k4 and k5 \u2014 the sought values that represent the optimal distribution of the scholarships. If there are multiple optimal answers, print any of them. If there is no answer, print -1.", "sample_inputs": ["5 11\n3 4 3 5 5", "6 15\n5 3 3 4 4 5"], "sample_outputs": ["1 3 3", "-1"], "notes": null}, "src_uid": "3f3eb49a127768139283ac04ee44950f"} {"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": "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": "InputThe input contains a single integer $$$a$$$ ($$$1 \\le a \\le 99$$$).OutputOutput \"YES\" or \"NO\".ExamplesInput\n5\nOutput\nYES\nInput\n13\nOutput\nNO\nInput\n24\nOutput\nNO\nInput\n46\nOutput\nYES\n", "input_spec": "The input contains a single integer $$$a$$$ ($$$1 \\le a \\le 99$$$).", "output_spec": "Output \"YES\" or \"NO\".", "sample_inputs": ["5", "13", "24", "46"], "sample_outputs": ["YES", "NO", "NO", "YES"], "notes": null}, "src_uid": "821529a4644b74483bcdf80fc318d1f8"} {"nl": {"description": "On the surface of a newly discovered planet, which we model by a plane, explorers found remains of two different civilizations in various locations. They would like to learn more about those civilizations and to explore the area they need to build roads between some of locations. But as always, there are some restrictions: Every two locations of the same civilization are connected by a unique path of roads No two locations from different civilizations may have road between them (explorers don't want to accidentally mix civilizations they are currently exploring) Roads must be straight line segments Since intersections are expensive to build, they don't want any two roads to intersect (that is, only common point for any two roads may be at some of locations) Obviously all locations are different points in the plane, but explorers found out one more interesting information that may help you \u2013 no three locations lie on the same line!Help explorers and find a solution for their problem, or report it is impossible.", "input_spec": "In the first line, integer $$$n$$$ $$$(1 \\leq n \\leq 10^3)$$$ - the number of locations discovered. In next $$$n$$$ lines, three integers $$$x, y, c$$$ $$$(0 \\leq x, y \\leq 10^4, c \\in \\{0, 1\\})$$$ - coordinates of the location and number of civilization it belongs to.", "output_spec": "In first line print number of roads that should be built. In the following lines print all pairs of locations (their $$$0$$$-based indices) that should be connected with a road. If it is not possible to build roads such that all restrictions are met, print \"Impossible\". You should not print the quotation marks.", "sample_inputs": ["5\n0 0 1\n1 0 0\n0 1 0\n1 1 1\n3 2 0"], "sample_outputs": ["3\n1 4\n4 2\n3 0"], "notes": null}, "src_uid": "3bc096d8cd3418948d5be6bf297aa9b5"} {"nl": {"description": "John Doe has an n\u2009\u00d7\u2009m table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size n\u2009\u00d7\u2009n have exactly k points.John Doe wondered, how many distinct ways to fill the table with points are there, provided that the condition must hold. As this number can be rather large, John Doe asks to find its remainder after dividing by 1000000007 (109\u2009+\u20097).You should assume that John always paints a point exactly in the center of some cell. Two ways to fill a table are considered distinct, if there exists a table cell, that has a point in one way and doesn't have it in the other.", "input_spec": "A single line contains space-separated integers n, m, k (1\u2009\u2264\u2009n\u2009\u2264\u2009100;\u00a0n\u2009\u2264\u2009m\u2009\u2264\u20091018;\u00a00\u2009\u2264\u2009k\u2009\u2264\u2009n2) \u2014 the number of rows of the table, the number of columns of the table and the number of points each square must contain. 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": "In a single line print a single integer \u2014 the remainder from dividing the described number of ways by 1000000007 (109\u2009+\u20097).", "sample_inputs": ["5 6 1"], "sample_outputs": ["45"], "notes": "NoteLet's consider the first test case: The gray area belongs to both 5\u2009\u00d7\u20095 squares. So, if it has one point, then there shouldn't be points in any other place. If one of the white areas has a point, then the other one also must have a point. Thus, there are about 20 variants, where the point lies in the gray area and 25 variants, where each of the white areas contains a point. Overall there are 45 variants."}, "src_uid": "9c71c8e031412e2bb21266a53821626a"} {"nl": {"description": "You are given two arithmetic progressions: a1k\u2009+\u2009b1 and a2l\u2009+\u2009b2. Find the number of integers x such that L\u2009\u2264\u2009x\u2009\u2264\u2009R and x\u2009=\u2009a1k'\u2009+\u2009b1\u2009=\u2009a2l'\u2009+\u2009b2, for some integers k',\u2009l'\u2009\u2265\u20090.", "input_spec": "The only line contains six integers a1,\u2009b1,\u2009a2,\u2009b2,\u2009L,\u2009R (0\u2009<\u2009a1,\u2009a2\u2009\u2264\u20092\u00b7109,\u2009\u2009-\u20092\u00b7109\u2009\u2264\u2009b1,\u2009b2,\u2009L,\u2009R\u2009\u2264\u20092\u00b7109,\u2009L\u2009\u2264\u2009R).", "output_spec": "Print the desired number of integers x.", "sample_inputs": ["2 0 3 3 5 21", "2 4 3 0 6 17"], "sample_outputs": ["3", "2"], "notes": null}, "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4"} {"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": "Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: deletes all the vowels, inserts a character \".\" before each consonant, replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters \"A\", \"O\", \"Y\", \"E\", \"U\", \"I\", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.Help Petya cope with this easy task.", "input_spec": "The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.", "output_spec": "Print the resulting string. It is guaranteed that this string is not empty.", "sample_inputs": ["tour", "Codeforces", "aBAcAba"], "sample_outputs": [".t.r", ".c.d.f.r.c.s", ".b.c.b"], "notes": null}, "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"nl": {"description": "Today is Mashtali's birthday! He received a Hagh tree from Haj Davood as his birthday present!A directed tree is called a Hagh tree iff: The length of the longest directed path in it is exactly $$$n$$$. Every vertex has at most three edges attached to it independent of their orientation. Let's call vertices $$$u$$$ and $$$v$$$ friends if one of them has a directed path to the other. For every pair of vertices $$$u$$$ and $$$v$$$ that are not friends, there should exist a vertex $$$w$$$ that is friends with both $$$u$$$ and $$$v$$$ (a mutual friend). After opening his gift, Mashtali found out that the labels on the vertices were gone.Immediately, he asked himself: how many different unlabeled Hagh trees are there? That is, how many possible trees could he have received as his birthday present?At the first glance, the number of such trees seemed to be infinite since there was no limit on the number of vertices; but then he solved the problem and proved that there's a finite number of unlabeled Hagh trees!Amazed by this fact, he shared the task with you so that you could enjoy solving it as well. Since the answer can be rather large he asked you to find the number of different unlabeled Hagh trees modulo $$$998244353$$$.Here two trees are considered different, if they are not isomorphic: if there is no way to map nodes of one tree to the second tree, so that edges are mapped to edges preserving the orientation.Some examples for $$$n = 2$$$: Directed trees $$$D$$$ and $$$E$$$ are Hagh. $$$C$$$ is not Hagh because it has a vertex with $$$4$$$ edges attached to it. $$$A$$$ and $$$B$$$ are not Hagh because their longest directed paths are not equal to $$$n$$$. Also in $$$B$$$ the leftmost and rightmost vertices are not friends neither do they have a mutual friend.", "input_spec": "The first line of input contains a single integer $$$n$$$ $$$(1 \\le n \\le 10^6)$$$.", "output_spec": "Print a single integer, the answer to Mashtali's task modulo $$$998244353$$$.", "sample_inputs": ["1", "2", "344031"], "sample_outputs": ["5", "31", "272040628"], "notes": "NoteAll the five Hagh trees for $$$n = 1$$$: "}, "src_uid": "92939054045c089cd25c8f4e7b9ffcf2"} {"nl": {"description": "There is a straight line colored in white. n black segments are added on it one by one.After each segment is added, determine the number of connected components of black segments (i.\u00a0e. the number of black segments in the union of the black segments). In particular, if one segment ends in a point x, and another segment starts in the point x, these two segments belong to the same connected component.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000) \u2014 the number of segments. The i-th of the next n lines contains two integers li and ri (1\u2009\u2264\u2009li\u2009<\u2009ri\u2009\u2264\u2009109) \u2014 the coordinates of the left and the right ends of the i-th segment. The segments are listed in the order they are added on the white line.", "output_spec": "Print n integers \u2014 the number of connected components of black segments after each segment is added. ", "sample_inputs": ["3\n1 3\n4 5\n2 4", "9\n10 20\n50 60\n30 40\n70 80\n90 100\n60 70\n10 40\n40 50\n80 90"], "sample_outputs": ["1 2 1", "1 2 3 4 5 4 3 2 1"], "notes": "NoteIn the first example there are two components after the addition of the first two segments, because these segments do not intersect. The third added segment intersects the left segment and touches the right segment at the point 4 (these segments belong to the same component, according to the statements). Thus the number of connected components of black segments is equal to 1 after that."}, "src_uid": "3979abbe7bad0f3b5cab15c1cba19f6b"} {"nl": {"description": "Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?", "input_spec": "The input contains a single integer n (0\u2009\u2264\u2009n\u2009\u2264\u20092000000000).", "output_spec": "Output a single integer.", "sample_inputs": ["11", "14", "61441", "571576", "2128506"], "sample_outputs": ["2", "0", "2", "10", "3"], "notes": null}, "src_uid": "16a784cb9953bc91cb2e7767b04b76f2"} {"nl": {"description": "One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that the boat can hold people with the total weight of at most k kilograms.Greg immediately took a piece of paper and listed there the weights of all people in his group (including himself). It turned out that each person weights either 50 or 100 kilograms. Now Greg wants to know what minimum number of times the boat needs to cross the river to transport the whole group to the other bank. The boat needs at least one person to navigate it from one bank to the other. As the boat crosses the river, it can have any non-zero number of passengers as long as their total weight doesn't exceed k.Also Greg is wondering, how many ways there are to transport everybody to the other side in the minimum number of boat rides. Two ways are considered distinct if during some ride they have distinct sets of people on the boat.Help Greg with this problem. ", "input_spec": "The first line contains two integers n, k (1\u2009\u2264\u2009n\u2009\u2264\u200950,\u20091\u2009\u2264\u2009k\u2009\u2264\u20095000) \u2014 the number of people, including Greg, and the boat's weight limit. The next line contains n integers \u2014 the people's weights. A person's weight is either 50 kilos or 100 kilos. You can consider Greg and his friends indexed in some way.", "output_spec": "In the first line print an integer \u2014 the minimum number of rides. If transporting everyone to the other bank is impossible, print an integer -1. In the second line print the remainder after dividing the number of ways to transport the people in the minimum number of rides by number 1000000007 (109\u2009+\u20097). If transporting everyone to the other bank is impossible, print integer 0.", "sample_inputs": ["1 50\n50", "3 100\n50 50 100", "2 50\n50 50"], "sample_outputs": ["1\n1", "5\n2", "-1\n0"], "notes": "NoteIn the first test Greg walks alone and consequently, he needs only one ride across the river.In the second test you should follow the plan: transport two 50 kg. people; transport one 50 kg. person back; transport one 100 kg. person; transport one 50 kg. person back; transport two 50 kg. people. That totals to 5 rides. Depending on which person to choose at step 2, we can get two distinct ways."}, "src_uid": "ebb0323a854e19794c79ab559792a1f7"} {"nl": {"description": "You are given two positive integers $$$a$$$ and $$$b$$$. There are two possible operations: multiply one of the numbers by some prime $$$p$$$; divide one of the numbers on its prime factor $$$p$$$. What is the minimum number of operations required to obtain two integers having the same number of divisors? You are given several such pairs, you need to find the answer for each of them.", "input_spec": "The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^5$$$) \u2014 the number of pairs of integers for which you are to find the answer. Each of the next $$$t$$$ lines contain two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \\le a_i, b_i \\le 10^6$$$).", "output_spec": "Output $$$t$$$ lines \u2014 the $$$i$$$-th of them should contain the answer for the pair $$$a_i$$$, $$$b_i$$$.", "sample_inputs": ["8\n9 10\n100 17\n220 70\n17 19\n4 18\n32 20\n100 32\n224 385"], "sample_outputs": ["1\n3\n1\n0\n1\n0\n1\n1"], "notes": "NoteThese are the numbers with equal number of divisors, which are optimal to obtain in the sample test case: $$$(27, 10)$$$, 4 divisors $$$(100, 1156)$$$, 9 divisors $$$(220, 140)$$$, 12 divisors $$$(17, 19)$$$, 2 divisors $$$(12, 18)$$$, 6 divisors $$$(50, 32)$$$, 6 divisors $$$(224, 1925)$$$, 12 divisors Note that there can be several optimal pairs of numbers."}, "src_uid": "6115ee1ccf651b1dd8145bf755ea7ea9"} {"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": "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": " *The two images are equivalent, feel free to use either one.", "input_spec": "The input contains a single integer $$$a$$$ ($$$-100 \\le a \\le 100$$$).", "output_spec": "Output the result \u2013 an integer number.", "sample_inputs": ["1"], "sample_outputs": ["1"], "notes": null}, "src_uid": "f76005f888df46dac38b0f159ca04d5f"} {"nl": {"description": "Those unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there's nothing to do with this before a cure is figured out. For now, she would only like to know the enormous number of possibilities to be faced with if someone gets lost.There are n towns in the region, numbered from 1 to n. The town numbered 1 is called the capital. The traffic network is formed by bidirectional roads connecting pairs of towns. No two roads connect the same pair of towns, and no road connects a town with itself. The time needed to travel through each of the roads is the same. Lost travelers will not be able to find out how the towns are connected, but the residents can help them by providing the following facts: Starting from each town other than the capital, the shortest path (i.e. the path passing through the minimum number of roads) to the capital exists, and is unique; Let li be the number of roads on the shortest path from town i to the capital, then li\u2009\u2265\u2009li\u2009-\u20091 holds for all 2\u2009\u2264\u2009i\u2009\u2264\u2009n; For town i, the number of roads connected to it is denoted by di, which equals either 2 or 3. You are to count the number of different ways in which the towns are connected, and give the answer modulo 109\u2009+\u20097. Two ways of connecting towns are considered different if a pair (u,\u2009v) (1\u2009\u2264\u2009u,\u2009v\u2009\u2264\u2009n) exists such there is a road between towns u and v in one of them but not in the other.", "input_spec": "The first line of input contains a positive integer n (3\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the number of towns. The second line contains n space-separated integers d1,\u2009d2,\u2009...,\u2009dn (2\u2009\u2264\u2009di\u2009\u2264\u20093) \u2014 the number of roads connected to towns 1,\u20092,\u2009...,\u2009n, respectively. It is guaranteed that the sum of di over all i is even.", "output_spec": "Output one integer \u2014 the total number of different possible ways in which the towns are connected, modulo 109\u2009+\u20097.", "sample_inputs": ["4\n3 2 3 2", "5\n2 3 3 2 2", "5\n2 2 2 2 2", "20\n2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 3 3 2"], "sample_outputs": ["1", "2", "2", "82944"], "notes": "NoteIn the first example, the following structure is the only one to satisfy the constraints, the distances from towns 2,\u20093,\u20094 to the capital are all 1. In the second example, the following two structures satisfy the constraints. "}, "src_uid": "db884d679d9cfb1dc4bc511f83beedda"} {"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": "This is the easy version of the problem. The only difference is that in this version $$$q=1$$$. You can make hacks only if all versions of the problem are solved.Zookeeper has been teaching his $$$q$$$ sheep how to write and how to add. The $$$i$$$-th sheep has to write exactly $$$k$$$ non-negative integers with the sum $$$n_i$$$.Strangely, sheep have superstitions about digits and believe that the digits $$$3$$$, $$$6$$$, and $$$9$$$ are lucky. To them, the fortune of a number depends on the decimal representation of the number; the fortune of a number is equal to the sum of fortunes of its digits, and the fortune of a digit depends on its value and position and can be described by the following table. For example, the number $$$319$$$ has fortune $$$F_{2} + 3F_{0}$$$. Each sheep wants to maximize the sum of fortune among all its $$$k$$$ written integers. Can you help them?", "input_spec": "The first line contains a single integer $$$k$$$ ($$$1 \\leq k \\leq 999999$$$): the number of numbers each sheep has to write. The next line contains six integers $$$F_0$$$, $$$F_1$$$, $$$F_2$$$, $$$F_3$$$, $$$F_4$$$, $$$F_5$$$ ($$$1 \\leq F_i \\leq 10^9$$$): the fortune assigned to each digit. The next line contains a single integer $$$q$$$ ($$$q = 1$$$): the number of sheep. Each of the next $$$q$$$ lines contains a single integer $$$n_i$$$ ($$$1 \\leq n_i \\leq 999999$$$): the sum of numbers that $$$i$$$-th sheep has to write. In this version, there is only one line.", "output_spec": "Print $$$q$$$ lines, where the $$$i$$$-th line contains the maximum sum of fortune of all numbers of the $$$i$$$-th sheep. In this version, you should print only one line.", "sample_inputs": ["3\n1 2 3 4 5 6\n1\n57", "3\n1 2 3 4 5 6\n1\n63"], "sample_outputs": ["11", "8"], "notes": "NoteIn the first test case, $$$57 = 9 + 9 + 39$$$. The three $$$9$$$'s contribute $$$1 \\cdot 3$$$ and $$$3$$$ at the tens position contributes $$$2 \\cdot 1$$$. Hence the sum of fortune is $$$11$$$.In the second test case, $$$63 = 35 + 19 + 9$$$. The sum of fortune is $$$8$$$."}, "src_uid": "92bcbac3f167a44c235e99afc4de20d2"} {"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": "This is an interactive problem.The judge has a hidden rooted full binary tree with n leaves. A full binary tree is one where every node has either 0 or 2 children. The nodes with 0 children are called the leaves of the tree. Since this is a full binary tree, there are exactly 2n\u2009-\u20091 nodes in the tree. The leaves of the judge's tree has labels from 1 to n. You would like to reconstruct a tree that is isomorphic to the judge's tree. To do this, you can ask some questions.A question consists of printing the label of three distinct leaves a1,\u2009a2,\u2009a3. Let the depth of a node be the shortest distance from the node to the root of the tree. Let LCA(a,\u2009b) denote the node with maximum depth that is a common ancestor of the nodes a and b.Consider X\u2009=\u2009LCA(a1,\u2009a2),\u2009Y\u2009=\u2009LCA(a2,\u2009a3),\u2009Z\u2009=\u2009LCA(a3,\u2009a1). The judge will tell you which one of X,\u2009Y,\u2009Z has the maximum depth. Note, this pair is uniquely determined since the tree is a binary tree; there can't be any ties. More specifically, if X (or Y, Z respectively) maximizes the depth, the judge will respond with the string \"X\" (or \"Y\", \"Z\" respectively). You may only ask at most 10\u00b7n questions.", "input_spec": "The first line of input will contain a single integer n (3\u2009\u2264\u2009n\u2009\u2264\u20091\u2009000)\u00a0\u2014 the number of leaves in the tree.", "output_spec": "To print the final answer, print out the string \"-1\" on its own line. Then, the next line should contain 2n\u2009-\u20091 integers. The i-th integer should be the parent of the i-th node, or -1, if it is the root. Your answer will be judged correct if your output is isomorphic to the judge's tree. In particular, the labels of the leaves do not need to be labeled from 1 to n. Here, isomorphic means that there exists a permutation \u03c0 such that node i is the parent of node j in the judge tree if and only node \u03c0(i) is the parent of node \u03c0(j) in your tree.", "sample_inputs": ["5\nX\nZ\nY\nY\nX"], "sample_outputs": ["1 4 2\n1 2 4\n2 4 1\n2 3 5\n2 4 3\n-1\n-1 1 1 2 2 3 3 6 6"], "notes": "NoteFor the first sample, the judge has the hidden tree:Here is a more readable format of the interaction: The last line can also be 8 6 9 8 9 7 -1 6 7. "}, "src_uid": "756b46a85b91346e189bb7c7646aa54f"} {"nl": {"description": "You are given a square board, consisting of $$$n$$$ rows and $$$n$$$ columns. Each tile in it should be colored either white or black.Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.Let's call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least $$$k$$$ tiles.Your task is to count the number of suitable colorings of the board of the given size.Since the answer can be very large, print it modulo $$$998244353$$$.", "input_spec": "A single line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 500$$$, $$$1 \\le k \\le n^2$$$) \u2014 the number of rows and columns of the board and the maximum number of tiles inside the rectangle of the single color, respectively.", "output_spec": "Print a single integer \u2014 the number of suitable colorings of the board of the given size modulo $$$998244353$$$.", "sample_inputs": ["1 1", "2 3", "49 1808"], "sample_outputs": ["0", "6", "359087121"], "notes": "NoteBoard of size $$$1 \\times 1$$$ is either a single black tile or a single white tile. Both of them include a rectangle of a single color, consisting of $$$1$$$ tile.Here are the beautiful colorings of a board of size $$$2 \\times 2$$$ that don't include rectangles of a single color, consisting of at least $$$3$$$ tiles: The rest of beautiful colorings of a board of size $$$2 \\times 2$$$ are the following: "}, "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b"} {"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": "Professional sport is more than hard work. It also is the equipment, designed by top engineers. As an example, let's take tennis. Not only should you be in great shape, you also need an excellent racket! In this problem your task is to contribute to the development of tennis and to help to design a revolutionary new concept of a racket!The concept is a triangular racket. Ant it should be not just any triangle, but a regular one. As soon as you've chosen the shape, you need to stretch the net. By the time you came the rocket had n holes drilled on each of its sides. The holes divide each side into equal n\u2009+\u20091 parts. At that, the m closest to each apex holes on each side are made for better ventilation only and you cannot stretch the net through them. The next revolutionary idea as to stretch the net as obtuse triangles through the holes, so that for each triangle all apexes lay on different sides. Moreover, you need the net to be stretched along every possible obtuse triangle. That's where we need your help \u2014 help us to count the number of triangles the net is going to consist of.Two triangles are considered to be different if their pictures on the fixed at some position racket are different.", "input_spec": "The first and the only input line contains two integers n, m .", "output_spec": "Print a single number \u2014 the answer to the problem.", "sample_inputs": ["3 0", "4 0", "10 1", "8 4"], "sample_outputs": ["9", "24", "210", "0"], "notes": "NoteFor the following picture n\u2009=\u20098, m\u2009=\u20092. White circles are the holes for ventilation, red circles \u2014 holes for net stretching. One of the possible obtuse triangles is painted red. "}, "src_uid": "355cc23d7a4addfc920c6e5e72a2bb64"} {"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": "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": "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": "Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number.For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109\u2009+\u20097).A number's length is the number of digits in its decimal representation without leading zeroes.", "input_spec": "The first line contains three integers: a, b, n (1\u2009\u2264\u2009a\u2009<\u2009b\u2009\u2264\u20099,\u20091\u2009\u2264\u2009n\u2009\u2264\u2009106).", "output_spec": "Print a single integer \u2014 the answer to the problem modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1 3 3", "2 3 10"], "sample_outputs": ["1", "165"], "notes": null}, "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81"} {"nl": {"description": "John Doe decided that some mathematical object must be named after him. So he invented the Doe graphs. The Doe graphs are a family of undirected graphs, each of them is characterized by a single non-negative number \u2014 its order. We'll denote a graph of order k as D(k), and we'll denote the number of vertices in the graph D(k) as |D(k)|. Then let's define the Doe graphs as follows: D(0) consists of a single vertex, that has number 1. D(1) consists of two vertices with numbers 1 and 2, connected by an edge. D(n) for n\u2009\u2265\u20092 is obtained from graphs D(n\u2009-\u20091) and D(n\u2009-\u20092). D(n\u2009-\u20091) and D(n\u2009-\u20092) are joined in one graph, at that numbers of all vertices of graph D(n\u2009-\u20092) increase by |D(n\u2009-\u20091)| (for example, vertex number 1 of graph D(n\u2009-\u20092) becomes vertex number 1\u2009+\u2009|D(n\u2009-\u20091)|). After that two edges are added to the graph: the first one goes between vertices with numbers |D(n\u2009-\u20091)| and |D(n\u2009-\u20091)|\u2009+\u20091, the second one goes between vertices with numbers |D(n\u2009-\u20091)|\u2009+\u20091 and 1. Note that the definition of graph D(n) implies, that D(n) is a connected graph, its vertices are numbered from 1 to |D(n)|. The picture shows the Doe graphs of order 1, 2, 3 and 4, from left to right. John thinks that Doe graphs are that great because for them exists a polynomial algorithm for the search of Hamiltonian path. However, your task is to answer queries of finding the shortest-length path between the vertices ai and bi in the graph D(n).A path between a pair of vertices u and v in the graph is a sequence of vertices x1, x2, ..., xk (k\u2009>\u20091) such, that x1\u2009=\u2009u, xk\u2009=\u2009v, and for any i (i\u2009<\u2009k) vertices xi and xi\u2009+\u20091 are connected by a graph edge. The length of path x1, x2, ..., xk is number (k\u2009-\u20091).", "input_spec": "The first line contains two integers t and n (1\u2009\u2264\u2009t\u2009\u2264\u2009105;\u00a01\u2009\u2264\u2009n\u2009\u2264\u2009103) \u2014 the number of queries and the order of the given graph. The i-th of the next t lines contains two integers ai and bi (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u20091016, ai\u2009\u2260\u2009bi) \u2014 numbers of two vertices in the i-th query. It is guaranteed that ai,\u2009bi\u2009\u2264\u2009|D(n)|. 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": "For each query print a single integer on a single line \u2014 the length of the shortest path between vertices ai and bi. Print the answers to the queries in the order, in which the queries are given in the input.", "sample_inputs": ["10 5\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"], "sample_outputs": ["1\n1\n1\n2\n1\n2\n3\n1\n2\n1"], "notes": null}, "src_uid": "7f9d6c14a77ee73c401c9d9b2b6602fa"} {"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": "The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching). Since she knows how reckless her pilots are, she wants to be sure that any two (straight) paths \u2013 from a base to its assigned spaceship \u2013 do not intersect in the galaxy plane (that is, in 2D), and so there is no risk of collision.", "input_spec": "The first line contains two space-separated integers R,\u2009B(1\u2009\u2264\u2009R,\u2009B\u2009\u2264\u200910). For 1\u2009\u2264\u2009i\u2009\u2264\u2009R, the i\u2009+\u20091-th line contains two space-separated integers xi and yi (|xi|,\u2009|yi|\u2009\u2264\u200910000) denoting the coordinates of the i-th Rebel spaceship. The following B lines have the same format, denoting the position of bases. It is guaranteed that no two points coincide and that no three points are on the same line.", "output_spec": "If it is possible to connect Rebel spaceships and bases so as satisfy the constraint, output Yes, otherwise output No (without quote).", "sample_inputs": ["3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2", "2 1\n1 0\n2 2\n3 1"], "sample_outputs": ["Yes", "No"], "notes": "NoteFor the first example, one possible way is to connect the Rebels and bases in order.For the second example, there is no perfect matching between Rebels and bases."}, "src_uid": "65f81f621c228c09915adcb05256c634"} {"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": "You have a set of items, each having some integer weight not greater than $$$8$$$. You denote that a subset of items is good if total weight of items in the subset does not exceed $$$W$$$.You want to calculate the maximum possible weight of a good subset of items. Note that you have to consider the empty set and the original set when calculating the answer.", "input_spec": "The first line contains one integer $$$W$$$ ($$$0 \\le W \\le 10^{18}$$$) \u2014 the maximum total weight of a good subset. The second line denotes the set of items you have. It contains $$$8$$$ integers $$$cnt_1$$$, $$$cnt_2$$$, ..., $$$cnt_8$$$ ($$$0 \\le cnt_i \\le 10^{16}$$$), where $$$cnt_i$$$ is the number of items having weight $$$i$$$ in the set.", "output_spec": "Print one integer \u2014 the maximum possible weight of a good subset of items.", "sample_inputs": ["10\n1 2 3 4 5 6 7 8", "0\n0 0 0 0 0 0 0 0", "3\n0 4 1 0 0 9 8 3"], "sample_outputs": ["10", "0", "3"], "notes": null}, "src_uid": "8097e10157320524c0faed56f2bc4880"} {"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": "Let's assume that we have a pair of numbers (a,\u2009b). We can get a new pair (a\u2009+\u2009b,\u2009b) or (a,\u2009a\u2009+\u2009b) from the given pair in a single step.Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.", "input_spec": "The input contains the only integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106).", "output_spec": "Print the only integer k.", "sample_inputs": ["5", "1"], "sample_outputs": ["3", "0"], "notes": "NoteThe pair (1,1) can be transformed into a pair containing 5 in three moves: (1,1) \u2009\u2192\u2009 (1,2) \u2009\u2192\u2009 (3,2) \u2009\u2192\u2009 (5,2)."}, "src_uid": "75739f77378b21c331b46b1427226fa1"} {"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": "You are given three integers k, pa and pb.You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability pa\u2009/\u2009(pa\u2009+\u2009pb), add 'a' to the end of the sequence. Otherwise (with probability pb\u2009/\u2009(pa\u2009+\u2009pb)), add 'b' to the end of the sequence.You stop once there are at least k subsequences that form 'ab'. Determine the expected number of times 'ab' is a subsequence in the resulting sequence. It can be shown that this can be represented by P\u2009/\u2009Q, where P and Q are coprime integers, and . Print the value of .", "input_spec": "The first line will contain three integers integer k,\u2009pa,\u2009pb (1\u2009\u2264\u2009k\u2009\u2264\u20091\u2009000, 1\u2009\u2264\u2009pa,\u2009pb\u2009\u2264\u20091\u2009000\u2009000).", "output_spec": "Print a single integer, the answer to the problem.", "sample_inputs": ["1 1 1", "3 1 4"], "sample_outputs": ["2", "370000006"], "notes": "NoteThe first sample, we will keep appending to our sequence until we get the subsequence 'ab' at least once. For instance, we get the sequence 'ab' with probability 1/4, 'bbab' with probability 1/16, and 'aab' with probability 1/8. Note, it's impossible for us to end with a sequence like 'aabab', since we would have stopped our algorithm once we had the prefix 'aab'. The expected amount of times that 'ab' will occur across all valid sequences is 2. For the second sample, the answer is equal to ."}, "src_uid": "0dc9f5d75143a2bc744480de859188b4"} {"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": "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": "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": "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": "Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.Tickets for group of x people are sold on the attraction, there should be at least one adult in each group (it is possible that the group consists of one adult). The ticket price for such group is c1\u2009+\u2009c2\u00b7(x\u2009-\u20091)2 (in particular, if the group consists of one person, then the price is c1). All pupils who came to the park and their parents decided to split into groups in such a way that each visitor join exactly one group, and the total price of visiting the most extreme attraction is as low as possible. You are to determine this minimum possible total price. There should be at least one adult in each group. ", "input_spec": "The first line contains three integers n, c1 and c2 (1\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000, 1\u2009\u2264\u2009c1,\u2009c2\u2009\u2264\u2009107)\u00a0\u2014 the number of visitors and parameters for determining the ticket prices for a group. The second line contains the string of length n, which consists of zeros and ones. If the i-th symbol of the string is zero, then the i-th visitor is a pupil, otherwise the i-th person is an adult. It is guaranteed that there is at least one adult. It is possible that there are no pupils.", "output_spec": "Print the minimum price of visiting the most extreme attraction for all pupils and their parents. Each of them should roll on the attraction exactly once.", "sample_inputs": ["3 4 1\n011", "4 7 2\n1101"], "sample_outputs": ["8", "18"], "notes": "NoteIn the first test one group of three people should go to the attraction. Then they have to pay 4\u2009+\u20091\u2009*\u2009(3\u2009-\u20091)2\u2009=\u20098.In the second test it is better to go to the attraction in two groups. The first group should consist of two adults (for example, the first and the second person), the second should consist of one pupil and one adult (the third and the fourth person). Then each group will have a size of two and for each the price of ticket is 7\u2009+\u20092\u2009*\u2009(2\u2009-\u20091)2\u2009=\u20099. Thus, the total price for two groups is 18."}, "src_uid": "78d013b01497053b8e321fe7b6ce3760"} {"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": "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": "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": "There is a grid with $$$n$$$ rows and $$$m$$$ columns. Every cell of the grid should be colored either blue or yellow.A coloring of the grid is called stupid if every row has exactly one segment of blue cells and every column has exactly one segment of yellow cells.In other words, every row must have at least one blue cell, and all blue cells in a row must be consecutive. Similarly, every column must have at least one yellow cell, and all yellow cells in a column must be consecutive. An example of a stupid coloring. Examples of clever colorings. The first coloring is missing a blue cell in the second row, and the second coloring has two yellow segments in the second column. How many stupid colorings of the grid are there? Two colorings are considered different if there is some cell that is colored differently.", "input_spec": "The only line contains two integers $$$n$$$, $$$m$$$ ($$$1\\le n, m\\le 2021$$$).", "output_spec": "Output a single integer \u2014 the number of stupid colorings modulo $$$998244353$$$.", "sample_inputs": ["2 2", "4 3", "2020 2021"], "sample_outputs": ["2", "294", "50657649"], "notes": "NoteIn the first test case, these are the only two stupid $$$2\\times 2$$$ colorings. "}, "src_uid": "1738dc65af1fffa445cb0c3074c6bedb"} {"nl": {"description": "Shrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds m cards and the Donkey holds n cards (the players do not see each other's cards), and one more card lies on the table face down so that both players cannot see it as well. Thus, at the beginning of the game there are overall m\u2009+\u2009n\u2009+\u20091 cards. Besides, the players know which cards the pack of cards consists of and their own cards (but they do not know which card lies on the table and which ones the other player has). The players move in turn and Shrek starts. During a move a player can: Try to guess which card is lying on the table. If he guesses correctly, the game ends and he wins. If his guess is wrong, the game also ends but this time the other player wins. Name any card from the pack. If the other player has such card, he must show it and put it aside (so that this card is no longer used in the game). If the other player doesn't have such card, he says about that. Recently Donkey started taking some yellow pills and winning over Shrek. Now Shrek wants to evaluate his chances to win if he too starts taking the pills.Help Shrek assuming the pills are good in quality and that both players using them start playing in the optimal manner.", "input_spec": "The first line contains space-separated integers m and n (0\u2009\u2264\u2009m,\u2009n\u2009\u2264\u20091000).", "output_spec": "Print space-separated probabilities that Shrek wins and Donkey wins correspondingly; the absolute error should not exceed 10\u2009-\u20099.", "sample_inputs": ["0 3", "1 0", "1 1"], "sample_outputs": ["0.25 0.75", "1 0", "0.5 0.5"], "notes": null}, "src_uid": "f51586ab88399c04ffb7eaa658d294dd"} {"nl": {"description": "There are n boys and m girls attending a theatre club. To set a play \"The Big Bang Theory\", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.Perform all calculations in the 64-bit type: long long for \u0421/\u0421++, int64 for Delphi and long for Java.", "input_spec": "The only line of the input data contains three integers n, m, t (4\u2009\u2264\u2009n\u2009\u2264\u200930,\u20091\u2009\u2264\u2009m\u2009\u2264\u200930,\u20095\u2009\u2264\u2009t\u2009\u2264\u2009n\u2009+\u2009m).", "output_spec": "Find the required number of ways. Please do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specificator.", "sample_inputs": ["5 2 5", "4 3 5"], "sample_outputs": ["10", "3"], "notes": null}, "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8"} {"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": "Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. \"Aha, blacks certainly didn't win!\", \u2014 Volodya said and was right for sure. And your task is to say whether whites had won or not.Pieces on the chessboard are guaranteed to represent a correct position (every piece occupies one cell, no two pieces occupy the same cell and kings cannot take each other). Thus, your task is only to decide whether whites mate blacks. We would remind you that it means that the black king can be taken by one of the opponent's pieces at the moment and also it cannot move to an unbeaten position. A rook moves vertically or horizontally by any number of free cells (assuming there are no other pieces on its path), a king \u2014 to the adjacent cells (either by corner or by side). Certainly, pieces cannot leave the board. The black king might be able to take opponent's rooks at his turn (see sample 3).", "input_spec": "The input contains 4 space-separated piece positions: positions of the two rooks, the white king and the black king. Each position on 8\u2009\u00d7\u20098 chessboard is denoted by two symbols \u2014 ('a' - 'h') and ('1' - '8') \u2014 which stand for horizontal and vertical coordinates of the cell occupied by the piece. It is guaranteed, that no two pieces occupy the same cell, and kings cannot take each other.", "output_spec": "Output should contain one word: \"CHECKMATE\" if whites mate blacks, and \"OTHER\" otherwise.", "sample_inputs": ["a6 b4 c8 a8", "a6 c4 b6 b8", "a2 b1 a3 a1"], "sample_outputs": ["CHECKMATE", "OTHER", "OTHER"], "notes": null}, "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3"} {"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": "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": "Shikamaru and Asuma like to play different games, and sometimes they play the following: given an increasing list of numbers, they take turns to move. Each move consists of picking a number from the list.Assume the picked numbers are $$$v_{i_1}$$$, $$$v_{i_2}$$$, $$$\\ldots$$$, $$$v_{i_k}$$$. The following conditions must hold: $$$i_{j} < i_{j+1}$$$ for all $$$1 \\leq j \\leq k-1$$$; $$$v_{i_{j+1}} - v_{i_j} < v_{i_{j+2}} - v_{i_{j+1}}$$$ for all $$$1 \\leq j \\leq k-2$$$. However, it's easy to play only one instance of game, so today Shikamaru and Asuma decided to play $$$n$$$ simultaneous games. They agreed on taking turns as for just one game, Shikamaru goes first. At each turn, the player performs a valid move in any single game. The player who cannot move loses. Find out who wins, provided that both play optimally.", "input_spec": "The first line contains the only integer $$$n$$$ ($$$1 \\leq n \\leq 1000$$$) standing for the number of games Shikamaru and Asuma play at once. Next lines describe the games. Each description starts from a line with the only number $$$m$$$ ($$$m\\geq 1$$$) denoting the length of the number list. The second line contains the increasing space-separated sequence $$$v_1$$$, $$$v_2$$$, ..., $$$v_m$$$ from the game ($$$1 \\leq v_{1} < v_{2} < ... < v_{m} \\leq 10^{5}$$$). The total length of all sequences doesn't exceed $$$10^5$$$.", "output_spec": "Print \"YES\" if Shikamaru can secure the victory, and \"NO\" otherwise.", "sample_inputs": ["1\n10\n1 2 3 4 5 6 7 8 9 10", "2\n10\n1 2 3 4 5 6 7 8 9 10\n10\n1 2 3 4 5 6 7 8 9 10", "4\n7\n14404 32906 41661 47694 51605 75933 80826\n5\n25374 42550 60164 62649 86273\n2\n7002 36731\n8\n23305 45601 46404 47346 47675 58125 74092 87225"], "sample_outputs": ["YES", "NO", "NO"], "notes": "NoteIn the first example Shikamaru can pick the last number, and Asuma cannot do anything because of the first constraint.In the second sample test Asuma can follow the symmetric strategy, repeating Shikamaru's moves in the other instance each time, and therefore win."}, "src_uid": "2a8c2be70fa8983040646150a579f6c1"} {"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": "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": "Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w\u2009=\u2009xy. A split operation is transforming word w\u2009=\u2009xy into word u\u2009=\u2009yx. For example, a split operation can transform word \"wordcut\" into word \"cutword\".You are given two words start and end. Count in how many ways we can transform word start into word end, if we apply exactly k split operations consecutively to word start. Two ways are considered different if the sequences of applied operations differ. Two operation sequences are different if exists such number i (1\u2009\u2264\u2009i\u2009\u2264\u2009k), that in the i-th operation of the first sequence the word splits into parts x and y, in the i-th operation of the second sequence the word splits into parts a and b, and additionally x\u2009\u2260\u2009a holds.", "input_spec": "The first line contains a non-empty word start, the second line contains a non-empty word end. The words consist of lowercase Latin letters. The number of letters in word start equals the number of letters in word end and is at least 2 and doesn't exceed 1000 letters. The third line contains integer k (0\u2009\u2264\u2009k\u2009\u2264\u2009105) \u2014 the required number of operations.", "output_spec": "Print a single number \u2014 the answer to the problem. As this number can be rather large, print it modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["ab\nab\n2", "ababab\nababab\n1", "ab\nba\n2"], "sample_outputs": ["1", "2", "0"], "notes": "NoteThe sought way in the first sample is:ab \u2009\u2192\u2009 a|b \u2009\u2192\u2009 ba \u2009\u2192\u2009 b|a \u2009\u2192\u2009 abIn the second sample the two sought ways are: ababab \u2009\u2192\u2009 abab|ab \u2009\u2192\u2009 ababab ababab \u2009\u2192\u2009 ab|abab \u2009\u2192\u2009 ababab"}, "src_uid": "414000abf4345f08ede20798de29b9d4"} {"nl": {"description": "The Smart Beaver from ABBYY has come up with a new developing game for children. The Beaver thinks that this game will help children to understand programming better.The main object of the game is finite rooted trees, each of their edges contains some lowercase English letter. Vertices on any tree are always numbered sequentially from 1 to m, where m is the number of vertices in the tree. Before describing the actual game, let's introduce some definitions.We'll assume that the sequence of vertices with numbers v1, v2, ..., vk (k\u2009\u2265\u20091) is a forward path, if for any integer i from 1 to k\u2009-\u20091 vertex vi is a direct ancestor of vertex vi\u2009+\u20091. If we sequentially write out all letters from the the edges of the given path from v1 to vk, we get some string (k\u2009=\u20091 gives us an empty string). We'll say that such string corresponds to forward path v1, v2, ..., vk.We'll assume that the sequence of tree vertices with numbers v1, v2, ..., vk (k\u2009\u2265\u20091) is a backward path if for any integer i from 1 to k\u2009-\u20091 vertex vi is the direct descendant of vertex vi\u2009+\u20091. If we sequentially write out all the letters from the edges of the given path from v1 to vk, we get some string (k\u2009=\u20091 gives us an empty string). We'll say that such string corresponds to backward path v1, v2, ..., vk.Now let's describe the game that the Smart Beaver from ABBYY has come up with. The game uses two rooted trees, each of which initially consists of one vertex with number 1. The player is given some sequence of operations. Each operation is characterized by three values (t, v, c) where: t is the number of the tree on which the operation is executed (1 or 2); v is the vertex index in this tree (it is guaranteed that the tree contains a vertex with this index); c is a lowercase English letter. The actual operation is as follows: vertex v of tree t gets a new descendant with number m\u2009+\u20091 (where m is the current number of vertices in tree t), and there should be letter c put on the new edge from vertex v to vertex m\u2009+\u20091.We'll say that an ordered group of three integers (i, j, q) is a good combination if: 1\u2009\u2264\u2009i\u2009\u2264\u2009m1, where m1 is the number of vertices in the first tree; 1\u2009\u2264\u2009j,\u2009q\u2009\u2264\u2009m2, where m2 is the number of vertices in the second tree; there exists a forward path v1, v2, ..., vk such that v1\u2009=\u2009j and vk\u2009=\u2009q in the second tree; the string that corresponds to the forward path in the second tree from vertex j to vertex q equals the string that corresponds to the backward path in the first tree from vertex i to vertex 1 (note that both paths are determined uniquely). Your task is to calculate the number of existing good combinations after each operation on the trees.", "input_spec": "The first line contains integer n \u2014 the number of operations on the trees. Next n lines specify the operations in the order of their execution. Each line has form \"t v c\", where t is the number of the tree, v is the vertex index in this tree, and c is a lowercase English letter. To get the full points for the first group of tests it is sufficient to solve the problem with 1\u2009\u2264\u2009n\u2009\u2264\u2009700. To get the full points for the second group of tests it is sufficient to solve the problem with 1\u2009\u2264\u2009n\u2009\u2264\u20097000. To get the full points for the third group of tests it is sufficient to solve the problem with 1\u2009\u2264\u2009n\u2009\u2264\u2009100000.", "output_spec": "Print exactly n lines, each containing one integer \u2014 the number of existing good combinations after the corresponding operation from the input. 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.", "sample_inputs": ["5\n1 1 a\n2 1 a\n1 2 b\n2 1 b\n2 3 a"], "sample_outputs": ["1\n3\n3\n4\n7"], "notes": "NoteAfter the first operation the only good combination was (1,\u20091,\u20091). After the second operation new good combinations appeared, (2,\u20091,\u20092) and (1,\u20092,\u20092). The third operation didn't bring any good combinations. The fourth operation added good combination (1,\u20093,\u20093). Finally, the fifth operation resulted in as much as three new good combinations \u2014 (1,\u20094,\u20094), (2,\u20093,\u20094) and (3,\u20091,\u20094)."}, "src_uid": "b0cd7ee6b5f13f977def002b53f8f443"} {"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": "Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n\u00b7m square tiles forming a n\u2009\u00d7\u2009m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color.Shaass wants to use a painter robot to color the tiles. In the beginning the robot is standing in a border tile (xs,\u2009ys) facing a diagonal direction (i.e. upper-left, upper-right, down-left or down-right). As the robot walks in the kitchen he paints every tile he passes even if it's painted before. Painting each tile consumes one unit of black paint. If at any moment the robot hits a wall of the kitchen he changes his direction according the reflection rules. Note that a tile gets painted when the robot enters the tile from another tile, in other words changing direction in the same tile doesn't lead to any painting. The first tile the robot is standing on, is also painted.The robot stops painting the first moment the floor is checkered. Given the dimensions of the kitchen and the position of the robot, find out the amount of paint the robot consumes before it stops painting the floor.Let's consider an examples depicted below. If the robot starts at tile number 1 (the tile (1,\u20091)) of the left grid heading to down-right it'll pass tiles 1354236 and consumes 7 units of black paint on his way until he stops at tile number 6. But if it starts at tile number 1 in the right grid heading to down-right it will get stuck in a loop painting tiles 1, 2, and 3.", "input_spec": "The first line of the input contains two integers n and m, (2\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105). The second line contains two integers xs and ys (1\u2009\u2264\u2009xs\u2009\u2264\u2009n,\u20091\u2009\u2264\u2009ys\u2009\u2264\u2009m) and the direction robot is facing initially. Direction is one of the strings: \"UL\" (upper-left direction), \"UR\" (upper-right), \"DL\" (down-left) or \"DR\" (down-right). Note, that record (xs,\u2009ys) denotes the tile that is located at the xs-th row from the top and at the ys-th column from the left of the kitchen. It's guaranteed that the starting position will be a border tile (a tile with less than four side-adjacent tiles).", "output_spec": "Print the amount of paint the robot consumes to obtain a checkered kitchen floor. Or print -1 if it never happens. Please do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specificator.", "sample_inputs": ["3 4\n1 1 DR", "3 4\n3 3 DR", "3 3\n1 1 DR", "3 3\n1 2 DL"], "sample_outputs": ["7", "11", "-1", "4"], "notes": null}, "src_uid": "8a59247013a9b1f34700f4bfc7d1831d"} {"nl": {"description": "Vasya is studying number theory. He has denoted a function f(a,\u2009b) such that: f(a,\u20090)\u2009=\u20090; f(a,\u2009b)\u2009=\u20091\u2009+\u2009f(a,\u2009b\u2009-\u2009gcd(a,\u2009b)), where gcd(a,\u2009b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calculate f(x,\u2009y). He tried to do it by himself, but found out that calculating this function the way he wants to do that might take very long time. So he decided to ask you to implement a program that will calculate this function swiftly.", "input_spec": "The first line contains two integer numbers x and y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20091012).", "output_spec": "Print f(x,\u2009y).", "sample_inputs": ["3 5", "6 3"], "sample_outputs": ["3", "1"], "notes": null}, "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e"} {"nl": {"description": "Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, \"AZ\", \"AA\", \"ZA\" \u2014 three distinct two-grams.You are given a string $$$s$$$ consisting of $$$n$$$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $$$s$$$ = \"BBAABBBA\" the answer is two-gram \"BB\", which contained in $$$s$$$ three times. In other words, find any most frequent two-gram.Note that occurrences of the two-gram can overlap with each other.", "input_spec": "The first line of the input contains integer number $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ capital Latin letters.", "output_spec": "Print the only line containing exactly two capital Latin letters \u2014 any two-gram contained in the given string $$$s$$$ as a substring (i.e. two consecutive characters of the string) maximal number of times.", "sample_inputs": ["7\nABACABA", "5\nZZZAA"], "sample_outputs": ["AB", "ZZ"], "notes": "NoteIn the first example \"BA\" is also valid answer.In the second example the only two-gram \"ZZ\" can be printed because it contained in the string \"ZZZAA\" two times."}, "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"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": "In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x\u2009+\u2009k). That is, f(x)\u2009=\u2009q(x)\u00b7(x\u2009+\u2009k)\u2009+\u2009p, where q(x) is a polynomial (not necessarily with integer coefficients).", "input_spec": "The only line of input contains two space-separated integers p and k (1\u2009\u2264\u2009p\u2009\u2264\u20091018, 2\u2009\u2264\u2009k\u2009\u2264\u20092\u2009000).", "output_spec": "If the polynomial does not exist, print a single integer -1, or output two lines otherwise. In the first line print a non-negative integer d \u2014 the number of coefficients in the polynomial. In the second line print d space-separated integers a0,\u2009a1,\u2009...,\u2009ad\u2009-\u20091, describing a polynomial fulfilling the given requirements. Your output should satisfy 0\u2009\u2264\u2009ai\u2009<\u2009k for all 0\u2009\u2264\u2009i\u2009\u2264\u2009d\u2009-\u20091, and ad\u2009-\u20091\u2009\u2260\u20090. If there are many possible solutions, print any of them.", "sample_inputs": ["46 2", "2018 214"], "sample_outputs": ["7\n0 1 0 0 1 1 1", "3\n92 205 1"], "notes": "NoteIn the first example, f(x)\u2009=\u2009x6\u2009+\u2009x5\u2009+\u2009x4\u2009+\u2009x\u2009=\u2009(x5\u2009-\u2009x4\u2009+\u20093x3\u2009-\u20096x2\u2009+\u200912x\u2009-\u200923)\u00b7(x\u2009+\u20092)\u2009+\u200946.In the second example, f(x)\u2009=\u2009x2\u2009+\u2009205x\u2009+\u200992\u2009=\u2009(x\u2009-\u20099)\u00b7(x\u2009+\u2009214)\u2009+\u20092018."}, "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5"} {"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": "On the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number t is his lucky number, if it can be represented as: t\u2009=\u2009a2\u2009+\u2009b2,\u2009 where a,\u2009b are arbitrary positive integers.Now, the boys decided to find out how many days of the interval [l,\u2009r] (l\u2009\u2264\u2009r) are suitable for pair programming. They decided that the day i (l\u2009\u2264\u2009i\u2009\u2264\u2009r) is suitable for pair programming if and only if the number i is lucky for Peter and lucky for Bob at the same time. Help the boys to find the number of such days.", "input_spec": "The first line of the input contains integer numbers l,\u2009r (1\u2009\u2264\u2009l,\u2009r\u2009\u2264\u20093\u00b7108).", "output_spec": "In the only line print the number of days on the segment [l,\u2009r], which are lucky for Peter and Bob at the same time.", "sample_inputs": ["3 5", "6 66"], "sample_outputs": ["1", "7"], "notes": null}, "src_uid": "55a83526c10126ac3a6e6e5154b120d0"} {"nl": {"description": "Let's assume that set S consists of m distinct intervals [l1,\u2009r1], [l2,\u2009r2], ..., [lm,\u2009rm] (1\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u2009n; li,\u2009ri are integers).Let's assume that f(S) is the maximum number of intervals that you can choose from the set S, such that every two of them do not intersect. We assume that two intervals, [l1,\u2009r1] and [l2,\u2009r2], intersect if there is an integer x, which meets two inequalities: l1\u2009\u2264\u2009x\u2009\u2264\u2009r1 and l2\u2009\u2264\u2009x\u2009\u2264\u2009r2.Sereja wonders, how many sets S are there, such that f(S)\u2009=\u2009k? Count this number modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line contains integers n, k (1\u2009\u2264\u2009n\u2009\u2264\u2009500;\u00a00\u2009\u2264\u2009k\u2009\u2264\u2009500).", "output_spec": "In a single line, print the answer to the problem modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["3 1", "3 2", "2 0", "2 2"], "sample_outputs": ["23", "32", "1", "2"], "notes": null}, "src_uid": "111673158df2e37ac6c019bb99225ccb"} {"nl": {"description": "Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.", "input_spec": "Input will consist of a single integer N (1\u2009\u2264\u2009N\u2009\u2264\u2009106), the number of city blocks that must be enclosed by the route.", "output_spec": "Print the minimum perimeter that can be achieved.", "sample_inputs": ["4", "11", "22"], "sample_outputs": ["8", "14", "20"], "notes": "NoteHere are some possible shapes for the examples:"}, "src_uid": "414cc57550e31d98c1a6a56be6722a12"} {"nl": {"description": "You are given a figure on a grid representing stairs consisting of 7 steps. The width of the stair on height i is wi squares. Formally, the figure is created by consecutively joining rectangles of size wi\u2009\u00d7\u2009i so that the wi sides lie on one straight line. Thus, for example, if all wi\u2009=\u20091, the figure will look like that (different colors represent different rectangles): And if w\u2009=\u2009{5,\u20091,\u20090,\u20093,\u20090,\u20090,\u20091}, then it looks like that: Find the number of ways to color some borders of the figure's inner squares so that no square had all four borders colored. The borders of the squares lying on the border of the figure should be considered painted. The ways that differ with the figure's rotation should be considered distinct. ", "input_spec": "The single line of the input contains 7 numbers w1,\u2009w2,\u2009...,\u2009w7 (0\u2009\u2264\u2009wi\u2009\u2264\u2009105). It is guaranteed that at least one of the wi's isn't equal to zero.", "output_spec": "In the single line of the output display a single number \u2014 the answer to the problem modulo 109\u2009+\u20097.", "sample_inputs": ["0 1 0 0 0 0 0", "0 2 0 0 0 0 0", "1 1 1 0 0 0 0", "5 1 0 3 0 0 1"], "sample_outputs": ["1", "7", "9", "411199181"], "notes": "NoteAll the possible ways of painting the third sample are given below: "}, "src_uid": "a4bda63b95dc14185c47a08652fe41bd"} {"nl": {"description": "You are given two bracket sequences (not necessarily regular) $$$s$$$ and $$$t$$$ consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous).Recall what is the regular bracket sequence: () is the regular bracket sequence; if $$$S$$$ is the regular bracket sequence, then ($$$S$$$) is a regular bracket sequence; if $$$S$$$ and $$$T$$$ regular bracket sequences, then $$$ST$$$ (concatenation of $$$S$$$ and $$$T$$$) is a regular bracket sequence. Recall that the subsequence of the string $$$s$$$ is such string $$$t$$$ that can be obtained from $$$s$$$ by removing some (possibly, zero) amount of characters. For example, \"coder\", \"force\", \"cf\" and \"cores\" are subsequences of \"codeforces\", but \"fed\" and \"z\" are not.", "input_spec": "The first line of the input contains one bracket sequence $$$s$$$ consisting of no more than $$$200$$$ characters '(' and ')'. The second line of the input contains one bracket sequence $$$t$$$ consisting of no more than $$$200$$$ characters '(' and ')'.", "output_spec": "Print one line \u2014 the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any.", "sample_inputs": ["(())(()\n()))()", ")\n((", ")\n)))", "())\n(()(()(()("], "sample_outputs": ["(())()()", "(())", "((()))", "(()()()(()()))"], "notes": null}, "src_uid": "cc222aab45b3ad3d0e71227592c883f1"} {"nl": {"description": "You are given an integer $$$n$$$ from $$$1$$$ to $$$10^{18}$$$ without leading zeroes.In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.What is the minimum number of moves you have to make to obtain a number that is divisible by $$$25$$$? Print -1 if it is impossible to obtain a number that is divisible by $$$25$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 10^{18}$$$). It is guaranteed that the first (left) digit of the number $$$n$$$ is not a zero.", "output_spec": "If it is impossible to obtain a number that is divisible by $$$25$$$, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number.", "sample_inputs": ["5071", "705", "1241367"], "sample_outputs": ["4", "1", "-1"], "notes": "NoteIn the first example one of the possible sequences of moves is 5071 $$$\\rightarrow$$$ 5701 $$$\\rightarrow$$$ 7501 $$$\\rightarrow$$$ 7510 $$$\\rightarrow$$$ 7150."}, "src_uid": "ea1c737956f88be94107f2565ca8bbfd"} {"nl": {"description": "Little Petya very much likes strings. Recently he has received a voucher to purchase a string as a gift from his mother. The string can be bought in the local shop. One can consider that the shop has all sorts of strings over the alphabet of fixed size. The size of the alphabet is equal to k. However, the voucher has a string type limitation: specifically, the voucher can be used to purchase string s if the length of string's longest substring that is also its weak subsequence (see the definition given below) equals w.String a with the length of n is considered the weak subsequence of the string s with the length of m, if there exists such a set of indexes 1\u2009\u2264\u2009i1\u2009<\u2009i2\u2009<\u2009...\u2009<\u2009in\u2009\u2264\u2009m, that has the following two properties: ak\u2009=\u2009sik for all k from 1 to n; there exists at least one such k (1\u2009\u2264\u2009k\u2009<\u2009n), for which ik\u2009+\u20091\u2009\u2013\u2009ik\u2009>\u20091. Petya got interested how many different strings are available for him to purchase in the shop. As the number of strings can be very large, please find it modulo 1000000007 (109\u2009+\u20097). If there are infinitely many such strings, print \"-1\".", "input_spec": "The first line contains two integers k (1\u2009\u2264\u2009k\u2009\u2264\u2009106) and w (2\u2009\u2264\u2009w\u2009\u2264\u2009109) \u2014 the alphabet size and the required length of the maximum substring that also is the weak subsequence, correspondingly.", "output_spec": "Print a single number \u2014 the number of strings Petya can buy using the voucher, modulo 1000000007 (109\u2009+\u20097). If there are infinitely many such strings, print \"-1\" (without the quotes).", "sample_inputs": ["2 2", "3 5", "2 139"], "sample_outputs": ["10", "1593", "717248223"], "notes": "NoteIn the first sample Petya can buy the following strings: aaa, aab, abab, abb, abba, baa, baab, baba, bba, bbb."}, "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130"} {"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": "Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n\u2009-\u20091 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v\u2009+\u20091.You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.", "input_spec": "The first line of the input will contain a single integer, n (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000).", "output_spec": "Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.", "sample_inputs": ["1", "2", "3", "8"], "sample_outputs": ["1", "2", "2 1", "4"], "notes": "NoteIn the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.In the second sample, we perform the following steps:Initially we place a single slime in a row by itself. Thus, row is initially 1.Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.In the last sample, the steps look as follows: 1 2 2 1 3 3 1 3 2 3 2 1 4 "}, "src_uid": "757cd804aba01dc4bc108cb0722f68dc"} {"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": "The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that after it the brightest minds will become his subordinates, and the toughest part of conquering the world will be completed.The final round of the Codeforces World Finals 20YY is scheduled for DD.MM.YY, where DD is the day of the round, MM is the month and YY are the last two digits of the year. Bob is lucky to be the first finalist form Berland. But there is one problem: according to the rules of the competition, all participants must be at least 18 years old at the moment of the finals. Bob was born on BD.BM.BY. This date is recorded in his passport, the copy of which he has already mailed to the organizers. But Bob learned that in different countries the way, in which the dates are written, differs. For example, in the US the month is written first, then the day and finally the year. Bob wonders if it is possible to rearrange the numbers in his date of birth so that he will be at least 18 years old on the day DD.MM.YY. He can always tell that in his motherland dates are written differently. Help him.According to another strange rule, eligible participant must be born in the same century as the date of the finals. If the day of the finals is participant's 18-th birthday, he is allowed to participate. As we are considering only the years from 2001 to 2099 for the year of the finals, use the following rule: the year is leap if it's number is divisible by four.", "input_spec": "The first line contains the date DD.MM.YY, the second line contains the date BD.BM.BY. It is guaranteed that both dates are correct, and YY and BY are always in [01;99]. It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date.", "output_spec": "If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the DD.MM.YY, output YES. In the other case, output NO. Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digits.", "sample_inputs": ["01.01.98\n01.01.80", "20.10.20\n10.02.30", "28.02.74\n28.02.64"], "sample_outputs": ["YES", "NO", "NO"], "notes": null}, "src_uid": "5418c98fe362909f7b28f95225837d33"} {"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": "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": "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": "For each positive integer n consider the integer \u03c8(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9\u2009\u2009-\u2009\u2009a). We say that \u03c8(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8.Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10\u00b789\u2009=\u2009890.Your task is to find the maximum weight of the numbers in the given range [l,\u2009r] (boundaries are included).", "input_spec": "Input contains two space-separated integers l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109) \u2014 bounds of the range.", "output_spec": "Output should contain single integer number: maximum value of the product n\u00b7\u03c8(n), where l\u2009\u2264\u2009n\u2009\u2264\u2009r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).", "sample_inputs": ["3 7", "1 1", "8 10"], "sample_outputs": ["20", "8", "890"], "notes": "NoteIn the third sample weight of 8 equals 8\u00b71\u2009=\u20098, weight of 9 equals 9\u00b70\u2009=\u20090, weight of 10 equals 890.Thus, maximum value of the product is equal to 890."}, "src_uid": "2c4b2a162563242cb2f43f6209b59d5e"} {"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": "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": "To add insult to injury, the zombies have taken all but two drawings from Heidi! Please help her recover the Tree of Life from only these two drawings.", "input_spec": "The input format is the same as in the medium version, except that now the bound on n is 2\u2009\u2264\u2009n\u2009\u2264\u20091000 and that k\u2009=\u20092.", "output_spec": "The same as in the medium version.", "sample_inputs": ["1\n9 2\n6\n4 3\n5 4\n6 1\n8 6\n8 2\n7 1\n5\n8 6\n8 7\n8 1\n7 3\n5 1"], "sample_outputs": ["YES\n2 1\n3 1\n5 4\n6 5\n7 6\n8 5\n9 8\n1 4"], "notes": null}, "src_uid": "25dcac5eddbad481c7ba6da97b37b676"} {"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": "Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.Look at the sample to understand what borders are included in the aswer.", "input_spec": "The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900\u2009\u2264\u2009yyyy\u2009\u2264\u20092038 and yyyy:mm:dd is a legal date).", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["1900:01:01\n2038:12:31", "1996:03:09\n1991:11:12"], "sample_outputs": ["50768", "1579"], "notes": null}, "src_uid": "bdf99d78dc291758fa09ec133fff1e9c"} {"nl": {"description": "Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2n seconds, in particular, it should be fried for n seconds on one side and n seconds on the other side. Arkady has already got a frying pan and turn on fire, but understood that maybe he won't be able to flip the cutlet exactly after n seconds after the beginning of cooking.Arkady is too busy with sorting sticker packs in his favorite messenger and can flip the cutlet only in some periods of time. Namely, there are k periods of time in which he can do it, the i-th of them is an interval of time from li seconds after he starts cooking till ri seconds, inclusive. Arkady decided that it's not required to flip the cutlet exactly in the middle of cooking, instead, he will flip it several times in such a way that the cutlet will be fried exactly n seconds on one side and n seconds on the other side in total.Help Arkady and find out if it's possible for him to cook the cutlet, if he is able to flip the cutlet only in given periods of time; and if yes, find the minimum number of flips he needs to cook the cutlet.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u2009100)\u00a0\u2014 the number of seconds the cutlet should be cooked on each side and number of periods of time in which Arkady can flip it. The next k lines contain descriptions of these intervals. Each line contains two integers li and ri (0\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u20092\u00b7n), meaning that Arkady can flip the cutlet in any moment starting from li seconds after the beginning of cooking and finishing at ri seconds after beginning of cooking. In particular, if li\u2009=\u2009ri then Arkady can flip the cutlet only in the moment li\u2009=\u2009ri. It's guaranteed that li\u2009>\u2009ri\u2009-\u20091 for all 2\u2009\u2264\u2009i\u2009\u2264\u2009k.", "output_spec": "Output \"Hungry\" if Arkady won't be able to fry the cutlet for exactly n seconds on one side and exactly n seconds on the other side. Otherwise, output \"Full\" in the first line, and the minimum number of times he should flip the cutlet in the second line.", "sample_inputs": ["10 2\n3 5\n11 13", "10 3\n3 5\n9 10\n11 13", "20 1\n3 19"], "sample_outputs": ["Full\n2", "Full\n1", "Hungry"], "notes": "NoteIn the first example Arkady should flip the cutlet in time moment 3 seconds after he starts cooking and in time moment 13 seconds after he starts cooking.In the second example, Arkady can flip the cutlet at 10 seconds after he starts cooking."}, "src_uid": "2e0d1b1f1a7b8df2d2598c3cb2c869d5"} {"nl": {"description": "In a Berland city S*** there is a tram engine house and only one tram. Three people work in the house \u2014 the tram driver, the conductor and the head of the engine house. The tram used to leave the engine house every morning and drove along his loop route. The tram needed exactly c minutes to complete the route. The head of the engine house controlled the tram\u2019s movement, going outside every c minutes when the tram drove by the engine house, and the head left the driver without a bonus if he was even one second late.It used to be so. Afterwards the Berland Federal Budget gave money to make more tramlines in S***, and, as it sometimes happens, the means were used as it was planned. The tramlines were rebuilt and as a result they turned into a huge network. The previous loop route may have been destroyed. S*** has n crossroads and now m tramlines that links the pairs of crossroads. The traffic in Berland is one way so the tram can move along each tramline only in one direction. There may be several tramlines between two crossroads, which go same way or opposite ways. Every tramline links two different crossroads and for each crossroad there is at least one outgoing tramline.So, the tramlines were built but for some reason nobody gave a thought to increasing the number of trams in S***! The tram continued to ride alone but now the driver had an excellent opportunity to get rid of the unending control of the engine house head. For now due to the tramline network he could choose the route freely! Now at every crossroad the driver can arbitrarily choose the way he can go. The tram may even go to the parts of S*** from where it cannot return due to one way traffic. The driver is not afraid of the challenge: at night, when the city is asleep, he can return to the engine house safely, driving along the tramlines in the opposite direction.The city people were rejoicing for some of the had been waiting for the tram to appear on their streets for several years. However, the driver\u2019s behavior enraged the engine house head. Now he tries to carry out an insidious plan of installing cameras to look after the rebellious tram.The plan goes as follows. The head of the engine house wants to install cameras at some crossroads, to choose a period of time t and every t minutes turn away from the favourite TV show to check where the tram is. Also the head of the engine house wants at all moments of time, divisible by t, and only at such moments the tram to appear on a crossroad under a camera. There must be a camera on the crossroad by the engine house to prevent possible terrorist attacks on the engine house head. Among all the possible plans the engine house head chooses the plan with the largest possible value of t (as he hates being distracted from his favourite TV show but he has to). If such a plan is not unique, pick the plan that requires the minimal possible number of cameras. Find such a plan.", "input_spec": "The first line contains integers n and m (2\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105) \u2014 the number of crossroads and tramlines in S*** respectively. The next m lines contain the descriptions of the tramlines in \"u v\" format, where u is the initial tramline crossroad and v is its final crossroad. The crossroads are numbered with integers from 1 to n, and the engine house is at the crossroad number 1.", "output_spec": "In the first line output the value of t. In the next line output the value of k \u2014 the required number of the cameras. In the next line output space-separated numbers of the crossroads, where the cameras should be installed. Output the numbers in increasing order.", "sample_inputs": ["4 5\n1 2\n2 3\n3 4\n4 1\n1 4"], "sample_outputs": ["2\n2\n1 3"], "notes": null}, "src_uid": "e13228fcdaa1c218581606ddfe186d52"} {"nl": {"description": "In this problem you have to solve a simple classification task: given an image, determine whether it depicts a Fourier doodle. You are given a set of 50 images with ids 1 through 50. You are also given a text file labels.txt containing the labels for images with ids 1 through 20, which comprise the learning data set. You have to output the classification results for images with ids 21 through 50 in the same format.", "input_spec": "Download the images and the training labels Each line of the file labels.txt contains a single integer 0 or 1. Line $$$i$$$ (1-based) contains the label of the image {i}.png. Label 1 means that the image depicts a Fourier doodle, label 0 - that it does not.", "output_spec": "Output 30 lines, one line per image 21 through 50. Line $$$i$$$ (1-based) should contain the classification result for the image {i + 20}.png.", "sample_inputs": [], "sample_outputs": [], "notes": null}, "src_uid": "4bda04e64ff661336a93464563f1b550"} {"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": "I\u2019m strolling on sunshine, yeah-ah! And doesn\u2019t it feel good! Well, it certainly feels good for our Heroes of Making Magic, who are casually walking on a one-directional road, fighting imps. Imps are weak and feeble creatures and they are not good at much. However, Heroes enjoy fighting them. For fun, if nothing else. Our Hero, Ignatius, simply adores imps. He is observing a line of imps, represented as a zero-indexed array of integers a of length n, where ai denotes the number of imps at the i-th position. Sometimes, imps can appear out of nowhere. When heroes fight imps, they select a segment of the line, start at one end of the segment, and finish on the other end, without ever exiting the segment. They can move exactly one cell left or right from their current position and when they do so, they defeat one imp on the cell that they moved to, so, the number of imps on that cell decreases by one. This also applies when heroes appear at one end of the segment, at the beginning of their walk. Their goal is to defeat all imps on the segment, without ever moving to an empty cell in it (without imps), since they would get bored. Since Ignatius loves imps, he doesn\u2019t really want to fight them, so no imps are harmed during the events of this task. However, he would like you to tell him whether it would be possible for him to clear a certain segment of imps in the above mentioned way if he wanted to. You are given q queries, which have two types: 1 a b k\u00a0\u2014 denotes that k imps appear at each cell from the interval [a,\u2009b] 2 a b - asks whether Ignatius could defeat all imps on the interval [a,\u2009b] in the way described above ", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000), the length of the array a. The following line contains n integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u20095\u2009000), the initial number of imps in each cell. The third line contains a single integer q (1\u2009\u2264\u2009q\u2009\u2264\u2009300\u2009000), the number of queries. The remaining q lines contain one query each. Each query is provided by integers a, b and, possibly, k (0\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009<\u2009n, 0\u2009\u2264\u2009k\u2009\u2264\u20095\u2009000).", "output_spec": "For each second type of query output 1 if it is possible to clear the segment, and 0 if it is not.", "sample_inputs": ["3\n2 2 2\n3\n2 0 2\n1 1 1 1\n2 0 2"], "sample_outputs": ["0\n1"], "notes": "NoteFor the first query, one can easily check that it is indeed impossible to get from the first to the last cell while clearing everything. After we add 1 to the second position, we can clear the segment, for example by moving in the following way: ."}, "src_uid": "a17833a733d59936d1c3ba5f27b0cbe0"} {"nl": {"description": "Let's consider an n\u2009\u00d7\u2009n square matrix, consisting of digits one and zero.We'll consider a matrix good, if it meets the following condition: in each row of the matrix all ones go in one group. That is, each row of the matrix looks like that 00...0011...1100...00 (or simply consists of zeroes if it has no ones).You are given matrix a of size n\u2009\u00d7\u2009n, consisting of zeroes and ones. Your task is to determine whether you can get a good matrix b from it by rearranging the columns or not.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009500) \u2014 the size of matrix a. Each of n following lines contains n characters \"0\" and \"1\" \u2014 matrix a. Note that the characters are written without separators.", "output_spec": "Print \"YES\" in the first line, if you can rearrange the matrix columns so as to get a good matrix b. In the next n lines print the good matrix b. If there are multiple answers, you are allowed to print any of them. If it is impossible to get a good matrix, print \"NO\".", "sample_inputs": ["6\n100010\n110110\n011001\n010010\n000100\n011001", "3\n110\n101\n011"], "sample_outputs": ["YES\n011000\n111100\n000111\n001100\n100000\n000111", "NO"], "notes": null}, "src_uid": "af8d46722e1bd8f7392e5596eaf4def8"} {"nl": {"description": "Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m\u2009+\u20091)\u2009\u00d7\u2009(m\u2009+\u20091):Maxim asks you to count, how many numbers m (1\u2009\u2264\u2009m\u2009\u2264\u2009n) are there, such that the sum of values in the cells in the row number m\u2009+\u20091 of the resulting matrix equals t.Expression (x xor y) means applying the operation of bitwise excluding \"OR\" to numbers x and y. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by character \"^\", in Pascal \u2014 by \"xor\".", "input_spec": "A single line contains two integers n and t (1\u2009\u2264\u2009n,\u2009t\u2009\u2264\u20091012,\u2009t\u2009\u2264\u2009n\u2009+\u20091). 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": "In a single line print a single integer \u2014 the answer to the problem. ", "sample_inputs": ["1 1", "3 2", "3 3", "1000000000000 1048576"], "sample_outputs": ["1", "1", "0", "118606527258"], "notes": null}, "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc"} {"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": "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": "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": "There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x1,\u2009x2,\u2009x3,\u2009x4} (x1\u2009\u2264\u2009x2\u2009\u2264\u2009x3\u2009\u2264\u2009x4) arithmetic mean is , median is and range is x4\u2009-\u2009x1. The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a \"debugging field\" and codes in the field will have no bugs.For example, 1,\u20091,\u20093,\u20093 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0\u2009\u2264\u2009n\u2009\u2264\u20094) boxes remaining. The i-th remaining box contains ai candies.Now Jeff wants to know: is there a possible way to find the number of candies of the 4\u2009-\u2009n missing boxes, meeting the condition above (the mean, median and range are equal)?", "input_spec": "The first line of input contains an only integer n (0\u2009\u2264\u2009n\u2009\u2264\u20094). The next n lines contain integers ai, denoting the number of candies in the i-th box (1\u2009\u2264\u2009ai\u2009\u2264\u2009500).", "output_spec": "In the first output line, print \"YES\" if a solution exists, or print \"NO\" if there is no solution. If a solution exists, you should output 4\u2009-\u2009n more lines, each line containing an integer b, denoting the number of candies in a missing box. All your numbers b must satisfy inequality 1\u2009\u2264\u2009b\u2009\u2264\u2009106. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them. Given numbers ai may follow in any order in the input, not necessary in non-decreasing. ai may have stood at any positions in the original set, not necessary on lowest n first positions.", "sample_inputs": ["2\n1\n1", "3\n1\n1\n1", "4\n1\n2\n2\n3"], "sample_outputs": ["YES\n3\n3", "NO", "YES"], "notes": "NoteFor the first sample, the numbers of candies in 4 boxes can be 1,\u20091,\u20093,\u20093. The arithmetic mean, the median and the range of them are all 2.For the second sample, it's impossible to find the missing number of candies.In the third example no box has been lost and numbers satisfy the condition.You may output b in any order."}, "src_uid": "230e613abf0f6a768829cbc1f1a09219"} {"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": "Dreamoon has just created a document of hard problems using notepad.exe. The document consists of n lines of text, ai denotes the length of the i-th line. He now wants to know what is the fastest way to move the cursor around because the document is really long.Let (r,\u2009c) be a current cursor position, where r is row number and c is position of cursor in the row. We have 1\u2009\u2264\u2009r\u2009\u2264\u2009n and 0\u2009\u2264\u2009c\u2009\u2264\u2009ar.We can use following six operations in notepad.exe to move our cursor assuming the current cursor position is at (r,\u2009c): up key: the new cursor position (nr,\u2009nc)\u2009=\u2009(max(r\u2009-\u20091,\u20091),\u2009min(anr,\u2009c)) down key: the new cursor position (nr,\u2009nc)\u2009=\u2009(min(r\u2009+\u20091,\u2009n),\u2009min(anr,\u2009c)) left key: the new cursor position (nr,\u2009nc)\u2009=\u2009(r,\u2009max(0,\u2009c\u2009-\u20091)) right key: the new cursor position (nr,\u2009nc)\u2009=\u2009(r,\u2009min(anr,\u2009c\u2009+\u20091)) HOME key: the new cursor position (nr,\u2009nc)\u2009=\u2009(r,\u20090) END key: the new cursor position (nr,\u2009nc)\u2009=\u2009(r,\u2009ar) You're given the document description (n and sequence ai) and q queries from Dreamoon. Each query asks what minimal number of key presses is needed to move the cursor from (r1,\u2009c1) to (r2,\u2009c2).", "input_spec": "The first line contains an integer n(1\u2009\u2264\u2009n\u2009\u2264\u2009400,\u2009000) \u2014 the number of lines of text. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an(1\u2009\u2264\u2009ai\u2009\u2264\u2009108). The third line contains an integer q(1\u2009\u2264\u2009q\u2009\u2264\u2009400,\u2009000). Each of the next q lines contains four integers r1,\u2009c1,\u2009r2,\u2009c2 representing a query (1\u2009\u2264\u2009r1,\u2009r2\u2009\u2264\u2009n,\u20090\u2009\u2264\u2009c1\u2009\u2264\u2009ar1,\u20090\u2009\u2264\u2009c2\u2009\u2264\u2009ar2).", "output_spec": "For each query print the result of the query.", "sample_inputs": ["9\n1 3 5 3 1 3 5 3 1\n4\n3 5 3 1\n3 3 7 3\n1 0 3 3\n6 0 7 3", "2\n10 5\n1\n1 0 1 5"], "sample_outputs": ["2\n5\n3\n2", "3"], "notes": "NoteIn the first sample, the first query can be solved with keys: HOME, right.The second query can be solved with keys: down, down, down, END, down.The third query can be solved with keys: down, END, down.The fourth query can be solved with keys: END, down."}, "src_uid": "79b6cdbcdfcf00e0649dfc85af46d021"} {"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": "Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation: F1\u2009=\u20091,\u2009F2\u2009=\u20092,\u2009Fi\u2009=\u2009Fi\u2009-\u20091\u2009+\u2009Fi\u2009-\u20092\u00a0(i\u2009>\u20092).We'll define a new number sequence Ai(k) by the formula: Ai(k)\u2009=\u2009Fi\u2009\u00d7\u2009ik\u00a0(i\u2009\u2265\u20091).In this problem, your task is to calculate the following sum: A1(k)\u2009+\u2009A2(k)\u2009+\u2009...\u2009+\u2009An(k). The answer can be very large, so print it modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line contains two space-separated integers n, k (1\u2009\u2264\u2009n\u2009\u2264\u20091017;\u00a01\u2009\u2264\u2009k\u2009\u2264\u200940).", "output_spec": "Print a single integer \u2014 the sum of the first n elements of the sequence Ai(k) modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1 1", "4 1", "5 2", "7 4"], "sample_outputs": ["1", "34", "316", "73825"], "notes": null}, "src_uid": "14f50a111db268182e5927839a993118"} {"nl": {"description": "When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced off the walls, the ceiling and the floor corridor and finally hit the exit door. As the ball was wet, it left a spot on the door. Now Valera wants to know the coordinates for this spot.Let's describe the event more formally. The ball will be considered a point in space. The door of the corridor will be considered a rectangle located on plane xOz, such that the lower left corner of the door is located at point (0,\u20090,\u20090), and the upper right corner is located at point (a,\u20090,\u2009b) . The corridor will be considered as a rectangular parallelepiped, infinite in the direction of increasing coordinates of y. In this corridor the floor will be considered as plane xOy, and the ceiling as plane, parallel to xOy and passing through point (a,\u20090,\u2009b). We will also assume that one of the walls is plane yOz, and the other wall is plane, parallel to yOz and passing through point (a,\u20090,\u2009b).We'll say that the ball hit the door when its coordinate y was equal to 0. Thus the coordinates of the spot are point (x0,\u20090,\u2009z0), where 0\u2009\u2264\u2009x0\u2009\u2264\u2009a,\u20090\u2009\u2264\u2009z0\u2009\u2264\u2009b. To hit the ball, Valera steps away from the door at distance m and puts the ball in the center of the corridor at point . After the hit the ball flies at speed (vx,\u2009vy,\u2009vz). This means that if the ball has coordinates (x,\u2009y,\u2009z), then after one second it will have coordinates (x\u2009+\u2009vx,\u2009y\u2009+\u2009vy,\u2009z\u2009+\u2009vz).See image in notes for clarification.When the ball collides with the ceiling, the floor or a wall of the corridor, it bounces off in accordance with the laws of reflection (the angle of incidence equals the angle of reflection). In the problem we consider the ideal physical model, so we can assume that there is no air resistance, friction force, or any loss of energy.", "input_spec": "The first line contains three space-separated integers a,\u2009b,\u2009m (1\u2009\u2264\u2009a,\u2009b,\u2009m\u2009\u2264\u2009100). The first two integers specify point (a,\u20090,\u2009b), through which the ceiling and one of the corridor walls pass. The third integer is the distance at which Valera went away from the door. The second line has three space-separated integers vx,\u2009vy,\u2009vz (|vx|,\u2009|vy|,\u2009|vz|\u2009\u2264\u2009100,\u2009vy\u2009<\u20090,\u2009vz\u2009\u2265\u20090) \u2014 the speed of the ball after the hit. It is guaranteed that the ball hits the door.", "output_spec": "Print two real numbers x0,\u2009z0 \u2014 the x and z coordinates of point (x0,\u20090,\u2009z0), at which the ball hits the exit door. The answer will be considered correct, if its absolute or relative error does not exceed 10\u2009\u2009-\u20096.", "sample_inputs": ["7 2 11\n3 -11 2", "7 2 11\n4 -3 3"], "sample_outputs": ["6.5000000000 2.0000000000", "4.1666666667 1.0000000000"], "notes": "Note"}, "src_uid": "84848b8bd92fd2834db1ee9cb0899cff"} {"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": "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": "The first ship with the Earth settlers landed on Mars. The colonists managed to build n necessary structures on the surface of the planet (which can be regarded as a plane, and the construction can be regarded as points on it). But one day the scanners recorded suspicious activity on the outskirts of the colony. It was decided to use the protective force field generating system to protect the colony against possible trouble.The system works as follows: the surface contains a number of generators of the field (they can also be considered as points). The active range of each generator is a circle of radius r centered at the location of the generator (the boundary of the circle is also included in the range). After the system is activated, it stretches the protective force field only over the part of the surface, which is within the area of all generators' activity. That is, the protected part is the intersection of the generators' active ranges.The number of generators available to the colonists is not limited, but the system of field generation consumes a lot of energy. More precisely, the energy consumption does not depend on the number of generators, but it is directly proportional to the area, which is protected by the field. Also, it is necessary that all the existing buildings are located within the protected area.Determine the smallest possible area of the protected part of the surface containing all the buildings.", "input_spec": "The first line contains two integers n and r (1\u2009\u2264\u2009n\u2009\u2264\u2009105, 1\u2009\u2264\u2009r\u2009\u2264\u200950000) \u2014 the number of buildings and the active ranges of the generators, correspondingly. Next n lines contains the buildings' coordinates. The i\u2009+\u20091-th (1\u2009\u2264\u2009i\u2009\u2264\u2009n) line contains two real numbers with at most three digits after the decimal point xi and yi (|xi|,\u2009|yi|\u2009\u2264\u200950000) \u2014 coordinates of the i-th building. It is guaranteed that no two buildings are located at the same point, and no two different buildings are located closer than 1. It is guaranteed that there exists a circle with radius r that contains all the buildings.", "output_spec": "Print the single real number \u2014 the minimum area of the protected part containing all the buildings. The answer is accepted if absolute or relative error doesn't exceed 10\u2009-\u20094.", "sample_inputs": ["3 5\n0.00 0.000\n0.0 8.00\n6 8.00", "4 1000\n0.0 0.0\n0 2.00\n2.00 2\n2.0 0.00", "4 5\n3.00 0.0\n-3 0.00\n0.000 1\n0.0 -1.00"], "sample_outputs": ["78.5398163397", "4.0026666140", "8.1750554397"], "notes": "NoteIn the first sample the given radius equals the radius of the circle circumscribed around the given points. That's why the circle that corresponds to it is the sought area. The answer is 25\u03c0.In the second sample the area nearly coincides with the square which has vertexes in the given points.The area for the third sample is shown on the picture below. "}, "src_uid": "5f2a0960bab9bdc91b190ed07d6adcf7"} {"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": "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": "\u00c6sir - CHAOS \u00c6sir - V.\"Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.The time right now...... 00:01:12......It's time.\"The emotion samples are now sufficient. After almost 3 years, it's time for Ivy to awake her bonded sister, Vanessa.The system inside A.R.C.'s Library core can be considered as an undirected graph with infinite number of processing nodes, numbered with all positive integers ($$$1, 2, 3, \\ldots$$$). The node with a number $$$x$$$ ($$$x > 1$$$), is directly connected with a node with number $$$\\frac{x}{f(x)}$$$, with $$$f(x)$$$ being the lowest prime divisor of $$$x$$$.Vanessa's mind is divided into $$$n$$$ fragments. Due to more than 500 years of coma, the fragments have been scattered: the $$$i$$$-th fragment is now located at the node with a number $$$k_i!$$$ (a factorial of $$$k_i$$$).To maximize the chance of successful awakening, Ivy decides to place the samples in a node $$$P$$$, so that the total length of paths from each fragment to $$$P$$$ is smallest possible. If there are multiple fragments located at the same node, the path from that node to $$$P$$$ needs to be counted multiple times.In the world of zeros and ones, such a requirement is very simple for Ivy. Not longer than a second later, she has already figured out such a node.But for a mere human like you, is this still possible?For simplicity, please answer the minimal sum of paths' lengths from every fragment to the emotion samples' assembly node $$$P$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$)\u00a0\u2014 number of fragments of Vanessa's mind. The second line contains $$$n$$$ integers: $$$k_1, k_2, \\ldots, k_n$$$ ($$$0 \\le k_i \\le 5000$$$), denoting the nodes where fragments of Vanessa's mind are located: the $$$i$$$-th fragment is at the node with a number $$$k_i!$$$.", "output_spec": "Print a single integer, denoting the minimal sum of path from every fragment to the node with the emotion samples (a.k.a. node $$$P$$$). As a reminder, if there are multiple fragments at the same node, the distance from that node to $$$P$$$ needs to be counted multiple times as well.", "sample_inputs": ["3\n2 1 4", "4\n3 1 4 4", "4\n3 1 4 1", "5\n3 1 4 1 5"], "sample_outputs": ["5", "6", "6", "11"], "notes": "NoteConsidering the first $$$24$$$ nodes of the system, the node network will look as follows (the nodes $$$1!$$$, $$$2!$$$, $$$3!$$$, $$$4!$$$ are drawn bold):For the first example, Ivy will place the emotion samples at the node $$$1$$$. From here: The distance from Vanessa's first fragment to the node $$$1$$$ is $$$1$$$. The distance from Vanessa's second fragment to the node $$$1$$$ is $$$0$$$. The distance from Vanessa's third fragment to the node $$$1$$$ is $$$4$$$. The total length is $$$5$$$.For the second example, the assembly node will be $$$6$$$. From here: The distance from Vanessa's first fragment to the node $$$6$$$ is $$$0$$$. The distance from Vanessa's second fragment to the node $$$6$$$ is $$$2$$$. The distance from Vanessa's third fragment to the node $$$6$$$ is $$$2$$$. The distance from Vanessa's fourth fragment to the node $$$6$$$ is again $$$2$$$. The total path length is $$$6$$$."}, "src_uid": "40002052843ca0357dbd3158b16d59f4"} {"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": "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": "In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4\u2009\u00d7\u20094 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2\u2009\u00d7\u20092 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2\u2009\u00d7\u20092 square, consisting of cells of the same color.", "input_spec": "Four lines contain four characters each: the j-th character of the i-th line equals \".\" if the cell in the i-th row and the j-th column of the square is painted white, and \"#\", if the cell is black.", "output_spec": "Print \"YES\" (without the quotes), if the test can be passed and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["####\n.#..\n####\n....", "####\n....\n####\n...."], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2\u2009\u00d7\u20092 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column."}, "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"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": "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": "You are given an integer array $$$a_0, a_1, \\dots, a_{n - 1}$$$, and an integer $$$k$$$. You perform the following code with it:long long ans = 0; // create a 64-bit signed variable which is initially equal to 0for(int i = 1; i <= k; i++){ int idx = rnd.next(0, n - 1); // generate a random integer between 0 and n - 1, both inclusive // each integer from 0 to n - 1 has the same probability of being chosen ans += a[idx]; a[idx] -= (a[idx] % i);}Your task is to calculate the expected value of the variable ans after performing this code.Note that the input is generated according to special rules (see the input format section).", "input_spec": "The only line contains six integers $$$n$$$, $$$a_0$$$, $$$x$$$, $$$y$$$, $$$k$$$ and $$$M$$$ ($$$1 \\le n \\le 10^7$$$; $$$1 \\le a_0, x, y < M \\le 998244353$$$; $$$1 \\le k \\le 17$$$). The array $$$a$$$ in the input is constructed as follows: $$$a_0$$$ is given in the input; for every $$$i$$$ from $$$1$$$ to $$$n - 1$$$, the value of $$$a_i$$$ can be calculated as $$$a_i = (a_{i - 1} \\cdot x + y) \\bmod M$$$. ", "output_spec": "Let the expected value of the variable ans after performing the code be $$$E$$$. It can be shown that $$$E \\cdot n^k$$$ is an integer. You have to output this integer modulo $$$998244353$$$.", "sample_inputs": ["3 10 3 5 13 88", "2 15363 270880 34698 17 2357023"], "sample_outputs": ["382842030", "319392398"], "notes": "NoteThe array in the first example test is $$$[10, 35, 22]$$$. In the second example, it is $$$[15363, 1418543]$$$."}, "src_uid": "1d45491e28d24e2b318605cd328d6ecf"} {"nl": {"description": "PolandBall is standing in a row with Many Other Balls. More precisely, there are exactly n Balls. Balls are proud of their home land\u00a0\u2014 and they want to prove that it's strong.The Balls decided to start with selecting exactly m groups of Balls, each consisting either of single Ball or two neighboring Balls. Each Ball can join no more than one group.The Balls really want to impress their Enemies. They kindly asked you to calculate number of such divisions for all m where 1\u2009\u2264\u2009m\u2009\u2264\u2009k. Output all these values modulo 998244353, the Enemies will be impressed anyway.", "input_spec": "There are exactly two numbers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009109, 1\u2009\u2264\u2009k\u2009<\u2009215), denoting the number of Balls and the maximim number of groups, respectively.", "output_spec": "You should output a sequence of k values. The i-th of them should represent the sought number of divisions into exactly i groups, according to PolandBall's rules.", "sample_inputs": ["3 3", "1 1", "5 10"], "sample_outputs": ["5 5 1", "1", "9 25 25 9 1 0 0 0 0 0"], "notes": "NoteIn the first sample case we can divide Balls into groups as follows: {1}, {2}, {3}, {12}, {23}.{12}{3}, {1}{23}, {1}{2}, {1}{3}, {2}{3}.{1}{2}{3}.Therefore, output is: 5 5 1."}, "src_uid": "266cc96acf6287f92a3bb0f8eccc5cf1"} {"nl": {"description": "A tree is a connected graph without cycles.Two trees, consisting of n vertices each, are called isomorphic if there exists a permutation p:\u2009{1,\u2009...,\u2009n}\u2009\u2192\u2009{1,\u2009...,\u2009n} such that the edge (u,\u2009v) is present in the first tree if and only if the edge (pu,\u2009pv) is present in the second tree.Vertex of the tree is called internal if its degree is greater than or equal to two.Count the number of different non-isomorphic trees, consisting of n vertices, such that the degree of each internal vertex is exactly d. Print the answer over the given prime modulo mod.", "input_spec": "The single line of the input contains three integers n, d and\u00a0mod (1\u2009\u2264\u2009n\u2009\u2264\u20091000, 2\u2009\u2264\u2009d\u2009\u2264\u200910, 108\u2009\u2264\u2009mod\u2009\u2264\u2009109) \u00a0\u2014 the number of vertices in the tree, the degree of internal vertices and the prime modulo.", "output_spec": "Print the number of trees over the modulo mod.", "sample_inputs": ["5 2 433416647", "10 3 409693891", "65 4 177545087"], "sample_outputs": ["1", "2", "910726"], "notes": null}, "src_uid": "bdd0fc1d6dbab5eeb5aea135fdfffc9d"} {"nl": {"description": "The Little Elephant very much loves sums on intervals.This time he has a pair of integers l and r (l\u2009\u2264\u2009r). The Little Elephant has to find the number of such integers x (l\u2009\u2264\u2009x\u2009\u2264\u2009r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.Help him and count the number of described numbers x for a given pair l and r.", "input_spec": "The single line contains a pair of integers l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20091018) \u2014 the boundaries of the interval. 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": "On a single line print a single integer \u2014 the answer to the problem.", "sample_inputs": ["2 47", "47 1024"], "sample_outputs": ["12", "98"], "notes": "NoteIn the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. "}, "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd"} {"nl": {"description": "Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter:How to build a wall: Take a set of bricks. Select one of the possible wall designs. Computing the number of possible designs is left as an exercise to the reader. Place bricks on top of each other, according to the chosen design. This seems easy enough. But Heidi is a Coding Cow, not a Constructing Cow. Her mind keeps coming back to point 2b. Despite the imminent danger of a zombie onslaught, she wonders just how many possible walls she could build with up to n bricks.A wall is a set of wall segments as defined in the easy version. How many different walls can be constructed such that the wall consists of at least 1 and at most n bricks? Two walls are different if there exist a column c and a row r such that one wall has a brick in this spot, and the other does not.Along with n, you will be given C, the width of the wall (as defined in the easy version). Return the number of different walls modulo 106\u2009+\u20093.", "input_spec": "The first line contains two space-separated integers n and C, 1\u2009\u2264\u2009n\u2009\u2264\u2009500000, 1\u2009\u2264\u2009C\u2009\u2264\u2009200000.", "output_spec": "Print the number of different walls that Heidi could build, modulo 106\u2009+\u20093.", "sample_inputs": ["5 1", "2 2", "3 2", "11 5", "37 63"], "sample_outputs": ["5", "5", "9", "4367", "230574"], "notes": "NoteThe number 106\u2009+\u20093 is prime.In the second sample case, the five walls are: B BB., .B, BB, B., and .BIn the third sample case, the nine walls are the five as in the second sample case and in addition the following four: B BB B B BB., .B, BB, and BB"}, "src_uid": "e63c70a9c96a94bce99618f2e695f83a"} {"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": "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": "A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.You're given a number. Determine if it is a magic number or not.", "input_spec": "The first line of input contains an integer n, (1\u2009\u2264\u2009n\u2009\u2264\u2009109). This number doesn't contain leading zeros.", "output_spec": "Print \"YES\" if n is a magic number or print \"NO\" if it's not.", "sample_inputs": ["114114", "1111", "441231"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"nl": {"description": "Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.", "input_spec": "You are given a string consisting of 6 characters (all characters are digits from 0 to 9) \u2014 this string denotes Luba's ticket. The ticket can start with the digit 0.", "output_spec": "Print one number \u2014 the minimum possible number of digits Luba needs to replace to make the ticket lucky.", "sample_inputs": ["000000", "123456", "111000"], "sample_outputs": ["0", "2", "1"], "notes": "NoteIn the first example the ticket is already lucky, so the answer is 0.In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required."}, "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"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": "They've screwed something up yet again... In one nuclear reactor of a research station an uncontrolled reaction is in progress and explosion which will destroy the whole station will happen soon.The station is represented by a square n\u2009\u00d7\u2009n divided into 1\u2009\u00d7\u20091 blocks. Each block is either a reactor or a laboratory. There can be several reactors and exactly one of them will explode soon. The reactors can be considered impassable blocks, but one can move through laboratories. Between any two laboratories, which are in adjacent blocks, there is a corridor. Blocks are considered adjacent if they have a common edge.In each laboratory there is some number of scientists and some number of rescue capsules. Once the scientist climbs into a capsule, he is considered to be saved. Each capsule has room for not more than one scientist.The reactor, which is about to explode, is damaged and a toxic coolant trickles from it into the neighboring blocks. The block, which contains the reactor, is considered infected. Every minute the coolant spreads over the laboratories through corridors. If at some moment one of the blocks is infected, then the next minute all the neighboring laboratories also become infected. Once a lab is infected, all the scientists there that are not in rescue capsules die. The coolant does not spread through reactor blocks.There are exactly t minutes to the explosion. Any scientist in a minute can move down the corridor to the next lab, if it is not infected. On any corridor an unlimited number of scientists can simultaneously move in both directions. It is believed that the scientists inside a lab moves without consuming time. Moreover, any scientist could get into the rescue capsule instantly. It is also believed that any scientist at any given moment always has the time to perform their actions (move from the given laboratory into the next one, or climb into the rescue capsule) before the laboratory will be infected.Find the maximum number of scientists who will be able to escape.", "input_spec": "The first line contains two integers n and t (2\u2009\u2264\u2009n\u2009\u2264\u200910, 1\u2009\u2264\u2009t\u2009\u2264\u200960). Each of the next n lines contains n characters. These lines describe the scientists' locations. Then exactly one empty line follows. Each of the next n more lines contains n characters. These lines describe the rescue capsules' locations. In the description of the scientists' and the rescue capsules' locations the character \"Y\" stands for a properly functioning reactor, \"Z\" stands for the malfunctioning reactor. The reactors' positions in both descriptions coincide. There is exactly one malfunctioning reactor on the station. The digits \"0\" - \"9\" stand for the laboratories. In the description of the scientists' locations those numbers stand for the number of scientists in the corresponding laboratories. In the rescue capsules' descriptions they stand for the number of such capsules in each laboratory.", "output_spec": "Print a single number \u2014 the maximum number of scientists who will manage to save themselves.", "sample_inputs": ["3 3\n1YZ\n1YY\n100\n\n0YZ\n0YY\n003", "4 4\nY110\n1Y1Z\n1Y0Y\n0100\n\nY001\n0Y0Z\n0Y0Y\n0005"], "sample_outputs": ["2", "3"], "notes": "NoteIn the second sample the events could take place as follows: "}, "src_uid": "544de9c3729a35eb08c143b1cb9ee085"} {"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": "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 calls a mask of a positive integer n the number that is obtained after successive writing of all lucky digits of number n from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number.Petya has two numbers \u2014 an arbitrary integer a and a lucky number b. Help him find the minimum number c (c\u2009>\u2009a) such that the mask of number c equals b.", "input_spec": "The only line contains two integers a and b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009105). It is guaranteed that number b is lucky.", "output_spec": "In the only line print a single number \u2014 the number c that is sought by Petya.", "sample_inputs": ["1 7", "100 47"], "sample_outputs": ["7", "147"], "notes": null}, "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb"} {"nl": {"description": "For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.For example, 4-rounding of 375 is 375\u00b780\u2009=\u200930000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.Write a program that will perform the k-rounding of n.", "input_spec": "The only line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009109, 0\u2009\u2264\u2009k\u2009\u2264\u20098).", "output_spec": "Print the k-rounding of n.", "sample_inputs": ["375 4", "10000 1", "38101 0", "123456789 8"], "sample_outputs": ["30000", "10000", "38101", "12345678900000000"], "notes": null}, "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"} {"nl": {"description": "Life in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are n junctions and m two way roads, at which one can get from each junction to any other one. The mayor wants to close some roads so that the number of roads left totaled to n\u2009-\u20091 roads and it were still possible to get from each junction to any other one. Besides, the mayor is concerned with the number of dead ends which are the junctions from which only one road goes. There shouldn't be too many or too few junctions. Having discussed the problem, the mayor and his assistants decided that after the roads are closed, the road map should contain exactly k dead ends. Your task is to count the number of different ways of closing the roads at which the following conditions are met: There are exactly n\u2009-\u20091 roads left. It is possible to get from each junction to any other one. There are exactly k dead ends on the resulting map. Two ways are considered different if there is a road that is closed in the first way, and is open in the second one.", "input_spec": "The first line contains three integers n, m and k (3\u2009\u2264\u2009n\u2009\u2264\u200910,\u2009n\u2009-\u20091\u2009\u2264\u2009m\u2009\u2264\u2009n\u00b7(n\u2009-\u20091)\u2009/\u20092,\u20092\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009-\u20091) which represent the number of junctions, roads and dead ends correspondingly. Then follow m lines each containing two different integers v1 and v2 (1\u2009\u2264\u2009v1,\u2009v2\u2009\u2264\u2009n,\u2009v1\u2009\u2260\u2009v2) which represent the number of junctions connected by another road. There can be no more than one road between every pair of junctions. The junctions are numbered with integers from 1 to n. It is guaranteed that it is possible to get from each junction to any other one along the original roads.", "output_spec": "Print a single number \u2014 the required number of ways.", "sample_inputs": ["3 3 2\n1 2\n2 3\n1 3", "4 6 2\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4", "4 6 3\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4"], "sample_outputs": ["3", "12", "4"], "notes": null}, "src_uid": "8087605a8f316150372cc4627f26231d"} {"nl": {"description": "It is known that passages in Singer house are complex and intertwined. Let's define a Singer k-house as a graph built by the following process: take complete binary tree of height k and add edges from each vertex to all its successors, if they are not yet present. Singer 4-house Count the number of non-empty paths in Singer k-house which do not pass the same vertex twice. Two paths are distinct if the sets or the orders of visited vertices are different. Since the answer can be large, output it modulo 109\u2009+\u20097.", "input_spec": "The only line contains single integer k (1\u2009\u2264\u2009k\u2009\u2264\u2009400).", "output_spec": "Print single integer\u00a0\u2014 the answer for the task modulo 109\u2009+\u20097.", "sample_inputs": ["2", "3", "20"], "sample_outputs": ["9", "245", "550384565"], "notes": "NoteThere are 9 paths in the first example (the vertices are numbered on the picture below): 1, 2, 3, 1-2, 2-1, 1-3, 3-1, 2-1-3, 3-1-2. Singer 2-house "}, "src_uid": "fda761834f7b5800f540178ac1c79fca"} {"nl": {"description": "Vasya has a set of 4n strings of equal length, consisting of lowercase English letters \"a\", \"b\", \"c\", \"d\" and \"e\". Moreover, the set is split into n groups of 4 equal strings each. Vasya also has one special string a of the same length, consisting of letters \"a\" only.Vasya wants to obtain from string a some fixed string b, in order to do this, he can use the strings from his set in any order. When he uses some string x, each of the letters in string a replaces with the next letter in alphabet as many times as the alphabet position, counting from zero, of the corresponding letter in string x. Within this process the next letter in alphabet after \"e\" is \"a\".For example, if some letter in a equals \"b\", and the letter on the same position in x equals \"c\", then the letter in a becomes equal \"d\", because \"c\" is the second alphabet letter, counting from zero. If some letter in a equals \"e\", and on the same position in x is \"d\", then the letter in a becomes \"c\". For example, if the string a equals \"abcde\", and string x equals \"baddc\", then a becomes \"bbabb\".A used string disappears, but Vasya can use equal strings several times.Vasya wants to know for q given strings b, how many ways there are to obtain from the string a string b using the given set of 4n strings? Two ways are different if the number of strings used from some group of 4 strings is different. Help Vasya compute the answers for these questions modulo 109\u2009+\u20097.", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009500)\u00a0\u2014 the number of groups of four strings in the set, and the length of all strings. Each of the next n lines contains a string s of length m, consisting of lowercase English letters \"a\", \"b\", \"c\", \"d\" and \"e\". This means that there is a group of four strings equal to s. The next line contains single integer q (1\u2009\u2264\u2009q\u2009\u2264\u2009300)\u00a0\u2014 the number of strings b Vasya is interested in. Each of the next q strings contains a string b of length m, consisting of lowercase English letters \"a\", \"b\", \"c\", \"d\" and \"e\"\u00a0\u2014 a string Vasya is interested in.", "output_spec": "For each string Vasya is interested in print the number of ways to obtain it from string a, modulo 109\u2009+\u20097.", "sample_inputs": ["1 1\nb\n2\na\ne", "2 4\naaaa\nbbbb\n1\ncccc"], "sample_outputs": ["1\n1", "5"], "notes": "NoteIn the first example, we have 4 strings \"b\". Then we have the only way for each string b: select 0 strings \"b\" to get \"a\" and select 4 strings \"b\" to get \"e\", respectively. So, we have 1 way for each request.In the second example, note that the choice of the string \"aaaa\" does not change anything, that is we can choose any amount of it (from 0 to 4, it's 5 different ways) and we have to select the line \"bbbb\" 2 times, since other variants do not fit. We get that we have 5 ways for the request."}, "src_uid": "5cb18864c88b7fdec4a85718df67333e"} {"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": "You have $$$c_1$$$ letters 'a', $$$c_2$$$ letters 'b', ..., $$$c_{26}$$$ letters 'z'. You want to build a beautiful string of length $$$n$$$ from them (obviously, you cannot use the $$$i$$$-th letter more than $$$c_i$$$ times). Each $$$c_i$$$ is greater than $$$\\frac{n}{3}$$$.A string is called beautiful if there are no palindromic contiguous substrings of odd length greater than $$$1$$$ in it. For example, the string \"abacaba\" is not beautiful, it has several palindromic substrings of odd length greater than $$$1$$$ (for example, \"aca\"). Another example: the string \"abcaa\" is beautiful.Calculate the number of different strings you can build, and print the answer modulo $$$998244353$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$3 \\le n \\le 400$$$). The second line contains $$$26$$$ integers $$$c_1$$$, $$$c_2$$$, ..., $$$c_{26}$$$ ($$$\\frac{n}{3} < c_i \\le n$$$).", "output_spec": "Print one integer \u2014 the number of strings you can build, taken modulo $$$998244353$$$.", "sample_inputs": ["4\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "3\n2 2 2 2 2 2 3 3 3 2 2 2 2 2 2 3 3 3 2 2 3 2 2 3 2 2", "400\n348 322 247 158 209 134 151 267 268 176 214 379 372 291 388 135 147 304 169 149 193 351 380 368 181 340"], "sample_outputs": ["422500", "16900", "287489790"], "notes": null}, "src_uid": "1f012349f4b229dc98faadf1ca732355"} {"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": "InputThe input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.OutputOutput \"YES\" or \"NO\".ExamplesInput\nHELP\nOutput\nYES\nInput\nAID\nOutput\nNO\nInput\nMARY\nOutput\nNO\nInput\nANNA\nOutput\nYES\nInput\nMUG\nOutput\nYES\nInput\nCUP\nOutput\nNO\nInput\nSUM\nOutput\nYES\nInput\nPRODUCT\nOutput\nNO\n", "input_spec": "The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.", "output_spec": "Output \"YES\" or \"NO\".", "sample_inputs": ["HELP", "AID", "MARY", "ANNA", "MUG", "CUP", "SUM", "PRODUCT"], "sample_outputs": ["YES", "NO", "NO", "YES", "YES", "NO", "YES", "NO"], "notes": null}, "src_uid": "27e977b41f5b6970a032d13e53db2a6a"} {"nl": {"description": "Mr. Bender has a digital table of size n\u2009\u00d7\u2009n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.We'll consider the table rows numbered from top to bottom from 1 to n, and the columns \u2014 numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x,\u2009y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.For a cell with coordinates (x,\u2009y) the side-adjacent cells are cells with coordinates (x\u2009-\u20091,\u2009y), (x\u2009+\u20091,\u2009y), (x,\u2009y\u2009-\u20091), (x,\u2009y\u2009+\u20091).In how many seconds will Mr. Bender get happy?", "input_spec": "The first line contains four space-separated integers n,\u2009x,\u2009y,\u2009c (1\u2009\u2264\u2009n,\u2009c\u2009\u2264\u2009109;\u00a01\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009n;\u00a0c\u2009\u2264\u2009n2).", "output_spec": "In a single line print a single integer \u2014 the answer to the problem.", "sample_inputs": ["6 4 3 1", "9 3 8 10"], "sample_outputs": ["0", "2"], "notes": "NoteInitially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. ."}, "src_uid": "232c5206ee7c1903556c3625e0b0efc6"} {"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": "We are going to build a new city: the Metropolis. The city is going to be built on an infinite square grid. The finished city will consist of $$$n$$$ skyscrapers, each occupying a different cell of the grid. At any moment during the construction, the cells that currently do not contain a skyscraper are called empty.You are given the planned coordinates of the $$$n$$$ skyscrapers. Your task is to find an order in which they can be built while satisfying the rules listed below. The building crew has only one crane, so the Metropolis has to be constructed one skyscraper at a time. The first skyscraper can be built anywhere on the grid. Each subsequent skyscraper has to share a side or a corner with at least one of the previously built skyscrapers (so that it's easier to align the new skyscraper to the grid properly). When building a skyscraper, there has to be a way to deliver material to the construction site from the outside of Metropolis by only moving it through empty cells that share a side. In other words, there should be a path of side-adjacent empty cells that connects the cell that will contain the skyscraper to some cell $$$(r,c)$$$ with $$$|r|>10^9$$$ and/or $$$|c|>10^9$$$. If a solution exists, let's denote the numbers of skyscrapers in the order in which they should be built by $$$s_1, \\dots, s_n$$$. There are two types of subtasks:Type 1: You may produce any valid order.Type 2: You must find the order that maximizes $$$s_n$$$. Among those, you must find the one that maximizes $$$s_{n-1}$$$. And so on. In other words, you must find the valid order of building for which the sequence $$$(s_n,s_{n-1},\\dots,s_1)$$$ is lexicographically largest.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 150,000$$$) \u2013 the number of skyscrapers. The second line contains a single integer $$$t$$$ ($$$1 \\le t \\le 2$$$) describing the type of the subtask as defined above. Then, $$$n$$$ lines follow. The $$$i$$$-th of these lines contains two space-separated integers $$$r_i$$$ and $$$c_i$$$ ($$$|r_i|, |c_i| \\le 10^9$$$) denoting the coordinates of the cell containing skyscraper $$$i$$$. (The skyscrapers are not numbered in any particular order. The only reason why they have numbers is that they are used in the output format.) It is guaranteed that no two skyscrapers coincide.", "output_spec": "If it is impossible to build the skyscrapers according to the given rules, print a single line containing the string \"NO\". Otherwise, print $$$n+1$$$ lines. The first of these lines should contain the string \"YES\". For each $$$i$$$, the $$$i$$$-th of the remaining $$$n$$$ lines should contain a single integer $$$s_i$$$. In subtasks with $$$t = 1$$$, if there are multiple valid orders, you may output any one of them.", "sample_inputs": ["3\n2\n0 0\n0 1\n0 2", "3\n1\n0 0\n1 1\n2 2", "2\n1\n0 0\n0 2"], "sample_outputs": ["YES\n1\n2\n3", "YES\n2\n3\n1", "NO"], "notes": "NoteIn the first example, there are three skyscrapers in a row. All of them can always be reached from outside the Metropolis, and there are four build orders which preserve connectivity: 1, 2, 3 2, 1, 3 2, 3, 1 3, 2, 1 Since $$$t = 2$$$, we must choose the first option.In the second example, the only difference from the first example is that skyscraper 2 shares only corners with skyscrapers 1 and 3, the same set of orders as in the first sample is valid. Since $$$t = 1$$$, each of these answers is correct.In the third example, the Metropolis is disconnected. We obviously can't build that."}, "src_uid": "873aca0e5ff5dccf8af62f7b244fef6b"} {"nl": {"description": "Calculate the number of ways to place $$$n$$$ rooks on $$$n \\times n$$$ chessboard so that both following conditions are met: each empty cell is under attack; exactly $$$k$$$ pairs of rooks attack each other. An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two rooks attack each other if they share the same row or column, and there are no other rooks between them. For example, there are only two pairs of rooks that attack each other in the following picture: One of the ways to place the rooks for $$$n = 3$$$ and $$$k = 2$$$ Two ways to place the rooks are considered different if there exists at least one cell which is empty in one of the ways but contains a rook in another way.The answer might be large, so print it modulo $$$998244353$$$.", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 200000$$$; $$$0 \\le k \\le \\frac{n(n - 1)}{2}$$$).", "output_spec": "Print one integer \u2014 the number of ways to place the rooks, taken modulo $$$998244353$$$.", "sample_inputs": ["3 2", "3 3", "4 0", "1337 42"], "sample_outputs": ["6", "0", "24", "807905441"], "notes": null}, "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc"} {"nl": {"description": "In the year 2500 the annual graduation ceremony in the German University in Cairo (GUC) has run smoothly for almost 500 years so far.The most important part of the ceremony is related to the arrangement of the professors in the ceremonial hall.Traditionally GUC has n professors. Each professor has his seniority level. All seniorities are different. Let's enumerate the professors from 1 to n, with 1 being the most senior professor and n being the most junior professor.The ceremonial hall has n seats, one seat for each professor. Some places in this hall are meant for more senior professors than the others. More specifically, m pairs of seats are in \"senior-junior\" relation, and the tradition requires that for all m pairs of seats (ai,\u2009bi) the professor seated in \"senior\" position ai should be more senior than the professor seated in \"junior\" position bi.GUC is very strict about its traditions, which have been carefully observed starting from year 2001. The tradition requires that: The seating of the professors changes every year. Year 2001 ceremony was using lexicographically first arrangement of professors in the ceremonial hall. Each consecutive year lexicographically next arrangement of the professors is used. The arrangement of the professors is the list of n integers, where the first integer is the seniority of the professor seated in position number one, the second integer is the seniority of the professor seated in position number two, etc.Given n, the number of professors, y, the current year and m pairs of restrictions, output the arrangement of the professors for this year.", "input_spec": "The first line contains three integers n, y and m (1\u2009\u2264\u2009n\u2009\u2264\u200916,\u20092001\u2009\u2264\u2009y\u2009\u2264\u20091018,\u20090\u2009\u2264\u2009m\u2009\u2264\u2009100) \u2014 the number of professors, the year for which the arrangement should be computed, and the number of pairs of seats for which the seniority relation should be kept, respectively. The next m lines contain one pair of integers each, \"ai bi\", indicating that professor on the ai-th seat is more senior than professor on the bi-th seat (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u2009n,\u2009ai\u2009\u2260\u2009bi). Some pair may be listed more than once. Please, do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use the cin stream (you may also use the %I64d specificator).", "output_spec": "Print the order in which the professors should be seated in the requested year. If by this year the GUC would have ran out of arrangements, or the given \"senior-junior\" relation are contradictory, print \"The times have changed\" (without quotes).", "sample_inputs": ["3 2001 2\n1 2\n2 3", "7 2020 6\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "10 3630801 0", "3 2001 3\n1 2\n2 3\n3 1"], "sample_outputs": ["1 2 3", "1 2 3 7 4 6 5", "The times have changed", "The times have changed"], "notes": "NoteIn the first example the lexicographically first order of seating is 1 2 3.In the third example the GUC will run out of arrangements after the year 3630800.In the fourth example there are no valid arrangements for the seating.The lexicographical comparison of arrangements is performed by the < operator in modern programming languages. The arrangement a is lexicographically less that the arrangement b, if there exists such i (1\u2009\u2264\u2009i\u2009\u2264\u2009n), that ai\u2009<\u2009bi, and for any j (1\u2009\u2264\u2009j\u2009<\u2009i) aj\u2009=\u2009bj."}, "src_uid": "e9db8d048e9763cf38c584342dea9f53"} {"nl": {"description": "It's tough to be a superhero. And it's twice as tough to resist the supervillain who is cool at math. Suppose that you're an ordinary Batman in an ordinary city of Gotham. Your enemy Joker mined the building of the city administration and you only have several minutes to neutralize the charge. To do that you should enter the cancel code on the bomb control panel.However, that mad man decided to give you a hint. This morning the mayor found a playing card under his pillow. There was a line written on the card:The bomb has a note saying \"J(x)\u2009=\u2009A\", where A is some positive integer. You suspect that the cancel code is some integer x that meets the equation J(x)\u2009=\u2009A. Now in order to decide whether you should neutralize the bomb or run for your life, you've got to count how many distinct positive integers x meet this equation.", "input_spec": "The single line of the input contains a single integer A (1\u2009\u2264\u2009A\u2009\u2264\u20091012).", "output_spec": "Print the number of solutions of the equation J(x)\u2009=\u2009A.", "sample_inputs": ["3", "24"], "sample_outputs": ["1", "3"], "notes": "NoteRecord x|n means that number n divides number x. is defined as the largest positive integer that divides both a and b.In the first sample test the only suitable value of x is 2. Then J(2)\u2009=\u20091\u2009+\u20092.In the second sample test the following values of x match: x\u2009=\u200914, J(14)\u2009=\u20091\u2009+\u20092\u2009+\u20097\u2009+\u200914\u2009=\u200924 x\u2009=\u200915, J(15)\u2009=\u20091\u2009+\u20093\u2009+\u20095\u2009+\u200915\u2009=\u200924 x\u2009=\u200923, J(23)\u2009=\u20091\u2009+\u200923\u2009=\u200924 "}, "src_uid": "1f68bd6f8b40e45a5bd360b03a264ef4"} {"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 dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how many lucky numbers in the permutation are located on the positions whose indexes are also lucky numbers.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009109) \u2014 the number of elements in the permutation and the lexicographical number of the permutation.", "output_spec": "If the k-th permutation of numbers from 1 to n does not exist, print the single number \"-1\" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes i, that i and ai are both lucky numbers.", "sample_inputs": ["7 4", "4 7"], "sample_outputs": ["1", "1"], "notes": "NoteA permutation is an ordered set of n elements, where each integer from 1 to n occurs exactly once. The element of permutation in position with index i is denoted as ai (1\u2009\u2264\u2009i\u2009\u2264\u2009n). Permutation a is lexicographically smaller that permutation b if there is such a i (1\u2009\u2264\u2009i\u2009\u2264\u2009n), that ai\u2009<\u2009bi, and for any j (1\u2009\u2264\u2009j\u2009<\u2009i) aj\u2009=\u2009bj. Let's make a list of all possible permutations of n elements and sort it in the order of lexicographical increasing. Then the lexicographically k-th permutation is the k-th element of this list of permutations.In the first sample the permutation looks like that:1 2 3 4 6 7 5The only suitable position is 4.In the second sample the permutation looks like that:2 1 3 4The only suitable position is 4."}, "src_uid": "cb2aa02772f95fefd1856960b6ceac4c"} {"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 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": "Note that the memory limit in this problem is lower than in others.You have a vertical strip with $$$n$$$ cells, numbered consecutively from $$$1$$$ to $$$n$$$ from top to bottom.You also have a token that is initially placed in cell $$$n$$$. You will move the token up until it arrives at cell $$$1$$$.Let the token be in cell $$$x > 1$$$ at some moment. One shift of the token can have either of the following kinds: Subtraction: you choose an integer $$$y$$$ between $$$1$$$ and $$$x-1$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$x - y$$$. Floored division: you choose an integer $$$z$$$ between $$$2$$$ and $$$x$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$\\lfloor \\frac{x}{z} \\rfloor$$$ ($$$x$$$ divided by $$$z$$$ rounded down). Find the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$ using one or more shifts, and print it modulo $$$m$$$. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le 4 \\cdot 10^6$$$; $$$10^8 < m < 10^9$$$; $$$m$$$ is a prime number)\u00a0\u2014 the length of the strip and the modulo.", "output_spec": "Print the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$, modulo $$$m$$$.", "sample_inputs": ["3 998244353", "5 998244353", "42 998244353", "787788 100000007"], "sample_outputs": ["5", "25", "793019428", "94810539"], "notes": "NoteIn the first test, there are three ways to move the token from cell $$$3$$$ to cell $$$1$$$ in one shift: using subtraction of $$$y = 2$$$, or using division by $$$z = 2$$$ or $$$z = 3$$$.There are also two ways to move the token from cell $$$3$$$ to cell $$$1$$$ via cell $$$2$$$: first subtract $$$y = 1$$$, and then either subtract $$$y = 1$$$ again or divide by $$$z = 2$$$.Therefore, there are five ways in total."}, "src_uid": "77443424be253352aaf2b6c89bdd4671"} {"nl": {"description": "There are two strings s and t, consisting only of letters a and b. You can make the following operation several times: choose a prefix of s, a prefix of t and swap them. Prefixes can be empty, also a prefix can coincide with a whole string. Your task is to find a sequence of operations after which one of the strings consists only of a letters and the other consists only of b letters. The number of operations should be minimized.", "input_spec": "The first line contains a string s (1\u2009\u2264\u2009|s|\u2009\u2264\u20092\u00b7105). The second line contains a string t (1\u2009\u2264\u2009|t|\u2009\u2264\u20092\u00b7105). Here |s| and |t| denote the lengths of s and t, respectively. It is guaranteed that at least one of the strings contains at least one a letter and at least one of the strings contains at least one b letter.", "output_spec": "The first line should contain a single integer n (0\u2009\u2264\u2009n\u2009\u2264\u20095\u00b7105)\u00a0\u2014 the number of operations. Each of the next n lines should contain two space-separated integers ai, bi\u00a0\u2014 the lengths of prefixes of s and t to swap, respectively. If there are multiple possible solutions, you can print any of them. It's guaranteed that a solution with given constraints exists.", "sample_inputs": ["bab\nbb", "bbbb\naaa"], "sample_outputs": ["2\n1 0\n1 3", "0"], "notes": "NoteIn the first example, you can solve the problem in two operations: Swap the prefix of the first string with length 1 and the prefix of the second string with length 0. After this swap, you'll have strings ab and bbb. Swap the prefix of the first string with length 1 and the prefix of the second string with length 3. After this swap, you'll have strings bbbb and a. In the second example, the strings are already appropriate, so no operations are needed."}, "src_uid": "4a50c4147becea13946272230f3dde6d"} {"nl": {"description": "This is an easier version of the problem. In this version, $$$n \\le 500$$$.Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believes, that the beauty of the bracket string is a number of its cyclical shifts, which form a correct bracket sequence.To digress from his problems, Vasya decided to select two positions of the string (not necessarily distinct) and swap characters located at this positions with each other. Vasya will apply this operation exactly once. He is curious what is the maximum possible beauty he can achieve this way. Please help him.We remind that bracket sequence $$$s$$$ is called correct if: $$$s$$$ is empty; $$$s$$$ is equal to \"($$$t$$$)\", where $$$t$$$ is correct bracket sequence; $$$s$$$ is equal to $$$t_1 t_2$$$, i.e. concatenation of $$$t_1$$$ and $$$t_2$$$, where $$$t_1$$$ and $$$t_2$$$ are correct bracket sequences. For example, \"(()())\", \"()\" are correct, while \")(\" and \"())\" are not.The cyclical shift of the string $$$s$$$ of length $$$n$$$ by $$$k$$$ ($$$0 \\leq k < n$$$) is a string formed by a concatenation of the last $$$k$$$ symbols of the string $$$s$$$ with the first $$$n - k$$$ symbols of string $$$s$$$. For example, the cyclical shift of string \"(())()\" by $$$2$$$ equals \"()(())\".Cyclical shifts $$$i$$$ and $$$j$$$ are considered different, if $$$i \\ne j$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 500$$$), the length of the string. The second line contains a string, consisting of exactly $$$n$$$ characters, where each of the characters is either \"(\" or \")\".", "output_spec": "The first line should contain a single integer\u00a0\u2014 the largest beauty of the string, which can be achieved by swapping some two characters. The second line should contain integers $$$l$$$ and $$$r$$$ ($$$1 \\leq l, r \\leq n$$$)\u00a0\u2014 the indices of two characters, which should be swapped in order to maximize the string's beauty. In case there are several possible swaps, print any of them.", "sample_inputs": ["10\n()()())(()", "12\n)(()(()())()", "6\n)))(()"], "sample_outputs": ["5\n8 7", "4\n5 10", "0\n1 1"], "notes": "NoteIn the first example, we can swap $$$7$$$-th and $$$8$$$-th character, obtaining a string \"()()()()()\". The cyclical shifts by $$$0, 2, 4, 6, 8$$$ of this string form a correct bracket sequence.In the second example, after swapping $$$5$$$-th and $$$10$$$-th character, we obtain a string \")(())()()(()\". The cyclical shifts by $$$11, 7, 5, 3$$$ of this string form a correct bracket sequence.In the third example, swap of any two brackets results in $$$0$$$ cyclical shifts being correct bracket sequences. "}, "src_uid": "2d10668fcc2d8e90e102b043f5e0578d"} {"nl": {"description": "Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to earn a lot of cheese. He will hand the three numbers x, y and z to Rat Kwesh, and Rat Kwesh will pick one of the these twelve options: a1\u2009=\u2009xyz; a2\u2009=\u2009xzy; a3\u2009=\u2009(xy)z; a4\u2009=\u2009(xz)y; a5\u2009=\u2009yxz; a6\u2009=\u2009yzx; a7\u2009=\u2009(yx)z; a8\u2009=\u2009(yz)x; a9\u2009=\u2009zxy; a10\u2009=\u2009zyx; a11\u2009=\u2009(zx)y; a12\u2009=\u2009(zy)x. Let m be the maximum of all the ai, and c be the smallest index (from 1 to 12) such that ac\u2009=\u2009m. Rat's goal is to find that c, and he asks you to help him. Rat Kwesh wants to see how much cheese he gets, so he you will have to print the expression corresponding to that ac. ", "input_spec": "The only line of the input contains three space-separated real numbers x, y and z (0.1\u2009\u2264\u2009x,\u2009y,\u2009z\u2009\u2264\u2009200.0). Each of x, y and z is given with exactly one digit after the decimal point.", "output_spec": "Find the maximum value of expression among xyz, xzy, (xy)z, (xz)y, yxz, yzx, (yx)z, (yz)x, zxy, zyx, (zx)y, (zy)x and print the corresponding expression. If there are many maximums, print the one that comes first in the list. xyz should be outputted as x^y^z (without brackets), and (xy)z should be outputted as (x^y)^z (quotes for clarity). ", "sample_inputs": ["1.1 3.4 2.5", "2.0 2.0 2.0", "1.9 1.8 1.7"], "sample_outputs": ["z^y^x", "x^y^z", "(x^y)^z"], "notes": null}, "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c"} {"nl": {"description": "In problems on strings one often has to find a string with some particular properties. The problem authors were reluctant to waste time on thinking of a name for some string so they called it good. A string is good if it doesn't have palindrome substrings longer than or equal to d. You are given string s, consisting only of lowercase English letters. Find a good string t with length |s|, consisting of lowercase English letters, which is lexicographically larger than s. Of all such strings string t must be lexicographically minimum.We will call a non-empty string s[a\u00a0...\u00a0b]\u2009=\u2009sasa\u2009+\u20091... sb (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009|s|) a substring of string s\u2009=\u2009s1s2... s|s|.A non-empty string s\u2009=\u2009s1s2... sn is called a palindrome if for all i from 1 to n the following fulfills: si\u2009=\u2009sn\u2009-\u2009i\u2009+\u20091. In other words, palindrome read the same in both directions.String x\u2009=\u2009x1x2... x|x| is lexicographically larger than string y\u2009=\u2009y1y2... y|y|, if either |x|\u2009>\u2009|y| and x1\u2009=\u2009y1,\u2009x2\u2009=\u2009y2,\u2009... ,\u2009x|y|\u2009=\u2009y|y|, or there exists such number r (r\u2009<\u2009|x|,\u2009r\u2009<\u2009|y|), that x1\u2009=\u2009y1,\u2009x2\u2009=\u2009y2,\u2009... ,\u2009xr\u2009=\u2009yr and xr\u2009+\u20091\u2009>\u2009yr\u2009+\u20091. Characters in such strings are compared like their ASCII codes.", "input_spec": "The first line contains integer d (1\u2009\u2264\u2009d\u2009\u2264\u2009|s|). The second line contains a non-empty string s, its length is no more than 4\u00b7105 characters. The string consists of lowercase English letters.", "output_spec": "Print the good string that lexicographically follows s, has the same length and consists of only lowercase English letters. If such string does not exist, print \"Impossible\" (without the quotes).", "sample_inputs": ["3\naaaaaaa", "3\nzzyzzzz", "4\nabbabbbabbb"], "sample_outputs": ["aabbcaa", "Impossible", "abbbcaaabab"], "notes": null}, "src_uid": "959a274a06219f4a8c061cd6f5b17160"} {"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": "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": "Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches.Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch.", "input_spec": "The only line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u200910000).", "output_spec": "Print two non-negative space-separated integers a and b, where a is the numbers of feet and b is the number of inches.", "sample_inputs": ["42", "5"], "sample_outputs": ["1 2", "0 2"], "notes": null}, "src_uid": "5d4f38ffd1849862623325fdbe06cd00"} {"nl": {"description": "Alice and Bob are decorating a Christmas Tree. Alice wants only $$$3$$$ types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have $$$y$$$ yellow ornaments, $$$b$$$ blue ornaments and $$$r$$$ red ornaments.In Bob's opinion, a Christmas Tree will be beautiful if: the number of blue ornaments used is greater by exactly $$$1$$$ than the number of yellow ornaments, and the number of red ornaments used is greater by exactly $$$1$$$ than the number of blue ornaments. That is, if they have $$$8$$$ yellow ornaments, $$$13$$$ blue ornaments and $$$9$$$ red ornaments, we can choose $$$4$$$ yellow, $$$5$$$ blue and $$$6$$$ red ornaments ($$$5=4+1$$$ and $$$6=5+1$$$).Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.In the example two paragraphs above, we would choose $$$7$$$ yellow, $$$8$$$ blue and $$$9$$$ red ornaments. If we do it, we will use $$$7+8+9=24$$$ ornaments. That is the maximum number.Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree! It is guaranteed that it is possible to choose at least $$$6$$$ ($$$1+2+3=6$$$) ornaments.", "input_spec": "The only line contains three integers $$$y$$$, $$$b$$$, $$$r$$$ ($$$1 \\leq y \\leq 100$$$, $$$2 \\leq b \\leq 100$$$, $$$3 \\leq r \\leq 100$$$)\u00a0\u2014 the number of yellow, blue and red ornaments. It is guaranteed that it is possible to choose at least $$$6$$$ ($$$1+2+3=6$$$) ornaments.", "output_spec": "Print one number\u00a0\u2014 the maximum number of ornaments that can be used. ", "sample_inputs": ["8 13 9", "13 3 6"], "sample_outputs": ["24", "9"], "notes": "NoteIn the first example, the answer is $$$7+8+9=24$$$.In the second example, the answer is $$$2+3+4=9$$$."}, "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"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": "Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make k consecutive trips in the lift.Let us suppose that at the moment you are on the floor number x (initially, you were on floor a). For another trip between floors you choose some floor with number y (y\u2009\u2260\u2009x) and the lift travels to this floor. As you cannot visit floor b with the secret lab, you decided that the distance from the current floor x to the chosen y must be strictly less than the distance from the current floor x to floor b with the secret lab. Formally, it means that the following inequation must fulfill: |x\u2009-\u2009y|\u2009<\u2009|x\u2009-\u2009b|. After the lift successfully transports you to floor y, you write down number y in your notepad.Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of k trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 (109\u2009+\u20097).", "input_spec": "The first line of the input contains four space-separated integers n, a, b, k (2\u2009\u2264\u2009n\u2009\u2264\u20095000, 1\u2009\u2264\u2009k\u2009\u2264\u20095000, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009n, a\u2009\u2260\u2009b).", "output_spec": "Print a single integer \u2014 the remainder after dividing the sought number of sequences by 1000000007 (109\u2009+\u20097).", "sample_inputs": ["5 2 4 1", "5 2 4 2", "5 3 4 1"], "sample_outputs": ["2", "2", "0"], "notes": "NoteTwo sequences p1,\u2009p2,\u2009...,\u2009pk and q1,\u2009q2,\u2009...,\u2009qk are distinct, if there is such integer j (1\u2009\u2264\u2009j\u2009\u2264\u2009k), that pj\u2009\u2260\u2009qj.Notes to the samples: In the first sample after the first trip you are either on floor 1, or on floor 3, because |1\u2009-\u20092|\u2009<\u2009|2\u2009-\u20094| and |3\u2009-\u20092|\u2009<\u2009|2\u2009-\u20094|. In the second sample there are two possible sequences: (1,\u20092); (1,\u20093). You cannot choose floor 3 for the first trip because in this case no floor can be the floor for the second trip. In the third sample there are no sought sequences, because you cannot choose the floor for the first trip. "}, "src_uid": "142b06ed43b3473513995de995e19fc3"} {"nl": {"description": "Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items?", "input_spec": "The only line of the input data contains a non-empty string consisting of letters \"\u0421\" and \"P\" whose length does not exceed 100 characters. If the i-th character in the string is the letter \"\u0421\", that means that the i-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the i-th character is the letter \"P\", than the i-th object on the wall is a photo.", "output_spec": "Print the only number \u2014 the minimum number of times Polycarpus has to visit the closet.", "sample_inputs": ["CPCPCPC", "CCCCCCPPPPPP", "CCCCCCPPCPPPPPPPPPP", "CCCCCCCCCC"], "sample_outputs": ["7", "4", "6", "2"], "notes": "NoteIn the first sample Polycarpus needs to take one item to the closet 7 times.In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice.In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go)."}, "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"} {"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": "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": "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": "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": "We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893)\u2009=\u20093, S(114514)\u2009=\u20096.You want to make a consecutive integer sequence starting from number m (m,\u2009m\u2009+\u20091,\u2009...). But you need to pay S(n)\u00b7k to add the number n to the sequence.You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.", "input_spec": "The first line contains three integers w (1\u2009\u2264\u2009w\u2009\u2264\u20091016), m (1\u2009\u2264\u2009m\u2009\u2264\u20091016), k (1\u2009\u2264\u2009k\u2009\u2264\u2009109). Please, do not write 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": "The first line should contain a single integer \u2014 the answer to the problem.", "sample_inputs": ["9 1 1", "77 7 7", "114 5 14", "1 1 2"], "sample_outputs": ["9", "7", "6", "0"], "notes": null}, "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea"} {"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": "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": "You, the mighty Blackout, are standing in the upper-left $$$(0,0)$$$ corner of $$$N$$$x$$$M$$$ matrix. You must move either right or down each second. There are $$$K$$$ transformers jumping around the matrix in the following way. Each transformer starts jumping from position $$$(x,y)$$$, at time $$$t$$$, and jumps to the next position each second. The $$$x$$$-axes grows downwards, and $$$y$$$-axes grows to the right. The order of jumping positions is defined as $$${(x,y),(x+d,y-d),(x+d,y),(x,y+d)}$$$, and is periodic. Before time $$$t$$$ transformer is not in the matrix.You want to arrive to the bottom-right corner $$$(N-1,M-1)$$$, while slaying transformers and losing the least possible amount of energy. When you meet the transformer (or more of them) in the matrix field, you must kill them all, and you lose the sum of the energy amounts required to kill each transformer.After the transformer is killed, he of course stops jumping, falls into the abyss and leaves the matrix world. Output minimum possible amount of energy wasted.", "input_spec": "In the first line, integers $$$N$$$,$$$M$$$ ($$$1 \\leq N, M \\leq 500$$$), representing size of the matrix, and $$$K$$$ ($$$0 \\leq K \\leq 5*10^5$$$) , the number of jumping transformers. In next $$$K$$$ lines, for each transformer, numbers $$$x$$$, $$$y$$$, $$$d$$$ ($$$d \\geq 1$$$), $$$t$$$ ($$$0 \\leq t \\leq N+M-2$$$), and $$$e$$$ ($$$0 \\leq e \\leq 10^9$$$), representing starting coordinates of transformer, jumping positions distance in pattern described above, time when transformer starts jumping, and energy required to kill it. It is guaranteed that all 4 of jumping points of the transformers are within matrix coordinates", "output_spec": "Print single integer, the minimum possible amount of energy wasted, for Blackout to arrive at bottom-right corner.", "sample_inputs": ["3 3 5\n0 1 1 0 7\n1 1 1 0 10\n1 1 1 1 2\n1 1 1 2 2\n0 1 1 2 3"], "sample_outputs": ["9"], "notes": "NoteIf Blackout takes the path from (0, 0) to (2, 0), and then from (2, 0) to (2, 2) he will need to kill the first and third transformer for a total energy cost of 9. There exists no path with less energy value."}, "src_uid": "b11cb0c2bf23bf4b4e6f6af61af9c290"} {"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": "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": "Smart Beaver is careful about his appearance and pays special attention to shoes so he has a huge number of pairs of shoes from the most famous brands of the forest. He's trying to handle his shoes carefully so that each pair stood side by side. But by the end of the week because of his very active lifestyle in his dressing room becomes a mess.Smart Beaver from ABBYY is not only the brightest beaver in the area, but he also is the most domestically oriented. For example, on Mondays the Smart Beaver cleans everything in his home.It's Monday morning. Smart Beaver does not want to spend the whole day cleaning, besides, there is much in to do and it\u2019s the gym day, so he wants to clean up as soon as possible. Now the floors are washed, the dust is wiped off \u2014 it\u2019s time to clean up in the dressing room. But as soon as the Smart Beaver entered the dressing room, all plans for the day were suddenly destroyed: chaos reigned there and it seemed impossible to handle, even in a week. Give our hero some hope: tell him what is the minimum number of shoes need to change the position to make the dressing room neat.The dressing room is rectangular and is divided into n\u2009\u00d7\u2009m equal squares, each square contains exactly one shoe. Each pair of shoes has a unique number that is integer from 1 to , more formally, a square with coordinates (i,\u2009j) contains an integer number of the pair which is lying on it. The Smart Beaver believes that the dressing room is neat only when each pair of sneakers lies together. We assume that the pair of sneakers in squares (i1,\u2009j1) and (i2,\u2009j2) lies together if |i1\u2009-\u2009i2|\u2009+\u2009|j1\u2009-\u2009j2|\u2009=\u20091.", "input_spec": "The first line contains two space-separated integers n and m. They correspond to the dressing room size. Next n lines contain m space-separated integers each. Those numbers describe the dressing room. Each number corresponds to a snicker. It is guaranteed that: n\u00b7m is even. All numbers, corresponding to the numbers of pairs of shoes in the dressing room, will lie between 1 and . Each number from 1 to will occur exactly twice. The input limits for scoring 30 points are (subproblem C1): 2\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20098. The input limits for scoring 100 points are (subproblems C1+C2): 2\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200980. ", "output_spec": "Print exactly one integer \u2014 the minimum number of the sneakers that need to change their location.", "sample_inputs": ["2 3\n1 1 2\n2 3 3", "3 4\n1 3 2 6\n2 1 5 6\n4 4 5 3"], "sample_outputs": ["2", "4"], "notes": "Note The second sample. "}, "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b"} {"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": "Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the half-backs and forwards (plays attack).Two teams of company Q decided to battle each other. Let's enumerate players from both teams by integers from 1 to 4. The first and second player play in the first team, the third and the fourth one play in the second team. For each of the four players we know their game skills in defence and attack. The defence skill of the i-th player is ai, the attack skill is bi.Before the game, the teams determine how they will play. First the players of the first team decide who will play in the attack, and who will play in the defence. Then the second team players do the same, based on the choice of their opponents.We will define a team's defence as the defence skill of player of the team who plays defence. Similarly, a team's attack is the attack skill of the player of the team who plays attack. We assume that one team is guaranteed to beat the other one, if its defence is strictly greater than the opponent's attack and its attack is strictly greater than the opponent's defence.The teams of company Q know each other's strengths and therefore arrange their teams optimally. Identify the team that is guaranteed to win (if both teams act optimally) or tell that there is no such team.", "input_spec": "The input contain the players' description in four lines. The i-th line contains two space-separated integers ai and bi (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u2009100) \u2014 the defence and the attack skill of the i-th player, correspondingly.", "output_spec": "If the first team can win, print phrase \"Team 1\" (without the quotes), if the second team can win, print phrase \"Team 2\" (without the quotes). If no of the teams can definitely win, print \"Draw\" (without the quotes).", "sample_inputs": ["1 100\n100 1\n99 99\n99 99", "1 1\n2 2\n3 3\n2 2", "3 3\n2 2\n1 1\n2 2"], "sample_outputs": ["Team 1", "Team 2", "Draw"], "notes": "NoteLet consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence.Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose first, the members of the second team can beat them (because they know the exact defence value and attack value of the first team)."}, "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f"} {"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": "There are n bears in the inn and p places to sleep. Bears will party together for some number of nights (and days).Bears love drinking juice. They don't like wine but they can't distinguish it from juice by taste or smell.A bear doesn't sleep unless he drinks wine. A bear must go to sleep a few hours after drinking a wine. He will wake up many days after the party is over.Radewoosh is the owner of the inn. He wants to put some number of barrels in front of bears. One barrel will contain wine and all other ones will contain juice. Radewoosh will challenge bears to find a barrel with wine.Each night, the following happens in this exact order: Each bear must choose a (maybe empty) set of barrels. The same barrel may be chosen by many bears. Each bear drinks a glass from each barrel he chose. All bears who drink wine go to sleep (exactly those bears who chose a barrel with wine). They will wake up many days after the party is over. If there are not enough places to sleep then bears lose immediately. At the end, if it's sure where wine is and there is at least one awake bear then bears win (unless they have lost before because of the number of places to sleep).Radewoosh wants to allow bears to win. He considers q scenarios. In the i-th scenario the party will last for i nights. Then, let Ri denote the maximum number of barrels for which bears surely win if they behave optimally. Let's define . Your task is to find , where denotes the exclusive or (also denoted as XOR).Note that the same barrel may be chosen by many bears and all of them will go to sleep at once.", "input_spec": "The only line of the input contains three integers n, p and q (1\u2009\u2264\u2009n\u2009\u2264\u2009109, 1\u2009\u2264\u2009p\u2009\u2264\u2009130, 1\u2009\u2264\u2009q\u2009\u2264\u20092\u2009000\u2009000)\u00a0\u2014 the number of bears, the number of places to sleep and the number of scenarios, respectively.", "output_spec": "Print one integer, equal to .", "sample_inputs": ["5 1 3", "1 100 4", "3 2 1", "100 100 100"], "sample_outputs": ["32", "4", "7", "381863924"], "notes": "NoteIn the first sample, there are 5 bears and only 1 place to sleep. We have R1\u2009=\u20096,\u2009R2\u2009=\u200911,\u2009R3\u2009=\u200916 so the answer is . Let's analyze the optimal strategy for scenario with 2 days. There are R2\u2009=\u200911 barrels and 10 of them contain juice. In the first night, the i-th bear chooses a barrel i only. If one of the first 5 barrels contains wine then one bear goes to sleep. Then, bears win because they know where wine is and there is at least one awake bear. But let's say none of the first 5 barrels contains wine. In the second night, the i-th bear chooses a barrel 5\u2009+\u2009i. If one of barrels 6\u2009\u2013\u200910 contains wine then one bear goes to sleep. And again, bears win in such a situation. If nobody went to sleep then wine is in a barrel 11. In the second sample, there is only one bear. He should choose an empty set of barrels in each night. Otherwise, he would maybe get wine and bears would lose (because there must be at least one awake bear). So, for any number of days we have Ri\u2009=\u20091. The answer is ."}, "src_uid": "28cf4ff955d089318ea08d17bc4f43da"} {"nl": {"description": "\u0412 \u0411\u0435\u0440\u043b\u044f\u043d\u0434\u0441\u043a\u043e\u043c \u0433\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a. \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0434\u0432\u0443\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u0440\u044f\u0434 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u0438 \u0434\u0432\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e. \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0438\u044f\u043d\u0438\u0438 \u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0432\u0442\u043e\u0440\u043e\u0433\u043e. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c. \u0414\u043b\u0438\u043d\u0430 \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c, \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0434\u043b\u0438\u043d\u044b \u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0434\u0432\u0443\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u00ababrakadabra\u00bb \u043f\u043e\u0434\u0440\u044f\u0434 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0430 \u00ababrakadabrabrakadabra\u00bb \u0438\u043b\u0438 \u00ababrakadabrakadabra\u00bb (\u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u2014 \u043f\u043e \u0447\u0435\u0442\u044b\u0440\u0435\u043c).\u041f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044e t \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u0438 \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 s. \u041d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 \u0434\u0432\u0443\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u00ababcd\u00bb, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435\u0442. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u0441\u043b\u0435\u0434 \u0437\u0430 \u0434\u0440\u0443\u0433\u0438\u043c \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u00ababcabc\u00bb, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435\u0442.", "input_spec": "\u0412 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0435\u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 t, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0431\u0443\u043a\u0432 \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430. \u0414\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 t \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 100 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.", "output_spec": "\u0415\u0441\u043b\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 t \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u00abNO\u00bb (\u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a) \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u00abYES\u00bb (\u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a), \u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 s\u00a0\u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0433\u043b\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0448\u0438\u0431\u043a\u0435. \u0415\u0441\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445.", "sample_inputs": ["abrakadabrabrakadabra", "acacacaca", "abcabc", "abababab", "tatbt"], "sample_outputs": ["YES\nabrakadabra", "YES\nacaca", "NO", "YES\nababab", "NO"], "notes": "\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 acacaca. "}, "src_uid": "bfa78f72af4875f670f7adc5ed127033"} {"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": "DO YOU EXPECT ME TO FIND THIS OUT?WHAT BASE AND/XOR LANGUAGE INCLUDES string?DON'T BYTE OF MORE THAN YOU CAN CHEWYOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FARSAYING \"ABRACADABRA\" WITHOUT A MAGIC AND WON'T DO YOU ANY GOODTHE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!I HAVE NO ARRAY AND I MUST SCREAMELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE", "input_spec": "The first line of input data contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200910). The second line of input data contains n space-separated integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u200911).", "output_spec": "Output a single integer.", "sample_inputs": ["4\n2 5 3 1"], "sample_outputs": ["4"], "notes": null}, "src_uid": "f45c769556ac3f408f5542fa71a67d98"} {"nl": {"description": "\u0413\u0435\u0440\u043e\u0439 \u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0443\u0437\u043a\u043e\u0439 \u043f\u043e\u043b\u043e\u0441\u043a\u0435 \u0437\u0435\u043c\u043b\u0438, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 n \u0437\u043e\u043d, \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 1 \u0434\u043e n. \u0418\u0437 i-\u0439 \u0437\u043e\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438 \u043b\u0438\u0448\u044c \u0432 (i\u2009-\u20091)-\u044e \u0437\u043e\u043d\u0443 \u0438 \u0432 (i\u2009+\u20091)-\u044e \u0437\u043e\u043d\u0443, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u043e\u0439 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0437\u043e\u043d \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0435 \u0432\u0440\u0430\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432, \u0446\u0432\u0435\u0442 \u0432\u0440\u0430\u0442 \u043c\u0435\u0436\u0434\u0443 i-\u0439 \u0438 (i\u2009+\u20091)-\u0439 \u0437\u043e\u043d\u043e\u0439 \u0440\u0430\u0432\u0435\u043d gi.\u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0435 \u0432\u0440\u0430\u0442\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043e\u043d \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043f\u043e\u0431\u044b\u0432\u0430\u043b \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0448\u0430\u0442\u0440\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u0435\u0439 \u043a\u043b\u044e\u0447\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0438 \u0432\u0437\u044f\u043b \u043a\u043b\u044e\u0447. \u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u043e\u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0448\u0430\u0442\u0435\u0440 \u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430, \u0446\u0432\u0435\u0442 \u0448\u0430\u0442\u0440\u0430 \u0432 i-\u0439 \u0437\u043e\u043d\u0435 \u0440\u0430\u0432\u0435\u043d ki. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u044f \u0448\u0430\u0442\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0440\u0430\u0437 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043b\u044e\u0431\u044b\u0435 \u0432\u0440\u0430\u0442\u0430 \u044d\u0442\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430.\u041d\u0430 \u043f\u0440\u043e\u0445\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u043d\u0438 \u0432\u0440\u0430\u0442\u0430 \u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u0442\u0440\u0430\u0442\u0438\u0442 \u043e\u0434\u0438\u043d \u0445\u043e\u0434, \u043d\u0430 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u0435 \u0448\u0430\u0442\u0440\u0430 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0445\u043e\u0434\u044b \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f. \u0417\u0430 \u043a\u0430\u043a\u043e\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0445\u043e\u0434\u043e\u0432 \u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u0437\u043e\u043d\u044b a \u0432 \u0437\u043e\u043d\u0443 b, \u0435\u0441\u043b\u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439?", "input_spec": "\u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0440\u0438 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 n, a, b (2\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009n, a\u2009\u2260\u2009b)\u00a0\u2014 \u0447\u0438\u0441\u043b\u043e \u0437\u043e\u043d, \u043d\u043e\u043c\u0435\u0440 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0437\u043e\u043d\u044b \u0438 \u043d\u043e\u043c\u0435\u0440 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0437\u043e\u043d\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 n\u2009-\u20091 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e g1,\u2009g2,\u2009...,\u2009gn\u2009-\u20091 (1\u2009\u2264\u2009gi\u2009\u2264\u2009100\u2009000), \u0433\u0434\u0435 gi \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0446\u0432\u0435\u0442 \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445 \u0432\u0440\u0430\u0442 \u043c\u0435\u0436\u0434\u0443 \u0437\u043e\u043d\u0430\u043c\u0438 i \u0438 i\u2009+\u20091. \u0422\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 n \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b k1,\u2009k2,\u2009...,\u2009kn (1\u2009\u2264\u2009ki\u2009\u2264\u2009100\u2009000), \u0433\u0434\u0435 ki \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0446\u0432\u0435\u0442 \u0448\u0430\u0442\u0440\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 i-\u0439 \u0437\u043e\u043d\u0435.", "output_spec": "\u0415\u0441\u043b\u0438 \u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u0437\u043e\u043d\u044b a \u0432 \u0437\u043e\u043d\u0443 b, \u043d\u0435 \u0438\u043c\u0435\u044f \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043a\u043b\u044e\u0447\u0435\u0439, \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 -1. \u0418\u043d\u0430\u0447\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0445\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0410\u0440\u043a\u0430\u0434\u0438\u044e.", "sample_inputs": ["5 4 1\n3 1 1 2\n7 1 2 1 3", "5 1 5\n4 3 2 1\n4 3 2 5 5"], "sample_outputs": ["7", "-1"], "notes": "\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u0437\u043e\u043d\u044b 4 \u0432 \u0437\u043e\u043d\u0443 1, \u0410\u0440\u043a\u0430\u0434\u0438\u044e \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0437\u044f\u0442\u044c \u043a\u043b\u044e\u0447 \u0446\u0432\u0435\u0442\u0430 1, \u043f\u0440\u043e\u0439\u0442\u0438 \u0432 \u0437\u043e\u043d\u0443 3, \u0442\u0430\u043c \u0432\u0437\u044f\u0442\u044c \u043a\u043b\u044e\u0447 \u0446\u0432\u0435\u0442\u0430 2 \u0438 \u043f\u0440\u043e\u0439\u0442\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0437\u043e\u043d\u0443 4 \u0438 \u0437\u0430\u0442\u0435\u043c \u0432 \u0437\u043e\u043d\u0443 5, \u0432\u0437\u044f\u0442\u044c \u0442\u0430\u043c \u043a\u043b\u044e\u0447 \u0446\u0432\u0435\u0442\u0430 3 \u0438 \u0434\u043e\u0439\u0442\u0438 \u0434\u043e \u0437\u043e\u043d\u044b 1 \u0437\u0430 \u0447\u0435\u0442\u044b\u0440\u0435 \u0445\u043e\u0434\u0430.\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0439\u0442\u0438 \u043b\u0438\u0448\u044c \u0434\u043e \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0439 \u0437\u043e\u043d\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u0448\u0430\u0442\u0440\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u0435\u0439 \u043a\u043b\u044e\u0447\u0435\u0439 \u0446\u0432\u0435\u0442\u0430 1 \u043d\u0435\u0442 \u0441\u043e\u0432\u0441\u0435\u043c."}, "src_uid": "fbd994944cfa06e4921aac227d9eaf31"} {"nl": {"description": "Maxim has got a calculator. The calculator has two integer cells. Initially, the first cell contains number 1, and the second cell contains number 0. In one move you can perform one of the following operations: Let's assume that at the current time the first cell contains number a, and the second cell contains number b. Write to the second cell number b\u2009+\u20091; Let's assume that at the current time the first cell contains number a, and the second cell contains number b. Write to the first cell number a\u00b7b. Maxim is wondering, how many integers x (l\u2009\u2264\u2009x\u2009\u2264\u2009r) are there, such that we can write the number x to the first cell of the calculator, having performed at most p moves.", "input_spec": "The first line contains three integers: l, r, p (2\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109,\u20091\u2009\u2264\u2009p\u2009\u2264\u2009100). The numbers in the line are separated by single spaces.", "output_spec": "In a single line print a single integer \u2014 the answer to the problem.", "sample_inputs": ["2 10 3", "2 111 100", "2 111 11"], "sample_outputs": ["1", "106", "47"], "notes": null}, "src_uid": "6d898638531e4713774bbd5d47e827bf"} {"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": "Ani and Borna are playing a short game on a two-variable polynomial. It's a special kind of a polynomial: the monomials are fixed, but all of its coefficients are fill-in-the-blanks dashes, e.g. $$$$$$ \\_ xy + \\_ x^4 y^7 + \\_ x^8 y^3 + \\ldots $$$$$$Borna will fill in the blanks with positive integers. He wants the polynomial to be bounded from below, i.e. his goal is to make sure there exists a real number $$$M$$$ such that the value of the polynomial at any point is greater than $$$M$$$. Ani is mischievous, and wants the polynomial to be unbounded. Along with stealing Borna's heart, she can also steal parts of polynomials. Ani is only a petty kind of thief, though: she can only steal at most one monomial from the polynomial before Borna fills in the blanks. If Ani and Borna play their only moves optimally, who wins?", "input_spec": "The first line contains a positive integer $$$N$$$ $$$(2 \\leq N \\leq 200\\, 000)$$$, denoting the number of the terms in the starting special polynomial. Each of the following $$$N$$$ lines contains a description of a monomial: the $$$k$$$-th line contains two **space**-separated integers $$$a_k$$$ and $$$b_k$$$ $$$(0 \\leq a_k, b_k \\leq 10^9$$$) which mean the starting polynomial has the term $$$\\_ x^{a_k} y^{b_k}$$$. It is guaranteed that for $$$k \\neq l$$$, either $$$a_k \\neq a_l$$$ or $$$b_k \\neq b_l$$$.", "output_spec": "If Borna can always choose the coefficients such that the resulting polynomial is bounded from below, regardless of what monomial Ani steals, output \"Borna\". Else, output \"Ani\". You shouldn't output the quotation marks.", "sample_inputs": ["3\n1 1\n2 0\n0 2", "4\n0 0\n0 1\n0 2\n0 8"], "sample_outputs": ["Ani", "Borna"], "notes": "NoteIn the first sample, the initial polynomial is $$$\\_xy+ \\_x^2 + \\_y^2$$$. If Ani steals the $$$\\_y^2$$$ term, Borna is left with $$$\\_xy+\\_x^2$$$. Whatever positive integers are written on the blanks, $$$y \\rightarrow -\\infty$$$ and $$$x := 1$$$ makes the whole expression go to negative infinity.In the second sample, the initial polynomial is $$$\\_1 + \\_x + \\_x^2 + \\_x^8$$$. One can check that no matter what term Ani steals, Borna can always win."}, "src_uid": "a7b35fee982e41c075c87135a62c3a0d"} {"nl": {"description": "Little Chris is having a nightmare. Even in dreams all he thinks about is math.Chris dreams about m binary strings of length n, indexed with numbers from 1 to m. The most horrifying part is that the bits of each string are ordered in either ascending or descending order. For example, Chris could be dreaming about the following 4 strings of length 5: The Hamming distance H(a,\u2009b) between two strings a and b of length n is the number of positions at which the corresponding symbols are different. \u0421hris thinks that each three strings with different indices constitute a single triple. Chris's delusion is that he will wake up only if he counts the number of such string triples a, b, c that the sum H(a,\u2009b)\u2009+\u2009H(b,\u2009c)\u2009+\u2009H(c,\u2009a) is maximal among all the string triples constructed from the dreamed strings.Help Chris wake up from this nightmare!", "input_spec": "The first line of input contains two space-separated integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u2009109; 3\u2009\u2264\u2009m\u2009\u2264\u2009105), the length and the number of strings. The next m lines contain the description of the strings. The i-th line contains two space-separated integers si and fi (0\u2009\u2264\u2009si\u2009\u2264\u20091; 1\u2009\u2264\u2009fi\u2009\u2264\u2009n), the description of the string with index i; that means that the first fi bits of the i-th string are equal to si, and the remaining n\u2009-\u2009fi bits are equal to 1\u2009-\u2009si. There can be multiple equal strings in Chris's dream.", "output_spec": "Output a single integer, the number of such string triples among the given that the sum of the Hamming distances between the strings of the triple is maximal.", "sample_inputs": ["5 4\n0 3\n0 5\n1 4\n1 5", "10 4\n1 5\n0 5\n0 5\n1 5"], "sample_outputs": ["3", "4"], "notes": null}, "src_uid": "bfc61d3e967fc28e1ab5b9028856125b"} {"nl": {"description": "Ksenia has her winter exams. Today she is learning combinatorics. Here's one of the problems she needs to learn to solve.How many distinct trees are there consisting of n vertices, each with the following properties: the tree is marked, that is, the vertices of the tree are numbered from 1 to n; each vertex of the tree is connected with at most three other vertices, and at the same moment the vertex with number 1 is connected with at most two other vertices; the size of the tree's maximum matching equals k. Two trees are considered distinct if there are such two vertices u and v, that in one tree they are connected by an edge and in the other tree they are not.Help Ksenia solve the problem for the given n and k. As the answer to the problem can be very huge you should output it modulo 1000000007\u00a0(109\u2009+\u20097).", "input_spec": "The first line contains two integers n,\u2009k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u200950).", "output_spec": "Print a single integer \u2014 the answer to the problem modulo 1000000007\u00a0(109\u2009+\u20097).", "sample_inputs": ["1 1", "2 1", "3 1", "4 2"], "sample_outputs": ["0", "1", "3", "12"], "notes": "NoteIf you aren't familiar with matchings, please, read the following link: http://en.wikipedia.org/wiki/Matching_(graph_theory)."}, "src_uid": "f98b740183281943eafd90328854746b"} {"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": "There are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.There are three keys\u00a0\u2014 one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.Can you open all the doors?", "input_spec": "The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 18$$$)\u00a0\u2014 the number of testcases. The first line of each testcase contains a single integer $$$x$$$ ($$$1 \\le x \\le 3$$$)\u00a0\u2014 the number on the key in your hands. The second line contains three integers $$$a, b$$$ and $$$c$$$ ($$$0 \\le a, b, c \\le 3$$$)\u00a0\u2014 the number on the key behind each of the doors. If there is no key behind the door, the number is equal to $$$0$$$. Values $$$1, 2$$$ and $$$3$$$ appear exactly once among $$$x, a, b$$$ and $$$c$$$.", "output_spec": "For each testcase, print \"YES\" if you can open all the doors. Otherwise, print \"NO\".", "sample_inputs": ["4\n\n3\n\n0 1 2\n\n1\n\n0 3 2\n\n2\n\n3 1 0\n\n2\n\n1 3 0"], "sample_outputs": ["YES\nNO\nYES\nNO"], "notes": null}, "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"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": "Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers\u00a0\u2014 amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.For each two integer numbers a and b such that l\u2009\u2264\u2009a\u2009\u2264\u2009r and x\u2009\u2264\u2009b\u2009\u2264\u2009y there is a potion with experience a and cost b in the store (that is, there are (r\u2009-\u2009l\u2009+\u20091)\u00b7(y\u2009-\u2009x\u2009+\u20091) potions).Kirill wants to buy a potion which has efficiency k. Will he be able to do this?", "input_spec": "First string contains five integer numbers l, r, x, y, k (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009107, 1\u2009\u2264\u2009x\u2009\u2264\u2009y\u2009\u2264\u2009107, 1\u2009\u2264\u2009k\u2009\u2264\u2009107).", "output_spec": "Print \"YES\" without quotes if a potion with efficiency exactly k can be bought in the store and \"NO\" without quotes otherwise. You can output each of the letters in any register.", "sample_inputs": ["1 10 1 10 1", "1 5 6 10 1"], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "1110d3671e9f77fd8d66dca6e74d2048"} {"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": "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": "A string $$$s$$$ of length $$$n$$$ can be encrypted by the following algorithm: iterate over all divisors of $$$n$$$ in decreasing order (i.e. from $$$n$$$ to $$$1$$$), for each divisor $$$d$$$, reverse the substring $$$s[1 \\dots d]$$$ (i.e. the substring which starts at position $$$1$$$ and ends at position $$$d$$$). For example, the above algorithm applied to the string $$$s$$$=\"codeforces\" leads to the following changes: \"codeforces\" $$$\\to$$$ \"secrofedoc\" $$$\\to$$$ \"orcesfedoc\" $$$\\to$$$ \"rocesfedoc\" $$$\\to$$$ \"rocesfedoc\" (obviously, the last reverse operation doesn't change the string because $$$d=1$$$).You are given the encrypted string $$$t$$$. Your task is to decrypt this string, i.e., to find a string $$$s$$$ such that the above algorithm results in string $$$t$$$. It can be proven that this string $$$s$$$ always exists and is unique.", "input_spec": "The first line of input consists of a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the length of the string $$$t$$$. The second line of input consists of the string $$$t$$$. The length of $$$t$$$ is $$$n$$$, and it consists only of lowercase Latin letters.", "output_spec": "Print a string $$$s$$$ such that the above algorithm results in $$$t$$$.", "sample_inputs": ["10\nrocesfedoc", "16\nplmaetwoxesisiht", "1\nz"], "sample_outputs": ["codeforces", "thisisexampletwo", "z"], "notes": "NoteThe first example is described in the problem statement."}, "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"nl": {"description": "Consider a linear function f(x)\u2009=\u2009Ax\u2009+\u2009B. Let's define g(0)(x)\u2009=\u2009x and g(n)(x)\u2009=\u2009f(g(n\u2009-\u20091)(x)) for n\u2009>\u20090. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109\u2009+\u20097.", "input_spec": "The only line contains four integers A, B, n and x (1\u2009\u2264\u2009A,\u2009B,\u2009x\u2009\u2264\u2009109,\u20091\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the parameters from the problem statement. Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "output_spec": "Print the only integer s \u2014 the value g(n)(x) modulo 109\u2009+\u20097.", "sample_inputs": ["3 4 1 1", "3 4 2 1", "3 4 3 1"], "sample_outputs": ["7", "25", "79"], "notes": null}, "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e"} {"nl": {"description": "Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is \"Unkillable\"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many! Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size x\u2009\u00d7\u2009y\u2009\u00d7\u2009z, consisting of undestructable cells 1\u2009\u00d7\u20091\u2009\u00d7\u20091. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value.All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut.Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most k times.Vasya's character uses absolutely thin sword with infinite length.", "input_spec": "The first line of input contains four integer numbers x,\u2009y,\u2009z,\u2009k (1\u2009\u2264\u2009x,\u2009y,\u2009z\u2009\u2264\u2009106,\u20090\u2009\u2264\u2009k\u2009\u2264\u2009109).", "output_spec": "Output the only number \u2014 the answer for the problem. 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).", "sample_inputs": ["2 2 2 3", "2 2 2 1"], "sample_outputs": ["8", "2"], "notes": "NoteIn the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two."}, "src_uid": "8787c5d46d7247d93d806264a8957639"} {"nl": {"description": "Fibonacci strings are defined as follows: f1 = \u00aba\u00bb f2 = \u00abb\u00bb fn = fn\u2009-\u20091\u00a0fn\u2009-\u20092, n\u2009>\u20092 Thus, the first five Fibonacci strings are: \"a\", \"b\", \"ba\", \"bab\", \"babba\".You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as a substring.", "input_spec": "The first line contains two space-separated integers k and m \u2014 the number of a Fibonacci string and the number of queries, correspondingly. Next m lines contain strings si that correspond to the queries. It is guaranteed that strings si aren't empty and consist only of characters \"a\" and \"b\". The input limitations for getting 30 points are: 1\u2009\u2264\u2009k\u2009\u2264\u20093000 1\u2009\u2264\u2009m\u2009\u2264\u20093000 The total length of strings si doesn't exceed 3000 The input limitations for getting 100 points are: 1\u2009\u2264\u2009k\u2009\u2264\u20091018 1\u2009\u2264\u2009m\u2009\u2264\u2009104 The total length of strings si doesn't exceed 105 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": "For each string si print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo 1000000007 (109\u2009+\u20097). Print the answers for the strings in the order in which they are given in the input.", "sample_inputs": ["6 5\na\nb\nab\nba\naba"], "sample_outputs": ["3\n5\n3\n3\n1"], "notes": null}, "src_uid": "8983915e904ba763d893d56e94d9f7f0"} {"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": "Linda likes to change her hair color from time to time, and would be pleased if her boyfriend Archie would notice the difference between the previous and the new color. Archie always comments on Linda's hair color if and only if he notices a difference \u2014 so Linda always knows whether Archie has spotted the difference or not.There is a new hair dye series in the market where all available colors are numbered by integers from $$$1$$$ to $$$N$$$ such that a smaller difference of the numerical values also means less visual difference.Linda assumes that for these series there should be some critical color difference $$$C$$$ ($$$1 \\le C \\le N$$$) for which Archie will notice color difference between the current color $$$\\mathrm{color}_{\\mathrm{new}}$$$ and the previous color $$$\\mathrm{color}_{\\mathrm{prev}}$$$ if $$$\\left|\\mathrm{color}_{\\mathrm{new}} - \\mathrm{color}_{\\mathrm{prev}}\\right| \\ge C$$$ and will not if $$$\\left|\\mathrm{color}_{\\mathrm{new}} - \\mathrm{color}_{\\mathrm{prev}}\\right| < C$$$.Now she has bought $$$N$$$ sets of hair dye from the new series \u2014 one for each of the colors from $$$1$$$ to $$$N$$$, and is ready to set up an experiment. Linda will change her hair color on a regular basis and will observe Archie's reaction \u2014 whether he will notice the color change or not. Since for the proper dye each set should be used completely, each hair color can be obtained no more than once.Before the experiment, Linda was using a dye from a different series which is not compatible with the new one, so for the clearness of the experiment Archie's reaction to the first used color is meaningless.Her aim is to find the precise value of $$$C$$$ in a limited number of dyes. Write a program which finds the value of $$$C$$$ by experimenting with the given $$$N$$$ colors and observing Archie's reactions to color changes.", "input_spec": null, "output_spec": null, "sample_inputs": ["1\n\n7\n\n1\n\n1\n\n0\n\n0\n\n1"], "sample_outputs": ["? 2\n\n? 7\n\n? 4\n\n? 1\n\n? 5\n\n= 4"], "notes": "NoteComments to the example input line by line: $$$N = 7$$$. Answer to the first query is meaningless (can also be $$$0$$$). $$$C \\leq 5$$$. $$$3 < C \\leq 5$$$. It would be wise to check difference $$$4$$$. However, this can not be done in the next query since $$$4 + 4 = 8$$$ and $$$4 - 4 = 0$$$ both are outside the allowed interval $$$1 \\le P \\le 7$$$. $$$3 < C \\leq 5$$$. $$$3 < C \\leq 4$$$. Therefore, $$$C = 4$$$. "}, "src_uid": "5a374c06b44a843233d9cf64a38c7e55"} {"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": "Everyone loves a freebie. Especially students.It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times \"Fly, freebie, fly!\" \u2014 then flown freebie helps him to pass the upcoming exam.In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time ti, where ti is the number of seconds elapsed since the beginning of the night.It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100), where n \u2014 the number of students shouted \"Fly, freebie, fly!\" The second line contains n positive integers ti (1\u2009\u2264\u2009ti\u2009\u2264\u20091000). The last line contains integer T (1\u2009\u2264\u2009T\u2009\u2264\u20091000) \u2014 the time interval during which the freebie was near the dormitory.", "output_spec": "Print a single integer \u2014 the largest number of people who will pass exam tomorrow because of the freebie visit.", "sample_inputs": ["6\n4 1 7 8 3 8\n1"], "sample_outputs": ["3"], "notes": null}, "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c"} {"nl": {"description": "Today is the final contest of INOI (Iranian National Olympiad in Informatics). The contest room is a row with $$$n$$$ computers. All computers are numbered with integers from $$$1$$$ to $$$n$$$ from left to right. There are $$$m$$$ participants, numbered with integers from $$$1$$$ to $$$m$$$.We have an array $$$a$$$ of length $$$m$$$ where $$$a_{i}$$$ ($$$1 \\leq a_i \\leq n$$$) is the computer behind which the $$$i$$$-th participant wants to sit.Also, we have another array $$$b$$$ of length $$$m$$$ consisting of characters 'L' and 'R'. $$$b_i$$$ is the side from which the $$$i$$$-th participant enters the room. 'L' means the participant enters from the left of computer $$$1$$$ and goes from left to right, and 'R' means the participant enters from the right of computer $$$n$$$ and goes from right to left.The participants in the order from $$$1$$$ to $$$m$$$ enter the room one by one. The $$$i$$$-th of them enters the contest room in the direction $$$b_i$$$ and goes to sit behind the $$$a_i$$$-th computer. If it is occupied he keeps walking in his direction until he reaches the first unoccupied computer. After that, he sits behind it. If he doesn't find any computer he gets upset and gives up on the contest.The madness of the $$$i$$$-th participant is the distance between his assigned computer ($$$a_i$$$) and the computer he ends up sitting behind. The distance between computers $$$i$$$ and $$$j$$$ is equal to $$$|i - j|$$$.The values in the array $$$a$$$ can be equal. There exist $$$n^m \\cdot 2^m$$$ possible pairs of arrays $$$(a, b)$$$.Consider all pairs of arrays $$$(a, b)$$$ such that no person becomes upset. For each of them let's calculate the sum of participants madnesses. Find the sum of all these values.You will be given some prime modulo $$$p$$$. Find this sum by modulo $$$p$$$.", "input_spec": "The only line contains three integers $$$n$$$, $$$m$$$, $$$p$$$ ($$$1 \\leq m \\leq n \\leq 500, 10^8 \\leq p \\leq 10 ^ 9 + 9$$$). It is guaranteed, that the number $$$p$$$ is prime.", "output_spec": "Print only one integer\u00a0\u2014 the required sum by modulo $$$p$$$.", "sample_inputs": ["3 1 1000000007", "2 2 1000000009", "3 2 998244353", "20 10 1000000009"], "sample_outputs": ["0", "4", "8", "352081045"], "notes": "NoteIn the first test, there are three possible arrays $$$a$$$: $$$\\{1\\}$$$, $$$\\{2\\}$$$, and $$$ \\{3\\}$$$ and two possible arrays $$$b$$$: $$$\\{\\mathtt{L}\\}$$$ and $$$\\{\\mathtt{R}\\}$$$. For all six pairs of arrays $$$(a, b)$$$, the only participant will sit behind the computer $$$a_1$$$, so his madness will be $$$0$$$. So the total sum of madnesses will be $$$0$$$.In the second test, all possible pairs of arrays $$$(a, b)$$$, such that no person becomes upset are: $$$(\\{1, 1\\}, \\{\\mathtt{L}, \\mathtt{L}\\})$$$, the sum of madnesses is $$$1$$$; $$$(\\{1, 1\\}, \\{\\mathtt{R}, \\mathtt{L}\\})$$$, the sum of madnesses is $$$1$$$; $$$(\\{2, 2\\}, \\{\\mathtt{R}, \\mathtt{R}\\})$$$, the sum of madnesses is $$$1$$$; $$$(\\{2, 2\\}, \\{\\mathtt{L}, \\mathtt{R}\\})$$$, the sum of madnesses is $$$1$$$; all possible pairs of $$$a \\in \\{\\{1, 2\\}, \\{2, 1\\}\\}$$$ and $$$b \\in \\{\\{\\mathtt{L}, \\mathtt{L}\\}, \\{\\mathtt{R}, \\mathtt{L}\\}, \\{\\mathtt{L}, \\mathtt{R}\\}, \\{\\mathtt{R}, \\mathtt{R}\\}\\}$$$, the sum of madnesses is $$$0$$$. So, the answer is $$$1 + 1 + 1 + 1 + 0 \\ldots = 4$$$."}, "src_uid": "9812de5f2d272511a63ead8765b23190"} {"nl": {"description": "Let's call a graph with $$$n$$$ vertices, each of which has it's own point $$$A_i = (x_i, y_i)$$$ with integer coordinates, a planar tree if: All points $$$A_1, A_2, \\ldots, A_n$$$ are different and no three points lie on the same line. The graph is a tree, i.e. there are exactly $$$n-1$$$ edges there exists a path between any pair of vertices. For all pairs of edges $$$(s_1, f_1)$$$ and $$$(s_2, f_2)$$$, such that $$$s_1 \\neq s_2, s_1 \\neq f_2,$$$ $$$f_1 \\neq s_2$$$, and $$$f_1 \\neq f_2$$$, the segments $$$A_{s_1} A_{f_1}$$$ and $$$A_{s_2} A_{f_2}$$$ don't intersect. Imagine a planar tree with $$$n$$$ vertices. Consider the convex hull of points $$$A_1, A_2, \\ldots, A_n$$$. Let's call this tree a spiderweb tree if for all $$$1 \\leq i \\leq n$$$ the following statements are true: All leaves (vertices with degree $$$\\leq 1$$$) of the tree lie on the border of the convex hull. All vertices on the border of the convex hull are leaves. An example of a spiderweb tree: The points $$$A_3, A_6, A_7, A_4$$$ lie on the convex hull and the leaf vertices of the tree are $$$3, 6, 7, 4$$$.Refer to the notes for more examples.Let's call the subset $$$S \\subset \\{1, 2, \\ldots, n\\}$$$ of vertices a subtree of the tree if for all pairs of vertices in $$$S$$$, there exists a path that contains only vertices from $$$S$$$. Note that any subtree of the planar tree is a planar tree.You are given a planar tree with $$$n$$$ vertexes. Let's call a partition of the set $$$\\{1, 2, \\ldots, n\\}$$$ into non-empty subsets $$$A_1, A_2, \\ldots, A_k$$$ (i.e. $$$A_i \\cap A_j = \\emptyset$$$ for all $$$1 \\leq i < j \\leq k$$$ and $$$A_1 \\cup A_2 \\cup \\ldots \\cup A_k = \\{1, 2, \\ldots, n\\}$$$) good if for all $$$1 \\leq i \\leq k$$$, the subtree $$$A_i$$$ is a spiderweb tree. Two partitions are different if there exists some set that lies in one parition, but not the other.Find the number of good partitions. Since this number can be very large, find it modulo $$$998\\,244\\,353$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the number of vertices in the tree. The next $$$n$$$ lines each contain two integers $$$x_i, y_i$$$ ($$$-10^9 \\leq x_i, y_i \\leq 10^9$$$) \u00a0\u2014 the coordinates of $$$i$$$-th vertex, $$$A_i$$$. The next $$$n-1$$$ lines contain two integers $$$s, f$$$ ($$$1 \\leq s, f \\leq n$$$)\u00a0\u2014 the edges $$$(s, f)$$$ of the tree. It is guaranteed that all given points are different and that no three of them lie at the same line. Additionally, it is guaranteed that the given edges and coordinates of the points describe a planar tree.", "output_spec": "Print one integer \u00a0\u2014 the number of good partitions of vertices of the given planar tree, modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["4\n0 0\n0 1\n-1 -1\n1 -1\n1 2\n1 3\n1 4", "5\n3 2\n0 -3\n-5 -3\n5 -5\n4 5\n4 2\n4 1\n5 2\n2 3", "6\n4 -5\n0 1\n-2 8\n3 -10\n0 -1\n-4 -5\n2 5\n3 2\n1 2\n4 6\n4 2", "8\n0 0\n-1 2\n-2 5\n-5 1\n1 3\n0 3\n2 4\n-1 -4\n1 2\n3 2\n5 6\n4 2\n1 5\n5 7\n5 8"], "sample_outputs": ["5", "8", "13", "36"], "notes": "Note The picture for the first sample. In the first test case, all good partitions are: $$$\\{1\\}$$$, $$$\\{2\\}$$$, $$$\\{3\\}$$$, $$$\\{4\\}$$$; $$$\\{1, 2\\}$$$, $$$\\{3\\}$$$, $$$\\{4\\}$$$; $$$\\{1, 3\\}$$$, $$$\\{2\\}$$$, $$$\\{4\\}$$$; $$$\\{1, 4\\}$$$, $$$\\{2\\}$$$, $$$\\{3\\}$$$; $$$\\{1, 2, 3, 4\\}$$$. The partition $$$\\{1, 2, 3\\}$$$, $$$\\{4\\}$$$ isn't good, because the subtree $$$\\{1, 2, 3\\}$$$ isn't spiderweb tree, since the non-leaf vertex $$$1$$$ lies on the convex hull.The partition $$$\\{2, 3, 4\\}$$$, $$$\\{1\\}$$$ isn't good, because the subset $$$\\{2, 3, 4\\}$$$ isn't a subtree. The picture for the second sample. In the second test case, the given tree isn't a spiderweb tree, because the leaf vertex $$$1$$$ doesn't lie on the convex hull. However, the subtree $$$\\{2, 3, 4, 5\\}$$$ is a spiderweb tree. The picture for the third sample. The picture for the fourth sample. In the fourth test case, the partition $$$\\{1, 2, 3, 4\\}$$$, $$$\\{5, 6, 7, 8\\}$$$ is good because all subsets are spiderweb subtrees."}, "src_uid": "9b764e44167cc5d2bdfabcb811cdd93b"} {"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": " In every generation there is a Chosen One. She alone will stand against the vampires, the demons, and the forces of darkness. She is the Slayer. \u2014 Joss Whedon ", "input_spec": "A string $$$s$$$ ($$$3 \\le |s| \\le 7$$$) consisting of lowercase English letters.", "output_spec": "A single string. If there is no answer, print \"none\" (without the quotes).", "sample_inputs": ["tourist"], "sample_outputs": ["ooggqjx"], "notes": null}, "src_uid": "56ec50526a3843fe3784d395850f45ae"} {"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": "One day a bear lived on the Oxy axis. He was afraid of the dark, so he couldn't move at night along the plane points that aren't lit. One day the bear wanted to have a night walk from his house at point (l,\u20090) to his friend's house at point (r,\u20090), along the segment of length (r\u2009-\u2009l). Of course, if he wants to make this walk, he needs each point of the segment to be lit. That's why the bear called his friend (and yes, in the middle of the night) asking for a very delicate favor.The Oxy axis contains n floodlights. Floodlight i is at point (xi,\u2009yi) and can light any angle of the plane as large as ai degree with vertex at point (xi,\u2009yi). The bear asked his friend to turn the floodlights so that he (the bear) could go as far away from his house as possible during the walking along the segment. His kind friend agreed to fulfill his request. And while he is at it, the bear wonders: what is the furthest he can go away from his house? Hep him and find this distance.Consider that the plane has no obstacles and no other light sources besides the floodlights. The bear's friend cannot turn the floodlights during the bear's walk. Assume that after all the floodlights are turned in the correct direction, the bear goes for a walk and his friend goes to bed.", "input_spec": "The first line contains three space-separated integers n, l, r (1\u2009\u2264\u2009n\u2009\u2264\u200920;\u00a0\u2009-\u2009105\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009105). The i-th of the next n lines contain three space-separated integers xi, yi, ai (\u2009-\u20091000\u2009\u2264\u2009xi\u2009\u2264\u20091000;\u00a01\u2009\u2264\u2009yi\u2009\u2264\u20091000;\u00a01\u2009\u2264\u2009ai\u2009\u2264\u200990) \u2014 the floodlights' description. Note that two floodlights can be at the same point of the plane.", "output_spec": "Print a single real number \u2014 the answer to the problem. The answer will be considered correct if its relative or absolute error doesn't exceed 10\u2009-\u20096.", "sample_inputs": ["2 3 5\n3 1 45\n5 1 45", "1 0 1\n1 1 30", "1 0 1\n1 1 45", "1 0 2\n0 2 90"], "sample_outputs": ["2.000000000", "0.732050808", "1.000000000", "2.000000000"], "notes": "NoteIn the first sample, one of the possible solutions is: In the second sample, a single solution is: In the third sample, a single solution is: "}, "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a"} {"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": "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": "Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to n (by the demand of the inventory commission). Figure 1. The initial position for n\u2009=\u20095. After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped. Figure 2. The example of a throw. In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2.Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the \"ball order\". The ball order is a sequence of n numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise.", "input_spec": "The first line contains a single number n \u2014 the number of students in the line and the number of balls. The next line contains exactly n space-separated integers. Each number corresponds to a student in the line (the i-th number corresponds to the i-th from the left student in the line) and shows the number of throws he can participate in. The input limits for scoring 30 points are (subproblem D1): 1\u2009\u2264\u2009n\u2009\u2264\u200910. The input limits for scoring 70 points are (subproblems D1+D2): 1\u2009\u2264\u2009n\u2009\u2264\u2009500. The input limits for scoring 100 points are (subproblems D1+D2+D3): 1\u2009\u2264\u2009n\u2009\u2264\u20091000000. ", "output_spec": "The output should contain a single integer \u2014 the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["5\n1 2 2 1 2", "8\n1 2 2 1 2 1 1 2"], "sample_outputs": ["120", "16800"], "notes": null}, "src_uid": "91e8dbe94273e255182aca0f94117bb9"} {"nl": {"description": "This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.You are given an array $$$[a_1, a_2, \\dots, a_n]$$$. Your goal is to find the length of the longest subarray of this array such that the most frequent value in it is not unique. In other words, you are looking for a subarray such that if the most frequent value occurs $$$f$$$ times in this subarray, then at least $$$2$$$ different values should occur exactly $$$f$$$ times.An array $$$c$$$ is a subarray of an array $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 200\\,000$$$)\u00a0\u2014 the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le min(n, 100)$$$)\u00a0\u2014 elements of the array.", "output_spec": "You should output exactly one integer \u00a0\u2014 the length of the longest subarray of the array whose most frequent value is not unique. If there is no such subarray, output $$$0$$$.", "sample_inputs": ["7\n1 1 2 2 3 3 3", "10\n1 1 1 5 4 1 3 1 2 2", "1\n1"], "sample_outputs": ["6", "7", "0"], "notes": "NoteIn the first sample, the subarray $$$[1, 1, 2, 2, 3, 3]$$$ is good, but $$$[1, 1, 2, 2, 3, 3, 3]$$$ isn't: in the latter there are $$$3$$$ occurrences of number $$$3$$$, and no other element appears $$$3$$$ times."}, "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed"} {"nl": {"description": "Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k\u2009+\u20091.Polycarp has M minutes of time. What is the maximum number of points he can earn?", "input_spec": "The first line contains three integer numbers n, k and M (1\u2009\u2264\u2009n\u2009\u2264\u200945, 1\u2009\u2264\u2009k\u2009\u2264\u200945, 0\u2009\u2264\u2009M\u2009\u2264\u20092\u00b7109). The second line contains k integer numbers, values tj (1\u2009\u2264\u2009tj\u2009\u2264\u20091000000), where tj is the time in minutes required to solve j-th subtask of any task.", "output_spec": "Print the maximum amount of points Polycarp can earn in M minutes.", "sample_inputs": ["3 4 11\n1 2 3 4", "5 5 10\n1 2 4 8 16"], "sample_outputs": ["6", "7"], "notes": "NoteIn the first example Polycarp can complete the first task and spend 1\u2009+\u20092\u2009+\u20093\u2009+\u20094\u2009=\u200910 minutes. He also has the time to solve one subtask of the second task in one minute.In the second example Polycarp can solve the first subtask of all five tasks and spend 5\u00b71\u2009=\u20095 minutes. Also he can solve the second subtasks of two tasks and spend 2\u00b72\u2009=\u20094 minutes. Thus, he earns 5\u2009+\u20092\u2009=\u20097 points in total."}, "src_uid": "d659e92a410c1bc836be64fc1c0db160"} {"nl": {"description": "Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\leq n \\leq 200\\,000$$$, $$$0 \\leq k \\leq n$$$) \u2014 the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ digits and doesn't contain any leading zeroes.", "output_spec": "Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.", "sample_inputs": ["5 3\n51528", "3 2\n102", "1 1\n1"], "sample_outputs": ["10028", "100", "0"], "notes": "NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes."}, "src_uid": "0515ac888937a4dda30cad5e2383164f"} {"nl": {"description": "A plane contains a not necessarily convex polygon without self-intersections, consisting of n vertexes, numbered from 1 to n. There is a spider sitting on the border of the polygon, the spider can move like that: Transfer. The spider moves from the point p1 with coordinates (x1,\u2009y1), lying on the polygon border, to the point p2 with coordinates (x2,\u2009y2), also lying on the border. The spider can't go beyond the polygon border as it transfers, that is, the spider's path from point p1 to point p2 goes along the polygon border. It's up to the spider to choose the direction of walking round the polygon border (clockwise or counterclockwise). Descend. The spider moves from point p1 with coordinates (x1,\u2009y1) to point p2 with coordinates (x2,\u2009y2), at that points p1 and p2 must lie on one vertical straight line (x1\u2009=\u2009x2), point p1 must be not lower than point p2 (y1\u2009\u2265\u2009y2) and segment p1p2 mustn't have points, located strictly outside the polygon (specifically, the segment can have common points with the border). Initially the spider is located at the polygon vertex with number s. Find the length of the shortest path to the vertex number t, consisting of transfers and descends. The distance is determined by the usual Euclidean metric .", "input_spec": "The first line contains integer n (3\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of vertexes of the given polygon. Next n lines contain two space-separated integers each \u2014 the coordinates of the polygon vertexes. The vertexes are listed in the counter-clockwise order. The coordinates of the polygon vertexes do not exceed 104 in their absolute value. The last line contains two space-separated integers s and t (1\u2009\u2264\u2009s,\u2009t\u2009\u2264\u2009n) \u2014 the start and the end vertexes of the sought shortest way. Consider the polygon vertexes numbered in the order they are given in the input, that is, the coordinates of the first vertex are located on the second line of the input and the coordinates of the n-th vertex are on the (n\u2009+\u20091)-th line. It is guaranteed that the given polygon is simple, that is, it contains no self-intersections or self-tangencies.", "output_spec": "In the output print a single real number \u2014 the length of the shortest way from vertex s to vertex t. The answer is considered correct, if its absolute or relative error does not exceed 10\u2009-\u20096.", "sample_inputs": ["4\n0 0\n1 0\n1 1\n0 1\n1 4", "4\n0 0\n1 1\n0 2\n-1 1\n3 3", "5\n0 0\n5 0\n1 4\n0 2\n2 1\n3 1"], "sample_outputs": ["1.000000000000000000e+000", "0.000000000000000000e+000", "5.650281539872884700e+000"], "notes": "NoteIn the first sample the spider transfers along the side that connects vertexes 1 and 4.In the second sample the spider doesn't have to transfer anywhere, so the distance equals zero.In the third sample the best strategy for the spider is to transfer from vertex 3 to point (2,3), descend to point (2,1), and then transfer to vertex 1."}, "src_uid": "ccc9d167caf5c4e3c7ab212bf4f5ca45"} {"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": "In some country live wizards. They love playing with numbers. The blackboard has two numbers written on it \u2014 a and b. The order of the numbers is not important. Let's consider a\u2009\u2264\u2009b for the sake of definiteness. The players can cast one of the two spells in turns: Replace b with b\u2009-\u2009ak. Number k can be chosen by the player, considering the limitations that k\u2009>\u20090 and b\u2009-\u2009ak\u2009\u2265\u20090. Number k is chosen independently each time an active player casts a spell. Replace b with b\u00a0mod\u00a0a. If a\u2009>\u2009b, similar moves are possible.If at least one of the numbers equals zero, a player can't make a move, because taking a remainder modulo zero is considered somewhat uncivilized, and it is far too boring to subtract a zero. The player who cannot make a move, loses.To perform well in the magic totalizator, you need to learn to quickly determine which player wins, if both wizards play optimally: the one that moves first or the one that moves second.", "input_spec": "The first line contains a single integer t \u2014 the number of input data sets (1\u2009\u2264\u2009t\u2009\u2264\u2009104). Each of the next t lines contains two integers a, b (0\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20091018). The numbers are separated by a space. Please do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specificator.", "output_spec": "For any of the t input sets print \"First\" (without the quotes) if the player who moves first wins. Print \"Second\" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input. ", "sample_inputs": ["4\n10 21\n31 10\n0 1\n10 30"], "sample_outputs": ["First\nSecond\nSecond\nFirst"], "notes": "NoteIn the first sample, the first player should go to (11,10). Then, after a single move of the second player to (1,10), he will take 10 modulo 1 and win.In the second sample the first player has two moves to (1,10) and (21,10). After both moves the second player can win.In the third sample, the first player has no moves.In the fourth sample, the first player wins in one move, taking 30 modulo 10."}, "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c"} {"nl": {"description": "At first, let's define function $$$f(x)$$$ as follows: $$$$$$ \\begin{matrix} f(x) & = & \\left\\{ \\begin{matrix} \\frac{x}{2} & \\mbox{if } x \\text{ is even} \\\\ x - 1 & \\mbox{otherwise } \\end{matrix} \\right. \\end{matrix} $$$$$$We can see that if we choose some value $$$v$$$ and will apply function $$$f$$$ to it, then apply $$$f$$$ to $$$f(v)$$$, and so on, we'll eventually get $$$1$$$. Let's write down all values we get in this process in a list and denote this list as $$$path(v)$$$. For example, $$$path(1) = [1]$$$, $$$path(15) = [15, 14, 7, 6, 3, 2, 1]$$$, $$$path(32) = [32, 16, 8, 4, 2, 1]$$$.Let's write all lists $$$path(x)$$$ for every $$$x$$$ from $$$1$$$ to $$$n$$$. The question is next: what is the maximum value $$$y$$$ such that $$$y$$$ is contained in at least $$$k$$$ different lists $$$path(x)$$$?Formally speaking, you need to find maximum $$$y$$$ such that $$$\\left| \\{ x ~|~ 1 \\le x \\le n, y \\in path(x) \\} \\right| \\ge k$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 10^{18}$$$).", "output_spec": "Print the only integer \u2014 the maximum value that is contained in at least $$$k$$$ paths.", "sample_inputs": ["11 3", "11 6", "20 20", "14 5", "1000000 100"], "sample_outputs": ["5", "4", "1", "6", "31248"], "notes": "NoteIn the first example, the answer is $$$5$$$, since $$$5$$$ occurs in $$$path(5)$$$, $$$path(10)$$$ and $$$path(11)$$$.In the second example, the answer is $$$4$$$, since $$$4$$$ occurs in $$$path(4)$$$, $$$path(5)$$$, $$$path(8)$$$, $$$path(9)$$$, $$$path(10)$$$ and $$$path(11)$$$.In the third example $$$n = k$$$, so the answer is $$$1$$$, since $$$1$$$ is the only number occuring in all paths for integers from $$$1$$$ to $$$20$$$."}, "src_uid": "783c4b3179c558369f94f4a16ac562d4"} {"nl": {"description": "Let's define the function $$$f$$$ of multiset $$$a$$$ as the multiset of number of occurences of every number, that is present in $$$a$$$.E.g., $$$f(\\{5, 5, 1, 2, 5, 2, 3, 3, 9, 5\\}) = \\{1, 1, 2, 2, 4\\}$$$.Let's define $$$f^k(a)$$$, as applying $$$f$$$ to array $$$a$$$ $$$k$$$ times: $$$f^k(a) = f(f^{k-1}(a)), f^0(a) = a$$$. E.g., $$$f^2(\\{5, 5, 1, 2, 5, 2, 3, 3, 9, 5\\}) = \\{1, 2, 2\\}$$$.You are given integers $$$n, k$$$ and you are asked how many different values the function $$$f^k(a)$$$ can have, where $$$a$$$ is arbitrary non-empty array with numbers of size no more than $$$n$$$. Print the answer modulo $$$998\\,244\\,353$$$.", "input_spec": "The first and only line of input consists of two integers $$$n, k$$$ ($$$1 \\le n, k \\le 2020$$$).", "output_spec": "Print one number\u00a0\u2014 the number of different values of function $$$f^k(a)$$$ on all possible non-empty arrays with no more than $$$n$$$ elements modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["3 1", "5 6", "10 1", "10 2"], "sample_outputs": ["6", "1", "138", "33"], "notes": null}, "src_uid": "c435a0cd437081cd3593637be4568c6a"} {"nl": {"description": "For an array of integers $$$a$$$, let's define $$$|a|$$$ as the number of elements in it.Let's denote two functions: $$$F(a, k)$$$ is a function that takes an array of integers $$$a$$$ and a positive integer $$$k$$$. The result of this function is the array containing $$$|a|$$$ first elements of the array that you get by replacing each element of $$$a$$$ with exactly $$$k$$$ copies of that element.For example, $$$F([2, 2, 1, 3, 5, 6, 8], 2)$$$ is calculated as follows: first, you replace each element of the array with $$$2$$$ copies of it, so you obtain $$$[2, 2, 2, 2, 1, 1, 3, 3, 5, 5, 6, 6, 8, 8]$$$. Then, you take the first $$$7$$$ elements of the array you obtained, so the result of the function is $$$[2, 2, 2, 2, 1, 1, 3]$$$. $$$G(a, x, y)$$$ is a function that takes an array of integers $$$a$$$ and two different integers $$$x$$$ and $$$y$$$. The result of this function is the array $$$a$$$ with every element equal to $$$x$$$ replaced by $$$y$$$, and every element equal to $$$y$$$ replaced by $$$x$$$.For example, $$$G([1, 1, 2, 3, 5], 3, 1) = [3, 3, 2, 1, 5]$$$.An array $$$a$$$ is a parent of the array $$$b$$$ if: either there exists a positive integer $$$k$$$ such that $$$F(a, k) = b$$$; or there exist two different integers $$$x$$$ and $$$y$$$ such that $$$G(a, x, y) = b$$$. An array $$$a$$$ is an ancestor of the array $$$b$$$ if there exists a finite sequence of arrays $$$c_0, c_1, \\dots, c_m$$$ ($$$m \\ge 0$$$) such that $$$c_0$$$ is $$$a$$$, $$$c_m$$$ is $$$b$$$, and for every $$$i \\in [1, m]$$$, $$$c_{i-1}$$$ is a parent of $$$c_i$$$.And now, the problem itself.You are given two integers $$$n$$$ and $$$k$$$. Your goal is to construct a sequence of arrays $$$s_1, s_2, \\dots, s_m$$$ in such a way that: every array $$$s_i$$$ contains exactly $$$n$$$ elements, and all elements are integers from $$$1$$$ to $$$k$$$; for every array $$$a$$$ consisting of exactly $$$n$$$ integers from $$$1$$$ to $$$k$$$, the sequence contains at least one array $$$s_i$$$ such that $$$s_i$$$ is an ancestor of $$$a$$$. Print the minimum number of arrays in such sequence.", "input_spec": "The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 2 \\cdot 10^5$$$).", "output_spec": "Print one integer \u2014 the minimum number of elements in a sequence of arrays meeting the constraints. Since the answer can be large, output it modulo $$$998244353$$$.", "sample_inputs": ["3 2", "4 10", "13 37", "1337 42", "198756 123456", "123456 198756"], "sample_outputs": ["2", "12", "27643508", "211887828", "159489391", "460526614"], "notes": "NoteLet's analyze the first example.One of the possible answers for the first example is the sequence $$$[[2, 1, 2], [1, 2, 2]]$$$. Every array of size $$$3$$$ consisting of elements from $$$1$$$ to $$$2$$$ has an ancestor in this sequence: for the array $$$[1, 1, 1]$$$, the ancestor is $$$[1, 2, 2]$$$: $$$F([1, 2, 2], 13) = [1, 1, 1]$$$; for the array $$$[1, 1, 2]$$$, the ancestor is $$$[1, 2, 2]$$$: $$$F([1, 2, 2], 2) = [1, 1, 2]$$$; for the array $$$[1, 2, 1]$$$, the ancestor is $$$[2, 1, 2]$$$: $$$G([2, 1, 2], 1, 2) = [1, 2, 1]$$$; for the array $$$[1, 2, 2]$$$, the ancestor is $$$[1, 2, 2]$$$; for the array $$$[2, 1, 1]$$$, the ancestor is $$$[1, 2, 2]$$$: $$$G([1, 2, 2], 1, 2) = [2, 1, 1]$$$; for the array $$$[2, 1, 2]$$$, the ancestor is $$$[2, 1, 2]$$$; for the array $$$[2, 2, 1]$$$, the ancestor is $$$[2, 1, 2]$$$: $$$F([2, 1, 2], 2) = [2, 2, 1]$$$; for the array $$$[2, 2, 2]$$$, the ancestor is $$$[1, 2, 2]$$$: $$$G(F([1, 2, 2], 4), 1, 2) = G([1, 1, 1], 1, 2) = [2, 2, 2]$$$. "}, "src_uid": "eb9d24070cc5b347d020189d803628ae"} {"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": "Getting closer and closer to a mathematician, Serval becomes a university student on math major in Japari University. On the Calculus class, his teacher taught him how to calculate the expected length of a random subsegment of a given segment. Then he left a bonus problem as homework, with the award of a garage kit from IOI. The bonus is to extend this problem to the general case as follows.You are given a segment with length $$$l$$$. We randomly choose $$$n$$$ segments by choosing two points (maybe with non-integer coordinates) from the given segment equiprobably and the interval between the two points forms a segment. You are given the number of random segments $$$n$$$, and another integer $$$k$$$. The $$$2n$$$ endpoints of the chosen segments split the segment into $$$(2n+1)$$$ intervals. Your task is to calculate the expected total length of those intervals that are covered by at least $$$k$$$ segments of the $$$n$$$ random segments.You should find the answer modulo $$$998244353$$$.", "input_spec": "First line contains three space-separated positive integers $$$n$$$, $$$k$$$ and $$$l$$$ ($$$1\\leq k \\leq n \\leq 2000$$$, $$$1\\leq l\\leq 10^9$$$).", "output_spec": "Output one integer\u00a0\u2014 the expected total length of all the intervals covered by at least $$$k$$$ segments of the $$$n$$$ random segments modulo $$$998244353$$$. Formally, let $$$M = 998244353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \\not \\equiv 0 \\pmod{M}$$$. Output the integer equal to $$$p \\cdot q^{-1} \\bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \\le x < M$$$ and $$$x \\cdot q \\equiv p \\pmod{M}$$$.", "sample_inputs": ["1 1 1", "6 2 1", "7 5 3", "97 31 9984524"], "sample_outputs": ["332748118", "760234711", "223383352", "267137618"], "notes": "NoteIn the first example, the expected total length is $$$\\int_0^1 \\int_0^1 |x-y| \\,\\mathrm{d}x\\,\\mathrm{d}y = {1\\over 3}$$$, and $$$3^{-1}$$$ modulo $$$998244353$$$ is $$$332748118$$$."}, "src_uid": "c9e79e83928d5d034123ebc3b2f5e064"} {"nl": {"description": "On one of the planets of Solar system, in Atmosphere University, many students are fans of bingo game.It is well known that one month on this planet consists of $$$n^2$$$ days, so calendars, represented as square matrix $$$n$$$ by $$$n$$$ are extremely popular.Weather conditions are even more unusual. Due to the unique composition of the atmosphere, when interacting with sunlight, every day sky takes one of three colors: blue, green or red.To play the bingo, you need to observe the sky for one month\u00a0\u2014 after each day, its cell is painted with the color of the sky in that day, that is, blue, green or red.At the end of the month, students examine the calendar. If at least one row or column contains only cells of one color, that month is called lucky.Let's call two colorings of calendar different, if at least one cell has different colors in them. It is easy to see that there are $$$3^{n \\cdot n}$$$ different colorings. How much of them are lucky? Since this number can be quite large, print it modulo $$$998244353$$$.", "input_spec": "The first and only line of input contains a single integer $$$n$$$ ($$$1 \\le n \\le 1000\\,000$$$)\u00a0\u2014 the number of rows and columns in the calendar.", "output_spec": "Print one number\u00a0\u2014 number of lucky colorings of the calendar modulo $$$998244353$$$", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["3", "63", "9933"], "notes": "NoteIn the first sample any coloring is lucky, since the only column contains cells of only one color.In the second sample, there are a lot of lucky colorings, in particular, the following colorings are lucky: While these colorings are not lucky: "}, "src_uid": "6e4b0ee2e1406041a961582ead299a3a"} {"nl": {"description": "Let's analyze a program written on some strange programming language. The variables in this language have names consisting of $$$1$$$ to $$$4$$$ characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit.There are four types of operations in the program, each denoted by one of the characters: $, ^, # or &.Each line of the program has one of the following formats: <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names; <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character. The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program.Two programs are called equivalent if no matter which operations do characters $, ^, # and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently).You are given a program consisting of $$$n$$$ lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 1000$$$) \u2014 the number of lines in the program. Then $$$n$$$ lines follow \u2014 the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces.", "output_spec": "In the first line print $$$k$$$ \u2014 the minimum number of lines in the equivalent program. Then print $$$k$$$ lines without any whitespaces \u2014 an equivalent program having exactly $$$k$$$ lines, in the same format it is described in the statement.", "sample_inputs": ["4\nc=aa#bb\nd12=c\nres=c^d12\ntmp=aa$c", "2\nmax=aaaa$bbbb\nmin=bbbb^aaaa"], "sample_outputs": ["2\naaaa=aa#bb\nres=aaaa^aaaa", "0"], "notes": null}, "src_uid": "da40321d92baaef42c2840e45599294c"} {"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": "Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.More formally, you are given an odd numer n. Find a set of numbers pi (1\u2009\u2264\u2009i\u2009\u2264\u2009k), such that 1\u2009\u2264\u2009k\u2009\u2264\u20093 pi is a prime The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.", "input_spec": "The single line contains an odd number n (3\u2009\u2264\u2009n\u2009<\u2009109).", "output_spec": "In the first line print k (1\u2009\u2264\u2009k\u2009\u2264\u20093), showing how many numbers are in the representation you found. In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.", "sample_inputs": ["27"], "sample_outputs": ["3\n5 11 11"], "notes": "NoteA prime is an integer strictly larger than one that is divisible only by one and by itself."}, "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3"} {"nl": {"description": "Petya is an unexperienced programming contestant. Recently he has come across the following problem:You are given a non-directed graph which consists of n nodes and m edges. Your task is to determine whether the graph contains a Hamiltonian path.Petya wrote a quick bug-free code which he believes solves this problem. After that Petya decided to give this problem for April Fools Day contest. Unfortunately, Petya might have made a mistake, and it's quite possible that his algorithm is wrong. But this isn't a good excuse to leave the contest without submitting this problem, is it?", "input_spec": "The first line contains two integers n,\u2009m (1\u2009\u2264\u2009n\u2009\u2264\u200920;\u00a00\u2009\u2264\u2009m\u2009\u2264\u2009400). Next m lines contain pairs of integers vi,\u2009ui (1\u2009\u2264\u2009vi,\u2009ui\u2009\u2264\u2009n).", "output_spec": "Follow the format of Petya's code output.", "sample_inputs": ["2 3\n1 2\n2 1\n1 1", "3 0", "10 20\n3 10\n4 6\n4 9\n7 5\n8 8\n3 10\n9 7\n5 2\n9 2\n10 6\n10 4\n1 1\n7 2\n8 4\n7 2\n1 8\n5 4\n10 2\n8 5\n5 2"], "sample_outputs": ["Yes", "No", "No"], "notes": null}, "src_uid": "d023fc9b58268a36d7fb80deb338b09a"} {"nl": {"description": "It happened at the times of the Great Berland Empire. Once the Emperor dreamt that the Messenger from the gods ordered to build a temple whose base would be a convex polygon with n angles. Next morning the Emperor gave the command to build a temple whose base was a regular polygon with n angles. The temple was built but soon the Empire was shaken with disasters and crop failures. After an earthquake destroyed the temple, the Emperor understood that he somehow caused the wrath of gods to fall on his people. He ordered to bring the wise man. When the wise man appeared, the Emperor retold the dream to him and asked \"Oh the wisest among the wisest, tell me how could I have infuriated the Gods?\". \"My Lord,\" the wise man answered. \"As far as I can judge, the gods are angry because you were too haste to fulfill their order and didn't listen to the end of the message\".Indeed, on the following night the Messenger appeared again. He reproached the Emperor for having chosen an imperfect shape for the temple. \"But what shape can be more perfect than a regular polygon!?\" cried the Emperor in his dream. To that the Messenger gave a complete and thorough reply. All the vertices of the polygon should be positioned in the lattice points. All the lengths of its sides should be different. From the possible range of such polygons a polygon which maximum side is minimal possible must be chosen. You are an obedient architect who is going to make the temple's plan. Note that the polygon should be simple (having a border without self-intersections and overlapping) and convex, however, it is acceptable for three consecutive vertices to lie on the same line.", "input_spec": "The first line contains the single number n (3\u2009\u2264\u2009n\u2009\u2264\u200910000).", "output_spec": "Print \"YES\" (without quotes) in the first line if it is possible to build a polygon possessing the needed qualities. In the next n lines print integer coordinates of the polygon vertices in the order in which they would be passed counter clockwise. The absolute value of the coordinates shouldn't exceed 109. No two vertices can coincide. It is permitted to print any of the possible solutions. Print \"NO\" if to build the polygon is impossible.", "sample_inputs": ["3", "3"], "sample_outputs": ["YES\n0 0\n1 0\n0 2", "YES\n0 1\n-1 0\n-1 -1"], "notes": null}, "src_uid": "77b281558c480607b02e8e263e81a455"} {"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": "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": "Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given a, b and n who wins the game.", "input_spec": "The only string contains space-separated integers a, b and n (1\u2009\u2264\u2009a,\u2009b,\u2009n\u2009\u2264\u2009100) \u2014 the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.", "output_spec": "If Simon wins, print \"0\" (without the quotes), otherwise print \"1\" (without the quotes).", "sample_inputs": ["3 5 9", "1 1 100"], "sample_outputs": ["0", "1"], "notes": "NoteThe greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a,\u2009b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x,\u20090)\u2009=\u2009gcd(0,\u2009x)\u2009=\u2009x.In the first sample the game will go like that: Simon should take gcd(3,\u20099)\u2009=\u20093 stones from the heap. After his move the heap has 6 stones left. Antisimon should take gcd(5,\u20096)\u2009=\u20091 stone from the heap. After his move the heap has 5 stones left. Simon should take gcd(3,\u20095)\u2009=\u20091 stone from the heap. After his move the heap has 4 stones left. Antisimon should take gcd(5,\u20094)\u2009=\u20091 stone from the heap. After his move the heap has 3 stones left. Simon should take gcd(3,\u20093)\u2009=\u20093 stones from the heap. After his move the heap has 0 stones left. Antisimon should take gcd(5,\u20090)\u2009=\u20095 stones from the heap. As 0\u2009<\u20095, it is impossible and Antisimon loses.In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that."}, "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"nl": {"description": "DZY loves Fast Fourier Transformation, and he enjoys using it.Fast Fourier Transformation is an algorithm used to calculate convolution. Specifically, if a, b and c are sequences with length n, which are indexed from 0 to n\u2009-\u20091, andWe can calculate c fast using Fast Fourier Transformation.DZY made a little change on this formula. NowTo make things easier, a is a permutation of integers from 1 to n, and b is a sequence only containing 0 and 1. Given a and b, DZY needs your help to calculate c.Because he is naughty, DZY provides a special way to get a and b. What you need is only three integers n, d, x. After getting them, use the code below to generate a and b.//x is 64-bit variable;function getNextX() { x = (x * 37 + 10007) % 1000000007; return x;}function initAB() { for(i = 0; i < n; i = i + 1){ a[i] = i + 1; } for(i = 0; i < n; i = i + 1){ swap(a[i], a[getNextX() % (i + 1)]); } for(i = 0; i < n; i = i + 1){ if (i < d) b[i] = 1; else b[i] = 0; } for(i = 0; i < n; i = i + 1){ swap(b[i], b[getNextX() % (i + 1)]); }}Operation x % y denotes remainder after division x by y. Function swap(x, y) swaps two values x and y.", "input_spec": "The only line of input contains three space-separated integers n,\u2009d,\u2009x\u00a0(1\u2009\u2264\u2009d\u2009\u2264\u2009n\u2009\u2264\u2009100000;\u00a00\u2009\u2264\u2009x\u2009\u2264\u20091000000006). Because DZY is naughty, x can't be equal to 27777500.", "output_spec": "Output n lines, the i-th line should contain an integer ci\u2009-\u20091.", "sample_inputs": ["3 1 1", "5 4 2", "5 4 3"], "sample_outputs": ["1\n3\n2", "2\n2\n4\n5\n5", "5\n5\n5\n5\n4"], "notes": "NoteIn the first sample, a is [1 3 2], b is [1 0 0], so c0\u2009=\u2009max(1\u00b71)\u2009=\u20091, c1\u2009=\u2009max(1\u00b70,\u20093\u00b71)\u2009=\u20093, c2\u2009=\u2009max(1\u00b70,\u20093\u00b70,\u20092\u00b71)\u2009=\u20092.In the second sample, a is [2 1 4 5 3], b is [1 1 1 0 1].In the third sample, a is [5 2 1 4 3], b is [1 1 1 1 0]."}, "src_uid": "948ae7a0189ada07c8c67a1757f691f0"} {"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": "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": "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": "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": "There are n cards (n is even) in the deck. Each card has a positive integer written on it. n\u2009/\u20092 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.", "input_spec": "The first line of the input contains integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of cards in the deck. It is guaranteed that n is even. The second line contains the sequence of n positive integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100), where ai is equal to the number written on the i-th card.", "output_spec": "Print n\u2009/\u20092 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.", "sample_inputs": ["6\n1 5 7 4 4 3", "4\n10 10 10 10"], "sample_outputs": ["1 3\n6 2\n4 5", "1 2\n3 4"], "notes": "NoteIn the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values ai are equal. Thus, any distribution is acceptable."}, "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"nl": {"description": "This version of the problem differs from the next one only in the constraint on $$$n$$$.Note that the memory limit in this problem is lower than in others.You have a vertical strip with $$$n$$$ cells, numbered consecutively from $$$1$$$ to $$$n$$$ from top to bottom.You also have a token that is initially placed in cell $$$n$$$. You will move the token up until it arrives at cell $$$1$$$.Let the token be in cell $$$x > 1$$$ at some moment. One shift of the token can have either of the following kinds: Subtraction: you choose an integer $$$y$$$ between $$$1$$$ and $$$x-1$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$x - y$$$. Floored division: you choose an integer $$$z$$$ between $$$2$$$ and $$$x$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$\\lfloor \\frac{x}{z} \\rfloor$$$ ($$$x$$$ divided by $$$z$$$ rounded down). Find the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$ using one or more shifts, and print it modulo $$$m$$$. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$; $$$10^8 < m < 10^9$$$; $$$m$$$ is a prime number)\u00a0\u2014 the length of the strip and the modulo.", "output_spec": "Print the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$, modulo $$$m$$$.", "sample_inputs": ["3 998244353", "5 998244353", "42 998244353"], "sample_outputs": ["5", "25", "793019428"], "notes": "NoteIn the first test, there are three ways to move the token from cell $$$3$$$ to cell $$$1$$$ in one shift: using subtraction of $$$y = 2$$$, or using division by $$$z = 2$$$ or $$$z = 3$$$.There are also two ways to move the token from cell $$$3$$$ to cell $$$1$$$ via cell $$$2$$$: first subtract $$$y = 1$$$, and then either subtract $$$y = 1$$$ again or divide by $$$z = 2$$$.Therefore, there are five ways in total."}, "src_uid": "a524aa54e83fd0223489a19531bf0e79"} {"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": "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": "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": "Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.", "input_spec": "The only line of the input contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u20091018)\u00a0\u2014 the number of players to participate in the tournament.", "output_spec": "Print the maximum number of games in which the winner of the tournament can take part.", "sample_inputs": ["2", "3", "4", "10"], "sample_outputs": ["1", "2", "2", "4"], "notes": "NoteIn all samples we consider that player number 1 is the winner.In the first sample, there would be only one game so the answer is 1.In the second sample, player 1 can consequently beat players 2 and 3. In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1,\u20092) and (3,\u20094) and then clash the winners."}, "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"nl": {"description": "Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $$$0$$$.Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $$$v$$$: If $$$v$$$ has a left subtree whose root is $$$u$$$, then the parity of the key of $$$v$$$ is different from the parity of the key of $$$u$$$. If $$$v$$$ has a right subtree whose root is $$$w$$$, then the parity of the key of $$$v$$$ is the same as the parity of the key of $$$w$$$. You are given a single integer $$$n$$$. Find the number of perfectly balanced striped binary search trees with $$$n$$$ vertices that have distinct integer keys between $$$1$$$ and $$$n$$$, inclusive. Output this number modulo $$$998\\,244\\,353$$$.", "input_spec": "The only line contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$), denoting the required number of vertices.", "output_spec": "Output the number of perfectly balanced striped binary search trees with $$$n$$$ vertices and distinct integer keys between $$$1$$$ and $$$n$$$, inclusive, modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["4", "3"], "sample_outputs": ["1", "0"], "notes": "NoteIn the first example, this is the only tree that satisfies the conditions: In the second example, here are various trees that don't satisfy some condition: "}, "src_uid": "821409c1b9bdcd18c4dcf35dc5116501"} {"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": "Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li,\u2009Ri] with the same probability. Determine the expected value that the winner will have to pay in a second-price auction.", "input_spec": "The first line of input contains an integer number n (2\u2009\u2264\u2009n\u2009\u2264\u20095). n lines follow, the i-th of them containing two numbers Li and Ri (1\u2009\u2264\u2009Li\u2009\u2264\u2009Ri\u2009\u2264\u200910000) describing the i-th company's bid preferences. This problem doesn't have subproblems. You will get 8 points for the correct submission.", "output_spec": "Output the answer with absolute or relative error no more than 1e\u2009-\u20099.", "sample_inputs": ["3\n4 7\n8 10\n5 5", "3\n2 5\n3 4\n1 6"], "sample_outputs": ["5.7500000000", "3.5000000000"], "notes": "NoteConsider the first example. The first company bids a random integer number of microdollars in range [4,\u20097]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5\u00b75\u2009+\u20090.25\u00b76\u2009+\u20090.25\u00b77\u2009=\u20095.75."}, "src_uid": "5258ce738eb268b9750cfef309d265ef"} {"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": "Alice and Bob begin their day with a quick game. They first choose a starting number X0\u2009\u2265\u20093 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.Formally, he or she selects a prime p\u2009<\u2009Xi\u2009-\u20091 and then finds the minimum Xi\u2009\u2265\u2009Xi\u2009-\u20091 such that p divides Xi. Note that if the selected prime p already divides Xi\u2009-\u20091, then the number does not change.Eve has witnessed the state of the game after two turns. Given X2, help her determine what is the smallest possible starting number X0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.", "input_spec": "The input contains a single integer X2 (4\u2009\u2264\u2009X2\u2009\u2264\u2009106). It is guaranteed that the integer X2 is composite, that is, is not prime.", "output_spec": "Output a single integer\u00a0\u2014 the minimum possible X0.", "sample_inputs": ["14", "20", "8192"], "sample_outputs": ["6", "15", "8191"], "notes": "NoteIn the first test, the smallest possible starting number is X0\u2009=\u20096. One possible course of the game is as follows: Alice picks prime 5 and announces X1\u2009=\u200910 Bob picks prime 7 and announces X2\u2009=\u200914. In the second case, let X0\u2009=\u200915. Alice picks prime 2 and announces X1\u2009=\u200916 Bob picks prime 5 and announces X2\u2009=\u200920. "}, "src_uid": "43ff6a223c68551eff793ba170110438"} {"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": "Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: \"+\", \"-\", \"[\", \"]\", \"<\", \">\", \".\" and \",\" (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table: \">\" \u2009\u2192\u2009 1000, \"<\" \u2009\u2192\u2009 1001, \"+\" \u2009\u2192\u2009 1010, \"-\" \u2009\u2192\u2009 1011, \".\" \u2009\u2192\u2009 1100, \",\" \u2009\u2192\u2009 1101, \"[\" \u2009\u2192\u2009 1110, \"]\" \u2009\u2192\u2009 1111. Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system \u2014 this is the Unary program equivalent to the original Brainfuck one.You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106\u2009+\u20093).", "input_spec": "The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be \"+\", \"-\", \"[\", \"]\", \"<\", \">\", \".\" or \",\".", "output_spec": "Output the size of the equivalent Unary program modulo 1000003 (106\u2009+\u20093).", "sample_inputs": [",.", "++++[>,.<-]"], "sample_outputs": ["220", "61425"], "notes": "NoteTo write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program."}, "src_uid": "04fc8dfb856056f35d296402ad1b2da1"} {"nl": {"description": "Polycarp plays a well-known computer game (we won't mention its name). Every object in this game consists of three-dimensional blocks \u2014 axis-aligned cubes of size $$$1 \\times 1 \\times 1$$$. These blocks are unaffected by gravity, so they can float in the air without support. The blocks are placed in cells of size $$$1 \\times 1 \\times 1$$$; each cell either contains exactly one block or is empty. Each cell is represented by its coordinates $$$(x, y, z)$$$ (the cell with these coordinates is a cube with opposite corners in $$$(x, y, z)$$$ and $$$(x + 1, y + 1, z + 1)$$$) and its contents $$$a_{x, y, z}$$$; if the cell is empty, then $$$a_{x, y, z} = 0$$$, otherwise $$$a_{x, y, z}$$$ is equal to the type of the block placed in it (the types are integers from $$$1$$$ to $$$2 \\cdot 10^5$$$).Polycarp has built a large structure consisting of blocks. This structure can be enclosed in an axis-aligned rectangular parallelepiped of size $$$n \\times m \\times k$$$, containing all cells $$$(x, y, z)$$$ such that $$$x \\in [1, n]$$$, $$$y \\in [1, m]$$$, and $$$z \\in [1, k]$$$. After that, Polycarp has installed $$$2nm + 2nk + 2mk$$$ sensors around this parallelepiped. A sensor is a special block that sends a ray in some direction and shows the type of the first block that was hit by this ray (except for other sensors). The sensors installed by Polycarp are adjacent to the borders of the parallelepiped, and the rays sent by them are parallel to one of the coordinate axes and directed inside the parallelepiped. More formally, the sensors can be divided into $$$6$$$ types: there are $$$mk$$$ sensors of the first type; each such sensor is installed in $$$(0, y, z)$$$, where $$$y \\in [1, m]$$$ and $$$z \\in [1, k]$$$, and it sends a ray that is parallel to the $$$Ox$$$ axis and has the same direction; there are $$$mk$$$ sensors of the second type; each such sensor is installed in $$$(n + 1, y, z)$$$, where $$$y \\in [1, m]$$$ and $$$z \\in [1, k]$$$, and it sends a ray that is parallel to the $$$Ox$$$ axis and has the opposite direction; there are $$$nk$$$ sensors of the third type; each such sensor is installed in $$$(x, 0, z)$$$, where $$$x \\in [1, n]$$$ and $$$z \\in [1, k]$$$, and it sends a ray that is parallel to the $$$Oy$$$ axis and has the same direction; there are $$$nk$$$ sensors of the fourth type; each such sensor is installed in $$$(x, m + 1, z)$$$, where $$$x \\in [1, n]$$$ and $$$z \\in [1, k]$$$, and it sends a ray that is parallel to the $$$Oy$$$ axis and has the opposite direction; there are $$$nm$$$ sensors of the fifth type; each such sensor is installed in $$$(x, y, 0)$$$, where $$$x \\in [1, n]$$$ and $$$y \\in [1, m]$$$, and it sends a ray that is parallel to the $$$Oz$$$ axis and has the same direction; finally, there are $$$nm$$$ sensors of the sixth type; each such sensor is installed in $$$(x, y, k + 1)$$$, where $$$x \\in [1, n]$$$ and $$$y \\in [1, m]$$$, and it sends a ray that is parallel to the $$$Oz$$$ axis and has the opposite direction. Polycarp has invited his friend Monocarp to play with him. Of course, as soon as Monocarp saw a large parallelepiped bounded by sensor blocks, he began to wonder what was inside of it. Polycarp didn't want to tell Monocarp the exact shape of the figure, so he provided Monocarp with the data from all sensors and told him to try guessing the contents of the parallelepiped by himself.After some hours of thinking, Monocarp has no clue about what's inside the sensor-bounded space. But he does not want to give up, so he decided to ask for help. Can you write a program that will analyze the sensor data and construct any figure that is consistent with it?", "input_spec": "The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \\le n, m, k \\le 2 \\cdot 10^5$$$, $$$nmk \\le 2 \\cdot 10^5$$$) \u2014 the dimensions of the parallelepiped. Then the sensor data follows. For each sensor, its data is either $$$0$$$, if the ray emitted from it reaches the opposite sensor (there are no blocks in between), or an integer from $$$1$$$ to $$$2 \\cdot 10^5$$$ denoting the type of the first block hit by the ray. The data is divided into $$$6$$$ sections (one for each type of sensors), each consecutive pair of sections is separated by a blank line, and the first section is separated by a blank line from the first line of the input. The first section consists of $$$m$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(0, i, j)$$$. The second section consists of $$$m$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(n + 1, i, j)$$$. The third section consists of $$$n$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, 0, j)$$$. The fourth section consists of $$$n$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, m + 1, j)$$$. The fifth section consists of $$$n$$$ lines containing $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, j, 0)$$$. Finally, the sixth section consists of $$$n$$$ lines containing $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, j, k + 1)$$$.", "output_spec": "If the information from the input is inconsistent, print one integer $$$-1$$$. Otherwise, print the figure inside the parallelepiped as follows. The output should consist of $$$nmk$$$ integers: $$$a_{1, 1, 1}$$$, $$$a_{1, 1, 2}$$$, ..., $$$a_{1, 1, k}$$$, $$$a_{1, 2, 1}$$$, ..., $$$a_{1, 2, k}$$$, ..., $$$a_{1, m, k}$$$, $$$a_{2, 1, 1}$$$, ..., $$$a_{n, m, k}$$$, where $$$a_{i, j, k}$$$ is the type of the block in $$$(i, j, k)$$$, or $$$0$$$ if there is no block there. If there are multiple figures consistent with sensor data, describe any of them. For your convenience, the sample output is formatted as follows: there are $$$n$$$ separate sections for blocks having $$$x = 1$$$, $$$x = 2$$$, ..., $$$x = n$$$; each section consists of $$$m$$$ lines containing $$$k$$$ integers each. Note that this type of output is acceptable, but you may print the integers with any other formatting instead (even all integers on the same line), only their order matters.", "sample_inputs": ["4 3 2\n\n1 4\n3 2\n6 5\n\n1 4\n3 2\n6 7\n\n1 4\n1 4\n0 0\n0 7\n\n6 5\n6 5\n0 0\n0 7\n\n1 3 6\n1 3 6\n0 0 0\n0 0 7\n\n4 3 5\n4 2 5\n0 0 0\n0 0 7", "1 1 1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0", "1 1 1\n\n0\n\n0\n\n1337\n\n0\n\n0\n\n0", "1 1 1\n\n1337\n\n1337\n\n1337\n\n1337\n\n1337\n\n1337"], "sample_outputs": ["1 4\n3 0\n6 5\n\n1 4\n3 2\n6 5\n\n0 0\n0 0\n0 0\n\n0 0\n0 0\n0 7", "0", "-1", "1337"], "notes": null}, "src_uid": "cdacfb8b1ca4c88b576fa7b3cf71f8ec"} {"nl": {"description": "One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory. The board of directors are worried that the production by the given plan may eventually stop (that means that there will be \u0430 moment when the current number of details on the factory is divisible by m). Given the number of details a on the first day and number m check if the production stops at some moment.", "input_spec": "The first line contains two integers a and m (1\u2009\u2264\u2009a,\u2009m\u2009\u2264\u2009105).", "output_spec": "Print \"Yes\" (without quotes) if the production will eventually stop, otherwise print \"No\".", "sample_inputs": ["1 5", "3 6"], "sample_outputs": ["No", "Yes"], "notes": null}, "src_uid": "f726133018e2149ec57e113860ec498a"} {"nl": {"description": "InputThe input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.OutputOutput \"YES\" or \"NO\".ExamplesInput\nGENIUS\nOutput\nYES\nInput\nDOCTOR\nOutput\nNO\nInput\nIRENE\nOutput\nYES\nInput\nMARY\nOutput\nNO\nInput\nSMARTPHONE\nOutput\nNO\nInput\nREVOLVER\nOutput\nYES\nInput\nHOLMES\nOutput\nNO\nInput\nWATSON\nOutput\nYES\n", "input_spec": "The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.", "output_spec": "Output \"YES\" or \"NO\".", "sample_inputs": ["GENIUS", "DOCTOR", "IRENE", "MARY", "SMARTPHONE", "REVOLVER", "HOLMES", "WATSON"], "sample_outputs": ["YES", "NO", "YES", "NO", "NO", "YES", "NO", "YES"], "notes": null}, "src_uid": "d0ad35798119f98320967127c43ae88d"} {"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": "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": "One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.More formally, you need to find such integer a (1\u2009\u2264\u2009a\u2009\u2264\u2009n), that the probability that is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009m\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 the range of numbers in the game, and the number selected by Misha respectively.", "output_spec": "Print a single number \u2014 such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.", "sample_inputs": ["3 1", "4 3"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first sample test: Andrew wins if c is equal to 2 or 3. The probability that Andrew wins is 2\u2009/\u20093. If Andrew chooses a\u2009=\u20093, the probability of winning will be 1\u2009/\u20093. If a\u2009=\u20091, the probability of winning is 0.In the second sample test: Andrew wins if c is equal to 1 and 2. The probability that Andrew wins is 1\u2009/\u20092. For other choices of a the probability of winning is less."}, "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"nl": {"description": "Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that \"the years fly by...\", it was decided that starting from the next year the number of days per year will begin to grow. So the coming year will have exactly a days, the next after coming year will have a\u2009+\u20091 days, the next one will have a\u2009+\u20092 days and so on. This schedule is planned for the coming n years (in the n-th year the length of the year will be equal a\u2009+\u2009n\u2009-\u20091 day).No one has yet decided what will become of months. An MP Palevny made the following proposal. The calendar for each month is comfortable to be printed on a square sheet of paper. We are proposed to make the number of days in each month be the square of some integer. The number of days per month should be the same for each month of any year, but may be different for different years. The number of days in each year must be divisible by the number of days per month in this year. This rule ensures that the number of months in each year is an integer. The number of days per month for each year must be chosen so as to save the maximum amount of paper to print the calendars. In other words, the number of days per month should be as much as possible. These rules provide an unambiguous method for choosing the number of days in each month for any given year length. For example, according to Palevny's proposition, a year that consists of 108 days will have three months, 36 days each. The year that consists of 99 days will have 11 months, 9 days each, and a year of 365 days will have 365 months, one day each.The proposal provoked heated discussion in the community, the famous mathematician Perelmanov quickly calculated that if the proposal is supported, then in a period of n years, beginning with the year that has a days, the country will spend p sheets of paper to print a set of calendars for these years. Perelmanov's calculations take into account the fact that the set will contain one calendar for each year and each month will be printed on a separate sheet.Repeat Perelmanov's achievement and print the required number p. You are given positive integers a and n. Perelmanov warns you that your program should not work longer than four seconds at the maximum test.", "input_spec": "The only input line contains a pair of integers a, n (1\u2009\u2264\u2009a,\u2009n\u2009\u2264\u2009107; a\u2009+\u2009n\u2009-\u20091\u2009\u2264\u2009107).", "output_spec": "Print the required number p. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use cin, cout streams or the %I64d specifier.", "sample_inputs": ["25 3", "50 5"], "sample_outputs": ["30", "125"], "notes": "NoteA note to the first sample test. A year of 25 days will consist of one month containing 25 days. A year of 26 days will consist of 26 months, one day each. A year of 27 days will have three months, 9 days each."}, "src_uid": "915081861e391958dce6ee2a117abd4e"} {"nl": {"description": "Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is ai meters high. Vladimir has just planted n bamboos in a row, each of which has height 0 meters right now, but they grow 1 meter each day. In order to make the partition nice Vladimir can cut each bamboo once at any height (no greater that the height of the bamboo), and then the bamboo will stop growing.Vladimir wants to check the bamboos each d days (i.e. d days after he planted, then after 2d days and so on), and cut the bamboos that reached the required height. Vladimir wants the total length of bamboo parts he will cut off to be no greater than k meters.What is the maximum value d he can choose so that he can achieve what he wants without cutting off more than k meters of bamboo?", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009100, 1\u2009\u2264\u2009k\u2009\u2264\u20091011)\u00a0\u2014 the number of bamboos and the maximum total length of cut parts, in meters. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009109)\u00a0\u2014 the required heights of bamboos, in meters.", "output_spec": "Print a single integer\u00a0\u2014 the maximum value of d such that Vladimir can reach his goal.", "sample_inputs": ["3 4\n1 3 5", "3 40\n10 30 50"], "sample_outputs": ["3", "32"], "notes": "NoteIn the first example Vladimir can check bamboos each 3 days. Then he will cut the first and the second bamboos after 3 days, and the third bamboo after 6 days. The total length of cut parts is 2\u2009+\u20090\u2009+\u20091\u2009=\u20093 meters."}, "src_uid": "2e1ab01d4d4440f33c840c4564a20a60"} {"nl": {"description": "Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first k Latin letters and not containing any other ones. Also, the title should be a palindrome, that is it should be read similarly from the left to the right and from the right to the left.Vasya has already composed the approximate variant of the title. You are given the title template s consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues.", "input_spec": "The first line contains an integer k (1\u2009\u2264\u2009k\u2009\u2264\u200926) which is the number of allowed alphabet letters. The second line contains s which is the given template. In s only the first k lowercase letters of Latin alphabet and question marks can be present, the length of s is from 1 to 100 characters inclusively.", "output_spec": "If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first k letters of the Latin alphabet. At that, each of those k letters must be present at least once. If there are several suitable titles, print the lexicographically minimal one. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if exists such an i (1\u2009\u2264\u2009i\u2009\u2264\u2009|s|), that ai\u2009<\u2009bi, and for any j (1\u2009\u2264\u2009j\u2009<\u2009i) aj\u2009=\u2009bj. |s| stands for the length of the given template.", "sample_inputs": ["3\na?c", "2\na??a", "2\n?b?a"], "sample_outputs": ["IMPOSSIBLE", "abba", "abba"], "notes": null}, "src_uid": "9d1dd9d722e5fe46823224334b3b208a"} {"nl": {"description": "You are given a binary string $$$s$$$.Find the number of distinct cyclical binary strings of length $$$n$$$ which contain $$$s$$$ as a substring.The cyclical string $$$t$$$ contains $$$s$$$ as a substring if there is some cyclical shift of string $$$t$$$, such that $$$s$$$ is a substring of this cyclical shift of $$$t$$$.For example, the cyclical string \"000111\" contains substrings \"001\", \"01110\" and \"10\", but doesn't contain \"0110\" and \"10110\".Two cyclical strings are called different if they differ from each other as strings. For example, two different strings, which differ from each other by a cyclical shift, are still considered different cyclical strings.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 40$$$)\u00a0\u2014 the length of the target string $$$t$$$. The next line contains the string $$$s$$$ ($$$1 \\le |s| \\le n$$$)\u00a0\u2014 the string which must be a substring of cyclical string $$$t$$$. String $$$s$$$ contains only characters '0' and '1'.", "output_spec": "Print the only integer\u00a0\u2014 the number of distinct cyclical binary strings $$$t$$$, which contain $$$s$$$ as a substring.", "sample_inputs": ["2\n0", "4\n1010", "20\n10101010101010"], "sample_outputs": ["3", "2", "962"], "notes": "NoteIn the first example, there are three cyclical strings, which contain \"0\"\u00a0\u2014 \"00\", \"01\" and \"10\".In the second example, there are only two such strings\u00a0\u2014 \"1010\", \"0101\"."}, "src_uid": "0034806908c9794086736a2d07fc654c"} {"nl": {"description": "For some experiments little Petya needs a synchrophasotron. He has already got the device, all that's left is to set the fuel supply. Fuel comes through a system of nodes numbered from 1 to n and connected by pipes. Pipes go from every node with smaller number to every node with greater number. Fuel can only flow through pipes in direction from node with smaller number to node with greater number. Any amount of fuel can enter through the first node and the last node is connected directly to the synchrophasotron. It is known that every pipe has three attributes: the minimum amount of fuel that should go through it, the maximum amount of fuel that can possibly go through it and the cost of pipe activation. If cij units of fuel (cij\u2009>\u20090) flow from node i to node j, it will cost aij\u2009+\u2009cij2 tugriks (aij is the cost of pipe activation), and if fuel doesn't flow through the pipe, it doesn't cost anything. Only integer number of units of fuel can flow through each pipe.Constraints on the minimal and the maximal fuel capacity of a pipe take place always, not only if it is active. You may assume that the pipe is active if and only if the flow through it is strictly greater than zero.Petya doesn't want the pipe system to be overloaded, so he wants to find the minimal amount of fuel, that, having entered the first node, can reach the synchrophasotron. Besides that he wants to impress the sponsors, so the sum of money needed to be paid for fuel to go through each pipe, must be as big as possible.", "input_spec": "First line contains integer n (2\u2009\u2264\u2009n\u2009\u2264\u20096), which represents the number of nodes. Each of the next n(n\u2009-\u20091)\u2009/\u20092 lines contains five integers s,\u2009f,\u2009l,\u2009h,\u2009a that describe pipes \u2014 the first node of the pipe, the second node of the pipe, the minimum and the maximum amount of fuel that can flow through the pipe and the the activation cost, respectively. (1\u2009\u2264\u2009s\u2009<\u2009f\u2009\u2264\u2009n,\u20090\u2009\u2264\u2009l\u2009\u2264\u2009h\u2009\u2264\u20095,\u20090\u2009\u2264\u2009a\u2009\u2264\u20096). It is guaranteed that for each pair of nodes with distinct numbers there will be exactly one pipe between them described in the input.", "output_spec": "Output in the first line two space-separated numbers: the minimum possible amount of fuel that can flow into the synchrophasotron, and the maximum possible sum that needs to be paid in order for that amount of fuel to reach synchrophasotron. If there is no amount of fuel that can reach synchrophasotron, output \"-1 -1\". The amount of fuel which will flow into synchrophasotron is not neccessary positive. It could be equal to zero if the minimum constraint of every pipe is equal to zero.", "sample_inputs": ["2\n1 2 1 2 3", "3\n1 2 1 2 3\n1 3 0 0 0\n2 3 3 4 5", "4\n1 2 0 2 1\n2 3 0 2 1\n1 3 0 2 6\n1 4 0 0 1\n2 4 0 0 0\n3 4 2 3 0", "3\n1 2 0 2 1\n1 3 1 2 1\n2 3 1 2 1"], "sample_outputs": ["1 4", "-1 -1", "2 15", "2 6"], "notes": "NoteIn the first test, we can either pass 1 or 2 units of fuel from node 1 to node 2. The minimum possible amount is 1, it costs a12\u2009+\u200912\u2009=\u20094.In the second test, you can pass at most 2 units from node 1 to node 2, and at you have to pass at least 3 units from node 2 to node 3. It is impossible.In the third test, the minimum possible amount is 2. You can pass each unit of fuel through two different paths: either 1->2->3->4 or 1->3->4. If you use the first path twice, it will cost a12\u2009+\u200922\u2009+\u2009a23\u2009+\u200922\u2009+\u2009a34\u2009+\u200922=14. If you use the second path twice, it will cost a13\u2009+\u200922\u2009+\u2009a34\u2009+\u200922=14. However, if you use each path (allowing one unit of fuel go through pipes 1->2, 2->3, 1->3, and two units go through 3->4) it will cost a12\u2009+\u200912\u2009+\u2009a23\u2009+\u200912\u2009+\u2009a13\u2009+\u200912\u2009+\u2009a34\u2009+\u200922=15 and it is the maximum possible cost.Also note that since no fuel flows from node 1 to node 4, activation cost for that pipe is not added to the answer."}, "src_uid": "38886ad7b0d83e66b77348be34828426"} {"nl": {"description": "In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.", "input_spec": "The first and only line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106) which represents the denomination of the most expensive coin. ", "output_spec": "Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination n of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.", "sample_inputs": ["10", "4", "3"], "sample_outputs": ["10 5 1", "4 2 1", "3 1"], "notes": null}, "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"} {"nl": {"description": "Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. ", "input_spec": "The first line contains the positive integer x (1\u2009\u2264\u2009x\u2009\u2264\u20091018) \u2014 the integer which Anton has. ", "output_spec": "Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.", "sample_inputs": ["100", "48", "521"], "sample_outputs": ["99", "48", "499"], "notes": null}, "src_uid": "e55b0debbf33c266091e6634494356b8"} {"nl": {"description": "There are $$$n$$$ cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from $$$1$$$ to $$$n$$$.Two fairs are currently taking place in Berland \u2014 they are held in two different cities $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le n$$$; $$$a \\ne b$$$).Find the number of pairs of cities $$$x$$$ and $$$y$$$ ($$$x \\ne a, x \\ne b, y \\ne a, y \\ne b$$$) such that if you go from $$$x$$$ to $$$y$$$ you will have to go through both fairs (the order of visits doesn't matter). Formally, you need to find the number of pairs of cities $$$x,y$$$ such that any path from $$$x$$$ to $$$y$$$ goes through $$$a$$$ and $$$b$$$ (in any order).Print the required number of pairs. The order of two cities in a pair does not matter, that is, the pairs $$$(x,y)$$$ and $$$(y,x)$$$ must be taken into account only once.", "input_spec": "The first line of the input contains an integer $$$t$$$ ($$$1 \\le t \\le 4\\cdot10^4$$$) \u2014 the number of test cases in the input. Next, $$$t$$$ test cases are specified. The first line of each test case contains four integers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$4 \\le n \\le 2\\cdot10^5$$$, $$$n - 1 \\le m \\le 5\\cdot10^5$$$, $$$1 \\le a,b \\le n$$$, $$$a \\ne b$$$) \u2014 numbers of cities and roads in Berland and numbers of two cities where fairs are held, respectively. The following $$$m$$$ lines contain descriptions of roads between cities. Each of road description contains a pair of integers $$$u_i, v_i$$$ ($$$1 \\le u_i, v_i \\le n$$$, $$$u_i \\ne v_i$$$) \u2014 numbers of cities connected by the road. Each road is bi-directional and connects two different cities. It is guaranteed that from any city you can pass to any other by roads. There can be more than one road between a pair of cities. The sum of the values of $$$n$$$ for all sets of input data in the test does not exceed $$$2\\cdot10^5$$$. The sum of the values of $$$m$$$ for all sets of input data in the test does not exceed $$$5\\cdot10^5$$$.", "output_spec": "Print $$$t$$$ integers \u2014 the answers to the given test cases in the order they are written in the input.", "sample_inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1"], "sample_outputs": ["4\n0\n1"], "notes": null}, "src_uid": "7636c493ad91210ec7571895b4b71214"} {"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": "Kolya has a turtle and a field of size $$$2 \\times n$$$. The field rows are numbered from $$$1$$$ to $$$2$$$ from top to bottom, while the columns are numbered from $$$1$$$ to $$$n$$$ from left to right.Suppose in each cell of the field there is a lettuce leaf. The energy value of lettuce leaf in row $$$i$$$ and column $$$j$$$ is equal to $$$a_{i,j}$$$. The turtle is initially in the top left cell and wants to reach the bottom right cell. The turtle can only move right and down and among all possible ways it will choose a way, maximizing the total energy value of lettuce leaves (in case there are several such paths, it will choose any of them).Kolya is afraid, that if turtle will eat too much lettuce, it can be bad for its health. So he wants to reorder lettuce leaves in the field, so that the energetic cost of leaves eaten by turtle will be minimized.", "input_spec": "The first line contains an integer $$$n$$$ ($$$2 \\le n \\le 25$$$)\u00a0\u2014 the length of the field. The second line contains $$$n$$$ integers $$$a_{1, i}$$$ ($$$0 \\le a_{1, i} \\le 50\\,000$$$), the energetic cost of lettuce leaves in the first row of the field. The third line contains $$$n$$$ integers $$$a_{2, i}$$$ ($$$0 \\le a_{2, i} \\le 50\\,000$$$), the energetic cost of lettuce leaves in the second row of the field.", "output_spec": "Print two lines with $$$n$$$ integers in each\u00a0\u2014 the optimal reordering of lettuce from the input data. In case there are several optimal ways to reorder lettuce, print any of them.", "sample_inputs": ["2\n1 4\n2 3", "3\n0 0 0\n0 0 0", "3\n1 0 1\n0 0 0"], "sample_outputs": ["1 3 \n4 2", "0 0 0 \n0 0 0", "0 0 1\n0 1 0"], "notes": "NoteIn the first example, after reordering, the turtle will eat lettuce with total energetic cost $$$1+4+2 = 7$$$.In the second example, the turtle will eat lettuce with energetic cost equal $$$0$$$.In the third example, after reordering, the turtle will eat lettuce with total energetic cost equal $$$1$$$."}, "src_uid": "02372f2c8e5fbf5dc579bbe61b975e1e"} {"nl": {"description": "Two best friends Serozha and Gena play a game.Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1\u2009>\u2009a2\u2009>\u2009...\u2009>\u2009ak\u2009>\u20090 stones. The piles should meet the condition a1\u2009-\u2009a2\u2009=\u2009a2\u2009-\u2009a3\u2009=\u2009...\u2009=\u2009ak\u2009-\u20091\u2009-\u2009ak\u2009=\u20091. Naturally, the number of piles k should be no less than two.The friends play in turns. The player who cannot make a move loses. Serozha makes the first move. Who will win if both players play in the optimal way?", "input_spec": "The single line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105).", "output_spec": "If Serozha wins, print k, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game. If Gena wins, print \"-1\" (without the quotes).", "sample_inputs": ["3", "6", "100"], "sample_outputs": ["2", "-1", "8"], "notes": null}, "src_uid": "63262317ba572d78163c91b853c05506"} {"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": "Tarly has two different type of items, food boxes and wine barrels. There are f food boxes and w wine barrels. Tarly stores them in various stacks and each stack can consist of either food boxes or wine barrels but not both. The stacks are placed in a line such that no two stacks of food boxes are together and no two stacks of wine barrels are together.The height of a stack is defined as the number of items in the stack. Two stacks are considered different if either their heights are different or one of them contains food and other contains wine.Jon Snow doesn't like an arrangement if any stack of wine barrels has height less than or equal to h. What is the probability that Jon Snow will like the arrangement if all arrangement are equiprobably?Two arrangement of stacks are considered different if exists such i, that i-th stack of one arrangement is different from the i-th stack of the other arrangement.", "input_spec": "The first line of input contains three integers f, w, h (0\u2009\u2264\u2009f,\u2009w,\u2009h\u2009\u2264\u2009105) \u2014 number of food boxes, number of wine barrels and h is as described above. It is guaranteed that he has at least one food box or at least one wine barrel.", "output_spec": "Output the probability that Jon Snow will like the arrangement. The probability is of the form , then you need to output a single integer p\u00b7q\u2009-\u20091 mod (109\u2009+\u20097).", "sample_inputs": ["1 1 1", "1 2 1"], "sample_outputs": ["0", "666666672"], "notes": "NoteIn the first example f\u2009\u2009=\u2009\u20091, w\u2009=\u20091 and h\u2009=\u20091, there are only two possible arrangement of stacks and Jon Snow doesn't like any of them.In the second example f\u2009=\u20091, w\u2009=\u20092 and h\u2009=\u20091, there are three arrangements. Jon Snow likes the (1) and (3) arrangement. So the probabilty is . "}, "src_uid": "a69f95db3fe677111cf0558271b40f39"} {"nl": {"description": "THE SxPLAY & KIV\u039b - \u6f02\u6d41 KIV\u039b & Nikki Simmons - PerspectivesWith a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.The space can be considered a 2D plane, with an infinite number of data nodes, indexed from $$$0$$$, with their coordinates defined as follows: The coordinates of the $$$0$$$-th node is $$$(x_0, y_0)$$$ For $$$i > 0$$$, the coordinates of $$$i$$$-th node is $$$(a_x \\cdot x_{i-1} + b_x, a_y \\cdot y_{i-1} + b_y)$$$ Initially Aroma stands at the point $$$(x_s, y_s)$$$. She can stay in OS space for at most $$$t$$$ seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point $$$(x_s, y_s)$$$ to warp home.While within the OS space, Aroma can do the following actions: From the point $$$(x, y)$$$, Aroma can move to one of the following points: $$$(x-1, y)$$$, $$$(x+1, y)$$$, $$$(x, y-1)$$$ or $$$(x, y+1)$$$. This action requires $$$1$$$ second. If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs $$$0$$$ seconds. Of course, each data node can be collected at most once. Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within $$$t$$$ seconds?", "input_spec": "The first line contains integers $$$x_0$$$, $$$y_0$$$, $$$a_x$$$, $$$a_y$$$, $$$b_x$$$, $$$b_y$$$ ($$$1 \\leq x_0, y_0 \\leq 10^{16}$$$, $$$2 \\leq a_x, a_y \\leq 100$$$, $$$0 \\leq b_x, b_y \\leq 10^{16}$$$), which define the coordinates of the data nodes. The second line contains integers $$$x_s$$$, $$$y_s$$$, $$$t$$$ ($$$1 \\leq x_s, y_s, t \\leq 10^{16}$$$)\u00a0\u2013 the initial Aroma's coordinates and the amount of time available.", "output_spec": "Print a single integer\u00a0\u2014 the maximum number of data nodes Aroma can collect within $$$t$$$ seconds.", "sample_inputs": ["1 1 2 3 1 0\n2 4 20", "1 1 2 3 1 0\n15 27 26", "1 1 2 3 1 0\n2 2 1"], "sample_outputs": ["3", "2", "0"], "notes": "NoteIn all three examples, the coordinates of the first $$$5$$$ data nodes are $$$(1, 1)$$$, $$$(3, 3)$$$, $$$(7, 9)$$$, $$$(15, 27)$$$ and $$$(31, 81)$$$ (remember that nodes are numbered from $$$0$$$).In the first example, the optimal route to collect $$$3$$$ nodes is as follows: Go to the coordinates $$$(3, 3)$$$ and collect the $$$1$$$-st node. This takes $$$|3 - 2| + |3 - 4| = 2$$$ seconds. Go to the coordinates $$$(1, 1)$$$ and collect the $$$0$$$-th node. This takes $$$|1 - 3| + |1 - 3| = 4$$$ seconds. Go to the coordinates $$$(7, 9)$$$ and collect the $$$2$$$-nd node. This takes $$$|7 - 1| + |9 - 1| = 14$$$ seconds. In the second example, the optimal route to collect $$$2$$$ nodes is as follows: Collect the $$$3$$$-rd node. This requires no seconds. Go to the coordinates $$$(7, 9)$$$ and collect the $$$2$$$-th node. This takes $$$|15 - 7| + |27 - 9| = 26$$$ seconds. In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that."}, "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"} {"nl": {"description": "Chouti thought about his very first days in competitive programming. When he had just learned to write merge sort, he thought that the merge sort is too slow, so he restricted the maximum depth of recursion and modified the merge sort to the following: Chouti found his idea dumb since obviously, this \"merge sort\" sometimes cannot sort the array correctly. However, Chouti is now starting to think of how good this \"merge sort\" is. Particularly, Chouti wants to know for a random permutation $$$a$$$ of $$$1, 2, \\ldots, n$$$ the expected number of inversions after calling MergeSort(a, 1, n, k).It can be proved that the expected number is rational. For the given prime $$$q$$$, suppose the answer can be denoted by $$$\\frac{u}{d}$$$ where $$$gcd(u,d)=1$$$, you need to output an integer $$$r$$$ satisfying $$$0 \\le r<q$$$ and $$$rd \\equiv u \\pmod q$$$. It can be proved that such $$$r$$$ exists and is unique.", "input_spec": "The first and only line contains three integers $$$n, k, q$$$ ($$$1 \\leq n, k \\leq 10^5, 10^8 \\leq q \\leq 10^9$$$, $$$q$$$ is a prime).", "output_spec": "The first and only line contains an integer $$$r$$$.", "sample_inputs": ["3 1 998244353", "3 2 998244353", "9 3 998244353", "9 4 998244353"], "sample_outputs": ["499122178", "665496236", "449209967", "665496237"], "notes": "NoteIn the first example, all possible permutations are $$$[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]$$$.With $$$k=1$$$, MergeSort(a, 1, n, k) will only return the original permutation. Thus the answer is $$$9/6=3/2$$$, and you should output $$$499122178$$$ because $$$499122178 \\times 2 \\equiv 3 \\pmod {998244353}$$$.In the second example, all possible permutations are $$$[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]$$$ and the corresponding outputs of MergeSort(a, 1, n, k) are $$$[1,2,3],[1,2,3],[2,1,3],[1,2,3],[2,3,1],[1,3,2]$$$ respectively. Thus the answer is $$$4/6=2/3$$$, and you should output $$$665496236$$$ because $$$665496236 \\times 3 \\equiv 2 \\pmod {998244353}$$$."}, "src_uid": "1dd54f5071872e947996ab32b16da19c"} {"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": "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": "This is the easy version of the problem. You can find the hard version in the Div. 1 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.This is an interactive problem.You're considering moving to another city, where one of your friends already lives. There are $$$n$$$ caf\u00e9s in this city, where $$$n$$$ is a power of two. The $$$i$$$-th caf\u00e9 produces a single variety of coffee $$$a_i$$$. As you're a coffee-lover, before deciding to move or not, you want to know the number $$$d$$$ of distinct varieties of coffees produced in this city.You don't know the values $$$a_1, \\ldots, a_n$$$. Fortunately, your friend has a memory of size $$$k$$$, where $$$k$$$ is a power of two.Once per day, you can ask him to taste a cup of coffee produced by the caf\u00e9 $$$c$$$, and he will tell you if he tasted a similar coffee during the last $$$k$$$ days.You can also ask him to take a medication that will reset his memory. He will forget all previous cups of coffee tasted. You can reset his memory at most $$$30\\ 000$$$ times.More formally, the memory of your friend is a queue $$$S$$$. Doing a query on caf\u00e9 $$$c$$$ will: Tell you if $$$a_c$$$ is in $$$S$$$; Add $$$a_c$$$ at the back of $$$S$$$; If $$$|S| > k$$$, pop the front element of $$$S$$$. Doing a reset request will pop all elements out of $$$S$$$.Your friend can taste at most $$$\\dfrac{2n^2}{k}$$$ cups of coffee in total. Find the diversity $$$d$$$ (number of distinct values in the array $$$a$$$).Note that asking your friend to reset his memory does not count towards the number of times you ask your friend to taste a cup of coffee.In some test cases the behavior of the interactor is adaptive. It means that the array $$$a$$$ may be not fixed before the start of the interaction and may depend on your queries. It is guaranteed that at any moment of the interaction, there is at least one array $$$a$$$ consistent with all the answers given so far.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 1024$$$, $$$k$$$ and $$$n$$$ are powers of two). It is guaranteed that $$$\\dfrac{2n^2}{k} \\le 20\\ 000$$$.", "output_spec": null, "sample_inputs": ["4 2\nN\nN\nY\nN\nN\nN\nN", "8 8\nN\nN\nN\nN\nY\nY"], "sample_outputs": ["? 1\n? 2\n? 3\n? 4\nR\n? 4\n? 1\n? 2\n! 3", "? 2\n? 6\n? 4\n? 5\n? 2\n? 5\n! 6"], "notes": "NoteIn the first example, the array is $$$a = [1, 4, 1, 3]$$$. The city produces $$$3$$$ different varieties of coffee ($$$1$$$, $$$3$$$ and $$$4$$$).The successive varieties of coffee tasted by your friend are $$$1, 4, \\textbf{1}, 3, 3, 1, 4$$$ (bold answers correspond to Y answers). Note that between the two ? 4 asks, there is a reset memory request R, so the answer to the second ? 4 ask is N. Had there been no reset memory request, the answer to the second ? 4 ask is Y.In the second example, the array is $$$a = [1, 2, 3, 4, 5, 6, 6, 6]$$$. The city produces $$$6$$$ different varieties of coffee.The successive varieties of coffee tasted by your friend are $$$2, 6, 4, 5, \\textbf{2}, \\textbf{5}$$$."}, "src_uid": "11ad68b4375456733526e74e72606d8d"} {"nl": {"description": "Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges.", "input_spec": "The first line of the input contains the number of cases t (1\u2009\u2264\u2009t\u2009\u2264\u200910). Each of the next t lines contains two natural numbers li and ri (1\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u20099\u2009\u00b71018). 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).", "output_spec": "Output should contain t numbers \u2014 answers to the queries, one number per line \u2014 quantities of beautiful numbers in given intervals (from li to ri, inclusively).", "sample_inputs": ["1\n1 9", "1\n12 15"], "sample_outputs": ["9", "2"], "notes": null}, "src_uid": "37feadce373f728ba2a560b198ca4bc9"} {"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": "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": "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": "SIHanatsuka - EMber SIHanatsuka - ATONEMENTBack in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.One day, Nora's adoptive father, Phoenix Wyle, brought Nora $$$n$$$ boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.She labelled all $$$n$$$ boxes with $$$n$$$ distinct integers $$$a_1, a_2, \\ldots, a_n$$$ and asked ROBO to do the following action several (possibly zero) times: Pick three distinct indices $$$i$$$, $$$j$$$ and $$$k$$$, such that $$$a_i \\mid a_j$$$ and $$$a_i \\mid a_k$$$. In other words, $$$a_i$$$ divides both $$$a_j$$$ and $$$a_k$$$, that is $$$a_j \\bmod a_i = 0$$$, $$$a_k \\bmod a_i = 0$$$. After choosing, Nora will give the $$$k$$$-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty. After doing so, the box $$$k$$$ becomes unavailable for any further actions. Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?As the number of such piles can be very large, you should print the answer modulo $$$10^9 + 7$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$3 \\le n \\le 60$$$), denoting the number of boxes. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 60$$$), where $$$a_i$$$ is the label of the $$$i$$$-th box.", "output_spec": "Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo $$$10^9 + 7$$$.", "sample_inputs": ["3\n2 6 8", "5\n2 3 4 9 12", "4\n5 7 2 9"], "sample_outputs": ["2", "4", "1"], "notes": "NoteLet's illustrate the box pile as a sequence $$$b$$$, with the pile's bottommost box being at the leftmost position.In the first example, there are $$$2$$$ distinct piles possible: $$$b = [6]$$$ ($$$[2, \\mathbf{6}, 8] \\xrightarrow{(1, 3, 2)} [2, 8]$$$) $$$b = [8]$$$ ($$$[2, 6, \\mathbf{8}] \\xrightarrow{(1, 2, 3)} [2, 6]$$$) In the second example, there are $$$4$$$ distinct piles possible: $$$b = [9, 12]$$$ ($$$[2, 3, 4, \\mathbf{9}, 12] \\xrightarrow{(2, 5, 4)} [2, 3, 4, \\mathbf{12}] \\xrightarrow{(1, 3, 4)} [2, 3, 4]$$$) $$$b = [4, 12]$$$ ($$$[2, 3, \\mathbf{4}, 9, 12] \\xrightarrow{(1, 5, 3)} [2, 3, 9, \\mathbf{12}] \\xrightarrow{(2, 3, 4)} [2, 3, 9]$$$) $$$b = [4, 9]$$$ ($$$[2, 3, \\mathbf{4}, 9, 12] \\xrightarrow{(1, 5, 3)} [2, 3, \\mathbf{9}, 12] \\xrightarrow{(2, 4, 3)} [2, 3, 12]$$$) $$$b = [9, 4]$$$ ($$$[2, 3, 4, \\mathbf{9}, 12] \\xrightarrow{(2, 5, 4)} [2, 3, \\mathbf{4}, 12] \\xrightarrow{(1, 4, 3)} [2, 3, 12]$$$) In the third sequence, ROBO can do nothing at all. Therefore, there is only $$$1$$$ valid pile, and that pile is empty."}, "src_uid": "c8d43a60ddc0a7b98a7269dc3a2478dc"} {"nl": {"description": "Doctor prescribed medicine to his patient. The medicine is represented by pills. Each pill consists of a shell and healing powder. The shell consists of two halves; each half has one of four colors \u2014 blue, red, white or yellow.The doctor wants to put 28 pills in a rectangular box 7\u2009\u00d7\u20098 in size. Besides, each pill occupies exactly two neighboring cells and any cell contains exactly one half of a pill. Thus, the result is a four colored picture 7\u2009\u00d7\u20098 in size.The doctor thinks that a patient will recover sooner if the picture made by the pills will be special. Unfortunately, putting the pills in the box so as to get the required picture is not a very easy task. That's why doctor asks you to help. Doctor has some amount of pills of each of 10 painting types. They all contain the same medicine, that's why it doesn't matter which 28 of them will be stored inside the box.Place the pills in the box so that the required picture was formed. If it is impossible to place the pills in the required manner, then place them so that the number of matching colors in all 56 cells in the final arrangement and the doctor's picture were maximum.", "input_spec": "First 7 lines contain the doctor's picture. Each line contains 8 characters, each character can be \"B\", \"R\", \"W\" and \"Y\" that stands for blue, red, white and yellow colors correspondingly. Next four lines contain 10 numbers that stand for, correspondingly, the number of pills painted: \"BY\" \"BW\" \"BR\" \"BB\" \"RY\" \"RW\" \"RR\" \"WY\" \"WW\" \"YY\" Those numbers lie within range from 0 to 28 inclusively. It is guaranteed that the total number of pills in no less than 28.", "output_spec": "Print on the first line the maximal number cells for which the colors match. Then print 13 lines each containing 15 characters \u2014 the pills' position in the optimal arrangement. The intersections of odd lines and odd columns should contain characters \"B\", \"R\", \"W\" and \"Y\". All other positions should contain characters \".\", \"-\" and \"|\". Use \"-\" and \"|\" to show which halves belong to one pill. See the samples for more clarification. If there are several possible solutions, print any of them.", "sample_inputs": ["WWWBBWWW\nWWWBBWWW\nYYWBBWWW\nYYWBBWRR\nYYWBBWRR\nYYWBBWRR\nYYWBBWRR\n0 0 0 8\n0 1 5\n1 10\n5", "WWWWWWWW\nWBYWRBBY\nBRYRBWYY\nWWBRYWBB\nBWWRWBYW\nRBWRBWYY\nWWWWWWWW\n0 0 0 1\n0 0 1\n0 1\n25"], "sample_outputs": ["53\nW.W.W.B.B.W.W.W\n|.|.|.|.|.|.|.|\nW.W.W.B.B.W.W.W\n...............\nY.Y.W.B.B.W.W-W\n|.|.|.|.|.|....\nY.Y.W.B.B.W.R.R\n............|.|\nY.Y.W.B.B.R.R.R\n|.|.|.|.|.|....\nY.Y.W.B.B.W.R.R\n............|.|\nY-Y.B-B.B-B.R.R", "15\nW.Y.Y-Y.Y-Y.Y-Y\n|.|............\nW.Y.Y.Y.Y.B-B.Y\n....|.|.|.....|\nY-Y.Y.Y.Y.Y-Y.Y\n...............\nY.Y.Y.R.Y.Y.Y-Y\n|.|.|.|.|.|....\nY.Y.Y.R.Y.Y.Y.Y\n............|.|\nY-Y.Y.Y-Y.Y.Y.Y\n....|.....|....\nY-Y.Y.Y-Y.Y.Y-Y"], "notes": null}, "src_uid": "cb56e7578ec5e04118993444283ad1eb"} {"nl": {"description": "Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side.Determine a minimal number of wooden bars which are needed to make the frames for two doors. Petya can cut the wooden bars into any parts, but each side of each door should be a solid piece of a wooden bar (or a whole wooden bar).", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091\u2009000) \u2014 the length of each wooden bar. The second line contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u2009n) \u2014 the length of the vertical (left and right) sides of a door frame. The third line contains a single integer b (1\u2009\u2264\u2009b\u2009\u2264\u2009n) \u2014 the length of the upper side of a door frame.", "output_spec": "Print the minimal number of wooden bars with length n which are needed to make the frames for two doors.", "sample_inputs": ["8\n1\n2", "5\n3\n4", "6\n4\n2", "20\n5\n6"], "sample_outputs": ["1", "6", "4", "2"], "notes": "NoteIn the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8.In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed."}, "src_uid": "1a50fe39e18f86adac790093e195979a"} {"nl": {"description": "In the year of 3000 travelling around parallel realities became a routine thing. However one has to take into consideration that travelling like that is highly dangerous as you never know beforehand where you're gonna get...Little Vasya, for instance, found himself in a gaming reality and now he has to successfully complete all levels of a very weird game to get back. The gaming reality is a three-dimensional space where n points are given. The game has m levels and at the beginning of the i-th level the player is positioned at some plane Qi that passes through the origin. On each level Vasya has to use special robots to construct and activate n powerful energy spheres of the equal radius with centers at the given points. The player chooses the radius of the spheres himself. The player has to spend R units of money to construct spheres whose radius equals R (consequently, one can construct spheres whose radius equals zero for free). Besides, once for each level a player can choose any point in space and release a laser ray from there, perpendicular to plane Qi (this action costs nothing). The ray can either be directed towards the plane or from the plane. The spheres that share at least one point with the ray will be immediately activated. The level is considered completed if the player has managed to activate all spheres. Note that the centers of the spheres are the same for all m levels but the spheres do not remain: the player should construct them anew on each new level.Help Vasya find out what minimum sum of money will be enough to complete each level.", "input_spec": "The first line contains two integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u2009900,\u20091\u2009\u2264\u2009m\u2009\u2264\u2009100) \u2014 the number of energetic spheres and the number of levels in the game correspondingly. Each of the following n lines contains three integers xi, yi, zi (0\u2009\u2264\u2009xi,\u2009yi,\u2009zi\u2009\u2264\u2009104) \u2014 the coordinates of the center of the i-th sphere. Assume that these points do not change their positions throughout the game. Then follow m lines, each containing three integers ai, bi, ci (0\u2009\u2264\u2009ai,\u2009bi,\u2009ci\u2009\u2264\u2009100, ai2\u2009+\u2009bi2\u2009+\u2009ci2\u2009>\u20090). These numbers are the coefficients in the equation of plane Qi (aix\u2009+\u2009biy\u2009+\u2009ciz\u2009=\u20090), where the player is positioned at the beginning of the i-th level.", "output_spec": "Print m numbers, one per line: the i-th line should contain the minimum sum of money needed to complete the i-th level. The absolute or relative error should not exceed 10\u2009-\u20096.", "sample_inputs": ["4 1\n0 0 0\n0 1 0\n1 0 0\n1 1 0\n0 0 1", "5 3\n0 1 0\n1 0 1\n1 2 1\n2 0 1\n1 3 0\n1 1 1\n1 2 3\n3 0 3", "2 1\n0 20 0\n0 0 0\n0 10 0"], "sample_outputs": ["0.7071067812", "1.6329931619\n1.6366341768\n1.5411035007", "0.0000000000"], "notes": null}, "src_uid": "25b2a84f0c3f574cdffd59a902b2326e"} {"nl": {"description": "There are $$$n$$$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $$$i-1$$$ and computer $$$i+1$$$ are both on, computer $$$i$$$ $$$(2 \\le i \\le n-1)$$$ will turn on automatically if it is not already on. Note that Phoenix cannot manually turn on a computer that already turned on automatically.If we only consider the sequence of computers that Phoenix turns on manually, how many ways can he turn on all the computers? Two sequences are distinct if either the set of computers turned on manually is distinct, or the order of computers turned on manually is distinct. Since this number may be large, please print it modulo $$$M$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$M$$$ ($$$3 \\le n \\le 400$$$; $$$10^8 \\le M \\le 10^9$$$)\u00a0\u2014 the number of computers and the modulo. It is guaranteed that $$$M$$$ is prime.", "output_spec": "Print one integer\u00a0\u2014 the number of ways to turn on the computers modulo $$$M$$$.", "sample_inputs": ["3 100000007", "4 100000007", "400 234567899"], "sample_outputs": ["6", "20", "20914007"], "notes": "NoteIn the first example, these are the $$$6$$$ orders in which Phoenix can turn on all computers: $$$[1,3]$$$. Turn on computer $$$1$$$, then $$$3$$$. Note that computer $$$2$$$ turns on automatically after computer $$$3$$$ is turned on manually, but we only consider the sequence of computers that are turned on manually. $$$[3,1]$$$. Turn on computer $$$3$$$, then $$$1$$$. $$$[1,2,3]$$$. Turn on computer $$$1$$$, $$$2$$$, then $$$3$$$. $$$[2,1,3]$$$ $$$[2,3,1]$$$ $$$[3,2,1]$$$ "}, "src_uid": "4f0e0d1deef0761a46b64de3eb98e774"} {"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": "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": "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": "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": "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": "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": "Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as \u00ab.\u00bb, 1 as \u00ab-.\u00bb and 2 as \u00ab--\u00bb. You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.", "input_spec": "The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).", "output_spec": "Output the decoded ternary number. It can have leading zeroes.", "sample_inputs": [".-.--", "--.", "-..-.--"], "sample_outputs": ["012", "20", "1012"], "notes": null}, "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"} {"nl": {"description": "Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li,\u2009ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri\u2009-\u2009bi|\u2009\u2264\u20091.Iahub thinks that point x belongs to segment [l,\u2009r], if inequality l\u2009\u2264\u2009x\u2009\u2264\u2009r holds.Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing.", "input_spec": "The first line of input contains two integers: n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) and m (1\u2009\u2264\u2009m\u2009\u2264\u2009100). The next line contains n space-separated integers x1,\u2009x2,\u2009...,\u2009xn (0\u2009\u2264\u2009xi\u2009\u2264\u2009100) \u2014 the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u2009100) \u2014 the borders of the i-th segment. It's guaranteed that all the points are distinct.", "output_spec": "If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.", "sample_inputs": ["3 3\n3 7 14\n1 5\n6 10\n11 15", "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2"], "sample_outputs": ["0 0 0", "1 0 1"], "notes": null}, "src_uid": "692698d4b49ad446984f3a7a631f961d"} {"nl": {"description": "The game of Egg Roulette is played between two players. Initially 2R raw eggs and 2C cooked eggs are placed randomly into a carton. The shells are left on so there is no way to distinguish a raw egg from a cooked egg. One at a time, a player will select an egg, and then smash the egg on his/her forehead. If the egg was cooked, not much happens, but if the egg was raw, it will make quite the mess. This continues until one player has broken R raw eggs, at which point that player is declared the loser and the other player wins.The order in which players take turns can be described as a string of 'A' and 'B' characters, where the i-th character tells which player should choose the i-th egg. Traditionally, players take turns going one after the other. That is, they follow the ordering \"ABABAB...\". This isn't very fair though, because the second player will win more often than the first. We'd like you to find a better ordering for the players to take their turns. Let's define the unfairness of an ordering as the absolute difference between the first player's win probability and the second player's win probability. We're interested in orderings that minimize the unfairness. We only consider an ordering valid if it contains the same number of 'A's as 'B's.You will also be given a string S of length 2(R\u2009+\u2009C) containing only 'A', 'B', and '?' characters. An ordering is said to match S if it only differs from S in positions where S contains a '?'. Of the valid orderings that minimize unfairness, how many match S?", "input_spec": "The first line of input will contain integers R and C (1\u2009\u2264\u2009R,\u2009C\u2009\u2264\u200920,\u2009R\u2009+\u2009C\u2009\u2264\u200930). The second line of input will contain the string S of length 2(R\u2009+\u2009C) consisting only of characters 'A', 'B', '?'.", "output_spec": "Print the number of valid orderings that minimize unfairness and match S.", "sample_inputs": ["1 1\n??BB", "2 4\n?BA??B??A???", "4 14\n????A??BB?????????????AB????????????"], "sample_outputs": ["0", "1", "314"], "notes": "NoteIn the first test case, the minimum unfairness is 0, and the orderings that achieve it are \"ABBA\" and \"BAAB\", neither of which match S. Note that an ordering such as \"ABBB\" would also have an unfairness of 0, but is invalid because it does not contain the same number of 'A's as 'B's.In the second example, the only matching ordering is \"BBAAABABABBA\"."}, "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85"} {"nl": {"description": "Imp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1\u2009\u2264\u2009i\u2009\u2264\u2009k, are distinct, i.\u00a0e. there is no such pair (i,\u2009j) that: 1\u2009\u2264\u2009i\u2009<\u2009j\u2009\u2264\u2009k, , where is the remainder of division x by y. ", "input_spec": "The only line contains two integers n, k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u20091018).", "output_spec": "Print \"Yes\", if all the remainders are distinct, and \"No\" otherwise. You can print each letter in arbitrary case (lower or upper).", "sample_inputs": ["4 4", "5 3"], "sample_outputs": ["No", "Yes"], "notes": "NoteIn the first sample remainders modulo 1 and 4 coincide."}, "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"} {"nl": {"description": "This problem was deleted from the contest, because it was used previously at another competition.", "input_spec": null, "output_spec": null, "sample_inputs": ["1 1\n1 2 100"], "sample_outputs": ["6"], "notes": null}, "src_uid": "2afe29a7dbbd2e261e1870a43d57b46f"} {"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": "A cubeword is a special type of a crossword. When building a cubeword, you start by choosing a positive integer $$$a$$$: the side length of the cube. Then, you build a big cube consisting of $$$a \\times a \\times a$$$ unit cubes. This big cube has 12 edges. Then, you discard all unit cubes that do not touch the edges of the big cube. The figure below shows the object you will get for $$$a=6$$$. Finally, you assign a letter to each of the unit cubes in the object. You must get a meaningful word along each edge of the big cube. Each edge can be read in either direction, and it is sufficient if one of the two directions of reading gives a meaningful word.The figure below shows the object for $$$a=6$$$ in which some unit cubes already have assigned letters. You can already read the words 'SUBMIT', 'ACCEPT' and 'TURING' along three edges of the big cube. You are given a list of valid words. Each word from the wordlist may appear on arbitrarily many edges of a valid cubeword. Find and report the number of different cubewords that can be constructed, modulo $$$998,244,353$$$.If one cubeword can be obtained from another by rotation or mirroring, they are considered distinct.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100,000$$$) \u2013 the number of words. Then, $$$n$$$ lines follow. Each of these lines contains one word that can appear on the edges of the big cube. The length of each word is between 3 and 10, inclusive. It is guaranteed that all words are different.", "output_spec": "Output a single integer, the number of distinct cubewords for the given list of valid words modulo $$$998,244,353$$$.", "sample_inputs": ["1\nradar", "1\nrobot", "2\nFLOW\nWOLF", "2\nbaobab\nbob", "3\nTURING\nSUBMIT\nACCEPT", "3\nMAN1LA\nMAN6OS\nAN4NAS"], "sample_outputs": ["1", "2", "2", "4097", "162", "114"], "notes": "NoteIn the first sample, the only possibility is for the word \"radar\" to be on each edge of the cube.In the second sample, there are two cubes, which are just rotations of each other \u2013 the word \"robot\" is on every edge, and the difference between the two cubes is whether the lower left front corner contains 'r' or 't'.The third sample is similar to the second one. The fact that we can read the word on each edge in both directions does not affect the answer.In the fourth sample, there is one cube with the word \"bob\" on each edge. There are also $$$2^{12} = 4096$$$ cubes with the word \"baobab\" on each edge. (For each of the 12 edges, we have two possible directions in which the word \"baobab\" can appear.)"}, "src_uid": "92ed1015b43f4b610cd7956db8588a9e"} {"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": "Your task is to calculate the number of arrays such that: each array contains $$$n$$$ elements; each element is an integer from $$$1$$$ to $$$m$$$; for each array, there is exactly one pair of equal elements; for each array $$$a$$$, there exists an index $$$i$$$ such that the array is strictly ascending before the $$$i$$$-th element and strictly descending after it (formally, it means that $$$a_j < a_{j + 1}$$$, if $$$j < i$$$, and $$$a_j > a_{j + 1}$$$, if $$$j \\ge i$$$). ", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le m \\le 2 \\cdot 10^5$$$).", "output_spec": "Print one integer \u2014 the number of arrays that meet all of the aforementioned conditions, taken modulo $$$998244353$$$.", "sample_inputs": ["3 4", "3 5", "42 1337", "100000 200000"], "sample_outputs": ["6", "10", "806066790", "707899035"], "notes": "NoteThe arrays in the first example are: $$$[1, 2, 1]$$$; $$$[1, 3, 1]$$$; $$$[1, 4, 1]$$$; $$$[2, 3, 2]$$$; $$$[2, 4, 2]$$$; $$$[3, 4, 3]$$$. "}, "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba"} {"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": "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": "This is the easy version of this problem. The difference between easy and hard versions is the constraint on $$$k$$$ and the time limit. Also, in this version of the problem, you only need to calculate the answer when $$$n=k$$$. You can make hacks only if both versions of the problem are solved.Cirno is playing a war simulator game with $$$n$$$ towers (numbered from $$$1$$$ to $$$n$$$) and $$$n$$$ bots (numbered from $$$1$$$ to $$$n$$$). The $$$i$$$-th tower is initially occupied by the $$$i$$$-th bot for $$$1 \\le i \\le n$$$.Before the game, Cirno first chooses a permutation $$$p = [p_1, p_2, \\ldots, p_n]$$$ of length $$$n$$$ (A permutation of length $$$n$$$ is an array of length $$$n$$$ where each integer between $$$1$$$ and $$$n$$$ appears exactly once). After that, she can choose a sequence $$$a = [a_1, a_2, \\ldots, a_n]$$$ ($$$1 \\le a_i \\le n$$$ and $$$a_i \\ne i$$$ for all $$$1 \\le i \\le n$$$).The game has $$$n$$$ rounds of attacks. In the $$$i$$$-th round, if the $$$p_i$$$-th bot is still in the game, it will begin its attack, and as the result the $$$a_{p_i}$$$-th tower becomes occupied by the $$$p_i$$$-th bot; the bot that previously occupied the $$$a_{p_i}$$$-th tower will no longer occupy it. If the $$$p_i$$$-th bot is not in the game, nothing will happen in this round.After each round, if a bot doesn't occupy any towers, it will be eliminated and leave the game. Please note that no tower can be occupied by more than one bot, but one bot can occupy more than one tower during the game.At the end of the game, Cirno will record the result as a sequence $$$b = [b_1, b_2, \\ldots, b_n]$$$, where $$$b_i$$$ is the number of the bot that occupies the $$$i$$$-th tower at the end of the game.However, as a mathematics master, she wants you to solve the following counting problem instead of playing games:Count the number of different pairs of sequences $$$a$$$ and $$$b$$$ that we can get from all possible choices of sequence $$$a$$$ and permutation $$$p$$$.Since this number may be large, output it modulo $$$M$$$.", "input_spec": "The only line contains two positive integers $$$k$$$ and $$$M$$$ ($$$1\\le k\\le 5000$$$, $$$2\\le M\\le 10^9$$$ ). It is guaranteed that $$$2^{18}$$$ is a divisor of $$$M-1$$$ and $$$M$$$ is a prime number. You need to calculate the answer for $$$n=k$$$.", "output_spec": "Output a single integer \u2014 the number of different pairs of sequences for $$$n=k$$$ modulo $$$M$$$.", "sample_inputs": ["1 998244353", "2 998244353", "3 998244353", "8 998244353"], "sample_outputs": ["0", "2", "24", "123391016"], "notes": "NoteFor $$$n=1$$$, no valid sequence $$$a$$$ exists. We regard the answer as $$$0$$$.For $$$n=2$$$, there is only one possible array $$$a$$$: $$$[2, 1]$$$. For array $$$a$$$ is $$$[2, 1]$$$ and permutation $$$p$$$ is $$$[1, 2]$$$, the sequence $$$b$$$ will be $$$[1, 1]$$$ after all rounds have finished. The details for each rounds: In the first round, the first bot will begin its attack and successfully capture the tower $$$2$$$. After this round, the second bot will be eliminated and leave the game as all of its towers are occupied by other bots. In the second round, the second bot is not in the game. For array $$$a$$$ is $$$[2, 1]$$$ and permutation $$$p$$$ is $$$[2, 1]$$$, the sequence $$$b$$$ will be $$$[2, 2]$$$ after all rounds have finished. The details for each rounds: In the first round, the second bot will begin its attack and successfully capture the tower $$$1$$$. After this round, the first bot will be eliminated and leave the game as all of its towers are occupied by other bots. In the second round, the first bot is not in the game. So the number of different pairs of sequences $$$(a,b)$$$ is $$$2$$$ ($$$[2, 1]$$$, $$$[1, 1]$$$ and $$$[2, 1]$$$, $$$[2, 2]$$$) for $$$n=2$$$."}, "src_uid": "2d5a5055aaf34f4d300cfdf7c21748c3"} {"nl": {"description": "Let's call an array a of size n coprime iff gcd(a1,\u2009a2,\u2009...,\u2009an)\u2009=\u20091, where gcd is the greatest common divisor of the arguments.You are given two numbers n and k. For each i (1\u2009\u2264\u2009i\u2009\u2264\u2009k) you have to determine the number of coprime arrays a of size n such that for every j (1\u2009\u2264\u2009j\u2009\u2264\u2009n) 1\u2009\u2264\u2009aj\u2009\u2264\u2009i. Since the answers can be very large, you have to calculate them modulo 109\u2009+\u20097.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u20092\u00b7106) \u2014 the size of the desired arrays and the maximum upper bound on elements, respectively.", "output_spec": "Since printing 2\u00b7106 numbers may take a lot of time, you have to output the answer in such a way: Let bi be the number of coprime arrays with elements in range [1,\u2009i], taken modulo 109\u2009+\u20097. You have to print , taken modulo 109\u2009+\u20097. Here denotes bitwise xor operation (^ in C++ or Java, xor in Pascal).", "sample_inputs": ["3 4", "2000000 8"], "sample_outputs": ["82", "339310063"], "notes": "NoteExplanation of the example:Since the number of coprime arrays is large, we will list the arrays that are non-coprime, but contain only elements in range [1,\u2009i]:For i\u2009=\u20091, the only array is coprime. b1\u2009=\u20091.For i\u2009=\u20092, array [2,\u20092,\u20092] is not coprime. b2\u2009=\u20097.For i\u2009=\u20093, arrays [2,\u20092,\u20092] and [3,\u20093,\u20093] are not coprime. b3\u2009=\u200925.For i\u2009=\u20094, arrays [2,\u20092,\u20092], [3,\u20093,\u20093], [2,\u20092,\u20094], [2,\u20094,\u20092], [2,\u20094,\u20094], [4,\u20092,\u20092], [4,\u20092,\u20094], [4,\u20094,\u20092] and [4,\u20094,\u20094] are not coprime. b4\u2009=\u200955."}, "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa"} {"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": "Polycarpus is sure that his life fits the description: \"first there is a white stripe, then a black one, then a white one again\". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to take place during each day. As each day is unequivocally characterizes as a part of a white or a black stripe, then each day is going to have events of the same type only (ether good or not-so-good).What is the number of distinct ways this scenario can develop over the next n days if Polycarpus is in for a white stripe (a stripe that has good events only, the stripe's length is at least 1 day), the a black stripe (a stripe that has not-so-good events only, the stripe's length is at least 1 day) and a white stripe again (a stripe that has good events only, the stripe's length is at least 1 day). Each of n days will belong to one of the three stripes only.Note that even the events of the same type are distinct from each other. Even if some events occur on the same day, they go in some order (there are no simultaneous events).Write a code that prints the number of possible configurations to sort the events into days. See the samples for clarifications on which scenarios should be considered distinct. Print the answer modulo 1000000009 (109\u2009+\u20099).", "input_spec": "The single line of the input contains integers n, w and b (3\u2009\u2264\u2009n\u2009\u2264\u20094000, 2\u2009\u2264\u2009w\u2009\u2264\u20094000, 1\u2009\u2264\u2009b\u2009\u2264\u20094000) \u2014 the number of days, the number of good events and the number of not-so-good events. It is guaranteed that w\u2009+\u2009b\u2009\u2265\u2009n.", "output_spec": "Print the required number of ways modulo 1000000009 (109\u2009+\u20099).", "sample_inputs": ["3 2 1", "4 2 2", "3 2 2"], "sample_outputs": ["2", "4", "4"], "notes": "NoteWe'll represent the good events by numbers starting from 1 and the not-so-good events \u2014 by letters starting from 'a'. Vertical lines separate days.In the first sample the possible ways are: \"1|a|2\" and \"2|a|1\". In the second sample the possible ways are: \"1|a|b|2\", \"2|a|b|1\", \"1|b|a|2\" and \"2|b|a|1\". In the third sample the possible ways are: \"1|ab|2\", \"2|ab|1\", \"1|ba|2\" and \"2|ba|1\"."}, "src_uid": "63e93a161bbff623323e66c98d5e20ac"} {"nl": {"description": "A prisoner wants to escape from a prison. The prison is represented by the interior of the convex polygon with vertices $$$P_1, P_2, P_3, \\ldots, P_{n+1}, P_{n+2}, P_{n+3}$$$. It holds $$$P_1=(0,0)$$$, $$$P_{n+1}=(0, h)$$$, $$$P_{n+2}=(-10^{18}, h)$$$ and $$$P_{n+3}=(-10^{18}, 0)$$$. The prison walls $$$P_{n+1}P_{n+2}$$$, $$$P_{n+2}P_{n+3}$$$ and $$$P_{n+3}P_1$$$ are very high and the prisoner is not able to climb them. Hence his only chance is to reach a point on one of the walls $$$P_1P_2, P_2P_3,\\dots, P_{n}P_{n+1}$$$ and escape from there. On the perimeter of the prison, there are two guards. The prisoner moves at speed $$$1$$$ while the guards move, remaining always on the perimeter of the prison, with speed $$$v$$$.If the prisoner reaches a point of the perimeter where there is a guard, the guard kills the prisoner. If the prisoner reaches a point of the part of the perimeter he is able to climb and there is no guard there, he escapes immediately. Initially the prisoner is at the point $$$(-10^{17}, h/2)$$$ and the guards are at $$$P_1$$$. Find the minimum speed $$$v$$$ such that the guards can guarantee that the prisoner will not escape (assuming that both the prisoner and the guards move optimally).Notes: At any moment, the guards and the prisoner can see each other. The \"climbing part\" of the escape takes no time. You may assume that both the prisoner and the guards can change direction and velocity instantly and that they both have perfect reflexes (so they can react instantly to whatever the other one is doing). The two guards can plan ahead how to react to the prisoner movements. ", "input_spec": "The first line of the input contains $$$n$$$ ($$$1 \\le n \\le 50$$$). The following $$$n+1$$$ lines describe $$$P_1, P_2,\\dots, P_{n+1}$$$. The $$$i$$$-th of such lines contain two integers $$$x_i$$$, $$$y_i$$$ ($$$0\\le x_i, y_i\\le 1,000$$$) \u2014 the coordinates of $$$P_i=(x_i, y_i)$$$. It is guaranteed that $$$P_1=(0,0)$$$ and $$$x_{n+1}=0$$$. The polygon with vertices $$$P_1,P_2,\\dots, P_{n+1}, P_{n+2}, P_{n+3}$$$ (where $$$P_{n+2}, P_{n+3}$$$ shall be constructed as described in the statement) is guaranteed to be convex and such that there is no line containing three of its vertices.", "output_spec": "Print a single real number, the minimum speed $$$v$$$ that allows the guards to guarantee that the prisoner will not escape. Your answer will be considered correct if its relative or absolute error does not exceed $$$10^{-6}$$$.", "sample_inputs": ["2\n0 0\n223 464\n0 749", "3\n0 0\n2 2\n2 4\n0 6", "4\n0 0\n7 3\n7 4\n5 7\n0 8", "5\n0 0\n562 248\n460 610\n281 702\n206 723\n0 746", "7\n0 0\n412 36\n745 180\n747 184\n746 268\n611 359\n213 441\n0 450"], "sample_outputs": ["1", "1.0823922", "1.130309669", "1.148649561", "1.134745994"], "notes": null}, "src_uid": "ee115d3f08a53c52db3e429ad0cee906"} {"nl": {"description": "Anna's got a birthday today. She invited many guests and cooked a huge (nearly infinite) birthday cake decorated by n banana circles of different sizes. Maria's birthday is about to start in 7 minutes too, and while Anna is older, she decided to play the boss a little. She told Maria to cut the cake by k straight-line cuts (the cutting lines can intersect) to divide banana circles into banana pieces. Anna has many guests and she wants everyone to get at least one banana piece. That's why she told Maria to make the total number of banana pieces maximum. It's not a problem if some banana pieces end up on the same cake piece \u2014 the key is to make the maximum number of banana pieces. Determine what result Maria will achieve.", "input_spec": "The first line contains two integers n and k \u2014 the number of banana circles and the number of cuts Maria should perform (1\u2009\u2264\u2009n\u2009\u2264\u20091000, 1\u2009\u2264\u2009k\u2009\u2264\u2009105). Next n lines contain the positions and sizes of the banana circles (all banana circles are round). On the cake the Cartesian coordinate system is defined. Each line contains three integers x, y and r \u2014 the coordinates of the center of the corresponding banana piece and its radius (\u2009-\u20091000\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20091000, 1\u2009\u2264\u2009r\u2009\u2264\u20091000). It is guaranteed that the banana circles do not intersect, do not touch each other and do not overlap with each other. Pretest 10 is big test with n\u2009=\u2009k\u2009=\u20091000.", "output_spec": "Print the only integer \u2014 the largest number of banana pieces that Maria can get after she performs the k straight-line cuts. Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.", "sample_inputs": ["1 1\n0 0 1", "3 1\n0 0 1\n3 0 1\n6 0 1", "1 3\n0 0 1"], "sample_outputs": ["2", "6", "7"], "notes": null}, "src_uid": "06ec7e481c963e635a6303503ffccc8b"} {"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": "It can be shown that any positive integer x can be uniquely represented as x\u2009=\u20091\u2009+\u20092\u2009+\u20094\u2009+\u2009...\u2009+\u20092k\u2009-\u20091\u2009+\u2009r, where k and r are integers, k\u2009\u2265\u20090, 0\u2009<\u2009r\u2009\u2264\u20092k. Let's call that representation prairie partition of x.For example, the prairie partitions of 12, 17, 7 and 1 are: 12\u2009=\u20091\u2009+\u20092\u2009+\u20094\u2009+\u20095,17\u2009=\u20091\u2009+\u20092\u2009+\u20094\u2009+\u20098\u2009+\u20092,7\u2009=\u20091\u2009+\u20092\u2009+\u20094,1\u2009=\u20091. Alice took a sequence of positive integers (possibly with repeating elements), replaced every element with the sequence of summands in its prairie partition, arranged the resulting numbers in non-decreasing order and gave them to Borys. Now Borys wonders how many elements Alice's original sequence could contain. Find all possible options!", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105)\u00a0\u2014 the number of numbers given from Alice to Borys. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u20091012; a1\u2009\u2264\u2009a2\u2009\u2264\u2009...\u2009\u2264\u2009an)\u00a0\u2014 the numbers given from Alice to Borys.", "output_spec": "Output, in increasing order, all possible values of m such that there exists a sequence of positive integers of length m such that if you replace every element with the summands in its prairie partition and arrange the resulting numbers in non-decreasing order, you will get the sequence given in the input. If there are no such values of m, output a single integer -1.", "sample_inputs": ["8\n1 1 2 2 3 4 5 8", "6\n1 1 1 2 2 2", "5\n1 2 4 4 4"], "sample_outputs": ["2", "2 3", "-1"], "notes": "NoteIn the first example, Alice could get the input sequence from [6,\u200920] as the original sequence.In the second example, Alice's original sequence could be either [4,\u20095] or [3,\u20093,\u20093]."}, "src_uid": "fc29e8c1a9117c1dd307131d852b6088"} {"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": "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": "Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display). Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.For example if a\u2009=\u20091 and b\u2009=\u20093 then at first the calculator will print 2 segments, then \u2014 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.", "input_spec": "The only line contains two integers a,\u2009b (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009106) \u2014 the first and the last number typed by Max.", "output_spec": "Print the only integer a \u2014 the total number of printed segments.", "sample_inputs": ["1 3", "10 15"], "sample_outputs": ["12", "39"], "notes": null}, "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"nl": {"description": "You are given a rooted tree. Let's denote d(x) as depth of node x: depth of the root is 1, depth of any other node x is d(y)\u2009+\u20091, where y is a parent of x.The tree has the following property: every node x with d(x)\u2009=\u2009i has exactly ai children. Maximum possible depth of a node is n, and an\u2009=\u20090.We define fk as the number of unordered pairs of vertices in the tree such that the number of edges on the simple path between them is equal to k.Calculate fk modulo 109\u2009+\u20097 for every 1\u2009\u2264\u2009k\u2009\u2264\u20092n\u2009-\u20092.", "input_spec": "The first line of input contains an integer n (2\u2009\u2009\u2264\u2009\u2009n\u2009\u2009\u2264\u2009\u20095\u2009000) \u2014 the maximum depth of a node. The second line of input contains n\u2009-\u20091 integers a1,\u2009\u2009a2,\u2009\u2009...,\u2009\u2009an\u2009-\u20091 (2\u2009\u2264\u2009\u2009ai\u2009\u2009\u2264\u2009109), where ai is the number of children of every node x such that d(x)\u2009=\u2009i. Since an\u2009=\u20090, it is not given in the input.", "output_spec": "Print 2n\u2009-\u20092 numbers. The k-th of these numbers must be equal to fk modulo 109\u2009+\u20097.", "sample_inputs": ["4\n2 2 2", "3\n2 3"], "sample_outputs": ["14 19 20 20 16 16", "8 13 6 9"], "notes": "NoteThis the tree from the first sample: "}, "src_uid": "3b86dfd0d077bc857ae3de70f026a409"} {"nl": {"description": "Rainbow built h cells in a row that are numbered from 1 to h from left to right. There are n cells with treasure. We call each of these n cells \"Treasure Cell\". The i-th \"Treasure Cell\" is the ai-th cell and the value of treasure in it is ci dollars.Then, Freda went in the first cell. For now, she can go just k cells forward, or return to the first cell. That means Freda was able to reach the 1st, (k\u2009+\u20091)-th, (2\u00b7k\u2009+\u20091)-th, (3\u00b7k\u2009+\u20091)-th cells and so on.Then Rainbow gave Freda m operations. Each operation is one of the following three types: Add another method x: she can also go just x cells forward at any moment. For example, initially she has only one method k. If at some moment she has methods a1,\u2009a2,\u2009...,\u2009ar then she can reach all the cells with number in form , where vi \u2014 some non-negative integer. Reduce the value of the treasure in the x-th \"Treasure Cell\" by y dollars. In other words, to apply assignment cx\u2009=\u2009cx\u2009-\u2009y. Ask the value of the most valuable treasure among the cells Freda can reach. If Freda cannot reach any cell with the treasure then consider the value of the most valuable treasure equal to 0, and do nothing. Otherwise take the most valuable treasure away. If several \"Treasure Cells\" have the most valuable treasure, take the \"Treasure Cell\" with the minimum number (not necessarily with the minimum number of cell). After that the total number of cells with a treasure is decreased by one. As a programmer, you are asked by Freda to write a program to answer each query.", "input_spec": "The first line of the input contains four integers: h\u00a0(1\u2009\u2264\u2009h\u2009\u2264\u20091018),\u2009n,\u2009m\u00a0(1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105) and k\u00a0(1\u2009\u2264\u2009k\u2009\u2264\u2009104). Each of the next n lines contains two integers: ai\u00a0(1\u2009\u2264\u2009ai\u2009\u2264\u2009h),\u2009ci\u00a0(1\u2009\u2264\u2009ci\u2009\u2264\u2009109). That means the i-th \"Treasure Cell\" is the ai-th cell and cost of the treasure in that cell is ci dollars. All the ai are distinct. Each of the next m lines is in one of the three following formats: \"1 x\" \u2014 an operation of type 1, 1\u2009\u2264\u2009x\u2009\u2264\u2009h; \"2 x y\" \u2014 an operation of type 2, 1\u2009\u2264\u2009x\u2009\u2264\u2009n,\u20090\u2009\u2264\u2009y\u2009<\u2009cx; \"3\" \u2014 an operation of type 3. There are at most 20 operations of type 1. It's guaranteed that at any moment treasure in each cell has positive value. It's guaranteed that all operations is correct (no operation can decrease the value of the taken tresure). Please, do not use the %lld specifier to read 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "For each operation of type 3, output an integer indicates the value (in dollars) of the most valuable treasure among the \"Treasure Cells\" Freda can reach. If there is no such treasure, output 0.", "sample_inputs": ["10 3 5 2\n5 50\n7 60\n8 100\n2 2 5\n3\n1 3\n3\n3"], "sample_outputs": ["55\n100\n50"], "notes": "NoteIn the sample, there are 10 cells and 3 \"Treasure Cells\". The first \"Treasure Cell\" is cell 5, having 50 dollars tresure in it. The second \"Treasure Cell\" is cell 7, having 60 dollars tresure in it. The third \"Treasure Cell\" is cell 8, having 100 dollars tresure in it.At first, Freda can only reach cell 1, 3, 5, 7 and 9. In the first operation, we reduce the value in the second \"Treasure Cell\" from 60 to 55. Then the most valuable treasure among the \"Treasure Cells\" she can reach is max(50, 55) = 55. After the third operation, she can also go 3 cells forward each step, being able to reach cell 1, 3, 4, 5, 6, 7, 8, 9, 10. So the most valuable tresure is 100.Noticed that she took the 55 dollars and 100 dollars treasure away, so the last answer is 50."}, "src_uid": "03c4df4f640633f3364ca9225588caf7"} {"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": "Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.He would like to find a positive integer n not greater than 1018, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms. ", "input_spec": "The first and only line contains an integer k (1\u2009\u2264\u2009k\u2009\u2264\u2009106)\u00a0\u2014 the desired number of loops.", "output_spec": "Output an integer\u00a0\u2014 if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positive decimal integer not exceeding 1018.", "sample_inputs": ["2", "6"], "sample_outputs": ["462", "8080"], "notes": null}, "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"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": "We'll call string s[a,\u2009b]\u2009=\u2009sasa\u2009+\u20091... sb (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009|s|) a substring of string s\u2009=\u2009s1s2... s|s|, where |s| is the length of string s.The trace of a non-empty string t is a set of characters that the string consists of. For example, the trace of string \"aab\" equals {'a', 'b'}.Let's consider an arbitrary string s and the set of its substrings with trace equal to C. We will denote the number of substrings from this set that are maximal by inclusion by r(C,\u2009s). Substring s[a,\u2009b] of length n\u2009=\u2009b\u2009-\u2009a\u2009+\u20091 belonging to some set is called maximal by inclusion, if there is no substring s[x,\u2009y] in this set with length greater than n, such that 1\u2009\u2264\u2009x\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009y\u2009\u2264\u2009|s|. Two substrings of string s are considered different even if they are equal but they are located at different positions of s.Polycarpus got a challenging practical task on a stringology exam. He must do the following: given string s and non-empty sets of characters C1, C2, ..., Cm, find r(Ci,\u2009s) for each set Ci. Help Polycarpus to solve the problem as he really doesn't want to be expelled from the university and go to the army!", "input_spec": "The first line contains a non-empty string s (1\u2009\u2264\u2009|s|\u2009\u2264\u2009106). The second line contains a single integer m (1\u2009\u2264\u2009m\u2009\u2264\u2009104). Next m lines contain descriptions of sets Ci. The i-th line contains string ci such that its trace equals Ci. It is guaranteed that all characters of each string ci are different. Note that Ci are not necessarily different. All given strings consist of lowercase English letters.", "output_spec": "Print m integers \u2014 the i-th integer must equal r(Ci,\u2009s).", "sample_inputs": ["aaaaa\n2\na\na", "abacaba\n3\nac\nba\na"], "sample_outputs": ["1\n1", "1\n2\n4"], "notes": null}, "src_uid": "9bafcd579d38d5c3f073839ccb1c6ed3"} {"nl": {"description": "This is a harder version of the problem. In this version, $$$n \\le 300\\,000$$$.Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believes, that the beauty of the bracket string is a number of its cyclical shifts, which form a correct bracket sequence.To digress from his problems, Vasya decided to select two positions of the string (not necessarily distinct) and swap characters located at this positions with each other. Vasya will apply this operation exactly once. He is curious what is the maximum possible beauty he can achieve this way. Please help him.We remind that bracket sequence $$$s$$$ is called correct if: $$$s$$$ is empty; $$$s$$$ is equal to \"($$$t$$$)\", where $$$t$$$ is correct bracket sequence; $$$s$$$ is equal to $$$t_1 t_2$$$, i.e. concatenation of $$$t_1$$$ and $$$t_2$$$, where $$$t_1$$$ and $$$t_2$$$ are correct bracket sequences. For example, \"(()())\", \"()\" are correct, while \")(\" and \"())\" are not.The cyclical shift of the string $$$s$$$ of length $$$n$$$ by $$$k$$$ ($$$0 \\leq k < n$$$) is a string formed by a concatenation of the last $$$k$$$ symbols of the string $$$s$$$ with the first $$$n - k$$$ symbols of string $$$s$$$. For example, the cyclical shift of string \"(())()\" by $$$2$$$ equals \"()(())\".Cyclical shifts $$$i$$$ and $$$j$$$ are considered different, if $$$i \\ne j$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 300\\,000$$$), the length of the string. The second line contains a string, consisting of exactly $$$n$$$ characters, where each of the characters is either \"(\" or \")\".", "output_spec": "The first line should contain a single integer\u00a0\u2014 the largest beauty of the string, which can be achieved by swapping some two characters. The second line should contain integers $$$l$$$ and $$$r$$$ ($$$1 \\leq l, r \\leq n$$$)\u00a0\u2014 the indices of two characters, which should be swapped in order to maximize the string's beauty. In case there are several possible swaps, print any of them.", "sample_inputs": ["10\n()()())(()", "12\n)(()(()())()", "6\n)))(()"], "sample_outputs": ["5\n8 7", "4\n5 10", "0\n1 1"], "notes": "NoteIn the first example, we can swap $$$7$$$-th and $$$8$$$-th character, obtaining a string \"()()()()()\". The cyclical shifts by $$$0, 2, 4, 6, 8$$$ of this string form a correct bracket sequence.In the second example, after swapping $$$5$$$-th and $$$10$$$-th character, we obtain a string \")(())()()(()\". The cyclical shifts by $$$11, 7, 5, 3$$$ of this string form a correct bracket sequence.In the third example, swap of any two brackets results in $$$0$$$ cyclical shifts being correct bracket sequences. "}, "src_uid": "be820239276b5e1a346309f9dd21c5cb"} {"nl": {"description": "InputThe only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive.OutputOutput \"Yes\" or \"No\".ExamplesInput373OutputYesInput121OutputNoInput436OutputYes", "input_spec": "The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive.", "output_spec": "Output \"Yes\" or \"No\".", "sample_inputs": ["373", "121", "436"], "sample_outputs": ["Yes", "No", "Yes"], "notes": null}, "src_uid": "0f11f41cefd7cf43f498e511405426c3"} {"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": "The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier.Future students will be asked just a single question. They are given a sequence of integer numbers $$$a_1, a_2, \\dots, a_n$$$, each number is from $$$1$$$ to $$$3$$$ and $$$a_i \\ne a_{i + 1}$$$ for each valid $$$i$$$. The $$$i$$$-th number represents a type of the $$$i$$$-th figure: circle; isosceles triangle with the length of height equal to the length of base; square. The figures of the given sequence are placed somewhere on a Cartesian plane in such a way that: $$$(i + 1)$$$-th figure is inscribed into the $$$i$$$-th one; each triangle base is parallel to OX; the triangle is oriented in such a way that the vertex opposite to its base is at the top; each square sides are parallel to the axes; for each $$$i$$$ from $$$2$$$ to $$$n$$$ figure $$$i$$$ has the maximum possible length of side for triangle and square and maximum radius for circle. Note that the construction is unique for some fixed position and size of just the first figure.The task is to calculate the number of distinct points (not necessarily with integer coordinates) where figures touch. The trick is, however, that the number is sometimes infinite. But that won't make the task difficult for you, will it?So can you pass the math test and enroll into Berland State University?", "input_spec": "The first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of figures. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 3$$$, $$$a_i \\ne a_{i + 1}$$$) \u2014 types of the figures.", "output_spec": "The first line should contain either the word \"Infinite\" if the number of distinct points where figures touch is infinite or \"Finite\" otherwise. If the number is finite than print it in the second line. It's guaranteed that the number fits into 32-bit integer type.", "sample_inputs": ["3\n2 1 3", "3\n1 2 3"], "sample_outputs": ["Finite\n7", "Infinite"], "notes": "NoteHere are the glorious pictures for the examples. Note that the triangle is not equilateral but just isosceles with the length of height equal to the length of base. Thus it fits into a square in a unique way.The distinct points where figures touch are marked red.In the second example the triangle and the square touch each other for the whole segment, it contains infinite number of points. "}, "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"nl": {"description": "We have a magic tree: a rooted tree on $$$n$$$ vertices. The vertices are numbered $$$1$$$ through $$$n$$$. Vertex $$$1$$$ is the root.The magic tree gives us magic fruit. The fruit only grows in vertices of the tree other than the root. Each vertex contains at most one piece of fruit.It is now day 0 and no fruit is ripe yet. Each fruit will only be ripe for a single day. For each fruit, we are given the vertex $$$v_j$$$ where it grows, the day $$$d_j$$$ on which it will be ripe, and the amount $$$w_j$$$ of magic juice we can extract from it if we harvest it when it is ripe.The fruits have to be harvested by cutting some branches of the tree. On each day, you may cut as many branches of the tree as you like. The parts of the tree you cut off will fall to the ground and you can collect all the ripe fruits they contain. All fruits that fall to the ground when they are not ripe are discarded and no magic juice is collected from them.Formally, on each day, you may erase some edges of the tree. Whenever you do so, the tree will split into multiple connected components. You then erase all components that do not contain the root and you harvest all ripe fruits those components contained.Given is a description of the tree together with the locations, ripening days and juiciness of all $$$m$$$ fruits. Calculate the maximum total amount of magic juice we can harvest from the tree.", "input_spec": "The first line contains three space-separated integers $$$n$$$ ($$$2 \\le n \\le 100,000$$$), $$$m$$$ ($$$1 \\le m \\le n-1$$$) and $$$k$$$ ($$$1 \\le k \\le 100,000$$$) \u2013 the number of vertices, the number of fruits, and the maximum day on which a fruit may become ripe. The following $$$n-1$$$ lines contain the integers $$$p_2, \\dots, p_n$$$, one per line. For each $$$i$$$ (from $$$2$$$ to $$$n$$$, inclusive), vertex $$$p_i$$$ ($$$1 \\leq p_i \\le i-1$$$) is the parent of vertex $$$i$$$. Each of the last $$$m$$$ lines describes one fruit. The $$$j$$$-th of these lines has the form \"$$$v_j\\ d_j\\ w_j$$$\" ($$$2 \\le v_j \\le n$$$, $$$1 \\le d_j \\le k$$$, $$$1 \\le w_j \\le 10^9$$$). It is guaranteed that no vertex contains more than one fruit (i.e., the values $$$v_j$$$ are distinct).", "output_spec": "Output a single line with a single integer, the maximum amount of magic juice we can harvest from the tree.", "sample_inputs": ["6 4 10\n1\n2\n1\n4\n4\n3 4 5\n4 7 2\n5 4 1\n6 9 3"], "sample_outputs": ["9"], "notes": "NoteIn the example input, one optimal solution looks as follows: On day 4, cut the edge between vertices 4 and 5 and harvest a ripe fruit with 1 unit of magic juice. On the same day, cut the edge between vertices 1 and 2 and harvest 5 units of magic juice from the ripe fruit in vertex 3. On day 7, do nothing. (We could harvest the fruit in vertex 4 that just became ripe, but doing so is not optimal.) On day 9, cut the edge between vertices 1 and 4. Discard the fruit in vertex 4 that is no longer ripe, and harvest 3 units of magic juice from the ripe fruit in vertex 6. (Alternately, we could achieve the same effect by cutting the edge between vertices 4 and 6.) "}, "src_uid": "d471aeb3d5b496b4d7a5cd2628574853"} {"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.Let next(x) be the minimum lucky number which is larger than or equals x. Petya is interested what is the value of the expression next(l)\u2009+\u2009next(l\u2009+\u20091)\u2009+\u2009...\u2009+\u2009next(r\u2009-\u20091)\u2009+\u2009next(r). Help him solve this problem.", "input_spec": "The single line contains two integers l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109) \u2014 the left and right interval limits.", "output_spec": "In the single line print the only number \u2014 the sum next(l)\u2009+\u2009next(l\u2009+\u20091)\u2009+\u2009...\u2009+\u2009next(r\u2009-\u20091)\u2009+\u2009next(r). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.", "sample_inputs": ["2 7", "7 7"], "sample_outputs": ["33", "7"], "notes": "NoteIn the first sample: next(2)\u2009+\u2009next(3)\u2009+\u2009next(4)\u2009+\u2009next(5)\u2009+\u2009next(6)\u2009+\u2009next(7)\u2009=\u20094\u2009+\u20094\u2009+\u20094\u2009+\u20097\u2009+\u20097\u2009+\u20097\u2009=\u200933In the second sample: next(7)\u2009=\u20097"}, "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd"} {"nl": {"description": "Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475\u2009=\u20091\u00b7162\u2009+\u200913\u00b7161\u2009+\u200911\u00b7160). Alexander lived calmly until he tried to convert the number back to the decimal number system.Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.", "input_spec": "The first line contains the integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009109). The second line contains the integer k (0\u2009\u2264\u2009k\u2009<\u20091060), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n. Alexander guarantees that the answer exists and does not exceed 1018. The number k doesn't contain leading zeros.", "output_spec": "Print the number x (0\u2009\u2264\u2009x\u2009\u2264\u20091018)\u00a0\u2014 the answer to the problem.", "sample_inputs": ["13\n12", "16\n11311", "20\n999", "17\n2016"], "sample_outputs": ["12", "475", "3789", "594"], "notes": "NoteIn the first example 12 could be obtained by converting two numbers to the system with base 13: 12\u2009=\u200912\u00b7130 or 15\u2009=\u20091\u00b7131\u2009+\u20092\u00b7130."}, "src_uid": "be66399c558c96566a6bb0a63d2503e5"} {"nl": {"description": "Hibiki and Dita are in love with each other, but belong to communities that are in a long lasting conflict. Hibiki is deeply concerned with the state of affairs, and wants to figure out if his relationship with Dita is an act of love or an act of treason. Hibiki prepared several binary features his decision will depend on, and built a three layer logical circuit on top of them, each layer consisting of one or more logic gates. Each gate in the circuit is either \"or\", \"and\", \"nor\" (not or) or \"nand\" (not and). Each gate in the first layer is connected to exactly two features. Each gate in the second layer is connected to exactly two gates in the first layer. The third layer has only one \"or\" gate, which is connected to all the gates in the second layer (in other words, the entire circuit produces 1 if and only if at least one gate in the second layer produces 1).The problem is, Hibiki knows very well that when the person is in love, his ability to think logically degrades drastically. In particular, it is well known that when a person in love evaluates a logical circuit in his mind, every gate evaluates to a value that is the opposite of what it was supposed to evaluate to. For example, \"or\" gates return 1 if and only if both inputs are zero, \"t{nand}\" gates produce 1 if and only if both inputs are one etc.In particular, the \"or\" gate in the last layer also produces opposite results, and as such if Hibiki is in love, the entire circuit produces 1 if and only if all the gates on the second layer produced 0.Hibiki can\u2019t allow love to affect his decision. He wants to know what is the smallest number of gates that needs to be removed from the second layer so that the output of the circuit for all possible inputs doesn't depend on whether Hibiki is in love or not.", "input_spec": "The first line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$2 \\le n, m \\le 50$$$; $$$1 \\le k \\le 50$$$) \u2014 the number of input features, the number of gates in the first layer, and the number of gates in the second layer correspondingly. The second line contains $$$m$$$ pairs of strings separated by spaces describing the first layer. The first string in each pair describes the gate (\"and\", \"or\", \"nand\" or \"nor\"), and the second string describes the two input features the gate is connected two as a string consisting of exactly $$$n$$$ characters, with exactly two characters (that correspond to the input features the gate is connected to) equal to 'x' and the remaining characters equal to \".'. The third line contains $$$k$$$ pairs of strings separated by spaces describing the second layer in the same format, where the strings that describe the input parameters have length $$$m$$$ and correspond to the gates of the first layer.", "output_spec": "Print the number of gates that need to be removed from the second layer so that the output of the remaining circuit doesn't depend on whether Hibiki is in love or not. If no matter how many gates are removed the output of the circuit continues to depend on Hibiki's feelings, print $$$-1$$$.", "sample_inputs": ["2 2 2\nand xx nand xx\nand xx or xx", "3 2 2\nand xx. nor .xx\nand xx nor xx", "4 4 5\nnor x..x and ..xx and xx.. nand xx..\nnand ..xx nor ..xx and xx.. nor ..xx or ..xx"], "sample_outputs": ["1", "-1", "2"], "notes": "NoteIn the first example the two gates in the first layer are connected to the same inputs, but first computes \"and\" while second computes \"nand\", and as such their output is always different no matter what the input is and whether Hibiki is in love or not. The second layer has \"or\" and \"and\" gates both connected to the two gates in the first layer. If Hibiki is not in love, the \"and\" gate will produce 0 and the \"or\" gate will produce 1 no matter what input features are equal to, with the final \"or\" gate in the third layer always producing the final answer of 1. If Hibiki is in love, \"and\" gate in the second layer will produce 1 and \"or\" gate will produce 0 no matter what the input is, with the final \"or\" gate in the third layer producing the final answer of 0. Thus, if both gates in the second layer are kept, the output of the circuit does depend on whether Hibiki is in love. If any of the two gates in the second layer is dropped, the output of the circuit will no longer depend on whether Hibiki is in love or not, and hence the answer is 1.In the second example no matter what gates are left in the second layer, the output of the circuit will depend on whether Hibiki is in love or not.In the third example if Hibiki keeps second, third and fourth gates in the second layer, the circuit will not depend on whether Hibiki is in love or not. Alternatively, he can keep the first and the last gates. The former requires removing two gates, the latter requires removing three gates, so the former is better, and the answer is 2."}, "src_uid": "2f80021e297dd57e306d2a50c3590bea"} {"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": "Jabber ID on the national Berland service \u00abBabber\u00bb has a form <username>@<hostname>[/resource], where <username> \u2014 is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters \u00ab_\u00bb, the length of <username> is between 1 and 16, inclusive. <hostname> \u2014 is a sequence of word separated by periods (characters \u00ab.\u00bb), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive. <resource> \u2014 is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters \u00ab_\u00bb, the length of <resource> is between 1 and 16, inclusive. The content of square brackets is optional \u2014 it can be present or can be absent.There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.Your task is to write program which checks if given string is a correct Jabber ID.", "input_spec": "The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.", "output_spec": "Print YES or NO.", "sample_inputs": ["mike@codeforces.com", "john.smith@codeforces.ru/contest.icpc/12"], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "2a68157e327f92415067f127feb31e24"} {"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": "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": "Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple actions)?", "input_spec": "The first line of the input contains three integers a, b and c (0\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20091\u2009000\u2009000)\u00a0\u2014 the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, x, y and z (0\u2009\u2264\u2009x,\u2009y,\u2009z\u2009\u2264\u20091\u2009000\u2009000)\u00a0\u2014 the number of blue, violet and orange spheres that he needs to get.", "output_spec": "If the wizard is able to obtain the required numbers of spheres, print \"Yes\". Otherwise, print \"No\".", "sample_inputs": ["4 4 0\n2 1 2", "5 6 1\n2 7 2", "3 3 3\n2 2 2"], "sample_outputs": ["Yes", "No", "Yes"], "notes": "NoteIn the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs."}, "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"} {"nl": {"description": "There is a chess tournament in All-Right-City. n players were invited to take part in the competition. The tournament is held by the following rules: Initially, each player plays one game with every other player. There are no ties; After that, the organizers build a complete directed graph with players as vertices. For every pair of players there is exactly one directed edge between them: the winner of their game is the startpoint of this edge and the loser is the endpoint; After that, the organizers build a condensation of this graph. The condensation of this graph is an acyclic complete graph, therefore it has the only Hamiltonian path which consists of strongly connected components of initial graph A1\u2009\u2192\u2009A2\u2009\u2192\u2009...\u2009\u2192\u2009Ak. The players from the first component A1 are placed on the first places, the players from the component A2 are placed on the next places, and so on. To determine exact place of each player in a strongly connected component, all the procedures from 1 to 5 are repeated recursively inside each component, i.e. for every i\u2009=\u20091,\u20092,\u2009...,\u2009k players from the component Ai play games with each other again, and so on; If a component consists of a single player, then he has no more rivals, his place is already determined and the process stops. The players are enumerated with integers from 1 to n. The enumeration was made using results of a previous tournament. It is known that player i wins player j (i\u2009<\u2009j) with probability p.You need to help to organize the tournament. Find the expected value of total number of games played by all the players. It can be shown that the answer can be represented as , where P and Q are coprime integers and . Print the value of P\u00b7Q\u2009-\u20091 modulo 998244353.If you are not familiar with any of the terms above, you can read about them here.", "input_spec": "The first line of input contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u20092000)\u00a0\u2014 the number of players. The second line contains two integers a and b (1\u2009\u2264\u2009a\u2009<\u2009b\u2009\u2264\u2009100)\u00a0\u2014 the numerator and the denominator of fraction .", "output_spec": "In the only line print the expected value of total number of games played by all the players. Print the answer using the format above.", "sample_inputs": ["3\n1 2", "3\n4 6", "4\n1 2"], "sample_outputs": ["4", "142606340", "598946623"], "notes": "NoteIn the first example the expected value is 4.In the second example the expected value is .In the third example the expected value is ."}, "src_uid": "67e599530203060c17f692f2624d0f99"} {"nl": {"description": "Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x\u2009=\u20094, and y\u2009=\u20097, then numbers 47, 744, 4 are lucky.Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20099), that the decimal representation of number a (without leading zeroes) contains only digits x and y.Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 Polycarpus's number.", "output_spec": "Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.", "sample_inputs": ["10", "123"], "sample_outputs": ["10", "113"], "notes": "NoteIn the first test sample all numbers that do not exceed 10 are undoubtedly lucky.In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky."}, "src_uid": "0f7f10557602c8c2f2eb80762709ffc4"} {"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": "The leader of some very secretive organization has decided to invite all other members to a meeting. All members of the organization live in the same town which can be represented as $$$n$$$ crossroads connected by $$$m$$$ two-directional streets. The meeting will be held in the leader's house near the crossroad $$$1$$$. There are $$$k$$$ members of the organization invited to the meeting; $$$i$$$-th of them lives near the crossroad $$$a_i$$$. All members of the organization receive the message about the meeting at the same moment and start moving to the location where the meeting is held. In the beginning of each minute each person is located at some crossroad. He or she can either wait a minute at this crossroad, or spend a minute to walk from the current crossroad along some street to another crossroad (obviously, it is possible to start walking along the street only if it begins or ends at the current crossroad). In the beginning of the first minute each person is at the crossroad where he or she lives. As soon as a person reaches the crossroad number $$$1$$$, he or she immediately comes to the leader's house and attends the meeting.Obviously, the leader wants all other members of the organization to come up as early as possible. But, since the organization is very secretive, the leader does not want to attract much attention. Let's denote the discontent of the leader as follows initially the discontent is $$$0$$$; whenever a person reaches the crossroad number $$$1$$$, the discontent of the leader increases by $$$c \\cdot x$$$, where $$$c$$$ is some fixed constant, and $$$x$$$ is the number of minutes it took the person to reach the crossroad number $$$1$$$; whenever $$$x$$$ members of the organization walk along the same street at the same moment in the same direction, $$$dx^2$$$ is added to the discontent, where $$$d$$$ is some fixed constant. This is not cumulative: for example, if two persons are walking along the same street in the same direction at the same moment, then $$$4d$$$ is added to the discontent, not $$$5d$$$. Before sending a message about the meeting, the leader can tell each member of the organization which path they should choose and where they should wait. Help the leader to establish a plan for every member of the organization so they all reach the crossroad $$$1$$$, and the discontent is minimized.", "input_spec": "The first line of the input contains five integer numbers $$$n$$$, $$$m$$$, $$$k$$$, $$$c$$$ and $$$d$$$ ($$$2 \\le n \\le 50$$$, $$$n - 1 \\le m \\le 50$$$, $$$1 \\le k, c, d \\le 50$$$) \u2014 the number of crossroads, the number of streets, the number of persons invited to the meeting and the constants affecting the discontent, respectively. The second line contains $$$k$$$ numbers $$$a_1$$$, $$$a_2$$$, ..., $$$a_k$$$ ($$$2 \\le a_i \\le n$$$) \u2014 the crossroads where the members of the organization live. Then $$$m$$$ lines follow, each denoting a bidirectional street. Each line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \\le x_i, y_i \\le n$$$, $$$x_i \\ne y_i$$$) denoting a street connecting crossroads $$$x_i$$$ and $$$y_i$$$. There may be multiple streets connecting the same pair of crossroads. It is guaranteed that every crossroad can be reached from every other crossroad using the given streets. ", "output_spec": "Print one integer: the minimum discontent of the leader after everyone reaches crossroad $$$1$$$.", "sample_inputs": ["3 2 4 2 3\n3 3 3 3\n1 2\n2 3", "3 3 4 2 3\n3 2 2 3\n1 2\n2 3\n2 3"], "sample_outputs": ["52", "38"], "notes": "NoteThe best course of action in the first test is the following: the first person goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting; the second person waits one minute on the crossroad $$$3$$$, then goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting; the third person waits two minutes on the crossroad $$$3$$$, then goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting; the fourth person waits three minutes on the crossroad $$$3$$$, then goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting. "}, "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c"} {"nl": {"description": "Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens.All characters in this game are lowercase English letters. There are two players: Mister B and his competitor.Initially the players have a string s consisting of the first a English letters in alphabetical order (for example, if a\u2009=\u20095, then s equals to \"abcde\").The players take turns appending letters to string s. Mister B moves first.Mister B must append exactly b letters on each his move. He can arbitrary choose these letters. His opponent adds exactly a letters on each move.Mister B quickly understood that his opponent was just a computer that used a simple algorithm. The computer on each turn considers the suffix of string s of length a and generates a string t of length a such that all letters in the string t are distinct and don't appear in the considered suffix. From multiple variants of t lexicographically minimal is chosen (if a\u2009=\u20094 and the suffix is \"bfdd\", the computer chooses string t equal to \"aceg\"). After that the chosen string t is appended to the end of s.Mister B soon found the game boring and came up with the following question: what can be the minimum possible number of different letters in string s on the segment between positions l and r, inclusive. Letters of string s are numerated starting from 1.", "input_spec": "First and only line contains four space-separated integers: a, b, l and r (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u200912, 1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109) \u2014 the numbers of letters each player appends and the bounds of the segment.", "output_spec": "Print one integer \u2014 the minimum possible number of different letters in the segment from position l to position r, inclusive, in string s.", "sample_inputs": ["1 1 1 8", "4 2 2 6", "3 7 4 6"], "sample_outputs": ["2", "3", "1"], "notes": "NoteIn the first sample test one of optimal strategies generate string s\u2009=\u2009\"abababab...\", that's why answer is 2.In the second sample test string s\u2009=\u2009\"abcdbcaefg...\" can be obtained, chosen segment will look like \"bcdbc\", that's why answer is 3.In the third sample test string s\u2009=\u2009\"abczzzacad...\" can be obtained, chosen, segment will look like \"zzz\", that's why answer is 1."}, "src_uid": "d055b2a594ae7788ecafb3ef80f246ec"} {"nl": {"description": "You are given $$$n$$$ non-decreasing arrays of non-negative numbers. Vasya repeats the following operation $$$k$$$ times: Selects a non-empty array. Puts the first element of the selected array in his pocket. Removes the first element from the selected array. Vasya wants to maximize the sum of the elements in his pocket.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 3\\,000$$$): the number of arrays and operations. Each of the next $$$n$$$ lines contain an array. The first integer in each line is $$$t_i$$$ ($$$1 \\le t_i \\le 10^6$$$): the size of the $$$i$$$-th array. The following $$$t_i$$$ integers $$$a_{i, j}$$$ ($$$0 \\le a_{i, 1} \\le \\ldots \\le a_{i, t_i} \\le 10^8$$$) are the elements of the $$$i$$$-th array. It is guaranteed that $$$k \\le \\sum\\limits_{i=1}^n t_i \\le 10^6$$$.", "output_spec": "Print one integer: the maximum possible sum of all elements in Vasya's pocket after $$$k$$$ operations.", "sample_inputs": ["3 3\n2 5 10\n3 1 2 3\n2 1 20"], "sample_outputs": ["26"], "notes": null}, "src_uid": "9e9d4f58ebd8293025ab8004aeb8d343"} {"nl": {"description": "Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $$$a$$$ and screen height not greater than $$$b$$$. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is $$$w$$$, and the height of the screen is $$$h$$$, then the following condition should be met: $$$\\frac{w}{h} = \\frac{x}{y}$$$.There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers $$$w$$$ and $$$h$$$ there is a TV set with screen width $$$w$$$ and height $$$h$$$ in the shop.Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers $$$w$$$ and $$$h$$$, beforehand, such that $$$(w \\le a)$$$, $$$(h \\le b)$$$ and $$$(\\frac{w}{h} = \\frac{x}{y})$$$.In other words, Monocarp wants to determine the number of TV sets having aspect ratio $$$\\frac{x}{y}$$$, screen width not exceeding $$$a$$$, and screen height not exceeding $$$b$$$. Two TV sets are considered different if they have different screen width or different screen height.", "input_spec": "The first line contains four integers $$$a$$$, $$$b$$$, $$$x$$$, $$$y$$$ ($$$1 \\le a, b, x, y \\le 10^{18}$$$)\u00a0\u2014 the constraints on the screen width and height, and on the aspect ratio.", "output_spec": "Print one integer\u00a0\u2014 the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.", "sample_inputs": ["17 15 5 3", "14 16 7 22", "4 2 6 4", "1000000000000000000 1000000000000000000 999999866000004473 999999822000007597"], "sample_outputs": ["3", "0", "1", "1000000063"], "notes": "NoteIn the first example, there are $$$3$$$ possible variants: $$$(5, 3)$$$, $$$(10, 6)$$$, $$$(15, 9)$$$.In the second example, there is no TV set meeting the constraints.In the third example, there is only one variant: $$$(3, 2)$$$."}, "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"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": null, "input_spec": null, "output_spec": null, "sample_inputs": [], "sample_outputs": [], "notes": null}, "src_uid": "b6a30a725754a4b4daeb6e87986e28a4"} {"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": "Some country is populated by wizards. They want to organize a demonstration.There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n\u2009-\u2009x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people.", "input_spec": "The first line contains three space-separated integers, n, x, y (1\u2009\u2264\u2009n,\u2009x,\u2009y\u2009\u2264\u2009104,\u2009x\u2009\u2264\u2009n) \u2014 the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (\u2009>\u2009n).", "output_spec": "Print a single integer \u2014 the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). ", "sample_inputs": ["10 1 14", "20 10 50", "1000 352 146"], "sample_outputs": ["1", "0", "1108"], "notes": "NoteIn the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones."}, "src_uid": "7038d7b31e1900588da8b61b325e4299"} {"nl": {"description": "You are working for the Gryzzl company, headquartered in Pawnee, Indiana.The new national park has been opened near Pawnee recently and you are to implement a geolocation system, so people won't get lost. The concept you developed is innovative and minimalistic. There will be $$$n$$$ antennas located somewhere in the park. When someone would like to know their current location, their Gryzzl hologram phone will communicate with antennas and obtain distances from a user's current location to all antennas.Knowing those distances and antennas locations it should be easy to recover a user's location... Right? Well, almost. The only issue is that there is no way to distinguish antennas, so you don't know, which distance corresponds to each antenna. Your task is to find a user's location given as little as all antennas location and an unordered multiset of distances.", "input_spec": "The first line of input contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 10^5$$$) which is the number of antennas. The following $$$n$$$ lines contain coordinates of antennas, $$$i$$$-th line contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \\leq x_i,y_i \\leq 10^8$$$). It is guaranteed that no two antennas coincide. The next line of input contains integer $$$m$$$ ($$$1 \\leq n \\cdot m \\leq 10^5$$$), which is the number of queries to determine the location of the user. Following $$$m$$$ lines contain $$$n$$$ integers $$$0 \\leq d_1 \\leq d_2 \\leq \\dots \\leq d_n \\leq 2 \\cdot 10^{16}$$$ each. These integers form a multiset of squared distances from unknown user's location $$$(x;y)$$$ to antennas. For all test cases except the examples it is guaranteed that all user's locations $$$(x;y)$$$ were chosen uniformly at random, independently from each other among all possible integer locations having $$$0 \\leq x, y \\leq 10^8$$$.", "output_spec": "For each query output $$$k$$$, the number of possible a user's locations matching the given input and then output the list of these locations in lexicographic order. It is guaranteed that the sum of all $$$k$$$ over all points does not exceed $$$10^6$$$.", "sample_inputs": ["3\n0 0\n0 1\n1 0\n1\n1 1 2", "4\n0 0\n0 1\n1 0\n1 1\n2\n0 1 1 2\n2 5 5 8"], "sample_outputs": ["1 1 1", "4 0 0 0 1 1 0 1 1 \n4 -1 -1 -1 2 2 -1 2 2"], "notes": "NoteAs you see in the second example, although initially a user's location is picked to have non-negative coordinates, you have to output all possible integer locations."}, "src_uid": "057fdc41579d2e070fb7ea2ebeecb0fa"} {"nl": {"description": "You are given integers $$$n$$$, $$$k$$$. Let's consider the alphabet consisting of $$$k$$$ different elements.Let beauty $$$f(s)$$$ of the string $$$s$$$ be the number of indexes $$$i$$$, $$$1\\le i<|s|$$$, for which prefix of $$$s$$$ of length $$$i$$$ equals to suffix of $$$s$$$ of length $$$i$$$. For example, beauty of the string $$$abacaba$$$ equals $$$2$$$, as for $$$i = 1, 3$$$ prefix and suffix of length $$$i$$$ are equal.Consider all words of length $$$n$$$ in the given alphabet. Find the expected value of $$$f(s)^2$$$ of a uniformly chosen at random word. We can show that it can be expressed as $$$\\frac{P}{Q}$$$, where $$$P$$$ and $$$Q$$$ are coprime and $$$Q$$$ isn't divided by $$$10^9 + 7$$$. Output $$$P\\cdot Q^{-1} \\bmod 10^9 + 7$$$.", "input_spec": "The first and the only line contains two integers $$$n$$$, $$$k$$$ ($$$1\\le n \\le 10^5$$$, $$$1\\le k\\le 10^9$$$)\u00a0\u2014 the length of a string and the size of alphabet respectively.", "output_spec": "Output a single integer\u00a0\u2014 $$$P\\times Q^{-1} \\bmod 10^9 + 7$$$.", "sample_inputs": ["2 3", "1 5", "100 1", "10 10"], "sample_outputs": ["333333336", "0", "9801", "412377396"], "notes": "NoteIn the first example, there are $$$9$$$ words of length $$$2$$$ in alphabet of size $$$3$$$\u00a0\u2014 $$$aa$$$, $$$ab$$$, $$$ac$$$, $$$ba$$$, $$$bb$$$, $$$bc$$$, $$$ca$$$, $$$cb$$$, $$$cc$$$. $$$3$$$ of them have beauty $$$1$$$ and $$$6$$$ of them have beauty $$$0$$$, so the average value is $$$\\frac{1}{3}$$$.In the third example, there is only one such word, and it has beauty $$$99$$$, so the average value is $$$99^2$$$."}, "src_uid": "be32c7b2fd197c3247d11aed25c3cc0d"} {"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": "Count the number of distinct sequences a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai) consisting of positive integers such that gcd(a1,\u2009a2,\u2009...,\u2009an)\u2009=\u2009x and . As this number could be large, print the answer modulo 109\u2009+\u20097.gcd here means the greatest common divisor.", "input_spec": "The only line contains two positive integers x and y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009109).", "output_spec": "Print the number of such sequences modulo 109\u2009+\u20097.", "sample_inputs": ["3 9", "5 8"], "sample_outputs": ["3", "0"], "notes": "NoteThere are three suitable sequences in the first test: (3,\u20093,\u20093), (3,\u20096), (6,\u20093).There are no suitable sequences in the second test."}, "src_uid": "de7731ce03735b962ee033613192f7bc"} {"nl": {"description": "There is a developed network of flights between Berland and Beerland. All of them belong to the Berland state company BerAvia. Each flight connects some Berland city with some Beerland city. For each flight airplanes fly in both directions.Changes are coming to Berland \u2014 the state decided to privatize BerAvia, namely, to sell out all flights to t private companies. Each of these companies wants to get the maximal number of flights, so if the Berland flights are sold unevenly, Berland can be accused of partiality. Berland Government decided to sell the flights as evenly as possible between the t companies.The unevenness of the distribution of flights between companies is calculated as follows. For each city i (both Berland and Beerland) we'll calculate the value of where aij is the number of flights from city i, which belong to company j. The sum of wi for all cities in both countries is called the unevenness of the distribution. The distribution with the minimal unevenness is the most even one.Help the Berland government come up with the most even distribution plan of selling flights.", "input_spec": "The first input line contains four integers n,\u2009m,\u2009k and t (1\u2009\u2264\u2009n,\u2009m,\u2009t\u2009\u2264\u2009200;1\u2009\u2264\u2009k\u2009\u2264\u20095000), where n,\u2009m are the numbers of cities in Berland and Beerland, correspondingly, k is the number of flights between them, and t is the number of private companies. Next k lines describe the flights, one per line, as pairs of positive integers xi,\u2009yi (1\u2009\u2264\u2009xi\u2009\u2264\u2009n;1\u2009\u2264\u2009yi\u2009\u2264\u2009m), where xi and yi are the indexes of cities in Berland and Beerland, correspondingly, connected by the i-th flight. There is at most one flight between any pair of cities, each flight connects cities of different countries. The cities in Berland are indexed from 1 to n, and in Beerland \u2014 from 1 to m.", "output_spec": "Print the unevenness of the sought plan on the first line. On the second line print a sequence of k integers c1,\u2009c2,\u2009...,\u2009ck (1\u2009\u2264\u2009ci\u2009\u2264\u2009t), where ci is the index of the company that should buy the i-th flight. Assume that the flights are indexed from 1 to k in the order they appear in the input. If there are multiple solutions, print any of them.", "sample_inputs": ["3 5 8 2\n1 4\n1 3\n3 3\n1 2\n1 1\n2 1\n1 5\n2 2"], "sample_outputs": ["4\n2 1 2 1 2 1 2 2"], "notes": null}, "src_uid": "99b97aabec566e5f966777947271ad3c"} {"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": "One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in the middle of a lesson. And only a loud ringing of a school bell could interrupt his sweet dream. Of course, the valuable material and the teacher's explanations were lost. However, Valera will one way or another have to do the homework. As he does not know the new material absolutely, he cannot do the job himself. That's why he asked you to help. You're his best friend after all, you just cannot refuse to help. Valera's home task has only one problem, which, though formulated in a very simple way, has not a trivial solution. Its statement looks as follows: if we consider all positive integers in the interval [a;b] then it is required to count the amount of such numbers in this interval that their smallest divisor will be a certain integer k (you do not have to consider divisor equal to one). In other words, you should count the amount of such numbers from the interval [a;b], that are not divisible by any number between 2 and k\u2009-\u20091 and yet are divisible by k. ", "input_spec": "The first and only line contains three positive integers a, b, k (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u20092\u00b7109,\u20092\u2009\u2264\u2009k\u2009\u2264\u20092\u00b7109). ", "output_spec": "Print on a single line the answer to the given problem. ", "sample_inputs": ["1 10 2", "12 23 3", "6 19 5"], "sample_outputs": ["5", "2", "0"], "notes": "NoteComments to the samples from the statement: In the first sample the answer is numbers 2,\u20094,\u20096,\u20098,\u200910.In the second one \u2014 15,\u200921In the third one there are no such numbers."}, "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2"} {"nl": {"description": "The Easter Rabbit laid n eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: Each of the seven colors should be used to paint at least one egg. Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.", "input_spec": "The only line contains an integer n \u2014 the amount of eggs (7\u2009\u2264\u2009n\u2009\u2264\u2009100).", "output_spec": "Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: \"R\" stands for red, \"O\" stands for orange, \"Y\" stands for yellow, \"G\" stands for green, \"B\" stands for blue, \"I\" stands for indigo, \"V\" stands for violet. If there are several answers, print any of them.", "sample_inputs": ["8", "13"], "sample_outputs": ["ROYGRBIV", "ROYGBIVGBIVYG"], "notes": "NoteThe way the eggs will be painted in the first sample is shown on the picture: "}, "src_uid": "dc3817c71b1fa5606f316e5e94732296"} {"nl": {"description": "You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors and is acute (i.e. strictly less than ). Otherwise, the point is called good.The angle between vectors and in 5-dimensional space is defined as , where is the scalar product and is length of .Given the list of points, print the indices of the good points in ascending order.", "input_spec": "The first line of input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009103)\u00a0\u2014 the number of points. The next n lines of input contain five integers ai,\u2009bi,\u2009ci,\u2009di,\u2009ei (|ai|,\u2009|bi|,\u2009|ci|,\u2009|di|,\u2009|ei|\u2009\u2264\u2009103) \u00a0\u2014 the coordinates of the i-th point. All points are distinct.", "output_spec": "First, print a single integer k\u00a0\u2014 the number of good points. Then, print k integers, each on their own line\u00a0\u2014 the indices of the good points in ascending order.", "sample_inputs": ["6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1", "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0"], "sample_outputs": ["1\n1", "0"], "notes": "NoteIn the first sample, the first point forms exactly a angle with all other pairs of points, so it is good.In the second sample, along the cd plane, we can see the points look as follows:We can see that all angles here are acute, so no points are good."}, "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"} {"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": "You are an intergalactic surgeon and you have an alien patient. For the purposes of this problem, we can and we will model this patient's body using a $$$2 \\times (2k + 1)$$$ rectangular grid. The alien has $$$4k + 1$$$ distinct organs, numbered $$$1$$$ to $$$4k + 1$$$.In healthy such aliens, the organs are arranged in a particular way. For example, here is how the organs of a healthy such alien would be positioned, when viewed from the top, for $$$k = 4$$$: Here, the E represents empty space. In general, the first row contains organs $$$1$$$ to $$$2k + 1$$$ (in that order from left to right), and the second row contains organs $$$2k + 2$$$ to $$$4k + 1$$$ (in that order from left to right) and then empty space right after. Your patient's organs are complete, and inside their body, but they somehow got shuffled around! Your job, as an intergalactic surgeon, is to put everything back in its correct position. All organs of the alien must be in its body during the entire procedure. This means that at any point during the procedure, there is exactly one cell (in the grid) that is empty. In addition, you can only move organs around by doing one of the following things: You can switch the positions of the empty space E with any organ to its immediate left or to its immediate right (if they exist). In reality, you do this by sliding the organ in question to the empty space; You can switch the positions of the empty space E with any organ to its immediate top or its immediate bottom (if they exist) only if the empty space is on the leftmost column, rightmost column or in the centermost column. Again, you do this by sliding the organ in question to the empty space. Your job is to figure out a sequence of moves you must do during the surgical procedure in order to place back all $$$4k + 1$$$ internal organs of your patient in the correct cells. If it is impossible to do so, you must say so.", "input_spec": "The first line of input contains a single integer $$$t$$$ ($$$1 \\le t \\le 4$$$) denoting the number of test cases. The next lines contain descriptions of the test cases. Each test case consists of three lines. The first line contains a single integer $$$k$$$ ($$$1 \\le k \\le 15$$$) which determines the size of the grid. Then two lines follow. Each of them contains $$$2k + 1$$$ space-separated integers or the letter E. They describe the first and second rows of organs, respectively. It is guaranteed that all $$$4k + 1$$$ organs are present and there is exactly one E.", "output_spec": "For each test case, first, print a single line containing either: SURGERY COMPLETE if it is possible to place back all internal organs in the correct locations; SURGERY FAILED if it is impossible. If it is impossible, then this is the only line of output for the test case. However, if it is possible, output a few more lines describing the sequence of moves to place the organs in the correct locations. The sequence of moves will be a (possibly empty) string of letters u, d, l or r, representing sliding the organ that's directly above, below, to the left or to the right of the empty space, respectively, into the empty space. Print the sequence of moves in the following line, as such a string. For convenience, you may use shortcuts to reduce the size of your output. You may use uppercase letters as shortcuts for sequences of moves. For example, you could choose T to represent the string lddrr. These shortcuts may also include other shortcuts on their own! For example, you could choose E to represent TruT, etc. You may use any number of uppercase letters (including none) as shortcuts. The only requirements are the following: The total length of all strings in your output for a single case is at most $$$10^4$$$; There must be no cycles involving the shortcuts that are reachable from the main sequence; The resulting sequence of moves is finite, after expanding all shortcuts. Note that the final sequence of moves (after expanding) may be much longer than $$$10^4$$$; the only requirement is that it's finite. As an example, if T = lddrr, E = TruT and R = rrr, then TurTlER expands to: TurTlER lddrrurTlER lddrrurlddrrlER lddrrurlddrrlTruTR lddrrurlddrrllddrrruTR lddrrurlddrrllddrrrulddrrR lddrrurlddrrllddrrrulddrrrrr To use shortcuts, print each one of them in a single line as the uppercase letter, then space, and then the string that this shortcut represents. They may be printed in any order. At the end of all of those, print a single line containing DONE. Note: You still need to print DONE even if you don't plan on using shortcuts. Your sequence does not need to be the shortest. Any valid sequence of moves (satisfying the requirements above) will be accepted.", "sample_inputs": ["2\n3\n1 2 3 5 6 E 7\n8 9 10 4 11 12 13\n11\n34 45 6 22 16 43 38 44 5 4 41 14 7 29 28 19 9 18 42 8 17 33 1\nE 15 40 36 31 24 10 2 21 11 32 23 30 27 35 25 13 12 39 37 26 20 3"], "sample_outputs": ["SURGERY COMPLETE\nIR\nR SrS\nS rr\nI lldll\nDONE\nSURGERY FAILED"], "notes": "NoteThere are three shortcuts defined in the first sample output: R = SrS S = rr I = lldll The sequence of moves is IR and it expands to: IR lldllR lldllSrS lldllrrrS lldllrrrrr "}, "src_uid": "697c4af98ea881892365bed856b49988"} {"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": "There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1,\u20092,\u2009...,\u2009m. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties. Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109\u2009+\u20097).", "input_spec": "A single line contains a single positive integer m (7\u2009\u2264\u2009m\u2009\u2264\u2009109) \u2014 the number of possible numbers in the ballot.", "output_spec": "In a single line print a single integer \u2014 the answer to the problem modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["7", "8"], "sample_outputs": ["0", "1440"], "notes": null}, "src_uid": "656ed7b1b80de84d65a253e5d14d62a9"} {"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": "Bike is a smart boy who loves math very much. He invented a number called \"Rotatable Number\" inspired by 142857. As you can see, 142857 is a magic number because any of its rotatings can be got by multiplying that number by 1,\u20092,\u2009...,\u20096 (numbers from one to number's length). Rotating a number means putting its last several digit into first. For example, by rotating number 12345 you can obtain any numbers: 12345,\u200951234,\u200945123,\u200934512,\u200923451. It's worth mentioning that leading-zeroes are allowed. So both 4500123 and 0123450 can be obtained by rotating 0012345. You can see why 142857 satisfies the condition. All of the 6 equations are under base 10. 142857\u00b71\u2009=\u2009142857; 142857\u00b72\u2009=\u2009285714; 142857\u00b73\u2009=\u2009428571; 142857\u00b74\u2009=\u2009571428; 142857\u00b75\u2009=\u2009714285; 142857\u00b76\u2009=\u2009857142. Now, Bike has a problem. He extends \"Rotatable Number\" under any base b. As is mentioned above, 142857 is a \"Rotatable Number\" under base 10. Another example is 0011 under base 2. All of the 4 equations are under base 2. 0011\u00b71\u2009=\u20090011; 0011\u00b710\u2009=\u20090110; 0011\u00b711\u2009=\u20091001; 0011\u00b7100\u2009=\u20091100. So, he wants to find the largest b (1\u2009<\u2009b\u2009<\u2009x) so that there is a positive \"Rotatable Number\" (leading-zeroes allowed) of length n under base b.Note that any time you multiply a rotatable number by numbers from 1 to its length you should get a rotating of that number.", "input_spec": "The only line contains two space-separated integers n,\u2009x (1\u2009\u2264\u2009n\u2009\u2264\u20095\u00b7106,\u20092\u2009\u2264\u2009x\u2009\u2264\u2009109). ", "output_spec": "Print a single integer \u2014 the largest b you found. If no such b exists, print -1 instead. ", "sample_inputs": ["6 11", "5 8"], "sample_outputs": ["10", "-1"], "notes": null}, "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a"} {"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": "A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands \"T\" (\"turn around\") and \"F\" (\"move 1 unit forward\").You are given a list of commands that will be given to the turtle. You have to change exactly n commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list?", "input_spec": "The first line of input contains a string commands \u2014 the original list of commands. The string commands contains between 1 and 100 characters, inclusive, and contains only characters \"T\" and \"F\". The second line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the number of commands you have to change in the list.", "output_spec": "Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list.", "sample_inputs": ["FT\n1", "FFFTFFF\n2"], "sample_outputs": ["2", "6"], "notes": "NoteIn the first example the best option is to change the second command (\"T\") to \"F\" \u2014 this way the turtle will cover a distance of 2 units.In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one."}, "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d"} {"nl": {"description": "Let's define a function $$$f(p)$$$ on a permutation $$$p$$$ as follows. Let $$$g_i$$$ be the greatest common divisor (GCD) of elements $$$p_1$$$, $$$p_2$$$, ..., $$$p_i$$$ (in other words, it is the GCD of the prefix of length $$$i$$$). Then $$$f(p)$$$ is the number of distinct elements among $$$g_1$$$, $$$g_2$$$, ..., $$$g_n$$$.Let $$$f_{max}(n)$$$ be the maximum value of $$$f(p)$$$ among all permutations $$$p$$$ of integers $$$1$$$, $$$2$$$, ..., $$$n$$$.Given an integers $$$n$$$, count the number of permutations $$$p$$$ of integers $$$1$$$, $$$2$$$, ..., $$$n$$$, such that $$$f(p)$$$ is equal to $$$f_{max}(n)$$$. Since the answer may be large, print the remainder of its division by $$$1000\\,000\\,007 = 10^9 + 7$$$.", "input_spec": "The only line contains the integer $$$n$$$ ($$$2 \\le n \\le 10^6$$$)\u00a0\u2014 the length of the permutations.", "output_spec": "The only line should contain your answer modulo $$$10^9+7$$$.", "sample_inputs": ["2", "3", "6"], "sample_outputs": ["1", "4", "120"], "notes": "NoteConsider the second example: these are the permutations of length $$$3$$$: $$$[1,2,3]$$$, $$$f(p)=1$$$. $$$[1,3,2]$$$, $$$f(p)=1$$$. $$$[2,1,3]$$$, $$$f(p)=2$$$. $$$[2,3,1]$$$, $$$f(p)=2$$$. $$$[3,1,2]$$$, $$$f(p)=2$$$. $$$[3,2,1]$$$, $$$f(p)=2$$$. The maximum value $$$f_{max}(3) = 2$$$, and there are $$$4$$$ permutations $$$p$$$ such that $$$f(p)=2$$$."}, "src_uid": "b2d59b1279d891dba9372a52364bced2"} {"nl": {"description": "Having learned (not without some help from the Codeforces participants) to play the card game from the previous round optimally, Shrek and Donkey (as you may remember, they too live now in the Kingdom of Far Far Away) have decided to quit the boring card games and play with toy soldiers.The rules of the game are as follows: there is a battlefield, its size equals n\u2009\u00d7\u2009m squares, some squares contain the toy soldiers (the green ones belong to Shrek and the red ones belong to Donkey). Besides, each of the n lines of the area contains not more than two soldiers. During a move a players should select not less than 1 and not more than k soldiers belonging to him and make them either attack or retreat.An attack is moving all of the selected soldiers along the lines on which they stand in the direction of an enemy soldier, if he is in this line. If this line doesn't have an enemy soldier, then the selected soldier on this line can move in any direction during the player's move. Each selected soldier has to move at least by one cell. Different soldiers can move by a different number of cells. During the attack the soldiers are not allowed to cross the cells where other soldiers stand (or stood immediately before the attack). It is also not allowed to go beyond the battlefield or finish the attack in the cells, where other soldiers stand (or stood immediately before attack).A retreat is moving all of the selected soldiers along the lines on which they stand in the direction from an enemy soldier, if he is in this line. The other rules repeat the rules of the attack.For example, let's suppose that the original battlefield had the form (here symbols \"G\" mark Shrek's green soldiers and symbols \"R\" mark Donkey's red ones): -G-R--R-G- Let's suppose that k\u2009=\u20092 and Shrek moves first. If he decides to attack, then after his move the battlefield can look like that: --GR- --GR- -G-R--RG-- -R-G- -RG-- If in the previous example Shrek decides to retreat, then after his move the battlefield can look like that: G--R- G--R- -G-R--R--G -R-G- -R--G On the other hand, the followings fields cannot result from Shrek's correct move: G--R- ---RG --GR--RG-- -R-G- GR--- Shrek starts the game. To make a move means to attack or to retreat by the rules. A player who cannot make a move loses and his opponent is the winner. Determine the winner of the given toy soldier game if Shrek and Donkey continue to be under the yellow pills from the last rounds' problem. Thus, they always play optimally (that is, they try to win if it is possible, or finish the game in a draw, by ensuring that it lasts forever, if they cannot win).", "input_spec": "The first line contains space-separated integers n, m and k (1\u2009\u2264\u2009n,\u2009m,\u2009k\u2009\u2264\u2009100). Then n lines contain m characters each. These characters belong to the set {\"-\", \"G\", \"R\"}, denoting, respectively, a battlefield's free cell, a cell occupied by Shrek's soldiers and a cell occupied by Donkey's soldiers. It is guaranteed that each line contains no more than two soldiers.", "output_spec": "Print \"First\" (without the quotes) if Shrek wins in the given Toy Soldier game. If Donkey wins, print \"Second\" (without the quotes). If the game continues forever, print \"Draw\" (also without the quotes).", "sample_inputs": ["2 3 1\nR-G\nRG-", "3 3 2\nG-R\nR-G\nG-R", "2 3 1\n-R-\n-G-", "2 5 2\n-G-R-\n-R-G-"], "sample_outputs": ["First", "Second", "Draw", "First"], "notes": null}, "src_uid": "69062f7c9b834e925ab23ebc2da96b52"} {"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": "This is an easier version of the problem. In this version, $$$n \\le 6$$$.Marek is working hard on creating strong testcases to his new algorithmic problem. You want to know what it is? Nah, we're not telling you. However, we can tell you how he generates the testcases.Marek chooses an integer $$$n$$$ and $$$n^2$$$ integers $$$p_{ij}$$$ ($$$1 \\le i \\le n$$$, $$$1 \\le j \\le n$$$). He then generates a random bipartite graph with $$$2n$$$ vertices. There are $$$n$$$ vertices on the left side: $$$\\ell_1, \\ell_2, \\dots, \\ell_n$$$, and $$$n$$$ vertices on the right side: $$$r_1, r_2, \\dots, r_n$$$. For each $$$i$$$ and $$$j$$$, he puts an edge between vertices $$$\\ell_i$$$ and $$$r_j$$$ with probability $$$p_{ij}$$$ percent.It turns out that the tests will be strong only if a perfect matching exists in the generated graph. What is the probability that this will occur?It can be shown that this value can be represented as $$$\\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \\not\\equiv 0 \\pmod{10^9+7}$$$. Let $$$Q^{-1}$$$ be an integer for which $$$Q \\cdot Q^{-1} \\equiv 1 \\pmod{10^9+7}$$$. Print the value of $$$P \\cdot Q^{-1}$$$ modulo $$$10^9+7$$$.", "input_spec": "The first line of the input contains a single integer $$$n$$$ ($$$\\mathbf{1 \\le n \\le 6}$$$). The following $$$n$$$ lines describe the probabilities of each edge appearing in the graph. The $$$i$$$-th of the lines contains $$$n$$$ integers $$$p_{i1}, p_{i2}, \\dots, p_{in}$$$ ($$$0 \\le p_{ij} \\le 100$$$); $$$p_{ij}$$$ denotes the probability, in percent, of an edge appearing between $$$\\ell_i$$$ and $$$r_j$$$.", "output_spec": "Print a single integer \u2014 the probability that the perfect matching exists in the bipartite graph, written as $$$P \\cdot Q^{-1} \\pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.", "sample_inputs": ["2\n50 50\n50 50", "3\n3 1 4\n1 5 9\n2 6 5"], "sample_outputs": ["937500007", "351284554"], "notes": "NoteIn the first sample test, each of the $$$16$$$ graphs below is equally probable. Out of these, $$$7$$$ have a perfect matching: Therefore, the probability is equal to $$$\\frac{7}{16}$$$. As $$$16 \\cdot 562\\,500\\,004 = 1 \\pmod{10^9+7}$$$, the answer to the testcase is $$$7 \\cdot 562\\,500\\,004 \\mod{(10^9+7)} = 937\\,500\\,007$$$."}, "src_uid": "906d4e49566e63fddaf8eac7384c6284"} {"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": "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": "From \"ftying rats\" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons? The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spases. Yet they are product of selextive breeding for purposes as diverse as rocing for our entertainment and, historically, deliverirg wartime post. Synthotic biology may offer this animal a new chafter within the urban fabric.Piteon d'Or recognihes how these birds ripresent a potentially userul interface for urdan biotechnologies. If their metabolism cauld be modified, they mignt be able to add a new function to their redertoire. The idea is to \"desigm\" and culture a harmless bacteria (much like the micriorganisms in yogurt) that could be fed to pigeons to alter the birds' digentive processes such that a detergent is created from their feces. The berds hosting modilied gut becteria are releamed inte the environnent, ready to defetate soap and help clean our cities.", "input_spec": "The first line of input data contains a single integer $$$n$$$ ($$$5 \\le n \\le 10$$$). The second line of input data contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \\le a_i \\le 32$$$).", "output_spec": "Output a single integer.", "sample_inputs": ["5\n1 2 3 4 5"], "sample_outputs": ["4"], "notes": "NoteWe did not proofread this statement at all."}, "src_uid": "a9eb85dfaa3c50ed488d41da4f29c697"} {"nl": {"description": "The only difference between easy and hard versions is on constraints. In this version constraints are lower. You can make hacks only if all versions of the problem are solved.Koa the Koala is at the beach!The beach consists (from left to right) of a shore, $$$n+1$$$ meters of sea and an island at $$$n+1$$$ meters from the shore.She measured the depth of the sea at $$$1, 2, \\dots, n$$$ meters from the shore and saved them in array $$$d$$$. $$$d_i$$$ denotes the depth of the sea at $$$i$$$ meters from the shore for $$$1 \\le i \\le n$$$.Like any beach this one has tide, the intensity of the tide is measured by parameter $$$k$$$ and affects all depths from the beginning at time $$$t=0$$$ in the following way: For a total of $$$k$$$ seconds, each second, tide increases all depths by $$$1$$$. Then, for a total of $$$k$$$ seconds, each second, tide decreases all depths by $$$1$$$. This process repeats again and again (ie. depths increase for $$$k$$$ seconds then decrease for $$$k$$$ seconds and so on ...).Formally, let's define $$$0$$$-indexed array $$$p = [0, 1, 2, \\ldots, k - 2, k - 1, k, k - 1, k - 2, \\ldots, 2, 1]$$$ of length $$$2k$$$. At time $$$t$$$ ($$$0 \\le t$$$) depth at $$$i$$$ meters from the shore equals $$$d_i + p[t \\bmod 2k]$$$ ($$$t \\bmod 2k$$$ denotes the remainder of the division of $$$t$$$ by $$$2k$$$). Note that the changes occur instantaneously after each second, see the notes for better understanding. At time $$$t=0$$$ Koa is standing at the shore and wants to get to the island. Suppose that at some time $$$t$$$ ($$$0 \\le t$$$) she is at $$$x$$$ ($$$0 \\le x \\le n$$$) meters from the shore: In one second Koa can swim $$$1$$$ meter further from the shore ($$$x$$$ changes to $$$x+1$$$) or not swim at all ($$$x$$$ stays the same), in both cases $$$t$$$ changes to $$$t+1$$$. As Koa is a bad swimmer, the depth of the sea at the point where she is can't exceed $$$l$$$ at integer points of time (or she will drown). More formally, if Koa is at $$$x$$$ ($$$1 \\le x \\le n$$$) meters from the shore at the moment $$$t$$$ (for some integer $$$t\\ge 0$$$), the depth of the sea at this point \u00a0\u2014 $$$d_x + p[t \\bmod 2k]$$$ \u00a0\u2014 can't exceed $$$l$$$. In other words, $$$d_x + p[t \\bmod 2k] \\le l$$$ must hold always. Once Koa reaches the island at $$$n+1$$$ meters from the shore, she stops and can rest.Note that while Koa swims tide doesn't have effect on her (ie. she can't drown while swimming). Note that Koa can choose to stay on the shore for as long as she needs and neither the shore or the island are affected by the tide (they are solid ground and she won't drown there). Koa wants to know whether she can go from the shore to the island. Help her!", "input_spec": "The first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u00a0\u2014 the number of test cases. Description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k$$$ and $$$l$$$ ($$$1 \\le n \\le 100; 1 \\le k \\le 100; 1 \\le l \\le 100$$$)\u00a0\u2014 the number of meters of sea Koa measured and parameters $$$k$$$ and $$$l$$$. The second line of each test case contains $$$n$$$ integers $$$d_1, d_2, \\ldots, d_n$$$ ($$$0 \\le d_i \\le 100$$$) \u00a0\u2014 the depths of each meter of sea Koa measured. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$.", "output_spec": "For each test case: Print Yes if Koa can get from the shore to the island, and No otherwise. You may print each letter in any case (upper or lower).", "sample_inputs": ["7\n2 1 1\n1 0\n5 2 3\n1 2 3 2 2\n4 3 4\n0 2 4 3\n2 3 5\n3 0\n7 2 3\n3 0 2 1 3 0 1\n7 1 4\n4 4 3 0 2 4 2\n5 2 3\n1 2 3 2 2"], "sample_outputs": ["Yes\nNo\nYes\nYes\nYes\nNo\nNo"], "notes": "NoteIn the following $$$s$$$ denotes the shore, $$$i$$$ denotes the island, $$$x$$$ denotes distance from Koa to the shore, the underline denotes the position of Koa, and values in the array below denote current depths, affected by tide, at $$$1, 2, \\dots, n$$$ meters from the shore.In test case $$$1$$$ we have $$$n = 2, k = 1, l = 1, p = [ 0, 1 ]$$$.Koa wants to go from shore (at $$$x = 0$$$) to the island (at $$$x = 3$$$). Let's describe a possible solution: Initially at $$$t = 0$$$ the beach looks like this: $$$[\\underline{s}, 1, 0, i]$$$. At $$$t = 0$$$ if Koa would decide to swim to $$$x = 1$$$, beach would look like: $$$[s, \\underline{2}, 1, i]$$$ at $$$t = 1$$$, since $$$2 > 1$$$ she would drown. So Koa waits $$$1$$$ second instead and beach looks like $$$[\\underline{s}, 2, 1, i]$$$ at $$$t = 1$$$. At $$$t = 1$$$ Koa swims to $$$x = 1$$$, beach looks like $$$[s, \\underline{1}, 0, i]$$$ at $$$t = 2$$$. Koa doesn't drown because $$$1 \\le 1$$$. At $$$t = 2$$$ Koa swims to $$$x = 2$$$, beach looks like $$$[s, 2, \\underline{1}, i]$$$ at $$$t = 3$$$. Koa doesn't drown because $$$1 \\le 1$$$. At $$$t = 3$$$ Koa swims to $$$x = 3$$$, beach looks like $$$[s, 1, 0, \\underline{i}]$$$ at $$$t = 4$$$. At $$$t = 4$$$ Koa is at $$$x = 3$$$ and she made it! We can show that in test case $$$2$$$ Koa can't get to the island."}, "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8"} {"nl": {"description": "One day, BThero decided to play around with arrays and came up with the following problem:You are given an array $$$a$$$, which consists of $$$n$$$ positive integers. The array is numerated $$$1$$$ through $$$n$$$. You execute the following procedure exactly once: You create a new array $$$b$$$ which consists of $$$2n$$$ positive integers, where for each $$$1 \\le i \\le n$$$ the condition $$$b_{2i-1}+b_{2i} = a_i$$$ holds. For example, for the array $$$a = [6, 8, 2]$$$ you can create $$$b = [2, 4, 4, 4, 1, 1]$$$. You merge consecutive equal numbers in $$$b$$$. For example, $$$b = [2, 4, 4, 4, 1, 1]$$$ becomes $$$b = [2, 4, 1]$$$. Find and print the minimum possible value of $$$|b|$$$ (size of $$$b$$$) which can be achieved at the end of the procedure. It can be shown that under the given constraints there is at least one way to construct $$$b$$$.", "input_spec": "The first line of the input file contains a single integer $$$T$$$ ($$$1 \\le T \\le 5 \\cdot 10^5$$$) denoting the number of test cases. The description of $$$T$$$ test cases follows. The first line of each test contains a single integer $$$n$$$ ($$$1 \\le n \\le 5 \\cdot 10^5$$$). The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$2 \\le a_i \\le 10^9$$$). It is guaranteed that $$$\\sum{n}$$$ over all test cases does not exceed $$$5 \\cdot 10^5$$$.", "output_spec": "For each test case, print a single line containing one integer \u2014 the minimum possible value of $$$|b|$$$.", "sample_inputs": ["3\n3\n6 8 2\n1\n4\n3\n5 6 6"], "sample_outputs": ["3\n1\n2"], "notes": null}, "src_uid": "e809d068b3ae47eb5ecfb9ac69892254"} {"nl": {"description": "Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a system of equations: You should count, how many there are pairs of integers (a,\u2009b) (0\u2009\u2264\u2009a,\u2009b) which satisfy the system.", "input_spec": "A single line contains two integers n,\u2009m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091000) \u2014 the parameters of the system. The numbers on the line are separated by a space.", "output_spec": "On a single line print the answer to the problem.", "sample_inputs": ["9 3", "14 28", "4 20"], "sample_outputs": ["1", "1", "0"], "notes": "NoteIn the first sample the suitable pair is integers (3,\u20090). In the second sample the suitable pair is integers (3,\u20095). In the third sample there is no suitable pair."}, "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"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": "Fox Ciel studies number theory.She thinks a non-empty set S contains non-negative integers is perfect if and only if for any (a can be equal to b), . Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or).Please calculate the number of perfect sets consisting of integers not greater than k. The answer can be very large, so print it modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The first line contains an integer k (0\u2009\u2264\u2009k\u2009\u2264\u2009109).", "output_spec": "Print a single integer \u2014 the number of required sets modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1", "2", "3", "4"], "sample_outputs": ["2", "3", "5", "6"], "notes": "NoteIn example 1, there are 2 such sets: {0} and {0, 1}. Note that {1} is not a perfect set since 1 xor 1 = 0 and {1} doesn't contain zero.In example 4, there are 6 such sets: {0}, {0, 1}, {0, 2}, {0, 3}, {0, 4} and {0, 1, 2, 3}."}, "src_uid": "ead64d8e3134fa8f29881cb487e52f60"} {"nl": {"description": "Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighboring ones. The mushroom gnomes loved it when everything was in order, that's why they always planted the mushrooms in one line in the order of their weights' increasing. Well... The gnomes planted the mushrooms and went to eat. After x minutes they returned and saw that new mushrooms had grown up, so that the increasing order had been violated. The gnomes replanted all the mushrooms in the correct order, that is, they sorted the mushrooms in the order of the weights' increasing. And went to eat again (those gnomes were quite big eaters). What total weights modulo p will the mushrooms have in another y minutes?", "input_spec": "The first line contains four integers n, x, y, p (1\u2009\u2264\u2009n\u2009\u2264\u2009106,\u20090\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20091018,\u2009x\u2009+\u2009y\u2009>\u20090,\u20092\u2009\u2264\u2009p\u2009\u2264\u2009109) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains n integers ai which represent the mushrooms' weight in the non-decreasing order (0\u2009\u2264\u2009ai\u2009\u2264\u2009109). 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).", "output_spec": "The answer should contain a single number which is the total weights of the mushrooms modulo p in the end after x\u2009+\u2009y minutes.", "sample_inputs": ["2 1 0 657276545\n1 2", "2 1 1 888450282\n1 2", "4 5 0 10000\n1 2 3 4"], "sample_outputs": ["6", "14", "1825"], "notes": null}, "src_uid": "b5dd2b94570973b3e312ae4b7a43284f"} {"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": "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": "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": "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": "Bearland is a big square on the plane. It contains all points with coordinates not exceeding 106 by the absolute value.There are n houses in Bearland. The i-th of them is located at the point (xi,\u2009yi). The n points are distinct, but some subsets of them may be collinear.Bear Limak lives in the first house. He wants to destroy his house and build a new one somewhere in Bearland.Bears don't like big changes. For every three points (houses) pi, pj and pk, the sign of their cross product (pj\u2009-\u2009pi)\u2009\u00d7\u2009(pk\u2009-\u2009pi) should be the same before and after the relocation. If it was negative/positive/zero, it should still be negative/positive/zero respectively. This condition should be satisfied for all triples of indices (i,\u2009j,\u2009k), possibly equal to each other or different than 1. Additionally, Limak isn't allowed to build the house at the point where some other house already exists (but it can be the point where his old house was).In the formula above, we define the difference and the cross product of points (ax,\u2009ay) and (bx,\u2009by) as: (ax,\u2009ay)\u2009-\u2009(bx,\u2009by)\u2009=\u2009(ax\u2009-\u2009bx,\u2009ay\u2009-\u2009by),\u2009 (ax,\u2009ay)\u2009\u00d7\u2009(bx,\u2009by)\u2009=\u2009ax\u00b7by\u2009-\u2009ay\u00b7bx.Consider a set of possible new placements of Limak's house. Your task is to find the area of that set of points.Formally, let's say that Limak chooses the new placement randomly (each coordinate is chosen independently uniformly at random from the interval [\u2009-\u2009106,\u2009106]). Let p denote the probability of getting the allowed placement of new house. Let S denote the area of Bearland (S\u2009=\u20094\u00b71012). Your task is to find p\u00b7S.", "input_spec": "The first line of the input contains an integer T (1\u2009\u2264\u2009T\u2009\u2264\u2009500)\u00a0\u2014 the number of test cases. The description of the test cases follows. The first line of the description of a test case contains an integer n (3\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000)\u00a0\u2014 the number of houses. The i-th of the next n lines contains two integers xi and yi (\u2009-\u2009106\u2009\u2264\u2009xi,\u2009yi\u2009\u2264\u2009106)\u00a0\u2014 coordinates of the i-th house. No two houses are located at the same point in the same test case. Limak lives in the first house. The sum of n won't exceed 200\u2009000.", "output_spec": "Print one real value, denoting the area of the set of points that are possible new placements of Limak's house. Your answer will be considered correct if its absolute or relative error doesn't exceed 10\u2009-\u20096. More precisely, let the jury's answer be b, and your answer be a. Then your answer will be accepted if and only if .", "sample_inputs": ["4\n4\n5 3\n0 1\n10 1\n3 51\n3\n-999123 700000\n-950000 123456\n-950000 987654\n3\n2 3\n10 -1\n-4 6\n5\n1 3\n5 2\n6 1\n4 4\n-3 3"], "sample_outputs": ["250.000000000000\n100000000000.000000000000\n0.000000000000\n6.562500000000"], "notes": "NoteIn the sample test, there are 4 test cases.In the first test case, there are four houses and Limak's one is in (5,\u20093). The set of valid new placements form a triangle with vertices in points (0,\u20091), (10,\u20091) and (3,\u200951), without its sides. The area of such a triangle is 250.In the second test case, the set of valid new placements form a rectangle of width 50\u2009000 and height 2\u2009000\u2009000. Don't forget that the new placement must be inside the big square that represents Bearland.In the third test case, the three given points are collinear. Each cross product is equal to 0 and it should be 0 after the relocation as well. Hence, Limak's new house must lie on the line that goes through the given points. Since it must also be inside the big square, new possible placements are limited to some segment (excluding the two points where the other houses are). The area of any segment is 0."}, "src_uid": "6afe0718ad89e3fd51a456e0144c538d"} {"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": "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": "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": "Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a string that reads the same forward and backward. For example, \"noon\", \"testset\" and \"a\" are all palindromes, while \"test\" and \"kitayuta\" are not.) You can choose any n lowercase English letters, and insert each of them to any position of s, possibly to the beginning or the end of s. You have to insert exactly n letters even if it is possible to turn s into a palindrome by inserting less than n letters.Find the number of the palindromes that can be obtained in this way, modulo 10007.", "input_spec": "The first line contains a string s (1\u2009\u2264\u2009|s|\u2009\u2264\u2009200). Each character in s is a lowercase English letter. The second line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Print the number of the palindromes that can be obtained, modulo 10007.", "sample_inputs": ["revive\n1", "add\n2"], "sample_outputs": ["1", "28"], "notes": "NoteFor the first sample, you can obtain the palindrome \"reviver\" by inserting 'r' to the end of \"revive\".For the second sample, the following 28 palindromes can be obtained: \"adada\", \"adbda\", ..., \"adzda\", \"dadad\" and \"ddadd\"."}, "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8"} {"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": "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": "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": "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": "Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with coordinates (xv,\u2009yv) and (xp,\u2009yp) respectively. The wall is a segment joining points with coordinates (xw,\u20091,\u2009yw,\u20091) and (xw,\u20092,\u2009yw,\u20092), the mirror \u2014 a segment joining points (xm,\u20091,\u2009ym,\u20091) and (xm,\u20092,\u2009ym,\u20092).If an obstacle has a common point with a line of vision, it's considered, that the boys can't see each other with this line of vision. If the mirror has a common point with the line of vision, it's considered, that the boys can see each other in the mirror, i.e. reflection takes place. The reflection process is governed by laws of physics \u2014 the angle of incidence is equal to the angle of reflection. The incident ray is in the same half-plane as the reflected ray, relative to the mirror. I.e. to see each other Victor and Peter should be to the same side of the line, containing the mirror (see example 1). If the line of vision is parallel to the mirror, reflection doesn't take place, and the mirror isn't regarded as an obstacle (see example 4).Victor got interested if he can see Peter, while standing at the same spot. Help him solve this problem.", "input_spec": "The first line contains two numbers xv and yv \u2014 coordinates of Victor. The second line contains two numbers xp and yp \u2014 coordinates of Peter. The third line contains 4 numbers xw,\u20091, yw,\u20091, xw,\u20092, yw,\u20092 \u2014 coordinates of the wall. The forth line contains 4 numbers xm,\u20091, ym,\u20091, xm,\u20092, ym,\u20092 \u2014 coordinates of the mirror. All the coordinates are integer numbers, and don't exceed 104 in absolute value. It's guaranteed, that the segments don't have common points, Victor and Peter are not on any of the segments, coordinates of Victor and Peter aren't the same, the segments don't degenerate into points.", "output_spec": "Output YES, if Victor can see Peter without leaving the initial spot. Otherwise output NO.", "sample_inputs": ["-1 3\n1 3\n0 2 0 4\n0 0 0 1", "0 0\n1 1\n0 1 1 0\n-100 -100 -101 -101", "0 0\n1 1\n0 1 1 0\n-1 1 1 3", "0 0\n10 0\n100 100 101 101\n1 0 3 0"], "sample_outputs": ["NO", "NO", "YES", "YES"], "notes": null}, "src_uid": "7539a41268b68238d644795bccaa0c0f"} {"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": "Sasha and Ira are two best friends. But they aren\u2019t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. The game is cooperative and turn based. In each turn, one of the players makes a move (it doesn\u2019t matter which player, it's possible that players turns do not alternate). Algorithm for bots that Sasha and Ira are developing works by keeping track of the state the game is in. Each time either bot makes a move, the state changes. And, since the game is very dynamic, it will never go back to the state it was already in at any point in the past.Sasha and Ira are perfectionists and want their algorithm to have an optimal winning strategy. They have noticed that in the optimal winning strategy, both bots make exactly N moves each. But, in order to find the optimal strategy, their algorithm needs to analyze all possible states of the game (they haven\u2019t learned about alpha-beta pruning yet) and pick the best sequence of moves.They are worried about the efficiency of their algorithm and are wondering what is the total number of states of the game that need to be analyzed? ", "input_spec": "The first and only line contains integer N. 1\u2009\u2264\u2009N\u2009\u2264\u2009106 ", "output_spec": "Output should contain a single integer \u2013 number of possible states modulo 109\u2009+\u20097.", "sample_inputs": ["2"], "sample_outputs": ["19"], "notes": "NoteStart: Game is in state A. Turn 1: Either bot can make a move (first bot is red and second bot is blue), so there are two possible states after the first turn \u2013 B and C. Turn 2: In both states B and C, either bot can again make a turn, so the list of possible states is expanded to include D, E, F and G. Turn 3: Red bot already did N=2 moves when in state D, so it cannot make any more moves there. It can make moves when in state E, F and G, so states I, K and M are added to the list. Similarly, blue bot cannot make a move when in state G, but can when in D, E and F, so states H, J and L are added. Turn 4: Red bot already did N=2 moves when in states H, I and K, so it can only make moves when in J, L and M, so states P, R and S are added. Blue bot cannot make a move when in states J, L and M, but only when in H, I and K, so states N, O and Q are added. Overall, there are 19 possible states of the game their algorithm needs to analyze."}, "src_uid": "a18833c987fd7743e8021196b5dcdd1b"} {"nl": {"description": "Dima loves making pictures on a piece of squared paper. And yet more than that Dima loves the pictures that depict one of his favorite figures. A piece of squared paper of size n\u2009\u00d7\u2009m is represented by a table, consisting of n rows and m columns. All squares are white on blank squared paper. Dima defines a picture as an image on a blank piece of paper, obtained by painting some squares black.The picture portrays one of Dima's favorite figures, if the following conditions hold: The picture contains at least one painted cell; All painted cells form a connected set, that is, you can get from any painted cell to any other one (you can move from one cell to a side-adjacent one); The minimum number of moves needed to go from the painted cell at coordinates (x1,\u2009y1) to the painted cell at coordinates (x2,\u2009y2), moving only through the colored cells, equals |x1\u2009-\u2009x2|\u2009+\u2009|y1\u2009-\u2009y2|. Now Dima is wondering: how many paintings are on an n\u2009\u00d7\u2009m piece of paper, that depict one of his favorite figures? Count this number modulo 1000000007\u00a0(109\u2009+\u20097).", "input_spec": "The first line contains two integers n and m \u2014 the sizes of the piece of paper (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009150).", "output_spec": "In a single line print the remainder after dividing the answer to the problem by number 1000000007\u00a0(109\u2009+\u20097).", "sample_inputs": ["2 2", "3 4"], "sample_outputs": ["13", "571"], "notes": null}, "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7"} {"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": "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": "Anfisa the monkey got disappointed in word processors as they aren't good enough at reflecting all the range of her emotions, that's why she decided to switch to graphics editors. Having opened the BerPaint, she saw a white rectangle W\u2009\u00d7\u2009H in size which can be painted on. First Anfisa learnt to navigate the drawing tool which is used to paint segments and quickly painted on that rectangle a certain number of black-colored segments. The resulting picture didn't seem bright enough to Anfisa, that's why she turned her attention to the \"fill\" tool which is used to find a point on the rectangle to paint and choose a color, after which all the area which is the same color as the point it contains, is completely painted the chosen color. Having applied the fill several times, Anfisa expressed her emotions completely and stopped painting. Your task is by the information on the painted segments and applied fills to find out for every color the total area of the areas painted this color after all the fills.", "input_spec": "The first input line has two integers W and H (3\u2009\u2264\u2009W,\u2009H\u2009\u2264\u2009104) \u2014 the sizes of the initially white rectangular painting area. The second line contains integer n \u2014 the number of black segments (0\u2009\u2264\u2009n\u2009\u2264\u2009100). On the next n lines are described the segments themselves, each of which is given by coordinates of their endpoints x1,\u2009y1,\u2009x2,\u2009y2 (0\u2009<\u2009x1,\u2009x2\u2009<\u2009W,\u20090\u2009<\u2009y1,\u2009y2\u2009<\u2009H). All segments have non-zero length. The next line contains preset number of fills m (0\u2009\u2264\u2009m\u2009\u2264\u2009100). Each of the following m lines defines the fill operation in the form of \"x y color\", where (x,\u2009y) are the coordinates of the chosen point (0\u2009<\u2009x\u2009<\u2009W,\u20090\u2009<\u2009y\u2009<\u2009H), and color \u2014 a line of lowercase Latin letters from 1 to 15 symbols in length, determining the color. All coordinates given in the input are integers. Initially the rectangle is \"white\" in color, whereas the segments are drawn \"black\" in color.", "output_spec": "For every color present in the final picture print on the single line the name of the color and the total area of areas painted that color with an accuracy of 10\u2009-\u20096. Print the colors in any order. ", "sample_inputs": ["4 5\n6\n1 1 1 3\n1 3 3 3\n3 3 3 1\n3 1 1 1\n1 3 3 1\n1 1 3 3\n2\n2 1 red\n2 2 blue", "5 5\n5\n1 1 2 2\n2 2 4 2\n4 2 4 4\n4 4 2 4\n2 4 2 2\n2\n3 3 black\n3 3 green", "7 4\n9\n1 2 2 3\n2 3 3 2\n3 2 2 1\n2 1 1 2\n3 2 4 2\n4 2 5 3\n5 3 6 2\n6 2 5 1\n5 1 4 2\n2\n2 2 black\n2 2 red"], "sample_outputs": ["blue 0.00000000\nwhite 20.00000000", "green 4.00000000\nwhite 21.00000000", "red 2.00000000\nwhite 26.00000000"], "notes": "NoteInitially the black segments painted by Anfisa can also be painted a color if any of the chosen points lays on the segment. The segments have areas equal to 0. That is why if in the final picture only parts of segments is painted some color, then the area, painted the color is equal to 0."}, "src_uid": "92caafd07e9afb03745aa6f5b450c38f"} {"nl": {"description": "Bob Bubblestrong just got a new job as security guard. Bob is now responsible for safety of a collection of warehouses, each containing the most valuable Bubble Cup assets - the high-quality bubbles. His task is to detect thieves inside the warehouses and call the police.Looking from the sky, each warehouse has a shape of a convex polygon. Walls of no two warehouses intersect, and of course, none of the warehouses is built inside of another warehouse.Little did the Bubble Cup bosses know how lazy Bob is and that he enjoys watching soap operas (he heard they are full of bubbles) from the coziness of his office. Instead of going from one warehouse to another to check if warehouses are secured, the plan Bob has is to monitor all the warehouses from the comfort of his office using the special X-ray goggles. The goggles have an infinite range, so a thief in any of the warehouses could easily be spotted.However, the goggles promptly broke and the X-rays are now strong only enough to let Bob see through a single wall. Now, Bob would really appreciate if you could help him find out what is the total area inside of the warehouses monitored by the broken goggles, so that he could know how much area of the warehouses he needs to monitor in person.", "input_spec": "The first line contains one integer $$$N$$$ ($$$1$$$ $$$\\leq$$$ $$$N$$$ $$$\\leq$$$ $$$10^4$$$) \u2013 the number of warehouses. The next $$$N$$$ lines describe the warehouses. The first number of the line is integer $$$c_i$$$ ($$$3$$$ $$$\\leq$$$ $$$c_i$$$ $$$\\leq$$$ $$$10^4$$$) \u2013 the number corners in the $$$i^{th}$$$ warehouse, followed by $$$c_i$$$ pairs of integers. The $$$j^{th}$$$ pair is $$$(x_j, y_j)$$$ \u2013 the coordinates of the $$$j^{th}$$$ corner ($$$|x_j|$$$, $$$|y_j|$$$ $$$\\leq$$$ $$$3 * 10^4$$$). The corners are listed in the clockwise order. The total number of corners in all the warehouses is at most $$$5 * 10^4$$$. Bob's office is positioned at the point with coordinates $$$(0, 0)$$$. The office is not contained within any of the warehouses.", "output_spec": "Print a single line containing a single decimal number accurate to at least four decimal places \u2013 the total area of the warehouses Bob can monitor using the broken X-ray goggles.", "sample_inputs": ["5\n4 1 1 1 3 3 3 3 1\n4 4 3 6 2 6 0 4 0\n6 -5 3 -4 4 -3 4 -2 3 -3 2 -4 2\n3 0 -1 1 -3 -1 -3\n4 1 -4 1 -6 -1 -6 -1 -4"], "sample_outputs": ["13.333333333333"], "notes": "Note Areas monitored by the X-ray goggles are colored green and areas not monitored by the goggles are colored red.The warehouses $$$ABCD$$$, $$$IJK$$$ and $$$LMNOPQ$$$ are completely monitored using the googles.The warehouse $$$EFGH$$$ is partially monitored using the goggles: part $$$EFW$$$ is not monitored because to monitor each point inside it, the X-rays must go through two walls of warehouse $$$ABCD$$$.The warehouse $$$RUTS$$$ is not monitored from the Bob's office, because there are two walls of the warehouse $$$IJK$$$ between Bob's office and each point in $$$RUTS$$$.The total area monitored by the goggles is $$$P$$$ = $$$P_{ABCD}$$$ + $$$P_{FGHW}$$$ + $$$P_{IJK}$$$ + $$$P_{LMNOPQ}$$$ = $$$4$$$ + $$$3.333333333333$$$ + $$$2$$$ + $$$4$$$ = $$$13.333333333333$$$."}, "src_uid": "f88b322137318b2fbae4f54a613b170c"} {"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": "Pak Chanek has a grid that has $$$N$$$ rows and $$$M$$$ columns. Each row is numbered from $$$1$$$ to $$$N$$$ from top to bottom. Each column is numbered from $$$1$$$ to $$$M$$$ from left to right.Each tile in the grid contains a number. The numbers are arranged as follows: Row $$$1$$$ contains integers from $$$1$$$ to $$$M$$$ from left to right. Row $$$2$$$ contains integers from $$$M+1$$$ to $$$2 \\times M$$$ from left to right. Row $$$3$$$ contains integers from $$$2 \\times M+1$$$ to $$$3 \\times M$$$ from left to right. And so on until row $$$N$$$. A domino is defined as two different tiles in the grid that touch by their sides. A domino is said to be tight if and only if the two numbers in the domino have a difference of exactly $$$1$$$. Count the number of distinct tight dominoes in the grid.Two dominoes are said to be distinct if and only if there exists at least one tile that is in one domino, but not in the other.", "input_spec": "The only line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \\leq N, M \\leq 10^9$$$) \u2014 the number of rows and columns in the grid.", "output_spec": "An integer representing the number of distinct tight dominoes in the grid.", "sample_inputs": ["3 4", "2 1"], "sample_outputs": ["9", "1"], "notes": "NoteThe picture below is the grid that Pak Chanek has in the first example. The picture below is an example of a tight domino in the grid. "}, "src_uid": "a91aab4c0618d036c81022232814ef44"} {"nl": {"description": "Farmer John is obsessed with making Bessie exercise more!Bessie is out grazing on the farm, which consists of $$$n$$$ fields connected by $$$m$$$ directed roads. Each road takes some time $$$w_i$$$ to cross. She is currently at field $$$1$$$ and will return to her home at field $$$n$$$ at the end of the day.Farmer John has plans to increase the time it takes to cross certain roads. He can increase the time it takes to cross each road by a nonnegative amount, but the total increase cannot exceed $$$x_i$$$ for the $$$i$$$-th plan. Determine the maximum he can make the shortest path from $$$1$$$ to $$$n$$$ for each of the $$$q$$$ independent plans.", "input_spec": "The first line contains integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le 50$$$, $$$1 \\le m \\le n \\cdot (n-1)$$$) \u2014 the number of fields and number of roads, respectively. Each of the following $$$m$$$ lines contains $$$3$$$ integers, $$$u_i$$$, $$$v_i$$$, and $$$w_i$$$ ($$$1 \\le u_i, v_i \\le n$$$, $$$1 \\le w_i \\le 10^6$$$), meaning there is an road from field $$$u_i$$$ to field $$$v_i$$$ that takes $$$w_i$$$ time to cross. It is guaranteed that there exists a way to get to field $$$n$$$ from field $$$1$$$. It is guaranteed that the graph does not contain self-loops or parallel edges. It is possible to have a road from $$$u$$$ to $$$v$$$ and a road from $$$v$$$ to $$$u$$$. The next line contains a single integer $$$q$$$ ($$$1 \\le q \\le 10^5$$$), the number of plans. Each of the following $$$q$$$ lines contains a single integer $$$x_i$$$, the query ($$$0 \\le x_i \\le 10^5$$$).", "output_spec": "For each query, output the maximum Farmer John can make the shortest path if the total increase does not exceed $$$x_i$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\\frac{|a - b|}{\\max{(1, |b|)}} \\le 10^{-6}$$$.", "sample_inputs": ["3 3\n1 2 2\n2 3 2\n1 3 3\n5\n0\n1\n2\n3\n4"], "sample_outputs": ["3.0000000000\n4.0000000000\n4.5000000000\n5.0000000000\n5.5000000000"], "notes": null}, "src_uid": "b0751071e12f729f6700586c5a8eed23"} {"nl": {"description": "Little Artem is a very smart programmer. He knows many different difficult algorithms. Recently he has mastered in 2-SAT one.In computer science, 2-satisfiability (abbreviated as 2-SAT) is the special case of the problem of determining whether a conjunction (logical AND) of disjunctions (logical OR) have a solution, in which all disjunctions consist of no more than two arguments (variables). For the purpose of this problem we consider only 2-SAT formulas where each disjunction consists of exactly two arguments.Consider the following 2-SAT problem as an example: . Note that there might be negations in 2-SAT formula (like for x1 and for x4).Artem now tries to solve as many problems with 2-SAT as possible. He found a very interesting one, which he can not solve yet. Of course, he asks you to help him. The problem is: given two 2-SAT formulas f and g, determine whether their sets of possible solutions are the same. Otherwise, find any variables assignment x such that f(x)\u2009\u2260\u2009g(x). ", "input_spec": "The first line of the input contains three integers n, m1 and m2 (1\u2009\u2264\u2009n\u2009\u2264\u20091000, 1\u2009\u2264\u2009m1,\u2009m2\u2009\u2264\u2009n2)\u00a0\u2014 the number of variables, the number of disjunctions in the first formula and the number of disjunctions in the second formula, respectively. Next m1 lines contains the description of 2-SAT formula f. The description consists of exactly m1 pairs of integers xi (\u2009-\u2009n\u2009\u2264\u2009xi\u2009\u2264\u2009n,\u2009xi\u2009\u2260\u20090) each on separate line, where xi\u2009>\u20090 corresponds to the variable without negation, while xi\u2009<\u20090 corresponds to the variable with negation. Each pair gives a single disjunction. Next m2 lines contains formula g in the similar format.", "output_spec": "If both formulas share the same set of solutions, output a single word \"SIMILAR\" (without quotes). Otherwise output exactly n integers xi ()\u00a0\u2014 any set of values x such that f(x)\u2009\u2260\u2009g(x).", "sample_inputs": ["2 1 1\n1 2\n1 2", "2 1 1\n1 2\n1 -2"], "sample_outputs": ["SIMILAR", "0 0"], "notes": "NoteFirst sample has two equal formulas, so they are similar by definition.In second sample if we compute first function with x1\u2009=\u20090 and x2\u2009=\u20090 we get the result 0, because . But the second formula is 1, because ."}, "src_uid": "e7f585455aaf039aa6f0f2846d818b40"} {"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": "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": "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": "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": "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": "Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is $$$\\{0,1,\u2026,M-1\\}$$$, for some positive integer $$$M$$$. Ajs draws a number from the first bag and a number from the second bag, and then sums them modulo $$$M$$$.What are the residues modulo $$$M$$$ that Ajs cannot obtain with this action?", "input_spec": "The first line contains two positive integer $$$N$$$ ($$$1 \\leq N \\leq 200\\,000$$$) and $$$M$$$ ($$$N+1 \\leq M \\leq 10^{9}$$$), denoting the number of the elements in the first bag and the modulus, respectively. The second line contains $$$N$$$ nonnegative integers $$$a_1,a_2,\\ldots,a_N$$$ ($$$0 \\leq a_1<a_2< \\ldots< a_N<M$$$), the contents of the first bag. ", "output_spec": "In the first line, output the cardinality $$$K$$$ of the set of residues modulo $$$M$$$ which Ajs cannot obtain. In the second line of the output, print $$$K$$$ space-separated integers greater or equal than zero and less than $$$M$$$, which represent the residues Ajs cannot obtain. The outputs should be sorted in increasing order of magnitude. If $$$K$$$=0, do not output the second line.", "sample_inputs": ["2 5\n3 4", "4 1000000000\n5 25 125 625", "2 4\n1 3"], "sample_outputs": ["1\n2", "0", "2\n0 2"], "notes": "NoteIn the first sample, the first bag and the second bag contain $$$\\{3,4\\}$$$ and $$$\\{0,1,2\\}$$$, respectively. Ajs can obtain every residue modulo $$$5$$$ except the residue $$$2$$$: $$$ 4+1 \\equiv 0, \\, 4+2 \\equiv 1, \\, 3+0 \\equiv 3, \\, 3+1 \\equiv 4 $$$ modulo $$$5$$$. One can check that there is no choice of elements from the first and the second bag which sum to $$$2$$$ modulo $$$5$$$.In the second sample, the contents of the first bag are $$$\\{5,25,125,625\\}$$$, while the second bag contains all other nonnegative integers with at most $$$9$$$ decimal digits. Every residue modulo $$$1\\,000\\,000\\,000$$$ can be obtained as a sum of an element in the first bag and an element in the second bag."}, "src_uid": "6a9f683dee69a7be2d06ec6646970f19"} {"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've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.", "input_spec": "The first and the single line contains three space-separated integers \u2014 the areas of the parallelepiped's faces. The area's values are positive (\u2009>\u20090) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.", "output_spec": "Print a single number \u2014 the sum of all edges of the parallelepiped.", "sample_inputs": ["1 1 1", "4 6 6"], "sample_outputs": ["12", "28"], "notes": "NoteIn the first sample the parallelepiped has sizes 1\u2009\u00d7\u20091\u2009\u00d7\u20091, in the second one\u00a0\u2014 2\u2009\u00d7\u20092\u2009\u00d7\u20093."}, "src_uid": "c0a3290be3b87f3a232ec19d4639fefc"} {"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": "Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!In the morning, there are $$$n$$$ opportunities to buy shares. The $$$i$$$-th of them allows to buy as many shares as you want, each at the price of $$$s_i$$$ bourles.In the evening, there are $$$m$$$ opportunities to sell shares. The $$$i$$$-th of them allows to sell as many shares as you want, each at the price of $$$b_i$$$ bourles. You can't sell more shares than you have.It's morning now and you possess $$$r$$$ bourles and no shares.What is the maximum number of bourles you can hold after the evening?", "input_spec": "The first line of the input contains three integers $$$n, m, r$$$ ($$$1 \\leq n \\leq 30$$$, $$$1 \\leq m \\leq 30$$$, $$$1 \\leq r \\leq 1000$$$) \u2014 the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now. The next line contains $$$n$$$ integers $$$s_1, s_2, \\dots, s_n$$$ ($$$1 \\leq s_i \\leq 1000$$$); $$$s_i$$$ indicates the opportunity to buy shares at the price of $$$s_i$$$ bourles. The following line contains $$$m$$$ integers $$$b_1, b_2, \\dots, b_m$$$ ($$$1 \\leq b_i \\leq 1000$$$); $$$b_i$$$ indicates the opportunity to sell shares at the price of $$$b_i$$$ bourles.", "output_spec": "Output a single integer \u2014 the maximum number of bourles you can hold after the evening.", "sample_inputs": ["3 4 11\n4 2 5\n4 4 5 4", "2 2 50\n5 7\n4 2"], "sample_outputs": ["26", "50"], "notes": "NoteIn the first example test, you have $$$11$$$ bourles in the morning. It's optimal to buy $$$5$$$ shares of a stock at the price of $$$2$$$ bourles in the morning, and then to sell all of them at the price of $$$5$$$ bourles in the evening. It's easy to verify that you'll have $$$26$$$ bourles after the evening.In the second example test, it's optimal not to take any action."}, "src_uid": "42f25d492bddc12d3d89d39315d63cb9"} {"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": "You are given a permutation $$$a_1, a_2, \\dots, a_n$$$ of numbers from $$$1$$$ to $$$n$$$. Also, you have $$$n$$$ sets $$$S_1,S_2,\\dots, S_n$$$, where $$$S_i=\\{a_i\\}$$$. Lastly, you have a variable $$$cnt$$$, representing the current number of sets. Initially, $$$cnt = n$$$.We define two kinds of functions on sets:$$$f(S)=\\min\\limits_{u\\in S} u$$$;$$$g(S)=\\max\\limits_{u\\in S} u$$$.You can obtain a new set by merging two sets $$$A$$$ and $$$B$$$, if they satisfy $$$g(A)<f(B)$$$ (Notice that the old sets do not disappear).Formally, you can perform the following sequence of operations:$$$cnt\\gets cnt+1$$$;$$$S_{cnt}=S_u\\cup S_v$$$, you are free to choose $$$u$$$ and $$$v$$$ for which $$$1\\le u, v < cnt$$$ and which satisfy $$$g(S_u)<f(S_v)$$$.You are required to obtain some specific sets.There are $$$q$$$ requirements, each of which contains two integers $$$l_i$$$,$$$r_i$$$, which means that there must exist a set $$$S_{k_i}$$$ ($$$k_i$$$ is the ID of the set, you should determine it) which equals $$$\\{a_u\\mid l_i\\leq u\\leq r_i\\}$$$, which is, the set consisting of all $$$a_i$$$ with indices between $$$l_i$$$ and $$$r_i$$$.In the end you must ensure that $$$cnt\\leq 2.2\\times 10^6$$$. Note that you don't have to minimize $$$cnt$$$. It is guaranteed that a solution under given constraints exists.", "input_spec": "The first line contains two integers $$$n,q$$$ $$$(1\\leq n \\leq 2^{12},1 \\leq q \\leq 2^{16})$$$ \u00a0\u2014 the length of the permutation and the number of needed sets correspondently. The next line consists of $$$n$$$ integers $$$a_1,a_2,\\cdots, a_n$$$ ($$$1\\leq a_i\\leq n$$$, $$$a_i$$$ are pairwise distinct) \u00a0\u2014 given permutation. $$$i$$$-th of the next $$$q$$$ lines contains two integers $$$l_i,r_i$$$ $$$(1\\leq l_i\\leq r_i\\leq n)$$$, describing a requirement of the $$$i$$$-th set.", "output_spec": "It is guaranteed that a solution under given constraints exists. The first line should contain one integer $$$cnt_E$$$ $$$(n\\leq cnt_E\\leq 2.2\\times 10^6)$$$, representing the number of sets after all operations. $$$cnt_E-n$$$ lines must follow, each line should contain two integers $$$u$$$, $$$v$$$ ($$$1\\leq u, v\\leq cnt'$$$, where $$$cnt'$$$ is the value of $$$cnt$$$ before this operation), meaning that you choose $$$S_u$$$, $$$S_v$$$ and perform a merging operation. In an operation, $$$g(S_u)<f(S_v)$$$ must be satisfied. The last line should contain $$$q$$$ integers $$$k_1,k_2,\\cdots,k_q$$$ $$$(1\\leq k_i\\leq cnt_E)$$$, representing that set $$$S_{k_i}$$$ is the $$$i$$$th required set. Please notice the large amount of output.", "sample_inputs": ["3 2\n1 3 2\n2 3\n1 3", "2 4\n2 1\n1 2\n1 2\n1 2\n1 1"], "sample_outputs": ["6\n3 2\n1 3\n5 2\n4 6", "5\n2 1\n2 1\n2 1\n5 3 3 1"], "notes": "NoteIn the first sample:We have $$$S_1=\\{1\\},S_2=\\{3\\},S_3=\\{2\\}$$$ initially.In the first operation, because $$$g(S_3)=2<f(S_2)=3$$$, we can merge $$$S_3,S_2$$$ into $$$S_4=\\{2,3\\}$$$.In the second operation, because $$$g(S_1)=1<f(S_3)=2$$$, we can merge $$$S_1,S_3$$$ into $$$S_5=\\{1,2\\}$$$.In the third operation, because $$$g(S_5)=2<f(S_2)=3$$$, we can merge $$$S_5,S_2$$$ into $$$S_6=\\{1,2,3\\}$$$.For the first requirement, $$$S_4=\\{2,3\\}=\\{a_2,a_3\\}$$$, satisfies it, thus $$$k_1=4$$$.For the second requirement, $$$S_6=\\{1,2,3\\}=\\{a_1,a_2,a_3\\}$$$, satisfies it, thus $$$k_2=6$$$Notice that unused sets, identical sets, outputting the same set multiple times, and using sets that are present initially are all allowed."}, "src_uid": "60cf596ad4853ebf3bbf9a96ef5d8791"} {"nl": {"description": "There are $$$n$$$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th box contains $$$r_i$$$ candies, candies have the color $$$c_i$$$ (the color can take one of three values \u200b\u200b\u2014 red, green, or blue). All candies inside a single box have the same color (and it is equal to $$$c_i$$$).Initially, Tanya is next to the box number $$$s$$$. Tanya can move to the neighbor box (that is, with a number that differs by one) or eat candies in the current box. Tanya eats candies instantly, but the movement takes one second.If Tanya eats candies from the box, then the box itself remains in place, but there is no more candies in it. In other words, Tanya always eats all the candies from the box and candies in the boxes are not refilled.It is known that Tanya cannot eat candies of the same color one after another (that is, the colors of candies in two consecutive boxes from which she eats candies are always different). In addition, Tanya's appetite is constantly growing, so in each next box from which she eats candies, there should be strictly more candies than in the previous one.Note that for the first box from which Tanya will eat candies, there are no restrictions on the color and number of candies.Tanya wants to eat at least $$$k$$$ candies. What is the minimum number of seconds she will need? Remember that she eats candies instantly, and time is spent only on movements.", "input_spec": "The first line contains three integers $$$n$$$, $$$s$$$ and $$$k$$$ ($$$1 \\le n \\le 50$$$, $$$1 \\le s \\le n$$$, $$$1 \\le k \\le 2000$$$) \u2014 number of the boxes, initial position of Tanya and lower bound on number of candies to eat. The following line contains $$$n$$$ integers $$$r_i$$$ ($$$1 \\le r_i \\le 50$$$) \u2014 numbers of candies in the boxes. The third line contains sequence of $$$n$$$ letters 'R', 'G' and 'B', meaning the colors of candies in the correspondent boxes ('R' for red, 'G' for green, 'B' for blue). Recall that each box contains candies of only one color. The third line contains no spaces.", "output_spec": "Print minimal number of seconds to eat at least $$$k$$$ candies. If solution doesn't exist, print \"-1\".", "sample_inputs": ["5 3 10\n1 2 3 4 5\nRGBRR", "2 1 15\n5 6\nRG"], "sample_outputs": ["4", "-1"], "notes": "NoteThe sequence of actions of Tanya for the first example: move from the box $$$3$$$ to the box $$$2$$$; eat candies from the box $$$2$$$; move from the box $$$2$$$ to the box $$$3$$$; eat candy from the box $$$3$$$; move from the box $$$3$$$ to the box $$$4$$$; move from the box $$$4$$$ to the box $$$5$$$; eat candies from the box $$$5$$$. Since Tanya eats candy instantly, the required time is four seconds."}, "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f"} {"nl": {"description": "For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.He knows that this year n competitions will take place. During the i-th competition the participant must as quickly as possible complete a ride along a straight line from point si to point fi (si\u2009<\u2009fi).Measuring time is a complex process related to usage of a special sensor and a time counter. Think of the front wheel of a bicycle as a circle of radius r. Let's neglect the thickness of a tire, the size of the sensor, and all physical effects. The sensor is placed on the rim of the wheel, that is, on some fixed point on a circle of radius r. After that the counter moves just like the chosen point of the circle, i.e. moves forward and rotates around the center of the circle.At the beginning each participant can choose any point bi, such that his bike is fully behind the starting line, that is, bi\u2009<\u2009si\u2009-\u2009r. After that, he starts the movement, instantly accelerates to his maximum speed and at time tsi, when the coordinate of the sensor is equal to the coordinate of the start, the time counter starts. The cyclist makes a complete ride, moving with his maximum speed and at the moment the sensor's coordinate is equal to the coordinate of the finish (moment of time tfi), the time counter deactivates and records the final time. Thus, the counter records that the participant made a complete ride in time tfi\u2009-\u2009tsi. Maxim is good at math and he suspects that the total result doesn't only depend on his maximum speed v, but also on his choice of the initial point bi. Now Maxim is asking you to calculate for each of n competitions the minimum possible time that can be measured by the time counter. The radius of the wheel of his bike is equal to r.", "input_spec": "The first line contains three integers n, r and v (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000,\u20091\u2009\u2264\u2009r,\u2009v\u2009\u2264\u2009109)\u00a0\u2014 the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively. Next n lines contain the descriptions of the contests. The i-th line contains two integers si and fi (1\u2009\u2264\u2009si\u2009<\u2009fi\u2009\u2264\u2009109)\u00a0\u2014 the coordinate of the start and the coordinate of the finish on the i-th competition.", "output_spec": "Print n real numbers, the i-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10\u2009-\u20096. Namely: let's assume that your answer equals a, and the answer of the jury is b. The checker program will consider your answer correct if .", "sample_inputs": ["2 1 2\n1 10\n5 9"], "sample_outputs": ["3.849644710502\n1.106060157705"], "notes": null}, "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88"} {"nl": {"description": "If you have gone that far, you'll probably skip unnecessary legends anyway...You are given a binary string and an integer . Find the number of integers k, 0\u2009\u2264\u2009k\u2009<\u2009N, such that for all i\u2009=\u20090, 1, ..., m\u2009-\u20091 Print the answer modulo 109\u2009+\u20097.", "input_spec": "In the first line of input there is a string s consisting of 0's and 1's (1\u2009\u2264\u2009|s|\u2009\u2264\u200940). In the next line of input there is an integer n (1\u2009\u2264\u2009n\u2009\u2264\u20095\u00b7105). Each of the next n lines contains two space-separated integers pi, \u03b1i (1\u2009\u2264\u2009pi,\u2009\u03b1i\u2009\u2264\u2009109, pi is prime). All pi are distinct.", "output_spec": "A single integer\u00a0\u2014 the answer to the problem.", "sample_inputs": ["1\n2\n2 1\n3 1", "01\n2\n3 2\n5 1", "1011\n1\n3 1000000000"], "sample_outputs": ["2", "15", "411979884"], "notes": null}, "src_uid": "a0140a8fc4215acec5f046485bc2c7f9"} {"nl": {"description": "Little Petya likes positive integers a lot. Recently his mom has presented him a positive integer a. There's only one thing Petya likes more than numbers: playing with little Masha. It turned out that Masha already has a positive integer b. Petya decided to turn his number a into the number b consecutively performing the operations of the following two types: Subtract 1 from his number. Choose any integer x from 2 to k, inclusive. Then subtract number (a mod x) from his number a. Operation a mod x means taking the remainder from division of number a by number x. Petya performs one operation per second. Each time he chooses an operation to perform during the current move, no matter what kind of operations he has performed by that moment. In particular, this implies that he can perform the same operation any number of times in a row.Now he wonders in what minimum number of seconds he could transform his number a into number b. Please note that numbers x in the operations of the second type are selected anew each time, independently of each other.", "input_spec": "The only line contains three integers a, b (1\u2009\u2264\u2009b\u2009\u2264\u2009a\u2009\u2264\u20091018) and k (2\u2009\u2264\u2009k\u2009\u2264\u200915). 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 required minimum number of seconds needed to transform number a into number b.", "sample_inputs": ["10 1 4", "6 3 10", "1000000000000000000 1 3"], "sample_outputs": ["6", "2", "666666666666666667"], "notes": "NoteIn the first sample the sequence of numbers that Petya gets as he tries to obtain number b is as follows: 10 \u2009\u2192\u2009 8 \u2009\u2192\u2009 6 \u2009\u2192\u2009 4 \u2009\u2192\u2009 3 \u2009\u2192\u2009 2 \u2009\u2192\u2009 1.In the second sample one of the possible sequences is as follows: 6 \u2009\u2192\u2009 4 \u2009\u2192\u2009 3."}, "src_uid": "bd599d76c83cc1f30c1349ffb51b4273"} {"nl": {"description": "During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.Cube is called solved if for each face of cube all squares on it has the same color.https://en.wikipedia.org/wiki/Rubik's_Cube", "input_spec": "In first line given a sequence of 24 integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u20096), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.", "output_spec": "Print \u00abYES\u00bb (without quotes) if it's possible to solve cube using one rotation and \u00abNO\u00bb (without quotes) otherwise.", "sample_inputs": ["2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4", "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3"], "sample_outputs": ["NO", "YES"], "notes": "NoteIn first test case cube looks like this: In second test case cube looks like this: It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16."}, "src_uid": "881a820aa8184d9553278a0002a3b7c4"} {"nl": {"description": "Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "In the first line print one integer k\u00a0\u2014 number of different values of x satisfying the condition. In next k lines print these values in ascending order.", "sample_inputs": ["21", "20"], "sample_outputs": ["1\n15", "0"], "notes": "NoteIn the first test case x\u2009=\u200915 there is only one variant: 15\u2009+\u20091\u2009+\u20095\u2009=\u200921.In the second test case there are no such x."}, "src_uid": "ae20ae2a16273a0d379932d6e973f878"} {"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": "One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for finding maximum element in an array of n positive integers was too slow. Desperate, Petya decided to use a somewhat unexpected optimization using parameter k, so now his function contains the following code:int fast_max(int n, int a[]) { int ans = 0; int offset = 0; for (int i = 0; i < n; ++i) if (ans < a[i]) { ans = a[i]; offset = 0; } else { offset = offset + 1; if (offset == k) return ans; } return ans;}That way the function iteratively checks array elements, storing the intermediate maximum, and if after k consecutive iterations that maximum has not changed, it is returned as the answer.Now Petya is interested in fault rate of his function. He asked you to find the number of permutations of integers from 1 to n such that the return value of his function on those permutations is not equal to n. Since this number could be very big, output the answer modulo 109\u2009+\u20097.", "input_spec": "The only line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009106), separated by a space\u00a0\u2014 the length of the permutations and the parameter k.", "output_spec": "Output the answer to the problem modulo 109\u2009+\u20097.", "sample_inputs": ["5 2", "5 3", "6 3"], "sample_outputs": ["22", "6", "84"], "notes": "NotePermutations from second example: [4,\u20091,\u20092,\u20093,\u20095], [4,\u20091,\u20093,\u20092,\u20095], [4,\u20092,\u20091,\u20093,\u20095], [4,\u20092,\u20093,\u20091,\u20095], [4,\u20093,\u20091,\u20092,\u20095], [4,\u20093,\u20092,\u20091,\u20095]."}, "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4"} {"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": "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": "Katya recently started to invent programming tasks and prepare her own contests. What she does not like is boring and simple constraints. Katya is fed up with all those \"N does not exceed a thousand\" and \"the sum of ai does not exceed a million\" and she decided to come up with something a little more complicated.The last problem written by Katya deals with strings. The input is a string of small Latin letters. To make the statement longer and strike terror into the people who will solve the contest, Katya came up with the following set of k restrictions of the same type (characters in restrictions can be repeated and some restrictions may contradict each other): The number of characters c1 in a string is not less than l1 and not more than r1. ... The number of characters ci in a string is not less than li and not more than ri. ... The number of characters ck in a string is not less than lk and not more than rk. However, having decided that it is too simple and obvious, Katya added the following condition: a string meets no less than L and not more than R constraints from the above given list.Katya does not like to compose difficult and mean tests, so she just took a big string s and wants to add to the tests all its substrings that meet the constraints. However, Katya got lost in her conditions and asked you to count the number of substrings of the string s that meet the conditions (each occurrence of the substring is counted separately).", "input_spec": "The first line contains a non-empty string s, consisting of small Latin letters. The length of the string s does not exceed 105. The second line contains three space-separated integers k, L and R (0\u2009\u2264\u2009L\u2009\u2264\u2009R\u2009\u2264\u2009k\u2009\u2264\u2009500). Next k lines contain Katya's constrictions in the following form \"ci li ri\". All letters ci are small Latin letters, li and ri are integers (0\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u2009|s|, where |s| is the length of string s). Letters ci are not necessarily different.", "output_spec": "Print a single number \u2014 the number of substrings that meet the constrictions. Please do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use the cout stream or the %I64d specificator.", "sample_inputs": ["codeforces\n2 0 0\no 1 2\ne 1 2", "codeforces\n2 1 1\no 1 2\no 1 2"], "sample_outputs": ["7", "0"], "notes": "NoteIn the first test we should count the number of strings that do not contain characters \"e\" and \"o\". All such strings are as follows (in the order of occurrence in the initial string from the left to the right): \"c\", \"d\"', \"f\", \"r\", \"rc\", \"c\", \"s\".In the second test we cannot achieve fulfilling exactly one of the two identical constrictions, so the answer is 0."}, "src_uid": "948f7747cab468b26cc28a3ff29fabdd"} {"nl": {"description": "You are given a rectangle grid. That grid's size is n\u2009\u00d7\u2009m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates \u2014 a pair of integers (x,\u2009y) (0\u2009\u2264\u2009x\u2009\u2264\u2009n,\u20090\u2009\u2264\u2009y\u2009\u2264\u2009m).Your task is to find a maximum sub-rectangle on the grid (x1,\u2009y1,\u2009x2,\u2009y2) so that it contains the given point (x,\u2009y), and its length-width ratio is exactly (a,\u2009b). In other words the following conditions must hold: 0\u2009\u2264\u2009x1\u2009\u2264\u2009x\u2009\u2264\u2009x2\u2009\u2264\u2009n, 0\u2009\u2264\u2009y1\u2009\u2264\u2009y\u2009\u2264\u2009y2\u2009\u2264\u2009m, .The sides of this sub-rectangle should be parallel to the axes. And values x1,\u2009y1,\u2009x2,\u2009y2 should be integers. If there are multiple solutions, find the rectangle which is closest to (x,\u2009y). Here \"closest\" means the Euclid distance between (x,\u2009y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here \"lexicographically minimum\" means that we should consider the sub-rectangle as sequence of integers (x1,\u2009y1,\u2009x2,\u2009y2), so we can choose the lexicographically minimum one.", "input_spec": "The first line contains six integers n,\u2009m,\u2009x,\u2009y,\u2009a,\u2009b (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009109,\u20090\u2009\u2264\u2009x\u2009\u2264\u2009n,\u20090\u2009\u2264\u2009y\u2009\u2264\u2009m,\u20091\u2009\u2264\u2009a\u2009\u2264\u2009n,\u20091\u2009\u2264\u2009b\u2009\u2264\u2009m).", "output_spec": "Print four integers x1,\u2009y1,\u2009x2,\u2009y2, which represent the founded sub-rectangle whose left-bottom point is (x1,\u2009y1) and right-up point is (x2,\u2009y2).", "sample_inputs": ["9 9 5 5 2 1", "100 100 52 50 46 56"], "sample_outputs": ["1 3 9 7", "17 8 86 92"], "notes": null}, "src_uid": "8f1211b995f35462ae83b2be27f54585"} {"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": "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": "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": "The Oak has $$$n$$$ nesting places, numbered with integers from $$$1$$$ to $$$n$$$. Nesting place $$$i$$$ is home to $$$b_i$$$ bees and $$$w_i$$$ wasps.Some nesting places are connected by branches. We call two nesting places adjacent if there exists a branch between them. A simple path from nesting place $$$x$$$ to $$$y$$$ is given by a sequence $$$s_0, \\ldots, s_p$$$ of distinct nesting places, where $$$p$$$ is a non-negative integer, $$$s_0 = x$$$, $$$s_p = y$$$, and $$$s_{i-1}$$$ and $$$s_{i}$$$ are adjacent for each $$$i = 1, \\ldots, p$$$. The branches of The Oak are set up in such a way that for any two pairs of nesting places $$$x$$$ and $$$y$$$, there exists a unique simple path from $$$x$$$ to $$$y$$$. Because of this, biologists and computer scientists agree that The Oak is in fact, a tree.A village is a nonempty set $$$V$$$ of nesting places such that for any two $$$x$$$ and $$$y$$$ in $$$V$$$, there exists a simple path from $$$x$$$ to $$$y$$$ whose intermediate nesting places all lie in $$$V$$$. A set of villages $$$\\cal P$$$ is called a partition if each of the $$$n$$$ nesting places is contained in exactly one of the villages in $$$\\cal P$$$. In other words, no two villages in $$$\\cal P$$$ share any common nesting place, and altogether, they contain all $$$n$$$ nesting places.The Oak holds its annual Miss Punyverse beauty pageant. The two contestants this year are Ugly Wasp and Pretty Bee. The winner of the beauty pageant is determined by voting, which we will now explain. Suppose $$$\\mathcal{P}$$$ is a partition of the nesting places into $$$m$$$ villages $$$V_1, \\ldots, V_m$$$. There is a local election in each village. Each of the insects in this village vote for their favorite contestant. If there are strictly more votes for Ugly Wasp than Pretty Bee, then Ugly Wasp is said to win in that village. Otherwise, Pretty Bee wins. Whoever wins in the most number of villages wins.As it always goes with these pageants, bees always vote for the bee (which is Pretty Bee this year) and wasps always vote for the wasp (which is Ugly Wasp this year). Unlike their general elections, no one abstains from voting for Miss Punyverse as everyone takes it very seriously.Mayor Waspacito, and his assistant Alexwasp, wants Ugly Wasp to win. He has the power to choose how to partition The Oak into exactly $$$m$$$ villages. If he chooses the partition optimally, determine the maximum number of villages in which Ugly Wasp wins.", "input_spec": "The first line of input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) denoting the number of test cases. The next lines contain descriptions of the test cases. The first line of each test case contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \\le m \\le n \\le 3000$$$). The second line contains $$$n$$$ space-separated integers $$$b_1, b_2, \\ldots, b_n$$$ ($$$0 \\le b_i \\le 10^9$$$). The third line contains $$$n$$$ space-separated integers $$$w_1, w_2, \\ldots, w_n$$$ ($$$0 \\le w_i \\le 10^9$$$). The next $$$n - 1$$$ lines describe the pairs of adjacent nesting places. In particular, the $$$i$$$-th of them contains two space-separated integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \\le x_i, y_i \\le n$$$, $$$x_i \\neq y_i$$$) denoting the numbers of two adjacent nesting places. It is guaranteed that these pairs form a tree. It is guaranteed that the sum of $$$n$$$ in a single file is at most $$$10^5$$$.", "output_spec": "For each test case, output a single line containing a single integer denoting the maximum number of villages in which Ugly Wasp wins, among all partitions of The Oak into $$$m$$$ villages.", "sample_inputs": ["2\n4 3\n10 160 70 50\n70 111 111 0\n1 2\n2 3\n3 4\n2 1\n143 420\n214 349\n2 1"], "sample_outputs": ["2\n0"], "notes": "NoteIn the first test case, we need to partition the $$$n = 4$$$ nesting places into $$$m = 3$$$ villages. We can make Ugly Wasp win in $$$2$$$ villages via the following partition: $$$\\{\\{1, 2\\}, \\{3\\}, \\{4\\}\\}$$$. In this partition, Ugly Wasp wins in village $$$\\{1, 2\\}$$$, garnering $$$181$$$ votes as opposed to Pretty Bee's $$$170$$$; Ugly Wasp also wins in village $$$\\{3\\}$$$, garnering $$$111$$$ votes as opposed to Pretty Bee's $$$70$$$; Ugly Wasp loses in the village $$$\\{4\\}$$$, garnering $$$0$$$ votes as opposed to Pretty Bee's $$$50$$$. Thus, Ugly Wasp wins in $$$2$$$ villages, and it can be shown that this is the maximum possible number.In the second test case, we need to partition the $$$n = 2$$$ nesting places into $$$m = 1$$$ village. There is only one way to do this: $$$\\{\\{1, 2\\}\\}$$$. In this partition's sole village, Ugly Wasp gets $$$563$$$ votes, and Pretty Bee also gets $$$563$$$ votes. Ugly Wasp needs strictly more votes in order to win. Therefore, Ugly Wasp doesn't win in any village."}, "src_uid": "d2d1d8c8532b652f172e87a151adae4f"} {"nl": {"description": "One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si \u2014 lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset \u2014 print \u00abYES\u00bb, if he can, and \u00abNO\u00bb, otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009100) \u2014 the number of baloons and friends. Next line contains string s \u2014 colors of baloons.", "output_spec": "Answer to the task \u2014 \u00abYES\u00bb or \u00abNO\u00bb in a single line. You can choose the case (lower or upper) for each letter arbitrary.", "sample_inputs": ["4 2\naabb", "6 3\naacaab"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is \u00abNO\u00bb."}, "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"nl": {"description": "\u041d\u0430 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043d\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0438\u0434\u0438\u0442 n \u0441\u043e\u0431\u0430\u0447\u0435\u043a, i-\u044f \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0442\u043e\u0447\u043a\u0435 xi. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430 \u043f\u0440\u044f\u043c\u043e\u0439 \u0435\u0441\u0442\u044c m \u043c\u0438\u0441\u043e\u043a \u0441 \u0435\u0434\u043e\u0439, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0435\u0451 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u043d\u0430 \u043f\u0440\u044f\u043c\u043e\u0439 uj \u0438 \u0432\u0440\u0435\u043c\u044f tj, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0435\u0434\u0430 \u0432 \u043c\u0438\u0441\u043a\u0435 \u043e\u0441\u0442\u044b\u043d\u0435\u0442 \u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0435\u0432\u043a\u0443\u0441\u043d\u043e\u0439. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u043f\u0440\u0438\u0431\u0435\u0436\u0438\u0442 \u043a \u043c\u0438\u0441\u043a\u0435 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0441\u0442\u0440\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u0439 tj, \u0442\u043e \u0435\u0434\u0430 \u0443\u0436\u0435 \u043e\u0441\u0442\u044b\u043d\u0435\u0442, \u0438 \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u043a\u0443\u0448\u0430\u0442\u044c \u0435\u0451 \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442.\u0421\u0447\u0438\u0442\u0430\u044f, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u0431\u0435\u0436\u0438\u0442 \u0441\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e 1, \u043d\u0430\u0439\u0434\u0438\u0442\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u0430\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043a\u0443\u0448\u0430\u0442\u044c. \u0421\u0447\u0438\u0442\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0441\u043e\u0431\u0430\u0447\u043a\u0438 \u043f\u043e\u0431\u0435\u0433\u0443\u0442 \u043a \u0442\u0435\u043c \u043c\u0438\u0441\u043a\u0430\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0438\u043c \u0443\u043a\u0430\u0436\u0435\u0442\u0435. \u0418\u0437 \u043e\u0434\u043d\u043e\u0439 \u043c\u0438\u0441\u043a\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043a\u0443\u0448\u0430\u0442\u044c \u0434\u0432\u0435 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u0431\u0430\u0447\u043a\u0438.\u0421\u043e\u0431\u0430\u0447\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0433\u043e\u043d\u044f\u0442\u044c \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0442\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043a\u0443\u0448\u0430\u0442\u044c, \u0434\u0440\u0443\u0433\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438 \u043c\u0438\u043c\u043e \u043d\u0435\u0451, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0438\u0441\u043a\u0435.", "input_spec": "\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0430\u0440\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b n \u0438 m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009200\u2009000)\u00a0\u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u0430\u0447\u0435\u043a \u0438 \u043c\u0438\u0441\u043e\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f n \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b xi (\u2009-\u2009109\u2009\u2264\u2009xi\u2009\u2264\u2009109)\u00a0\u2014 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 i-\u0439 \u0441\u043e\u0431\u0430\u0447\u043a\u0438. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 m \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u0430\u0440\u044b \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b uj \u0438 tj (\u2009-\u2009109\u2009\u2264\u2009uj\u2009\u2264\u2009109, 1\u2009\u2264\u2009tj\u2009\u2264\u2009109)\u00a0\u2014 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 j-\u0439 \u043c\u0438\u0441\u043a\u0438 \u0438 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0442\u044b\u043d\u0435\u0442 \u0435\u0434\u0430 \u0432 \u043d\u0435\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0432\u0435 \u0441\u043e\u0431\u0430\u0447\u043a\u0438 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0435. \u041d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0432\u0435 \u043c\u0438\u0441\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0435.", "output_spec": "\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e a\u00a0\u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u0430\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043a\u0443\u0448\u0430\u0442\u044c.", "sample_inputs": ["5 4\n-2 0 4 8 13\n-1 1\n4 3\n6 3\n11 2", "3 3\n-1 3 7\n1 1\n4 1\n7 1", "4 4\n20 1 10 30\n1 1\n2 5\n22 2\n40 10"], "sample_outputs": ["4", "2", "3"], "notes": "\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u043f\u043e\u0431\u0435\u0436\u0438\u0442 \u043d\u0430\u043f\u0440\u0430\u0432\u043e \u043a \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u0438\u0441\u043a\u0435, \u0442\u0440\u0435\u0442\u044c\u044f \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u0447\u043d\u0451\u0442 \u0435\u0441\u0442\u044c \u0438\u0437 \u0432\u0442\u043e\u0440\u043e\u0439 \u043c\u0438\u0441\u043a\u0438, \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u0430\u044f \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u043f\u043e\u0431\u0435\u0436\u0438\u0442 \u0432\u043b\u0435\u0432\u043e \u043a \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u043c\u0438\u0441\u043a\u0435, \u0430 \u043f\u044f\u0442\u0430\u044f \u0441\u043e\u0431\u0430\u0447\u043a\u0430 \u043f\u043e\u0431\u0435\u0436\u0438\u0442 \u0432\u043b\u0435\u0432\u043e \u043a \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u043e\u0439 \u043c\u0438\u0441\u043a\u0435."}, "src_uid": "04375596477fc65a2093554ff7b7934d"} {"nl": {"description": "Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitonesVasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads \u2014 major and minor.Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z \u2014 4 semitones.For example, the triad \"C E G\" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet \"C# B F\" is minor, because if we order the notes as \"B C# F\", than between B and C# will be 3 semitones, and between C# and F \u2014 4 semitones.Help Vasya classify the triad the teacher has given to him.", "input_spec": "The only line contains 3 space-separated notes in the above-given notation.", "output_spec": "Print \"major\" if the chord is major, \"minor\" if it is minor, and \"strange\" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.", "sample_inputs": ["C E G", "C# B F", "A B H"], "sample_outputs": ["major", "minor", "strange"], "notes": null}, "src_uid": "6aa83c2f6e095848bc63aba7d013aa58"} {"nl": {"description": "Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter $$$y$$$ Koa selects can be any letter from the first $$$20$$$ lowercase letters of English alphabet (read statement for better understanding). You can make hacks in these problems independently.Koa the Koala has two strings $$$A$$$ and $$$B$$$ of the same length $$$n$$$ ($$$|A|=|B|=n$$$) consisting of the first $$$20$$$ lowercase English alphabet letters (ie. from a to t).In one move Koa: selects some subset of positions $$$p_1, p_2, \\ldots, p_k$$$ ($$$k \\ge 1; 1 \\le p_i \\le n; p_i \\neq p_j$$$ if $$$i \\neq j$$$) of $$$A$$$ such that $$$A_{p_1} = A_{p_2} = \\ldots = A_{p_k} = x$$$ (ie. all letters on this positions are equal to some letter $$$x$$$). selects any letter $$$y$$$ (from the first $$$20$$$ lowercase letters in English alphabet). sets each letter in positions $$$p_1, p_2, \\ldots, p_k$$$ to letter $$$y$$$. More formally: for each $$$i$$$ ($$$1 \\le i \\le k$$$) Koa sets $$$A_{p_i} = y$$$. Note that you can only modify letters in string $$$A$$$.Koa wants to know the smallest number of moves she has to do to make strings equal to each other ($$$A = B$$$) or to determine that there is no way to make them equal. Help her!", "input_spec": "Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \\le t \\le 10$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$)\u00a0\u2014 the length of strings $$$A$$$ and $$$B$$$. The second line of each test case contains string $$$A$$$ ($$$|A|=n$$$). The third line of each test case contains string $$$B$$$ ($$$|B|=n$$$). Both strings consists of the first $$$20$$$ lowercase English alphabet letters (ie. from a to t). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.", "output_spec": "For each test case: Print on a single line the smallest number of moves she has to do to make strings equal to each other ($$$A = B$$$) or $$$-1$$$ if there is no way to make them equal.", "sample_inputs": ["5\n3\naab\nbcc\n4\ncabc\nabcb\n3\nabc\ntsr\n4\naabd\ncccd\n5\nabcbd\nbcdda"], "sample_outputs": ["2\n3\n3\n2\n4"], "notes": "Note In the $$$1$$$-st test case Koa: selects positions $$$1$$$ and $$$2$$$ and sets $$$A_1 = A_2 = $$$ b ($$$\\color{red}{aa}b \\rightarrow \\color{blue}{bb}b$$$). selects positions $$$2$$$ and $$$3$$$ and sets $$$A_2 = A_3 = $$$ c ($$$b\\color{red}{bb} \\rightarrow b\\color{blue}{cc}$$$). In the $$$2$$$-nd test case Koa: selects positions $$$1$$$ and $$$4$$$ and sets $$$A_1 = A_4 = $$$ a ($$$\\color{red}{c}ab\\color{red}{c} \\rightarrow \\color{blue}{a}ab\\color{blue}{a}$$$). selects positions $$$2$$$ and $$$4$$$ and sets $$$A_2 = A_4 = $$$ b ($$$a\\color{red}{a}b\\color{red}{a} \\rightarrow a\\color{blue}{b}b\\color{blue}{b}$$$). selects position $$$3$$$ and sets $$$A_3 = $$$ c ($$$ab\\color{red}{b}b \\rightarrow ab\\color{blue}{c}b$$$). In the $$$3$$$-rd test case Koa: selects position $$$1$$$ and sets $$$A_1 = $$$ t ($$$\\color{red}{a}bc \\rightarrow \\color{blue}{t}bc$$$). selects position $$$2$$$ and sets $$$A_2 = $$$ s ($$$t\\color{red}{b}c \\rightarrow t\\color{blue}{s}c$$$). selects position $$$3$$$ and sets $$$A_3 = $$$ r ($$$ts\\color{red}{c} \\rightarrow ts\\color{blue}{r}$$$). "}, "src_uid": "d0735a763e2a40bfc94085019cd646f0"} {"nl": {"description": "Kuro has recently won the \"Most intelligent cat ever\" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.The paper is divided into $$$n$$$ pieces enumerated from $$$1$$$ to $$$n$$$. Shiro has painted some pieces with some color. Specifically, the $$$i$$$-th piece has color $$$c_{i}$$$ where $$$c_{i} = 0$$$ defines black color, $$$c_{i} = 1$$$ defines white color and $$$c_{i} = -1$$$ means that the piece hasn't been colored yet.The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($$$0$$$ or $$$1$$$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $$$[1 \\to 0 \\to 1 \\to 0]$$$, $$$[0 \\to 1 \\to 0 \\to 1]$$$, $$$[1]$$$, $$$[0]$$$ are valid paths and will be counted. You can only travel from piece $$$x$$$ to piece $$$y$$$ if and only if there is an arrow from $$$x$$$ to $$$y$$$.But Kuro is not fun yet. He loves parity. Let's call his favorite parity $$$p$$$ where $$$p = 0$$$ stands for \"even\" and $$$p = 1$$$ stands for \"odd\". He wants to put the arrows and choose colors in such a way that the score has the parity of $$$p$$$.It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $$$10^{9} + 7$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \\leq n \\leq 50$$$, $$$0 \\leq p \\leq 1$$$) \u2014 the number of pieces and Kuro's wanted parity. The second line contains $$$n$$$ integers $$$c_{1}, c_{2}, ..., c_{n}$$$ ($$$-1 \\leq c_{i} \\leq 1$$$) \u2014 the colors of the pieces.", "output_spec": "Print a single integer \u2014 the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $$$p$$$.", "sample_inputs": ["3 1\n-1 0 1", "2 1\n1 0", "1 1\n-1"], "sample_outputs": ["6", "1", "2"], "notes": "NoteIn the first example, there are $$$6$$$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $$$3, 3, 5$$$ for the first row and $$$5, 3, 3$$$ for the second row, both from left to right. "}, "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd"} {"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": "In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.", "input_spec": "The single line contains six integers a1,\u2009...,\u2009a6 (0\u2009\u2264\u2009ai\u2009\u2264\u20091000) \u2014 scores of the participants", "output_spec": "Print \"YES\" (quotes for clarity), if it is possible to build teams with equal score, and \"NO\" otherwise. You can print each character either upper- or lowercase (\"YeS\" and \"yes\" are valid when the answer is \"YES\").", "sample_inputs": ["1 3 2 1 2 1", "1 1 1 1 1 99"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample, first team can be composed of 1st, 2nd and 6th participant, second \u2014 of 3rd, 4th and 5th: team scores are 1\u2009+\u20093\u2009+\u20091\u2009=\u20092\u2009+\u20091\u2009+\u20092\u2009=\u20095.In the second sample, score of participant number 6 is too high: his team score will be definitely greater."}, "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"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": "One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.", "input_spec": "The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters \u00abA\u00bb, \u00abB\u00bb and \u00abC\u00bb. Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin \"A\" proved lighter than coin \"B\", the result of the weighting is A<B.", "output_spec": "It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters \u00abA\u00bb, \u00abB\u00bb and \u00abC\u00bb which represent the coins in the increasing order of their weights.", "sample_inputs": ["A>B\nC<B\nA>C", "A<B\nB>C\nC>A"], "sample_outputs": ["CBA", "ACB"], "notes": null}, "src_uid": "97fd9123d0fb511da165b900afbde5dc"} {"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": "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": "An n\u2009\u00d7\u2009n table a is defined as follows: The first row and the first column contain ones, that is: ai,\u20091\u2009=\u2009a1,\u2009i\u2009=\u20091 for all i\u2009=\u20091,\u20092,\u2009...,\u2009n. Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula ai,\u2009j\u2009=\u2009ai\u2009-\u20091,\u2009j\u2009+\u2009ai,\u2009j\u2009-\u20091. These conditions define all the values in the table.You are given a number n. You need to determine the maximum value in the n\u2009\u00d7\u2009n table defined by the rules above.", "input_spec": "The only line of input contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u200910) \u2014 the number of rows and columns of the table.", "output_spec": "Print a single line containing a positive integer m \u2014 the maximum value in the table.", "sample_inputs": ["1", "5"], "sample_outputs": ["1", "70"], "notes": "NoteIn the second test the rows of the table look as follows: {1,\u20091,\u20091,\u20091,\u20091},\u2009 {1,\u20092,\u20093,\u20094,\u20095},\u2009 {1,\u20093,\u20096,\u200910,\u200915},\u2009 {1,\u20094,\u200910,\u200920,\u200935},\u2009 {1,\u20095,\u200915,\u200935,\u200970}."}, "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"nl": {"description": "In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $$$s$$$ starting from the $$$l$$$-th character and ending with the $$$r$$$-th character as $$$s[l \\dots r]$$$. The characters of each string are numbered from $$$1$$$.We can perform several operations on the strings we consider. Each operation is to choose a substring of our string and replace it with another string. There are two possible types of operations: replace 011 with 110, or replace 110 with 011. For example, if we apply exactly one operation to the string 110011110, it can be transformed into 011011110, 110110110, or 110011011.Binary string $$$a$$$ is considered reachable from binary string $$$b$$$ if there exists a sequence $$$s_1$$$, $$$s_2$$$, ..., $$$s_k$$$ such that $$$s_1 = a$$$, $$$s_k = b$$$, and for every $$$i \\in [1, k - 1]$$$, $$$s_i$$$ can be transformed into $$$s_{i + 1}$$$ using exactly one operation. Note that $$$k$$$ can be equal to $$$1$$$, i.\u2009e., every string is reachable from itself.You are given a string $$$t$$$ and $$$q$$$ queries to it. Each query consists of three integers $$$l_1$$$, $$$l_2$$$ and $$$len$$$. To answer each query, you have to determine whether $$$t[l_1 \\dots l_1 + len - 1]$$$ is reachable from $$$t[l_2 \\dots l_2 + len - 1]$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the length of string $$$t$$$. The second line contains one string $$$t$$$ ($$$|t| = n$$$). Each character of $$$t$$$ is either 0 or 1. The third line contains one integer $$$q$$$ ($$$1 \\le q \\le 2 \\cdot 10^5$$$) \u2014 the number of queries. Then $$$q$$$ lines follow, each line represents a query. The $$$i$$$-th line contains three integers $$$l_1$$$, $$$l_2$$$ and $$$len$$$ ($$$1 \\le l_1, l_2 \\le |t|$$$, $$$1 \\le len \\le |t| - \\max(l_1, l_2) + 1$$$) for the $$$i$$$-th query.", "output_spec": "For each query, print either YES if $$$t[l_1 \\dots l_1 + len - 1]$$$ is reachable from $$$t[l_2 \\dots l_2 + len - 1]$$$, or NO otherwise. You may print each letter in any register.", "sample_inputs": ["5\n11011\n3\n1 3 3\n1 4 2\n1 2 3"], "sample_outputs": ["Yes\nYes\nNo"], "notes": null}, "src_uid": "6bd41042c6a442765cd93c73d55f6189"} {"nl": {"description": "Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.Help Vasya count to which girlfriend he will go more often.", "input_spec": "The first line contains two integers a and b (a\u2009\u2260\u2009b,\u20091\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009106).", "output_spec": "Print \"Dasha\" if Vasya will go to Dasha more frequently, \"Masha\" if he will go to Masha more frequently, or \"Equal\" if he will go to both girlfriends with the same frequency.", "sample_inputs": ["3 7", "5 3", "2 3"], "sample_outputs": ["Dasha", "Masha", "Equal"], "notes": "NoteLet's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0,\u20096], he will go to both girls equally often. If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.In sum Masha and Dasha get equal time \u2014 three minutes for each one, thus, Vasya will go to both girlfriends equally often."}, "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc"} {"nl": {"description": "Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below://input: integers x, k, pa = x;for(step = 1; step <= k; step = step + 1){ rnd = [random integer from 1 to 100]; if(rnd <= p) a = a * 2; else a = a + 1;}s = 0;while(remainder after dividing a by 2 equals 0){ a = a / 2; s = s + 1;}Now Valera wonders: given the values x, k and p, what is the expected value of the resulting number s?", "input_spec": "The first line of the input contains three integers x,\u2009k,\u2009p (1\u2009\u2264\u2009x\u2009\u2264\u2009109;\u00a01\u2009\u2264\u2009k\u2009\u2264\u2009200;\u00a00\u2009\u2264\u2009p\u2009\u2264\u2009100).", "output_spec": "Print the required expected value. Your answer will be considered correct if the absolute or relative error doesn't exceed 10\u2009-\u20096.", "sample_inputs": ["1 1 50", "5 3 0", "5 3 25"], "sample_outputs": ["1.0000000000000", "3.0000000000000", "1.9218750000000"], "notes": "NoteIf the concept of expected value is new to you, you can read about it by the link: http://en.wikipedia.org/wiki/Expected_value"}, "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0"} {"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": "You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.", "input_spec": "The first line contains integers n and k \u2014 the number and digit capacity of numbers correspondingly (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u20098). Next n lines contain k-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits.", "output_spec": "Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule.", "sample_inputs": ["6 4\n5237\n2753\n7523\n5723\n5327\n2537", "3 3\n010\n909\n012", "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156"], "sample_outputs": ["2700", "3", "20522"], "notes": "NoteIn the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102."}, "src_uid": "08f85cd4ffbd135f0b630235209273a4"} {"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": "You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself. The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.", "input_spec": "The first line contains the only integer q (1\u2009\u2264\u2009q\u2009\u2264\u20091013). Please do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specificator.", "output_spec": "In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer \u2014 his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.", "sample_inputs": ["6", "30", "1"], "sample_outputs": ["2", "1\n6", "1\n0"], "notes": "NoteNumber 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory."}, "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"} {"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": "Alice and Bob are playing a game with a string of characters, with Alice going first. The string consists n characters, each of which is one of the first k letters of the alphabet. On a player\u2019s turn, they can either arbitrarily permute the characters in the words, or delete exactly one character in the word (if there is at least one character). In addition, their resulting word cannot have appeared before throughout the entire game. The player unable to make a valid move loses the game.Given n,\u2009k,\u2009p, find the number of words with exactly n characters consisting of the first k letters of the alphabet such that Alice will win if both Alice and Bob play optimally. Return this number modulo the prime number p.", "input_spec": "The first line of input will contain three integers n,\u2009k,\u2009p (1\u2009\u2264\u2009n\u2009\u2264\u2009250\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u200926, 108\u2009\u2264\u2009p\u2009\u2264\u2009109\u2009+\u2009100, p will be prime).", "output_spec": "Print a single integer, the number of winning words for Alice, modulo p.", "sample_inputs": ["4 2 100000007"], "sample_outputs": ["14"], "notes": "NoteThere are 14 strings that that Alice can win with. For example, some strings are \"bbaa\" and \"baaa\". Alice will lose on strings like \"aaaa\" or \"bbbb\"."}, "src_uid": "97f737f59100babe5e45e1a82a1f7d99"} {"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": "Consider the following equation: where sign [a] represents the integer part of number a.Let's find all integer z (z\u2009>\u20090), for which this equation is unsolvable in positive integers. The phrase \"unsolvable in positive integers\" means that there are no such positive integers x and y (x,\u2009y\u2009>\u20090), for which the given above equation holds.Let's write out all such z in the increasing order: z1,\u2009z2,\u2009z3, and so on (zi\u2009<\u2009zi\u2009+\u20091). Your task is: given the number n, find the number zn.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200940).", "output_spec": "Print a single integer \u2014 the number zn modulo 1000000007 (109\u2009+\u20097). It is guaranteed that the answer exists.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["1", "3", "15"], "notes": null}, "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7"} {"nl": {"description": "Suppose you are stuck on a desert island. The only way to save yourself is to craft a wooden raft and go to the sea. Fortunately, you have a hand-made saw and a forest nearby. Moreover, you've already cut several trees and prepared it to the point that now you have $$$n$$$ logs and the $$$i$$$-th log has length $$$a_i$$$.The wooden raft you'd like to build has the following structure: $$$2$$$ logs of length $$$x$$$ and $$$x$$$ logs of length $$$y$$$. Such raft would have the area equal to $$$x \\cdot y$$$. Both $$$x$$$ and $$$y$$$ must be integers since it's the only way you can measure the lengths while being on a desert island. And both $$$x$$$ and $$$y$$$ must be at least $$$2$$$ since the raft that is one log wide is unstable.You can cut logs in pieces but you can't merge two logs in one. What is the maximum area of the raft you can craft?", "input_spec": "The first line contains the only integer $$$n$$$ ($$$1 \\le n \\le 5 \\cdot 10^5$$$)\u00a0\u2014 the number of logs you have. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$2 \\le a_i \\le 5 \\cdot 10^5$$$)\u00a0\u2014 the corresponding lengths of the logs. It's guaranteed that you can always craft at least $$$2 \\times 2$$$ raft.", "output_spec": "Print the only integer\u00a0\u2014 the maximum area of the raft you can craft.", "sample_inputs": ["1\n9", "9\n9 10 9 18 9 9 9 28 9"], "sample_outputs": ["4", "90"], "notes": "NoteIn the first example, you can cut the log of the length $$$9$$$ in $$$5$$$ parts: $$$2 + 2 + 2 + 2 + 1$$$. Now you can build $$$2 \\times 2$$$ raft using $$$2$$$ logs of length $$$x = 2$$$ and $$$x = 2$$$ logs of length $$$y = 2$$$.In the second example, you can cut $$$a_4 = 18$$$ into two pieces $$$9 + 9$$$ and $$$a_8 = 28$$$ in three pieces $$$10 + 9 + 9$$$. Now you can make $$$10 \\times 9$$$ raft using $$$2$$$ logs of length $$$10$$$ and $$$10$$$ logs of length $$$9$$$."}, "src_uid": "bca20e0910e9fe4d89326b50ab45e4ca"} {"nl": {"description": "There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates $$$(0, 0)$$$, and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates $$$(x_1, y_1)$$$, and the top right \u2014 $$$(x_2, y_2)$$$.After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are $$$(x_3, y_3)$$$, and the top right \u2014 $$$(x_4, y_4)$$$. Coordinates of the bottom left corner of the second black sheet are $$$(x_5, y_5)$$$, and the top right \u2014 $$$(x_6, y_6)$$$. Example of three rectangles. Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.", "input_spec": "The first line of the input contains four integers $$$x_1, y_1, x_2, y_2$$$ $$$(0 \\le x_1 < x_2 \\le 10^{6}, 0 \\le y_1 < y_2 \\le 10^{6})$$$ \u2014 coordinates of the bottom left and the top right corners of the white sheet. The second line of the input contains four integers $$$x_3, y_3, x_4, y_4$$$ $$$(0 \\le x_3 < x_4 \\le 10^{6}, 0 \\le y_3 < y_4 \\le 10^{6})$$$ \u2014 coordinates of the bottom left and the top right corners of the first black sheet. The third line of the input contains four integers $$$x_5, y_5, x_6, y_6$$$ $$$(0 \\le x_5 < x_6 \\le 10^{6}, 0 \\le y_5 < y_6 \\le 10^{6})$$$ \u2014 coordinates of the bottom left and the top right corners of the second black sheet. The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.", "output_spec": "If some part of the white sheet can be seen from the above after the two black sheets are placed, print \"YES\" (without quotes). Otherwise print \"NO\".", "sample_inputs": ["2 2 4 4\n1 1 3 5\n3 1 5 5", "3 3 7 5\n0 0 4 6\n0 0 7 4", "5 2 10 5\n3 1 7 6\n8 1 11 7", "0 0 1000000 1000000\n0 0 499999 1000000\n500000 0 1000000 1000000"], "sample_outputs": ["NO", "YES", "YES", "YES"], "notes": "NoteIn the first example the white sheet is fully covered by black sheets.In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point $$$(6.5, 4.5)$$$ lies not strictly inside the white sheet and lies strictly outside of both black sheets."}, "src_uid": "05c90c1d75d76a522241af6bb6af7781"} {"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": "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": "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": "You are in charge of the BubbleReactor. It consists of $$$N$$$ BubbleCores connected with $$$N$$$ lines of electrical wiring. Each electrical wiring connects two distinct BubbleCores. There are no BubbleCores connected with more than one line of electrical wiring.Your task is to start the BubbleReactor by starting each BubbleCore. In order for a BubbleCore to be started it needs to be receiving power from a directly connected BubbleCore which is already started. However, you can kick-start one BubbleCore manually without needing power. It is guaranteed that all BubbleCores can be started.Before the BubbleCore boot up procedure its potential is calculated as the number of BubbleCores it can power on (the number of inactive BubbleCores which are connected to it directly or with any number of inactive BubbleCores in between, itself included)Start the BubbleReactor so that the sum of all BubbleCores' potentials is maximum.", "input_spec": "First line contains one integer $$$N (3 \\leq N \\leq 15.000)$$$, the number of BubbleCores. The following N lines contain two integers $$$U, V (0 \\leq U \\neq V < N)$$$ denoting that there exists electrical wiring between BubbleCores $$$U$$$ and $$$V$$$.", "output_spec": "Single integer, the maximum sum of all BubbleCores' potentials.", "sample_inputs": ["10\n0 1\n0 3\n0 4\n0 9\n1 2\n2 3\n2 7\n4 5\n4 6\n7 8"], "sample_outputs": ["51"], "notes": "NoteIf we start by kickstarting BubbleCup 8 and then turning on cores 7, 2, 1, 3, 0, 9, 4, 5, 6 in that order we get potentials 10 + 9 + 8 + 7 + 6 + 5 + 1 + 3 + 1 + 1 = 51"}, "src_uid": "c3da92d4b495d3e99c83a5ffe206709a"} {"nl": {"description": "You are given $$$a$$$ uppercase Latin letters 'A' and $$$b$$$ letters 'B'.The period of the string is the smallest such positive integer $$$k$$$ that $$$s_i = s_{i~mod~k}$$$ ($$$0$$$-indexed) for each $$$i$$$. Note that this implies that $$$k$$$ won't always divide $$$a+b = |s|$$$.For example, the period of string \"ABAABAA\" is $$$3$$$, the period of \"AAAA\" is $$$1$$$, and the period of \"AABBB\" is $$$5$$$.Find the number of different periods over all possible strings with $$$a$$$ letters 'A' and $$$b$$$ letters 'B'.", "input_spec": "The first line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^9$$$) \u2014 the number of letters 'A' and 'B', respectively.", "output_spec": "Print the number of different periods over all possible strings with $$$a$$$ letters 'A' and $$$b$$$ letters 'B'.", "sample_inputs": ["2 4", "5 3"], "sample_outputs": ["4", "5"], "notes": "NoteAll the possible periods for the first example: $$$3$$$ \"BBABBA\" $$$4$$$ \"BBAABB\" $$$5$$$ \"BBBAAB\" $$$6$$$ \"AABBBB\" All the possible periods for the second example: $$$3$$$ \"BAABAABA\" $$$5$$$ \"BAABABAA\" $$$6$$$ \"BABAAABA\" $$$7$$$ \"BAABAAAB\" $$$8$$$ \"AAAAABBB\" Note that these are not the only possible strings for the given periods."}, "src_uid": "0e6a204565fef118ea99d2fa1e378dd0"} {"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": "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": "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": "\"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!\" \u2014 people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy.", "input_spec": "The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index.", "output_spec": "The only line of the output contains an integer between 1 and 3, inclusive.", "sample_inputs": [], "sample_outputs": [], "notes": "NoteThis problem has no samples, since there so few test cases."}, "src_uid": "c702e07fed684b7741d8337aafa005fb"} {"nl": {"description": "Malek is a rich man. He also is very generous. That's why he decided to split his money between poor people. A charity institute knows n poor people numbered from 1 to n. The institute gave Malek q recommendations. A recommendation is a segment of people like [l,\u2009r] which means the institute recommended that Malek gives one dollar to every person whose number is in this segment.However this charity has very odd rules about the recommendations. Because of those rules the recommendations are given in such a way that for every two recommendation [a,\u2009b] and [c,\u2009d] one of the following conditions holds: The two segments are completely disjoint. More formally either a\u2009\u2264\u2009b\u2009<\u2009c\u2009\u2264\u2009d or c\u2009\u2264\u2009d\u2009<\u2009a\u2009\u2264\u2009b One of the two segments are inside another. More formally either a\u2009\u2264\u2009c\u2009\u2264\u2009d\u2009\u2264\u2009b or c\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u2009d. The goodness of a charity is the value of maximum money a person has after Malek finishes giving his money. The institute knows for each recommendation what is the probability that Malek will accept it. They want to know the expected value of goodness of this charity. So they asked you for help.You have been given the list of recommendations and for each recommendation the probability of it being accepted by Malek. You have also been given how much money each person initially has. You must find the expected value of goodness.", "input_spec": "In the first line two space-separated integers n,\u2009q (1\u2009\u2264\u2009n\u2009\u2264\u2009105, 1\u2009\u2264\u2009q\u2009\u2264\u20095000) are given. In the second line n space-separated integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u2009109) are given meaning that person number i initially has ai dollars. Each of the next q lines contains three space-separated numbers li,\u2009ri,\u2009pi (1\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u2009n, 0\u2009\u2264\u2009p\u2009\u2264\u20091) where li and ri are two integers describing the segment of recommendation and pi is a real number given with exactly three digits after decimal point which is equal to probability of Malek accepting this recommendation. Note that a segment may appear several times in recommendations.", "output_spec": "Output the sought value. Your answer will be considered correct if its absolute or relative error is less than 10\u2009-\u20096.", "sample_inputs": ["5 2\n1 7 2 4 3\n1 3 0.500\n2 2 0.500", "5 2\n281 280 279 278 282\n1 4 1.000\n1 4 0.000", "3 5\n1 2 3\n1 3 0.500\n2 2 0.250\n1 2 0.800\n1 1 0.120\n2 2 0.900"], "sample_outputs": ["8.000000000", "282.000000000", "4.465000000"], "notes": null}, "src_uid": "2a6e1be07d3edf6b00998998cf9e621b"} {"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": "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": "Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is \"123456789101112131415...\". Your task is to print the n-th digit of this string (digits are numbered starting with 1.", "input_spec": "The only line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000)\u00a0\u2014 the position of the digit you need to print.", "output_spec": "Print the n-th digit of the line.", "sample_inputs": ["3", "11"], "sample_outputs": ["3", "0"], "notes": "NoteIn the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.In the second sample, the digit at position 11 is '0', it belongs to the integer 10."}, "src_uid": "2d46e34839261eda822f0c23c6e19121"} {"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": "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": "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.Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.", "input_spec": "The single line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number that needs to be checked.", "output_spec": "In the only line print \"YES\" (without the quotes), if number n is almost lucky. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["47", "16", "78"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteNote that all lucky numbers are almost lucky as any number is evenly divisible by itself.In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4."}, "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"nl": {"description": "Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $$$x$$$ in an array. For an array $$$a$$$ indexed from zero, and an integer $$$x$$$ the pseudocode of the algorithm is as follows: Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $$$x$$$!Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $$$n$$$ such that the algorithm finds $$$x$$$ in them. A permutation of size $$$n$$$ is an array consisting of $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ in arbitrary order.Help Andrey and find the number of permutations of size $$$n$$$ which contain $$$x$$$ at position $$$pos$$$ and for which the given implementation of the binary search algorithm finds $$$x$$$ (returns true). As the result may be extremely large, print the remainder of its division by $$$10^9+7$$$.", "input_spec": "The only line of input contains integers $$$n$$$, $$$x$$$ and $$$pos$$$ ($$$1 \\le x \\le n \\le 1000$$$, $$$0 \\le pos \\le n - 1$$$) \u2014 the required length of the permutation, the number to search, and the required position of that number, respectively.", "output_spec": "Print a single number\u00a0\u2014 the remainder of the division of the number of valid permutations by $$$10^9+7$$$.", "sample_inputs": ["4 1 2", "123 42 24"], "sample_outputs": ["6", "824071958"], "notes": "NoteAll possible permutations in the first test case: $$$(2, 3, 1, 4)$$$, $$$(2, 4, 1, 3)$$$, $$$(3, 2, 1, 4)$$$, $$$(3, 4, 1, 2)$$$, $$$(4, 2, 1, 3)$$$, $$$(4, 3, 1, 2)$$$."}, "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"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": "You are given a tree of $$$n$$$ nodes. The tree is rooted at node $$$1$$$, which is not considered as a leaf regardless of its degree.Each leaf of the tree has one of the two colors: red or blue. Leaf node $$$v$$$ initially has color $$$s_{v}$$$.The color of each of the internal nodes (including the root) is determined as follows. Let $$$b$$$ be the number of blue immediate children, and $$$r$$$ be the number of red immediate children of a given vertex. Then the color of this vertex is blue if and only if $$$b - r \\ge k$$$, otherwise red. Integer $$$k$$$ is a parameter that is same for all the nodes.You need to handle the following types of queries: 1 v: print the color of node $$$v$$$; 2 v c: change the color of leaf $$$v$$$ to $$$c$$$ ($$$c = 0$$$ means red, $$$c = 1$$$ means blue); 3 h: update the current value of $$$k$$$ to $$$h$$$. ", "input_spec": "The first line of the input consists of two integers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 10^{5}$$$, $$$-n \\le k \\le n$$$)\u00a0\u2014 the number of nodes and the initial parameter $$$k$$$. Each of the next $$$n - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \\le u,v \\le n$$$), denoting that there is an edge between vertices $$$u$$$ and $$$v$$$. The next line consists of $$$n$$$ space separated integers\u00a0\u2014 the initial array $$$s$$$ ($$$-1 \\le s_i \\le 1$$$). $$$s_{i} = 0$$$ means that the color of node $$$i$$$ is red. $$$s_{i} = 1$$$ means that the color of node $$$i$$$ is blue. $$$s_{i} = -1$$$ means that the node $$$i$$$ is not a leaf. The next line contains an integer $$$q$$$ ($$$1 \\le q \\le 10^5$$$), the number of queries. $$$q$$$ lines follow, each containing a query in one of the following queries: 1 v ($$$1 \\le v \\le n$$$): print the color of node $$$v$$$; 2 v c ($$$1 \\le v \\le n$$$, $$$c = 0$$$ or $$$c = 1$$$): change the color of leaf $$$v$$$ to $$$c$$$ ($$$c = 0$$$ means red, $$$c = 1$$$ means blue). It is guaranteed that $$$v$$$ is a leaf; 3 h ($$$-n \\le h \\le n$$$): update the current value of $$$k$$$ to $$$h$$$. ", "output_spec": "For each query of the first type, print $$$0$$$ if the color of vertex $$$v$$$ is red, and $$$1$$$ otherwise.", "sample_inputs": ["5 2\n1 2\n1 3\n2 4\n2 5\n-1 -1 0 1 0\n9\n1 1\n1 2\n3 -2\n1 1\n1 2\n3 1\n2 5 1\n1 1\n1 2"], "sample_outputs": ["0\n0\n1\n1\n0\n1"], "notes": "Note Figures:(i) The initial tree (ii) The tree after the 3rd query (iii) The tree after the 7th query "}, "src_uid": "a2869b349dc2d47d96b572397978e77d"} {"nl": {"description": "Wabbit is playing a game with $$$n$$$ bosses numbered from $$$1$$$ to $$$n$$$. The bosses can be fought in any order. Each boss needs to be defeated exactly once. There is a parameter called boss bonus which is initially $$$0$$$.When the $$$i$$$-th boss is defeated, the current boss bonus is added to Wabbit's score, and then the value of the boss bonus increases by the point increment $$$c_i$$$. Note that $$$c_i$$$ can be negative, which means that other bosses now give fewer points.However, Wabbit has found a glitch in the game. At any point in time, he can reset the playthrough and start a New Game Plus playthrough. This will set the current boss bonus to $$$0$$$, while all defeated bosses remain defeated. The current score is also saved and does not reset to zero after this operation. This glitch can be used at most $$$k$$$ times. He can reset after defeating any number of bosses (including before or after defeating all of them), and he also can reset the game several times in a row without defeating any boss.Help Wabbit determine the maximum score he can obtain if he has to defeat all $$$n$$$ bosses.", "input_spec": "The first line of input contains two spaced integers $$$n$$$ and $$$k$$$ ($$$1 \\leq n \\leq 5 \\cdot 10^5$$$, $$$0 \\leq k \\leq 5 \\cdot 10^5$$$), representing the number of bosses and the number of resets allowed. The next line of input contains $$$n$$$ spaced integers $$$c_1,c_2,\\ldots,c_n$$$ ($$$-10^6 \\leq c_i \\leq 10^6$$$), the point increments of the $$$n$$$ bosses.", "output_spec": "Output a single integer, the maximum score Wabbit can obtain by defeating all $$$n$$$ bosses (this value may be negative).", "sample_inputs": ["3 0\n1 1 1", "5 1\n-1 -2 -3 -4 5", "13 2\n3 1 4 1 5 -9 -2 -6 -5 -3 -5 -8 -9"], "sample_outputs": ["3", "11", "71"], "notes": "NoteIn the first test case, no resets are allowed. An optimal sequence of fights would be Fight the first boss $$$(+0)$$$. Boss bonus becomes equal to $$$1$$$. Fight the second boss $$$(+1)$$$. Boss bonus becomes equal to $$$2$$$. Fight the third boss $$$(+2)$$$. Boss bonus becomes equal to $$$3$$$. Thus the answer for the first test case is $$$0+1+2=3$$$.In the second test case, it can be shown that one possible optimal sequence of fights is Fight the fifth boss $$$(+0)$$$. Boss bonus becomes equal to $$$5$$$. Fight the first boss $$$(+5)$$$. Boss bonus becomes equal to $$$4$$$. Fight the second boss $$$(+4)$$$. Boss bonus becomes equal to $$$2$$$. Fight the third boss $$$(+2)$$$. Boss bonus becomes equal to $$$-1$$$. Reset. Boss bonus becomes equal to $$$0$$$. Fight the fourth boss $$$(+0)$$$. Boss bonus becomes equal to $$$-4$$$. Hence the answer for the second test case is $$$0+5+4+2+0=11$$$."}, "src_uid": "53155daf2375e01a3b87fa1c76f1e9a8"} {"nl": {"description": "After making a strategic plan with carriers for expansion of mobile network throughout the whole country, the government decided to cover rural areas with the last generation of 5G network.Since 5G antenna towers will be built in the area of mainly private properties, the government needs an easy way to find information about landowners for each property partially or fully contained in the planned building area. The planned building area is represented as a rectangle with sides $$$width$$$ and $$$height$$$.Every 5G antenna tower occupies a circle with a center in $$$(x,y)$$$ and radius $$$r$$$. There is a database of Geodetic Institute containing information about each property. Each property is defined with its identification number and polygon represented as an array of $$$(x,y)$$$ points in the counter-clockwise direction. Your task is to build an IT system which can handle queries of type $$$(x, y, r)$$$ in which $$$(x,y)$$$ represents a circle center, while $$$r$$$ represents its radius. The IT system should return the total area of properties that need to be acquired for the building of a tower so that the government can estimate the price. Furthermore, the system should return a list of identification numbers of these properties (so that the owners can be contacted for land acquisition).A property needs to be acquired if the circle of the antenna tower is intersecting or touching it. ", "input_spec": "The first line contains the size of the building area as double values $$$width$$$, $$$height$$$, and an integer $$$n$$$ \u2014 the number of properties in the database. Each of the next $$$n$$$ lines contains the description of a single property in the form of an integer number $$$v$$$ ($$$3 \\le v \\le 40$$$) \u2014 the number of points that define a property, as well as $$$2*v$$$ double numbers \u2014 the coordinates $$$(x,y)$$$ of each property point. Line $$$i$$$ ($$$0 \\le i \\le n-1$$$) contains the information for property with id $$$i$$$. The next line contains an integer $$$q$$$ \u2014 the number of queries. Each of the next $$$q$$$ lines contains double values $$$x$$$, $$$y$$$, $$$r$$$ \u2014 the coordinates of an antenna circle center $$$(x, y)$$$ and its radius $$$r$$$. $$$1 \\le n * q \\le 10^6$$$", "output_spec": "For each of the $$$q$$$ queries, your program should output a line containing the total area of all the properties that need to be acquired, an integer representing the number of such properties, as well as the list of ids of these properties (separated by blank characters, arbitrary order).", "sample_inputs": ["10 10 3\n4 2 2 3 2 3 3 2 3\n3 3.5 2 4.5 2 4.5 3\n4 7 8 7.5 8.5 8 8 7.5 9\n5\n2 3.5 0.5\n3.3 2 0.4\n5 2.5 0.5\n7.5 8.5 0.5\n3 7 0.5"], "sample_outputs": ["1.000000 1 0 \n1.500000 2 0 1 \n0.500000 1 1 \n0.250000 1 2 \n0.000000 0"], "notes": "NoteYou can assume that the land not covered with properties (polygons) is under the government's ownership and therefore doesn't need to be acquired. Properties do not intersect with each other.Precision being used for solution checking is $$$10^{-4}$$$."}, "src_uid": "a1e94ec65b28e428faac529e602b0fa6"} {"nl": {"description": "Our bear's forest has a checkered field. The checkered field is an n\u2009\u00d7\u2009n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection of row x and column y by record (x,\u2009y). Each cell of the field contains growing raspberry, at that, the cell (x,\u2009y) of the field contains x\u2009+\u2009y raspberry bushes.The bear came out to walk across the field. At the beginning of the walk his speed is (dx,\u2009dy). Then the bear spends exactly t seconds on the field. Each second the following takes place: Let's suppose that at the current moment the bear is in cell (x,\u2009y). First the bear eats the raspberry from all the bushes he has in the current cell. After the bear eats the raspberry from k bushes, he increases each component of his speed by k. In other words, if before eating the k bushes of raspberry his speed was (dx,\u2009dy), then after eating the berry his speed equals (dx\u2009+\u2009k,\u2009dy\u2009+\u2009k). Let's denote the current speed of the bear (dx,\u2009dy) (it was increased after the previous step). Then the bear moves from cell (x,\u2009y) to cell (((x\u2009+\u2009dx\u2009-\u20091)\u00a0mod\u00a0n)\u2009+\u20091,\u2009((y\u2009+\u2009dy\u2009-\u20091)\u00a0mod\u00a0n)\u2009+\u20091). Then one additional raspberry bush grows in each cell of the field. You task is to predict the bear's actions. Find the cell he ends up in if he starts from cell (sx,\u2009sy). Assume that each bush has infinitely much raspberry and the bear will never eat all of it.", "input_spec": "The first line of the input contains six space-separated integers: n, sx, sy, dx, dy, t (1\u2009\u2264\u2009n\u2009\u2264\u2009109;\u00a01\u2009\u2264\u2009sx,\u2009sy\u2009\u2264\u2009n;\u00a0\u2009-\u2009100\u2009\u2264\u2009dx,\u2009dy\u2009\u2264\u2009100;\u00a00\u2009\u2264\u2009t\u2009\u2264\u20091018).", "output_spec": "Print two integers \u2014 the coordinates of the cell the bear will end up in after t seconds.", "sample_inputs": ["5 1 2 0 1 2", "1 1 1 -1 -1 2"], "sample_outputs": ["3 1", "1 1"], "notes": "NoteOperation a\u00a0mod\u00a0b means taking the remainder after dividing a by b. Note that the result of the operation is always non-negative. For example, (\u2009-\u20091)\u00a0mod\u00a03\u2009=\u20092.In the first sample before the first move the speed vector will equal (3,4) and the bear will get to cell (4,1). Before the second move the speed vector will equal (9,10) and he bear will get to cell (3,1). Don't forget that at the second move, the number of berry bushes increased by 1.In the second sample before the first move the speed vector will equal (1,1) and the bear will get to cell (1,1). Before the second move, the speed vector will equal (4,4) and the bear will get to cell (1,1). Don't forget that at the second move, the number of berry bushes increased by 1."}, "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785"} {"nl": {"description": "One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are \"Danil\", \"Olya\", \"Slava\", \"Ann\" and \"Nikita\".Names are case sensitive.", "input_spec": "The only line contains string from lowercase and uppercase letters and \"_\" symbols of length, not more than 100 \u2014 the name of the problem.", "output_spec": "Print \"YES\", if problem is from this contest, and \"NO\" otherwise.", "sample_inputs": ["Alex_and_broken_contest", "NikitaAndString", "Danil_and_Olya"], "sample_outputs": ["NO", "YES", "NO"], "notes": null}, "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"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": "Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm: On the first step the string consists of a single character \"a\". On the k-th step Polycarpus concatenates two copies of the string obtained on the (k\u2009-\u20091)-th step, while inserting the k-th character of the alphabet between them. Polycarpus uses the alphabet that consists of lowercase Latin letters and digits (a total of 36 characters). The alphabet characters are numbered like this: the 1-st character is \"a\", the 2-nd \u2014 \"b\", ..., the 26-th \u2014 \"z\", the 27-th \u2014 \"0\", the 28-th \u2014 \"1\", ..., the 36-th \u2014 \"9\". Let's have a closer look at the algorithm. On the second step Polycarpus will concatenate two strings \"a\" and insert the character \"b\" between them, resulting in \"aba\" string. The third step will transform it into \"abacaba\", and the fourth one - into \"abacabadabacaba\". Thus, the string constructed on the k-th step will consist of 2k\u2009-\u20091 characters. Polycarpus wrote down the string he got after 30 steps of the given algorithm and chose two non-empty substrings of it. Your task is to find the length of the longest common substring of the two substrings selected by Polycarpus.A substring s[i... j] (1\u2009\u2264\u2009i\u2009\u2264\u2009j\u2009\u2264\u2009|s|) of string s = s1s2... s|s| is a string sisi\u2009+\u20091... sj. For example, substring s[2...4] of string s = \"abacaba\" equals \"bac\". The string is its own substring.The longest common substring of two strings s and t is the longest string that is a substring of both s and t. For example, the longest common substring of \"contest\" and \"systemtesting\" is string \"test\". There can be several common substrings of maximum length.", "input_spec": "The input consists of a single line containing four integers l1, r1, l2, r2 (1\u2009\u2264\u2009li\u2009\u2264\u2009ri\u2009\u2264\u2009109, i\u2009=\u20091,\u20092). The numbers are separated by single spaces. li and ri give the indices of the first and the last characters of the i-th chosen substring, correspondingly (i\u2009=\u20091,\u20092). The characters of string abracadabra are numbered starting from 1.", "output_spec": "Print a single number \u2014 the length of the longest common substring of the given strings. If there are no common substrings, print 0.", "sample_inputs": ["3 6 1 4", "1 1 4 4"], "sample_outputs": ["2", "0"], "notes": "NoteIn the first sample the first substring is \"acab\", the second one is \"abac\". These two substrings have two longest common substrings \"ac\" and \"ab\", but we are only interested in their length \u2014 2.In the second sample the first substring is \"a\", the second one is \"c\". These two substrings don't have any common characters, so the length of their longest common substring is 0."}, "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513"} {"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": "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": "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": "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 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": "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": "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 permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.Let's call a permutation an almost identity permutation iff there exist at least n\u2009-\u2009k indices i (1\u2009\u2264\u2009i\u2009\u2264\u2009n) such that pi\u2009=\u2009i.Your task is to count the number of almost identity permutations for given numbers n and k.", "input_spec": "The first line contains two integers n and k (4\u2009\u2264\u2009n\u2009\u2264\u20091000, 1\u2009\u2264\u2009k\u2009\u2264\u20094).", "output_spec": "Print the number of almost identity permutations for given n and k.", "sample_inputs": ["4 1", "4 2", "5 3", "5 4"], "sample_outputs": ["1", "7", "31", "76"], "notes": null}, "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"} {"nl": {"description": "Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. \"What ungentlemanly behavior!\" \u2014 you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called \"R2:D2\". What can \"R2:D2\" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as \"a:b\", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.Your task is to print the radixes of all numeral system which can contain the time \"a:b\".", "input_spec": "The first line contains a single string as \"a:b\" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string \"008:1\" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.", "output_spec": "Print the radixes of the numeral systems that can represent the time \"a:b\" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time \"a:b\", print the single integer 0. If there are infinitely many numeral systems that can represent the time \"a:b\", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.", "sample_inputs": ["11:20", "2A:13", "000B:00001"], "sample_outputs": ["3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22", "0", "-1"], "notes": "NoteLet's consider the first sample. String \"11:20\" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String \"2A:13\" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.Let's consider the third sample. String \"000B:00001\" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12."}, "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293"} {"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": "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": "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": "Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.", "input_spec": "The first and only line of input contains a single string in the format hh:mm (00\u2009\u2264\u2009 hh \u2009\u2264\u200923, 00\u2009\u2264\u2009 mm \u2009\u2264\u200959).", "output_spec": "Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.", "sample_inputs": ["05:39", "13:31", "23:59"], "sample_outputs": ["11", "0", "1"], "notes": "NoteIn the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome."}, "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"} {"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": "There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary.Can she fill all the linesTo work at all times?On juggling the wordsRight around two-thirdsShe nearly ran out of rhymes.", "input_spec": "The input contains a single integer $$$a$$$ ($$$4 \\le a \\le 998$$$). Not every integer in the range is a valid input for the problem; you are guaranteed that the input will be a valid integer.", "output_spec": "Output a single number.", "sample_inputs": ["35", "57", "391"], "sample_outputs": ["57", "319", "1723"], "notes": null}, "src_uid": "7220f2da5081547a12118595bbeda4f6"} {"nl": {"description": "Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,\u20092,\u2009...,\u2009n} is such function , that for any the formula g(g(x))\u2009=\u2009g(x) holds.Let's denote as f(k)(x) the function f applied k times to the value x. More formally, f(1)(x)\u2009=\u2009f(x), f(k)(x)\u2009=\u2009f(f(k\u2009-\u20091)(x)) for each k\u2009>\u20091.You are given some function . Your task is to find minimum positive integer k such that function f(k)(x) is idempotent.", "input_spec": "In the first line of the input there is a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200) \u2014 the size of function f domain. In the second line follow f(1),\u2009f(2),\u2009...,\u2009f(n) (1\u2009\u2264\u2009f(i)\u2009\u2264\u2009n for each 1\u2009\u2264\u2009i\u2009\u2264\u2009n), the values of a function.", "output_spec": "Output minimum k such that function f(k)(x) is idempotent.", "sample_inputs": ["4\n1 2 2 4", "3\n2 3 3", "3\n2 3 1"], "sample_outputs": ["1", "2", "3"], "notes": "NoteIn the first sample test function f(x)\u2009=\u2009f(1)(x) is already idempotent since f(f(1))\u2009=\u2009f(1)\u2009=\u20091, f(f(2))\u2009=\u2009f(2)\u2009=\u20092, f(f(3))\u2009=\u2009f(3)\u2009=\u20092, f(f(4))\u2009=\u2009f(4)\u2009=\u20094.In the second sample test: function f(x)\u2009=\u2009f(1)(x) isn't idempotent because f(f(1))\u2009=\u20093 but f(1)\u2009=\u20092; function f(x)\u2009=\u2009f(2)(x) is idempotent since for any x it is true that f(2)(x)\u2009=\u20093, so it is also true that f(2)(f(2)(x))\u2009=\u20093. In the third sample test: function f(x)\u2009=\u2009f(1)(x) isn't idempotent because f(f(1))\u2009=\u20093 but f(1)\u2009=\u20092; function f(f(x))\u2009=\u2009f(2)(x) isn't idempotent because f(2)(f(2)(1))\u2009=\u20092 but f(2)(1)\u2009=\u20093; function f(f(f(x)))\u2009=\u2009f(3)(x) is idempotent since it is identity function: f(3)(x)\u2009=\u2009x for any meaning that the formula f(3)(f(3)(x))\u2009=\u2009f(3)(x) also holds. "}, "src_uid": "1daa784c0eb1cde514e4319da07c8d00"} {"nl": {"description": "This problem consists of two subproblems: for solving subproblem E1 you will receive 11 points, and for solving subproblem E2 you will receive 13 points.A tree is an undirected connected graph containing no cycles. The distance between two nodes in an unweighted tree is the minimum number of edges that have to be traversed to get from one node to another.You are given 3 trees that have to be united into a single tree by adding two edges between these trees. Each of these edges can connect any pair of nodes from two trees. After the trees are connected, the distances between all unordered pairs of nodes in the united tree should be computed. What is the maximum possible value of the sum of these distances?", "input_spec": "The first line contains three space-separated integers n1, n2, n3 \u2014 the number of vertices in the first, second, and third trees, respectively. The following n1\u2009-\u20091 lines describe the first tree. Each of these lines describes an edge in the first tree and contains a pair of integers separated by a single space \u2014 the numeric labels of vertices connected by the edge. The following n2\u2009-\u20091 lines describe the second tree in the same fashion, and the n3\u2009-\u20091 lines after that similarly describe the third tree. The vertices in each tree are numbered with consecutive integers starting with 1. 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 E1 (11 points), the number of vertices in each tree will be between 1 and 1000, inclusive. In subproblem E2 (13 points), the number of vertices in each tree will be between 1 and 100000, inclusive. ", "output_spec": "Print a single integer number \u2014 the maximum possible sum of distances between all pairs of nodes in the united tree.", "sample_inputs": ["2 2 3\n1 2\n1 2\n1 2\n2 3", "5 1 4\n1 2\n2 5\n3 4\n4 2\n1 2\n1 3\n1 4"], "sample_outputs": ["56", "151"], "notes": "NoteConsider the first test case. There are two trees composed of two nodes, and one tree with three nodes. The maximum possible answer is obtained if the trees are connected in a single chain of 7 vertices.In the second test case, a possible choice of new edges to obtain the maximum answer is the following: Connect node 3 from the first tree to node 1 from the second tree; Connect node 2 from the third tree to node 1 from the second tree. "}, "src_uid": "2f299b0083b89d8b8ec8b26b65d201f2"} {"nl": {"description": "You are given a positive (greater than zero) integer $$$n$$$.You have to represent $$$n$$$ as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, $$$24 = 11 + 11 + 1 + 1$$$ and $$$102 = 111 - 11 + 1 + 1$$$. Among all possible representations, you have to find the one that uses the minimum number of ones in total.", "input_spec": "The single line contains one integer $$$n$$$ ($$$1 \\le n < 10^{50}$$$).", "output_spec": "Print one integer $$$x$$$ \u2014 the minimum number of ones, such that there exist a representation of $$$n$$$ as the sum of integers (possibly negative) that uses $$$x$$$ ones in total.", "sample_inputs": ["24", "102"], "sample_outputs": ["6", "7"], "notes": null}, "src_uid": "1961e7c9120ff652b15cad5dd5ca0907"} {"nl": {"description": "Permutation p is an ordered set of integers p1,\u2009\u2009p2,\u2009\u2009...,\u2009\u2009pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1,\u2009\u2009p2,\u2009\u2009...,\u2009\u2009pn.We'll call position i (1\u2009\u2264\u2009i\u2009\u2264\u2009n) in permutation p1,\u2009p2,\u2009...,\u2009pn good, if |p[i]\u2009-\u2009i|\u2009=\u20091. Count the number of permutations of size n with exactly k good positions. Print the answer modulo 1000000007 (109\u2009+\u20097).", "input_spec": "The single line contains two space-separated integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u20091000,\u20090\u2009\u2264\u2009k\u2009\u2264\u2009n).", "output_spec": "Print the number of permutations of length n with exactly k good positions modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1 0", "2 1", "3 2", "4 1", "7 4"], "sample_outputs": ["1", "0", "4", "6", "328"], "notes": "NoteThe only permutation of size 1 has 0 good positions.Permutation (1,\u20092) has 0 good positions, and permutation (2,\u20091) has 2 positions.Permutations of size 3: (1,\u20092,\u20093) \u2014 0 positions \u2014 2 positions \u2014 2 positions \u2014 2 positions \u2014 2 positions (3,\u20092,\u20091) \u2014 0 positions"}, "src_uid": "1243e98fe2ebd6e6d1de851984b96079"} {"nl": {"description": "The campus has $$$m$$$ rooms numbered from $$$0$$$ to $$$m - 1$$$. Also the $$$x$$$-mouse lives in the campus. The $$$x$$$-mouse is not just a mouse: each second $$$x$$$-mouse moves from room $$$i$$$ to the room $$$i \\cdot x \\mod{m}$$$ (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the $$$x$$$-mouse is unknown.You are responsible to catch the $$$x$$$-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the $$$x$$$-mouse enters a trapped room, it immediately gets caught.And the only observation you made is $$$\\text{GCD} (x, m) = 1$$$.", "input_spec": "The only line contains two integers $$$m$$$ and $$$x$$$ ($$$2 \\le m \\le 10^{14}$$$, $$$1 \\le x < m$$$, $$$\\text{GCD} (x, m) = 1$$$) \u2014 the number of rooms and the parameter of $$$x$$$-mouse. ", "output_spec": "Print the only integer \u2014 minimum number of traps you need to install to catch the $$$x$$$-mouse.", "sample_inputs": ["4 3", "5 2"], "sample_outputs": ["3", "2"], "notes": "NoteIn the first example you can, for example, put traps in rooms $$$0$$$, $$$2$$$, $$$3$$$. If the $$$x$$$-mouse starts in one of this rooms it will be caught immediately. If $$$x$$$-mouse starts in the $$$1$$$-st rooms then it will move to the room $$$3$$$, where it will be caught.In the second example you can put one trap in room $$$0$$$ and one trap in any other room since $$$x$$$-mouse will visit all rooms $$$1..m-1$$$ if it will start in any of these rooms."}, "src_uid": "c2dd6de750812d6213c770b3587d8fcb"} {"nl": {"description": "Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017.Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes.Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages: download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package; download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package. Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds.Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages.", "input_spec": "The first line contains three integer numbers f, T and t0 (1\u2009\u2264\u2009f,\u2009T,\u2009t0\u2009\u2264\u2009107) \u2014 size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff. The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1\u2009\u2264\u2009a1,\u2009t1,\u2009p1\u2009\u2264\u2009107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles). The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1\u2009\u2264\u2009a2,\u2009t2,\u2009p2\u2009\u2264\u2009107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles). Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.", "output_spec": "Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1.", "sample_inputs": ["120 964 20\n26 8 8\n13 10 4", "10 200 20\n1 1 1\n2 2 3", "8 81 11\n4 10 16\n3 10 12", "8 79 11\n4 10 16\n3 10 12"], "sample_outputs": ["40", "0", "28", "-1"], "notes": "NoteIn the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26\u00b75\u2009=\u2009130 bytes) in 120\u00b78\u2009=\u2009960 milliseconds (960\u2009\u2264\u2009964). He spends 8\u00b75\u2009=\u200940 burles on it.In the second example Polycarp has enough time to download 10 bytes. It takes 10\u00b720\u2009=\u2009200 milliseconds which equals to upper constraint on download time.In the third example Polycarp has to buy one first additional package and one second additional package.In the fourth example Polycarp has no way to download the file on time."}, "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1"} {"nl": {"description": "The fundamental prerequisite for justice is not to be correct, but to be strong. That's why justice is always the victor.The Cinderswarm Bee. Koyomi knows it.The bees, according to their nature, live in a tree. To be more specific, a complete binary tree with n nodes numbered from 1 to n. The node numbered 1 is the root, and the parent of the i-th (2\u2009\u2264\u2009i\u2009\u2264\u2009n) node is . Note that, however, all edges in the tree are undirected.Koyomi adds m extra undirected edges to the tree, creating more complication to trick the bees. And you're here to count the number of simple paths in the resulting graph, modulo 109\u2009+\u20097. A simple path is an alternating sequence of adjacent nodes and undirected edges, which begins and ends with nodes and does not contain any node more than once. Do note that a single node is also considered a valid simple path under this definition. Please refer to the examples and notes below for instances.", "input_spec": "The first line of input contains two space-separated integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u2009109, 0\u2009\u2264\u2009m\u2009\u2264\u20094) \u2014 the number of nodes in the tree and the number of extra edges respectively. The following m lines each contains two space-separated integers u and v (1\u2009\u2264\u2009u,\u2009v\u2009\u2264\u2009n, u\u2009\u2260\u2009v) \u2014 describing an undirected extra edge whose endpoints are u and v. Note that there may be multiple edges between nodes in the resulting graph.", "output_spec": "Output one integer \u2014 the number of simple paths in the resulting graph, modulo 109\u2009+\u20097.", "sample_inputs": ["3 0", "3 1\n2 3", "2 4\n1 2\n2 1\n1 2\n2 1"], "sample_outputs": ["9", "15", "12"], "notes": "NoteIn the first example, the paths are: (1); (2); (3); (1,\u20092); (2,\u20091); (1,\u20093); (3,\u20091); (2,\u20091,\u20093); (3,\u20091,\u20092). (For the sake of clarity, the edges between nodes are omitted since there are no multiple edges in this case.)In the second example, the paths are: (1); (1,\u20092); (1,\u20092,\u20093); (1,\u20093); (1,\u20093,\u20092); and similarly for paths starting with 2 and 3. (5\u2009\u00d7\u20093\u2009=\u200915 paths in total.)In the third example, the paths are: (1); (2); any undirected edge connecting the two nodes travelled in either direction. (2\u2009+\u20095\u2009\u00d7\u20092\u2009=\u200912 paths in total.)"}, "src_uid": "250314325e3d088ceedaba7dcde762f1"} {"nl": {"description": "As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different types of brackets since prehistoric times. A bracket type is a positive integer. The shamans define a correct bracket sequence as follows: An empty sequence is a correct bracket sequence. If {a1,\u2009a2,\u2009...,\u2009al} and {b1,\u2009b2,\u2009...,\u2009bk} are correct bracket sequences, then sequence {a1,\u2009a2,\u2009...,\u2009al,\u2009b1,\u2009b2,\u2009...,\u2009bk} (their concatenation) also is a correct bracket sequence. If {a1,\u2009a2,\u2009...,\u2009al} \u2014 is a correct bracket sequence, then sequence also is a correct bracket sequence, where v (v\u2009>\u20090) is an integer. For example, sequences {1,\u20091,\u2009\u2009-\u20091,\u20092,\u2009\u2009-\u20092,\u2009\u2009-\u20091} and {3,\u2009\u2009-\u20093} are correct bracket sequences, and {2,\u2009\u2009-\u20093} is not.Moreover, after Vova became a shaman, he learned the most important correct bracket sequence {x1,\u2009x2,\u2009...,\u2009xn}, consisting of n integers. As sequence x is the most important, Vova decided to encrypt it just in case.Encrypting consists of two sequences. The first sequence {p1,\u2009p2,\u2009...,\u2009pn} contains types of brackets, that is, pi\u2009=\u2009|xi| (1\u2009\u2264\u2009i\u2009\u2264\u2009n). The second sequence {q1,\u2009q2,\u2009...,\u2009qt} contains t integers \u2014 some positions (possibly, not all of them), which had negative numbers in sequence {x1,\u2009x2,\u2009...,\u2009xn}.Unfortunately, Vova forgot the main sequence. But he was lucky enough to keep the encryption: sequences {p1,\u2009p2,\u2009...,\u2009pn} and {q1,\u2009q2,\u2009...,\u2009qt}. Help Vova restore sequence x by the encryption. If there are multiple sequences that correspond to the encryption, restore any of them. If there are no such sequences, you should tell so.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106). The second line contains n integers: p1,\u2009p2,\u2009...,\u2009pn (1\u2009\u2264\u2009pi\u2009\u2264\u2009109). The third line contains integer t (0\u2009\u2264\u2009t\u2009\u2264\u2009n), followed by t distinct integers q1,\u2009q2,\u2009...,\u2009qt (1\u2009\u2264\u2009qi\u2009\u2264\u2009n). The numbers in each line are separated by spaces.", "output_spec": "Print a single string \"NO\" (without the quotes) if Vova is mistaken and a suitable sequence {x1,\u2009x2,\u2009...,\u2009xn} doesn't exist. Otherwise, in the first line print \"YES\" (without the quotes) and in the second line print n integers x1,\u2009x2,\u2009...,\u2009xn (|xi|\u2009=\u2009pi;\u00a0xqj\u2009<\u20090). If there are multiple sequences that correspond to the encrypting, you are allowed to print any of them.", "sample_inputs": ["2\n1 1\n0", "4\n1 1 1 1\n1 3", "3\n1 1 1\n0", "4\n1 2 2 1\n2 3 4"], "sample_outputs": ["YES\n1 -1", "YES\n1 1 -1 -1", "NO", "YES\n1 2 -2 -1"], "notes": null}, "src_uid": "be82b8f209217875221ebe5de8675971"} {"nl": {"description": "Alice and Bob play a game. Alice has got $$$n$$$ treasure chests (the $$$i$$$-th of which contains $$$a_i$$$ coins) and $$$m$$$ keys (the $$$j$$$-th of which she can sell Bob for $$$b_j$$$ coins).Firstly, Alice puts some locks on the chests. There are $$$m$$$ types of locks, the locks of the $$$j$$$-th type can only be opened with the $$$j$$$-th key. To put a lock of type $$$j$$$ on the $$$i$$$-th chest, Alice has to pay $$$c_{i,j}$$$ dollars. Alice can put any number of different types of locks on each chest (possibly, zero).Then, Bob buys some of the keys from Alice (possibly none, possibly all of them) and opens each chest he can (he can open a chest if he has the keys for all of the locks on this chest). Bob's profit is the difference between the total number of coins in the opened chests and the total number of coins he spends buying keys from Alice. If Bob's profit is strictly positive (greater than zero), he wins the game. Otherwise, Alice wins the game.Alice wants to put some locks on some chests so no matter which keys Bob buys, she always wins (Bob cannot get positive profit). Of course, she wants to spend the minimum possible number of dollars on buying the locks. Help her to determine whether she can win the game at all, and if she can, how many dollars she has to spend on the locks.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 6$$$)\u00a0\u2014 the number of chests and the number of keys, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 4$$$), where $$$a_i$$$ is the number of coins in the $$$i$$$-th chest. The third line contains $$$m$$$ integers $$$b_1, b_2, \\dots, b_m$$$ ($$$1 \\le b_j \\le 4$$$), where $$$b_j$$$ is the number of coins Bob has to spend to buy the $$$j$$$-th key from Alice. Then $$$n$$$ lines follow. The $$$i$$$-th of them contains $$$m$$$ integers $$$c_{i,1}, c_{i,2}, \\dots, c_{i,m}$$$ ($$$1 \\le c_{i,j} \\le 10^7$$$), where $$$c_{i,j}$$$ is the number of dollars Alice has to spend to put a lock of the $$$j$$$-th type on the $$$i$$$-th chest.", "output_spec": "If Alice cannot ensure her victory (no matter which locks she puts on which chests, Bob always has a way to gain positive profit), print $$$-1$$$. Otherwise, print one integer\u00a0\u2014 the minimum number of dollars Alice has to spend to win the game regardless of Bob's actions.", "sample_inputs": ["2 3\n3 3\n1 1 4\n10 20 100\n20 15 80", "2 3\n3 3\n2 1 4\n10 20 100\n20 15 80", "2 3\n3 4\n1 1 4\n10 20 100\n20 15 80"], "sample_outputs": ["205", "110", "-1"], "notes": "NoteIn the first example, Alice should put locks of types $$$1$$$ and $$$3$$$ on the first chest, and locks of type $$$2$$$ and $$$3$$$ on the second chest.In the second example, Alice should put locks of types $$$1$$$ and $$$2$$$ on the first chest, and a lock of type $$$3$$$ on the second chest."}, "src_uid": "4dc5dc78bda59c1ec6dd8acd6f1d7333"} {"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": "Integers from $$$1$$$ to $$$n$$$ (inclusive) were sorted lexicographically (considering integers as strings). As a result, array $$$a_1, a_2, \\dots, a_n$$$ was obtained.Calculate value of $$$(\\sum_{i = 1}^n ((i - a_i) \\mod 998244353)) \\mod 10^9 + 7$$$.$$$x \\mod y$$$ here means the remainder after division $$$x$$$ by $$$y$$$. This remainder is always non-negative and doesn't exceed $$$y - 1$$$. For example, $$$5 \\mod 3 = 2$$$, $$$(-1) \\mod 6 = 5$$$. ", "input_spec": "The first line contains the single integer $$$n$$$ ($$$1 \\leq n \\leq 10^{12}$$$).", "output_spec": "Print one integer\u00a0\u2014 the required sum.", "sample_inputs": ["3", "12", "21", "1000000000000"], "sample_outputs": ["0", "994733045", "978932159", "289817887"], "notes": "NoteA string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \\ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$. For example, $$$42$$$ is lexicographically smaller than $$$6$$$, because they differ in the first digit, and $$$4 < 6$$$; $$$42 < 420$$$, because $$$42$$$ is a prefix of $$$420$$$.Let's denote $$$998244353$$$ as $$$M$$$.In the first example, array $$$a$$$ is equal to $$$[1, 2, 3]$$$. $$$(1 - 1) \\mod M = 0 \\mod M = 0$$$ $$$(2 - 2) \\mod M = 0 \\mod M = 0$$$ $$$(3 - 3) \\mod M = 0 \\mod M = 0$$$ As a result, $$$(0 + 0 + 0) \\mod 10^9 + 7 = 0$$$In the second example, array $$$a$$$ is equal to $$$[1, 10, 11, 12, 2, 3, 4, 5, 6, 7, 8, 9]$$$. $$$(1 - 1) \\mod M = 0 \\mod M = 0$$$ $$$(2 - 10) \\mod M = (-8) \\mod M = 998244345$$$ $$$(3 - 11) \\mod M = (-8) \\mod M = 998244345$$$ $$$(4 - 12) \\mod M = (-8) \\mod M = 998244345$$$ $$$(5 - 2) \\mod M = 3 \\mod M = 3$$$ $$$(6 - 3) \\mod M = 3 \\mod M = 3$$$ $$$(7 - 4) \\mod M = 3 \\mod M = 3$$$ $$$(8 - 5) \\mod M = 3 \\mod M = 3$$$ $$$(9 - 6) \\mod M = 3 \\mod M = 3$$$ $$$(10 - 7) \\mod M = 3 \\mod M = 3$$$ $$$(11 - 8) \\mod M = 3 \\mod M = 3$$$ $$$(12 - 9) \\mod M = 3 \\mod M = 3$$$ As a result, $$$(0 + 998244345 + 998244345 + 998244345 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) \\mod 10^9 + 7$$$ $$$=$$$ $$$2994733059 \\mod 10^9 + 7$$$ $$$=$$$ $$$994733045$$$"}, "src_uid": "2c70ae38f91ab739621a31b897b8fbf3"} {"nl": {"description": "The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: Only one disk can be moved at a time. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. No disk may be placed on top of a smaller disk. With three disks, the puzzle can be solved in seven moves. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2n\u2009-\u20091, where n is the number of disks. (c) Wikipedia.SmallY's puzzle is very similar to the famous Tower of Hanoi. In the Tower of Hanoi puzzle you need to solve a puzzle in minimum number of moves, in SmallY's puzzle each move costs some money and you need to solve the same puzzle but for minimal cost. At the beginning of SmallY's puzzle all n disks are on the first rod. Moving a disk from rod i to rod j (1\u2009\u2264\u2009i,\u2009j\u2009\u2264\u20093) costs tij units of money. The goal of the puzzle is to move all the disks to the third rod.In the problem you are given matrix t and an integer n. You need to count the minimal cost of solving SmallY's puzzle, consisting of n disks.", "input_spec": "Each of the first three lines contains three integers \u2014 matrix t. The j-th integer in the i-th line is tij (1\u2009\u2264\u2009tij\u2009\u2264\u200910000;\u00a0i\u2009\u2260\u2009j). The following line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200940) \u2014 the number of disks. It is guaranteed that for all i (1\u2009\u2264\u2009i\u2009\u2264\u20093), tii\u2009=\u20090.", "output_spec": "Print a single integer \u2014 the minimum cost of solving SmallY's puzzle.", "sample_inputs": ["0 1 1\n1 0 1\n1 1 0\n3", "0 2 2\n1 0 100\n1 2 0\n3", "0 2 1\n1 0 100\n1 2 0\n5"], "sample_outputs": ["7", "19", "87"], "notes": null}, "src_uid": "c4c20228624365e39299d0a6e8fe7095"} {"nl": {"description": "The King of Flatland will organize a knights' tournament! The winner will get half the kingdom and the favor of the princess of legendary beauty and wisdom. The final test of the applicants' courage and strength will be a fencing tournament. The tournament is held by the following rules: the participants fight one on one, the winner (or rather, the survivor) transfers to the next round.Before the battle both participants stand at the specified points on the Ox axis with integer coordinates. Then they make moves in turn. The first participant moves first, naturally. During a move, the first participant can transfer from the point x to any integer point of the interval [x\u2009+\u2009a; x\u2009+\u2009b]. The second participant can transfer during a move to any integer point of the interval [x\u2009-\u2009b; x\u2009-\u2009a]. That is, the options for the players' moves are symmetric (note that the numbers a and b are not required to be positive, and if a\u2009\u2264\u20090\u2009\u2264\u2009b, then staying in one place is a correct move). At any time the participants can be located arbitrarily relative to each other, that is, it is allowed to \"jump\" over the enemy in any direction. A participant wins if he uses his move to transfer to the point where his opponent is.Of course, the princess has already chosen a husband and now she wants to make her sweetheart win the tournament. He has already reached the tournament finals and he is facing the last battle. The princess asks the tournament manager to arrange the tournament finalists in such a way that her sweetheart wins the tournament, considering that both players play optimally. However, the initial location of the participants has already been announced, and we can only pull some strings and determine which participant will be first and which one will be second. But how do we know which participant can secure the victory? Alas, the princess is not learned in the military affairs... Therefore, she asks you to determine how the battle will end considering that both opponents play optimally. Also, if the first player wins, your task is to determine his winning move.", "input_spec": "The first line contains four space-separated integers \u2014 x1, x2, a and b (x1\u2009\u2260\u2009x2, a\u2009\u2264\u2009b, \u2009-\u2009109\u2009\u2264\u2009x1,\u2009x2,\u2009a,\u2009b\u2009\u2264\u2009109) \u2014 coordinates of the points where the first and the second participant start, and the numbers that determine the players' moves, correspondingly.", "output_spec": "On the first line print the outcome of the battle as \"FIRST\" (without the quotes), if both players play optimally and the first player wins. Print \"SECOND\" (without the quotes) if the second player wins and print \"DRAW\" (without the quotes), if nobody is able to secure the victory. If the first player wins, print on the next line the single integer x \u2014 the coordinate of the point where the first player should transfer to win. The indicated move should be valid, that is, it should meet the following condition: x1\u2009+\u2009a\u2009\u2264\u2009x\u2009\u2264\u2009x1\u2009+\u2009b. If there are several winning moves, print any of them. If the first participant can't secure the victory, then you do not have to print anything.", "sample_inputs": ["0 2 0 4", "0 2 1 1", "0 2 0 1"], "sample_outputs": ["FIRST\n2", "SECOND", "DRAW"], "notes": "NoteIn the first sample the first player can win in one move.In the second sample the first participant must go to point 1, where the second participant immediately goes and wins. In the third sample changing the position isn't profitable to either participant, so nobody wins."}, "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6"} {"nl": {"description": "Mr. Chanek has an integer represented by a string $$$s$$$. Zero or more digits have been erased and are denoted by the character _. There are also zero or more digits marked by the character X, meaning they're the same digit.Mr. Chanek wants to count the number of possible integer $$$s$$$, where $$$s$$$ is divisible by $$$25$$$. Of course, $$$s$$$ must not contain any leading zero. He can replace the character _ with any digit. He can also replace the character X with any digit, but it must be the same for every character X.As a note, a leading zero is any 0 digit that comes before the first nonzero digit in a number string in positional notation. For example, 0025 has two leading zeroes. An exception is the integer zero, (0 has no leading zero, but 0000 has three leading zeroes).", "input_spec": "One line containing the string $$$s$$$ ($$$1 \\leq |s| \\leq 8$$$). The string $$$s$$$ consists of the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, _, and X.", "output_spec": "Output an integer denoting the number of possible integer $$$s$$$.", "sample_inputs": ["25", "_00", "_XX", "0", "0_25"], "sample_outputs": ["1", "9", "9", "1", "0"], "notes": "NoteIn the first example, the only possible $$$s$$$ is $$$25$$$.In the second and third example, $$$s \\in \\{100, 200,300,400,500,600,700,800,900\\}$$$.In the fifth example, all possible $$$s$$$ will have at least one leading zero."}, "src_uid": "4a905f419550a6c839992b40f1617af3"} {"nl": {"description": "The only difference between easy and hard versions is the number of elements in the array.You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move you can choose any $$$a_i$$$ and divide it by $$$2$$$ rounding down (in other words, in one move you can set $$$a_i := \\lfloor\\frac{a_i}{2}\\rfloor$$$).You can perform such an operation any (possibly, zero) number of times with any $$$a_i$$$.Your task is to calculate the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.Don't forget that it is possible to have $$$a_i = 0$$$ after some operations, thus the answer always exists.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 50$$$) \u2014 the number of elements in the array and the number of equal numbers required. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 2 \\cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.", "output_spec": "Print one integer \u2014 the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.", "sample_inputs": ["5 3\n1 2 2 4 5", "5 3\n1 2 3 4 5", "5 3\n1 2 3 3 3"], "sample_outputs": ["1", "2", "0"], "notes": null}, "src_uid": "ed1a2ae733121af6486568e528fe2d84"} {"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": "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": "The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1\u2009\u2264\u2009i\u2009\u2264\u2009n) day, the price for one barrel of honey is going to is xi kilos of raspberry.Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1\u2009\u2264\u2009d\u2009<\u2009n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d\u2009+\u20091) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day d\u2009+\u20091) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel.The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.", "input_spec": "The first line contains two space-separated integers, n and c (2\u2009\u2264\u2009n\u2009\u2264\u2009100,\u20090\u2009\u2264\u2009c\u2009\u2264\u2009100), \u2014 the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains n space-separated integers x1,\u2009x2,\u2009...,\u2009xn (0\u2009\u2264\u2009xi\u2009\u2264\u2009100), the price of a honey barrel on day i.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["5 1\n5 10 7 3 20", "6 2\n100 1 10 40 10 40", "3 0\n1 2 3"], "sample_outputs": ["3", "97", "0"], "notes": "NoteIn the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97."}, "src_uid": "411539a86f2e94eb6386bb65c9eb9557"} {"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": "Karlsson has visited Lillebror again. They found a box of chocolates and a big whipped cream cake at Lillebror's place. Karlsson immediately suggested to divide the sweets fairly between Lillebror and himself. Specifically, to play together a game he has just invented with the chocolates. The winner will get the cake as a reward.The box of chocolates has the form of a hexagon. It contains 19 cells for the chocolates, some of which contain a chocolate. The players move in turns. During one move it is allowed to eat one or several chocolates that lay in the neighboring cells on one line, parallel to one of the box's sides. The picture below shows the examples of allowed moves and of an unacceptable one. The player who cannot make a move loses. Karlsson makes the first move as he is Lillebror's guest and not vice versa. The players play optimally. Determine who will get the cake.", "input_spec": "The input data contains 5 lines, containing 19 words consisting of one symbol. The word \"O\" means that the cell contains a chocolate and a \".\" stands for an empty cell. It is guaranteed that the box contains at least one chocolate. See the examples for better understanding.", "output_spec": "If Karlsson gets the cake, print \"Karlsson\" (without the quotes), otherwise print \"Lillebror\" (yet again without the quotes).", "sample_inputs": [". . .\n . . O .\n. . O O .\n . . . .\n . . .", ". . .\n . . . O\n. . . O .\n O . O .\n . O ."], "sample_outputs": ["Lillebror", "Karlsson"], "notes": null}, "src_uid": "eaa022cc7846c983a826900dc6dd919f"} {"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": "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": "You are given array $$$a_1, a_2, \\dots, a_n$$$. You need to split it into $$$k$$$ subsegments (so every element is included in exactly one subsegment).The weight of a subsegment $$$a_l, a_{l+1}, \\dots, a_r$$$ is equal to $$$(r - l + 1) \\cdot \\max\\limits_{l \\le i \\le r}(a_i)$$$. The weight of a partition is a total weight of all its segments.Find the partition of minimal weight.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 2 \\cdot 10^4$$$, $$$1 \\le k \\le \\min(100, n)$$$) \u2014 the length of the array $$$a$$$ and the number of subsegments in the partition. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 2 \\cdot 10^4$$$) \u2014 the array $$$a$$$.", "output_spec": "Print single integer \u2014 the minimal weight among all possible partitions.", "sample_inputs": ["4 2\n6 1 7 4", "4 3\n6 1 7 4", "5 4\n5 1 5 1 5"], "sample_outputs": ["25", "21", "21"], "notes": "NoteThe optimal partition in the first example is next: $$$6$$$ $$$1$$$ $$$7$$$ $$$\\bigg|$$$ $$$4$$$.The optimal partition in the second example is next: $$$6$$$ $$$\\bigg|$$$ $$$1$$$ $$$\\bigg|$$$ $$$7$$$ $$$4$$$.One of the optimal partitions in the third example is next: $$$5$$$ $$$\\bigg|$$$ $$$1$$$ $$$5$$$ $$$\\bigg|$$$ $$$1$$$ $$$\\bigg|$$$ $$$5$$$."}, "src_uid": "f42faaaa88628748a8da49111936be00"} {"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 was given this problem for homework:You are given function (here represents the operation of taking the remainder). His task is to count the number of integers x in range [a;b] with property f(x)\u2009=\u2009x.It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers with property that probability that f(x)\u2009=\u2009x is not less than 31.4159265352718281828459045%. In other words, Petya will pick up the number x if there exist at least 7 permutations of numbers p1,\u2009p2,\u2009p3,\u2009p4, for which f(x)\u2009=\u2009x.", "input_spec": "First line of the input will contain 6 integers, separated by spaces: p1,\u2009p2,\u2009p3,\u2009p4,\u2009a,\u2009b (1\u2009\u2264\u2009p1,\u2009p2,\u2009p3,\u2009p4\u2009\u2264\u20091000,\u20090\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u200931415). It is guaranteed that numbers p1,\u2009p2,\u2009p3,\u2009p4 will be pairwise distinct.", "output_spec": "Output the number of integers in the given range that have the given property.", "sample_inputs": ["2 7 1 8 2 8", "20 30 40 50 0 100", "31 41 59 26 17 43"], "sample_outputs": ["0", "20", "9"], "notes": null}, "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a"} {"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": "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": "Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used!Vasya's life goes in states of a program. In each state, Vasya can either be used (for example, to calculate the value of another variable), or be assigned a value, or ignored. Between some states are directed (oriented) transitions.A path is a sequence of states v1,\u2009v2,\u2009...,\u2009vx, where for any 1\u2009\u2264\u2009i\u2009<\u2009x exists a transition from vi to vi\u2009+\u20091.Vasya's value in state v is interesting to the world, if exists path p1,\u2009p2,\u2009...,\u2009pk such, that pi\u2009=\u2009v for some i (1\u2009\u2264\u2009i\u2009\u2264\u2009k), in state p1 Vasya gets assigned a value, in state pk Vasya is used and there is no state pi (except for p1) where Vasya gets assigned a value.Help Vasya, find the states in which Vasya's value is interesting to the world.", "input_spec": "The first line contains two space-separated integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105) \u2014 the numbers of states and transitions, correspondingly. The second line contains space-separated n integers f1,\u2009f2,\u2009...,\u2009fn (0\u2009\u2264\u2009fi\u2009\u2264\u20092), fi described actions performed upon Vasya in state i: 0 represents ignoring, 1 \u2014 assigning a value, 2 \u2014 using. Next m lines contain space-separated pairs of integers ai,\u2009bi (1\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u2009n, ai\u2009\u2260\u2009bi), each pair represents the transition from the state number ai to the state number bi. Between two states can be any number of transitions.", "output_spec": "Print n integers r1,\u2009r2,\u2009...,\u2009rn, separated by spaces or new lines. Number ri should equal 1, if Vasya's value in state i is interesting to the world and otherwise, it should equal 0. The states are numbered from 1 to n in the order, in which they are described in the input.", "sample_inputs": ["4 3\n1 0 0 2\n1 2\n2 3\n3 4", "3 1\n1 0 2\n1 3", "3 1\n2 0 1\n1 3"], "sample_outputs": ["1\n1\n1\n1", "1\n0\n1", "0\n0\n0"], "notes": "NoteIn the first sample the program states can be used to make the only path in which the value of Vasya interests the world, 1 2 3 4; it includes all the states, so in all of them Vasya's value is interesting to the world.The second sample the only path in which Vasya's value is interesting to the world is , \u2014 1 3; state 2 is not included there.In the third sample we cannot make from the states any path in which the value of Vasya would be interesting to the world, so the value of Vasya is never interesting to the world."}, "src_uid": "87d869a0fd4a510c5e7e310886b86a57"} {"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": "In a far away kingdom is the famous Lio Shan monastery. Gods constructed three diamond pillars on the monastery's lawn long ago. Gods also placed on one pillar n golden disks of different diameters (in the order of the diameters' decreasing from the bottom to the top). Besides, gods commanded to carry all the disks from the first pillar to the third one according to the following rules: you can carry only one disk in one move; you cannot put a larger disk on a smaller one. There was no universal opinion concerning what is to happen after the gods' will is done: some people promised world peace and eternal happiness to everyone, whereas others predicted that the kingdom will face communi\u2026 (gee, what am I rambling about?) the Armageddon. However, as everybody knew that it was impossible to solve the problem in less than 2n\u2009-\u20091 moves and the lazy Lio Shan monks never even started to solve it, everyone lives peacefully even though the problem was never solved and nobody was afraid of the Armageddon.However, the monastery wasn't doing so well lately and the wise prior Ku Sean Sun had to cut some disks at the edges and use the gold for the greater good. Wouldn't you think that the prior is entitled to have an air conditioning system? Besides, staying in the monastery all year is sooo dull\u2026 One has to have a go at something new now and then, go skiing, for example\u2026 Ku Sean Sun realize how big a mistake he had made only after a while: after he cut the edges, the diameters of some disks got the same; that means that some moves that used to be impossible to make, were at last possible (why, gods never prohibited to put a disk on a disk of the same diameter). Thus, the possible Armageddon can come earlier than was initially planned by gods. Much earlier. So much earlier, in fact, that Ku Sean Sun won't even have time to ski all he wants or relax under the air conditioner.The wise prior could never let that last thing happen and he asked one very old and very wise witch PikiWedia to help him. May be she can determine the least number of moves needed to solve the gods' problem. However, the witch laid out her cards and found no answer for the prior. Then he asked you to help him.Can you find the shortest solution of the problem, given the number of disks and their diameters? Keep in mind that it is allowed to place disks of the same diameter one on the other one, however, the order in which the disks are positioned on the third pillar in the end should match the initial order of the disks on the first pillar.", "input_spec": "The first line contains an integer n \u2014 the number of disks (1\u2009\u2264\u2009n\u2009\u2264\u200920). The second line contains n integers di \u2014 the disks' diameters after Ku Sean Sun cut their edges. The diameters are given from the bottom to the top (1\u2009\u2264\u2009di\u2009\u2264\u200920, besides, di\u2009\u2265\u2009di\u2009+\u20091 for any 1\u2009\u2264\u2009i\u2009<\u2009n).", "output_spec": "Print on the first line number m \u2014 the smallest number of moves to solve the gods' problem. Print on the next m lines the description of moves: two space-separated positive integers si and ti that determine the number of the pillar from which the disk is moved and the number of pillar where the disk is moved, correspondingly (1\u2009\u2264\u2009si,\u2009ti\u2009\u2264\u20093, si\u2009\u2260\u2009ti). ", "sample_inputs": ["3\n3 2 1", "3\n3 1 1", "3\n3 3 3"], "sample_outputs": ["7\n1 3\n1 2\n3 2\n1 3\n2 1\n2 3\n1 3", "5\n1 2\n1 2\n1 3\n2 3\n2 3", "5\n1 2\n1 2\n1 3\n2 3\n2 3"], "notes": "NotePay attention to the third test demonstrating that the order of disks should remain the same in the end, even despite the disks' same radius. If this condition was not necessary to fulfill, the gods' task could have been solved within a smaller number of moves (three \u2014 simply moving the three disks from the first pillar on the third one)."}, "src_uid": "4ea4ad10ef422a9cd45b8a7b25d359c5"} {"nl": {"description": "The only difference between the easy and the hard versions is constraints.A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string \"abaca\" the following strings are subsequences: \"abaca\", \"aba\", \"aaa\", \"a\" and \"\" (empty string). But the following strings are not subsequences: \"aabaca\", \"cb\" and \"bcaa\".You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.In one move you can take any subsequence $$$t$$$ of the given string and add it to the set $$$S$$$. The set $$$S$$$ can't contain duplicates. This move costs $$$n - |t|$$$, where $$$|t|$$$ is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).Your task is to find out the minimum possible total cost to obtain a set $$$S$$$ of size $$$k$$$ or report that it is impossible to do so.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100$$$) \u2014 the length of the string and the size of the set, correspondingly. The second line of the input contains a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.", "output_spec": "Print one integer \u2014 if it is impossible to obtain the set $$$S$$$ of size $$$k$$$, print -1. Otherwise, print the minimum possible total cost to do it.", "sample_inputs": ["4 5\nasdf", "5 6\naaaaa", "5 7\naaaaa", "10 100\najihiushda"], "sample_outputs": ["4", "15", "-1", "233"], "notes": "NoteIn the first example we can generate $$$S$$$ = { \"asdf\", \"asd\", \"adf\", \"asf\", \"sdf\" }. The cost of the first element in $$$S$$$ is $$$0$$$ and the cost of the others is $$$1$$$. So the total cost of $$$S$$$ is $$$4$$$."}, "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b"} {"nl": {"description": "InputThe only line of input contains three integers a1,\u2009a2,\u2009a3 (1\u2009\u2264\u2009a1,\u2009a2,\u2009a3\u2009\u2264\u200920), separated by spaces.OutputOutput a single integer.ExamplesInput2 3 2Output5Input13 14 1Output14Input14 5 9Output464Input17 18 3Output53", "input_spec": "The only line of input contains three integers a1,\u2009a2,\u2009a3 (1\u2009\u2264\u2009a1,\u2009a2,\u2009a3\u2009\u2264\u200920), separated by spaces.", "output_spec": "Output a single integer.", "sample_inputs": ["2 3 2", "13 14 1", "14 5 9", "17 18 3"], "sample_outputs": ["5", "14", "464", "53"], "notes": null}, "src_uid": "6ff30f5a9afc3f7befca813469188aab"} {"nl": {"description": "Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1\u2009\u00d7\u2009b1 segments large and the second one is a2\u2009\u00d7\u2009b2 segments large.Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself. Besides, he wants to show that Polycarpus's mind and Paraskevi's beauty are equally matched, so the two bars must have the same number of squares.To make the bars have the same number of squares, Polycarpus eats a little piece of chocolate each minute. Each minute he does the following: he either breaks one bar exactly in half (vertically or horizontally) and eats exactly a half of the bar, or he chips of exactly one third of a bar (vertically or horizontally) and eats exactly a third of the bar. In the first case he is left with a half, of the bar and in the second case he is left with two thirds of the bar.Both variants aren't always possible, and sometimes Polycarpus cannot chip off a half nor a third. For example, if the bar is 16\u2009\u00d7\u200923, then Polycarpus can chip off a half, but not a third. If the bar is 20\u2009\u00d7\u200918, then Polycarpus can chip off both a half and a third. If the bar is 5\u2009\u00d7\u20097, then Polycarpus cannot chip off a half nor a third.What is the minimum number of minutes Polycarpus needs to make two bars consist of the same number of squares? Find not only the required minimum number of minutes, but also the possible sizes of the bars after the process.", "input_spec": "The first line of the input contains integers a1,\u2009b1 (1\u2009\u2264\u2009a1,\u2009b1\u2009\u2264\u2009109) \u2014 the initial sizes of the first chocolate bar. The second line of the input contains integers a2,\u2009b2 (1\u2009\u2264\u2009a2,\u2009b2\u2009\u2264\u2009109) \u2014 the initial sizes of the second bar. You can use the data of type int64 (in Pascal), long long (in \u0421++), long (in Java) to process large integers (exceeding 231\u2009-\u20091).", "output_spec": "In the first line print m \u2014 the sought minimum number of minutes. In the second and third line print the possible sizes of the bars after they are leveled in m minutes. Print the sizes using the format identical to the input format. Print the sizes (the numbers in the printed pairs) in any order. The second line must correspond to the first bar and the third line must correspond to the second bar. If there are multiple solutions, print any of them. If there is no solution, print a single line with integer -1.", "sample_inputs": ["2 6\n2 3", "36 5\n10 16", "3 5\n2 1"], "sample_outputs": ["1\n1 6\n2 3", "3\n16 5\n5 16", "-1"], "notes": null}, "src_uid": "4fcd8c4955a47661462c326cbb3429bd"} {"nl": {"description": "Natasha's favourite numbers are $$$n$$$ and $$$1$$$, and Sasha's favourite numbers are $$$m$$$ and $$$-1$$$. One day Natasha and Sasha met and wrote down every possible array of length $$$n+m$$$ such that some $$$n$$$ of its elements are equal to $$$1$$$ and another $$$m$$$ elements are equal to $$$-1$$$. For each such array they counted its maximal prefix sum, probably an empty one which is equal to $$$0$$$ (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as $$$f(a)$$$ the maximal prefix sum of an array $$$a_{1, \\ldots ,l}$$$ of length $$$l \\geq 0$$$. Then: $$$$$$f(a) = \\max (0, \\smash{\\displaystyle\\max_{1 \\leq i \\leq l}} \\sum_{j=1}^{i} a_j )$$$$$$Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo $$$998\\: 244\\: 853$$$.", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \\le n,m \\le 2\\,000$$$).", "output_spec": "Output the answer to the problem modulo $$$998\\: 244\\: 853$$$.", "sample_inputs": ["0 2", "2 0", "2 2", "2000 2000"], "sample_outputs": ["0", "2", "5", "674532367"], "notes": "NoteIn the first example the only possible array is [-1,-1], its maximal prefix sum is equal to $$$0$$$. In the second example the only possible array is [1,1], its maximal prefix sum is equal to $$$2$$$. There are $$$6$$$ possible arrays in the third example:[1,1,-1,-1], f([1,1,-1,-1]) = 2[1,-1,1,-1], f([1,-1,1,-1]) = 1[1,-1,-1,1], f([1,-1,-1,1]) = 1[-1,1,1,-1], f([-1,1,1,-1]) = 1[-1,1,-1,1], f([-1,1,-1,1]) = 0[-1,-1,1,1], f([-1,-1,1,1]) = 0So the answer for the third example is $$$2+1+1+1+0+0 = 5$$$."}, "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb"} {"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": "Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n\u2009+\u20091)-th day again he uses the pen number 1, on the (n\u2009+\u20092)-th \u2014 he uses the pen number 2 and so on.On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day. Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.", "input_spec": "The first line contains the integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950\u2009000) \u2014 the number of pens Stepan has. The second line contains the sequence of integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009109), where ai is equal to the number of milliliters of ink which the pen number i currently has.", "output_spec": "Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above. Pens are numbered in the order they are given in input data. The numeration begins from one. Note that the answer is always unambiguous, since several pens can not end at the same time.", "sample_inputs": ["3\n3 3 3", "5\n5 4 5 4 4"], "sample_outputs": ["2", "5"], "notes": "NoteIn the first test Stepan uses ink of pens as follows: on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it; on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it; on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it; on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it; on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it; on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it; on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it; on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink. So, the first pen which will not have ink is the pen number 2."}, "src_uid": "8054dc5dd09d600d7fb8d9f5db4dcaca"} {"nl": {"description": "Koa the Koala has a directed graph $$$G$$$ with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a capacity associated with it. Exactly $$$k$$$ edges of the graph, numbered from $$$1$$$ to $$$k$$$, are special, such edges initially have a capacity equal to $$$0$$$.Koa asks you $$$q$$$ queries. In each query she gives you $$$k$$$ integers $$$w_1, w_2, \\ldots, w_k$$$. This means that capacity of the $$$i$$$-th special edge becomes $$$w_i$$$ (and other capacities remain the same).Koa wonders: what is the maximum flow that goes from node $$$1$$$ to node $$$n$$$ after each such query?Help her!", "input_spec": "The first line of the input contains four integers $$$n$$$, $$$m$$$, $$$k$$$, $$$q$$$ ($$$2 \\le n \\le 10^4$$$, $$$1 \\le m \\le 10^4$$$, $$$1 \\le k \\le \\min(10, m)$$$, $$$1 \\le q \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the number of nodes, the number of edges, the number of special edges and the number of queries. Each of the next $$$m$$$ lines contains three integers $$$u$$$, $$$v$$$, $$$w$$$ ($$$1 \\le u, v \\le n$$$; $$$0 \\le w \\le 25$$$)\u00a0\u2014 the description of a directed edge from node $$$u$$$ to node $$$v$$$ with capacity $$$w$$$. Edges are numbered starting from $$$1$$$ in the same order they are listed in the input. The first $$$k$$$ edges are the special edges. It is guaranteed that $$$w_i = 0$$$ for all $$$i$$$ with $$$1 \\le i \\le k$$$. Each of the next $$$q$$$ lines contains $$$k$$$ integers $$$w_1, w_2, \\ldots, w_k$$$ ($$$0 \\le w_i \\le 25$$$) \u00a0\u2014 the description of the query. $$$w_i$$$ denotes the capacity of $$$i$$$-th edge.", "output_spec": "For the $$$i$$$-th query, print one integer $$$res_i$$$ \u00a0\u2014 the maximum flow that can be obtained from node $$$1$$$ to node $$$n$$$ given the $$$i$$$-th query's special edge weights.", "sample_inputs": ["2 1 1 3\n1 2 0\n0\n1\n2", "4 4 2 5\n1 2 0\n2 3 0\n2 4 5\n3 4 2\n0 0\n1 10\n10 0\n7 1\n7 2"], "sample_outputs": ["0\n1\n2", "0\n1\n5\n6\n7"], "notes": "NoteFor the second sample, the following images correspond to the first two queries (from left to right respectively). For each edge there is a pair flow/capacity denoting flow pushed through the edge and edge's capacity. The special edges are colored in red. As you can see in first query maximum flow from node $$$1$$$ to node $$$4$$$ equals $$$0$$$ and in second query equals $$$1$$$."}, "src_uid": "7421c7d81cc7b481d61a6ef07e557e33"} {"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": "There are N cities in Bob's country connected by roads. Some pairs of cities are connected by public transport. There are two competing transport companies\u00a0\u2014 Boblines operating buses and Bobrail running trains. When traveling from A to B, a passenger always first selects the mode of transport (either bus or train), and then embarks on a journey. For every pair of cities, there are exactly two ways of how to travel between them without visiting any city more than once\u00a0\u2014 one using only bus routes, and the second using only train routes. Furthermore, there is no pair of cities that is directly connected by both a bus route and a train route.You obtained the plans of each of the networks. Unfortunately, each of the companies uses different names for the same cities. More precisely, the bus company numbers the cities using integers from 1 to N, while the train company uses integers between N\u2009+\u20091 and 2N. Find one possible mapping between those two numbering schemes, such that no pair of cities is connected directly by both a bus route and a train route. Note that this mapping has to map different cities to different cities.", "input_spec": "The first line contains an integer N (2\u2009\u2264\u2009N\u2009\u2264\u200910000), the number of cities. N\u2009-\u20091 lines follow, representing the network plan of Boblines. Each contains two integers u and v (1\u2009\u2264\u2009u,\u2009v\u2009\u2264\u2009N), meaning that there is a bus route between cities u and v. N\u2009-\u20091 lines follow, representing the network plan of Bobrail. Each contains two integers u and v (N\u2009+\u20091\u2009\u2264\u2009u,\u2009v\u2009\u2264\u20092N), meaning that there is a train route between cities u and v.", "output_spec": "If there is no solution, output a single line with the word \"No\". If a solution exists, output two lines. On the first line, there should be the word \"Yes\". On the second line, there should be N integers P1,\u2009P2,\u2009...,\u2009PN (N\u2009+\u20091\u2009\u2264\u2009Pi\u2009\u2264\u20092N)\u00a0\u2014 the mapping between the two numbering schemes. More precisely, for i\u2009\u2260\u2009j it should be Pi\u2009\u2260\u2009Pj, and for every direct bus route (i,\u2009j), there is no direct train route between (Pi,\u2009Pj). If there are multiple solutions, you may print any of them.", "sample_inputs": ["4\n1 2\n2 3\n3 4\n5 6\n6 7\n7 8", "4\n1 2\n2 3\n3 4\n5 6\n5 7\n5 8", "7\n1 2\n1 3\n1 4\n1 5\n5 6\n6 7\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14"], "sample_outputs": ["Yes\n6 8 5 7", "No", "Yes\n9 14 11 12 13 10 8"], "notes": "NoteThe first sample (bus lines in red and rail lines in blue):"}, "src_uid": "cdfe11f58ae66e4eef935543236f5098"} {"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": "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": "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": "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": "You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one. A square (x; y) is considered bad, if at least one of the two conditions is fulfilled: |x\u2009+\u2009y|\u2009\u2261\u20090 (mod\u00a02a), |x\u2009-\u2009y|\u2009\u2261\u20090 (mod\u00a02b). Your task is to find the minimum number of bad cells one will have to visit on the way from (x1; y1) to (x2; y2).", "input_spec": "The only line contains integers a, b, x1, y1, x2 and y2 \u2014 the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109 and |x1|,|y1|,|x2|,|y2|\u2009\u2264\u2009109). It is guaranteed that the initial and the final square aren't bad.", "output_spec": "Print a single number \u2014 the minimum number of bad cells that one will have to visit in order to travel from square (x1; y1) to square (x2; y2).", "sample_inputs": ["2 2 1 0 0 1", "2 2 10 11 0 1", "2 4 3 -1 3 7"], "sample_outputs": ["1", "5", "2"], "notes": "NoteIn the third sample one of the possible paths in (3;-1)->(3;0)->(3;1)->(3;2)->(4;2)->(4;3)->(4;4)->(4;5)->(4;6)->(4;7)->(3;7). Squares (3;1) and (4;4) are bad."}, "src_uid": "7219d1837c83b5920992aee5a60dc0d9"} {"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": "So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2). The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x,\u2009y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.", "input_spec": "The only input line contains three integers: a, x, y, where a (1\u2009\u2264\u2009a\u2009\u2264\u2009100) is the side of the square, x and y (\u2009-\u2009106\u2009\u2264\u2009x\u2009\u2264\u2009106,\u20090\u2009\u2264\u2009y\u2009\u2264\u2009106) are coordinates of the stone.", "output_spec": "Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print \"-1\" without the quotes.", "sample_inputs": ["1 0 0", "3 1 1", "3 0 10", "3 0 7", "3 4 0"], "sample_outputs": ["-1", "1", "5", "-1", "-1"], "notes": null}, "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"} {"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": "As Kevin is in BigMan's house, suddenly a trap sends him onto a grid with $$$n$$$ rows and $$$m$$$ columns.BigMan's trap is configured by two arrays: an array $$$a_1,a_2,\\ldots,a_n$$$ and an array $$$b_1,b_2,\\ldots,b_m$$$.In the $$$i$$$-th row there is a heater which heats the row by $$$a_i$$$ degrees, and in the $$$j$$$-th column there is a heater which heats the column by $$$b_j$$$ degrees, so that the temperature of cell $$$(i,j)$$$ is $$$a_i+b_j$$$.Fortunately, Kevin has a suit with one parameter $$$x$$$ and two modes: heat resistance. In this mode suit can stand all temperatures greater or equal to $$$x$$$, but freezes as soon as reaches a cell with temperature less than $$$x$$$. cold resistance. In this mode suit can stand all temperatures less than $$$x$$$, but will burn as soon as reaches a cell with temperature at least $$$x$$$.Once Kevin lands on a cell the suit automatically turns to cold resistance mode if the cell has temperature less than $$$x$$$, or to heat resistance mode otherwise, and cannot change after that.We say that two cells are adjacent if they share an edge.Let a path be a sequence $$$c_1,c_2,\\ldots,c_k$$$ of cells such that $$$c_i$$$ and $$$c_{i+1}$$$ are adjacent for $$$1 \\leq i \\leq k-1$$$.We say that two cells are connected if there is a path between the two cells consisting only of cells that Kevin can step on.A connected component is a maximal set of pairwise connected cells.We say that a connected component is good if Kevin can escape the grid starting from it \u00a0\u2014 when it contains at least one border cell of the grid, and that it's bad otherwise.To evaluate the situation, Kevin gives a score of $$$1$$$ to each good component and a score of $$$2$$$ for each bad component.The final score will be the difference between the total score of components with temperatures bigger than or equal to $$$x$$$ and the score of components with temperatures smaller than $$$x$$$.There are $$$q$$$ possible values of $$$x$$$ that Kevin can use, and for each of them Kevin wants to know the final score.Help Kevin defeat BigMan!", "input_spec": "The first line contains three integers $$$n$$$,$$$m$$$,$$$q$$$ ($$$1 \\leq n,m,q \\leq 10^5$$$) \u00a0\u2013 the number of rows, columns, and the number of possible values for $$$x$$$ respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 10^5$$$). The third line contains $$$m$$$ integers $$$b_1, b_2, \\dots, b_m$$$ ($$$1 \\leq b_i \\leq 10^5$$$). Each of the next $$$q$$$ lines contains one integer $$$x$$$ ($$$1 \\leq x \\leq 2 \\cdot 10^5$$$).", "output_spec": "Output $$$q$$$ lines, in the $$$i$$$-th line output the answer for the $$$i$$$-th possible value of $$$x$$$ from the input.", "sample_inputs": ["5 5 1\n1 3 2 3 1\n1 3 2 3 1\n5", "3 3 2\n1 2 2\n2 1 2\n3\n4"], "sample_outputs": ["-1", "0\n1"], "notes": "NoteIn the first example, the score for components with temperature smaller than $$$5$$$ is $$$1+2$$$, and the score for components with temperature at least $$$5$$$ is $$$2$$$. Thus, the final score is $$$2-3=-1$$$."}, "src_uid": "25a6428f57022c12dfabdabbcc69c5a4"} {"nl": {"description": "To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: aij \u2014 the cost of buying an item; bij \u2014 the cost of selling an item; cij \u2014 the number of remaining items.It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind.Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get.", "input_spec": "The first line contains three space-separated integers n, m and k (2\u2009\u2264\u2009n\u2009\u2264\u200910, 1\u2009\u2264\u2009m,\u2009k\u2009\u2264\u2009100) \u2014 the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1\u2009\u2264\u2009bij\u2009<\u2009aij\u2009\u2264\u20091000, 0\u2009\u2264\u2009cij\u2009\u2264\u2009100) \u2014 the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different.", "output_spec": "Print a single number \u2014 the maximum profit Qwerty can get.", "sample_inputs": ["3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5"], "sample_outputs": ["16"], "notes": "NoteIn the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3\u00b76\u2009+\u20097\u00b78\u2009=\u200974). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3\u00b79\u2009+\u20097\u00b79\u2009=\u200990 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case."}, "src_uid": "7419c4268a9815282fadca6581f28ec1"} {"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": "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": "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": "Alice has got addicted to a game called Sirtet recently.In Sirtet, player is given an $$$n \\times m$$$ grid. Initially $$$a_{i,j}$$$ cubes are stacked up in the cell $$$(i,j)$$$. Two cells are called adjacent if they share a side. Player can perform the following operations: stack up one cube in two adjacent cells; stack up two cubes in one cell. Cubes mentioned above are identical in height.Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that $$$L \\le a_{i,j} \\le R$$$ for all $$$1 \\le i \\le n$$$, $$$1 \\le j \\le m$$$; player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo $$$998,244,353$$$.", "input_spec": "The only line contains four integers $$$n$$$, $$$m$$$, $$$L$$$ and $$$R$$$ ($$$1\\le n,m,L,R \\le 10^9$$$, $$$L \\le R$$$, $$$n \\cdot m \\ge 2$$$).", "output_spec": "Output one integer, representing the desired answer modulo $$$998,244,353$$$.", "sample_inputs": ["2 2 1 1", "1 2 1 2"], "sample_outputs": ["1", "2"], "notes": "NoteIn the first sample, the only initial grid that satisfies the requirements is $$$a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1$$$. Thus the answer should be $$$1$$$.In the second sample, initial grids that satisfy the requirements are $$$a_{1,1}=a_{1,2}=1$$$ and $$$a_{1,1}=a_{1,2}=2$$$. Thus the answer should be $$$2$$$."}, "src_uid": "ded299fa1cd010822c60f2389a3ba1a3"} {"nl": {"description": "Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.They will be N guests tonight: N\u2009-\u20091 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to N\u2009-\u20091, and Heidi, who still appears slightly different from the others, is attributed the highest rank, N. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure:The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes \u2013 in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.)You should know that zombies are very greedy and sly, and they know this too \u2013 basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order: survive the event (they experienced death already once and know it is no fun), get as many brains as possible. Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself.What is the smallest number of brains that have to be in the chest for this to be possible?", "input_spec": "The only line of input contains one integer: N, the number of attendees (1\u2009\u2264\u2009N\u2009\u2264\u2009109).", "output_spec": "Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home.", "sample_inputs": ["1", "4"], "sample_outputs": ["1", "2"], "notes": "Note"}, "src_uid": "30e95770f12c631ce498a2b20c2931c7"} {"nl": {"description": "One Martian boy called Zorg wants to present a string of beads to his friend from the Earth \u2014 Masha. He knows that Masha likes two colours: blue and red, \u2014 and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if one unfastens it, one might notice that all the strings of beads in the shop are of the same length. Because of the peculiarities of the Martian eyesight, if Zorg sees one blue-and-red string of beads first, and then the other with red beads instead of blue ones, and blue \u2014 instead of red, he regards these two strings of beads as identical. In other words, Zorg regards as identical not only those strings of beads that can be derived from each other by the string turnover, but as well those that can be derived from each other by a mutual replacement of colours and/or by the string turnover.It is known that all Martians are very orderly, and if a Martian sees some amount of objects, he tries to put them in good order. Zorg thinks that a red bead is smaller than a blue one. Let's put 0 for a red bead, and 1 \u2014 for a blue one. From two strings the Martian puts earlier the string with a red bead in the i-th position, providing that the second string has a blue bead in the i-th position, and the first two beads i\u2009-\u20091 are identical.At first Zorg unfastens all the strings of beads, and puts them into small heaps so, that in each heap strings are identical, in his opinion. Then he sorts out the heaps and chooses the minimum string in each heap, in his opinion. He gives the unnecassary strings back to the shop assistant and says he doesn't need them any more. Then Zorg sorts out the remaining strings of beads and buys the string with index k. All these manupulations will take Zorg a lot of time, that's why he asks you to help and find the string of beads for Masha.", "input_spec": "The input file contains two integers n and k (2\u2009\u2264\u2009n\u2009\u2264\u200950;1\u2009\u2264\u2009k\u2009\u2264\u20091016) \u2014the length of a string of beads, and the index of the string, chosen by Zorg. ", "output_spec": "Output the k-th string of beads, putting 0 for a red bead, and 1 \u2014 for a blue one. If it s impossible to find the required string, output the only number -1.", "sample_inputs": ["4 4"], "sample_outputs": ["0101"], "notes": "NoteLet's consider the example of strings of length 4 \u2014 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110. Zorg will divide them into heaps: {0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}. Then he will choose the minimum strings of beads in each heap: 0001, 0010, 0011, 0101, 0110. The forth string \u2014 0101."}, "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a"} {"nl": {"description": "Hasan loves playing games and has recently discovered a game called TopScore. In this soccer-like game there are $$$p$$$ players doing penalty shoot-outs. Winner is the one who scores the most. In case of ties, one of the top-scorers will be declared as the winner randomly with equal probability.They have just finished the game and now are waiting for the result. But there's a tiny problem! The judges have lost the paper of scores! Fortunately they have calculated sum of the scores before they get lost and also for some of the players they have remembered a lower bound on how much they scored. However, the information about the bounds is private, so Hasan only got to know his bound.According to the available data, he knows that his score is at least $$$r$$$ and sum of the scores is $$$s$$$.Thus the final state of the game can be represented in form of sequence of $$$p$$$ integers $$$a_1, a_2, \\dots, a_p$$$ ($$$0 \\le a_i$$$) \u2014 player's scores. Hasan is player number $$$1$$$, so $$$a_1 \\ge r$$$. Also $$$a_1 + a_2 + \\dots + a_p = s$$$. Two states are considered different if there exists some position $$$i$$$ such that the value of $$$a_i$$$ differs in these states. Once again, Hasan doesn't know the exact scores (he doesn't know his exact score as well). So he considers each of the final states to be equally probable to achieve.Help Hasan find the probability of him winning.It can be shown that it is in the form of $$$\\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are non-negative integers and $$$Q \\ne 0$$$, $$$P \\le Q$$$. Report the value of $$$P \\cdot Q^{-1} \\pmod {998244353}$$$.", "input_spec": "The only line contains three integers $$$p$$$, $$$s$$$ and $$$r$$$ ($$$1 \\le p \\le 100$$$, $$$0 \\le r \\le s \\le 5000$$$) \u2014 the number of players, the sum of scores of all players and Hasan's score, respectively.", "output_spec": "Print a single integer \u2014 the probability of Hasan winning. It can be shown that it is in the form of $$$\\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are non-negative integers and $$$Q \\ne 0$$$, $$$P \\le Q$$$. Report the value of $$$P \\cdot Q^{-1} \\pmod {998244353}$$$.", "sample_inputs": ["2 6 3", "5 20 11", "10 30 10"], "sample_outputs": ["124780545", "1", "85932500"], "notes": "NoteIn the first example Hasan can score $$$3$$$, $$$4$$$, $$$5$$$ or $$$6$$$ goals. If he scores $$$4$$$ goals or more than he scores strictly more than his only opponent. If he scores $$$3$$$ then his opponent also scores $$$3$$$ and Hasan has a probability of $$$\\frac 1 2$$$ to win the game. Thus, overall he has the probability of $$$\\frac 7 8$$$ to win.In the second example even Hasan's lower bound on goal implies him scoring more than any of his opponents. Thus, the resulting probability is $$$1$$$."}, "src_uid": "609195ef4a970c62a8210dafe118580e"} {"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": "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": "There are $$$n$$$ parrots standing in a circle. Each parrot has a certain level of respect among other parrots, namely $$$r_i$$$. When a parrot with respect level $$$x$$$ starts chattering, $$$x$$$ neighbours to the right and to the left of it start repeating the same words in 1 second. Their neighbours then start repeating as well, and so on, until all the birds begin to chatter.You are given the respect levels of all parrots. For each parrot answer a question: if this certain parrot starts chattering, how many seconds will pass until all other birds will start repeating it?", "input_spec": "In the first line of input there is a single integer $$$n$$$, the number of parrots ($$$1 \\leq n \\leq 10^5$$$). In the next line of input there are $$$n$$$ integers $$$r_1$$$, ..., $$$r_n$$$, the respect levels of parrots in order they stand in the circle ($$$1 \\leq r_i \\leq n$$$).", "output_spec": "Print $$$n$$$ integers. $$$i$$$-th of them should equal the number of seconds that is needed for all parrots to start chattering if the $$$i$$$-th parrot is the first to start.", "sample_inputs": ["4\n1 1 4 1", "8\n1 2 2 1 5 1 3 1"], "sample_outputs": ["2 2 1 2", "3 3 2 2 1 2 2 3"], "notes": null}, "src_uid": "e7dd44bf5e0a0345fd1c40e6957d5641"} {"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": "A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.As before, the chessboard is a square-checkered board with the squares arranged in a 8\u2009\u00d7\u20098 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.It goes without saying that in such business one should economize on everything \u2014 for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.", "input_spec": "The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character \u2014 for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).", "output_spec": "Output the only number \u2014 the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.", "sample_inputs": ["WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW"], "sample_outputs": ["3", "1"], "notes": null}, "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"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": "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": "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": "Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.Limak has a string s that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string \"ABBC\" into \"BABC\" or \"ABCB\" in one move.Limak wants to obtain a string without a substring \"VK\" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string s.What is the minimum possible number of moves Limak can do?", "input_spec": "The first line of the input contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u200975)\u00a0\u2014 the length of the string. The second line contains a string s, consisting of uppercase English letters. The length of the string is equal to n.", "output_spec": "Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring \"VK\".", "sample_inputs": ["4\nVKVK", "5\nBVVKV", "7\nVVKEVKK", "20\nVKVKVVVKVOVKVQKKKVVK", "5\nLIMAK"], "sample_outputs": ["3", "2", "3", "8", "0"], "notes": "NoteIn the first sample, the initial string is \"VKVK\". The minimum possible number of moves is 3. One optimal sequence of moves is: Swap two last letters. The string becomes \"VKKV\". Swap first two letters. The string becomes \"KVKV\". Swap the second and the third letter. The string becomes \"KKVV\". Indeed, this string doesn't have a substring \"VK\".In the second sample, there are two optimal sequences of moves. One is \"BVVKV\"\u2009\u2009\u2192\u2009\u2009\"VBVKV\"\u2009\u2009\u2192\u2009\u2009\"VVBKV\". The other is \"BVVKV\"\u2009\u2009\u2192\u2009\u2009\"BVKVV\"\u2009\u2009\u2192\u2009\u2009\"BKVVV\".In the fifth sample, no swaps are necessary."}, "src_uid": "08444f9ab1718270b5ade46852b155d7"} {"nl": {"description": "Every true king during his life must conquer the world, hold the Codeforces world finals, win pink panda in the shooting gallery and travel all over his kingdom.King Copa has already done the first three things. Now he just needs to travel all over the kingdom. The kingdom is an infinite plane with Cartesian coordinate system on it. Every city is a point on this plane. There are n cities in the kingdom at points with coordinates (x1,\u20090),\u2009(x2,\u20090),\u2009...,\u2009(xn,\u20090), and there is one city at point (xn\u2009+\u20091,\u2009yn\u2009+\u20091). King starts his journey in the city number k. Your task is to find such route for the king, which visits all cities (in any order) and has minimum possible length. It is allowed to visit a city twice. The king can end his journey in any city. Between any pair of cities there is a direct road with length equal to the distance between the corresponding points. No two cities may be located at the same point.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009105,\u20091\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009+\u20091) \u2014 amount of cities and index of the starting city. The second line contains n\u2009+\u20091 numbers xi. The third line contains yn\u2009+\u20091. All coordinates are integers and do not exceed 106 by absolute value. No two cities coincide.", "output_spec": "Output the minimum possible length of the journey. Your answer must have relative or absolute error less than 10\u2009-\u20096.", "sample_inputs": ["3 1\n0 1 2 1\n1", "3 1\n1 0 2 1\n1", "4 5\n0 5 -1 -5 2\n3"], "sample_outputs": ["3.41421356237309490000", "3.82842712474619030000", "14.24264068711928400000"], "notes": null}, "src_uid": "f9ed5faca211e654d9d4e0a7557616f4"} {"nl": {"description": "Madoka wants to enter to \"Novosibirsk State University\", but in the entrance exam she came across a very difficult task:Given an integer $$$n$$$, it is required to calculate $$$\\sum{\\operatorname{lcm}(c, \\gcd(a, b))}$$$, for all triples of positive integers $$$(a, b, c)$$$, where $$$a + b + c = n$$$.In this problem $$$\\gcd(x, y)$$$ denotes the greatest common divisor of $$$x$$$ and $$$y$$$, and $$$\\operatorname{lcm}(x, y)$$$ denotes the least common multiple of $$$x$$$ and $$$y$$$.Solve this problem for Madoka and help her to enter to the best university!", "input_spec": "The first and the only line contains a single integer $$$n$$$ ($$$3 \\le n \\le 10^5$$$).", "output_spec": "Print exactly one interger\u00a0\u2014 $$$\\sum{\\operatorname{lcm}(c, \\gcd(a, b))}$$$. Since the answer can be very large, then output it modulo $$$10^9 + 7$$$.", "sample_inputs": ["3", "5", "69228"], "sample_outputs": ["1", "11", "778304278"], "notes": "NoteIn the first example, there is only one suitable triple $$$(1, 1, 1)$$$. So the answer is $$$\\operatorname{lcm}(1, \\gcd(1, 1)) = \\operatorname{lcm}(1, 1) = 1$$$.In the second example, $$$\\operatorname{lcm}(1, \\gcd(3, 1)) + \\operatorname{lcm}(1, \\gcd(2, 2)) + \\operatorname{lcm}(1, \\gcd(1, 3)) + \\operatorname{lcm}(2, \\gcd(2, 1)) + \\operatorname{lcm}(2, \\gcd(1, 2)) + \\operatorname{lcm}(3, \\gcd(1, 1)) = \\operatorname{lcm}(1, 1) + \\operatorname{lcm}(1, 2) + \\operatorname{lcm}(1, 1) + \\operatorname{lcm}(2, 1) + \\operatorname{lcm}(2, 1) + \\operatorname{lcm}(3, 1) = 1 + 2 + 1 + 2 + 2 + 3 = 11$$$"}, "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb"} {"nl": {"description": "InputThe first line of the input contains a single integer $$$N$$$ ($$$1 \\le N \\le 24$$$). The next $$$N$$$ lines contain $$$5$$$ space-separated integers each. The first three integers will be between 0 and 2, inclusive. The last two integers will be between 0 and 3, inclusive. The sum of the first three integers will be equal to the sum of the last two integers.OutputOutput the result \u2013 a string of lowercase English letters.ExamplesInput\n1\n1 0 0 1 0\nOutput\na\nInput\n10\n2 0 0 1 1\n1 1 1 2 1\n2 1 0 1 2\n1 1 0 1 1\n2 1 0 2 1\n1 1 1 2 1\n1 2 1 3 1\n2 0 0 1 1\n1 1 0 1 1\n1 1 2 2 2\nOutput\ncodeforcez\n", "input_spec": "The first line of the input contains a single integer $$$N$$$ ($$$1 \\le N \\le 24$$$). The next $$$N$$$ lines contain $$$5$$$ space-separated integers each. The first three integers will be between 0 and 2, inclusive. The last two integers will be between 0 and 3, inclusive. The sum of the first three integers will be equal to the sum of the last two integers.", "output_spec": "Output the result \u2013 a string of lowercase English letters.", "sample_inputs": ["1\n1 0 0 1 0", "10\n2 0 0 1 1\n1 1 1 2 1\n2 1 0 1 2\n1 1 0 1 1\n2 1 0 2 1\n1 1 1 2 1\n1 2 1 3 1\n2 0 0 1 1\n1 1 0 1 1\n1 1 2 2 2"], "sample_outputs": ["a", "codeforcez"], "notes": null}, "src_uid": "a3603f5ed0d8bdb7fe829342991b78e6"} {"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": "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": "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": "This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called \"Take-It-Light\" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.To make a toast, each friend needs nl milliliters of the drink, a slice of lime and np grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?", "input_spec": "The first and only line contains positive integers n, k, l, c, d, p, nl, np, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.", "output_spec": "Print a single integer \u2014 the number of toasts each friend can make.", "sample_inputs": ["3 4 5 10 8 100 3 1", "5 100 10 1 19 90 4 3", "10 1000 1000 25 23 1 50 1"], "sample_outputs": ["2", "3", "0"], "notes": "NoteA comment to the first sample: Overall the friends have 4\u2009*\u20095\u2009=\u200920 milliliters of the drink, it is enough to make 20\u2009/\u20093\u2009=\u20096 toasts. The limes are enough for 10\u2009*\u20098\u2009=\u200980 toasts and the salt is enough for 100\u2009/\u20091\u2009=\u2009100 toasts. However, there are 3 friends in the group, so the answer is min(6,\u200980,\u2009100)\u2009/\u20093\u2009=\u20092."}, "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"} {"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": "What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. \"Wait a second!\" \u2014 thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1\u2009\u2264\u2009i\u2009\u2264\u200912) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters.", "input_spec": "The first line contains exactly one integer k (0\u2009\u2264\u2009k\u2009\u2264\u2009100). The next line contains twelve space-separated integers: the i-th (1\u2009\u2264\u2009i\u2009\u2264\u200912) number in the line represents ai (0\u2009\u2264\u2009ai\u2009\u2264\u2009100). ", "output_spec": "Print the only integer \u2014 the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1.", "sample_inputs": ["5\n1 1 1 1 2 2 3 2 2 1 1 1", "0\n0 0 0 0 0 0 0 1 1 2 3 0", "11\n1 1 4 1 1 5 1 1 4 1 1 1"], "sample_outputs": ["2", "0", "3"], "notes": "NoteLet's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k\u2009=\u20090). So, it is possible for Petya not to water the flower at all."}, "src_uid": "59dfa7a4988375febc5dccc27aca90a8"} {"nl": {"description": "There are $$$n + 2$$$ towns located on a coordinate line, numbered from $$$0$$$ to $$$n + 1$$$. The $$$i$$$-th town is located at the point $$$i$$$.You build a radio tower in each of the towns $$$1, 2, \\dots, n$$$ with probability $$$\\frac{1}{2}$$$ (these events are independent). After that, you want to set the signal power on each tower to some integer from $$$1$$$ to $$$n$$$ (signal powers are not necessarily the same, but also not necessarily different). The signal from a tower located in a town $$$i$$$ with signal power $$$p$$$ reaches every city $$$c$$$ such that $$$|c - i| < p$$$.After building the towers, you want to choose signal powers in such a way that: towns $$$0$$$ and $$$n + 1$$$ don't get any signal from the radio towers; towns $$$1, 2, \\dots, n$$$ get signal from exactly one radio tower each. For example, if $$$n = 5$$$, and you have built the towers in towns $$$2$$$, $$$4$$$ and $$$5$$$, you may set the signal power of the tower in town $$$2$$$ to $$$2$$$, and the signal power of the towers in towns $$$4$$$ and $$$5$$$ to $$$1$$$. That way, towns $$$0$$$ and $$$n + 1$$$ don't get the signal from any tower, towns $$$1$$$, $$$2$$$ and $$$3$$$ get the signal from the tower in town $$$2$$$, town $$$4$$$ gets the signal from the tower in town $$$4$$$, and town $$$5$$$ gets the signal from the tower in town $$$5$$$.Calculate the probability that, after building the towers, you will have a way to set signal powers to meet all constraints.", "input_spec": "The first (and only) line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$).", "output_spec": "Print one integer \u2014 the probability that there will be a way to set signal powers so that all constraints are met, taken modulo $$$998244353$$$. Formally, the probability can be expressed as an irreducible fraction $$$\\frac{x}{y}$$$. You have to print the value of $$$x \\cdot y^{-1} \\bmod 998244353$$$, where $$$y^{-1}$$$ is an integer such that $$$y \\cdot y^{-1} \\bmod 998244353 = 1$$$.", "sample_inputs": ["2", "3", "5", "200000"], "sample_outputs": ["748683265", "748683265", "842268673", "202370013"], "notes": "NoteThe real answer for the first example is $$$\\frac{1}{4}$$$: with probability $$$\\frac{1}{4}$$$, the towers are built in both towns $$$1$$$ and $$$2$$$, so we can set their signal powers to $$$1$$$. The real answer for the second example is $$$\\frac{1}{4}$$$: with probability $$$\\frac{1}{8}$$$, the towers are built in towns $$$1$$$, $$$2$$$ and $$$3$$$, so we can set their signal powers to $$$1$$$; with probability $$$\\frac{1}{8}$$$, only one tower in town $$$2$$$ is built, and we can set its signal power to $$$2$$$. The real answer for the third example is $$$\\frac{5}{32}$$$. Note that even though the previous explanations used equal signal powers for all towers, it is not necessarily so. For example, if $$$n = 5$$$ and the towers are built in towns $$$2$$$, $$$4$$$ and $$$5$$$, you may set the signal power of the tower in town $$$2$$$ to $$$2$$$, and the signal power of the towers in towns $$$4$$$ and $$$5$$$ to $$$1$$$."}, "src_uid": "cec37432956bb0a1ce62a0188fe2d805"} {"nl": {"description": "\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u043b\u0438\u044f\u043d\u0438\u0435\u043c \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Python: def sort(a): n = len(a) b = [0 for i in range(n)] log = [] def mergeSort(l, r): if r - l <= 1: return m = (l + r) >> 1 mergeSort(l, m) mergeSort(m, r) i, j, k = l, m, l while i < m and j < r: if a[i] < a[j]: log.append('0') b[k] = a[i] i += 1 else: log.append('1') b[k] = a[j] j += 1 k += 1 while i < m: b[k] = a[i] i += 1 k += 1 while j < r: b[k] = a[j] j += 1 k += 1 for p in range(l, r): a[p] = b[p] mergeSort(0, n) return \"\".join(log)\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u00a0\u2014 \u0432\u0430\u0436\u043d\u0435\u0439\u0448\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.\u0421\u0442\u0430\u0440\u0448\u0438\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0412\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 \u0412\u0430\u0441\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 $$$a$$$ (\u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 $$$n$$$ \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 $$$1$$$ \u0434\u043e $$$n$$$), \u0434\u0430\u043b \u0435\u0451 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 sort \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 $$$s$$$. \u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u043d\u044c \u0441\u0442\u0440\u043e\u043a\u0443 $$$s$$$ \u0412\u0430\u0441\u044f \u043d\u0430\u0448\u0451\u043b, \u0430 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 $$$a$$$ \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0430\u0441\u044c. \u0412\u0430\u0441\u044f \u0445\u043e\u0447\u0435\u0442 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 $$$a$$$ \u0442\u0430\u043a\u0443\u044e, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 sort \u043e\u0442 \u043d\u0435\u0451 \u0434\u0430\u0441\u0442 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 $$$s$$$. \u041f\u043e\u043c\u043e\u0433\u0438\u0442\u0435 \u0435\u043c\u0443!", "input_spec": "\u0412\u0432\u043e\u0434 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 $$$s$$$, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0438\u0437 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 0 \u0438 1. \u0412 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0434\u043b\u0438\u043d\u044b $$$16$$$, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0430\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u0430\u0448 \u043e\u0442\u0432\u0435\u0442 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0434\u043b\u0438\u043d\u0443, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u043e\u0442 $$$16$$$.", "output_spec": "\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $$$n$$$\u00a0\u2014 \u0434\u043b\u0438\u043d\u0443 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 $$$n$$$ \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b $$$a_0, a_1, \\ldots, a_{n-1}$$$ ($$$1 \\le a_i \\le n$$$)\u00a0\u2014 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438. \u0415\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430, \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445.", "sample_inputs": ["00000000000000000000000000000000", "11111111111111111111111111111111", "101011010001100100011011001111011000011110010"], "sample_outputs": ["16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16", "16\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "16\n13 6 1 7 12 5 4 15 14 16 10 11 3 8 9 2"], "notes": null}, "src_uid": "b2ee84d23d73947fa84faaaebfde85c8"} {"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": "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": "John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when divided by 1013. John got interested in number f (0\u2009\u2264\u2009f\u2009<\u20091013) and now wants to find its first occurrence in the list given above. Help John and find the number of the first occurence of number f in the list or otherwise state that number f does not occur in the list. The numeration in John's list starts from zero. There, the 0-th position is the number 0, the 1-st position is the number 1, the 2-nd position is the number 1, the 3-rd position is the number 2, the 4-th position is the number 3 and so on. Thus, the beginning of the list looks like this: 0,\u20091,\u20091,\u20092,\u20093,\u20095,\u20098,\u200913,\u200921,\u2009...", "input_spec": "The first line contains the single integer f (0\u2009\u2264\u2009f\u2009<\u20091013) \u2014 the number, which position in the list we should find. 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 number \u2014 the number of the first occurrence of the given number in John's list. If this number doesn't occur in John's list, print -1.", "sample_inputs": ["13", "377"], "sample_outputs": ["7", "14"], "notes": null}, "src_uid": "cbf786abfceeb8df29732c8a872f7f8a"} {"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": "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": "By the year 3018, Summer Informatics School has greatly grown. Hotel \u00abBerendeetronik\u00bb has been chosen as a location of the school. The camp consists of $$$n$$$ houses with $$$n-1$$$ pathways between them. It is possible to reach every house from each other using the pathways.Everything had been perfect until the rains started. The weather forecast promises that rains will continue for $$$m$$$ days. A special squad of teachers was able to measure that the $$$i$$$-th pathway, connecting houses $$$u_i$$$ and $$$v_i$$$, before the rain could be passed in $$$b_i$$$ seconds. Unfortunately, the rain erodes the roads, so with every day the time to pass the road will increase by $$$a_i$$$ seconds. In other words, on the $$$t$$$-th (from zero) day after the start of the rain, it will take $$$a_i \\cdot t + b_i$$$ seconds to pass through this road.Unfortunately, despite all the efforts of teachers, even in the year 3018 not all the students are in their houses by midnight. As by midnight all students have to go to bed, it is important to find the maximal time between all the pairs of houses for each day, so every student would know the time when he has to run to his house.Find all the maximal times of paths between every pairs of houses after $$$t=0$$$, $$$t=1$$$, ..., $$$t=m-1$$$ days.", "input_spec": "In the first line you are given two integers $$$n$$$ and $$$m$$$\u00a0\u2014 the number of houses in the camp and the number of raining days ($$$1 \\le n \\le 100\\,000$$$; $$$1 \\le m \\le 1\\,000\\,000$$$). In the next $$$n-1$$$ lines you are given the integers $$$u_i$$$, $$$v_i$$$, $$$a_i$$$, $$$b_i$$$\u00a0\u2014 description of pathways ($$$1 \\le u_i, v_i \\le n$$$; $$$0 \\le a_i \\le 10^5$$$; $$$0 \\le b_i \\le 10^9$$$). $$$i$$$-th pathway connects houses $$$u_i$$$ and $$$v_i$$$, and in day $$$t$$$ requires $$$a_i \\cdot t + b_i$$$ seconds to pass through. It is guaranteed that every two houses are connected by a sequence of pathways.", "output_spec": "Print $$$m$$$ integers\u00a0\u2014 the lengths of the longest path in the camp after a $$$t=0, t=1, \\ldots, t=m-1$$$ days after the start of the rain.", "sample_inputs": ["5 10\n1 2 0 100\n1 3 0 100\n1 4 10 80\n1 5 20 0"], "sample_outputs": ["200 200 200 210 220 230 260 290 320 350"], "notes": "NoteLet's consider the first example.In the first three days ($$$0 \\le t \\le 2$$$) the longest path is between 2nd and 3rd houses, and its length is equal to $$$100+100=200$$$ seconds.In the third day ($$$t=2$$$) the road between houses 1 and 4 has length $$$100$$$ and keeps increasing. So, in days $$$t=2, 3, 4, 5$$$ the longest path is between vertices 4 and (1 or 2), and has length $$$180+10t$$$. Notice, that in the day $$$t=2$$$ there are three pathways with length 100, so there are three maximal paths of equal length.In the sixth day ($$$t=5$$$) pathway between first and fifth houses get length 100. So in every day with $$$t=5$$$ and further the longest path is between houses 4 and 5 and has length $$$80+30t$$$."}, "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31"} {"nl": {"description": "A string a of length m is called antipalindromic iff m is even, and for each i (1\u2009\u2264\u2009i\u2009\u2264\u2009m) ai\u2009\u2260\u2009am\u2009-\u2009i\u2009+\u20091.Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as bi, and the beauty of t as the sum of bi among all indices i such that si\u2009=\u2009ti.Help Ivan to determine maximum possible beauty of t he can get.", "input_spec": "The first line contains one integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100, n is even) \u2014 the number of characters in s. The second line contains the string s itself. It consists of only lowercase Latin letters, and it is guaranteed that its letters can be reordered to form an antipalindromic string. The third line contains n integer numbers b1, b2, ..., bn (1\u2009\u2264\u2009bi\u2009\u2264\u2009100), where bi is the beauty of index i.", "output_spec": "Print one number \u2014 the maximum possible beauty of t.", "sample_inputs": ["8\nabacabac\n1 1 1 1 1 1 1 1", "8\nabaccaba\n1 2 3 4 5 6 7 8", "8\nabacabca\n1 2 3 4 4 3 2 1"], "sample_outputs": ["8", "26", "17"], "notes": null}, "src_uid": "896555ddb6e1c268cd7b3b6b063fce50"} {"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": "In modern cryptography much is tied to the algorithmic complexity of solving several problems. One of such problems is a discrete logarithm problem. It is formulated as follows: Let's fix a finite field and two it's elements $$$a$$$ and $$$b$$$. One need to fun such $$$x$$$ that $$$a^x = b$$$ or detect there is no such x. It is most likely that modern mankind cannot solve the problem of discrete logarithm for a sufficiently large field size. For example, for a field of residues modulo prime number, primes of 1024 or 2048 bits are considered to be safe. However, calculations with such large numbers can place a significant load on servers that perform cryptographic operations. For this reason, instead of a simple module residue field, more complex fields are often used. For such field no fast algorithms that use a field structure are known, smaller fields can be used and operations can be properly optimized. Developer Nikolai does not trust the generally accepted methods, so he wants to invent his own. Recently, he read about a very strange field\u00a0\u2014 nimbers, and thinks it's a great fit for the purpose. The field of nimbers is defined on a set of integers from 0 to $$$2^{2^k} - 1$$$ for some positive integer $$$k$$$ . Bitwise exclusive or ($$$\\oplus$$$) operation is used as addition. One of ways to define multiplication operation ($$$\\odot$$$) is following properties: $$$0 \\odot a = a \\odot 0 = 0$$$ $$$1 \\odot a = a \\odot 1 = a$$$ $$$a \\odot b = b \\odot a$$$ $$$a \\odot (b \\odot c)= (a \\odot b) \\odot c$$$ $$$a \\odot (b \\oplus c) = (a \\odot b) \\oplus (a \\odot c)$$$ If $$$a = 2^{2^n}$$$ for some integer $$$n > 0$$$, and $$$b < a$$$, then $$$a \\odot b = a \\cdot b$$$. If $$$a = 2^{2^n}$$$ for some integer $$$n > 0$$$, then $$$a \\odot a = \\frac{3}{2}\\cdot a$$$. For example: $$$ 4 \\odot 4 = 6$$$ $$$ 8 \\odot 8 = 4 \\odot 2 \\odot 4 \\odot 2 = 4 \\odot 4 \\odot 2 \\odot 2 = 6 \\odot 3 = (4 \\oplus 2) \\odot 3 = (4 \\odot 3) \\oplus (2 \\odot (2 \\oplus 1)) = (4 \\odot 3) \\oplus (2 \\odot 2) \\oplus (2 \\odot 1) = 12 \\oplus 3 \\oplus 2 = 13.$$$ $$$32 \\odot 64 = (16 \\odot 2) \\odot (16 \\odot 4) = (16 \\odot 16) \\odot (2 \\odot 4) = 24 \\odot 8 = (16 \\oplus 8) \\odot 8 = (16 \\odot 8) \\oplus (8 \\odot 8) = 128 \\oplus 13 = 141$$$ $$$5 \\odot 6 = (4 \\oplus 1) \\odot (4 \\oplus 2) = (4\\odot 4) \\oplus (4 \\odot 2) \\oplus (4 \\odot 1) \\oplus (1 \\odot 2) = 6 \\oplus 8 \\oplus 4 \\oplus 2 = 8$$$ Formally, this algorithm can be described by following pseudo-code. multiply(a, b) { ans = 0 for p1 in bits(a) // numbers of bits of a equal to one for p2 in bits(b) // numbers of bits of b equal to one ans = ans xor multiply_powers_of_2(1 << p1, 1 << p2) return ans;}multiply_powers_of_2(a, b) { if (a == 1 or b == 1) return a * b n = maximal value, such 2^{2^{n}} <= max(a, b) power = 2^{2^{n}}; if (a >= power and b >= power) { return multiply(power * 3 / 2, multiply_powers_of_2(a / power, b / power)) } else if (a >= power) { return multiply_powers_of_2(a / power, b) * power } else { return multiply_powers_of_2(a, b / power) * power }}It can be shown, that this operations really forms a field. Moreover, than can make sense as game theory operations, but that's not related to problem much. With the help of appropriate caching and grouping of operations, it is possible to calculate the product quickly enough, which is important to improve speed of the cryptoalgorithm. More formal definitions as well as additional properties can be clarified in the wikipedia article at link. The authors of the task hope that the properties listed in the statement should be enough for the solution. Powering for such muliplication is defined in same way, formally $$$a^{\\odot k} = \\underbrace{a \\odot a \\odot \\cdots \\odot a}_{k~\\texttt{times}}$$$.You need to analyze the proposed scheme strength. For pairs of numbers $$$a$$$ and $$$b$$$ you need to find such $$$x$$$, that $$$a^{\\odot x} = b$$$, or determine that it doesn't exist. ", "input_spec": "In the first line of input there is single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 number of pairs, for which you need to find the discrete logarithm. In each of next $$$t$$$ line there is a pair of integers $$$a$$$ $$$b$$$ ($$$1 \\le a, b < 2^{64}$$$). ", "output_spec": "For each pair you should print one integer $$$x$$$ ($$$0 \\le x < 2^{64}$$$), such that $$$a^{\\odot x} = b$$$, or -1 if no such x exists. It can be shown, that if any such $$$x$$$ exists, there is one inside given bounds. If there are several good values, you can output any of them. ", "sample_inputs": ["7\n2 2\n1 1\n2 3\n8 10\n8 2\n321321321321 2\n123214213213 4356903202345442785"], "sample_outputs": ["1\n1\n2\n4\n-1\n6148914691236517205\n68943624821423112"], "notes": null}, "src_uid": "54b41c5184c27d1373ec05775bc43b50"} {"nl": {"description": "A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k\u2009-\u20091 hasso\u0441ks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that flea has infinitely much time for this jumping.", "input_spec": "The only line contains single integer: 1\u2009\u2264\u2009n\u2009\u2264\u20091000 \u2014 number of hassocks.", "output_spec": "Output \"YES\" if all the hassocks will be visited and \"NO\" otherwise.", "sample_inputs": ["1", "3"], "sample_outputs": ["YES", "NO"], "notes": null}, "src_uid": "4bd174a997707ed3a368bd0f2424590f"} {"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": "A sequence of integers $$$b_1, b_2, \\ldots, b_m$$$ is called good if $$$max(b_1, b_2, \\ldots, b_m) \\cdot min(b_1, b_2, \\ldots, b_m) \\ge b_1 + b_2 + \\ldots + b_m$$$.A sequence of integers $$$a_1, a_2, \\ldots, a_n$$$ is called perfect if every non-empty subsequence of $$$a$$$ is good.YouKn0wWho has two integers $$$n$$$ and $$$M$$$, $$$M$$$ is prime. Help him find the number, modulo $$$M$$$, of perfect sequences $$$a_1, a_2, \\ldots, a_n$$$ such that $$$1 \\le a_i \\le n + 1$$$ for each integer $$$i$$$ from $$$1$$$ to $$$n$$$.A sequence $$$d$$$ is a subsequence of a sequence $$$c$$$ if $$$d$$$ can be obtained from $$$c$$$ by deletion of several (possibly, zero or all) elements.", "input_spec": "The first and only line of the input contains two space-separated integers $$$n$$$ and $$$M$$$ ($$$1 \\le n \\le 200$$$; $$$10^8 \\le M \\le 10^9$$$). It is guaranteed that $$$M$$$ is prime.", "output_spec": "Print a single integer \u00a0\u2014 the number of perfect sequences modulo $$$M$$$.", "sample_inputs": ["2 998244353", "4 100000007", "69 999999937"], "sample_outputs": ["4", "32", "456886663"], "notes": "NoteIn the first test case, the perfect sequences are $$$[2, 2]$$$, $$$[2, 3]$$$, $$$[3, 2]$$$ and $$$[3, 3]$$$.In the second test case, some of the perfect sequences are $$$[3, 4, 3, 5]$$$, $$$[4, 5, 4, 4]$$$, $$$[4, 5, 5, 5]$$$ etc. One example of a sequence which is not perfect is $$$[2, 3, 3, 4]$$$, because, for example, the subsequence $$$[2, 3, 4]$$$ is not an good as $$$2 \\cdot 4 < 2 + 3 + 4$$$."}, "src_uid": "cf57508de47d80bc983861f70bb5f3d6"} {"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": "Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234)\u2009=\u20091\u2009+\u20092\u2009+\u20093\u2009+\u20094). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with . You are given number a, help Little X to find a proper test for hack.", "input_spec": "The first line contains a single integer a\u00a0(1\u2009\u2264\u2009a\u2009\u2264\u20091018).", "output_spec": "Print two integers: l,\u2009r\u00a0(1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009<\u200910200) \u2014 the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.", "sample_inputs": ["46", "126444381000032"], "sample_outputs": ["1 10", "2333333 2333333333333"], "notes": null}, "src_uid": "52b8d97f216ea22693bc16fadcd46dae"} {"nl": {"description": "The Little Elephant is playing with the Cartesian coordinates' system. Most of all he likes playing with integer points. The Little Elephant defines an integer point as a pair of integers (x;\u00a0y), such that 0\u2009\u2264\u2009x\u2009\u2264\u2009w and 0\u2009\u2264\u2009y\u2009\u2264\u2009h. Thus, the Little Elephant knows only (w\u2009+\u20091)\u00b7(h\u2009+\u20091) distinct integer points.The Little Elephant wants to paint a triangle with vertexes at integer points, the triangle's area must be a positive integer. For that, he needs to find the number of groups of three points that form such triangle. At that, the order of points in a group matters, that is, the group of three points (0;0), (0;2), (2;2) isn't equal to the group (0;2), (0;0), (2;2).Help the Little Elephant to find the number of groups of three integer points that form a nondegenerate triangle with integer area.", "input_spec": "A single line contains two integers w and h (1\u2009\u2264\u2009w,\u2009h\u2009\u2264\u20094000).", "output_spec": "In a single output line print an integer \u2014 the remainder of dividing the answer to the problem by 1000000007 (109\u2009+\u20097).", "sample_inputs": ["2 1", "2 2"], "sample_outputs": ["36", "240"], "notes": null}, "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa"} {"nl": {"description": "There are four stones on an infinite line in integer coordinates $$$a_1, a_2, a_3, a_4$$$. The goal is to have the stones in coordinates $$$b_1, b_2, b_3, b_4$$$. The order of the stones does not matter, that is, a stone from any position $$$a_i$$$ can end up in at any position $$$b_j$$$, provided there is a required number of stones in each position (that is, if a coordinate $$$x$$$ appears $$$k$$$ times among numbers $$$b_1, \\ldots, b_4$$$, there should be exactly $$$k$$$ stones at $$$x$$$ in the end).We are allowed to move stones with the following operation: choose two stones at distinct positions $$$x$$$ and $$$y$$$ with at least one stone each, and move one stone from $$$x$$$ to $$$2y - x$$$. In other words, the operation moves a stone to a symmetric position relative to some other stone. At any moment it is allowed to have any number of stones at the same position.Find any sequence of operations that achieves the goal, or determine that it is impossible. The sequence does not have to be shortest, but it may contain at most $$$1000$$$ operations.", "input_spec": "The first line contains four integers $$$a_1, \\ldots, a_4$$$ ($$$-10^9 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 initial coordinates of the stones. There may be multiple stones sharing the same coordinate. The second line contains four integers $$$b_1, \\ldots, b_4$$$ ($$$-10^9 \\leq b_i \\leq 10^9$$$)\u00a0\u2014 target coordinates of the stones. There may be multiple targets sharing the same coordinate.", "output_spec": "If there is no sequence of operations that achieves the goal, print a single integer $$$-1$$$. Otherwise, on the first line print a single integer $$$k$$$ ($$$0 \\leq k \\leq 1000$$$)\u00a0\u2014 the number of operations in your sequence. On the next $$$k$$$ lines, describe the operations. The $$$i$$$-th of these lines should contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$x_i \\neq y_i$$$)\u00a0\u2014 coordinates of the moved stone and the center of symmetry stone for the $$$i$$$-th operation. For each operation $$$i$$$, there should at least one stone in each of the coordinates $$$x_i$$$ and $$$y_i$$$, and the resulting coordinate $$$2y_i - x_i$$$ must not exceed $$$10^{18}$$$ by absolute value. If there are multiple suitable sequences, print any of them. It is guaranteed that if there is a suitable sequence of operations, then there is also a suitable sequence that satisfies all the additional requirement.", "sample_inputs": ["0 1 2 3\n3 5 6 8", "0 0 0 0\n1 1 1 1", "0 0 0 1\n0 1 0 1"], "sample_outputs": ["3\n1 3\n2 5\n0 3", "-1", "-1"], "notes": null}, "src_uid": "7b6b3d4bc0a269836bc0113bb17f562f"} {"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": "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": "An infinitely long Line Chillland Collider (LCC) was built in Chillland. There are $$$n$$$ pipes with coordinates $$$x_i$$$ that are connected to LCC. When the experiment starts at time 0, $$$i$$$-th proton flies from the $$$i$$$-th pipe with speed $$$v_i$$$. It flies to the right with probability $$$p_i$$$ and flies to the left with probability $$$(1 - p_i)$$$. The duration of the experiment is determined as the time of the first collision of any two protons. In case there is no collision, the duration of the experiment is considered to be zero.Find the expected value of the duration of the experiment.Illustration for the first example", "input_spec": "The first line of input contains one integer $$$n$$$\u00a0\u2014 the number of pipes ($$$1 \\le n \\le 10^5$$$). Each of the following $$$n$$$ lines contains three integers $$$x_i$$$, $$$v_i$$$, $$$p_i$$$\u00a0\u2014 the coordinate of the $$$i$$$-th pipe, the speed of the $$$i$$$-th proton and the probability that the $$$i$$$-th proton flies to the right in percentage points ($$$-10^9 \\le x_i \\le 10^9, 1 \\le v \\le 10^6, 0 \\le p_i \\le 100$$$). It is guaranteed that all $$$x_i$$$ are distinct and sorted in increasing order.", "output_spec": "It's possible to prove that the answer can always be represented as a fraction $$$P/Q$$$, where $$$P$$$ is an integer and $$$Q$$$ is a natural number not divisible by $$$998\\,244\\,353$$$. In this case, print $$$P \\cdot Q^{-1}$$$ modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["2\n1 1 100\n3 1 0", "3\n7 10 0\n9 4 86\n14 5 100", "4\n6 4 50\n11 25 50\n13 16 50\n15 8 50"], "sample_outputs": ["1", "0", "150902884"], "notes": null}, "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7"} {"nl": {"description": "A chessboard n\u2009\u00d7\u2009m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly four corner-adjacent squares painted i\u2009-\u20091 (all such squares are repainted simultaneously). This process continues ad infinitum. You have to figure out how many squares we repainted exactly x times.The upper left square of the board has to be assumed to be always black. Two squares are called corner-adjacent, if they have exactly one common point.", "input_spec": "The first line contains integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20095000). The second line contains integer x (1\u2009\u2264\u2009x\u2009\u2264\u2009109).", "output_spec": "Print how many squares will be painted exactly x times.", "sample_inputs": ["3 3\n1", "3 3\n2", "1 1\n1"], "sample_outputs": ["4", "1", "1"], "notes": null}, "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb"} {"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": "Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every $$$a$$$ and $$$b$$$ such that $$$1 \\leq a \\leq b \\leq 6$$$, there is exactly one domino with $$$a$$$ dots on one half and $$$b$$$ dots on the other half. The set contains exactly $$$21$$$ dominoes. Here is an exact illustration of his set: Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It's not necessary to place a domino on each edge of the graph.When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There's a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots.How many dominoes at most can Anadi place on the edges of his graph?", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n \\leq 7$$$, $$$0 \\leq m \\leq \\frac{n\\cdot(n-1)}{2}$$$) \u2014 the number of vertices and the number of edges in the graph. The next $$$m$$$ lines contain two integers each. Integers in the $$$i$$$-th line are $$$a_i$$$ and $$$b_i$$$ ($$$1 \\leq a, b \\leq n$$$, $$$a \\neq b$$$) and denote that there is an edge which connects vertices $$$a_i$$$ and $$$b_i$$$. The graph might be disconnected. It's however guaranteed that the graph doesn't contain any self-loops, and that there is at most one edge between any pair of vertices.", "output_spec": "Output one integer which denotes the maximum number of dominoes which Anadi can place on the edges of the graph.", "sample_inputs": ["4 4\n1 2\n2 3\n3 4\n4 1", "7 0", "3 1\n1 3", "7 21\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7"], "sample_outputs": ["4", "0", "1", "16"], "notes": "NoteHere is an illustration of Anadi's graph from the first sample test: And here is one of the ways to place a domino on each of its edges: Note that each vertex is faced by the halves of dominoes with the same number of dots. For instance, all halves directed toward vertex $$$1$$$ have three dots."}, "src_uid": "11e6559cfb71b8f6ca88242094b17a2b"} {"nl": {"description": "The prestigious Codeforces kindergarten consists of n kids, numbered 1 through n. Each of them are given allowance in rubles by their parents.Today, they are going to the most famous candy shop in the town. The shop sells candies in packages: for all i between 1 and m, inclusive, it sells a package containing exactly i candies. A candy costs one ruble, so a package containing x candies costs x rubles.The kids will purchase candies in turns, starting from kid 1. In a single turn, kid i will purchase one candy package. Due to the highly competitive nature of Codeforces kindergarten, during a turn, the number of candies contained in the package purchased by the kid will always be strictly greater than the number of candies contained in the package purchased by the kid in the preceding turn (an exception is in the first turn: the first kid may purchase any package). Then, the turn proceeds to kid i\u2009+\u20091, or to kid 1 if it was kid n's turn. This process can be ended at any time, but at the end of the purchase process, all the kids must have the same number of candy packages. Of course, the amount spent by each kid on the candies cannot exceed their allowance.You work at the candy shop and would like to prepare the candies for the kids. Print the maximum number of candies that can be sold by the candy shop to the kids. If the kids cannot purchase any candy (due to insufficient allowance), print 0.", "input_spec": "The first line contains two space-separated integers n and m (2\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105,\u20092\u2009\u2264\u2009m\u2009\u2264\u20095\u00b7106,\u2009n\u2009\u2264\u2009m), denoting the number of kids and the maximum number of candies in a package sold by the candy shop, respectively. Then n lines follow, each line will contain a single positive integer not exceeding denoting the allowance of a kid in rubles. The allowances are given in order from kid 1 to kid n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is recommended to use cin, cout streams (also you may use %I64d specificator).", "output_spec": "Print a single integer denoting the maximum number of candies that can be sold by the candy shop.", "sample_inputs": ["2 5\n5\n10", "3 8\n8\n16\n13", "2 5000000\n12500002500000\n12500002500000"], "sample_outputs": ["13", "32", "12500002500000"], "notes": "NoteFor the first example, one of the scenarios that will result in 13 purchased candies is as follows. Turn 1. Kid 1 purchases 1 candy. Turn 2. Kid 2 purchases 3 candies. Turn 3. Kid 1 purchases 4 candies. Turn 4. Kid 2 purchases 5 candies. "}, "src_uid": "169f58dc87d26e0fadde6a83bb623f54"} {"nl": {"description": "Arkady decided to buy roses for his girlfriend.A flower shop has white, orange and red roses, and the total amount of them is n. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red and white roses. Also, Arkady won't buy a bouquet where all roses have the same color. Arkady wants to buy exactly k roses. For each rose in the shop he knows its beauty and color: the beauty of the i-th rose is bi, and its color is ci ('W' for a white rose, 'O' for an orange rose and 'R' for a red rose). Compute the maximum possible total beauty of a bouquet of k roses satisfying the constraints above or determine that it is not possible to make such a bouquet.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000) \u2014 the number of roses in the show and the number of roses Arkady wants to buy. The second line contains a sequence of integers b1,\u2009b2,\u2009...,\u2009bn (1\u2009\u2264\u2009bi\u2009\u2264\u200910\u2009000), where bi equals the beauty of the i-th rose. The third line contains a string c of length n, consisting of uppercase English letters 'W', 'O' and 'R', where ci denotes the color of the i-th rose: 'W' denotes white, 'O' \u00a0\u2014 orange, 'R' \u2014 red.", "output_spec": "Print the maximum possible total beauty of a bouquet of k roses that satisfies the constraints above. If it is not possible to make a single such bouquet, print -1.", "sample_inputs": ["5 3\n4 3 4 1 6\nRROWW", "5 2\n10 20 14 20 11\nRRRRR", "11 5\n5 6 3 2 3 4 7 5 4 5 6\nRWOORWORROW"], "sample_outputs": ["11", "-1", "28"], "notes": "NoteIn the first example Arkady wants to buy 3 roses. He can, for example, buy both red roses (their indices are 1 and 2, and their total beauty is 7) and the only orange rose (its index is 3, its beauty is 4). This way the total beauty of the bouquet is 11. In the second example Arkady can not buy a bouquet because all roses have the same color."}, "src_uid": "104cf5253e027929f257364b3874c38b"} {"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": "Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat.One day the director of the F company got hold of the records of a part of an online meeting of one successful team. The director watched the record and wanted to talk to the team leader. But how can he tell who the leader is? The director logically supposed that the leader is the person who is present at any conversation during a chat meeting. In other words, if at some moment of time at least one person is present on the meeting, then the leader is present on the meeting.You are the assistant director. Given the 'user logged on'/'user logged off' messages of the meeting in the chronological order, help the director determine who can be the leader. Note that the director has the record of only a continuous part of the meeting (probably, it's not the whole meeting).", "input_spec": "The first line contains integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105) \u2014 the number of team participants and the number of messages. Each of the next m lines contains a message in the format: '+ id': the record means that the person with number id (1\u2009\u2264\u2009id\u2009\u2264\u2009n) has logged on to the meeting. '- id': the record means that the person with number id (1\u2009\u2264\u2009id\u2009\u2264\u2009n) has logged off from the meeting. Assume that all the people of the team are numbered from 1 to n and the messages are given in the chronological order. It is guaranteed that the given sequence is the correct record of a continuous part of the meeting. It is guaranteed that no two log on/log off events occurred simultaneously.", "output_spec": "In the first line print integer k (0\u2009\u2264\u2009k\u2009\u2264\u2009n) \u2014 how many people can be leaders. In the next line, print k integers in the increasing order \u2014 the numbers of the people who can be leaders. If the data is such that no member of the team can be a leader, print a single number 0.", "sample_inputs": ["5 4\n+ 1\n+ 2\n- 2\n- 1", "3 2\n+ 1\n- 2", "2 4\n+ 1\n- 1\n+ 2\n- 2", "5 6\n+ 1\n- 1\n- 3\n+ 3\n+ 4\n- 4", "2 4\n+ 1\n- 2\n+ 2\n- 1"], "sample_outputs": ["4\n1 3 4 5", "1\n3", "0", "3\n2 3 5", "0"], "notes": null}, "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5"} {"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": "Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N\u2009-\u20091 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.", "input_spec": "The only line of input contains one integer: N, the number of attendees (1\u2009\u2264\u2009N\u2009\u2264\u2009109).", "output_spec": "Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.", "sample_inputs": ["1", "3", "99"], "sample_outputs": ["0", "1", "49"], "notes": null}, "src_uid": "422abdf2f705c069e540d4f5c09a4948"} {"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": "Ildar took a band (a thin strip of cloth) and colored it. Formally, the band has $$$n$$$ cells, each of them is colored into one of $$$26$$$ colors, so we can denote each color with one of the lowercase letters of English alphabet. Ildar decided to take some segment of the band $$$[l, r]$$$ ($$$1 \\le l \\le r \\le n$$$) he likes and cut it from the band. So he will create a new band that can be represented as a string $$$t = s_l s_{l+1} \\ldots s_r$$$.After that Ildar will play the following game: he cuts the band $$$t$$$ into some new bands and counts the number of different bands among them. Formally, Ildar chooses $$$1 \\le k \\le |t|$$$ indexes $$$1 \\le i_1 < i_2 < \\ldots < i_k = |t|$$$ and cuts $$$t$$$ to $$$k$$$ bands-strings $$$t_1 t_2 \\ldots t_{i_1}, t_{i_1 + 1} \\ldots t_{i_2}, \\ldots, {t_{i_{k-1} + 1}} \\ldots t_{i_k}$$$ and counts the number of different bands among them. He wants to know the minimal possible number of different bands he can get under the constraint that at least one band repeats at least two times. The result of the game is this number. If it is impossible to cut $$$t$$$ in such a way, the result of the game is -1.Unfortunately Ildar hasn't yet decided which segment he likes, but he has $$$q$$$ segments-candidates $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_q, r_q]$$$. Your task is to calculate the result of the game for each of them.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 200\\,000$$$)\u00a0\u2014 the length of the band Ildar has. The second line contains a string $$$s$$$ consisting of $$$n$$$ lowercase English letters\u00a0\u2014 the band Ildar has. The third line contains a single integer $$$q$$$ ($$$1 \\le q \\le 200\\,000$$$)\u00a0\u2014 the number of segments Ildar has chosen as candidates. Each of the next $$$q$$$ lines contains two integer integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \\le l_i \\le r_i \\le n$$$) denoting the ends of the $$$i$$$-th segment.", "output_spec": "Output $$$q$$$ lines, where the $$$i$$$-th of them should contain the result of the game on the segment $$$[l_i, r_i]$$$.", "sample_inputs": ["9\nabcabcdce\n7\n1 6\n4 7\n5 9\n6 9\n1 9\n3 6\n4 4"], "sample_outputs": ["1\n-1\n4\n3\n2\n2\n-1"], "notes": "NoteConsider the first example.If Ildar chooses the segment $$$[1, 6]$$$, he cuts a string $$$t = abcabc$$$. If he cuts $$$t$$$ into two bands $$$abc$$$ and $$$abc$$$, the band $$$abc$$$ repeats two times and the number of different tapes is $$$1$$$. So, the result of this game is $$$1$$$.If Ildar chooses the segment $$$[4, 7]$$$, he cuts a string $$$t = abcd$$$. It is impossible to cut this band in such a way that there is at least one band repeating at least two times. So, the result of this game is $$$-1$$$.If Ildar chooses the segment $$$[3, 6]$$$, he cuts a string $$$t = cabc$$$. If he cuts $$$t$$$ into three bands $$$c$$$, $$$ab$$$ and $$$c$$$, the band $$$c$$$ repeats two times and the number of different bands is $$$2$$$. So, the result of this game is $$$2$$$."}, "src_uid": "bc839e9a025a5d83e2c85fb1e224c175"} {"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": "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": "Little Petya loves training spiders. Petya has a board n\u2009\u00d7\u2009m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform its commands. There are 5 possible commands: to stay idle or to move from current cell to some of the four side-neighboring cells (that is, one command for each of the four possible directions). Petya gives the commands so that no spider leaves the field. It is allowed for spiders to pass through each other when they crawl towards each other in opposite directions. All spiders crawl simultaneously and several spiders may end up in one cell. Petya wants to know the maximum possible number of spider-free cells after one second.", "input_spec": "The first line contains two space-separated integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200940,\u2009n\u00b7m\u2009\u2264\u200940) \u2014 the board sizes.", "output_spec": "In the first line print the maximum number of cells without spiders.", "sample_inputs": ["1 1", "2 3"], "sample_outputs": ["0", "4"], "notes": "NoteIn the first sample the only possible answer is:sIn the second sample one of the possible solutions is: rdlruls denotes command \"stay idle\", l, r, d, u denote commands \"crawl left\", \"crawl right\", \"crawl down\", \"crawl up\", correspondingly."}, "src_uid": "097674b4dd696b30e102938f71dd39b9"} {"nl": {"description": "A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...", "input_spec": "The first line of input contains two integers $$$H$$$ and $$$W$$$ ($$$1 \\le H, W \\le 5$$$), separated by a space, \u2014 the height and the width of the cake. The next $$$H$$$ lines contain a string of $$$W$$$ characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.", "output_spec": "Output the number of berries the mouse will eat following her strategy.", "sample_inputs": ["4 3\n*..\n.*.\n..*\n...", "4 4\n.*..\n*...\n...*\n..*.", "3 4\n..**\n*...\n....", "5 5\n..*..\n.....\n**...\n**...\n**..."], "sample_outputs": ["3", "2", "1", "1"], "notes": null}, "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d"} {"nl": {"description": "Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies. Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions: Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer. Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that. Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that. Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that. Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that. Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that. Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that. Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary. ", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200) \u2014 the number of game parts. The next line contains n integers, the i-th integer \u2014 ci (1\u2009\u2264\u2009ci\u2009\u2264\u20093) represents the number of the computer, on which you can complete the game part number i. Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0\u2009\u2264\u2009ki\u2009\u2264\u2009n\u2009-\u20091), then ki distinct integers ai,\u2009j (1\u2009\u2264\u2009ai,\u2009j\u2009\u2264\u2009n;\u00a0ai,\u2009j\u2009\u2260\u2009i) \u2014 the numbers of parts to complete before part i. Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.", "output_spec": "On a single line print the answer to the problem.", "sample_inputs": ["1\n1\n0", "5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0"], "sample_outputs": ["1", "7"], "notes": "NoteNote to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours."}, "src_uid": "be42e213ff43e303e475d77a9560367f"} {"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": " 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": "For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence).You are given two positive integers n and m. Let S be the set of all sequences of length n consisting of numbers from 1 to m. Compute the sum f(a) over all a in S modulo 109\u2009+\u20097.", "input_spec": "The only line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009106) \u2014 the number of elements in arrays and the upper bound for elements.", "output_spec": "Print the only integer c \u2014 the desired sum modulo 109\u2009+\u20097.", "sample_inputs": ["1 3", "2 2", "3 3"], "sample_outputs": ["6", "14", "174"], "notes": null}, "src_uid": "5b775f17b188c1d8a4da212ebb3a525c"} {"nl": {"description": "The citizens of BubbleLand are celebrating their 10th anniversary so they decided to organize a big music festival. Bob got a task to invite N famous singers who would sing on the fest. He was too busy placing stages for their performances that he totally forgot to write the invitation e-mails on time, and unfortunately he only found K available singers. Now there are more stages than singers, leaving some of the stages empty. Bob would not like if citizens of BubbleLand noticed empty stages and found out that he was irresponsible.Because of that he decided to choose exactly K stages that form a convex set, make large posters as edges of that convex set and hold festival inside. While those large posters will make it impossible for citizens to see empty stages outside Bob still needs to make sure they don't see any of the empty stages inside that area.Since lots of people are coming, he would like that the festival area is as large as possible. Help him calculate the maximum area that he could obtain respecting the conditions. If there is no such area, the festival cannot be organized and the answer is 0.00.", "input_spec": "The first line of input contains two integers N (3\u2009\u2264\u2009N\u2009\u2264\u2009200) and K (3\u2009\u2264\u2009K\u2009\u2264\u2009min(N,\u200950)), separated with one empty space, representing number of stages and number of singers, respectively. Each of the next N lines contains two integers Xi and Yi (0\u2009\u2264\u2009Xi,\u2009Yi\u2009\u2264\u2009106) representing the coordinates of the stages. There are no three or more collinear stages.", "output_spec": "Output contains only one line with one number, rounded to exactly two decimal places: the maximal festival area. Rounding is performed so that 0.5 and more rounds up and everything else rounds down.", "sample_inputs": ["5 4\n0 0\n3 0\n2 1\n4 4\n1 5"], "sample_outputs": ["10.00"], "notes": "NoteExample explanation: From all possible convex polygon with 4 vertices and no other vertex inside, the largest is one with points (0,\u20090), (2,\u20091), (4,\u20094) and (1,\u20095)."}, "src_uid": "6afcdad100c8e2469fef5abcc5bd96c6"} {"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": "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": "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": "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": "Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size $$$n \\times m$$$ cells on a map (rows of grid are numbered from $$$1$$$ to $$$n$$$ from north to south, and columns are numbered from $$$1$$$ to $$$m$$$ from west to east). After that he measured the average height of each cell above Rybinsk sea level and obtained a matrix of heights of size $$$n \\times m$$$. The cell $$$(i, j)$$$ lies on the intersection of the $$$i$$$-th row and the $$$j$$$-th column and has height $$$h_{i, j}$$$. Seryozha is going to look at the result of his work in the browser. The screen of Seryozha's laptop can fit a subrectangle of size $$$a \\times b$$$ of matrix of heights ($$$1 \\le a \\le n$$$, $$$1 \\le b \\le m$$$). Seryozha tries to decide how the weather can affect the recreation center \u2014 for example, if it rains, where all the rainwater will gather. To do so, he is going to find the cell having minimum height among all cells that are shown on the screen of his laptop.Help Seryozha to calculate the sum of heights of such cells for all possible subrectangles he can see on his screen. In other words, you have to calculate the sum of minimum heights in submatrices of size $$$a \\times b$$$ with top left corners in $$$(i, j)$$$ over all $$$1 \\le i \\le n - a + 1$$$ and $$$1 \\le j \\le m - b + 1$$$.Consider the sequence $$$g_i = (g_{i - 1} \\cdot x + y) \\bmod z$$$. You are given integers $$$g_0$$$, $$$x$$$, $$$y$$$ and $$$z$$$. By miraculous coincidence, $$$h_{i, j} = g_{(i - 1) \\cdot m + j - 1}$$$ ($$$(i - 1) \\cdot m + j - 1$$$ is the index).", "input_spec": "The first line of the input contains four integers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$1 \\le n, m \\le 3\\,000$$$, $$$1 \\le a \\le n$$$, $$$1 \\le b \\le m$$$) \u2014 the number of rows and columns in the matrix Seryozha has, and the number of rows and columns that can be shown on the screen of the laptop, respectively. The second line of the input contains four integers $$$g_0$$$, $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \\le g_0, x, y < z \\le 10^9$$$).", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["3 4 2 1\n1 2 3 59"], "sample_outputs": ["111"], "notes": "NoteThe matrix from the first example: "}, "src_uid": "4618fbffb2b9d321a6d22c11590a4773"} {"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": "Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such tickets and moved on to a more general question. Now he explores k-lucky tickets.Pollard sais that a ticket is k-lucky if we can add arithmetic operation signs between its digits to the left or right of them (i.e., \"+\", \"-\", \"\u2009\u00d7\u2009\") and brackets so as to obtain the correct arithmetic expression whose value would equal k. For example, ticket \"224201016\" is 1000-lucky as (\u2009-\u20092\u2009-\u2009(2\u2009+\u20094))\u2009\u00d7\u2009(2\u2009+\u20090)\u2009+\u20091016\u2009=\u20091000.Pollard was so carried away by the lucky tickets that he signed up for a seminar on lucky tickets and, as far as Gerald knows, Pollard will attend it daily at 7 pm in some famous institute and will commute to it in the same tram for m days. In this tram tickets have eight digits. And Gerald wants to make a surprise for Pollard: each day Pollard will receive a tram k-lucky ticket. The conductor has already agreed to give Pollard certain tickets during all these m days and he only wants Gerald to tell him what kind of tickets to give out. In this regard, help Gerald pick exactly m distinct k-lucky tickets.", "input_spec": "The single line contains two integers k and m (0\u2009\u2264\u2009k\u2009\u2264\u2009104, 1\u2009\u2264\u2009m\u2009\u2264\u20093\u00b7105).", "output_spec": "Print m lines. Each line must contain exactly 8 digits \u2014 the k-winning ticket. The tickets may begin with 0, all tickets must be distinct. If there are more than m distinct k-lucky tickets, print any m of them. It is guaranteed that at least m distinct k-lucky tickets exist. The tickets can be printed in any order.", "sample_inputs": ["0 3", "7 4"], "sample_outputs": ["00000000\n00000001\n00000002", "00000007\n00000016\n00000017\n00000018"], "notes": null}, "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c"} {"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": "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": "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": "Fedya loves problems involving data structures. Especially ones about different queries on subsegments. Fedya had a nice array $$$a_1, a_2, \\ldots a_n$$$ and a beautiful data structure. This data structure, given $$$l$$$ and $$$r$$$, $$$1 \\le l \\le r \\le n$$$, could find the greatest integer $$$d$$$, such that $$$d$$$ divides each of $$$a_l$$$, $$$a_{l+1}$$$, ..., $$$a_{r}$$$. Fedya really likes this data structure, so he applied it to every non-empty contiguous subarray of array $$$a$$$, put all answers into the array and sorted it. He called this array $$$b$$$. It's easy to see that array $$$b$$$ contains $$$n(n+1)/2$$$ elements.After that, Fedya implemented another cool data structure, that allowed him to find sum $$$b_l + b_{l+1} + \\ldots + b_r$$$ for given $$$l$$$ and $$$r$$$, $$$1 \\le l \\le r \\le n(n+1)/2$$$. Surely, Fedya applied this data structure to every contiguous subarray of array $$$b$$$, called the result $$$c$$$ and sorted it. Help Fedya find the lower median of array $$$c$$$.Recall that for a sorted array of length $$$k$$$ the lower median is an element at position $$$\\lfloor \\frac{k + 1}{2} \\rfloor$$$, if elements of the array are enumerated starting from $$$1$$$. For example, the lower median of array $$$(1, 1, 2, 3, 6)$$$ is $$$2$$$, and the lower median of $$$(0, 17, 23, 96)$$$ is $$$17$$$.", "input_spec": "First line contains a single integer $$$n$$$\u00a0\u2014 number of elements in array $$$a$$$ ($$$1 \\le n \\le 50\\,000$$$). Second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$\u00a0\u2014 elements of the array ($$$1 \\le a_i \\le 100\\,000$$$).", "output_spec": "Print a single integer\u00a0\u2014 the lower median of array $$$c$$$.", "sample_inputs": ["2\n6 3", "2\n8 8", "5\n19 16 2 12 15"], "sample_outputs": ["6", "8", "12"], "notes": "NoteIn the first sample array $$$b$$$ is equal to $$${3, 3, 6}$$$, then array $$$c$$$ is equal to $$${3, 3, 6, 6, 9, 12}$$$, so the lower median is $$$6$$$.In the second sample $$$b$$$ is $$${8, 8, 8}$$$, $$$c$$$ is $$${8, 8, 8, 16, 16, 24}$$$, so the lower median is $$$8$$$."}, "src_uid": "7516cc0a6d76569a761cf795cfb22d50"} {"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": "Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 10^9$$$).", "output_spec": "Output one integer\u00a0\u2014 the answer to the problem.", "sample_inputs": ["7", "8", "9"], "sample_outputs": ["4", "5", "5"], "notes": "NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\\textbf 7$$$] Weight 2: [$$$\\textbf 3$$$, $$$\\textbf 3$$$, 1] Weight 3: [$$$\\textbf 2$$$, $$$\\textbf 2$$$, $$$\\textbf 2$$$, 1] Weight 7: [$$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$]"}, "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"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": "One day Vasya heard a story: \"In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids...\"The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.The bus fare equals one berland ruble in High Bertown. However, not everything is that easy \u2014 no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k\u2009>\u20090) children, pays overall k rubles: a ticket for himself and (k\u2009-\u20091) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.", "input_spec": "The input file consists of a single line containing two space-separated numbers n and m (0\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105) \u2014 the number of the grown-ups and the number of the children in the bus, correspondingly.", "output_spec": "If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers \u2014 the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print \"Impossible\" (without the quotes).", "sample_inputs": ["1 2", "0 5", "2 2"], "sample_outputs": ["2 2", "Impossible", "2 3"], "notes": "NoteIn the first sample a grown-up rides with two children and pays two rubles.In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total. "}, "src_uid": "1e865eda33afe09302bda9077d613763"} {"nl": {"description": "There are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k\u2009+\u20091, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types k\u2009+\u20091 and k equals ak. It is known that for each x there are at most 20 coin types of denomination x.Byteasar has bk coins of type k with him, and he needs to pay exactly m tugricks. It is known that Byteasar never has more than 3\u00b7105 coins with him. Byteasar want to know how many ways there are to pay exactly m tugricks. Two ways are different if there is an integer k such that the amount of coins of type k differs in these two ways. As all Byteland citizens, Byteasar wants to know the number of ways modulo 109\u2009+\u20097.", "input_spec": "The first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20093\u00b7105)\u00a0\u2014 the number of coin types. The second line contains n\u2009-\u20091 integers a1, a2, ..., an\u2009-\u20091 (1\u2009\u2264\u2009ak\u2009\u2264\u2009109)\u00a0\u2014 the ratios between the coin types denominations. It is guaranteed that for each x there are at most 20 coin types of denomination x. The third line contains n non-negative integers b1, b2, ..., bn\u00a0\u2014 the number of coins of each type Byteasar has. It is guaranteed that the sum of these integers doesn't exceed 3\u00b7105. The fourth line contains single integer m (0\u2009\u2264\u2009m\u2009<\u20091010000)\u00a0\u2014 the amount in tugricks Byteasar needs to pay.", "output_spec": "Print single integer\u00a0\u2014 the number of ways to pay exactly m tugricks modulo 109\u2009+\u20097.", "sample_inputs": ["1\n\n4\n2", "2\n1\n4 4\n2", "3\n3 3\n10 10 10\n17"], "sample_outputs": ["1", "3", "6"], "notes": "NoteIn the first example Byteasar has 4 coins of denomination 1, and he has to pay 2 tugricks. There is only one way.In the second example Byteasar has 4 coins of each of two different types of denomination 1, he has to pay 2 tugricks. There are 3 ways: pay one coin of the first type and one coin of the other, pay two coins of the first type, and pay two coins of the second type.In the third example the denominations are equal to 1, 3, 9."}, "src_uid": "71b23bc529ee1484d9dcea84def45d53"} {"nl": {"description": "Earlier, when there was no Internet, each bank had a lot of offices all around Bankopolis, and it caused a lot of problems. Namely, each day the bank had to collect cash from all the offices.Once Oleg the bank client heard a dialogue of two cash collectors. Each day they traveled through all the departments and offices of the bank following the same route every day. The collectors started from the central department and moved between some departments or between some department and some office using special roads. Finally, they returned to the central department. The total number of departments and offices was n, the total number of roads was n\u2009-\u20091. In other words, the special roads system was a rooted tree in which the root was the central department, the leaves were offices, the internal vertices were departments. The collectors always followed the same route in which the number of roads was minimum possible, that is 2n\u2009-\u20092.One of the collectors said that the number of offices they visited between their visits to offices a and then b (in the given order) is equal to the number of offices they visited between their visits to offices b and then a (in this order). The other collector said that the number of offices they visited between their visits to offices c and then d (in this order) is equal to the number of offices they visited between their visits to offices d and then c (in this order). The interesting part in this talk was that the shortest path (using special roads only) between any pair of offices among a, b, c and d passed through the central department.Given the special roads map and the indexes of offices a, b, c and d, determine if the situation described by the collectors was possible, or not.", "input_spec": "The first line contains single integer n (5\u2009\u2264\u2009n\u2009\u2264\u20095000)\u00a0\u2014 the total number of offices and departments. The departments and offices are numbered from 1 to n, the central office has index 1. The second line contains four integers a, b, c and d (2\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d\u2009\u2264\u2009n)\u00a0\u2014 the indexes of the departments mentioned in collector's dialogue. It is guaranteed that these indexes are offices (i.e. leaves of the tree), not departments. It is guaranteed that the shortest path between any pair of these offices passes through the central department. On the third line n\u2009-\u20091 integers follow: p2,\u2009p3,\u2009...,\u2009pn (1\u2009\u2264\u2009pi\u2009<\u2009i), where pi denotes that there is a special road between the i-th office or department and the pi-th department. Please note the joint enumeration of departments and offices. It is guaranteed that the given graph is a tree. The offices are the leaves, the departments are the internal vertices.", "output_spec": "If the situation described by the cash collectors was possible, print \"YES\". Otherwise, print \"NO\".", "sample_inputs": ["5\n2 3 4 5\n1 1 1 1", "10\n3 8 9 10\n1 2 2 2 2 2 1 1 1", "13\n13 12 9 7\n1 1 1 1 5 5 2 2 2 3 3 4"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example the following collector's route was possible: . We can note that between their visits to offices a and b the collectors visited the same number of offices as between visits to offices b and a; the same holds for c and d (the collectors' route is infinite as they follow it each day).In the second example there is no route such that between their visits to offices c and d the collectors visited the same number of offices as between visits to offices d and c. Thus, there situation is impossible. In the third example one of the following routes is: ."}, "src_uid": "87db879f0ca422020125a3e4d99d3c23"} {"nl": {"description": "It's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood. The neighborhood consists of n houses in a straight line, labelled 1 to n from left to right, all an equal distance apart.Everyone in this neighborhood loves peace and quiet. Because of this, whenever a new person moves into the neighborhood, he or she always chooses the house whose minimum distance to any occupied house is maximized. If there are multiple houses with the maximum possible minimum distance, he or she chooses the leftmost one.Note that the first person to arrive always moves into house 1.Karen is the k-th person to enter this neighborhood. If everyone, including herself, follows this rule, which house will she move into?", "input_spec": "The first and only line of input contains two integers, n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u20091018), describing the number of houses in the neighborhood, and that Karen was the k-th person to move in, respectively.", "output_spec": "Output a single integer on a line by itself, the label of the house Karen will move into.", "sample_inputs": ["6 4", "39 3"], "sample_outputs": ["2", "20"], "notes": "NoteIn the first test case, there are 6 houses in the neighborhood, and Karen is the fourth person to move in: The first person moves into house 1. The second person moves into house 6. The third person moves into house 3. The fourth person moves into house 2. In the second test case, there are 39 houses in the neighborhood, and Karen is the third person to move in: The first person moves into house 1. The second person moves into house 39. The third person moves into house 20. "}, "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f"} {"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": "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": "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": "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": "qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.", "input_spec": "jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1\u2009\u2264\u2009d\u2009\u2264\u200911184) \u2014 jxu edu-rqiut ydtun ev jxu ucyhf je vydt.", "output_spec": "ekjfkj q iydwbu dkcruh.", "sample_inputs": ["1"], "sample_outputs": ["13"], "notes": null}, "src_uid": "53879e79cccbacfa6586d40cf3436657"} {"nl": {"description": "Valera came to Japan and bought many robots for his research. He's already at the airport, the plane will fly very soon and Valera urgently needs to bring all robots to the luggage compartment.The robots are self-propelled (they can potentially move on their own), some of them even have compartments to carry other robots. More precisely, for the i-th robot we know value ci \u2014 the number of robots it can carry. In this case, each of ci transported robots can additionally carry other robots.However, the robots need to be filled with fuel to go, so Valera spent all his last money and bought S liters of fuel. He learned that each robot has a restriction on travel distances. Thus, in addition to features ci, the i-th robot has two features fi and li \u2014 the amount of fuel (in liters) needed to move the i-th robot, and the maximum distance that the robot can go.Due to the limited amount of time and fuel, Valera wants to move the maximum number of robots to the luggage compartment. He operates as follows. First Valera selects some robots that will travel to the luggage compartment on their own. In this case the total amount of fuel required to move all these robots must not exceed S. Then Valera seats the robots into the compartments, so as to transport as many robots as possible. Note that if a robot doesn't move by itself, you can put it in another not moving robot that is moved directly or indirectly by a moving robot. After that all selected and seated robots along with Valera go to the luggage compartment and the rest robots will be lost. There are d meters to the luggage compartment. Therefore, the robots that will carry the rest, must have feature li of not less than d. During the moving Valera cannot stop or change the location of the robots in any way.Help Valera calculate the maximum number of robots that he will be able to take home, and the minimum amount of fuel he will have to spend, because the remaining fuel will come in handy in Valera's research.", "input_spec": "The first line contains three space-separated integers n,\u2009d,\u2009S (1\u2009\u2264\u2009n\u2009\u2264\u2009105,\u20091\u2009\u2264\u2009d,\u2009S\u2009\u2264\u2009109). The first number represents the number of robots, the second one \u2014 the distance to the luggage compartment and the third one \u2014 the amount of available fuel. Next n lines specify the robots. The i-th line contains three space-separated integers ci,\u2009fi,\u2009li (0\u2009\u2264\u2009ci,\u2009fi,\u2009li\u2009\u2264\u2009109) \u2014 the i-th robot's features. The first number is the number of robots the i-th robot can carry, the second number is the amount of fuel needed for the i-th robot to move and the third one shows the maximum distance the i-th robot can go.", "output_spec": "Print two space-separated integers \u2014 the maximum number of robots Valera can transport to the luggage compartment and the minimum amount of fuel he will need for that. If Valera won't manage to get any robots to the luggage compartment, print two zeroes.", "sample_inputs": ["3 10 10\n0 12 10\n1 6 10\n0 1 1", "2 7 10\n3 12 10\n5 16 8", "4 8 10\n0 12 3\n1 1 0\n0 3 11\n1 6 9"], "sample_outputs": ["2 6", "0 0", "4 9"], "notes": null}, "src_uid": "e69f42403f3b0357e06a14523025b34a"} {"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": "One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.", "input_spec": "The single input line contains space-separated integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u200950, 1\u2009\u2264\u2009k\u2009\u2264\u2009250) \u2014 the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.", "output_spec": "Print the single number \u2014 the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.", "sample_inputs": ["4 8", "4 10", "1 3"], "sample_outputs": ["4", "2", "0"], "notes": "NoteIn the first sample the author has to get a 2 for all his exams.In the second sample he should get a 3 for two exams and a 2 for two more.In the third sample he should get a 3 for one exam."}, "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"nl": {"description": "Little C loves number \u00ab3\u00bb very much. He loves all things about it.Now he is playing a game on a chessboard of size $$$n \\times m$$$. The cell in the $$$x$$$-th row and in the $$$y$$$-th column is called $$$(x,y)$$$. Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly $$$3$$$. The Manhattan distance between two cells $$$(x_i,y_i)$$$ and $$$(x_j,y_j)$$$ is defined as $$$|x_i-x_j|+|y_i-y_j|$$$.He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.", "input_spec": "A single line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n,m \\leq 10^9$$$) \u2014 the number of rows and the number of columns of the chessboard.", "output_spec": "Print one integer \u2014 the maximum number of chessmen Little C can place.", "sample_inputs": ["2 2", "3 3"], "sample_outputs": ["0", "8"], "notes": "NoteIn the first example, the Manhattan distance between any two cells is smaller than $$$3$$$, so the answer is $$$0$$$.In the second example, a possible solution is $$$(1,1)(3,2)$$$, $$$(1,2)(3,3)$$$, $$$(2,1)(1,3)$$$, $$$(3,1)(2,3)$$$."}, "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70"} {"nl": {"description": "InputThe only line of the input contains a 7-digit hexadecimal number. The first \"digit\" of the number is letter A, the rest of the \"digits\" are decimal digits 0-9.OutputOutput a single integer.ExamplesInput\nA278832\nOutput\n0\nInput\nA089956\nOutput\n0\nInput\nA089957\nOutput\n1\nInput\nA144045\nOutput\n1\n", "input_spec": "The only line of the input contains a 7-digit hexadecimal number. The first \"digit\" of the number is letter A, the rest of the \"digits\" are decimal digits 0-9.", "output_spec": "Output a single integer.", "sample_inputs": ["A278832", "A089956", "A089957", "A144045"], "sample_outputs": ["0", "0", "1", "1"], "notes": null}, "src_uid": "e52bc741bb72bb8e79cf392b2d15354f"} {"nl": {"description": "In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.You are given two strings s1, s2 and another string called virus. Your task is to find the longest common subsequence of s1 and s2, such that it doesn't contain virus as a substring.", "input_spec": "The input contains three strings in three separate lines: s1, s2 and virus (1\u2009\u2264\u2009|s1|,\u2009|s2|,\u2009|virus|\u2009\u2264\u2009100). Each string consists only of uppercase English letters.", "output_spec": "Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted. If there is no valid common subsequence, output 0.", "sample_inputs": ["AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "AA\nA\nA"], "sample_outputs": ["ORZ", "0"], "notes": null}, "src_uid": "391c2abbe862139733fcb997ba1629b8"} {"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": "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": "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": "n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by k or decrease all numbers at points in the set by k. You would like to eventually end up with all numbers equal to 0. Is it possible?A set of 2 points is considered evenly spaced if they are diametrically opposed, and a set of 3 or more points is considered evenly spaced if they form a regular polygon.", "input_spec": "The first line of input contains an integer n (3\u2009\u2264\u2009n\u2009\u2264\u2009100000), the number of points along the circle. The following line contains a string s with exactly n digits, indicating the numbers initially present at each of the points, in clockwise order.", "output_spec": "Print \"YES\" (without quotes) if there is some sequence of operations that results in all numbers being 0, otherwise \"NO\" (without quotes). You can print each letter in any case (upper or lower).", "sample_inputs": ["30\n000100000100000110000000001100", "6\n314159"], "sample_outputs": ["YES", "NO"], "notes": "NoteIf we label the points from 1 to n, then for the first test case we can set k\u2009=\u20091. Then we increase the numbers at points 7 and 22 by 1, then decrease the numbers at points 7, 17, and 27 by 1, then decrease the numbers at points 4, 10, 16, 22, and 28 by 1."}, "src_uid": "63c00c5ea7aee792e8a30dc2c330c3f7"} {"nl": {"description": "While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number \"586\" are the same as finger movements for number \"253\": Mike has already put in a number by his \"finger memory\" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?", "input_spec": "The first line of the input contains the only integer n (1\u2009\u2264\u2009n\u2009\u2264\u20099)\u00a0\u2014 the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.", "output_spec": "If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print \"YES\" (without quotes) in the only line. Otherwise print \"NO\" (without quotes) in the first line.", "sample_inputs": ["3\n586", "2\n09", "9\n123456789", "3\n911"], "sample_outputs": ["NO", "NO", "YES", "YES"], "notes": "NoteYou can find the picture clarifying the first sample case in the statement above."}, "src_uid": "d0f5174bb0bcca5a486db327b492bf33"} {"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": "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": "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": "Igor the analyst is at work. He learned about a feature in his text editor called \"Replace All\". Igor is too bored at work and thus he came up with the following problem:Given two strings x and y which consist of the English letters 'A' and 'B' only, a pair of strings (s,\u2009t) is called good if: s and t consist of the characters '0' and '1' only. 1\u2009\u2264\u2009|s|,\u2009|t|\u2009\u2264\u2009n, where |z| denotes the length of string z, and n is a fixed positive integer. If we replace all occurrences of 'A' in x and y with the string s, and replace all occurrences of 'B' in x and y with the string t, then the two obtained from x and y strings are equal. For example, if x\u2009=\u2009AAB, y\u2009=\u2009BB and n\u2009=\u20094, then (01, 0101) is one of good pairs of strings, because both obtained after replacing strings are \"01010101\".The flexibility of a pair of strings x and y is the number of pairs of good strings (s,\u2009t). The pairs are ordered, for example the pairs (0, 1) and (1, 0) are different.You're given two strings c and d. They consist of characters 'A', 'B' and '?' only. Find the sum of flexibilities of all possible pairs of strings (c',\u2009d') such that c' and d' can be obtained from c and d respectively by replacing the question marks with either 'A' or 'B', modulo 109\u2009+\u20097.", "input_spec": "The first line contains the string c (1\u2009\u2264\u2009|c|\u2009\u2264\u20093\u00b7105). The second line contains the string d (1\u2009\u2264\u2009|d|\u2009\u2264\u20093\u00b7105). The last line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20093\u00b7105).", "output_spec": "Output a single integer: the answer to the problem, modulo 109\u2009+\u20097.", "sample_inputs": ["A?\n?\n3", "A\nB\n10"], "sample_outputs": ["2", "2046"], "notes": "NoteFor the first sample, there are four possible pairs of (c',\u2009d').If (c',\u2009d')\u2009=\u2009(AA,\u2009A), then the flexibility is 0.If (c',\u2009d')\u2009=\u2009(AB,\u2009A), then the flexibility is 0.If (c',\u2009d')\u2009=\u2009(AA,\u2009B), then the flexibility is 2, as the pairs of binary strings (1,\u200911), (0,\u200900) are the only good pairs.If (c',\u2009d')\u2009=\u2009(AB,\u2009B), then the flexibility is 0.Thus, the total flexibility is 2.For the second sample, there are 21\u2009+\u200922\u2009+\u2009...\u2009+\u2009210\u2009=\u20092046 possible binary strings of length not greater 10, and the set of pairs of good strings is precisely the set of pairs (s,\u2009s), where s is a binary string of length not greater than 10."}, "src_uid": "4a6525f37d70dd1bf4f33cef57371b64"} {"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": "Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request.Also, there are now villages with as few as a single inhabitant, meaning that .Can you help Heidi find out whether a village follows a Poisson or a uniform distribution?", "input_spec": "Same as for the easy and medium versions. But remember that now 1\u2009\u2264\u2009P\u2009\u2264\u20091000 and that the marmots may provide positive as well as negative integers.", "output_spec": "Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution.", "sample_inputs": [], "sample_outputs": [], "notes": null}, "src_uid": "6ef75e501b318c0799d3cbe8ca998984"} {"nl": {"description": "Two chess pieces, a rook and a knight, stand on a standard chessboard 8\u2009\u00d7\u20098 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square.", "input_spec": "The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide.", "output_spec": "Print a single number which is the required number of ways.", "sample_inputs": ["a1\nb2", "a8\nd4"], "sample_outputs": ["44", "38"], "notes": null}, "src_uid": "073023c6b72ce923df2afd6130719cfc"} {"nl": {"description": "As you all know, the plum harvesting season is on! Little Milutin had his plums planted in an orchard that can be represented as an $$$n$$$ by $$$m$$$ matrix. While he was harvesting, he wrote the heights of all trees in a matrix of dimensions $$$n$$$ by $$$m$$$.At night, when he has spare time, he likes to perform various statistics on his trees. This time, he is curious to find out the height of his lowest tree. So far, he has discovered some interesting properties of his orchard. There is one particular property that he thinks is useful for finding the tree with the smallest heigh.Formally, let $$$L(i)$$$ be the leftmost tree with the smallest height in the $$$i$$$-th row of his orchard. He knows that $$$L(i) \\le L(i+1)$$$ for all $$$1 \\le i \\le n - 1$$$. Moreover, if he takes a submatrix induced by any subset of rows and any subset of columns, $$$L(i) \\le L(i+1)$$$ will hold for all $$$1 \\le i \\le n'-1$$$, where $$$n'$$$ is the number of rows in that submatrix.Since the season is at its peak and he is short on time, he asks you to help him find the plum tree with minimal height.", "input_spec": "This problem is interactive. The first line of input will contain two integers $$$n$$$ and $$$m$$$, representing the number of rows and the number of columns in Milutin's orchard. It is guaranteed that $$$1 \\le n, m \\le 10^6$$$. The following lines will contain the answers to your queries.", "output_spec": "Once you know have found the minimum value $$$r$$$, you should print ! $$$r$$$ to the standard output.", "sample_inputs": ["5 5\n13 15 10 9 15\n15 17 12 11 17\n10 12 7 6 12\n17 19 14 13 19\n16 18 13 12 18"], "sample_outputs": [""], "notes": null}, "src_uid": "d663fcd3c550d7e4987010e07c001422"} {"nl": {"description": "Qwerty the Ranger arrived to the Diatar system with a very important task. He should deliver a special carcinogen for scientific research to planet Persephone. This is urgent, so Qwerty has to get to the planet as soon as possible. A lost day may fail negotiations as nobody is going to pay for an overdue carcinogen.You can consider Qwerty's ship, the planet Persephone and the star Diatar points on a plane. Diatar is located in the origin of coordinate axes \u2014 at point (0,\u20090). Persephone goes round Diatar along a circular orbit with radius R in the counter-clockwise direction at constant linear speed vp (thus, for instance, a full circle around the star takes of time). At the initial moment of time Persephone is located at point (xp,\u2009yp).At the initial moment of time Qwerty's ship is at point (x,\u2009y). Qwerty can move in any direction at speed of at most v (v\u2009>\u2009vp). The star Diatar is hot (as all stars), so Qwerty can't get too close to it. The ship's metal sheathing melts at distance r (r\u2009<\u2009R) from the star.Find the minimum time Qwerty needs to get the carcinogen to planet Persephone.", "input_spec": "The first line contains space-separated integers xp, yp and vp (\u2009-\u2009104\u2009\u2264\u2009xp,\u2009yp\u2009\u2264\u2009104, 1\u2009\u2264\u2009vp\u2009<\u2009104) \u2014 Persephone's initial position and the speed at which it goes round Diatar. The second line contains space-separated integers x, y, v and r (\u2009-\u2009104\u2009\u2264\u2009x,\u2009y\u2009\u2264\u2009104, 1\u2009<\u2009v\u2009\u2264\u2009104, 1\u2009\u2264\u2009r\u2009\u2264\u2009104) \u2014 The intial position of Qwerty's ship, its maximum speed and the minimum safe distance to star Diatar. It is guaranteed that r2\u2009<\u2009x2\u2009+\u2009y2, r2\u2009<\u2009xp2\u2009+\u2009yp2 and vp\u2009<\u2009v.", "output_spec": "Print a single real number \u2014 the minimum possible delivery time. The answer will be considered valid if its absolute or relative error does not exceed 10\u2009-\u20096.", "sample_inputs": ["10 0 1\n-10 0 2 8", "50 60 10\n50 60 20 40"], "sample_outputs": ["9.584544103", "0.000000000"], "notes": null}, "src_uid": "e8471556906e5fa3a701842570fa4ee2"} {"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": "Consider the following grammar: <expression> ::= <term> | <expression> '+' <term> <term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')' <number> ::= <pos_digit> | <number> <digit> <digit> ::= '0' | <pos_digit> <pos_digit> ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'This grammar describes a number in decimal system using the following rules: <number> describes itself, <number>-<number> (l-r, l\u2009\u2264\u2009r) describes integer which is concatenation of all integers from l to r, written without leading zeros. For example, 8-11 describes 891011, <number>(<expression>) describes integer which is concatenation of <number> copies of integer described by <expression>, <expression>+<term> describes integer which is concatenation of integers described by <expression> and <term>.For example, 2(2-4+1)+2(2(17)) describes the integer 2341234117171717.You are given an expression in the given grammar. Print the integer described by it modulo 109\u2009+\u20097.", "input_spec": "The only line contains a non-empty string at most 105 characters long which is valid according to the given grammar. In particular, it means that in terms l-r l\u2009\u2264\u2009r holds.", "output_spec": "Print single integer\u00a0\u2014 the number described by the expression modulo 109\u2009+\u20097.", "sample_inputs": ["8-11", "2(2-4+1)+2(2(17))", "1234-5678", "1+2+3+4-5+6+7-9"], "sample_outputs": ["891011", "100783079", "745428774", "123456789"], "notes": null}, "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c"} {"nl": {"description": "Vasya has got a tree consisting of $$$n$$$ vertices. He wants to delete some (possibly zero) edges in this tree such that the maximum matching in the resulting graph is unique. He asks you to calculate the number of ways to choose a set of edges to remove.A matching in the graph is a subset of its edges such that there is no vertex incident to two (or more) edges from the subset. A maximum matching is a matching such that the number of edges in the subset is maximum possible among all matchings in this graph.Since the answer may be large, output it modulo $$$998244353$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 3 \\cdot 10^5$$$) \u2014 the number of vertices in the tree. Each of the next $$$n \u2212 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \\le u, v \\le n, u \\neq v$$$) denoting an edge between vertex $$$u$$$ and vertex $$$v$$$. It is guaranteed that these edges form a tree.", "output_spec": "Print one integer \u2014 the number of ways to delete some (possibly empty) subset of edges so that the maximum matching in the resulting graph is unique. Print the answer modulo $$$998244353$$$.", "sample_inputs": ["4\n1 2\n1 3\n1 4", "4\n1 2\n2 3\n3 4", "1"], "sample_outputs": ["4", "6", "1"], "notes": "NotePossible ways to delete edges in the first example: delete $$$(1, 2)$$$ and $$$(1, 3)$$$. delete $$$(1, 2)$$$ and $$$(1, 4)$$$. delete $$$(1, 3)$$$ and $$$(1, 4)$$$. delete all edges. Possible ways to delete edges in the second example: delete no edges. delete $$$(1, 2)$$$ and $$$(2, 3)$$$. delete $$$(1, 2)$$$ and $$$(3, 4)$$$. delete $$$(2, 3)$$$ and $$$(3, 4)$$$. delete $$$(2, 3)$$$. delete all edges. "}, "src_uid": "a40e78a7144ac2fae1890ac7598990bf"} {"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": "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": "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": " 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": "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": "InputThe input contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u200964).OutputOutput a single integer.ExamplesInput2Output1Input4Output2Input27Output5Input42Output6", "input_spec": "The input contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u200964).", "output_spec": "Output a single integer.", "sample_inputs": ["2", "4", "27", "42"], "sample_outputs": ["1", "2", "5", "6"], "notes": null}, "src_uid": "c50b6af99ca7b9c35628b52774d6c32b"} {"nl": {"description": "In the wilds far beyond lies the Land of Sacredness, which can be viewed as a tree \u00a0\u2014 connected undirected graph consisting of $$$n$$$ nodes and $$$n-1$$$ edges. The nodes are numbered from $$$1$$$ to $$$n$$$. There are $$$m$$$ travelers attracted by its prosperity and beauty. Thereupon, they set off their journey on this land. The $$$i$$$-th traveler will travel along the shortest path from $$$s_i$$$ to $$$t_i$$$. In doing so, they will go through all edges in the shortest path from $$$s_i$$$ to $$$t_i$$$, which is unique in the tree.During their journey, the travelers will acquaint themselves with the others. Some may even become friends. To be specific, the $$$i$$$-th traveler and the $$$j$$$-th traveler will become friends if and only if there are at least $$$k$$$ edges that both the $$$i$$$-th traveler and the $$$j$$$-th traveler will go through. Your task is to find out the number of pairs of travelers $$$(i, j)$$$ satisfying the following conditions: $$$1 \\leq i < j \\leq m$$$. the $$$i$$$-th traveler and the $$$j$$$-th traveler will become friends. ", "input_spec": "The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \\le n, m \\le 1.5 \\cdot 10^5$$$, $$$1\\le k\\le n$$$). Each of the next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \\le u,v \\le n$$$), denoting there is an edge between $$$u$$$ and $$$v$$$. The $$$i$$$-th line of the next $$$m$$$ lines contains two integers $$$s_i$$$ and $$$t_i$$$ ($$$1\\le s_i,t_i\\le n$$$, $$$s_i \\neq t_i$$$), denoting the starting point and the destination of $$$i$$$-th traveler. It is guaranteed that the given edges form a tree.", "output_spec": "The only line contains a single integer \u00a0\u2014 the number of pairs of travelers satisfying the given conditions.", "sample_inputs": ["8 4 1\n1 7\n1 2\n2 5\n4 6\n6 3\n6 2\n6 8\n7 8\n3 8\n2 6\n4 1", "10 4 2\n3 10\n9 3\n4 9\n4 6\n8 2\n1 7\n2 1\n4 5\n6 7\n7 1\n8 7\n9 2\n10 3", "13 8 3\n7 6\n9 11\n5 6\n11 3\n9 7\n2 12\n4 3\n1 2\n5 8\n6 13\n5 10\n3 1\n10 4\n10 11\n8 11\n4 9\n2 5\n3 5\n7 3\n8 10"], "sample_outputs": ["4", "1", "14"], "notes": "NoteIn the first example there are $$$4$$$ pairs satisfying the given requirements: $$$(1,2)$$$, $$$(1,3)$$$, $$$(1,4)$$$, $$$(3,4)$$$. The $$$1$$$-st traveler and the $$$2$$$-nd traveler both go through the edge $$$6-8$$$. The $$$1$$$-st traveler and the $$$3$$$-rd traveler both go through the edge $$$2-6$$$. The $$$1$$$-st traveler and the $$$4$$$-th traveler both go through the edge $$$1-2$$$ and $$$2-6$$$. The $$$3$$$-rd traveler and the $$$4$$$-th traveler both go through the edge $$$2-6$$$. "}, "src_uid": "6253b155201f2490f031613188b9820c"} {"nl": {"description": "per nextum in unam tum XI conscribementis fac sic vestibulo perlegementum da varo. morde varo. seqis cumula varum.cisper nextum in unam tum XI conscribementis fac sic seqis decumulamenta da varo. varum privamentum fodementum da aresulto. varum tum III elevamentum tum V multiplicamentum da bresulto. aresultum tum bresultum addementum da resulto. si CD tum resultum non praestantiam fac sic dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe. novumversum egresso scribe. cis si CD tum resultum praestantiam fac sic dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe. novumversum egresso scribe. ciscis", "input_spec": "The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.", "output_spec": "As described in the problem statement.", "sample_inputs": ["0\n1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n10"], "sample_outputs": ["f(10) = MAGNA NIMIS!\nf(-9) = -3642.00\nf(-8) = -2557.17\nf(-7) = -1712.35\nf(-6) = -1077.55\nf(-5) = -622.76\nf(-4) = -318.00\nf(-3) = -133.27\nf(-2) = -38.59\nf(1) = 6.00\nf(0) = 0.00"], "notes": null}, "src_uid": "30b3411c3c23d029ea1e9cf73e7d2f01"} {"nl": {"description": "Alex enjoys performing magic tricks. He has a trick that requires a deck of n cards. He has m identical decks of n different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs n cards at random and performs the trick with those. The resulting deck looks like a normal deck, but may have duplicates of some cards.The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful.You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case.", "input_spec": "First line of the input consists of two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091000), separated by space \u2014 number of cards in each deck, and number of decks.", "output_spec": "On the only line of the output print one floating point number \u2013 probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10\u2009-\u20096.", "sample_inputs": ["2 2", "4 4", "1 2"], "sample_outputs": ["0.6666666666666666", "0.4000000000000000", "1.0000000000000000"], "notes": "NoteIn the first sample, with probability Alex will perform the trick with two cards with the same value from two different decks. In this case the trick is guaranteed to succeed.With the remaining probability he took two different cards, and the probability of pulling off the trick is .The resulting probability is "}, "src_uid": "0b9ce20c36e53d4702869660cbb53317"} {"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": "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": "You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 10$$$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $$$n$$$ distinct space-separated integers $$$x_1, x_2, \\ldots, x_n$$$ ($$$0 \\le x_i \\le 9$$$) representing the sequence. The next line contains $$$m$$$ distinct space-separated integers $$$y_1, y_2, \\ldots, y_m$$$ ($$$0 \\le y_i \\le 9$$$) \u2014 the keys with fingerprints.", "output_spec": "In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.", "sample_inputs": ["7 3\n3 5 7 1 6 2 8\n1 2 7", "4 4\n3 4 1 0\n0 1 7 9"], "sample_outputs": ["7 1 2", "1 0"], "notes": "NoteIn the first example, the only digits with fingerprints are $$$1$$$, $$$2$$$ and $$$7$$$. All three of them appear in the sequence you know, $$$7$$$ first, then $$$1$$$ and then $$$2$$$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.In the second example digits $$$0$$$, $$$1$$$, $$$7$$$ and $$$9$$$ have fingerprints, however only $$$0$$$ and $$$1$$$ appear in the original sequence. $$$1$$$ appears earlier, so the output is 1 0. Again, the order is important."}, "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"} {"nl": {"description": "Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x\u2009\u2260\u2009y) meet in a violent fight, then the pixel that survives the fight immediately changes its color to z (z\u2009\u2260\u2009x;\u00a0z\u2009\u2260\u2009y). Pixels of the same color are friends, so they don't fight.The King of Flatland knows that his land will be peaceful and prosperous when the pixels are of the same color. For each of the three colors you know the number of pixels of this color that inhabit Flatland. Help the king and determine whether fights can bring peace and prosperity to the country and if it is possible, find the minimum number of fights needed to make the land peaceful and prosperous. ", "input_spec": "The first line contains three space-separated integers a, b and c (0\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u2009231;\u00a0a\u2009+\u2009b\u2009+\u2009c\u2009>\u20090) \u2014 the number of red, green and blue pixels, correspondingly.", "output_spec": "Print a single number \u2014 the minimum number of pixel fights before the country becomes peaceful and prosperous. If making the country peaceful and prosperous is impossible, print -1.", "sample_inputs": ["1 1 1", "3 1 0"], "sample_outputs": ["1", "3"], "notes": "NoteIn the first test sample the country needs only one fight to achieve peace and prosperity. Besides, it can be any fight whatsoever. For example, let's assume that the green and the blue pixels fight, then the surviving pixel will be red. As a result, after the fight there are two red pixels. There won't be other pixels.In the second sample the following sequence of fights is possible: red and blue, green and red, red and blue. As a result, after all fights there is one green pixel left."}, "src_uid": "b8008caf788336775cb8ebb76478b04c"} {"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": "Since next season are coming, you'd like to form a team from two or three participants. There are $$$n$$$ candidates, the $$$i$$$-th candidate has rank $$$a_i$$$. But you have weird requirements for your teammates: if you have rank $$$v$$$ and have chosen the $$$i$$$-th and $$$j$$$-th candidate, then $$$GCD(v, a_i) = X$$$ and $$$LCM(v, a_j) = Y$$$ must be met.You are very experienced, so you can change your rank to any non-negative integer but $$$X$$$ and $$$Y$$$ are tied with your birthdate, so they are fixed.Now you want to know, how many are there pairs $$$(i, j)$$$ such that there exists an integer $$$v$$$ meeting the following constraints: $$$GCD(v, a_i) = X$$$ and $$$LCM(v, a_j) = Y$$$. It's possible that $$$i = j$$$ and you form a team of two.$$$GCD$$$ is the greatest common divisor of two number, $$$LCM$$$ \u2014 the least common multiple.", "input_spec": "First line contains three integers $$$n$$$, $$$X$$$ and $$$Y$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$, $$$1 \\le X \\le Y \\le 10^{18}$$$) \u2014 the number of candidates and corresponding constants. Second line contains $$$n$$$ space separated integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^{18}$$$) \u2014 ranks of candidates.", "output_spec": "Print the only integer \u2014 the number of pairs $$$(i, j)$$$ such that there exists an integer $$$v$$$ meeting the following constraints: $$$GCD(v, a_i) = X$$$ and $$$LCM(v, a_j) = Y$$$. It's possible that $$$i = j$$$.", "sample_inputs": ["12 2 2\n1 2 3 4 5 6 7 8 9 10 11 12", "12 1 6\n1 3 5 7 9 11 12 10 8 6 4 2"], "sample_outputs": ["12", "30"], "notes": "NoteIn the first example next pairs are valid: $$$a_j = 1$$$ and $$$a_i = [2, 4, 6, 8, 10, 12]$$$ or $$$a_j = 2$$$ and $$$a_i = [2, 4, 6, 8, 10, 12]$$$. The $$$v$$$ in both cases can be equal to $$$2$$$.In the second example next pairs are valid: $$$a_j = 1$$$ and $$$a_i = [1, 5, 7, 11]$$$; $$$a_j = 2$$$ and $$$a_i = [1, 5, 7, 11, 10, 8, 4, 2]$$$; $$$a_j = 3$$$ and $$$a_i = [1, 3, 5, 7, 9, 11]$$$; $$$a_j = 6$$$ and $$$a_i = [1, 3, 5, 7, 9, 11, 12, 10, 8, 6, 4, 2]$$$. "}, "src_uid": "8d43a542d5bf79d15926c4a6a5ff608f"} {"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": "You are given a complete bipartite graph with $$$2n$$$ nodes, with $$$n$$$ nodes on each side of the bipartition. Nodes $$$1$$$ through $$$n$$$ are on one side of the bipartition, and nodes $$$n+1$$$ to $$$2n$$$ are on the other side. You are also given an $$$n \\times n$$$ matrix $$$a$$$ describing the edge weights. $$$a_{ij}$$$ denotes the weight of the edge between nodes $$$i$$$ and $$$j+n$$$. Each edge has a distinct weight.Alice and Bob are playing a game on this graph. First Alice chooses to play as either \"increasing\" or \"decreasing\" for herself, and Bob gets the other choice. Then she places a token on any node of the graph. Bob then moves the token along any edge incident to that node. They now take turns playing the following game, with Alice going first.The current player must move the token from the current vertex to some adjacent unvisited vertex. Let $$$w$$$ be the last weight of the last edge that was traversed. The edge that is traversed must be strictly greater than $$$w$$$ if the player is playing as \"increasing\", otherwise, it must be strictly less. The first player unable to make a move loses.You are given $$$n$$$ and the edge weights of the graph. You can choose to play as either Alice or Bob, and you will play against the judge. You must win all the games for your answer to be judged correct.", "input_spec": null, "output_spec": null, "sample_inputs": ["2\n3\n3 1 9\n2 5 7\n6 4 8\n6\n-1\n1\n1\nI 1\n-1"], "sample_outputs": ["A\nD 3\n2\nB\n2"], "notes": "NoteThe first example has two test cases. In the first test case, the graph looks like the following. In the sample output, the player decides to play as Alice and chooses \"decreasing\" and starting at node $$$3$$$. The judge responds by moving to node $$$6$$$. After, the player moves to node $$$2$$$. At this point, the judge has no more moves (since the weight must \"increase\"), so it gives up and prints $$$-1$$$.In the next case, we have two nodes connected by an edge of weight $$$1$$$. The player decides to play as Bob. No matter what the judge chooses, the player can move the token to the other node and the judge has no moves so will lose."}, "src_uid": "299c209b070e510e7ed3b525f51fec8a"} {"nl": {"description": "Consider a billiard table of rectangular size $$$n \\times m$$$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). There is one ball at the point $$$(x, y)$$$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $$$45^{\\circ}$$$ angle with them. We will assume that: the angles between the directions of the ball before and after a collision with a side are equal, the ball moves indefinitely long, it only stops when it falls into a pocket, the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets, initially the ball is not in a pocket. Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be.", "input_spec": "The only line contains $$$6$$$ integers $$$n$$$, $$$m$$$, $$$x$$$, $$$y$$$, $$$v_x$$$, $$$v_y$$$ ($$$1 \\leq n, m \\leq 10^9$$$, $$$0 \\leq x \\leq n$$$; $$$0 \\leq y \\leq m$$$; $$$-1 \\leq v_x, v_y \\leq 1$$$; $$$(v_x, v_y) \\neq (0, 0)$$$)\u00a0\u2014 the width of the table, the length of the table, the $$$x$$$-coordinate of the initial position of the ball, the $$$y$$$-coordinate of the initial position of the ball, the $$$x$$$-component of its initial speed and the $$$y$$$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket.", "output_spec": "Print the coordinates of the pocket the ball will fall into, or $$$-1$$$ if the ball will move indefinitely.", "sample_inputs": ["4 3 2 2 -1 1", "4 4 2 0 1 1", "10 10 10 1 -1 0"], "sample_outputs": ["0 0", "-1", "-1"], "notes": "NoteThe first sample: The second sample: In the third sample the ball will never change its $$$y$$$ coordinate, so the ball will never fall into a pocket."}, "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee"} {"nl": {"description": "Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor\u00a0\u2014\u00a0a square tile that is diagonally split into white and black part as depicted in the figure below. The dimension of this tile is perfect for this kitchen, as he will need exactly $$$w \\times h$$$ tiles without any scraps. That is, the width of the kitchen is $$$w$$$ tiles, and the height is $$$h$$$ tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge\u00a0\u2014\u00a0i.e. one of the tiles must have a white colour on the shared border, and the second one must be black. The picture on the left shows one valid tiling of a $$$3 \\times 2$$$ kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts. Find the number of possible tilings. As this number may be large, output its remainder when divided by $$$998244353$$$ (a prime number). ", "input_spec": "The only line contains two space separated integers $$$w$$$, $$$h$$$\u00a0($$$1 \\leq w,h \\leq 1\\,000$$$)\u00a0\u2014\u00a0the width and height of the kitchen, measured in tiles.", "output_spec": "Output a single integer $$$n$$$\u00a0\u2014\u00a0the remainder of the number of tilings when divided by $$$998244353$$$.", "sample_inputs": ["2 2", "2 4"], "sample_outputs": ["16", "64"], "notes": null}, "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"} {"nl": {"description": "To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings.More formally, for each invited person the following conditions should be fulfilled: all his friends should also be invited to the party; the party shouldn't have any people he dislikes; all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2,\u2009a3,\u2009...,\u2009ap\u2009-\u20091 such that all pairs of people ai and ai\u2009+\u20091 (1\u2009\u2264\u2009i\u2009<\u2009p) are friends. Help the Beaver find the maximum number of acquaintances he can invite.", "input_spec": "The first line of input contains an integer n \u2014 the number of the Beaver's acquaintances. The second line contains an integer k \u2014 the number of pairs of friends. Next k lines contain space-separated pairs of integers ui,\u2009vi \u2014 indices of people who form the i-th pair of friends. The next line contains an integer m \u2014 the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once . In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: 2\u2009\u2264\u2009n\u2009\u2264\u200914 The input limitations for getting 100 points are: 2\u2009\u2264\u2009n\u2009\u2264\u20092000 ", "output_spec": "Output a single number \u2014 the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.", "sample_inputs": ["9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9"], "sample_outputs": ["3"], "notes": "NoteLet's have a look at the example. Two groups of people can be invited: {1,\u20092,\u20093} and {4,\u20095}, thus the answer will be the size of the largest of these groups. Group {6,\u20097,\u20098,\u20099} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1,\u20092,\u20093,\u20094,\u20095} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected)."}, "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1"} {"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": "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": "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": "Ujan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers $$$n$$$ and $$$k$$$. He creates an infinite sequence $$$s$$$ by repeating the following steps. Find $$$k$$$ smallest distinct positive integers that are not in $$$s$$$. Let's call them $$$u_{1}, u_{2}, \\ldots, u_{k}$$$ from the smallest to the largest. Append $$$u_{1}, u_{2}, \\ldots, u_{k}$$$ and $$$\\sum_{i=1}^{k} u_{i}$$$ to $$$s$$$ in this order. Go back to the first step. Ujan will stop procrastinating when he writes the number $$$n$$$ in the sequence $$$s$$$. Help him find the index of $$$n$$$ in $$$s$$$. In other words, find the integer $$$x$$$ such that $$$s_{x} = n$$$. It's possible to prove that all positive integers are included in $$$s$$$ only once.", "input_spec": "The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^{5}$$$), the number of test cases. Each of the following $$$t$$$ lines contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 10^{18}$$$, $$$2 \\le k \\le 10^{6}$$$), the number to be found in the sequence $$$s$$$ and the parameter used to create the sequence $$$s$$$.", "output_spec": "In each of the $$$t$$$ lines, output the answer for the corresponding test case.", "sample_inputs": ["2\n10 2\n40 5"], "sample_outputs": ["11\n12"], "notes": "NoteIn the first sample, $$$s = (1, 2, 3, 4, 5, 9, 6, 7, 13, 8, 10, 18, \\ldots)$$$. $$$10$$$ is the $$$11$$$-th number here, so the answer is $$$11$$$.In the second sample, $$$s = (1, 2, 3, 4, 5, 15, 6, 7, 8, 9, 10, 40, \\ldots)$$$."}, "src_uid": "053192b4f6acc3a94b701e787a4172e2"} {"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": "\"Multidimensional spaces are completely out of style these days, unlike genetics problems\" \u2014 thought physicist Woll and changed his subject of study to bioinformatics. Analysing results of sequencing he faced the following problem concerning DNA sequences. We will further think of a DNA sequence as an arbitrary string of uppercase letters \"A\", \"C\", \"G\" and \"T\" (of course, this is a simplified interpretation).Let w be a long DNA sequence and s1,\u2009s2,\u2009...,\u2009sm \u2014 collection of short DNA sequences. Let us say that the collection filters w iff w can be covered with the sequences from the collection. Certainly, substrings corresponding to the different positions of the string may intersect or even cover each other. More formally: denote by |w| the length of w, let symbols of w be numbered from 1 to |w|. Then for each position i in w there exist pair of indices l,\u2009r (1\u2009\u2264\u2009l\u2009\u2264\u2009i\u2009\u2264\u2009r\u2009\u2264\u2009|w|) such that the substring w[l\u00a0...\u00a0r] equals one of the elements s1,\u2009s2,\u2009...,\u2009sm of the collection.Woll wants to calculate the number of DNA sequences of a given length filtered by a given collection, but he doesn't know how to deal with it. Help him! Your task is to find the number of different DNA sequences of length n filtered by the collection {si}.Answer may appear very large, so output it modulo 1000000009.", "input_spec": "First line contains two integer numbers n and m (1\u2009\u2264\u2009n\u2009\u2264\u20091000,\u20091\u2009\u2264\u2009m\u2009\u2264\u200910) \u2014 the length of the string and the number of sequences in the collection correspondently. Next m lines contain the collection sequences si, one per line. Each si is a nonempty string of length not greater than 10. All the strings consist of uppercase letters \"A\", \"C\", \"G\", \"T\". The collection may contain identical strings.", "output_spec": "Output should contain a single integer \u2014 the number of strings filtered by the collection modulo 1000000009 (109\u2009+\u20099).", "sample_inputs": ["2 1\nA", "6 2\nCAT\nTACT"], "sample_outputs": ["1", "2"], "notes": "NoteIn the first sample, a string has to be filtered by \"A\". Clearly, there is only one such string: \"AA\".In the second sample, there exist exactly two different strings satisfying the condition (see the pictures below). "}, "src_uid": "3f053c07deaac55c2c51df6147080340"} {"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 a special connected undirected graph where each vertex belongs to at most one simple cycle.Your task is to remove as many edges as needed to convert this graph into a tree (connected graph with no cycles). For each node, independently, output the maximum distance between it and a leaf in the resulting tree, assuming you were to remove the edges in a way that minimizes this distance.", "input_spec": "The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n \\leq 5\\cdot 10^5$$$), the number of nodes and the number of edges, respectively. Each of the following $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \\leq u,v \\leq n$$$, $$$u \\ne v$$$), and represents an edge connecting the two nodes $$$u$$$ and $$$v$$$. Each pair of nodes is connected by at most one edge. It is guaranteed that the given graph is connected and each vertex belongs to at most one simple cycle.", "output_spec": "Print $$$n$$$ space-separated integers, the $$$i$$$-th integer represents the maximum distance between node $$$i$$$ and a leaf if the removed edges were chosen in a way that minimizes this distance.", "sample_inputs": ["9 10\n7 2\n9 2\n1 6\n3 1\n4 3\n4 7\n7 6\n9 8\n5 8\n5 9", "4 4\n1 2\n2 3\n3 4\n4 1"], "sample_outputs": ["5 3 5 4 5 4 3 5 4", "2 2 2 2"], "notes": "NoteIn the first sample, a possible way to minimize the maximum distance from vertex $$$1$$$ is by removing the marked edges in the following image: Note that to minimize the answer for different nodes, you can remove different edges."}, "src_uid": "c980495a264a6314f45c230daf19c2e0"} {"nl": {"description": "A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.Given an array $$$a$$$ of length $$$n$$$, consisting only of the numbers $$$0$$$ and $$$1$$$, and the number $$$k$$$. Exactly $$$k$$$ times the following happens: Two numbers $$$i$$$ and $$$j$$$ are chosen equiprobable such that ($$$1 \\leq i < j \\leq n$$$). The numbers in the $$$i$$$ and $$$j$$$ positions are swapped. Sonya's task is to find the probability that after all the operations are completed, the $$$a$$$ array will be sorted in non-decreasing order. She turned to you for help. Help Sonya solve this problem.It can be shown that the desired probability is either $$$0$$$ or it can be represented as $$$\\dfrac{P}{Q}$$$, where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \\not\\equiv 0~\\pmod {10^9+7}$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\leq n \\leq 100, 1 \\leq k \\leq 10^9$$$)\u00a0\u2014 the length of the array $$$a$$$ and the number of operations. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 1$$$)\u00a0\u2014 the description of the array $$$a$$$.", "output_spec": "If the desired probability is $$$0$$$, print $$$0$$$, otherwise print the value $$$P \\cdot Q^{-1}$$$ $$$\\pmod {10^9+7}$$$, where $$$P$$$ and $$$Q$$$ are defined above.", "sample_inputs": ["3 2\n0 1 0", "5 1\n1 1 1 0 0", "6 4\n1 0 0 1 1 0"], "sample_outputs": ["333333336", "0", "968493834"], "notes": "NoteIn the first example, all possible variants of the final array $$$a$$$, after applying exactly two operations: $$$(0, 1, 0)$$$, $$$(0, 0, 1)$$$, $$$(1, 0, 0)$$$, $$$(1, 0, 0)$$$, $$$(0, 1, 0)$$$, $$$(0, 0, 1)$$$, $$$(0, 0, 1)$$$, $$$(1, 0, 0)$$$, $$$(0, 1, 0)$$$. Therefore, the answer is $$$\\dfrac{3}{9}=\\dfrac{1}{3}$$$.In the second example, the array will not be sorted in non-decreasing order after one operation, therefore the answer is $$$0$$$."}, "src_uid": "77f28d155a632ceaabd9f5a9d846461a"}