-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode_contests_sample_train_short.jsonl
More file actions
30 lines (30 loc) · 60.8 KB
/
code_contests_sample_train_short.jsonl
File metadata and controls
30 lines (30 loc) · 60.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{"name":"361_A. Levko and Table","description":"Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.\n\nUnfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. \n\nInput\n\nThe single line contains two integers, n and k (1 \u2264 n \u2264 100, 1 \u2264 k \u2264 1000).\n\nOutput\n\nPrint any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.\n\nIf there are multiple suitable tables, you are allowed to print any of them.\n\nExamples\n\nInput\n\n2 4\n\n\nOutput\n\n1 3\n3 1\n\n\nInput\n\n4 7\n\n\nOutput\n\n2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n\nNote\n\nIn the first sample the sum in the first row is 1 + 3 = 4, in the second row \u2014 3 + 1 = 4, in the first column \u2014 1 + 3 = 4 and in the second column \u2014 3 + 1 = 4. There are other beautiful tables for this sample.\n\nIn the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.","public_tests":{"input":["4 7\n","2 4\n"],"output":["7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 \n","4 0 \n0 4 \n"]},"source":2,"difficulty":7,"cf_contest_id":361,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["constructive algorithms","implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"732_A. Buy a Shovel","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.\n\nIn his pocket Polycarp has an unlimited number of \"10-burle coins\" and exactly one coin of r burles (1 \u2264 r \u2264 9).\n\nWhat 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.\n\nInput\n\nThe single line of input contains two integers k and r (1 \u2264 k \u2264 1000, 1 \u2264 r \u2264 9) \u2014 the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from \"10-burle coins\". \n\nRemember 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.\n\nOutput\n\nPrint the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. \n\nExamples\n\nInput\n\n117 3\n\n\nOutput\n\n9\n\n\nInput\n\n237 7\n\n\nOutput\n\n1\n\n\nInput\n\n15 2\n\n\nOutput\n\n2\n\nNote\n\nIn the first example Polycarp can buy 9 shovels and pay 9\u00b7117 = 1053 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.\n\nIn the second example it is enough for Polycarp to buy one shovel.\n\nIn the third example Polycarp should buy two shovels and pay 2\u00b715 = 30 burles. It is obvious that he can pay this sum without any change. ","public_tests":{"input":["237 7\n","15 2\n","117 3\n"],"output":["1\n","2\n","9\n"]},"source":2,"difficulty":7,"cf_contest_id":732,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["brute force","constructive algorithms","implementation","math"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"596_B. Wilbur and Array","description":"Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. \n\nOf course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.\n\nInput\n\nThe first line of the input contains a single integer n (1 \u2264 n \u2264 200 000) \u2014 the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input.\n\nThe second line of the input contains n integers b1, b2, ..., bn ( - 109 \u2264 bi \u2264 109).\n\nOutput\n\nPrint the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.\n\nExamples\n\nInput\n\n5\n1 2 3 4 5\n\n\nOutput\n\n5\n\nInput\n\n4\n1 2 2 1\n\n\nOutput\n\n3\n\nNote\n\nIn the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.\n\nIn the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.","public_tests":{"input":["4\n1 2 2 1\n","5\n1 2 3 4 5\n"],"output":["3\n","5\n"]},"source":2,"difficulty":8,"cf_contest_id":596,"cf_index":"B","cf_points":1000.0,"cf_rating":1100,"cf_tags":["greedy","implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"994_A. Fingerprints","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.\n\nSome 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.\n\nInput\n\nThe first line contains two integers n and m (1 \u2264 n, m \u2264 10) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.\n\nThe next line contains n distinct space-separated integers x_1, x_2, \u2026, x_n (0 \u2264 x_i \u2264 9) representing the sequence.\n\nThe next line contains m distinct space-separated integers y_1, y_2, \u2026, y_m (0 \u2264 y_i \u2264 9) \u2014 the keys with fingerprints.\n\nOutput\n\nIn 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.\n\nExamples\n\nInput\n\n7 3\n3 5 7 1 6 2 8\n1 2 7\n\n\nOutput\n\n7 1 2\n\n\nInput\n\n4 4\n3 4 1 0\n0 1 7 9\n\n\nOutput\n\n1 0\n\nNote\n\nIn 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.\n\nIn 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.","public_tests":{"input":["4 4\n3 4 1 0\n0 1 7 9\n","7 3\n3 5 7 1 6 2 8\n1 2 7\n"],"output":["1 0\n","7 1 2\n"]},"source":2,"difficulty":7,"cf_contest_id":994,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1295_A. Display The Number","description":"You have a large electronic screen which can display up to 998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 7 segments which can be turned on and off to compose different digits. The following picture describes how you can display all 10 decimal digits:\n\n<image>\n\nAs you can see, different digits may require different number of segments to be turned on. For example, if you want to display 1, you have to turn on 2 segments of the screen, and if you want to display 8, all 7 segments of some place to display a digit should be turned on.\n\nYou want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than n segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than n segments.\n\nYour program should be able to process t different test cases.\n\nInput\n\nThe first line contains one integer t (1 \u2264 t \u2264 100) \u2014 the number of test cases in the input.\n\nThen the test cases follow, each of them is represented by a separate line containing one integer n (2 \u2264 n \u2264 10^5) \u2014 the maximum number of segments that can be turned on in the corresponding testcase.\n\nIt is guaranteed that the sum of n over all test cases in the input does not exceed 10^5.\n\nOutput\n\nFor each test case, print the greatest integer that can be displayed by turning on no more than n segments of the screen. Note that the answer may not fit in the standard 32-bit or 64-bit integral data type.\n\nExample\n\nInput\n\n\n2\n3\n4\n\n\nOutput\n\n\n7\n11","public_tests":{"input":["2\n3\n4\n"],"output":["7\n11\n"]},"source":2,"difficulty":7,"cf_contest_id":1295,"cf_index":"A","cf_points":0.0,"cf_rating":900,"cf_tags":["greedy"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1490_C. Sum of Cubes","description":"You are given a positive integer x. Check whether the number x is representable as the sum of the cubes of two positive integers.\n\nFormally, you need to check if there are two integers a and b (1 \u2264 a, b) such that a^3+b^3=x.\n\nFor example, if x = 35, then the numbers a=2 and b=3 are suitable (2^3+3^3=8+27=35). If x=4, then no pair of numbers a and b is suitable.\n\nInput\n\nThe first line contains one integer t (1 \u2264 t \u2264 100) \u2014 the number of test cases. Then t test cases follow.\n\nEach test case contains one integer x (1 \u2264 x \u2264 10^{12}).\n\nPlease note, that the input for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language.\n\nOutput\n\nFor each test case, output on a separate line: \n\n * \"YES\" if x is representable as the sum of the cubes of two positive integers. \n * \"NO\" otherwise. \n\n\n\nYou can output \"YES\" and \"NO\" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).\n\nExample\n\nInput\n\n\n7\n1\n2\n4\n34\n35\n16\n703657519796\n\n\nOutput\n\n\nNO\nYES\nNO\nNO\nYES\nYES\nYES\n\nNote\n\nThe number 1 is not representable as the sum of two cubes.\n\nThe number 2 is represented as 1^3+1^3.\n\nThe number 4 is not representable as the sum of two cubes.\n\nThe number 34 is not representable as the sum of two cubes.\n\nThe number 35 is represented as 2^3+3^3.\n\nThe number 16 is represented as 2^3+2^3.\n\nThe number 703657519796 is represented as 5779^3+7993^3.","public_tests":{"input":["7\n1\n2\n4\n34\n35\n16\n703657519796\n"],"output":["\nNO\nYES\nNO\nNO\nYES\nYES\nYES\n"]},"source":2,"difficulty":9,"cf_contest_id":1490,"cf_index":"C","cf_points":0.0,"cf_rating":1100,"cf_tags":["binary search","brute force","brute force","math"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"478_A. Initial Bet","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.\n\nYour 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.\n\nInput\n\nThe input consists of a single line containing five integers c1, c2, c3, c4 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 \u2264 c1, c2, c3, c4, c5 \u2264 100).\n\nOutput\n\nPrint 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).\n\nExamples\n\nInput\n\n2 5 4 0 4\n\n\nOutput\n\n3\n\n\nInput\n\n4 5 9 2 1\n\n\nOutput\n\n-1\n\nNote\n\nIn the first sample the following sequence of operations is possible:\n\n 1. One coin is passed from the fourth player to the second player; \n 2. One coin is passed from the fourth player to the fifth player; \n 3. One coin is passed from the first player to the third player; \n 4. One coin is passed from the fourth player to the second player. ","public_tests":{"input":["2 5 4 0 4\n","4 5 9 2 1\n"],"output":["3\n","-1\n"]},"source":2,"difficulty":7,"cf_contest_id":478,"cf_index":"A","cf_points":500.0,"cf_rating":1100,"cf_tags":["implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"629_A. Far Relative\u2019s Birthday Cake","description":"Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!\n\nThe cake is a n \u00d7 n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?\n\nPlease, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.\n\nInput\n\nIn the first line of the input, you are given a single integer n (1 \u2264 n \u2264 100) \u2014 the length of the side of the cake.\n\nThen follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.\n\nOutput\n\nPrint the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.\n\nExamples\n\nInput\n\n3\n.CC\nC..\nC.C\n\n\nOutput\n\n4\n\n\nInput\n\n4\nCC..\nC..C\n.CC.\n.CC.\n\n\nOutput\n\n9\n\nNote\n\nIf we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: \n\n 1. (1, 2) and (1, 3)\n 2. (3, 1) and (3, 3)\n\nPieces that share the same column are: \n 1. (2, 1) and (3, 1)\n 2. (1, 3) and (3, 3)","public_tests":{"input":["4\nCC..\nC..C\n.CC.\n.CC.\n","3\n.CC\nC..\nC.C\n"],"output":["9\n","4\n"]},"source":2,"difficulty":7,"cf_contest_id":629,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["brute force","combinatorics","constructive algorithms","implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"560_A. Currency System in Geraldion","description":"A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?\n\nInput\n\nThe first line contains number n (1 \u2264 n \u2264 1000) \u2014 the number of values of the banknotes that used in Geraldion. \n\nThe second line contains n distinct space-separated numbers a1, a2, ..., an (1 \u2264 ai \u2264 106) \u2014 the values of the banknotes.\n\nOutput\n\nPrint a single line \u2014 the minimum unfortunate sum. If there are no unfortunate sums, print - 1.\n\nExamples\n\nInput\n\n5\n1 2 3 4 5\n\n\nOutput\n\n-1","public_tests":{"input":["5\n1 2 3 4 5\n"],"output":["-1\n"]},"source":2,"difficulty":7,"cf_contest_id":560,"cf_index":"A","cf_points":500.0,"cf_rating":1000,"cf_tags":["implementation","sortings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1466_B. Last minute enhancements","description":"Athenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be met with a warm reception. \n\nHis song consists of n notes, which we will treat as positive integers. The diversity of a song is the number of different notes it contains. As a patron of music, Euterpe watches over composers and guides them throughout the process of creating new melodies. She decided to help Athenaeus by changing his song to make it more diverse.\n\nBeing a minor goddess, she cannot arbitrarily change the song. Instead, for each of the n notes in the song, she can either leave it as it is or increase it by 1.\n\nGiven the song as a sequence of integers describing the notes, find out the maximal, achievable diversity.\n\nInput\n\nThe input consists of multiple test cases. The first line contains an integer t (1 \u2264 t \u2264 10 000) \u2014 the number of test cases. Then t test cases follow, each one is described in two lines.\n\nIn the first line of each test case there is a single integer n (1 \u2264 n \u2264 10^5) denoting the length of the song. The next line contains a sequence of n integers x_1, x_2, \u2026, x_n (1 \u2264 x_1 \u2264 x_2 \u2264 \u2026 \u2264 x_n \u2264 2 \u22c5 n), describing the song.\n\nThe sum of n over all test cases does not exceed 10^5.\n\nOutput\n\nFor each test case, you should output a single line containing precisely one integer, the maximal diversity of the song, i.e. the maximal possible number of different elements in the final sequence.\n\nExample\n\nInput\n\n\n5\n6\n1 2 2 2 5 6\n2\n4 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 2\n\n\nOutput\n\n\n5\n2\n6\n1\n3\n\nNote\n\nIn the first test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence 1, \\underline{3}, 2, 2, \\underline{6}, \\underline{7}, which has 5 different elements (increased elements are underlined).\n\nIn the second test case, Euterpe can increase the first element to obtain the sequence \\underline{5}, 4, which has 2 different elements.\n\nIn the third test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence 1, \\underline{2}, 3, 4, \\underline{5}, \\underline{6}, which has 6 different elements.","public_tests":{"input":["5\n6\n1 2 2 2 5 6\n2\n4 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 2\n"],"output":["\n5\n2\n6\n1\n3\n"]},"source":2,"difficulty":8,"cf_contest_id":1466,"cf_index":"B","cf_points":750.0,"cf_rating":800,"cf_tags":["dp","greedy"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"992_A. Nastya and an Array","description":"Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:\n\n * In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. \n * When all elements of the array become equal to zero, the array explodes. \n\n\n\nNastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.\n\nInput\n\nThe first line contains a single integer n (1 \u2264 n \u2264 105) \u2014 the size of the array.\n\nThe second line contains n integers a1, a2, ..., an ( - 105 \u2264 ai \u2264 105) \u2014 the elements of the array.\n\nOutput\n\nPrint a single integer \u2014 the minimum number of seconds needed to make all elements of the array equal to zero.\n\nExamples\n\nInput\n\n5\n1 1 1 1 1\n\n\nOutput\n\n1\n\n\nInput\n\n3\n2 0 -1\n\n\nOutput\n\n2\n\n\nInput\n\n4\n5 -6 -5 1\n\n\nOutput\n\n4\n\nNote\n\nIn the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.\n\nIn the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.","public_tests":{"input":["4\n5 -6 -5 1\n","5\n1 1 1 1 1\n","3\n2 0 -1\n"],"output":["4\n","1\n","2\n"]},"source":2,"difficulty":7,"cf_contest_id":992,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["implementation","sortings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1173_A. Nauuo and Votes","description":"Nauuo is a girl who loves writing comments.\n\nOne day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.\n\nIt'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.\n\nThere 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\".\n\nBecause 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.\n\nTell Nauuo the result or report that the result is uncertain.\n\nInput\n\nThe only line contains three integers x, y, z (0\u2264 x,y,z\u2264100), corresponding to the number of persons who would upvote, downvote or unknown.\n\nOutput\n\nIf there is only one possible result, print the result : \"+\", \"-\" or \"0\".\n\nOtherwise, print \"?\" to report that the result is uncertain.\n\nExamples\n\nInput\n\n\n3 7 0\n\n\nOutput\n\n\n-\n\nInput\n\n\n2 0 1\n\n\nOutput\n\n\n+\n\nInput\n\n\n1 1 0\n\n\nOutput\n\n\n0\n\nInput\n\n\n0 0 1\n\n\nOutput\n\n\n?\n\nNote\n\nIn the first example, Nauuo would definitely get three upvotes and seven downvotes, so the only possible result is \"-\".\n\nIn the second example, no matter the person unknown downvotes or upvotes, Nauuo would get more upvotes than downvotes. So the only possible result is \"+\".\n\nIn the third example, Nauuo would definitely get one upvote and one downvote, so the only possible result is \"0\".\n\nIn 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.","public_tests":{"input":["3 7 0\n","1 1 0\n","0 0 1\n","2 0 1\n"],"output":["-","0","?","+"]},"source":2,"difficulty":7,"cf_contest_id":1173,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["greedy"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"405_A. Gravity Flip","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.\n\nThere 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.\n\n<image>\n\nGiven 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!\n\nInput\n\nThe first line of input contains an integer n (1 \u2264 n \u2264 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 \u2264 ai \u2264 100) denotes the number of cubes in the i-th column.\n\nOutput\n\nOutput 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.\n\nExamples\n\nInput\n\n4\n3 2 1 2\n\n\nOutput\n\n1 2 2 3 \n\n\nInput\n\n3\n2 3 8\n\n\nOutput\n\n2 3 8 \n\nNote\n\nThe 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.\n\nIn the second example case the gravity switch does not change the heights of the columns.","public_tests":{"input":["3\n2 3 8\n","4\n3 2 1 2\n"],"output":["2 3 8 ","1 2 2 3 "]},"source":2,"difficulty":7,"cf_contest_id":405,"cf_index":"A","cf_points":500.0,"cf_rating":900,"cf_tags":["greedy","implementation","sortings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1526_A. Mean Inequality","description":"You are given an array a of 2n distinct integers. You want to arrange the elements of the array in a circle such that no element is equal to the the arithmetic mean of its 2 neighbours.\n\nMore formally, find an array b, such that: \n\n * b is a permutation of a.\n\n * For every i from 1 to 2n, b_i \u2260 \\frac{b_{i-1}+b_{i+1}}{2}, where b_0 = b_{2n} and b_{2n+1} = b_1.\n\n\n\n\nIt can be proved that under the constraints of this problem, such array b always exists.\n\nInput\n\nThe first line of input contains a single integer t (1 \u2264 t \u2264 1000) \u2014 the number of testcases. The description of testcases follows.\n\nThe first line of each testcase contains a single integer n (1 \u2264 n \u2264 25).\n\nThe second line of each testcase contains 2n integers a_1, a_2, \u2026, a_{2n} (1 \u2264 a_i \u2264 10^9) \u2014 elements of the array.\n\nNote that there is no limit to the sum of n over all testcases.\n\nOutput\n\nFor each testcase, you should output 2n integers, b_1, b_2, \u2026 b_{2n}, for which the conditions from the statement are satisfied.\n\nExample\n\nInput\n\n\n3\n3\n1 2 3 4 5 6\n2\n123 456 789 10\n1\n6 9\n\n\nOutput\n\n\n3 1 4 2 5 6\n123 10 456 789\n9 6\n\nNote\n\nIn the first testcase, array [3, 1, 4, 2, 5, 6] works, as it's a permutation of [1, 2, 3, 4, 5, 6], and (3+4)\/(2)\u2260 1, (1+2)\/(2)\u2260 4, (4+5)\/(2)\u2260 2, (2+6)\/(2)\u2260 5, (5+3)\/(2)\u2260 6, (6+1)\/(2)\u2260 3.","public_tests":{"input":["3\n3\n1 2 3 4 5 6\n2\n123 456 789 10\n1\n6 9\n"],"output":["\n3 1 4 2 5 6\n123 10 456 789\n9 6\n"]},"source":2,"difficulty":7,"cf_contest_id":1526,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["constructive algorithms","sortings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"676_A. Nicholas and Permutation","description":"Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.\n\nNicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.\n\nInput\n\nThe first line of the input contains a single integer n (2 \u2264 n \u2264 100) \u2014 the size of the permutation.\n\nThe second line of the input contains n distinct integers a1, a2, ..., an (1 \u2264 ai \u2264 n), where ai is equal to the element at the i-th position.\n\nOutput\n\nPrint a single integer \u2014 the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.\n\nExamples\n\nInput\n\n5\n4 5 1 3 2\n\n\nOutput\n\n3\n\n\nInput\n\n7\n1 6 5 3 4 7 2\n\n\nOutput\n\n6\n\n\nInput\n\n6\n6 5 4 3 2 1\n\n\nOutput\n\n5\n\nNote\n\nIn the first sample, one may obtain the optimal answer by swapping elements 1 and 2.\n\nIn the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.\n\nIn the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.","public_tests":{"input":["6\n6 5 4 3 2 1\n","7\n1 6 5 3 4 7 2\n","5\n4 5 1 3 2\n"],"output":["5\n","6\n","3\n"]},"source":2,"difficulty":7,"cf_contest_id":676,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["constructive algorithms","implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1030_B. Vasya and Cornfield","description":"Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0, d), (d, 0), (n, n - d) and (n - d, n).\n\n<image> An example of a cornfield with n = 7 and d = 2.\n\nVasya also knows that there are m grasshoppers near the field (maybe even inside it). The i-th grasshopper is at the point (x_i, y_i). Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.\n\nHelp Vasya! For each grasshopper determine if it is inside the field (including the border).\n\nInput\n\nThe first line contains two integers n and d (1 \u2264 d < n \u2264 100).\n\nThe second line contains a single integer m (1 \u2264 m \u2264 100) \u2014 the number of grasshoppers.\n\nThe i-th of the next m lines contains two integers x_i and y_i (0 \u2264 x_i, y_i \u2264 n) \u2014 position of the i-th grasshopper.\n\nOutput\n\nPrint m lines. The i-th line should contain \"YES\" if the position of the i-th grasshopper lies inside or on the border of the cornfield. Otherwise the i-th line should contain \"NO\".\n\nYou can print each letter in any case (upper or lower).\n\nExamples\n\nInput\n\n7 2\n4\n2 4\n4 1\n6 3\n4 5\n\n\nOutput\n\nYES\nNO\nNO\nYES\n\n\nInput\n\n8 7\n4\n4 4\n2 8\n8 1\n6 1\n\n\nOutput\n\nYES\nNO\nYES\nYES\n\nNote\n\nThe cornfield from the first example is pictured above. Grasshoppers with indices 1 (coordinates (2, 4)) and 4 (coordinates (4, 5)) are inside the cornfield.\n\nThe cornfield from the second example is pictured below. Grasshoppers with indices 1 (coordinates (4, 4)), 3 (coordinates (8, 1)) and 4 (coordinates (6, 1)) are inside the cornfield. \n\n<image>","public_tests":{"input":["7 2\n4\n2 4\n4 1\n6 3\n4 5\n","8 7\n4\n4 4\n2 8\n8 1\n6 1\n"],"output":["YES\nNO\nNO\nYES\n","YES\nNO\nYES\nYES\n"]},"source":2,"difficulty":8,"cf_contest_id":1030,"cf_index":"B","cf_points":500.0,"cf_rating":1100,"cf_tags":["geometry"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"765_B. Code obfuscation","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.\n\nTo 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.\n\nYou 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.\n\nInput\n\nIn the only line of input there is a string S of lowercase English letters (1 \u2264 |S| \u2264 500) \u2014 the identifiers of a program with removed whitespace characters.\n\nOutput\n\nIf this program can be a result of Kostya's obfuscation, print \"YES\" (without quotes), otherwise print \"NO\".\n\nExamples\n\nInput\n\nabacaba\n\n\nOutput\n\nYES\n\n\nInput\n\njinotega\n\n\nOutput\n\nNO\n\nNote\n\nIn 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:\n\n * replace all occurences of number with a, the result would be \"a string a character a string a\",\n * replace all occurences of string with b, the result would be \"a b a character a b a\",\n * replace all occurences of character with c, the result would be \"a b a c a b a\",\n * all identifiers have been replaced, thus the obfuscation is finished.","public_tests":{"input":["jinotega\n","abacaba\n"],"output":["NO\n","YES\n"]},"source":2,"difficulty":8,"cf_contest_id":765,"cf_index":"B","cf_points":1000.0,"cf_rating":1100,"cf_tags":["greedy","implementation","strings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":512000000,"input_file":"","output_file":""}
{"name":"43_A. Football","description":"One day Vasya decided to have a look at the results of Berland 1910 Football Championship\u2019s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.\n\nInput\n\nThe first line contains an integer n (1 \u2264 n \u2264 100) \u2014 the number of lines in the description. Then follow n lines \u2014 for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.\n\nOutput\n\nPrint the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.\n\nExamples\n\nInput\n\n1\nABC\n\n\nOutput\n\nABC\n\n\nInput\n\n5\nA\nABA\nABA\nA\nA\n\n\nOutput\n\nA","public_tests":{"input":["1\nABC\n","5\nA\nABA\nABA\nA\nA\n"],"output":["ABC\n","A\n"]},"source":2,"difficulty":7,"cf_contest_id":43,"cf_index":"A","cf_points":500.0,"cf_rating":1000,"cf_tags":["strings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"989_A. A Blend of Springtime","description":"When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside \u2014 not tangerines, but blossoms instead.\n\n\"What a pity it's already late spring,\" sighs Mino with regret, \"one more drizzling night and they'd be gone.\"\n\n\"But these blends are at their best, aren't they?\" Absorbed in the landscape, Kanno remains optimistic. \n\nThe 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.\n\nWhen 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.\n\nYou 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.\n\nInput\n\nThe 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 \u2264 100) \u2014 denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.\n\nOutput\n\nOutput \"Yes\" if it's possible that all three colours appear in some cell, and \"No\" otherwise.\n\nYou can print each letter in any case (upper or lower).\n\nExamples\n\nInput\n\n.BAC.\n\n\nOutput\n\nYes\n\n\nInput\n\nAA..CB\n\n\nOutput\n\nNo\n\nNote\n\nIn the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.\n\nIn the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.","public_tests":{"input":["AA..CB\n",".BAC.\n"],"output":["NO","YES"]},"source":2,"difficulty":7,"cf_contest_id":989,"cf_index":"A","cf_points":500.0,"cf_rating":900,"cf_tags":["implementation","strings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1095_B. Array Stabilization","description":"You are given an array a consisting of n integer numbers.\n\nLet instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i.\n\nYou have to remove exactly one element from this array to minimize instability of the resulting (n-1)-elements array. Your task is to calculate the minimum possible instability.\n\nInput\n\nThe first line of the input contains one integer n (2 \u2264 n \u2264 10^5) \u2014 the number of elements in the array a.\n\nThe second line of the input contains n integers a_1, a_2, ..., a_n (1 \u2264 a_i \u2264 10^5) \u2014 elements of the array a.\n\nOutput\n\nPrint one integer \u2014 the minimum possible instability of the array if you have to remove exactly one element from the array a.\n\nExamples\n\nInput\n\n\n4\n1 3 3 7\n\n\nOutput\n\n\n2\n\n\nInput\n\n\n2\n1 100000\n\n\nOutput\n\n\n0\n\nNote\n\nIn the first example you can remove 7 then instability of the remaining array will be 3 - 1 = 2.\n\nIn the second example you can remove either 1 or 100000 then instability of the remaining array will be 100000 - 100000 = 0 and 1 - 1 = 0 correspondingly.","public_tests":{"input":["4\n1 3 3 7\n","2\n1 100000\n"],"output":["2\n","0\n"]},"source":2,"difficulty":8,"cf_contest_id":1095,"cf_index":"B","cf_points":0.0,"cf_rating":900,"cf_tags":["implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"959_A. Mahmoud and Ehab and the even-odd game","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:\n\n * 1 \u2264 a \u2264 n. \n * If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has to be odd. \n\n\n\nIf the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?\n\nInput\n\nThe only line contains an integer n (1 \u2264 n \u2264 109), the number at the beginning of the game.\n\nOutput\n\nOutput \"Mahmoud\" (without quotes) if Mahmoud wins and \"Ehab\" (without quotes) otherwise.\n\nExamples\n\nInput\n\n1\n\n\nOutput\n\nEhab\n\nInput\n\n2\n\n\nOutput\n\nMahmoud\n\nNote\n\nIn 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.\n\nIn the second sample, Mahmoud has to choose a = 2 and subtract it from n. It's Ehab's turn and n = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.","public_tests":{"input":["1\n","2\n"],"output":["Ehab","Mahmoud"]},"source":2,"difficulty":7,"cf_contest_id":959,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["games","math"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1399_A. Remove Smallest","description":"You are given the array a consisting of n positive (greater than zero) integers.\n\nIn one move, you can choose two indices i and j (i \u2260 j) such that the absolute difference between a_i and a_j is no more than one (|a_i - a_j| \u2264 1) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).\n\nYour task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.\n\nYou have to answer t independent test cases.\n\nInput\n\nThe first line of the input contains one integer t (1 \u2264 t \u2264 1000) \u2014 the number of test cases. Then t test cases follow.\n\nThe first line of the test case contains one integer n (1 \u2264 n \u2264 50) \u2014 the length of a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 \u2264 a_i \u2264 100), where a_i is the i-th element of a.\n\nOutput\n\nFor each test case, print the answer: \"YES\" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or \"NO\" otherwise.\n\nExample\n\nInput\n\n\n5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n\n\nOutput\n\n\nYES\nYES\nNO\nNO\nYES\n\nNote\n\nIn the first test case of the example, we can perform the following sequence of moves:\n\n * choose i=1 and j=3 and remove a_i (so a becomes [2; 2]); \n * choose i=1 and j=2 and remove a_j (so a becomes [2]). \n\n\n\nIn the second test case of the example, we can choose any possible i and j any move and it doesn't matter which element we remove.\n\nIn the third test case of the example, there is no way to get rid of 2 and 4.","public_tests":{"input":["5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n"],"output":["YES\nYES\nNO\nNO\nYES\n"]},"source":2,"difficulty":7,"cf_contest_id":1399,"cf_index":"A","cf_points":0.0,"cf_rating":800,"cf_tags":["greedy","sortings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"467_A. George and Accommodation","description":"George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. \n\nGeorge and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi \u2264 qi). Your task is to count how many rooms has free place for both George and Alex.\n\nInput\n\nThe first line contains a single integer n (1 \u2264 n \u2264 100) \u2014 the number of rooms.\n\nThe i-th of the next n lines contains two integers pi and qi (0 \u2264 pi \u2264 qi \u2264 100) \u2014 the number of people who already live in the i-th room and the room's capacity.\n\nOutput\n\nPrint a single integer \u2014 the number of rooms where George and Alex can move in.\n\nExamples\n\nInput\n\n3\n1 1\n2 2\n3 3\n\n\nOutput\n\n0\n\n\nInput\n\n3\n1 10\n0 10\n10 10\n\n\nOutput\n\n2","public_tests":{"input":["3\n1 1\n2 2\n3 3\n","3\n1 10\n0 10\n10 10\n"],"output":["0\n","2\n"]},"source":2,"difficulty":7,"cf_contest_id":467,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1282_A. Temporarily unavailable","description":"Polycarp lives on the coordinate axis Ox and travels from the point x=a to x=b. It moves uniformly rectilinearly at a speed of one unit of distance per minute.\n\nOn the axis Ox at the point x=c the base station of the mobile operator is placed. It is known that the radius of its coverage is r. Thus, if Polycarp is at a distance less than or equal to r from the point x=c, then he is in the network coverage area, otherwise \u2014 no. The base station can be located both on the route of Polycarp and outside it.\n\nPrint the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from x=a to x=b. His speed \u2014 one unit of distance per minute.\n\nInput\n\nThe first line contains a positive integer t (1 \u2264 t \u2264 1000) \u2014 the number of test cases. In the following lines are written t test cases.\n\nThe description of each test case is one line, which contains four integers a, b, c and r (-10^8 \u2264 a,b,c \u2264 10^8, 0 \u2264 r \u2264 10^8) \u2014 the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.\n\nAny of the numbers a, b and c can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.\n\nOutput\n\nPrint t numbers \u2014 answers to given test cases in the order they are written in the test. Each answer is an integer \u2014 the number of minutes during which Polycarp will be unavailable during his movement.\n\nExample\n\nInput\n\n\n9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n\n\nOutput\n\n\n7\n0\n4\n0\n30\n5\n4\n0\n3\n\nNote\n\nThe following picture illustrates the first test case. \n\n<image> Polycarp goes from 1 to 10. The yellow area shows the coverage area of the station with a radius of coverage of 1, which is located at the point of 7. The green area shows a part of the path when Polycarp is out of coverage area.","public_tests":{"input":["9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n"],"output":["7\n0\n4\n0\n30\n5\n4\n0\n3\n"]},"source":2,"difficulty":7,"cf_contest_id":1282,"cf_index":"A","cf_points":500.0,"cf_rating":900,"cf_tags":["implementation","math"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"1480_B. The Great Hero","description":"The great hero guards the country where Homer lives. The hero has attack power A and initial health value B. There are n monsters in front of the hero. The i-th monster has attack power a_i and initial health value b_i. \n\nThe hero or a monster is said to be living, if his or its health value is positive (greater than or equal to 1); and he or it is said to be dead, if his or its health value is non-positive (less than or equal to 0).\n\nIn order to protect people in the country, the hero will fight with monsters until either the hero is dead or all the monsters are dead.\n\n * In each fight, the hero can select an arbitrary living monster and fight with it. Suppose the i-th monster is selected, and the health values of the hero and the i-th monster are x and y before the fight, respectively. After the fight, the health values of the hero and the i-th monster become x-a_i and y-A, respectively. \n\n\n\nNote that the hero can fight the same monster more than once.\n\nFor the safety of the people in the country, please tell them whether the great hero can kill all the monsters (even if the great hero himself is dead after killing the last monster).\n\nInput\n\nEach test contains multiple test cases. The first line contains t (1 \u2264 t \u2264 10^5) \u2014 the number of test cases. Description of the test cases follows.\n\nThe first line of each test case contains three integers A (1 \u2264 A \u2264 10^6), B (1 \u2264 B \u2264 10^6) and n (1 \u2264 n \u2264 10^5) \u2014 the attack power of the great hero, the initial health value of the great hero, and the number of monsters.\n\nThe second line of each test case contains n integers a_1, a_2, ..., a_n (1 \u2264 a_i \u2264 10^6), where a_i denotes the attack power of the i-th monster.\n\nThe third line of each test case contains n integers b_1, b_2, ..., b_n (1 \u2264 b_i \u2264 10^6), where b_i denotes the initial health value of the i-th monster.\n\nIt is guaranteed that the sum of n over all test cases does not exceed 10^5.\n\nOutput\n\nFor each test case print the answer: \"YES\" (without quotes) if the great hero can kill all the monsters. Otherwise, print \"NO\" (without quotes).\n\nExample\n\nInput\n\n\n5\n3 17 1\n2\n16\n10 999 3\n10 20 30\n100 50 30\n1000 1000 4\n200 300 400 500\n1000 1000 1000 1000\n999 999 1\n1000\n1000\n999 999 1\n1000000\n999\n\n\nOutput\n\n\nYES\nYES\nYES\nNO\nYES\n\nNote\n\nIn the first example: There will be 6 fights between the hero and the only monster. After that, the monster is dead and the health value of the hero becomes 17 - 6 \u00d7 2 = 5 > 0. So the answer is \"YES\", and moreover, the hero is still living.\n\nIn the second example: After all monsters are dead, the health value of the hero will become 709, regardless of the order of all fights. So the answer is \"YES\".\n\nIn the third example: A possible order is to fight with the 1-st, 2-nd, 3-rd and 4-th monsters. After all fights, the health value of the hero becomes -400. Unfortunately, the hero is dead, but all monsters are also dead. So the answer is \"YES\".\n\nIn the fourth example: The hero becomes dead but the monster is still living with health value 1000 - 999 = 1. So the answer is \"NO\".","public_tests":{"input":["5\n3 17 1\n2\n16\n10 999 3\n10 20 30\n100 50 30\n1000 1000 4\n200 300 400 500\n1000 1000 1000 1000\n999 999 1\n1000\n1000\n999 999 1\n1000000\n999\n"],"output":["\nYES\nYES\nYES\nNO\nYES\n"]},"source":2,"difficulty":8,"cf_contest_id":1480,"cf_index":"B","cf_points":1000.0,"cf_rating":900,"cf_tags":["greedy","implementation","sortings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":512000000,"input_file":"","output_file":""}
{"name":"1191_A. Tokitsukaze and Enhancement","description":"Tokitsukaze is one of the characters in the game \"Kantai Collection\". In this game, every character has a common attribute \u2014 health points, shortened to HP.\n\nIn general, different values of HP are grouped into 4 categories:\n\n * Category A if HP is in the form of (4 n + 1), that is, when divided by 4, the remainder is 1; \n * Category B if HP is in the form of (4 n + 3), that is, when divided by 4, the remainder is 3; \n * Category C if HP is in the form of (4 n + 2), that is, when divided by 4, the remainder is 2; \n * Category D if HP is in the form of 4 n, that is, when divided by 4, the remainder is 0. \n\n\n\nThe above-mentioned n can be any integer.\n\nThese 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.\n\nWhile 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?\n\nInput\n\nThe only line contains a single integer x (30 \u2264 x \u2264 100) \u2014 the value Tokitsukaze's HP currently.\n\nOutput\n\nPrint an integer a (0 \u2264 a \u2264 2) and an uppercase letter b (b \u2208 { A, B, C, D }), representing that the best way is to increase her HP by a, and then the category becomes b.\n\nNote that the output characters are case-sensitive.\n\nExamples\n\nInput\n\n\n33\n\n\nOutput\n\n\n0 A\n\n\nInput\n\n\n98\n\n\nOutput\n\n\n1 B\n\nNote\n\nFor the first example, the category of Tokitsukaze's HP is already A, so you don't need to enhance her ability.\n\nFor the second example:\n\n * If you don't increase her HP, its value is still 98, which equals to (4 \u00d7 24 + 2), and its category is C. \n * If you increase her HP by 1, its value becomes 99, which equals to (4 \u00d7 24 + 3), and its category becomes B. \n * If you increase her HP by 2, its value becomes 100, which equals to (4 \u00d7 25), and its category becomes D. \n\n\n\nTherefore, the best way is to increase her HP by 1 so that the category of her HP becomes B.","public_tests":{"input":["33\n","98\n"],"output":["0 A\n","1 B\n"]},"source":2,"difficulty":7,"cf_contest_id":1191,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["brute force"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"835_A. Key races","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.\n\nIf connection ping (delay) is t milliseconds, the competition passes for a participant as follows: \n\n 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. \n 2. Right after that he starts to type it. \n 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. \n\n\n\nThe 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.\n\nGiven the length of the text and the information about participants, determine the result of the game.\n\nInput\n\nThe first line contains five integers s, v1, v2, t1, t2 (1 \u2264 s, v1, v2, t1, t2 \u2264 1000) \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.\n\nOutput\n\nIf the first participant wins, print \"First\". If the second participant wins, print \"Second\". In case of a draw print \"Friendship\".\n\nExamples\n\nInput\n\n5 1 2 1 2\n\n\nOutput\n\nFirst\n\n\nInput\n\n3 3 1 1 1\n\n\nOutput\n\nSecond\n\n\nInput\n\n4 5 3 1 5\n\n\nOutput\n\nFriendship\n\nNote\n\nIn the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant \u2014 in 14 milliseconds. So, the first wins.\n\nIn the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant \u2014 in 5 milliseconds. So, the second wins.\n\nIn the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant \u2014 in 22 milliseconds. So, it is be a draw.","public_tests":{"input":["4 5 3 1 5\n","5 1 2 1 2\n","3 3 1 1 1\n"],"output":["Friendship\n","First\n","Second\n"]},"source":2,"difficulty":7,"cf_contest_id":835,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["math"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"263_B. Squares","description":"Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.\n\nVasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary. \n\nHelp Vasya find a point that would meet the described limits.\n\nInput\n\nThe first line contains two space-separated integers n, k (1 \u2264 n, k \u2264 50). The second line contains space-separated integers a1, a2, ..., an (1 \u2264 ai \u2264 109).\n\nIt is guaranteed that all given squares are distinct.\n\nOutput\n\nIn a single line print two space-separated integers x and y (0 \u2264 x, y \u2264 109) \u2014 the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them. \n\nIf there is no answer, print \"-1\" (without the quotes).\n\nExamples\n\nInput\n\n4 3\n5 1 3 4\n\n\nOutput\n\n2 1\n\n\nInput\n\n3 1\n2 4 1\n\n\nOutput\n\n4 0\n\n\nInput\n\n4 50\n5 1 10 2\n\n\nOutput\n\n-1","public_tests":{"input":["3 1\n2 4 1\n","4 3\n5 1 3 4\n","4 50\n5 1 10 2\n"],"output":["4 4\n","3 3\n","-1\n"]},"source":2,"difficulty":8,"cf_contest_id":263,"cf_index":"B","cf_points":500.0,"cf_rating":900,"cf_tags":["greedy","implementation","sortings"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"611_A. New Year and Days","description":"Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.\n\nLimak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.\n\nLimak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.\n\nLimak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.\n\nInput\n\nThe only line of the input is in one of the following two formats: \n\n * \"x of week\" where x (1 \u2264 x \u2264 7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. \n * \"x of month\" where x (1 \u2264 x \u2264 31) denotes the day of the month. \n\nOutput\n\nPrint one integer \u2014 the number of candies Limak will save in the year 2016.\n\nExamples\n\nInput\n\n4 of week\n\n\nOutput\n\n52\n\n\nInput\n\n30 of month\n\n\nOutput\n\n11\n\nNote\n\nPolar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to \u2013 <https:\/\/en.wikipedia.org\/wiki\/Gregorian_calendar>. The week starts with Monday.\n\nIn the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.\n\nIn the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 \u2014 all months but February. It means that Limak will save 11 candies in total.","public_tests":{"input":["4 of week\n","30 of month\n"],"output":["52","11"]},"source":2,"difficulty":7,"cf_contest_id":611,"cf_index":"A","cf_points":500.0,"cf_rating":900,"cf_tags":["implementation"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":2,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}
{"name":"378_A. Playing with Dice","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.\n\nThe 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?\n\nInput\n\nThe single line contains two integers a and b (1 \u2264 a, b \u2264 6) \u2014 the numbers written on the paper by the first and second player, correspondingly.\n\nOutput\n\nPrint 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.\n\nExamples\n\nInput\n\n2 5\n\n\nOutput\n\n3 0 3\n\n\nInput\n\n2 4\n\n\nOutput\n\n2 1 3\n\nNote\n\nThe 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.\n\nYou can assume that number a is closer to number x than number b, if |a - x| < |b - x|.","public_tests":{"input":["2 5\n","2 4\n"],"output":["3 0 3\n","2 1 3\n"]},"source":2,"difficulty":7,"cf_contest_id":378,"cf_index":"A","cf_points":500.0,"cf_rating":800,"cf_tags":["brute force"],"is_description_translated":false,"untranslated_description":"","time_limit":{"seconds":1,"nanos":0},"memory_limit_bytes":256000000,"input_file":"","output_file":""}