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
8
209_B. Pixels
Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel t...
{ "input": [ "1 1 1\n", "3 1 0\n" ], "output": [ " 1\n", " 3\n" ] }
{ "input": [ "9 530792195 6\n", "0 0 10\n", "1944219055 454183506 1369298327\n", "914835 2742837 9234739\n", "10 10 0\n", "2 2 0\n", "0 0 1\n", "3 10 1007169359\n", "0 1 0\n", "1016450951 2 9\n", "0 2 10\n", "2147483648 0 2147483647\n", "92134834 23742837 92374738\n...
2,100
500
2
7
235_A. LCM Challenge
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find th...
{ "input": [ "7\n", "9\n" ], "output": [ "210\n", "504\n" ] }
{ "input": [ "447244\n", "958507\n", "816923\n", "836603\n", "862795\n", "756604\n", "1000000\n", "4\n", "668827\n", "245\n", "520731\n", "642635\n", "8\n", "244\n", "148\n", "213\n", "984699\n", "20\n", "810411\n", "796\n", "924\n", ...
1,600
500
2
10
25_D. Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
{ "input": [ "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n", "2\n1 2\n" ], "output": [ "1\n3 1 1 4 ", "0\n" ] }
{ "input": [ "4\n1 4\n3 1\n3 4\n", "5\n4 1\n4 3\n5 3\n2 4\n", "21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\n3 17\n16 9\n13 8\n", "3\n3 1\n3 2\n", "6\n5 2\n5 3\n1 4\n3 1\n5 6\n", "60\n17 34\n46 22\n50 44\n46 33\n41 21\n31 33\n48 6\n3...
1,900
0
2
9
306_C. White, Black and White Again
Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to ta...
{ "input": [ "3 2 1\n", "3 2 2\n", "4 2 2\n" ], "output": [ "2\n", "4\n", "4\n" ] }
{ "input": [ "3 3 1\n", "300 2 300\n", "4000 4000 1\n", "4000 4000 100\n", "4 2 3\n", "3 300 300\n", "4000 100 4000\n", "3 300 1\n", "300 300 1\n", "4000 1000 3000\n", "3 2 4000\n", "4 3 2\n", "3 2 300\n", "4000 3998 2\n", "100 200 300\n", "300 300 300\n...
2,100
1,500
2
9
378_C. Maze
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
{ "input": [ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n" ], "output": [ "#..#\n..#X\n#..X\n", "#...\n#.#.\nX#..\nXX.#\nX#X#\n" ] }
{ "input": [ "19 20 196\n###.....##.#..#..##.\n####............##..\n###....#..#.#....#.#\n##....###......#...#\n.####...#.....#.##..\n.###......#...#.#.#.\n...##.#...#..#..#...\n.....#.....#..#....#\n.#.....##..#........\n.##....#......#....#\n....#.......#.......\n......##..#........#\n......#.#.##....#...\n......
1,600
500
2
11
39_E. What Has Dirichlet Got to Do with That?
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items. Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. T...
{ "input": [ "3 1 4\n", "2 2 10\n", "5 5 16808\n", "1 4 10\n" ], "output": [ "Stas\n\n", "Masha\n\n", "Masha\n\n", "Missing\n\n" ] }
{ "input": [ "2 2 5\n", "9 9 1000000000\n", "3 17 999999997\n", "3 3 64\n", "5 1 64\n", "29 2 1000000000\n", "1010 1 1000000000\n", "3 2 27\n", "1 1 60\n", "2 4 64\n", "2 2 64\n", "3 4 1000\n", "2 3 64\n", "2 1 536870912\n", "2 2 17\n", "117 1 13689\n", ...
2,000
0
2
7
425_A. Sereja and Swaps
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation: <image> A swap operation is the following sequence of actions: * choose two indexes i, j (i ≠ j); * perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp. What maximum value of function m(a) can Serej...
{ "input": [ "5 10\n-1 -1 -1 -1 -1\n", "10 2\n10 -1 2 2 2 2 2 2 -1 10\n" ], "output": [ "-1\n", "32\n" ] }
{ "input": [ "1 10\n1\n", "10 1\n-1 1 1 1 1 1 1 1 1 1\n", "78 8\n-230 -757 673 -284 381 -324 -96 975 249 971 -355 186 -526 804 147 -553 655 263 -247 775 108 -246 -107 25 -786 -372 -24 -619 265 -192 269 392 210 449 335 -207 371 562 307 141 668 78 13 251 623 -238 60 543 618 201 73 -35 -663 620 485 444 330 3...
1,500
500
2
10
449_D. Jzzhu and Numbers
Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n) a group of size k. Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≤ k ≤ n)? Help him and print this number modulo 1000000007 (109 + 7). Operation x & y deno...
{ "input": [ "3\n2 3 3\n", "4\n0 1 2 3\n", "6\n5 2 0 5 2 1\n" ], "output": [ "0\n", "10\n", "53\n" ] }
{ "input": [ "2\n1 31\n", "2\n1 0\n", "10\n450661 128600 993228 725823 293549 33490 843121 903634 556169 448234\n", "1\n1\n", "5\n1 3 5 7 9\n", "6\n524 529 5249 524 529 529\n", "3\n1 2 3\n", "2\n0 1\n", "55\n0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 3 4 5 6 7 8 9 4 5 6 ...
2,400
2,000
2
7
494_A. Treasure
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the ...
{ "input": [ "(((#)((#)\n", "#\n", "()((#((#(#()\n", "(#)\n" ], "output": [ "1\n2\n", "-1\n", "1\n1\n3\n", "-1\n" ] }
{ "input": [ "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(\n", "(#((((()\n", "(#((\n", "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##\n", "(())((((#)\n", "(#(\n", "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())(((...
1,500
500
2
11
518_E. Arthur and Questions
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n. This sequence had the following property: if you write out the sums of all its segments consisting of k consecutive elements (a1 + a2 ... + ak, ...
{ "input": [ "3 2\n? 1 2\n", "5 1\n-10 -9 ? -7 -6\n", "5 3\n4 6 7 2 9\n" ], "output": [ "0 1 2\n", "-10 -9 -8 -7 -6\n", "Incorrect sequence\n" ] }
{ "input": [ "7 2\n-10 0 ? 1 ? 2 10\n", "1 1\n0\n", "5 1\n-3 -2 -1 0 1\n", "7 1\n-4 ? ? ? ? ? 2\n", "17 1\n? -13 ? ? ? -3 ? ? ? ? ? 10 ? ? ? ? 100\n", "3 1\n-5 ? 0\n", "7 2\n-10 0 ? 1 6 2 ?\n", "3 1\n-3 ? -2\n", "6 1\n-1 ? 1 2 3 4\n", "1 1\n?\n", "9 2\n-10 0 ? 1 ? 2 ? 3 ?\n...
2,200
2,500
2
11
544_E. Remembering Strings
You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some letter c of the English alphabet, such that this string is the only string in the multiset that has letter c in position i....
{ "input": [ "4 3\nabc\naba\nadc\nada\n10 10 10\n10 1 10\n10 10 10\n10 1 10\n", "4 5\nabcde\nabcde\nabcde\nabcde\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n", "3 3\nabc\nada\nssa\n1 1 1\n1 1 1\n1 1 1\n" ], "output": [ "2", "3", "0" ] }
{ "input": [ "1 1\na\n10\n", "1 20\naaaaaaaaaaaaaaaaaaaa\n924705 786913 546594 427698 741583 189683 354089 380570 10694 41046 656300 416271 467032 627269 387941 432085 400210 97543 279672 409814\n", "20 2\ned\nci\ngg\nib\nae\ndd\nka\nce\naf\ngb\nag\nke\ngj\nab\nie\nif\ngb\nkd\njg\neg\n52414 63820\n271794 ...
2,500
1,750
2
8
571_B. Minimization
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n. You need to permute the array elements so that value <image> became minimal possible. In particular, it is allowed not to change order of elements at all. Input The first line contains two integers n,...
{ "input": [ "5 2\n3 -5 3 -5 3\n", "3 2\n1 2 4\n", "6 3\n4 3 4 3 2 5\n" ], "output": [ "0\n", "1\n", "3\n" ] }
{ "input": [ "30 2\n-999999924 -499999902 500000091 -999999998 500000030 -999999934 500000086 -499999918 -499999998 67 -999999964 -499999975 -499999947 -499999925 3 -499999985 14 500000015 500000022 88 25 -499999909 500000051 -499999984 -999999964 -499999905 -499999968 86 43 -999999980\n", "5 2\n1 2 8 8 16\n"...
2,000
1,250
2
9
614_C. Peter and Snow Blower
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
{ "input": [ "3 0 0\n0 1\n-1 2\n1 2\n", "4 1 -1\n0 0\n1 2\n2 0\n1 1\n" ], "output": [ "12.566370614359176\n", "21.991148575128552\n" ] }
{ "input": [ "4 0 0\n1 -1\n1 3\n3 3\n3 -1\n", "3 0 0\n-10 1\n0 2\n1 1\n", "3 0 0\n-1 1\n0 3\n1 1\n", "20 -999719 -377746\n-999718 -377746\n-997432 -940486\n-982215 -950088\n-903861 -997725\n-127953 -999833\n846620 -999745\n920305 -992903\n947027 -986746\n991646 -959876\n998264 -944885\n999301 870671\n...
1,900
750
2
7
687_A. NP-Hard Problem
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv there is at least one endpoint of it in this set, i.e. <image> or <image>...
{ "input": [ "4 2\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n" ], "output": [ "3\n1 3 4 \n1\n2 ", "-1" ] }
{ "input": [ "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3\n", "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1\n", "20 22\n3 18\n9 19\n6 15\n7 1\n16 8\n18 7\n12 3\n18 4\n9 15\n20 1\n4 2\n6 7\n14 2\n7 15\n7 10\n8 1\n13 6\n9 7\n11 8\n2 6\n18 5\n17 15\n", "1...
1,500
500
2
13
730_G. Car Repair Shop
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time. Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order...
{ "input": [ "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n", "3\n9 2\n7 3\n2 4\n" ], "output": [ "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000\n", "9 10\n1 3\n4 7\n" ] }
{ "input": [ "1\n1 5000000\n", "1\n1000000000 1\n", "10\n588 12\n560 10\n593 14\n438 15\n761 11\n984 6\n503 2\n855 19\n538 2\n650 7\n", "20\n360 26\n475 17\n826 12\n815 23\n567 28\n897 26\n707 20\n1000 9\n576 5\n16 5\n714 16\n630 17\n426 26\n406 23\n899 25\n102 22\n896 8\n320 27\n964 25\n932 18\n", ...
1,600
0
2
8
754_B. Ilya and tic-tac-toe game
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making...
{ "input": [ "o.x.\no...\n.x..\nooxx\n", "x.ox\nox..\nx.o.\noo.x\n", "xx..\n.oo.\nx...\noox.\n", "x..x\n..oo\no...\nx.xo\n" ], "output": [ "NO\n", "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "xoox\n.xx.\no..o\n..xo\n", "o.xx\nxo.o\n...o\n..x.\n", "xxoo\no.oo\n...x\nx..x\n", "o..x\n....\n...x\n..o.\n", "....\n.o..\n....\nox.x\n", "xxo.\n.oo.\n..x.\n..xo\n", "....\n..ox\n....\n.o.x\n", "x..o\nxo.x\no.xo\nxoox\n", ".xx.\n...x\noo.o\no..x\n", "x...\no.ox\n...
1,100
1,000
2
17
774_K. Stepan and Vowels
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa". Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowe...
{ "input": [ "18\naeiouyaaeeiioouuyy\n", "22\niiiimpleeemeentatiioon\n", "13\npobeeeedaaaaa\n", "24\naaaoooiiiuuuyyyeeeggghhh\n" ], "output": [ "aeiouyaeeioouy", "implemeentatioon", "pobeda", "aoiuyeggghhh" ] }
{ "input": [ "3\neoo\n", "36\naeiouyaaeeiioouuyyaaaeeeiiiooouuuyyy\n", "3\nooo\n", "1\na\n", "4\neeoo\n", "5\noooee\n", "5\nooeoo\n", "1\nf\n", "200\nmmffggzvuuzzlkafduueqocuybiiaaeeoiioouaaurccuqoouuooooooyjjtyyxxiipneeueyuuoyxxhhkaaooooyaaauuoppzabuuoiiuuggcciissuugejjiirruummsii...
1,600
0
2
7
820_A. Mister B and Book Reading
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages. At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second —...
{ "input": [ "5 5 10 5 4\n", "12 4 12 4 1\n", "15 1 100 0 0\n" ], "output": [ "1\n", "3\n", "15\n" ] }
{ "input": [ "10 1 4 10 0\n", "100 1 2 1000 0\n", "1 11 12 0 10\n", "1 2 3 0 0\n", "8 6 13 2 5\n", "8 3 5 1 0\n", "17 10 12 6 5\n", "6 4 4 1 2\n", "50 4 5 5 0\n", "20 2 40 1 1\n", "1000 501 510 1 499\n", "129 2 3 4 0\n", "16 4 23 8 3\n", "11 2 4 1 1\n", "97 ...
900
500
2
8
846_B. Math Show
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order. By solving s...
{ "input": [ "5 5 10\n1 2 4 8 16\n", "3 4 11\n1 2 3 4\n" ], "output": [ "7\n", "6\n" ] }
{ "input": [ "1 3 0\n6 3 4\n", "5 4 32\n4 2 1 1\n", "32 6 635\n3 4 2 1 7 7\n", "3 7 20012\n1 1 1 1 1 1 10000\n", "1 5 44\n2 19 18 6 8\n", "1 3 8\n5 4 4\n", "3 3 15\n1 2 1\n", "1 1 1\n1\n", "1 1 0\n2\n", "12 1 710092\n145588\n", "21 3 26\n1 2 3\n", "11 2 20\n1 9\n", ...
1,800
0
2
7
893_A. Chess For Three
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three. So they play with each other according to following rules: ...
{ "input": [ "2\n1\n2\n", "3\n1\n1\n2\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "99\n1\n3\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n1\n1\n3\n3\n3\n3\n1\n1\n3\n2\n1\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n1\n3\n3\n1\n1\n3\n2\n1\n3\n3\n1\n2\n3\n3\n3\n1\n2\n2\n2\n3\n3\n3\n3\n3\n3\n2\n2\n2\n2\n3\n3\n3\n1\n1\n3\n2\n1\n1\n2\n2\n2\n3\n3\n2\n1\n1\n2\n2\n1\n3\n2\n1\n1\n2\n3\n3\n3\n3\n2\n2\n2\n2\n2\n1\n3\...
900
0
2
10
937_D. Sleepy Game
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't m...
{ "input": [ "3 2\n1 3\n1 1\n0\n2\n", "2 2\n1 2\n1 1\n1\n", "5 6\n2 2 3\n2 4 5\n1 4\n1 5\n0\n1\n" ], "output": [ "Lose\n", "Draw\n", "Win\n1 2 4 5\n" ] }
{ "input": [ "11 20\n1 2\n2 7 6\n1 7\n4 10 9 3 2\n2 9 2\n1 3\n0\n0\n3 1 6 7\n4 11 7 5 6\n2 2 8\n4\n", "5 5\n1 2\n1 3\n2 1 4\n1 5\n0\n1\n", "5 5\n1 2\n1 3\n2 2 4\n1 5\n0\n1\n", "4 3\n1 2\n1 3\n1 1\n0\n1\n", "6 6\n1 2\n2 3 6\n1 4\n0\n1 3\n1 5\n2\n", "5 5\n1 2\n2 3 5\n1 4\n1 2\n0\n1\n", "5 5\...
2,100
1,000
2
8
990_B. Micro-World
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have n bacteria in the Petri dish and size of the i-th bacteria is a_i. Also you know intergalactic positive integer constan...
{ "input": [ "6 5\n20 15 10 15 20 25\n", "7 1\n101 53 42 102 101 55 54\n", "7 1000000\n1 1 1 1 1 1 1\n" ], "output": [ "1\n", "3\n", "7\n" ] }
{ "input": [ "2 1\n1 1\n", "4 1\n2 2 1 1\n", "10 1\n2 6 3 4 2 4 4 3 2 1\n", "2 1\n999152 999153\n", "8 1000000\n1 1 5 1000000 1000000 2 2 2\n", "9 2\n1 6 1 5 5 8 6 8 7\n", "15 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "1 4\n8\n", "10 1\n6 3 1 3 6 4 1 3 6 4\n", "10 1\n1 2 3 5 6 8 10 ...
1,200
0
2
11
1030_E. Vasya and Good Sequences
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10...
{ "input": [ "4\n1 2 1 16\n", "3\n6 7 14\n" ], "output": [ "4\n", "2\n" ] }
{ "input": [ "5\n1000000000000000000 352839520853234088 175235832528365792 753467583475385837 895062156280564685\n", "1\n15\n", "1\n4\n" ], "output": [ "3\n", "0\n", "0\n" ] }
2,000
2,000
2
10
1075_D. Intersecting Subtrees
You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's labelling of the tree. You and Li Chen each chose a subtree (i.e., a connected su...
{ "input": [ "1\n3\n1 2\n2 3\n1\n1\n1\n2\n2\n1\n", "2\n6\n1 2\n1 3\n1 4\n4 5\n4 6\n4\n1 3 4 5\n3\n3 5 2\n3\n6\n1 2\n1 3\n1 4\n4 5\n4 6\n3\n1 2 3\n3\n4 1 6\n5\n" ], "output": [ "B 2\nA 1\nC -1\n", "B 2\nC 3\nB 1\nA 1\nC -1\n" ] }
{ "input": [ "1\n1\n1\n1\n1\n1\n1\n", "1\n3\n2 3 1\n1 2\n2 3\n1\n1\n1\n2\n", "2\n6\n5 3 2 4 1 6\n1 2\n1 3\n1 4\n4 5\n4 6\n4\n1 3 4 5\n3\n3 5 2\n6\n5 3 2 4 1 6\n1 2\n1 3\n1 4\n4 5\n4 6\n3\n1 2 3\n3\n4 1 6\n" ], "output": [ "B 1\nC 1\n", "B 1\nA 0\nC -1\n", "B 4\nA 4\nC -1\nB 2\nC 1\n" ] }
1,900
1,250
2
11
1096_E. The Top Scorer
Hasan loves playing games and has recently discovered a game called TopScore. In this soccer-like game there are p players doing penalty shoot-outs. Winner is the one who scores the most. In case of ties, one of the top-scorers will be declared as the winner randomly with equal probability. They have just finished the...
{ "input": [ "10 30 10\n", "2 6 3\n", "5 20 11\n" ], "output": [ "85932500\n", "124780545\n", "1\n" ] }
{ "input": [ "1 5000 4999\n", "2 1 0\n", "83 2813 123\n", "93 2364 2364\n", "100 1 0\n", "21 862 387\n", "1 1 0\n", "93 2364 1182\n", "1 0 0\n", "100 5000 30\n", "100 0 0\n", "45 2315 2018\n", "45 886 245\n", "69 813 598\n", "1 5000 0\n", "45 2315 860\n"...
2,500
0
2
8
1144_B. Parity Alternated Deletions
Polycarp has an array a consisting of n integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its...
{ "input": [ "2\n1000000 1000000\n", "6\n5 1 2 4 6 3\n", "5\n1 5 7 8 2\n" ], "output": [ "1000000\n", "0\n", "0\n" ] }
{ "input": [ "5\n1 1 1 1 1\n", "5\n2 1 1 1 1\n" ], "output": [ "4\n", "2\n" ] }
900
0
2
7
1165_A. Remainder
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
{ "input": [ "11 5 2\n11010100101\n", "11 5 1\n11010100101\n" ], "output": [ "1\n", "3\n" ] }
{ "input": [ "6 4 2\n100010\n", "4 2 1\n1000\n", "8 5 2\n10000100\n", "11 5 2\n11010000101\n", "64 40 14\n1010011100101100101011000001000011110111011011000111011011000100\n", "7 5 3\n1011000\n", "8 5 1\n10000000\n", "5 2 1\n11010\n", "11 5 2\n11110000100\n", "4 1 0\n1000\n", ...
1,100
0
2
9
1244_C. The Football Season
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in ...
{ "input": [ "30 60 3 1\n", "20 0 15 5\n", "10 51 5 4\n" ], "output": [ "20 0 10\n", "0 0 20\n", "-1\n" ] }
{ "input": [ "728961319347 33282698448966372 52437 42819\n", "461788563846 36692905412962338 93797 64701\n", "567018385179 15765533940665693 35879 13819\n", "21644595275 987577030498703 66473 35329\n", "1000000000000 1000000000000 6 3\n", "33 346 15 8\n", "778 37556 115 38\n", "4529304...
2,000
1,500
2
7
1264_A. Beautiful Regional Contest
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n. Help the jury distrib...
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n" ], "output": [ "1 2 3\n0 0 0\n0 0 0\n1 2 7\n2 6 6\n" ] }
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n" ], "output": [ "1 2 3\n0 0 0\n0 0 0\n1 2 7\n2 6 6\n" ] }
1,500
500
2
9
1285_C. Fadi and LCM
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers. LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6. O...
{ "input": [ "1\n", "4\n", "6\n", "2\n" ], "output": [ "1 1\n", "1 4\n", "2 3\n", "1 2\n" ] }
{ "input": [ "205078485761\n", "873109054817\n", "518649879439\n", "401021537803\n", "821985629174\n", "614685146646\n", "551519879446\n", "583102513046\n", "690824608515\n", "681460970070\n", "355170254369\n", "924639053494\n", "726702209411\n", "287784545004\n...
1,400
1,250
2
11
1304_E. 1-Trees and Queries
Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree? Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wan...
{ "input": [ "5\n1 2\n2 3\n3 4\n4 5\n5\n1 3 1 2 2\n1 4 1 3 2\n1 4 1 3 3\n4 2 3 3 9\n5 2 3 3 9\n" ], "output": [ "YES\nYES\nNO\nYES\nNO\n" ] }
{ "input": [ "9\n3 9\n3 4\n7 2\n6 9\n5 3\n6 2\n8 3\n1 9\n10\n8 4 8 2 5\n9 2 7 4 4\n8 5 7 3 3\n1 2 3 8 4\n2 9 2 4 3\n6 4 3 4 5\n6 7 6 6 4\n7 5 3 1 4\n5 4 7 8 3\n4 5 1 5 2\n", "14\n4 9\n3 7\n4 1\n3 2\n14 9\n7 6\n10 13\n8 7\n5 7\n7 10\n1 3\n12 3\n7 11\n20\n13 6 14 9 3\n6 4 3 7 9\n9 3 6 13 7\n6 11 11 5 9\n14 5 2 ...
2,000
2,000
2
12
1328_F. Make k Equal
You are given the array a consisting of n elements and the integer k ≤ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of ...
{ "input": [ "6 5\n1 2 2 4 2 3\n", "7 5\n3 3 2 1 1 1 3\n" ], "output": [ "4\n", "2\n" ] }
{ "input": [ "21 6\n12 15 14 4 4 7 2 4 11 1 15 4 12 11 12 8 11 12 3 4 4\n", "50 25\n19 1 17 6 4 21 9 16 5 21 2 12 17 11 54 18 36 20 34 17 32 1 4 14 26 11 6 2 7 5 2 3 12 16 20 5 16 1 18 55 16 20 2 3 2 12 65 20 7 11\n", "5 2\n9 9 9 9 9\n", "1 1\n1000000000\n", "7 3\n1 1 1 1 1 1 1\n", "2 1\n1 100...
2,200
0
2
10
1369_D. TediousLee
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level n ...
{ "input": [ "7\n1\n2\n3\n4\n5\n100\n2000000\n" ], "output": [ "0\n0\n4\n4\n12\n990998587\n804665184\n" ] }
{ "input": [ "3\n1234567\n1268501\n1268499\n" ], "output": [ "788765312\n999997375\n999999350\n" ] }
1,900
2,000
2
9
1391_C. Cyclic Permutations
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). Consider a permutation p of length ...
{ "input": [ "4\n", "583291\n" ], "output": [ "16\n", "135712853\n" ] }
{ "input": [ "66\n", "652615\n", "482331\n", "336161\n", "33\n", "1000000\n", "79531\n", "768208\n", "3\n", "885131\n" ], "output": [ "257415584\n", "960319213\n", "722928541\n", "234634596\n", "762187807\n", "23581336\n", "162141608\n", "635...
1,500
1,250
2
8
161_B. Discounts
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape...
{ "input": [ "3 2\n2 1\n3 2\n3 1\n", "4 3\n4 1\n1 2\n2 2\n3 2\n" ], "output": [ "5.5\n1 3 \n2 1 2 \n", "8.0\n1 1 \n1 2 \n2 3 4 \n" ] }
{ "input": [ "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2\n", "21 7\n14 1\n882797755 2\n17 1\n906492329 2\n209923513 2\n802927469 2\n949195463 2\n677323647 2\n2129083 2\n2 1\n13 1\n539523264 2\n7 1\n8 1\n12 1\n363470241 2\n9838294 2\n18716193 2\n30 1\n17 1\n24 1\n", "1 1\n1 1\n", "10 ...
1,700
1,000
2
10
180_D. Name
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep...
{ "input": [ "abc\ndefg\n", "czaaab\nabcdef\n", "aad\naac\n", "abad\nbob\n" ], "output": [ "-1\n", "abczaa\n", "aad\n", "daab\n" ] }
{ "input": [ "z\na\n", "abc\naaac\n", "bcbcdddbbd\nbcbcdbdbbd\n", "aaabccadac\nacabbbabaa\n", "a\nb\n", "acaccaaadz\ncaadccaaaa\n", "aa\nab\n", "abacaba\naba\n", "aabbaa\naaaaaaaaaaaaaaaaaaaa\n", "ac\na\n", "a\na\n", "aabbaa\ncaaaaaaaaa\n", "aaaaaaaaa\na\n", "cc...
1,900
0
2
8
252_B. Unsorting Array
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct po...
{ "input": [ "3\n1 1 1\n", "1\n1\n", "2\n1 2\n", "4\n1 2 3 4\n" ], "output": [ "-1\n", "-1\n", "-1\n", "1 2\n" ] }
{ "input": [ "3\n3 2 3\n", "3\n1 3 1\n", "5\n1 1 2 1 1\n", "5\n1 1 1 1 2\n", "4\n562617869 562617869 562617869 562617869\n", "6\n1 2 3 3 2 1\n", "4\n562617869 961148050 961148050 961148050\n", "4\n961148050 951133776 596819899 0\n", "4\n961148050 961148050 562617869 961148050\n", ...
1,800
1,000
2
7
348_A. Mafia
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ...
{ "input": [ "3\n3 2 2\n", "4\n2 2 2 2\n" ], "output": [ "4\n", "3\n" ] }
{ "input": [ "3\n1000000000 1000000000 10000000\n", "3\n1 2 1\n", "3\n4 10 11\n", "5\n1000000000 5 5 4 4\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "10\n94 96 91 95 99 94 96 92 95 99\n", "7\n9 7 7 8 8 7 8\n", "3\n1 1 1\n", "3\n677876423 834056477 553175531\n...
1,600
500
2
8
371_B. Fox Dividing Cheese
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox...
{ "input": [ "15 20\n", "14 8\n", "6 6\n" ], "output": [ "3\n", "-1\n", "0\n" ] }
{ "input": [ "919536000 993098880\n", "691200 583200\n", "5 1000000000\n", "100 10\n", "537814642 537814642\n", "21 35\n", "800000 729000\n", "881280 765000\n", "864000000 607500000\n", "648293430 540244525\n", "445906944 528482304\n", "820125000 874800000\n", "5096...
1,300
1,000
2
9
442_C. Artem and Array
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
{ "input": [ "5\n1 2 3 4 5\n", "5\n1 100 101 100 1\n", "5\n3 1 5 2 6\n" ], "output": [ "6", "102", "11" ] }
{ "input": [ "9\n72 49 39 50 68 35 75 94 56\n", "4\n2 3 1 2\n", "8\n3 4 3 1 1 3 4 1\n", "1\n4\n", "7\n2 1 2 2 2 2 2\n", "6\n1 7 3 1 6 2\n", "8\n77 84 26 34 17 56 76 3\n", "2\n93 51\n", "1\n87\n", "4\n86 21 58 60\n", "10\n96 66 8 18 30 48 34 11 37 42\n", "6\n46 30 38 9 6...
2,500
1,500
2
9
488_C. Fight the Monster
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0,...
{ "input": [ "1 2 1\n1 100 1\n1 100 100\n", "100 100 100\n1 1 1\n1 1 1\n" ], "output": [ "99", "0" ] }
{ "input": [ "51 89 97\n18 25 63\n22 91 74\n", "1 100 1\n100 100 100\n1 100 100\n", "20 1 1\n100 100 100\n1 100 100\n", "1 10 29\n1 1 43\n1 1 100\n", "25 38 49\n84 96 42\n3 51 92\n", "2 1 1\n100 2 100\n100 1 100\n", "1 1 1\n100 100 100\n1 100 100\n", "99 32 20\n89 72 74\n1 100 39\n", ...
1,800
500
2
8
512_B. Fox And Jumping
Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0. There are also n cards, each card has 2 attributes: length li and cost ci. If she pays ci dollars then she can apply i-th card. After app...
{ "input": [ "5\n10 20 30 40 50\n1 1 1 1 1\n", "8\n4264 4921 6321 6984 2316 8432 6120 1026\n4264 4921 6321 6984 2316 8432 6120 1026\n", "3\n100 99 9900\n1 1 1\n", "7\n15015 10010 6006 4290 2730 2310 1\n1 1 1 1 1 1 10\n" ], "output": [ "-1", "7237\n", "2\n", "6\n" ] }
{ "input": [ "8\n2 3 5 7 11 13 17 19\n4 8 7 1 5 2 6 3\n", "1\n2\n2\n", "1\n1000000000\n100000\n", "1\n1\n1\n", "6\n1 2 4 8 16 32\n32 16 8 4 2 1\n", "2\n1000000000 999999999\n100000 100000\n", "39\n692835 4849845 22610 1995 19019 114 6270 15 85085 27170 1365 1155 7410 238 3135 546 373065 71...
1,900
2,000
2
10
560_D. Equivalent Strings
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: 1. They are equal. 2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2...
{ "input": [ "aaba\nabaa\n", "aabb\nabab\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "aabbaaaa\naaaaabab\n", "qgiufelsfhanx\naaaaaaaaaaaaa\n", "abcddd\nbacddd\n", "azzz\nzzaz\n", "zzaa\naazz\n", "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtu...
1,700
1,000
2
12
586_F. Lizard Era: Beginning
In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has n mandatory quests. To perform each of them, you need to take exactly two companions. The attitude of each of the companions to the hero is an integer. Initially, the attitude of each o...
{ "input": [ "7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7\n", "2\n1 0 0\n1 1 0\n", "3\n1 0 0\n0 1 0\n0 0 1\n" ], "output": [ "LM\nMW\nLM\nLW\nMW\nLM\nLW\n", "Impossible\n", "LM\nLM\nLW\n" ] }
{ "input": [ "3\n7089544 9134148 -5332724\n368810 1638695 7889905\n-3866235 -4257263 5802154\n", "16\n-3253484 -6513322 5617669\n-8870526 9976385 -7313669\n5682511 -1202928 -7057533\n4747064 475782 7416790\n-4387656 3965849 9530503\n-8224426 4339650 181725\n1012598 -8651198 -222828\n-1012251 -9099337 719019\n...
2,300
1,750
2
8
609_B. The Best Gift
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the nu...
{ "input": [ "7 4\n4 2 3 1 2 4 3\n", "4 3\n2 1 3 1\n" ], "output": [ "18\n", "5\n" ] }
{ "input": [ "100 10\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6\n", "3 2\n1 2 2\n", "12 3\n1 2 3 1 2 3 1 2 3 1 2 3\n", "100 3\n2 1 ...
1,100
0
2
7
630_A. Again Twenty Five!
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using ...
{ "input": [ "2\n" ], "output": [ "25\n" ] }
{ "input": [ "7\n", "2000000000000000000\n", "1000000000000000000\n", "987654321012345678\n" ], "output": [ "25\n", "25\n", "25\n", "25\n" ] }
800
0
2
11
656_E. Out of Controls
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them. Input The first line of the input contains a single integer N (3 ≤ N ≤ 10). Th...
{ "input": [ "3\n0 1 1\n1 0 4\n1 4 0\n", "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0\n" ], "output": [ "2", "5" ] }
{ "input": [ "6\n0 41 48 86 94 14\n41 0 1 30 59 39\n48 1 0 9 31 49\n86 30 9 0 48 30\n94 59 31 48 0 33\n14 39 49 30 33 0\n", "6\n0 92 9 24 50 94\n92 0 70 73 57 87\n9 70 0 31 14 100\n24 73 31 0 66 25\n50 57 14 66 0 81\n94 87 100 25 81 0\n", "3\n0 86 45\n86 0 54\n45 54 0\n", "6\n0 41 81 77 80 79\n41 0 64...
2,000
0
2
11
702_E. Analysis of Pathes in Functional Graph
You are given a functional graph. It is a directed graph, in which from each vertex goes exactly one arc. The vertices are numerated from 0 to n - 1. Graph is given as the array f0, f1, ..., fn - 1, where fi — the number of vertex to which goes the only arc from the vertex i. Besides you are given array with weights o...
{ "input": [ "5 3\n1 2 3 4 0\n4 1 2 14 3\n", "7 3\n1 2 3 4 3 2 6\n6 3 1 4 2 2 3\n", "4 4\n0 1 2 3\n0 1 2 3\n" ], "output": [ " 7 1\n ...
{ "input": [ "1 1\n0\n10000\n", "2 3\n1 0\n4 7\n", "1 2\n0\n10000\n", "3 10\n0 1 2\n9240 5331 6721\n", "4 10\n2 1 2 1\n960 2596 3752 8303\n", "6 10\n0 3 3 5 3 5\n4845 6494 579 5025 2998 4787\n", "1 10000000000\n0\n10000\n", "2 3\n0 1\n4 7\n", "2 3\n1 1\n4 7\n", "8 10\n7 5 0 0 2...
2,100
0
2
9
814_C. An impassioned circulation of affection
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from le...
{ "input": [ "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n", "6\nkoyomi\n3\n1 o\n4 o\n4 m\n", "10\naaaaaaaaaa\n2\n10 b\n10 z\n" ], "output": [ "3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n", "3\n6\n5\n", "10\n10\n" ] }
{ "input": [ "20\naaaaaaaaaaaaaaaaaaaa\n1\n11 a\n", "4\ncbcc\n12\n4 b\n4 c\n1 b\n2 a\n3 b\n2 c\n4 a\n1 a\n2 b\n3 a\n1 c\n3 c\n", "100\ndddddccccdddddaaaaabbbbbbbbbbbbbaaacdcabbacccacccccbdbbadddbbddddbdaaccacdddbbbaddddbbbbdcbbbdddddda\n50\n54 b\n48 d\n45 b\n52 c\n52 a\n48 a\n54 b\n45 a\n47 d\n50 d\n53 a\...
1,600
1,750
2
9
83_C. Track
You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest. The track's map is represented by a rectangle n × m in size divi...
{ "input": [ "5 3 2\nSba\nccc\naac\nccc\nabT\n", "3 4 1\nSxyy\nyxxx\nyyyT\n", "1 3 3\nTyS\n", "1 4 1\nSxyT\n" ], "output": [ "bcccc\n", "xxxx\n", "y\n", "-1\n" ] }
{ "input": [ "20 10 3\nebebccacdb\neeebccddeT\neadebecaac\nadeeeaccbc\nbaccccdaed\ndeabceabba\ndadbecbaaa\neacbbcedcb\naeeScdbbab\nbabaecaead\nbacdbebeae\naacbadbeec\nacddceecca\nacaeaebaba\ncdddeaaeae\neabddadade\nddddaeaeed\nbccbaacadd\ndccccbabdc\necdaebeccc\n", "1 30 2\nbmjcfldkloleiqqiTnmdjpaSckkijf\n", ...
2,400
1,500
2
10
886_D. Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
{ "input": [ "3\nkek\npreceq\ncheburek\n", "4\nmail\nai\nlru\ncf\n" ], "output": [ "NO\n", "cfmailru\n" ] }
{ "input": [ "2\nab\nac\n", "2\nca\ncb\n", "2\ndc\nec\n", "2\naz\nzb\n", "2\naa\nb\n", "25\nsw\nwt\nc\nl\nyo\nag\nz\nof\np\nmz\nnm\nui\nzs\nj\nq\nk\ngd\nb\nen\nx\ndv\nty\nh\nr\nvu\n", "51\np\nsu\nbpxh\nx\nxhvacdy\nqosuf\ncdy\nbpxhvacd\nxh\nbpxhv\nf\npxh\nhva\nhvac\nxhva\nos\ns\ndy\nqo\nv\n...
2,000
2,000
2
10
909_D. Colorful Points
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right. You perform a sequence of operations on this set of p...
{ "input": [ "aabb\n", "aabcaa\n" ], "output": [ "2\n", "1\n" ] }
{ "input": [ "bbbbbbbbaaaaaaaaaaaccccccaaaaaaaaaaaaaaccccccccaaaaaaaaabbbbbbccbbbaaaaaabccccccaaaacaaacccccccccccb\n", "ccccccccccccccccccccccccccccccccaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccccccc\n", "aaaaabbbbbaaaaabbbbaaabbbbbbbaaabbbbbabbbbbbbaabbbbbbbbbbbbaaaaabbbbbbbbbbbbbbbb...
2,100
1,750
2
7
931_A. Friends Meeting
Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the f...
{ "input": [ "3\n4\n", "5\n10\n", "101\n99\n" ], "output": [ "1", "9", "2" ] }
{ "input": [ "188\n762\n", "352\n445\n", "596\n777\n", "1000\n999\n", "1000\n2\n", "773\n70\n", "1\n1000\n", "285\n153\n", "892\n520\n", "1000\n1\n", "2\n1000\n", "138\n370\n", "1\n999\n", "967\n487\n", "999\n2\n", "2\n1\n", "2\n999\n", "944\n348...
800
500
2
7
985_A. Chess Placing
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to <image>. In one step you can mov...
{ "input": [ "10\n1 2 3 4 5\n", "6\n1 2 6\n" ], "output": [ "10\n", "2\n" ] }
{ "input": [ "10\n9 8 7 6 5\n", "100\n41 13 29 11 25 15 6 23 28 50 48 17 3 9 44 24 5 19 34 22 33 32 20 16 35 37 4 10 46 2 39 40 47 49 36 42 1 30 43 21 14 7 18 45 31 8 12 26 27 38\n", "10\n10 9 8 1 5\n", "6\n3 5 6\n", "6\n1 4 5\n", "100\n84 10 26 79 58 93 67 85 7 2 99 4 47 45 75 22 32 82 65 53 ...
1,100
0
2
10
1003_D. Coins and Queries
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of...
{ "input": [ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n" ], "output": [ "1\n-1\n3\n2\n" ] }
{ "input": [ "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "3 3\n1 1 1\n1\n2\n3\n", "4 1\n2 4 16 32\n14\n" ], "output": [ "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\n-1...
1,600
0
2
11
1027_E. Inverse Coloring
You are given a square board, consisting of n rows and n columns. Each tile in it should be colored either white or black. Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well. Let's call some col...
{ "input": [ "2 3\n", "1 1\n", "49 1808\n" ], "output": [ "6\n", "0\n", "359087121\n" ] }
{ "input": [ "4 15\n", "4 2\n", "467 4\n", "4 11\n", "4 7\n", "3 1\n", "4 14\n", "500 125000\n", "3 7\n", "499 248999\n", "3 2\n", "4 9\n", "3 4\n", "2 2\n", "4 12\n", "499 249001\n", "4 5\n", "499 249000\n", "4 13\n", "3 8\n", "467 1...
2,100
0
2
13
1091_G. New Year and the Factorisation Collaboration
Integer factorisation is hard. The RSA Factoring Challenge offered $100 000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number. Since your programming language of choice might not offer facilities for handli...
{ "input": [ "21\n\n7\n\n17\n\n15\n\n17\n\n11\n\n-1\n\n15\n\n" ], "output": [ "+ 12 16\n\n- 6 10\n\n* 8 15\n\n/ 5 4\n\nsqrt 16\n\nsqrt 5\n\n^ 6 12\n\n! 2 3 7" ] }
{ "input": [ "3\n230967221047542071272908186525868331398921682471308664253988778356539397562182960087 182611080502122916090565666030857827681271950069759605734177210648361435031281924911 205581245187208120217130726679204642305706761599409643715552516156991358586934923987\n", "2\n519012199941316147938736364774...
3,200
3,750
2
11
1110_E. Magic Stones
Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to c_i. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, where 2 ≤ i ≤ n - 1), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its ...
{ "input": [ "4\n7 2 4 12\n7 15 10 12\n", "3\n4 4 4\n1 2 3\n" ], "output": [ "Yes\n", "No\n" ] }
{ "input": [ "10\n62159435 282618243 791521863 214307200 976959598 590907019 166397456 708291256 85377387 569889619\n296371399 546807332 272720717 689420404 273026579 74510326 749070707 104458586 450770185 466655231\n", "7\n12 9 8 6 9 12 84\n12 9 8 5 9 12 84\n", "2\n1 3\n2 3\n", "2\n0 0\n2000000000 20...
2,200
2,500
2
8
1140_B. Good String
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
{ "input": [ "3\n2\n&lt;&gt;\n3\n&gt;&lt;&lt;\n1\n&gt;\n" ], "output": [ "0\n0\n0\n" ] }
{ "input": [ "1\n9\n>>>>>>>><\n", "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n", "14\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n<\n", "3\n2\n<>\n3\n><<\n1\n>\n" ], "output": [ "0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0...
1,200
0
2
11
1199_E. Matching vs Independent Set
You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices. A set of edges is called a matching if no two edges share an endpoint. A set of vertices is called an independent set if no two vertices are connected with an edge. Input The first line...
{ "input": [ "4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6\n" ], "output": [ "Matching\n1 \nMatching\n1 \nIndSet\n3 4 \nMatching\n1 10 \n\n" ] }
{ "input": [ "1\n5 39\n1 2\n3 4\n5 6\n7 8\n1 9\n3 10\n3 11\n5 12\n5 13\n7 14\n7 15\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n9 4\n10 4\n11 4\n12 4\n13 4\n14 4\n15 4\n9 6\n10 6\n11 6\n12 6\n13 6\n14 6\n15 6\n9 8\n10 8\n11 8\n12 8\n13 8\n14 8\n15 8\n", "4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n...
2,000
1,250
2
10
1216_D. Swords
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swo...
{ "input": [ "2\n2 9\n", "3\n3 12 6\n", "7\n2 1000000000 4 6 8 4 2\n", "6\n13 52 0 13 26 52\n" ], "output": [ "1 7\n", "5 3\n", "2999999987 2\n", "12 13\n" ] }
{ "input": [ "10\n100000000 200000000 300000000 20 500000000 600000000 700000000 800000000 900000000 1000000000\n", "10\n1 1000000000 1 1 1 1 1 1 1 1\n", "5\n0 0 1 0 0\n", "10\n1000000000 1 2 3 4 5 6 7 8 9\n", "3\n1000000000 1 1000000000\n" ], "output": [ "244999999 20\n", "9 999999999...
1,300
0
2
8
1281_B. Azamon Web Services
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better ...
{ "input": [ "3\nAZAMON APPLE\nAZAMON AAAAAAAAAAALIBABA\nAPPLE BANANA\n" ], "output": [ "AAZMON\n---\nAEPLP\n" ] }
{ "input": [ "3\nAZAMON APPLE\nAZAMON AAAAAAAAAAALIBABA\nAPPLE BANANA\n" ], "output": [ "AAZMON\n---\nAEPLP\n" ] }
1,600
1,250
2
8
1301_B. Motarack's Birthday
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers. Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high...
{ "input": [ "7\n5\n-1 10 -1 12 -1\n5\n-1 40 35 -1 35\n6\n-1 -1 9 -1 3 -1\n2\n-1 -1\n2\n0 -1\n4\n1 -1 3 -1\n7\n1 -1 7 5 2 -1 5\n" ], "output": [ "1 11\n5 37\n3 6\n0 0\n0 0\n1 2\n3 4\n" ] }
{ "input": [ "7\n5\n-1 10 -1 12 -1\n5\n-1 40 35 -1 35\n6\n-1 -1 9 -1 3 -1\n2\n-1 -1\n2\n0 -1\n4\n1 -1 3 -1\n7\n1 -1 7 5 2 -1 5\n" ], "output": [ "1 11\n5 37\n3 6\n0 0\n0 0\n1 2\n3 4\n" ] }
1,500
1,000
2
8
1325_B. CopyCopyCopyCopyCopy
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence? A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (pos...
{ "input": [ "2\n3\n3 2 1\n6\n3 1 4 1 5 9\n" ], "output": [ "3\n5\n" ] }
{ "input": [ "1\n5\n1 3 4 5 2\n", "1\n3\n1 1 274005660\n", "4\n7\n6 6 8 8 6 6 6\n1\n2\n5\n4 5 9 8 7\n7\n1 2 7 1 6 10 2\n", "2\n3\n1 1 1\n2\n1 1\n", "2\n2\n1 1\n1\n1\n", "2\n5\n5 5 5 5 5\n3\n1 2 5\n", "2\n5\n1 2 3 4 5\n4\n2 3 4 5\n", "2\n4\n1 3 3 3\n3\n1 2 3\n" ], "output": [ "5...
800
750
2
7
1344_A. Hilbert's Hotel
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself,...
{ "input": [ "6\n1\n14\n2\n1 -1\n4\n5 5 5 1\n3\n3 2 1\n2\n0 1\n5\n-239 -2 -100 -3 -11\n" ], "output": [ "YES\nYES\nYES\nNO\nNO\nYES\n" ] }
{ "input": [ "10\n3\n-15 -33 79\n16\n45 -84 19 85 69 -64 93 -70 0 -53 2 -52 -55 66 33 -60\n2\n14 -2\n4\n-65 -76 5 25\n5\n55 -66 63 -66 -35\n5\n-87 59 78 2 -10\n1\n25\n1\n-19\n1\n-8\n12\n32 34 43 -83 57 8 -86 88 -25 96 22 -44\n", "10\n1\n1000000000\n1\n-1000000000\n2\n1000000000 0\n2\n0 1000000000\n2\n10000000...
1,600
500
2
7
1366_A. Shovels and Swords
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick. Each tool can be sold for exactly one emerald. How many...
{ "input": [ "4\n4 4\n1000000000 0\n7 15\n8 7\n" ], "output": [ "2\n0\n7\n5\n" ] }
{ "input": [ "1\n656 656\n", "1\n666 666\n", "2\n7 4\n1 5\n", "1\n33993 5\n", "1\n1656 5\n", "1\n1319 1777\n", "1\n667 666\n" ], "output": [ "437\n", "444\n", "3\n1\n", "5\n", "5\n", "1032\n", "444\n" ] }
1,100
0
2
7
1408_A. Circle Coloring
You are given three sequences: a_1, a_2, …, a_n; b_1, b_2, …, b_n; c_1, c_2, …, c_n. For each i, a_i ≠ b_i, a_i ≠ c_i, b_i ≠ c_i. Find a sequence p_1, p_2, …, p_n, that satisfy the following conditions: * p_i ∈ \\{a_i, b_i, c_i\} * p_i ≠ p_{(i mod n) + 1}. In other words, for each element, you need to choose ...
{ "input": [ "5\n3\n1 1 1\n2 2 2\n3 3 3\n4\n1 2 1 2\n2 1 2 1\n3 4 3 4\n7\n1 3 3 1 1 1 1\n2 4 4 3 2 2 4\n4 2 2 2 4 4 2\n3\n1 2 1\n2 3 3\n3 1 2\n10\n1 1 1 2 2 2 3 3 3 1\n2 2 2 3 3 3 1 1 1 2\n3 3 3 1 1 1 2 2 2 3\n" ], "output": [ "1 2 3\n1 2 1 2\n1 3 4 1 2 1 4\n1 2 3\n1 2 1 2 3 2 3 1 3 2\n" ] }
{ "input": [ "5\n3\n1 1 1\n2 2 2\n3 3 3\n4\n1 2 1 2\n2 1 2 1\n3 4 3 4\n7\n1 3 3 1 1 1 1\n2 4 4 3 2 2 4\n4 2 2 2 4 4 2\n3\n1 2 1\n2 3 3\n3 1 2\n10\n1 1 1 2 2 2 3 3 3 1\n2 2 2 3 3 3 1 1 1 2\n3 3 3 1 1 1 2 2 2 3\n" ], "output": [ "1 2 3\n1 2 1 2\n1 3 4 1 2 1 4\n1 2 3\n1 2 1 2 3 2 3 1 3 2\n" ] }
800
500
2
10
1428_D. Bouncing Boomerangs
To improve the boomerang throwing skills of the animals, Zookeeper has set up an n × n grid with some targets, where each row and each column has at most 2 targets each. The rows are numbered from 1 to n from top to bottom, and the columns are numbered from 1 to n from left to right. For each column, Zookeeper will t...
{ "input": [ "1\n0\n", "6\n2 0 3 0 1 1\n", "6\n3 2 2 2 1 1\n" ], "output": [ "0\n\n", "5\n6 6\n5 5\n4 3\n4 5\n6 1\n", "-1\n" ] }
{ "input": [ "6\n0 1 3 2 1 2\n", "4\n1 2 3 1\n", "4\n1 1 1 2\n", "4\n3 3 2 1\n", "4\n1 2 1 1\n", "4\n1 1 2 1\n", "1\n3\n", "6\n1 3 2 0 3 1\n", "4\n1 3 2 1\n", "4\n2 3 1 1\n", "4\n3 1 1 1\n", "4\n3 2 3 1\n", "4\n2 1 2 1\n", "6\n0 2 1 3 2 3\n", "4\n1 3 3 1\n",...
1,900
1,500
2
10
1475_D. Cleaning the Phone
Polycarp often uses his smartphone. He has already installed n applications on it. Application with number i takes up a_i units of memory. Polycarp wants to free at least m units of memory (by removing some applications). Of course, some applications are more important to Polycarp than others. He came up with the fol...
{ "input": [ "5\n5 7\n5 3 2 1 4\n2 1 1 2 1\n1 3\n2\n1\n5 10\n2 3 2 3 2\n1 2 1 2 1\n4 10\n5 1 3 4\n1 2 1 2\n4 5\n3 2 1 2\n2 1 2 1\n" ], "output": [ "\n2\n-1\n6\n4\n3\n" ] }
{ "input": [ "1\n17 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 10 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2\n" ], "output": [ "4\n" ] }
1,800
0
2
8
1500_B. Two chandeliers
Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered both chandeliers that can change its color cyclically. For example: r...
{ "input": [ "3 8 41\n1 3 2\n1 6 4 3 5 7 2 8\n", "1 2 31\n1\n1 2\n", "4 2 4\n4 2 3 1\n2 1\n" ], "output": [ "\n47\n", "\n62\n", "\n5\n" ] }
{ "input": [ "20 101 100\n1 14 20 3 19 10 12 18 4 17 13 6 8 5 2 15 7 16 9 11\n69 53 101 100 41 38 63 84 96 21 57 93 13 43 90 86 7 20 87 88 59 49 80 82 40 18 9 1 2 67 6 15 99 79 16 22 56 19 60 61 85 28 65 8 23 46 39 25 48 36 64 98 37 27 45 12 72 44 52 75 26 31 14 47 81 95 70 83 97 11 34 73 51 89 68 32 74 42 30 4 7...
2,200
750
2
10
1525_D. Armchairs
There are n armchairs, numbered from 1 to n from left to right. Some armchairs are occupied by people (at most one person per armchair), others are not. The number of occupied armchairs is not greater than n/2. For some reason, you would like to tell people to move from their armchairs to some other ones. If the i-th ...
{ "input": [ "6\n1 1 1 0 0 0\n", "5\n0 0 0 0 0\n", "7\n1 0 0 1 0 0 1\n" ], "output": [ "\n9\n", "\n0\n", "\n3\n" ] }
{ "input": [ "100\n0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 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 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0\n", "2\n1 0\n", "2\n0 0\n", "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1...
1,800
0
2
7
157_A. Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
{ "input": [ "1\n1\n", "2\n1 2\n3 4\n", "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n" ], "output": [ "0\n", "2\n", "6\n" ] }
{ "input": [ "9\n53 80 94 41 58 49 88 24 42\n85 11 32 64 40 56 63 95 73\n17 85 60 41 13 71 54 67 87\n38 14 21 81 66 59 52 33 86\n29 34 46 18 19 80 10 44 51\n4 27 65 75 77 21 15 49 50\n35 68 86 98 98 62 69 52 71\n43 28 56 91 89 21 14 57 79\n27 27 29 26 15 76 21 70 78\n", "4\n89 79 14 89\n73 24 58 89\n62 88 69 ...
800
500
2
7
178_A1. Educational Game
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc...
{ "input": [ "8\n1 2 3 4 5 6 7 8\n", "4\n1 0 1 2\n" ], "output": [ "1\n3\n6\n10\n16\n24\n40\n", "1\n1\n3\n" ] }
{ "input": [ "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 20 36 70 66 75 12 54 96\n", "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 7...
1,000
20
2
8
19_B. Checkout Assistant
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. ...
{ "input": [ "4\n2 10\n0 20\n1 5\n1 3\n", "3\n0 1\n0 10\n0 100\n" ], "output": [ "8", "111" ] }
{ "input": [ "5\n0 968804136\n0 736567537\n2 343136264\n0 259899572\n1 425744418\n", "5\n0 51690939\n0 62436494\n0 39009053\n0 70426298\n0 631569476\n", "5\n5 491957578\n4 747764103\n3 446810728\n4 896625835\n4 190748656\n", "2\n2 87623264\n0 864627704\n", "10\n3 512981548\n0 214269975\n2 60390123...
1,900
0
2
9
223_C. Partial Sums
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that ...
{ "input": [ "5 0\n3 14 15 92 6\n", "3 1\n1 2 3\n" ], "output": [ "3 14 15 92 6 ", "1 3 6 " ] }
{ "input": [ "10 1000000\n1 2 3 4 84 5 6 7 8 9\n", "1 1\n3\n", "13 666\n84 89 29 103 128 233 190 122 117 208 119 97 200\n", "1 0\n0\n", "42 42\n42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42\n", "4 1\n3 20 3 4\n", ...
1,900
1,500
2
7
248_A. Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
{ "input": [ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ], "output": [ "3\n" ] }
{ "input": [ "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0\n", "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1\n", "2\n0 0\n0 0\n", "3\n0 1\n1 1\n1 1\n", "5\n1 0\n1 0\n1 0\n0 1\n0 1\n", "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n" ], "output": [ "7\n", ...
800
500
2
8
272_B. Dima and Sequence
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: * f(0) = 0; * f(2·x) = f(x); * f(2·x + 1) = f(x) + 1. Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤...
{ "input": [ "3\n1 2 4\n", "3\n5 3 1\n" ], "output": [ "3", "1" ] }
{ "input": [ "6\n396640239 62005863 473635171 329666981 510631133 207643327\n", "4\n363034183 741262741 657823174 453546052\n", "2\n7 1\n", "1\n1\n", "2\n1 1\n", "8\n851991424 32517099 310793856 776130403 342626527 58796623 49544509 517126753\n", "8\n7 1 2 7 6 8 6 5\n", "2\n469264357 9...
1,400
1,000
2
8
319_B. Psychos in a Line
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. You're given the initial arrangeme...
{ "input": [ "6\n1 2 3 4 5 6\n", "10\n10 9 7 8 6 5 3 4 2 1\n" ], "output": [ "0\n", "2\n" ] }
{ "input": [ "2\n1 2\n", "100\n61 96 25 10 50 71 38 77 76 75 59 100 89 66 6 99 2 13 3 23 91 93 22 92 4 86 90 44 39 31 9 47 28 95 18 54 1 73 94 78 60 20 42 84 97 83 16 81 67 64 74 46 82 5 88 80 14 48 53 79 30 11 62 21 41 70 63 58 51 56 57 17 87 72 27 85 68 49 52 8 12 98 43 37 35 69 55 32 26 40 29 65 19 24 34 3...
1,900
1,000
2
8
343_B. Alternating Current
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u...
{ "input": [ "-++-\n", "++\n", "+-\n", "-\n" ], "output": [ "YES\n", "YES\n", "NO\n", "NO\n" ] }
{ "input": [ "+-+--+-+\n", "+-+--+\n", "+-+++-\n", "+++-\n", "-++-+--++--+-++-\n", "-+++--\n", "-+--+-\n", "+-++-+\n", "+++---+++---\n", "+-+-\n", "-+-+-+\n", "+++---\n", "++--++\n", "+---+\n", "--++-+\n", "-+\n", "-+-\n", "--\n", "-+++++\n",...
1,600
1,000
2
9
38_C. Blinds
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they ma...
{ "input": [ "5 3\n5 5 7 3 1\n", "4 2\n1 2 3 4\n", "2 3\n1 2\n" ], "output": [ "15\n", "8\n", "0\n" ] }
{ "input": [ "93 10\n6 47 6 89 21 91 51 72 32 48 54 89 36 12 25 38 58 62 54 16 5 52 52 85 67 33 81 72 6 42 91 16 29 78 56 62 75 48 69 12 89 34 27 15 7 80 14 57 29 6 80 46 64 94 83 96 1 42 11 41 15 26 17 36 44 11 68 73 93 45 73 35 91 14 84 48 7 8 63 84 59 68 87 26 91 10 54 41 74 71 74 62 24\n", "15 6\n1 6 6 5 ...
1,400
0
2
8
40_B. Repaintings
A chessboard n × m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly four corner-adjacent squares painted i - 1 (all such squares are repainted simultaneously). This process continues a...
{ "input": [ "1 1\n1\n", "3 3\n2\n", "3 3\n1\n" ], "output": [ "1\n", "1\n", "4\n" ] }
{ "input": [ "2016 4549\n433\n", "5000 1\n3\n", "4035 369\n26\n", "1595 2881\n710\n", "3762 3914\n1073\n", "4583 2774\n1206\n", "10 10\n1\n", "1812 240\n9\n", "991 2301\n291\n", "3154 527\n112\n", "1353 2988\n589\n", "4999 1\n7\n", "3432 4788\n1203\n", "3990 180...
1,600
1,000
2
7
438_A. The Child and Toy
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The...
{ "input": [ "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n", "4 3\n10 20 30 40\n1 4\n1 2\n2 3\n", "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n" ], "output": [ "400\n", "40\n", "160\n" ] }
{ "input": [ "1 0\n23333\n", "3 3\n1 1 1\n1 2\n2 3\n3 1\n", "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5\n", "10 30\n3 6 17 15 13 15 6 12 9 1\n3 8\n1 10\n4 7\n1 7\n3 7\n2 9\n8 10\n3 1\n3 4\n8 6\n10 3\n3 9\n2 3\n10 4\n2 10\n5 8\n9 5\n6 1\n2 1\n7 2\n7 6\n7 10\n4 8\n5 6\n3 6\n4 1\n8 9\n7 9\n4 2\n5 10\n" ], "o...
1,400
1,500
2
14
45_H. Road Problem
The Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions. The city administrat...
{ "input": [ "4 4\n1 2\n2 3\n2 4\n3 4\n", "4 3\n1 2\n2 3\n3 4\n" ], "output": [ "1\n1 3\n", "1\n1 4\n" ] }
{ "input": [ "10 9\n7 9\n8 9\n8 2\n10 6\n8 3\n9 4\n2 6\n8 5\n9 1\n", "2 1\n1 2\n", "20 20\n1 9\n11 9\n3 5\n15 13\n1 20\n11 18\n10 6\n10 8\n10 19\n12 16\n10 3\n9 18\n8 4\n15 1\n13 16\n11 2\n7 20\n10 15\n3 17\n17 14\n", "20 20\n2 17\n5 17\n14 4\n4 11\n5 1\n4 9\n18 16\n1 18\n13 6\n9 19\n2 7\n20 6\n11 12\...
2,100
0
2
8
483_B. Friends and Presents
You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the fir...
{ "input": [ "3 1 2 3\n", "1 3 2 3\n" ], "output": [ "5\n", "4\n" ] }
{ "input": [ "1 999999999 29983 29989\n", "9999999 10000 29983 29989\n", "808351 17767 433 509\n", "197 2 6361 18223\n", "5099 2895 16273 29473\n", "500000000 500000000 2 3\n", "1000 9999999 29983 29989\n", "1277613 596606 10427 29387\n", "26941620 135675892 4093 28979\n", "39 ...
1,800
1,000
2
8
507_B. Amr and Pins
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
{ "input": [ "1 1 1 4 4\n", "2 0 0 0 4\n", "4 5 6 5 6\n" ], "output": [ "3\n", "1\n", "0\n" ] }
{ "input": [ "1 100000 100000 100000 -100000\n", "46456 -2621 -23623 -98302 -99305\n", "9 20 0 40 0\n", "100000 -100000 -100000 100000 100000\n", "5 6 3 7 2\n", "97741 23818 78751 97583 26933\n", "99125 26876 -21414 14176 17443\n", "56767 -29030 51625 79823 -56297\n", "125 455 450 ...
1,400
1,000
2
9
556_C. Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
{ "input": [ "3 2\n2 1 2\n1 3\n", "7 3\n3 1 3 7\n2 2 5\n2 4 6\n" ], "output": [ "1\n", "10\n" ] }
{ "input": [ "100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\n29 12 13 14 16 17 20 22 25 26 32 45 50 53 57 67 68 70 72 73 74 77 79 81 87 90 91 ...
1,500
250
2
7
582_A. GCD Table
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula <image> Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,...
{ "input": [ "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n", "1\n42\n", "2\n1 1 1 1\n" ], "output": [ "6 4 3 2 ", "42 ", "1 1 " ] }
{ "input": [ "3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339\n", "3\n1 7 923264237 374288891 7 524125987 1 1 1\n", "5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2029 165353355 4058 2029 731472761 739767313 2029 2029 2029 585281282\n", "3...
1,700
750
2
7
604_A. Uncowed Forces
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a...
{ "input": [ "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "119 119 119 119 119\n0 0 0 0 0\n10 0\n" ], "output": [ "4900\n", "4930\n" ] }
{ "input": [ "36 102 73 101 19\n5 9 2 2 6\n4 13\n", "119 0 0 0 0\n2 0 0 0 0\n5 5\n", "0 0 119 0 0\n0 0 2 0 0\n5 5\n", "0 0 0 0 0\n10 10 10 10 10\n0 20\n", "0 46 86 72 40\n1 5 5 5 9\n6 5\n", "45 45 75 36 76\n6 2 2 0 0\n8 17\n", "119 119 119 119 119\n10 10 10 10 10\n0 20\n", "79 112 37 3...
1,000
500
2
10
626_D. Jerry's Protest
Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t...
{ "input": [ "3\n1 2 10\n", "2\n1 2\n" ], "output": [ "0.0740740741", "0.0000000000" ] }
{ "input": [ "11\n54 91 4 6 88 23 38 71 77 26 84\n", "20\n11 37 81 56 61 2 26 27 59 69 24 7 71 76 45 54 89 17 95 20\n", "13\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096\n", "11\n1 2 4 8 16 32 64 128 256 512 1024\n", "4\n2 4 1 3\n", "15\n1 2 3 4 5 10 20 40 80 160 320 640 1280 2560 5000\n", ...
1,800
1,500
2
8
650_B. Image Preview
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec...
{ "input": [ "5 2 4 13\nhhwhh\n", "3 1 100 10\nwhw\n", "5 2 4 1000\nhhwhh\n", "4 2 3 10\nwwhw\n" ], "output": [ "4", "0", "5", "2" ] }
{ "input": [ "5 2 4 12\nhhhwh\n", "2 5 5 1000000000\nwh\n", "16 1 1000 2100\nhhhwwwhhhwhhhwww\n", "1 2 3 3\nw\n", "10 2 3 32\nhhwwhwhwwh\n", "5 2 4 13\nhhhwh\n", "7 1 1000 13\nhhhhwhh\n", "100 20 100 10202\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwhwhhwhwwhhwhwhwwwhww...
1,900
1,000
2
11
675_E. Trains and Statistic
Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station. Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j....
{ "input": [ "4\n4 4 4\n", "5\n2 3 5 5\n" ], "output": [ "6\n", "17\n" ] }
{ "input": [ "7\n7 3 4 6 6 7\n", "4\n3 3 4\n", "6\n3 3 6 6 6\n", "5\n4 4 4 5\n", "9\n2 9 7 6 9 7 8 9\n", "3\n3 3\n", "8\n3 7 7 8 8 7 8\n", "10\n2 10 8 7 8 8 10 9 10\n", "2\n2\n" ], "output": [ "35\n", "8\n", "21\n", "13\n", "52\n", "3\n", "37\n", ...
2,300
2,500
2
10
765_D. Artsem and Saunders
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem. Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y. Now then, you are given a function f: [...
{ "input": [ "3\n1 2 3\n", "3\n2 2 2\n", "2\n2 1\n" ], "output": [ "3\n1 2 3 \n1 2 3 ", "1\n1 1 1 \n2 ", "-1" ] }
{ "input": [ "3\n2 2 3\n", "5\n1 4 5 4 5\n", "4\n2 2 4 4\n", "3\n1 1 2\n", "4\n1 2 1 2\n", "4\n4 2 2 4\n", "6\n1 2 3 4 5 5\n", "1\n1\n", "10\n4 4 4 4 4 4 4 4 4 4\n", "7\n7 3 3 5 5 7 7\n", "5\n1 2 3 4 3\n", "4\n1 2 1 1\n", "4\n4 2 4 4\n", "6\n1 1 1 4 4 4\n", ...
1,700
2,000
2
7
789_A. Anastasia and pebbles
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most k pebbles in each pocket at the same time....
{ "input": [ "5 4\n3 1 8 9 7\n", "3 2\n2 3 4\n" ], "output": [ "5\n", "3\n" ] }
{ "input": [ "10 1\n1 1 1 1 1 1 1 1 1 1\n", "3 57\n78 165 54\n", "1 1\n10000\n", "2 2\n2 2\n", "9 13\n132 87 200 62 168 51 185 192 118\n", "5 72\n74 10 146 189 184\n", "1 22\n1\n" ], "output": [ "5\n", "3\n", "5000\n", "1\n", "48\n", "6\n", "1\n" ] }
1,100
500
2
9
80_C. Heroes
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us...
{ "input": [ "3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n", "2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50\n" ], "output": [ "30 3\n", "1950 2\n" ] }
{ "input": [ "0\n2000000000 2000000000 1\n", "22\nCleo likes Snowy\nCleo likes Troll\nChapay likes Dracul\nSnowy likes Troll\nDracul likes Chapay\nDracul likes Snowy\nChapay likes Cleo\nSnowy likes Chapay\nDracul likes Troll\nAnka likes Hexadecimal\nSnowy likes Anka\nHexadecimal likes Cleo\nHexadecimal likes ...
1,400
500
2
7
835_A. Key races
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 millis...
{ "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" ] }
{ "input": [ "2 313 856 964 421\n", "61 464 623 89 548\n", "37 261 207 1 1000\n", "4 202 512 995 375\n", "3 3 1 6 9\n", "213 480 811 134 745\n", "1 10 2 6 10\n", "6 5 7 10 4\n", "2 7 6 2 3\n", "29 344 406 900 1\n", "1 2 8 8 5\n", "1 1 1 1 1\n", "424 41 41 909 909\n"...
800
500
2
8
87_B. Vasya and Types
Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below...
{ "input": [ "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &amp;b b\ntypeof b\ntypeof c\ntypedef &amp;&amp;b* c\ntypeof c\ntypedef &amp;b* c\ntypeof c\ntypedef &amp;void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &amp;&amp;b* c\ntypeof c\n", "5\ntypedef void* ptv\ntypeof ptv\ntypedef...
{ "input": [ "10\ntypedef errtype** ucywcaykzh\ntypeof &ucywcaykzh*********\ntypedef &&&&&&void********* ucywcaykzh\ntypeof &&&ucywcaykzh******\ntypedef &errtype vfqmtssewklwhiukrz\ntypeof &&vfqmtssewklwhiukrz********\ntypedef &errtype********** xvhxopvh\ntypeof &xvhxopvh\ntypedef &void****** kieypzcclmsvce\ntype...
1,800
1,000
2
10
903_D. Almost Difference
Let's denote a function <image> You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. Input The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a. The second line contains n integers a1, a2, ..., ...
{ "input": [ "4\n6 6 5 5\n", "5\n1 2 3 1 3\n", "4\n6 6 4 4\n" ], "output": [ "0", "4", "-8" ] }
{ "input": [ "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 ...
2,200
0
2
12
954_F. Runner's Problem
You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column. You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to: * (i - 1, j + 1) — only if i > 1, * (i, ...
{ "input": [ "2 5\n1 3 4\n2 2 3\n" ], "output": [ "2\n" ] }
{ "input": [ "50 100\n1 71 96\n2 34 52\n2 16 95\n1 54 55\n1 65 85\n1 76 92\n2 19 91\n1 26 43\n2 83 95\n2 70 88\n2 67 88\n1 9 75\n2 4 50\n2 9 11\n1 77 92\n1 28 58\n1 23 72\n1 24 75\n2 12 50\n1 54 55\n2 45 93\n1 88 93\n2 98 99\n1 40 58\n2 40 42\n1 16 61\n2 94 94\n1 82 86\n2 81 85\n2 46 46\n2 88 97\n2 6 86\n1 30 86\...
2,100
0
2
11
9_E. Interesting Graph and Apples
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f...
{ "input": [ "3 2\n1 2\n2 3\n" ], "output": [ "YES\n1\n1 3\n" ] }
{ "input": [ "42 28\n7 19\n15 24\n3 42\n18 5\n32 27\n26 20\n40 30\n35 2\n14 8\n22 10\n36 4\n16 14\n21 29\n37 40\n2 12\n30 21\n19 17\n39 34\n31 28\n20 3\n4 33\n11 42\n26 21\n9 10\n4 32\n6 1\n1 14\n14 12\n", "2 2\n1 2\n2 1\n", "3 2\n3 2\n2 1\n", "3 3\n1 3\n2 1\n3 2\n", "2 3\n1 1\n1 2\n2 1\n", "5...
2,300
0
2
7
1011_A. Stages
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are n stages available. The rock...
{ "input": [ "7 4\nproblem\n", "2 2\nab\n", "5 3\nxyabd\n", "12 1\nabaabbaaabbb\n" ], "output": [ "34\n", "-1\n", "29\n", "1\n" ] }
{ "input": [ "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "2 1\nxz\n", "2 2\nac\n", "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n", "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "12 6\nfwseyrarkwcd\n", "20 20\ntzmvhskkyugkuuxpvtbh\n", "1 ...
900
500