source int64 2 2 | difficulty int64 7 25 | name stringlengths 9 60 | description stringlengths 164 7.12k | public_tests dict | private_tests dict | cf_rating int64 0 3.5k | cf_points float64 0 4k |
|---|---|---|---|---|---|---|---|
2 | 11 | 614_E. Necklace | Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward).
... | {
"input": [
"1\n4\n",
"3\n4 2 1\n",
"2\n1 1\n"
],
"output": [
"4\naaaa\n",
"1\naabcbaa\n",
"0\nab\n"
]
} | {
"input": [
"2\n50000 50000\n",
"18\n369 2583 4551 615 369 369 2091 3813 1845 369 615 861 1599 984 3567 2337 123 1599\n",
"26\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"3\n4 2 1\n",
"4\n1100 220 66 11\n",
"3\n3 3 3\n",
"2\n2 2\n",
"1\n100000\n",
"3\n6 6 9\n",
"3... | 2,500 | 1,250 |
2 | 8 | 634_B. XOR Equation | Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
Input
The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive integers, respectively.
Output
Print a s... | {
"input": [
"5 2\n",
"3 3\n",
"9 5\n"
],
"output": [
"0",
"2",
"4"
]
} | {
"input": [
"322414792152 285840263184\n",
"751720572344 569387893618\n",
"3 7\n",
"169616 132704\n",
"274861129991 274861129463\n",
"18436 18436\n",
"6 2\n",
"1322568 271816\n",
"1530587 566563\n",
"419432708 419432708\n",
"228503520839 471917524248\n",
"915425594051 ... | 1,700 | 500 |
2 | 9 | 687_C. The Values You Can Make | Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.
Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Ar... | {
"input": [
"3 50\n25 25 50\n",
"6 18\n5 6 1 10 12 2\n"
],
"output": [
"3\n0 25 50 ",
"16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 "
]
} | {
"input": [
"10 1\n1 1 1 1 1 1 1 1 1 1\n",
"10 58\n57 2 18 35 3 35 38 7 38 3\n",
"10 10\n7 4 6 2 9 6 8 8 10 10\n",
"8 42\n7 24 22 25 31 12 17 26\n",
"10 67\n58 39 56 7 51 47 20 26 24 54\n",
"10 86\n64 5 30 53 65 24 32 36 23 23\n",
"5 34\n28 32 91 6 70\n",
"15 388\n33 232 106 369 266 1... | 1,900 | 1,500 |
2 | 8 | 70_B. Text Messaging | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not like ... | {
"input": [
"25\nHello. I am a little walrus.\n",
"2\nHow are you?\n",
"19\nHello! Do you like fish? Why?\n"
],
"output": [
"2\n",
"Impossible\n",
"3\n"
]
} | {
"input": [
"16\nAbacaba. Abacaba. abacaba. abacab.\n",
"123\nOjg CVJm qfE RnHislFds nNKKt TCPLWukqNGAsVBplYbTfq? VeYKjfFGTzXWA ydpVZLIImNub yApKnAHv iXQmqv GjQvxrnAgtfTApiQyCKtg. GdmapGwvI udRqxTbnzgnOUNZx slAuEuLGCJycZJvtCczQ vommS xuuT eIK! DOJeFEaubbz HYLGlIIlNKfyaJQKVN eFNnUvKKCQLXvGhwX gjmRscMkedELUlHq... | 1,600 | 1,000 |
2 | 15 | 730_I. Olympiad in Programming and Sports | There are n students at Berland State University. Every student has two skills, each measured as a number: ai — the programming skill and bi — the sports skill.
It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to take part in... | {
"input": [
"5 2 2\n1 3 4 5 2\n5 3 2 1 4\n",
"5 3 1\n5 2 5 1 7\n6 3 1 6 3\n",
"4 2 2\n10 8 8 3\n10 7 9 4\n"
],
"output": [
"18\n3 4 \n1 5 \n",
"23\n1 3 5 \n4 \n",
"31\n1 2 \n3 4 \n"
]
} | {
"input": [
"14 2 8\n20 14 17 18 12 12 19 3 2 20 13 12 17 20\n20 10 3 15 8 15 12 12 14 2 1 15 7 10\n",
"6 1 4\n7 9 3 5 9 2\n10 9 10 10 10 1\n",
"5 2 3\n10 4 19 8 18\n6 16 11 15 3\n",
"6 3 3\n15 12 12 19 1 7\n7 2 20 10 4 12\n",
"3 1 1\n10 5 5\n9 1 4\n",
"12 2 4\n16 17 12 8 18 9 2 9 13 18 3 8\n... | 2,000 | 0 |
2 | 10 | 754_D. Fedor and coupons | All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket.
The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with ... | {
"input": [
"3 2\n1 12\n15 20\n25 30\n",
"4 2\n1 100\n40 70\n120 130\n125 180\n",
"5 2\n1 10\n5 15\n14 50\n30 70\n99 100\n"
],
"output": [
"0\n1 2 ",
"31\n1 2 ",
"21\n3 4 "
]
} | {
"input": [
"9 2\n5 10\n-10 -10\n0 10\n-6 3\n-8 7\n6 10\n-8 1\n5 7\n2 2\n",
"54 7\n-98 -39\n14 60\n-23 -5\n58 75\n14 16\n-40 20\n-6 10\n11 60\n-47 54\n-71 -17\n-48 -25\n-87 -46\n-10 99\n-97 -88\n-14 94\n-25 29\n-96 -92\n68 75\n-75 2\n12 84\n-47 3\n-88 49\n-37 88\n-61 -25\n36 67\n30 54\n12 31\n-71 60\n-18 -15... | 2,100 | 2,000 |
2 | 7 | 7_A. Kalevitch and Chess | 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, th... | {
"input": [
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n",
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n"
],
"output": [
"1\n",
"3\n"
]
} | {
"input": [
"BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB\n",
"BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB\n",
"BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB\n",
"BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBB... | 1,100 | 0 |
2 | 9 | 820_C. Mister B and Boring Game | 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... | {
"input": [
"4 2 2 6\n",
"1 1 1 8\n",
"3 7 4 6\n"
],
"output": [
"3",
"2",
"1"
]
} | {
"input": [
"6 1 654321100 654321115\n",
"10 7 987654339 987654340\n",
"7 8 305686738 573739036\n",
"10 1 100 1000000000\n",
"3 12 987654345 987654347\n",
"1 1 1 1000000000\n",
"2 2 987654333 987654335\n",
"3 3 240953737 404170887\n",
"11 4 987654330 987654343\n",
"2 1 1 10000... | 2,200 | 500 |
2 | 10 | 846_D. Monitor | Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k × k consisting entirely of broken pixels. She knows that q pixels are alread... | {
"input": [
"3 3 2 5\n1 2 2\n2 2 1\n2 3 5\n3 2 10\n2 1 100\n",
"2 3 2 5\n2 1 8\n2 2 8\n1 2 1\n1 3 4\n2 3 2\n"
],
"output": [
"-1\n",
"8\n"
]
} | {
"input": [
"500 500 1 0\n",
"29 50 5 29\n21 42 1565821\n21 43 53275635\n21 44 2717830\n21 45 9579585\n21 46 20725775\n22 42 2568372\n22 43 9584662\n22 44 31411635\n22 45 5089311\n22 46 4960702\n23 42 11362237\n23 43 42200296\n23 44 18762146\n23 45 8553819\n23 46 4819516\n24 42 10226552\n24 43 21022685\n24 4... | 1,900 | 0 |
2 | 9 | 893_C. Rumor | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | {
"input": [
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n",
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n"
],
"output": [
"15\n",
"10\n",
"55\n"
]
} | {
"input": [
"2 0\n1000000000 1000000000\n",
"2 0\n1000000000 0\n",
"1 0\n1000000000\n",
"2 0\n0 1000000000\n",
"1 0\n0\n",
"2 1\n0 0\n1 2\n",
"2 0\n0 0\n"
],
"output": [
"2000000000\n",
"1000000000\n",
"1000000000\n",
"1000000000\n",
"0\n",
"0\n",
"0\n"
]... | 1,300 | 0 |
2 | 7 | 938_A. Word Correction | 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 consec... | {
"input": [
"4\nword\n",
"5\naaeaa\n",
"5\nweird\n"
],
"output": [
"word\n",
"a\n",
"werd\n"
]
} | {
"input": [
"4\naepo\n",
"6\naaaaaa\n",
"2\nou\n",
"10\naaaaaaaaaa\n",
"6\nxxxahg\n",
"2\nba\n",
"13\nmmmmmmmmmmmmm\n",
"18\niuiuqpyyaoaetiwliu\n",
"79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"3\nzcv\n",
"7\nmahmoud\n",
"12\... | 800 | 0 |
2 | 7 | 963_A. Alternating Sum | You are given two integers a and b. Moreover, you are given a sequence s_0, s_1, ..., s_{n}. All values in s are integers 1 or -1. It's known that sequence is k-periodic and k divides n+1. In other words, for each k ≤ i ≤ n it's satisfied that s_{i} = s_{i - k}.
Find out the non-negative remainder of division of ∑ _{i... | {
"input": [
"4 1 5 1\n-\n",
"2 2 3 3\n+-+\n"
],
"output": [
"999999228\n",
"7\n"
]
} | {
"input": [
"234179195 430477711 115381398 12\n++++-+-+-+++\n",
"262060935 184120408 148332034 148\n+--+-------+-+-+--++-+++--++-+-++++++--++-+++-+++--+-------+-+--+++-+-+-+---++-++-+-++---+--+-+-+--+------+++--+--+-+-+---+---+-+-++++---+++--+++---\n",
"179358 828426 548710 67\n++++---+--++----+-+-++++--... | 1,800 | 500 |
2 | 10 | 990_D. Graph And Its Complement | Given three numbers n, a, b. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to a, and the number of components in its complement is b. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edges fro... | {
"input": [
"3 1 2\n",
"3 3 3\n"
],
"output": [
"YES\n001\n001\n110\n",
"NO\n"
]
} | {
"input": [
"3 2 1\n",
"123 1 84\n",
"3 1 3\n",
"4 4 1\n",
"4 1 2\n",
"4 4 4\n",
"4 3 2\n",
"5 1 1\n",
"1 1 1\n",
"101 1 1\n",
"4 1 1\n",
"3 3 1\n",
"4 1 4\n",
"4 4 2\n",
"4 2 2\n",
"103 1 1\n",
"5 1 2\n",
"3 2 2\n",
"3 2 3\n",
"2 2 1\n"... | 1,700 | 0 |
2 | 8 | 1005_B. Delete from the Left | You are given two strings s and t. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by 1. You can't choose a string if it is empty.
For example:
* by applying a move to the string "where", the result is the s... | {
"input": [
"b\nab\n",
"codeforces\nyes\n",
"test\nyes\n",
"test\nwest\n"
],
"output": [
"1",
"9",
"7",
"2"
]
} | {
"input": [
"ama\nsama\n",
"z\na\n",
"abacabadabacaba\nabacabadacaba\n",
"ahmedaly\naly\n",
"bbdab\ndab\n",
"aaabc\nbc\n",
"aa\na\n",
"a\nab\n",
"dddc\ncdcde\n",
"codeforces\nces\n",
"a\naa\n",
"aa\nab\n",
"cccba\nba\n",
"lxuyspmieeuyxluv\ndfwxqvavzxctblaa\n",
... | 900 | 0 |
2 | 10 | 1047_D. Little C Loves 3 II | Little C loves number «3» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n × 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 ... | {
"input": [
"3 3\n",
"2 2\n"
],
"output": [
"8\n",
"0\n"
]
} | {
"input": [
"11111111 77777777\n",
"3 7\n",
"4 3\n",
"1 4\n",
"1 10\n",
"2 1\n",
"2 66666666\n",
"23333 66666\n",
"1 8\n",
"7 2\n",
"1000000000 1000000000\n",
"66666666 66668888\n",
"998244353 19260817\n",
"19260817 19260817\n",
"7 1\n",
"2 5\n",
"6... | 2,200 | 1,000 |
2 | 8 | 1093_B. Letters Rearranging | You are given a string s consisting only of lowercase Latin letters.
You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.
Let's call a string good if it is not a palindrome. Palindrome is... | {
"input": [
"3\naa\nabacaba\nxdd\n"
],
"output": [
"-1\naaaabbc\nddx\n"
]
} | {
"input": [
"1\naad\n",
"3\naa\nbb\nccd\n",
"1\nxy\n",
"1\naax\n",
"1\nab\n",
"1\nabb\n",
"3\naa\nabacaba\nxdd\n",
"4\ncz\naabb\na\naba\n",
"1\nabbabab\n",
"1\nasasa\n",
"1\naab\n",
"1\nabc\n",
"1\naabb\n",
"100\naa\nb\ncbc\nc\nbab\nc\nbdb\ndd\nhfh\nebe\nb\nf\n... | 900 | 0 |
2 | 8 | 1113_B. Sasha and Magnetic Machines | One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by n machines, and the power of the i-th machine is a_i.
This year 2D decided to cultivate a new culture, but what exactly he d... | {
"input": [
"5\n2 4 2 3 7\n",
"5\n1 2 3 4 5\n",
"4\n4 2 4 4\n"
],
"output": [
"18",
"14",
"14"
]
} | {
"input": [
"12\n95 98 98 92 94 97 100 83 93 97 87 72\n",
"3\n1 36 38\n",
"166\n61 19 19 67 11 11 73 89 73 11 47 2 59 43 61 31 19 83 71 19 29 97 89 97 2 11 5 73 19 2 19 7 41 53 5 23 11 89 2 23 47 47 83 71 17 71 67 67 43 3 29 97 17 83 11 19 67 17 97 7 19 29 29 41 13 71 29 19 19 43 47 17 71 3 13 71 41 19 4... | 1,300 | 1,000 |
2 | 11 | 1141_E. Superhero Battle | A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again.
Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≤ d_i ≤ 10^6). Th... | {
"input": [
"1000 6\n-100 -200 -300 125 77 -4\n",
"10 4\n-3 -6 5 4\n",
"1000000000000 5\n-1 0 0 0 0\n"
],
"output": [
"9\n",
"-1\n",
"4999999999996\n"
]
} | {
"input": [
"1 1\n-1000000\n",
"1000 13\n0 0 0 -3 -5 0 0 0 0 -1 -1 0 7\n",
"1000000000000 10\n8 10 3 0 -4 3 -7 -6 3 -6\n",
"100000 5\n0 0 0 0 0\n",
"6000 6\n-199 -19009 19009 -199 -199 -199\n",
"1 2\n-1 1\n",
"1000000000000 10\n-6 5 -2 -2 -10 -7 -5 -9 -3 -4\n",
"1 3\n-1 -1 10\n",
... | 1,700 | 0 |
2 | 10 | 1182_D. Complete Mirror | You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then degree(v_{1}) = degree(v_{2}), where degree means the number of vertices connected to that vertex, and distance means... | {
"input": [
"6\n1 3\n2 3\n3 4\n4 5\n4 6\n",
"7\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n"
],
"output": [
"-1\n",
"3\n"
]
} | {
"input": [
"7\n5 7\n3 5\n4 5\n2 7\n1 3\n3 6\n",
"9\n1 4\n4 6\n7 8\n2 5\n1 8\n3 8\n1 9\n1 2\n",
"1\n",
"9\n2 4\n3 7\n5 7\n6 9\n2 5\n2 8\n1 8\n5 9\n",
"14\n10 12\n8 10\n6 8\n4 6\n2 4\n1 2\n2 3\n3 5\n5 7\n7 9\n9 11\n10 14\n9 13\n",
"9\n1 2\n2 3\n3 4\n4 5\n2 6\n4 7\n3 8\n8 9\n",
"8\n3 5\n7 8... | 2,400 | 2,000 |
2 | 11 | 1260_E. Tournament | You are organizing a boxing tournament, where n boxers will participate (n is a power of 2), and your friend is one of them. All boxers have different strength from 1 to n, and boxer i wins in the match against boxer j if and only if i is stronger than j.
The tournament will be organized as follows: n boxers will be d... | {
"input": [
"8\n11 -1 13 19 24 7 17 5\n",
"4\n3 9 1 -1\n"
],
"output": [
"12",
"0"
]
} | {
"input": [
"2\n-1 1000000000\n",
"16\n-1 70 57 84 80 17 45 10 70 10 51 72 100 37 26 89\n",
"16\n-1 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2\n",
"8\n-1 99 99 2 4 3 2 4\n",
"8\n-1 10 10 10 2 2 2 2\n",
"32\n455576261 993874315 239353491 105019778 757559104 -1 146197710 100212939 206681524 960634920... | 2,400 | 0 |
2 | 11 | 1326_E. Bombs | You are given a permutation, p_1, p_2, …, p_n.
Imagine that some positions of the permutation contain bombs, such that there exists at least one position without a bomb.
For some fixed configuration of bombs, consider the following process. Initially, there is an empty set, A.
For each i from 1 to n:
* Add p_i to... | {
"input": [
"6\n2 3 6 1 5 4\n5 2 1 4 6 3\n",
"3\n3 2 1\n1 2 3\n"
],
"output": [
"6 5 5 5 4 1 \n",
"3 2 1 \n"
]
} | {
"input": [
"2\n1 2\n2 1\n",
"2\n2 1\n1 2\n",
"2\n1 2\n1 2\n",
"10\n7 10 1 8 3 9 2 4 6 5\n7 6 5 3 8 10 4 1 9 2\n",
"2\n2 1\n2 1\n"
],
"output": [
"2 1 \n",
"2 1 \n",
"2 2 \n",
"10 9 8 7 6 6 5 5 5 1 \n",
"2 1 \n"
]
} | 2,400 | 2,500 |
2 | 11 | 1345_E. Quantifier Question | Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universal (∀) and existential (∃). You can read more about them here.
The universa... | {
"input": [
"3 2\n1 3\n2 3\n",
"4 3\n1 2\n2 3\n3 1\n",
"2 1\n1 2\n"
],
"output": [
"2\nAAE\n",
"-1\n",
"1\nAE\n"
]
} | {
"input": [
"51 50\n4 34\n50 28\n46 41\n37 38\n29 9\n4 29\n38 42\n16 3\n34 21\n27 39\n34 29\n22 50\n14 47\n23 35\n11 4\n26 5\n50 27\n29 33\n18 14\n42 24\n18 29\n28 36\n17 48\n47 51\n51 37\n47 48\n35 9\n23 28\n41 36\n34 6\n8 17\n7 30\n27 23\n41 51\n19 6\n21 46\n11 22\n21 46\n16 15\n1 4\n51 29\n3 36\n15 40\n17 42\... | 2,600 | 1,500 |
2 | 10 | 1367_D. Task On The Board | Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.
After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some ad... | {
"input": [
"4\nabac\n3\n2 1 0\nabc\n1\n0\nabba\n3\n1 0 1\necoosdcefr\n10\n38 13 24 14 11 5 3 24 17 0\n"
],
"output": [
"aac\nc\naba\ncodeforces\n"
]
} | {
"input": [
"2\naccccccc\n1\n0\naaaaac\n3\n0 0 0\n",
"1\naba\n2\n0 0\n",
"1\naaabbc\n4\n3 2 1 0\n",
"3\nybb\n2\n0 0\nzbb\n2\n0 0\nzyybb\n2\n0 0\n",
"1\nabbc\n3\n0 2 0\n",
"1\naaab\n3\n0 0 0\n",
"1\naaabb\n3\n0 0 0\n",
"1\naaabbc\n5\n0 0 3 5 7\n",
"1\nzbb\n2\n0 0\n",
"1\nxbbbbc... | 1,800 | 0 |
2 | 10 | 1388_D. Captain Flint and Treasure | Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and offered an absurdly high reward: one day off. The problem itself sounds like t... | {
"input": [
"3\n1 2 3\n2 3 -1\n",
"10\n-10 -1 2 2 5 -2 -3 -4 2 -6\n-1 -1 2 2 -1 5 5 7 7 9\n",
"2\n-1 100\n2 -1\n"
],
"output": [
"10\n1 2 3 \n",
"-9\n3 4 2 9 5 7 10 8 6 1\n",
"99\n2 1\n"
]
} | {
"input": [
"10\n-10 -1 2 2 5 -2 -3 -4 2 -6\n-1 -1 2 2 -1 5 5 7 7 9\n"
],
"output": [
"-9\n3 4 2 9 5 7 10 8 6 1\n"
]
} | 2,000 | 2,000 |
2 | 8 | 1409_B. Minimum Product | You are given four integers a, b, x and y. Initially, a ≥ x and b ≥ y. You can do the following operation no more than n times:
* Choose either a or b and decrease it by one. However, as a result of this operation, value of a cannot become less than x, and value of b cannot become less than y.
Your task is to fi... | {
"input": [
"7\n10 10 8 5 3\n12 8 8 7 2\n12343 43 4543 39 123212\n1000000000 1000000000 1 1 1\n1000000000 1000000000 1 1 1000000000\n10 11 2 1 5\n10 11 9 1 10\n"
],
"output": [
"70\n77\n177177\n999999999000000000\n999999999\n55\n10\n"
]
} | {
"input": [
"11\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n",
"3\n5 6 3 4 4\n10 10 2 2 4\n10 10 2 2 4\n",
"1\n10 10 8 5 3\n"
],
"output": [
"70\n70\n70\n70\n70\n70\n70\n70\n70\n70\n70\n",
"12\... | 1,100 | 0 |
2 | 11 | 142_E. Help Greg the Dwarf 2 | Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. T... | {
"input": [
"2 2\n1.0 0.0 0.0\n1.0 0.0 1.0\n",
"2 2\n1.0 0.0 0.0\n0.0 1.0 1.0\n",
"2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0\n",
"2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0\n"
],
"output": [
"2.4142135624\n",
"3.2544701977\n",
"2.0000000000\n",
"2.53432426266160\n"
]
} | {
"input": [
"2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0\n",
"939 172\n760.602725383313210 550.640076764737840 0.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000\n",
"816 723\n-409.404815276986650 251.893602766220970 297.094693677376310\n-102.999857434057130 -809.473303678733940 0.00000000000000... | 3,000 | 2,500 |
2 | 8 | 1453_B. Suffix Operations | Gildong has an interesting machine that has an array a with n integers. The machine supports two kinds of operations:
1. Increase all elements of a suffix of the array by 1.
2. Decrease all elements of a suffix of the array by 1.
A suffix is a subsegment (contiguous elements) of the array that contains a_n. I... | {
"input": [
"7\n2\n1 1\n3\n-1 0 2\n4\n99 96 97 95\n4\n-3 -5 -2 1\n6\n1 4 3 2 4 1\n5\n5 0 0 0 5\n9\n-367741579 319422997 -415264583 -125558838 -300860379 420848004 294512916 -383235489 425814447\n"
],
"output": [
"\n0\n1\n3\n4\n6\n5\n2847372102\n"
]
} | {
"input": [
"1\n2\n9 -10\n"
],
"output": [
"0\n"
]
} | 1,400 | 1,000 |
2 | 10 | 1503_D. Flip the Cards | There is a deck of n cards. The i-th card has a number a_i on the front and a number b_i on the back. Every integer between 1 and 2n appears exactly once on the cards.
A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if a_i< a_{i+1} and b_i> b_{i... | {
"input": [
"2\n1 2\n3 4\n",
"3\n1 2\n3 6\n4 5\n",
"5\n3 10\n6 4\n1 9\n5 8\n2 7\n"
],
"output": [
"\n-1\n",
"\n-1\n",
"\n2\n"
]
} | {
"input": [
"3\n3 5\n4 1\n2 6\n",
"3\n1 6\n5 4\n2 3\n",
"20\n7 29\n4 34\n40 2\n39 10\n33 5\n1 37\n20 23\n14 21\n22 9\n8 28\n19 24\n26 13\n32 6\n30 16\n11 38\n36 3\n35 12\n15 31\n17 27\n18 25\n",
"1\n1 2\n",
"4\n5 4\n6 2\n7 1\n8 3\n",
"5\n8 5\n10 3\n4 7\n6 9\n1 2\n",
"10\n20 1\n15 6\n8 13\... | 2,600 | 1,750 |
2 | 7 | 159_A. Friends or Not | Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ... | {
"input": [
"1 1000\na b 0\n",
"4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4\n"
],
"output": [
"0\n",
"1\npetya vasya\n"
]
} | {
"input": [
"3 1\na b 1\nb c 2\nc d 3\n",
"3 1\na b 1\na b 2\nb a 2\n",
"10 2\nfxn ipntr 0\nipntr fxn 1\nfxn ipntr 1\npfvpfteadph ipntr 2\nfxn pfvpfteadph 4\nipntr fxn 4\npfvpfteadph fxn 5\nfxn pfvpfteadph 5\npfvpfteadph ipntr 6\nipntr pfvpfteadph 6\n",
"10 2\nyltec xnzdtcgzxqqltvpfr 0\nfxxhcmbzzg xn... | 1,400 | 500 |
2 | 10 | 178_D2. Magic Squares | The Smart Beaver from ABBYY loves puzzles. One of his favorite puzzles is the magic square. He has recently had an idea to automate the solution of this puzzle. The Beaver decided to offer this challenge to the ABBYY Cup contestants.
The magic square is a matrix of size n × n. The elements of this matrix are integers.... | {
"input": [
"2\n5 5 5 5\n",
"3\n1 0 -1 0 2 -1 -2 0 1\n",
"3\n1 2 3 4 5 6 7 8 9\n"
],
"output": [
"10\n5 5 \n5 5 \n",
"0\n-1 0 1\n2 0 -2\n-1 0 1\n",
"15\n2 7 6\n9 5 1\n4 3 8\n"
]
} | {
"input": [
"3\n2 4 6 8 10 12 14 16 18\n",
"4\n1936924 6264932 1936924 -4555088 -8883096 -19703116 -8883096 1936924 12756944 -8883096 -8883096 -8883096 6264932 1936924 6264932 -8883096\n",
"3\n399 -1025 -129 -497 927 -577 479 31 -49\n",
"4\n3284309 -2011475 3284309 -23194611 -12603043 -7307259 -20114... | 1,900 | 30 |
2 | 10 | 200_D. Programming Language | Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, de... | {
"input": [
"6\nvoid f(string,double,int)\nvoid f(int)\n void f ( T )\nvoid procedure(int,double)\nvoid f (T, double,int) \nvoid f(string, T,T)\n4\n int a\n int x\nstring t\ndouble val \n5\nf(t, a, a)\nf(t,val,a)\nf(val,a, val)\n solve300(val, val)\nf (x)\n",
"4\nvoid f(int,T)\nvoid f(T, T)\n voi... | {
"input": [
"3\nvoid la3yoe ( int,T, T, T, T ) \nvoid la3yoe (string,string,string, int )\nvoid la3yoe ( int, int,T )\n1\n string ef7w \n2\nla3yoe ( ef7w, ef7w, ef7w, ef7w ) \nla3yoe (ef7w) \n",
"1\n void xyi9mzfgil (T )\n1\n string 1h9ro7z1lo \n1\n xyi9mzfgil (1h9ro7z1lo )\n",... | 1,800 | 1,500 |
2 | 9 | 225_C. Barcode | You've got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
* All pixels in each column are of the same color.
* The width of each monochrome ver... | {
"input": [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
],
"output": [
"11",
"5"
]
} | {
"input": [
"5 10 4 16\n.#####....\n##..#..##.\n.#..##.#..\n##..#####.\n...#.##..#\n",
"1 1 1 2\n.\n",
"6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#\n",
"69 1 1 2\n#\n.\n#\n#\n.\n#\n#\n.\n.\n#\n.\n.\n#\n.\n#\n#\n.\n#\n#\n#\n#\n#\n.\n#\n.\n.\n#\n#\n#\n.\n.\n.\n.\n#\n#\n.\n#\n#\n.\n#\n.\n.\n#\n.\n.\n.\n#\n.\n... | 1,700 | 1,500 |
2 | 7 | 24_A. Ring road | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot... | {
"input": [
"3\n1 3 1\n1 2 1\n3 2 1\n",
"3\n1 3 1\n1 2 5\n3 2 1\n",
"6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n",
"4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n"
],
"output": [
"1\n",
"2\n",
"39\n",
"0\n"
]
} | {
"input": [
"5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54\n",
"10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n",
"22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 93\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 ... | 1,400 | 0 |
2 | 8 | 274_B. Zero Tree | A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.
You're given a tr... | {
"input": [
"3\n1 2\n1 3\n1 -1 1\n"
],
"output": [
"3\n"
]
} | {
"input": [
"5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3\n",
"12\n1 6\n10 1\n4 1\n7 1\n1 2\n5 1\n1 8\n1 11\n3 1\n12 1\n9 1\n580660007 861441526 -264928594 488291045 253254575 -974301934 709266786 926718320 87511873 514836444 -702876508 848928657\n",
"5\n3 1\n2 4\n3 4\n2 5\n0 -3 -1 2 4\n",
"10\n5 6\n8 2\n9 3\n4 ... | 1,800 | 1,000 |
2 | 8 | 320_B. Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | {
"input": [
"5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n"
],
"output": [
"NO\nYES\n"
]
} | {
"input": [
"9\n1 1 4\n1 5 20\n1 11 30\n1 29 60\n1 59 100\n1 100 200\n2 1 5\n2 1 6\n2 2 5\n",
"10\n1 -1365 -865\n1 1244 1834\n2 1 2\n1 -1508 -752\n2 3 2\n2 2 1\n1 -779 595\n1 -1316 877\n2 2 1\n1 -698 1700\n",
"20\n1 1208 1583\n1 -258 729\n1 -409 1201\n1 194 1938\n1 -958 1575\n1 -1466 1752\n2 1 2\n2 1 2\n... | 1,500 | 1,000 |
2 | 10 | 368_D. Sereja ans Anagrams | Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions q (q + (m - 1)·p ≤ n; q ≥ 1), such that sequence b can be obtained... | {
"input": [
"5 3 1\n1 2 3 2 1\n1 2 3\n",
"6 3 2\n1 3 2 2 3 1\n1 2 3\n"
],
"output": [
"2\n1 3 ",
"2\n1 2 "
]
} | {
"input": [
"70 7 3\n4 2 5 5 2 3 1 1 2 5 3 1 5 1 1 4 2 4 3 4 4 5 2 3 2 3 5 3 5 5 1 2 2 4 5 1 3 1 2 2 1 5 4 2 4 1 5 1 1 4 5 2 3 4 4 2 4 2 1 3 5 5 1 3 3 2 1 5 5 5\n4 1 1 3 2 3 4\n",
"5 10 1\n1 1 1 1 2\n1 1 1 1 1 1 1 1 1 2\n",
"3 5 1\n1 1 1\n1 2 3 4 5\n",
"59 2 3\n2 4 5 3 2 4 4 5 5 5 4 3 4 2 5 4 5 4 5 2... | 1,900 | 1,000 |
2 | 10 | 412_D. Giving Awards | The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.
Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ... | {
"input": [
"2 1\n1 2\n",
"3 3\n1 2\n2 3\n3 1\n"
],
"output": [
"2 1 ",
"3 2 1 "
]
} | {
"input": [
"10 45\n10 5\n10 7\n6 1\n5 8\n3 5\n6 5\n1 2\n6 10\n2 9\n9 5\n4 1\n7 5\n1 8\n6 8\n10 9\n7 2\n7 9\n4 10\n7 3\n4 8\n10 3\n10 8\n2 10\n8 2\n4 2\n5 2\n9 1\n4 5\n1 3\n9 6\n3 8\n5 1\n6 4\n4 7\n8 7\n7 1\n9 3\n3 4\n6 2\n3 2\n6 7\n6 3\n4 9\n8 9\n1 10\n",
"5 10\n4 2\n4 5\n3 1\n2 1\n3 4\n3 2\n5 1\n5 2\n4 1\n... | 2,000 | 2,000 |
2 | 7 | 43_A. Football | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s 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. Eve... | {
"input": [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
],
"output": [
"ABC\n",
"A\n"
]
} | {
"input": [
"100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\... | 1,000 | 500 |
2 | 9 | 461_C. Appleman and a Sheet of Paper | Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types:
1. Fold the sheet of paper at position pi. After this query the leftmost... | {
"input": [
"10 9\n2 2 9\n1 1\n2 0 1\n1 8\n2 0 8\n1 2\n2 1 3\n1 4\n2 2 4\n",
"7 4\n1 3\n1 2\n2 0 1\n2 1 2\n"
],
"output": [
"7\n2\n10\n4\n5\n",
"4\n3\n"
]
} | {
"input": [
"10 5\n2 1 9\n2 4 10\n1 1\n2 0 1\n2 0 1\n",
"100000 1\n2 19110 78673\n",
"10 10\n2 5 9\n2 2 9\n2 1 7\n2 3 9\n2 3 4\n2 0 6\n2 3 9\n2 2 8\n2 5 9\n1 9\n",
"2 3\n2 0 2\n2 0 1\n1 1\n",
"1 1\n2 0 1\n",
"100000 1\n1 99307\n"
],
"output": [
"8\n6\n2\n2\n",
"59563\n",
"4\n7... | 2,200 | 1,500 |
2 | 8 | 485_B. Valuable Resources | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | {
"input": [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
],
"output": [
"4\n",
"9\n"
]
} | {
"input": [
"2\n-10 0\n-9 0\n",
"3\n2 2\n1 1\n3 3\n",
"10\n-200157522 -824574736\n299208799 -287211553\n-160170880 148363130\n103709327 245344406\n482860382 547328085\n895537733 -545816336\n671947380 910981768\n-43209851 585461399\n-573679087 427675821\n151452830 27262384\n",
"2\n999999999 999999999\... | 1,300 | 500 |
2 | 8 | 509_B. Painting Pebbles | There are n piles of pebbles on the table, the i-th pile contains ai pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most one.
... | {
"input": [
"5 4\n3 2 4 3 5\n",
"5 2\n3 2 4 1 3\n",
"4 4\n1 2 3 4\n"
],
"output": [
"YES\n1 2 3\n1 2\n1 2 3 4\n1 2 3\n1 2 3 4 1\n",
"NO\n",
"YES\n1\n1 2\n1 2 3\n1 2 3 4\n"
]
} | {
"input": [
"1 100\n1\n",
"100 35\n99 90 67 85 68 67 76 75 77 78 81 85 98 88 70 77 89 87 68 91 83 74 70 65 74 86 82 79 81 93 80 66 93 72 100 99 96 66 89 71 93 80 74 97 73 80 93 81 70 68 80 72 75 70 78 67 73 79 76 75 77 78 85 96 72 84 100 68 77 71 79 91 75 100 67 94 73 79 88 73 92 71 68 66 81 68 81 73 69 75 7... | 1,300 | 0 |
2 | 9 | 558_C. Amr and Chemistry | Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.
Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his t... | {
"input": [
"3\n4 8 2\n",
"3\n3 5 6\n"
],
"output": [
"2\n",
"5\n"
]
} | {
"input": [
"2\n99999 99998\n",
"7\n7 4096 8192 16384 32768 65536 100000\n",
"17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536\n",
"9\n7 4096 8192 16384 32768 65536 100000 100000 100000\n",
"1\n100000\n",
"17\n100000 99999 49999 24999 12499 6249 3124 1562 781 390 195 97 ... | 1,900 | 1,500 |
2 | 7 | 584_A. Olesya and Rodion | Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.
Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print - 1.
Input
T... | {
"input": [
"3 2\n"
],
"output": [
"100\n"
]
} | {
"input": [
"2 8\n",
"98 4\n",
"6 10\n",
"97 5\n",
"5 3\n",
"100 10\n",
"1 6\n",
"8 10\n",
"4 3\n",
"54 5\n",
"2 2\n",
"99 7\n",
"9 4\n",
"1 2\n",
"3 2\n",
"20 10\n",
"72 4\n",
"18 10\n",
"3 4\n",
"4 10\n",
"1 10\n",
"89 5\n",
... | 1,000 | 500 |
2 | 7 | 606_A. Magic Spheres | 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... | {
"input": [
"3 3 3\n2 2 2\n",
"5 6 1\n2 7 2\n",
"4 4 0\n2 1 2\n"
],
"output": [
"Yes\n",
"No\n",
"Yes\n"
]
} | {
"input": [
"135522 188282 377041\n245719 212473 108265\n",
"1000000 500000 500000\n0 1000000 500000\n",
"1 1 0\n0 0 1\n",
"3 2 3\n2 3 2\n",
"5 5 5\n2 2 2\n",
"3 1 0\n1 1 1\n",
"286845 704749 266526\n392296 104421 461239\n",
"275980 429361 101824\n274288 302579 166062\n",
"4 6 0\n... | 1,200 | 500 |
2 | 7 | 628_A. Tennis Tournament | 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 ... | {
"input": [
"5 2 3\n",
"8 2 4\n"
],
"output": [
"20 15\n",
"35 32\n"
]
} | {
"input": [
"59 1 1\n",
"1 2 133\n",
"1 2 4\n",
"63 1 1\n",
"2 100 90\n",
"1 10 10\n",
"10 1 500\n",
"1 2 100\n",
"500 500 500\n",
"1 10 15\n",
"67 1 1\n",
"1 3 5\n",
"1 100 90\n",
"7 12 13\n",
"1 500 499\n",
"1 3 4\n",
"349 2 5\n",
"73 73 73\n"... | 1,000 | 0 |
2 | 8 | 652_B. z-sort | A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold:
1. ai ≥ ai - 1 for all even i,
2. ai ≤ ai - 1 for all odd i > 1.
For example the arrays [1,2,1,2] and [1,1,1,1] are z-sorted while the array [1,2,3,4] isn’t z-sorted.
Can you make the... | {
"input": [
"5\n1 3 2 2 5\n",
"4\n1 2 2 1\n"
],
"output": [
"1 5 2 3 2 ",
"1 2 1 2 "
]
} | {
"input": [
"3\n100 1 2\n",
"1\n1\n",
"3\n1 2 3\n",
"136\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | 1,000 | 0 |
2 | 11 | 6_E. Exposition | There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | {
"input": [
"3 3\n14 12 10\n",
"4 5\n8 19 10 13\n",
"2 0\n10 10\n"
],
"output": [
"2 2\n1 2\n2 3\n",
"2 1\n3 4\n",
"2 1\n1 2\n"
]
} | {
"input": [
"2 10\n35 45\n",
"3 0\n1000000 1000000 1000000\n",
"4 1000\n11497 9999 10730 12280\n",
"7 14\n28 28 29 35 25 29 28\n",
"5 1\n9 6 8 7 5\n",
"4 1000000\n100001 1 200001 300001\n",
"4 0\n1 1 1 1\n",
"4 8\n89 33 54 75\n",
"10 163\n7541 2535 5883 5775 2821 5962 4489 5548 28... | 1,900 | 0 |
2 | 8 | 722_B. Verse Pattern | You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels:... | {
"input": [
"3\n2 2 3\nintel\ncode\nch allenge\n",
"4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n",
"4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n"
],
"output... | {
"input": [
"5\n2 2 1 1 1\nfdbie\naaj\ni\ni n\nshi\n",
"5\n2 11 10 7 9\nhy of\nyur pjyacbatdoylojayu\nemd ibweioiimyxya\nyocpyivudobua\nuiraueect impxqhzpty e\n",
"2\n26 35\ngouojxaoobw iu bkaadyo degnjkubeabt kbap thwki dyebailrhnoh ooa\npiaeaebaocptyswuc wezesazipu osebhaonouygasjrciyiqaejtqsioubiuakg ... | 1,200 | 500 |
2 | 11 | 743_E. Vladik and cards | Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
* the number of occ... | {
"input": [
"3\n1 1 1\n",
"24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\n",
"8\n8 7 6 5 4 3 2 1\n"
],
"output": [
"1",
"17\n",
"8\n"
]
} | {
"input": [
"7\n8 8 2 6 1 8 5\n",
"18\n4 3 3 3 7 7 5 2 1 1 3 3 6 1 2 4 1 8\n",
"120\n6 7 8 5 2 8 5 4 6 4 3 2 5 6 5 7 5 7 1 7 4 6 4 1 4 1 1 7 6 7 3 7 4 7 4 6 4 7 6 6 6 5 5 7 3 5 3 7 2 2 4 2 5 6 8 4 1 2 2 8 3 3 2 5 6 4 3 6 2 4 1 4 2 8 8 3 7 6 4 7 2 7 3 3 8 8 6 8 7 7 6 8 3 2 5 2 6 5 7 5 7 5 3 2 6 2 6 5 7 8 ... | 2,200 | 2,500 |
2 | 8 | 767_B. The Queue | Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He know... | {
"input": [
"10 15 2\n2\n10 13\n",
"8 17 3\n4\n3 4 5 8\n"
],
"output": [
"12\n",
"2\n"
]
} | {
"input": [
"30 70 10\n3\n30 32 35\n",
"100000000000 200000000000 10000000000\n10\n1 1 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000\n",
"61 1000000000 13\n55\n29 72 85 94 103 123 125 144 147 153 154 184 189 192 212 234 247 265 292 296 299 304 309... | 2,100 | 1,250 |
2 | 7 | 791_A. Bear and Big Brother | 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... | {
"input": [
"4 9\n",
"1 1\n",
"4 7\n"
],
"output": [
"3\n",
"1\n",
"2\n"
]
} | {
"input": [
"1 9\n",
"3 3\n",
"6 7\n",
"5 6\n",
"2 5\n",
"2 7\n",
"5 8\n",
"6 9\n",
"1 7\n",
"5 5\n",
"3 10\n",
"1 3\n",
"7 7\n",
"3 7\n",
"4 4\n",
"4 5\n",
"3 5\n",
"6 8\n",
"2 4\n",
"1 2\n",
"7 10\n",
"8 8\n",
"6 6\n",
... | 800 | 500 |
2 | 9 | 811_C. Vladik and Memorable Trip | Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code ai is know... | {
"input": [
"9\n5 1 3 1 5 2 4 2 5\n",
"6\n4 4 2 5 2 3\n"
],
"output": [
"9\n",
"14\n"
]
} | {
"input": [
"100\n915 7 282 162 24 550 851 240 39 302 538 76 131 150 104 848 507 842 32 453 998 990 1002 225 887 1005 259 199 873 87 258 318 837 511 663 1008 861 516 445 426 335 743 672 345 320 461 650 649 612 9 1017 113 169 722 643 253 562 661 879 522 524 878 600 894 312 1005 283 911 322 509 836 261 424 976 68 ... | 1,900 | 1,500 |
2 | 11 | 837_E. Vasya's Function | Vasya is studying number theory. He has denoted a function f(a, b) such that:
* f(a, 0) = 0;
* f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b.
Vasya has two numbers x and y, and he wants to calculate f(x, y). He tried to do it by himself, but found out that calcul... | {
"input": [
"3 5\n",
"6 3\n"
],
"output": [
"3\n",
"1\n"
]
} | {
"input": [
"1 100000000000\n",
"100000000000 100000000000\n",
"191480607107 629918602611\n",
"3 135415909531\n",
"1000000000000 1\n",
"999999999989 999999999988\n",
"1000000009 1000000000000\n",
"767389814 1136900240\n",
"1000000009 1000000010\n",
"450002679907 2\n",
"963... | 2,100 | 0 |
2 | 7 | 858_A. k-rounding | 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·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program... | {
"input": [
"10000 1\n",
"375 4\n",
"38101 0\n",
"123456789 8\n"
],
"output": [
"10000\n",
"30000\n",
"38101\n",
"12345678900000000\n"
]
} | {
"input": [
"9 1\n",
"100000000 8\n",
"2 0\n",
"123456789 1\n",
"8 1\n",
"3711871 8\n",
"125 3\n",
"78125 8\n",
"1953125 8\n",
"3 1\n",
"16 4\n",
"999999997 7\n",
"8 8\n",
"1000000000 7\n",
"55555 8\n",
"8 3\n",
"10000000 8\n",
"7 1\n",
"12 ... | 1,100 | 750 |
2 | 13 | 883_G. Orientation of Edges | Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
1. to orient each undirected edge in one of two possible directions to maximize... | {
"input": [
"2 2 1\n1 1 2\n2 2 1\n",
"6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3\n"
],
"output": [
"2\n-\n2\n+\n",
"6\n++-\n2\n+-+\n"
]
} | {
"input": [
"5 5 5\n2 5 3\n1 2 3\n1 4 5\n2 5 2\n1 2 1\n",
"5 10 3\n2 5 1\n2 1 3\n2 3 5\n2 1 4\n2 5 4\n2 2 5\n2 3 2\n2 2 1\n2 4 3\n2 4 2\n",
"5 5 1\n2 5 3\n2 2 5\n1 2 1\n2 4 2\n1 1 5\n",
"14 19 14\n2 5 7\n1 4 1\n2 9 8\n1 7 3\n2 14 2\n2 2 8\n2 6 7\n2 14 7\n1 7 8\n2 10 8\n2 11 10\n1 11 7\n2 3 13\n1 5 4\... | 1,900 | 0 |
2 | 8 | 907_B. Tic-Tac-Toe | 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.
<image>
Players are making moves by turns. At first move a player can put his chip in any cell of any sm... | {
"input": [
"xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4\n",
"... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4\n",
"o.. ... ...\n... ... ...\n... ..... | {
"input": [
"xxo xoo xxo\nooo ooo xxx\noox oxo oxx\n\noxo oxo xxx\nxoo oxx oxo\nxxx oxx ooo\n\noxx xoo xxo\nxxx oox xox\nxxo o.o oxo\n9 6\n",
"ox. o.x .o.\nxxo xoo .oo\n.xx oox o..\n\nxx. oox oxx\noox oxx xxo\nxo. oxo x.x\n\no.x .x. xx.\n.xo ox. ooo\n.ox xo. ..o\n6 2\n",
"... .o. ...\n... ... ...\n... ..... | 1,400 | 1,000 |
2 | 15 | 926_I. A Vital Problem | Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute.
Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in... | {
"input": [
"4\n22:00\n03:21\n16:03\n09:59\n",
"1\n05:43\n"
],
"output": [
"06:37\n",
"23:59\n"
]
} | {
"input": [
"9\n01:38\n15:16\n18:50\n00:45\n17:26\n16:30\n09:10\n00:46\n05:49\n",
"2\n06:25\n22:43\n",
"50\n21:58\n09:10\n01:27\n20:25\n12:48\n20:44\n23:13\n08:44\n14:55\n05:58\n09:30\n01:54\n04:15\n14:25\n12:22\n13:37\n06:18\n20:07\n00:40\n19:11\n15:06\n15:49\n01:40\n17:53\n01:04\n19:54\n00:31\n22:25\n0... | 1,700 | 0 |
2 | 7 | 957_A. Tritonic Iridescence | 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 colo... | {
"input": [
"5\n?CYC?\n",
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\nC??MM\n",
"3\nMMY\n"
],
"output": [
"Yes",
"Yes",
"Yes",
"No",
"No"
]
} | {
"input": [
"8\nCMC??MCM\n",
"10\nMCYM?MYM?C\n",
"5\nC???Y\n",
"6\n?CC???\n",
"1\nC\n",
"3\nMC?\n",
"6\nMC??MC\n",
"2\nY?\n",
"100\n????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"4\nCYCM\n",
"50\nCMCMCYM?MY?C?MC??Y... | 1,300 | 500 |
2 | 7 | 982_A. Row | You're given a row with n chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated.
2. 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... | {
"input": [
"3\n101\n",
"5\n10001\n",
"4\n1011\n"
],
"output": [
"Yes\n",
"No\n",
"No\n"
]
} | {
"input": [
"459\n0001110001010100001000010010101111100110110100011001011110101110111011101111011111011001011000110110011001100010011110011010001110010111001101000111110111110000100001100100111001100110111111100111000011010011110001001110110010000010111111001101000010010011001010111000011101101001010110111101001... | 1,200 | 500 |
2 | 9 | 1042_C. Array Product | You are given an array a consisting of n integers. You can perform the following operations with it:
1. Choose some positions i and j (1 ≤ i, j ≤ n, i ≠ j), write the value of a_i ⋅ a_j into the j-th cell and remove the number from the i-th cell;
2. Choose some position i and remove the number from the i-th cell... | {
"input": [
"4\n0 0 0 0\n",
"5\n5 2 0 4 0\n",
"2\n2 -1\n",
"5\n5 -2 0 1 -3\n",
"4\n0 -10 0 0\n"
],
"output": [
"1 1 2\n1 2 3\n1 3 4\n",
"1 3 5\n2 5\n1 1 2\n1 2 4\n",
"2 2\n",
"2 3\n1 1 2\n1 2 4\n1 4 5\n",
"1 1 3\n1 3 4\n1 4 2\n"
]
} | {
"input": [
"3\n0 0 0\n",
"2\n0 -246606331\n",
"2\n162752926 74678428\n",
"3\n901757671 602032179 648227272\n",
"2\n-334123344 -715238512\n",
"3\n0 826310696 475306516\n",
"3\n-556173614 890149857 30628101\n",
"3\n-378090190 0 463698701\n",
"2\n0 957794556\n",
"3\n-547909114 -... | 1,700 | 1,500 |
2 | 8 | 1065_B. Vasya and Isolated Vertices | 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 (... | {
"input": [
"3 1\n",
"4 2\n"
],
"output": [
"1 1\n",
"0 1\n"
]
} | {
"input": [
"10 2\n",
"100 0\n",
"1 0\n",
"18889 138011083\n",
"4 6\n",
"10 45\n",
"6 15\n",
"20 55\n",
"15 4\n",
"100000 4999950000\n",
"2 0\n",
"5 5\n",
"2 1\n",
"100 100\n",
"100000 3950493829\n",
"20 54\n",
"6740 22710430\n",
"20 56\n",
... | 1,300 | 0 |
2 | 12 | 1106_F. Lunar New Year and a Recursive Sequence | Lunar New Year is approaching, and Bob received a gift from his friend recently — a recursive sequence! He loves this sequence very much and wants to play with it.
Let f_1, f_2, …, f_i, … be an infinite sequence of positive integers. Bob knows that for i > k, f_i can be obtained by the following recursive equation:
$... | {
"input": [
"1\n2\n88888 66666\n",
"10\n283 463 213 777 346 201 463 283 102 999\n2333333 6263423\n",
"8\n2 3 5 6 1 7 9 10\n23333 1\n",
"3\n998244352 998244352 998244352\n4 2\n",
"5\n4 7 1 5 6\n7 14187219\n",
"3\n2 3 5\n4 16\n"
],
"output": [
"-1\n",
"382480067\n",
"1\n",
"... | {
"input": [
"1\n1\n2 1\n",
"22\n488943077 290998271 852584973 786860017 964602359 374433568 813129205 475010862 41067202 967591690 240784159 919167142 791355038 494235116 152467900 187619570 933100341 42564459 304249492 605073760 894993417 917201696\n681131419 406058366\n",
"1\n693639663\n552241631 26555... | 2,400 | 3,000 |
2 | 12 | 1133_F2. Spanning Tree with One Fixed Degree | You are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
Your task is to find any spanning tree of this graph such that the degree of the first vertex (vertex with label 1 on it) is equal to D (or sa... | {
"input": [
"4 5 1\n1 2\n1 3\n1 4\n2 3\n3 4\n",
"4 4 3\n1 2\n1 4\n2 3\n3 4\n",
"4 5 3\n1 2\n1 3\n1 4\n2 3\n3 4\n"
],
"output": [
"YES\n1 2\n2 3\n3 4\n",
"NO\n",
"YES\n1 2\n1 3\n1 4\n"
]
} | {
"input": [
"4 5 2\n4 1\n2 4\n1 2\n1 3\n4 3\n",
"10 16 1\n4 3\n4 10\n9 6\n2 5\n10 6\n5 4\n6 7\n3 1\n2 4\n8 6\n1 5\n8 1\n2 8\n1 4\n4 9\n9 5\n",
"4 5 1\n1 2\n1 3\n1 4\n2 3\n3 4\n",
"7 13 6\n6 5\n6 1\n1 3\n3 5\n3 7\n6 7\n4 1\n5 7\n1 2\n1 5\n7 2\n1 7\n4 7\n",
"6 10 3\n1 6\n3 2\n3 4\n1 3\n2 1\n1 4\n5 ... | 1,900 | 0 |
2 | 10 | 1154_D. Walking Robot | There is a robot staying at X=0 on the Ox axis. He has to walk to X=n. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.
The i-th segment of the path (from X=i-1 to X=i) can be exposed to sunlight or not. The array s denotes which segments are ex... | {
"input": [
"5 2 1\n0 1 0 1 0\n",
"6 2 1\n1 0 0 1 0 1\n"
],
"output": [
"5\n",
"3\n"
]
} | {
"input": [
"1 1 1\n0\n",
"100 1 1\n0 0 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1\n",
"3 1 1\n1 1 1\n",
"81 36 6\n1 1 1 1 0 1 0 0 0 1 0 0 1 0 1 0 0... | 1,500 | 0 |
2 | 8 | 1176_B. Merge it! | You are given an array a consisting of n integers a_1, a_2, ... , a_n.
In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array [2, 1, 4] you can obtain the following arrays: [3, 4],... | {
"input": [
"2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2\n"
],
"output": [
"3\n3\n"
]
} | {
"input": [
"1\n5\n3 3 3 3 3\n"
],
"output": [
"5\n"
]
} | 1,100 | 0 |
2 | 7 | 1195_A. Drinks Choosing | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?
There are n students living in a building, and for each of them the favorite drink a_i is known. So you know n integer... | {
"input": [
"5 3\n1\n3\n1\n1\n2\n",
"10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2\n"
],
"output": [
"4\n",
"9\n"
]
} | {
"input": [
"1 1000\n548\n",
"16 6\n1\n1\n1\n2\n2\n2\n3\n3\n3\n4\n4\n4\n5\n5\n6\n6\n",
"8 3\n1\n1\n1\n2\n2\n2\n3\n3\n",
"16 4\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n3\n3\n3\n3\n4\n4\n",
"14 4\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n3\n3\n4\n4\n",
"1 1\n1\n",
"3 1000\n1000\n1000\n1000\n",
"20 4\n1\n1\n... | 1,000 | 500 |
2 | 8 | 1253_B. Silly Mistake | The Central Company has an office with a sophisticated security system. There are 10^6 employees, numbered from 1 to 10^6.
The security system logs entrances and departures. The entrance of the i-th employee is denoted by the integer i, while the departure of the i-th employee is denoted by the integer -i.
The compan... | {
"input": [
"3\n-8 1 1\n",
"8\n1 -1 1 2 -1 -2 3 -3\n",
"6\n1 7 -7 3 -1 -3\n",
"6\n2 5 -5 5 -5 -2\n"
],
"output": [
"-1\n",
"3\n2 4 2 \n",
"1\n6 \n",
"-1\n"
]
} | {
"input": [
"4\n1 -1 -3 5\n",
"4\n1 2 -2 -2\n",
"2\n1000000 -1000000\n",
"4\n1 2 -1 -1\n",
"3\n1 1 -1\n",
"8\n1 -1 2 3 1 -2 -3 -1\n",
"4\n1 -1 -1 1\n",
"4\n1 1 -1 -1\n",
"2\n1 -3\n",
"20\n384933 946658 407136 242739 -242739 -407136 -946658 -384933 384933 -384933 319281 407136 ... | 1,400 | 1,000 |
2 | 8 | 1320_B. Navigation System | 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... | {
"input": [
"7 7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n7\n1 2 3 4 5 6 7\n",
"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\n",
"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\n"
],
"output": [
"0 0\n",
"0 3\n",
"1 2\n"
]
} | {
"input": [
"2 2\n1 2\n2 1\n2\n1 2\n",
"20 50\n20 3\n5 16\n1 3\n10 11\n10 15\n15 9\n20 9\n14 6\n16 5\n13 4\n11 5\n3 20\n13 17\n11 8\n11 6\n12 14\n16 18\n17 13\n18 7\n3 1\n8 10\n17 15\n7 2\n9 13\n5 11\n6 1\n2 16\n8 18\n10 8\n4 13\n9 15\n14 12\n1 6\n9 20\n7 18\n6 14\n7 6\n18 16\n2 7\n3 11\n15 17\n3 12\n14 10\n... | 1,700 | 1,000 |
2 | 7 | 1361_A. Johnny and Contribution | Today Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the readers ... | {
"input": [
"5 3\n1 2\n2 3\n4 5\n2 1 2 2 1\n",
"3 3\n1 2\n2 3\n3 1\n2 1 3\n",
"3 3\n1 2\n2 3\n3 1\n1 1 1\n"
],
"output": [
"2 5 1 3 4 ",
"2 1 3 ",
"-1\n"
]
} | {
"input": [
"4 4\n1 2\n1 3\n2 4\n3 4\n1 2 2 3\n",
"6 5\n1 3\n3 2\n2 4\n2 5\n5 6\n1 3 3 1 2 1\n",
"5 4\n1 2\n5 2\n5 3\n1 5\n1 3 1 1 2\n",
"10 20\n8 9\n2 1\n8 4\n3 4\n4 6\n10 3\n7 8\n2 3\n10 7\n10 9\n3 6\n3 5\n9 1\n10 2\n5 8\n8 3\n8 1\n7 5\n9 2\n6 8\n2 4 3 2 2 4 3 1 3 1\n",
"5 3\n1 3\n2 3\n4 2\n1 2... | 1,700 | 500 |
2 | 8 | 1381_B. Unmerge | Let a and b be two arrays of lengths n and m, respectively, with no elements in common. We can define a new array merge(a,b) of length n+m recursively as follows:
* If one of the arrays is empty, the result is the other array. That is, merge(∅,b)=b and merge(a,∅)=a. In particular, merge(∅,∅)=∅.
* If both arrays a... | {
"input": [
"6\n2\n2 3 1 4\n2\n3 1 2 4\n4\n3 2 6 1 5 7 8 4\n3\n1 2 3 4 5 6\n4\n6 1 3 7 4 5 8 2\n6\n4 3 2 5 1 11 9 12 8 6 10 7\n"
],
"output": [
"YES\nNO\nYES\nYES\nNO\nNO\n"
]
} | {
"input": [
"1\n16\n27 1 28 2 29 3 4 5 6 7 30 8 9 10 11 12 13 31 14 15 16 17 18 19 32 20 21 22 23 24 25 26\n",
"1\n9\n2 1 4 3 7 6 5 10 9 8 13 12 11 18 17 16 15 14\n"
],
"output": [
"YES\n",
"YES\n"
]
} | 1,800 | 1,500 |
2 | 9 | 1401_C. Mere Array | You are given an array a_1, a_2, ..., a_n where all a_i are integers and greater than 0.
In one operation, you can choose two different indices i and j (1 ≤ i, j ≤ n). If gcd(a_i, a_j) is equal to the minimum element of the whole array a, you can swap a_i and a_j. gcd(x, y) denotes the [greatest common divisor (GCD)](... | {
"input": [
"4\n1\n8\n6\n4 3 6 6 2 9\n4\n4 5 6 7\n5\n7 5 2 2 4\n"
],
"output": [
"YES\nYES\nYES\nNO\n"
]
} | {
"input": [
"1\n5\n2 6 2 4 5\n"
],
"output": [
"NO\n"
]
} | 1,300 | 1,500 |
2 | 16 | 1424_J. Lonely Numbers | In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.
More precisely, two different numbers a and b are friends if gcd(a,b), (a)/(gcd(a,b)), (b)/(gcd(a,b)) can form sides of a triangle.
Three numbers a, b and c can form sides of a triangle if a + b > c, b... | {
"input": [
"3\n1 5 10\n"
],
"output": [
"1\n3\n3\n"
]
} | {
"input": [
"6\n12 432 21 199 7 1\n",
"100\n791 303 765 671 210 999 106 489 243 635 807 104 558 628 545 926 35 3 75 196 35 460 523 621 748 45 501 143 240 318 78 908 207 369 436 6 285 200 236 864 731 786 915 672 293 563 141 708 698 646 48 128 603 716 681 329 389 489 683 616 875 510 20 493 141 176 803 106 92 9... | 1,600 | 0 |
2 | 7 | 1446_A. Knapsack | You have a knapsack with the capacity of W. There are also n items, the i-th one has weight w_i.
You want to put some of these items into the knapsack in such a way that their total weight C is at least half of its size, but (obviously) does not exceed it. Formally, C should satisfy: ⌈ W/2⌉ ≤ C ≤ W.
Output the list... | {
"input": [
"3\n1 3\n3\n6 2\n19 8 19 69 9 4\n7 12\n1 1 1 17 1 1 1\n"
],
"output": [
"1\n1 \n-1\n6\n1 2 3 5 6 7 \n"
]
} | {
"input": [
"1\n1 1\n1\n",
"3\n1 3\n3\n6 2\n19 8 19 69 9 4\n7 12\n1 1 1 17 1 1 1\n",
"2\n1 2000000001\n1000000000\n1 1000000000000000000\n1\n",
"1\n1 1\n2\n",
"1\n1 900000000\n494311454\n",
"1\n1 2000000001\n1000000000\n"
],
"output": [
"1\n1 \n",
"1\n1 \n-1\n6\n1 2 3 5 6 7 \n",
... | 1,300 | 500 |
2 | 7 | 1470_A. Strange Birthday Party | Petya organized a strange birthday party. He invited n friends and assigned an integer k_i to the i-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are m unique presents available, the j-th present costs c_j dollars (1 ≤ c_1 ≤ c_2 ≤ … ≤ c_m). It's not allowed to buy a single... | {
"input": [
"2\n5 4\n2 3 4 3 2\n3 5 12 20\n5 5\n5 4 3 2 1\n10 40 90 160 250\n",
"1\n1 1\n1\n1\n"
],
"output": [
"\n30\n190\n",
"\n1\n"
]
} | {
"input": [
"6\n6 6\n2 3 1 5 6 6\n629717071 992393438 995305242 999968259 999970082 999971487\n6 6\n2 3 2 2 4 3\n756869732 979591024 993778447 997092844 999873038 999943064\n6 6\n5 1 4 5 6 4\n733550952 979779220 979918868 983712198 991976436 995169050\n6 6\n4 2 2 3 2 4\n257971677 920812339 981000482 998142568 99... | 1,300 | 500 |
2 | 8 | 1496_B. Max and Mex | You are given a multiset S initially consisting of n distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.
You will perform the following operation k times:
* Add the element ⌈(a+b)/(2)⌉ (rounded up) into S, where a = \operatorname{mex}(S) and b = max(S). If this numbe... | {
"input": [
"5\n4 1\n0 1 3 4\n3 1\n0 1 4\n3 0\n0 1 4\n3 2\n0 1 2\n3 2\n1 2 3\n"
],
"output": [
"\n4\n4\n3\n5\n3\n"
]
} | {
"input": [
"1\n6 2\n0 1 2 3 6 8\n",
"7\n5 1000000000\n4 2 3 0 1\n4 0\n5 2 0 1\n3 0\n100 0 1\n6 1234567\n1 2 3 4 5 0\n3 114514\n8 0 4\n1 1000000\n0\n1 10000000\n1\n",
"1\n5 3\n0 1 3 10 4\n",
"1\n3 1\n1 2 4\n",
"1\n1 0\n0\n"
],
"output": [
"6\n",
"1000000005\n4\n3\n1234573\n4\n1000001\... | 1,100 | 1,000 |
2 | 11 | 1519_E. Off by One | There are n points on an infinite plane. The i-th point has coordinates (x_i, y_i) such that x_i > 0 and y_i > 0. The coordinates are not necessarily integer.
In one move you perform the following operations:
* choose two points a and b (a ≠ b);
* move point a from (x_a, y_a) to either (x_a + 1, y_a) or (x_a, y... | {
"input": [
"7\n4 1 5 1\n1 1 1 1\n3 3 3 3\n1 1 4 1\n6 1 1 1\n5 1 4 1\n6 1 1 1\n",
"4\n2 1 1 1\n1 1 2 1\n2 1 1 2\n1 2 1 2\n",
"4\n182 168 60 96\n78 72 45 72\n69 21 144 63\n148 12 105 6\n"
],
"output": [
"\n3\n1 6\n2 4\n5 7\n",
"\n1\n1 2\n",
"\n1\n2 4\n"
]
} | {
"input": [
"10\n4 4 2 2\n2 1 1 3\n1 1 2 3\n5 1 4 4\n2 5 2 3\n4 5 3 4\n1 3 2 4\n5 2 3 1\n4 1 2 5\n5 1 5 4\n",
"3\n3 1 3 2\n2 3 3 5\n1 5 1 1\n",
"2\n5 3 2 2\n4 1 1 3\n",
"4\n252 819 616 728\n561 27 784 63\n56 182 385 455\n840 333 506 222\n",
"2\n341219848 125292072 784316551 422624149\n96974462 1 ... | 2,700 | 0 |
2 | 7 | 174_A. Problem About Equation | A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the pro... | {
"input": [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
],
"output": [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
]
} | {
"input": [
"100 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"3 5\n2 1 3\n",
"13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52\n",
"3 2\n1 ... | 1,100 | 500 |
2 | 8 | 194_B. Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | {
"input": [
"3\n4 8 100\n"
],
"output": [
"17\n33\n401\n"
]
} | {
"input": [
"8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\n",
"3\n13 17 21\n"
],
"output": [
"4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27\n",
"27\n35\n43\n"
]
} | 1,200 | 1,000 |
2 | 8 | 218_B. Airport | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
* it is up to a passenger to choose a plane to fly on;
* if the chosen plane has x (x > 0) empty seats at the given moment, then the ticket for such a plane costs ... | {
"input": [
"4 3\n2 2 2\n",
"4 3\n2 1 1\n"
],
"output": [
"7 6\n",
"5 5\n"
]
} | {
"input": [
"10 2\n4 7\n",
"10 1\n19\n",
"40 10\n1 2 3 4 5 6 7 10 10 10\n",
"10 1\n100\n",
"1 2\n10 9\n",
"10 2\n7 3\n",
"510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45... | 1,100 | 500 |
2 | 8 | 338_B. Book of Evil | Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to r... | {
"input": [
"6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n"
],
"output": [
"3\n"
]
} | {
"input": [
"10 1 0\n3\n10 1\n9 4\n4 5\n6 4\n2 4\n7 5\n8 3\n5 3\n1 3\n",
"5 2 1\n1 5\n1 2\n2 3\n3 4\n4 5\n",
"5 2 0\n1 2\n1 2\n2 3\n3 4\n4 5\n",
"50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 ... | 2,000 | 2,000 |
2 | 8 | 384_B. Multitasking | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.
Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position ... | {
"input": [
"2 5 0\n1 3 2 5 4\n1 4 3 2 5\n",
"3 2 1\n1 2\n2 3\n3 4\n"
],
"output": [
"10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n",
"1\n2 1\n"
]
} | {
"input": [
"2 1 0\n1\n2\n",
"2 5 1\n331081 525217 574775 753333 840639\n225591 347017 538639 620341 994088\n",
"1 1 1\n1\n",
"2 2 0\n2 1\n3 1\n",
"1 1 0\n1\n",
"2 5 0\n836096 600367 472071 200387 79763\n714679 505282 233544 157810 152591\n",
"1 2 1\n2 1\n",
"2 2 1\n2 1\n3 1\n",
"... | 1,500 | 1,000 |
2 | 7 | 405_A. Gravity Flip | 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... | {
"input": [
"3\n2 3 8\n",
"4\n3 2 1 2\n"
],
"output": [
"2 3 8 ",
"1 2 2 3 "
]
} | {
"input": [
"90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52\n",
"100\n7 4 5 5 10 10 5 8 5 7 4... | 900 | 500 |
2 | 8 | 432_B. Football Kit | Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one aw... | {
"input": [
"2\n1 2\n2 1\n",
"3\n1 2\n2 1\n1 3\n"
],
"output": [
"2 0\n2 0\n",
"3 1\n4 0\n2 2\n"
]
} | {
"input": [
"3\n1 100000\n1 100000\n100000 2\n",
"30\n14 1\n12 5\n16 18\n17 9\n17 5\n13 4\n5 17\n10 8\n13 9\n11 9\n11 5\n15 11\n12 17\n10 7\n20 4\n9 8\n4 18\n10 6\n6 18\n3 16\n14 9\n8 17\n12 14\n18 11\n3 10\n1 15\n4 17\n7 20\n11 18\n18 13\n",
"20\n1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 10000... | 1,200 | 1,000 |
2 | 8 | 477_B. Dreamoon and Sets | Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>.
Given k and n, Dream... | {
"input": [
"2 2\n",
"1 1\n"
],
"output": [
"22\n2 4 6 10\n14 16 18 22\n",
"5\n1 2 3 5\n"
]
} | {
"input": [
"2 2\n",
"19 21\n",
"13 7\n",
"1 100\n",
"7 7\n",
"1 10\n",
"1 1\n",
"113 97\n",
"15 27\n",
"3081 11\n",
"1171 46\n",
"5422 87\n",
"407 39\n",
"6518 18\n",
"1563 15\n",
"4237 87\n",
"3844 46\n",
"770 59\n",
"6155 94\n"
],
"ou... | 1,900 | 2,000 |
2 | 9 | 4_C. Registration system | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | {
"input": [
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n",
"4\nabacaba\nacaba\nabacaba\nacab\n"
],
"output": [
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n",
"OK\nOK\nabacaba1\nOK\n"
]
} | {
"input": [
"10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzz... | 1,300 | 0 |
2 | 8 | 525_B. Pasha and String | Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent ... | {
"input": [
"abcdef\n3\n1 2 3\n",
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n"
],
"output": [
"fbdcea\n",
"aedcbf\n",
"vwxyz\n"
]
} | {
"input": [
"wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3\n",
"xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybedklsaztyyiuurfbrzmwumujy\n100\n14 43 30 13 8 19 33 7 8 14 15 35 5 18 44 1 35 1 18 7 50 47 9 49 28 29 39 37 27 17 19 12 5 24 37 42 37 23 35 31 10 26 5 38 40 34 42 47 2 40 43 ... | 1,400 | 750 |
2 | 9 | 550_C. Divisibility by Eight | 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-... | {
"input": [
"111111\n",
"3454\n",
"10\n"
],
"output": [
"NO\n",
"YES\n344\n",
"YES\n0\n"
]
} | {
"input": [
"3697519\n",
"39\n",
"8353\n",
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222\n",
"5531399953495399131957773999751571911139197159755793777773799119333593915333593153173775755771193715\n",
"1111111111111111111111111111111111111... | 1,500 | 1,000 |
2 | 10 | 577_D. Invariance of Tree | A tree of size n is an undirected connected graph consisting of n vertices without cycles.
Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the condition holds: "vertices u and v are connected by an edge if and only if vert... | {
"input": [
"3\n3 1 2\n",
"4\n4 3 2 1\n"
],
"output": [
"NO\n",
"YES\n1 4\n1 2\n4 3\n"
]
} | {
"input": [
"1\n1\n",
"6\n2 1 6 5 3 4\n",
"11\n7 3 5 2 10 1 9 6 8 4 11\n",
"8\n1 2 6 4 5 7 8 3\n",
"6\n2 1 4 5 6 3\n",
"4\n3 4 1 2\n",
"6\n4 1 2 3 6 5\n",
"2\n2 1\n",
"3\n3 2 1\n",
"4\n2 3 4 1\n",
"2\n1 2\n",
"5\n5 3 2 1 4\n",
"6\n2 3 4 1 6 5\n"
],
"output": [
... | 2,100 | 1,250 |
2 | 8 | 59_B. Fortune Telling | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a... | {
"input": [
"3\n5 6 7\n",
"1\n2\n",
"1\n1\n"
],
"output": [
"13\n",
"0\n",
"1\n"
]
} | {
"input": [
"99\n86 16 38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 49 73 69 93 1 93 23 65 67 45 21 29 5 9 63 31 87 13 97 99 63 57 49 17 49 49 7 37 7 15 53 1 59 53 61 83 91 97 3 71 65 25 13 87 99 15 9 5 87\n",
"6\... | 1,200 | 1,000 |
2 | 11 | 641_E. Little Artem and Time Machine | Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.
Artem wants to create a basic multiset of integers. He wants these structure to support operations of three typ... | {
"input": [
"3\n1 1 1\n2 2 1\n3 3 1\n",
"6\n1 1 5\n3 5 5\n1 2 5\n3 6 5\n2 3 5\n3 7 5\n"
],
"output": [
"0\n",
"1\n2\n1\n"
]
} | {
"input": [
"12\n1 9 1\n1 8 1\n1 7 1\n1 6 1\n1 1 1\n1 2 1\n1 3 1\n1 4 1\n2 5 1\n3 12 1\n3 14 2\n3 15 999999999\n",
"20\n1 1 1\n1 2 2\n1 3 3\n1 4 4\n1 5 5\n2 11 5\n2 12 4\n2 13 3\n2 14 2\n2 15 1\n3 6 1\n3 7 2\n3 8 3\n3 9 4\n3 10 5\n3 16 1\n3 17 2\n3 18 3\n3 19 4\n3 20 5\n",
"10\n1 1 1000000000\n1 4 100000... | 2,000 | 2,000 |
2 | 9 | 66_C. Petya and File System | Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo... | {
"input": [
"C:<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file.txt\nC:<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file<span class=\"tex-span\"... | {
"input": [
"C:\\a\\b\\c\\d\\d.txt\nC:\\a\\b\\c\\e\\f.txt\n",
"C:\\z\\z.txt\nD:\\1\\1.txt\nD:\\1\\2.txt\n",
"C:\\test1\\test2\\test.txt\nC:\\test1\\test2\\test2.txt\n",
"D:\\0000\\1.txt\nE:\\00000\\1.txt\n",
"C:\\folder1\\folder2\\folder3\\file1.txt\nC:\\folder1\\folder2\\folder4\\file1.txt\nD:\\... | 1,800 | 1,500 |
2 | 8 | 736_B. Taxes | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he ne... | {
"input": [
"27\n",
"4\n"
],
"output": [
"3\n",
"2\n"
]
} | {
"input": [
"13\n",
"200000015\n",
"719241201\n",
"3\n",
"55\n",
"344472101\n",
"2\n",
"1999999927\n",
"8\n",
"11\n",
"9\n",
"1000000009\n",
"101\n",
"21\n",
"123\n",
"10003\n",
"49\n",
"25\n",
"10759922\n",
"22\n",
"24\n",
"115\... | 1,600 | 1,750 |
2 | 8 | 760_B. Frodo and pillows | n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if h... | {
"input": [
"3 10 3\n",
"3 6 1\n",
"4 6 2\n"
],
"output": [
"4\n",
"3\n",
"2\n"
]
} | {
"input": [
"100 1000000000 20\n",
"100 999981057 92\n",
"100000 999899822 30885\n",
"40000 40771 22564\n",
"40000 999997662 8976\n",
"1000 1000 994\n",
"1 999999999 1\n",
"100000000 200000000 54345\n",
"30000 30593 5980\n",
"3450234 97656670 3000000\n",
"1000000 914032367... | 1,500 | 1,000 |
2 | 9 | 804_C. Ice cream coloring | Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?"
We have a tree T with n vertices and m types of ice cream numerated from 1 to m. Each vertex i has a set of si types of ice cream. Vertices which have the i-t... | {
"input": [
"3 3\n1 1\n2 2 3\n1 2\n1 2\n2 3\n",
"4 5\n0\n1 1\n1 3\n3 2 4 5\n2 1\n3 2\n4 3\n"
],
"output": [
"2\n1 1 2 ",
"3\n1 1 1 2 3 "
]
} | {
"input": [
"15 57\n7 1 12 25 28 40 43 47\n6 2 27 41 53 56 57\n8 2 4 21 26 27 31 34 45\n9 8 20 22 24 35 37 38 44 50\n4 3 7 48 51\n3 8 14 37\n5 10 13 15 32 47\n5 10 18 23 32 47\n2 36 55\n2 8 37\n5 9 29 49 52 56\n5 8 16 30 37 54\n3 17 19 46\n4 6 11 33 39\n3 5 42 56\n2 1\n3 2\n4 2\n5 4\n6 4\n7 1\n8 7\n9 4\n10 6\n11... | 2,200 | 1,500 |
2 | 8 | 82_B. Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | {
"input": [
"4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2\n",
"4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7\n",
"3\n2 1 2\n2 1 3\n2 2 3\n"
],
"output": [
"1 1 \n1 2 \n2 6 100 \n3 7 8 9 \n",
"2 1 3 \n2 2 4 \n1 5 \n1 7 \n",
"1 1 \n1 2 \n1 3 \n"
]
} | {
"input": [
"3\n2 1 2\n10 1 90 80 70 60 50 40 30 20 10\n10 2 10 20 30 40 50 60 70 80 90\n",
"2\n2 1 2\n",
"2\n10 1 2 3 4 5 6 7 8 9 10\n",
"4\n4 56 44 53 43\n3 109 44 43\n3 109 56 53\n3 43 62 44\n3 62 56 53\n2 109 62\n",
"10\n2 32 157\n2 86 157\n2 86 32\n2 154 157\n2 32 154\n2 86 154\n2 157 38\n2 ... | 1,700 | 1,000 |
2 | 11 | 899_E. Segments Removal | Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operat... | {
"input": [
"8\n4 4 4 2 2 100 100 100\n",
"4\n2 5 5 2\n",
"5\n6 3 4 1 5\n",
"6\n10 10 50 10 50 50\n"
],
"output": [
"3",
"2",
"5",
"4"
]
} | {
"input": [
"100\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 4... | 2,000 | 2,250 |
2 | 7 | 920_A. Water The Garden | It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned ... | {
"input": [
"3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n"
],
"output": [
"3\n1\n4\n"
]
} | {
"input": [
"1\n8 4\n1 2 3 7\n",
"1\n13 2\n8 13\n",
"1\n200 2\n50 150\n",
"31\n5 1\n5\n5 1\n4\n5 2\n4 5\n5 1\n3\n5 2\n3 5\n5 2\n3 4\n5 3\n3 4 5\n5 1\n2\n5 2\n2 5\n5 2\n2 4\n5 3\n2 4 5\n5 2\n2 3\n5 3\n2 3 5\n5 3\n2 3 4\n5 4\n2 3 4 5\n5 1\n1\n5 2\n1 5\n5 2\n1 4\n5 3\n1 4 5\n5 2\n1 3\n5 3\n1 3 5\n5 3\n1... | 1,000 | 0 |
2 | 10 | 976_D. Degree Set | You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that:
* there are exactly dn + 1 vertices;
* there are no self-loops;
* there are no multiple edges;
* there are no more than 106 edges;
* its degree set is equal to d.... | {
"input": [
"3\n1 2 3\n",
"3\n2 3 4\n"
],
"output": [
"4\n1 2\n1 3\n1 4\n2 3\n",
"8\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n"
]
} | {
"input": [
"2\n2 3\n",
"2\n1 2\n",
"3\n2 3 4\n",
"2\n1 1000\n",
"4\n1 3 4 6\n",
"4\n6 8 11 19\n",
"1\n1\n",
"10\n1 2 3 4 5 6 7 8 9 10\n",
"10\n1 3 4 6 10 12 16 18 19 20\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3... | 2,500 | 0 |
2 | 8 | 996_B. World Cup | Allen wants to enter a fan zone that occupies a round square and has n entrances.
There already is a queue of a_i people in front of the i-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.
Allen uses the following strategy to enter the fan zone:
* Initially he stands... | {
"input": [
"4\n2 3 2 0\n",
"6\n5 2 6 5 7 4\n",
"2\n10 10\n"
],
"output": [
"3\n",
"6\n",
"1\n"
]
} | {
"input": [
"2\n1 1\n",
"2\n483544186 940350702\n",
"4\n5 2 3 4\n",
"2\n1 0\n",
"2\n999999999 1000000000\n",
"10\n3 3 3 5 6 9 3 1 7 3\n",
"2\n1000000000 1000000000\n",
"10\n5 6 7 8 9 10 11 12 13 14\n",
"3\n15 8 9\n",
"6\n7 2 6 5 7 9\n",
"3\n1000000000 1000000000 1000000000... | 1,300 | 1,000 |
2 | 11 | 1056_E. Check Transcription | One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal s towards a faraway galaxy. Recently they've received a response t which they believe to be a response from aliens! The scientists now want to check if the signal t is similar to s.
The original signal s was a se... | {
"input": [
"001\nkokokokotlin\n",
"01\naaaaaa\n"
],
"output": [
"2\n",
"4\n"
]
} | {
"input": [
"010\nugkircaaaaaaaaaab\n",
"010\ngvmorcaaaaaaaaaab\n",
"01\nzbrronwaofovklkopelo\n",
"010\nojwprcaaaaaaaaaab\n"
],
"output": [
"0\n",
"0\n",
"19\n",
"0\n"
]
} | 2,100 | 2,500 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.