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
1168_B. Good Triple
Toad Rash has a binary string s. A binary string consists only of zeros and ones. Let n be the length of s. Rash needs to find the number of such pairs of integers l, r that 1 ≀ l ≀ r ≀ n and there is at least one pair of integers x, k such that 1 ≀ x, k ≀ n, l ≀ x < x + 2k ≀ r, and s_x = s_{x+k} = s_{x+2k}. Find th...
{ "input": [ "010101\n", "11001100\n" ], "output": [ "3\n", "0\n" ] }
{ "input": [ "0000\n", "00\n", "1101111000011110111111110101100111111110111100001111011010111001101100010110000001010101101010111000\n", "101\n", "100\n", "0\n", "0010\n", "000\n", "001\n", "1010\n", "1000\n", "0100101110\n", "1011\n", "0011\n", "01\n", ...
1,900
1,000
2
11
1186_E. Vus the Cossack and a Field
Vus the Cossack has a field with dimensions n Γ— m, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way: 1. He takes the current field and finds a new inverted field. In other words, the new field will contain "1" only there, where "0" was in the current field...
{ "input": [ "2 3 7\n100\n101\n4 12 5 17\n5 4 9 4\n1 4 13 18\n12 1 14 9\n3 10 7 18\n3 15 12 17\n8 6 8 12\n", "2 2 5\n10\n11\n1 1 8 8\n2 4 5 6\n1 2 7 8\n3 3 6 8\n5 6 7 8\n" ], "output": [ "6\n3\n98\n13\n22\n15\n3\n", "32\n5\n25\n14\n4\n" ] }
{ "input": [ "1 2 10\n01\n4 1 5 2\n1 2 1 4\n3 4 3 5\n1 3 1 5\n4 3 5 5\n1 1 3 3\n1 3 4 5\n3 2 3 4\n3 1 5 2\n3 1 3 5\n" ], "output": [ "2\n2\n1\n2\n3\n4\n6\n1\n3\n2\n" ] }
2,500
2,500
2
10
1205_D. Almost All
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied: For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of this path. Write all obtained sums on the blackboard. Then every integer from ...
{ "input": [ "3\n2 3\n2 1\n", "4\n2 4\n2 3\n2 1\n", "5\n1 2\n1 3\n1 4\n2 5\n" ], "output": [ "2 3 1\n2 1 2\n", "2 4 1\n2 3 2\n2 1 4\n", "1 2 1\n2 5 1\n1 3 3\n1 4 6\n" ] }
{ "input": [ "10\n8 2\n5 6\n1 8\n2 9\n1 4\n8 10\n10 5\n2 7\n2 3\n", "5\n5 1\n5 2\n5 3\n5 4\n", "30\n17 27\n30 7\n4 3\n25 12\n7 10\n1 11\n14 13\n3 23\n4 20\n7 29\n22 30\n18 24\n26 21\n3 15\n23 19\n20 26\n16 14\n25 16\n18 2\n16 6\n18 9\n26 18\n22 25\n22 5\n1 8\n28 4\n3 1\n4 22\n25 17\n", "40\n11 8\n18 3...
2,700
2,000
2
7
1223_A. CME
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero. For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not. Now, you ha...
{ "input": [ "4\n2\n5\n8\n11\n" ], "output": [ "2\n1\n0\n1\n" ] }
{ "input": [ "100\n579\n568\n595\n573\n523\n543\n509\n510\n599\n525\n570\n563\n516\n598\n501\n586\n588\n524\n546\n531\n521\n561\n532\n550\n515\n530\n557\n503\n520\n558\n575\n596\n537\n553\n600\n582\n536\n533\n583\n554\n589\n519\n538\n528\n511\n581\n507\n518\n527\n587\n577\n542\n560\n584\n576\n517\n565\n548\n549\n...
800
500
2
10
1248_D2. The World Is Just a Programming Task (Hard Version)
This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya beli...
{ "input": [ "12\n)(()(()())()\n", "10\n()()())(()\n", "6\n)))(()\n" ], "output": [ "4\n5 10\n", "5\n8 7", "0\n1 1" ] }
{ "input": [ "10\n(()(()))()\n", "10\n))))((((()\n", "50\n(((((((((((((((((((((((()))))))))))))))))))))))))(\n", "4\n))((\n", "10\n(())())()(\n", "1\n(\n", "4\n)()(\n", "100\n))()()(())()()(()()())((()()())())((())())((()))(())()((()))((())())()((()())())(()())(())(()(()))((\n", "2...
2,500
1,250
2
8
1267_B. Balls of Buma
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls). When the ball is inserted the following happens repeatedly: if so...
{ "input": [ "OOOWWW\n", "BBWBB\n", "BBWWBB\n", "BWWB\n", "WWWOOOOOOWWW\n" ], "output": [ "0\n", "0\n", "3\n", "0\n", "7\n" ] }
{ "input": [ "AA\n", "A\n", "ABCDEF\n" ], "output": [ "3\n", "0\n", "0\n" ] }
900
0
2
10
1288_D. Minimax Problem
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≀ i, j ≀ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ...
{ "input": [ "6 5\n5 0 3 1 2\n1 8 9 1 3\n1 2 3 4 5\n9 1 0 3 7\n2 3 0 6 3\n6 4 1 7 0\n" ], "output": [ "1 5\n" ] }
{ "input": [ "1 4\n93 85 23 13\n", "1 2\n0 0\n", "2 2\n1 0\n0 0\n", "3 3\n99 99 99\n100 100 100\n100 100 100\n", "1 7\n67 78 37 36 41 0 14\n", "1 1\n0\n", "3 3\n1000 1000 1000\n1 1 1\n2 2 2\n", "100 1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n...
2,000
0
2
8
1352_B. Same Parity Summands
You are given two positive integers n (1 ≀ n ≀ 10^9) and k (1 ≀ k ≀ 100). Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided by 2). In other words, find a_1, a_2, …, a_k such that all a_i>0, n = a_1 + a_2 + … + a_k and either all a_i are even or all a_i ar...
{ "input": [ "8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n" ], "output": [ "yes\n2 2 6\nyes\n1 1 1 97\nno\nno\nyes\n1 1 1 1 1 1 1 1\nno\nyes\n1 1 3\nyes\n2 2 2 2 2 2 2 2 999999984\n" ] }
{ "input": [ "8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n", "7\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n" ], "output": [ "yes\n2 2 6\nyes\n1 1 1 97\nno\nno\nyes\n1 1 1 1 1 1 1 1\nno\nyes\n1 1 3\nyes\n2 2 2 2 2 2 2 2 999999984\n", "no\nno\nno\nno\nno\nno\nno\n" ] }
1,200
0
2
12
1461_F. Mathematical Expression
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, …, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers ...
{ "input": [ "4\n2 1 1 2\n+*\n", "3\n2 2 0\n+-*\n" ], "output": [ "\n2+1+1+2\n", "\n2*2-0\n" ] }
{ "input": [ "4\n2 1 1 5\n+*-\n", "10\n1 1 0 1 1 1 1 0 0 0\n*-+\n", "10\n0 2 2 2 0 0 0 2 0 0\n-*+\n", "100\n1 2 2 2 1 1 2 2 0 2 2 0 1 0 0 0 0 1 0 0 0 1 1 2 1 1 2 2 0 2 0 2 1 1 0 2 1 0 1 2 1 2 2 1 1 1 2 1 1 1 0 1 1 0 0 2 2 1 2 2 1 0 1 0 0 2 1 2 1 1 0 2 1 0 2 0 2 1 2 0 0 0 1 1 2 0 1 0 2 2 2 1 1 1 0 2 2 ...
2,700
2,750
2
7
1487_A. Arena
n heroes fight against each other in the Arena. Initially, the i-th hero has level a_i. Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were fighting during the last minute). When two heroes of equal levels fight,...
{ "input": [ "3\n3\n3 2 2\n2\n5 5\n4\n1 3 3 7\n" ], "output": [ "\n1\n0\n3\n" ] }
{ "input": [ "2\n4\n2 2 2 3\n2\n2 2\n", "2\n4\n1 1 1 1\n3\n1 1 1\n", "2\n5\n1 2 3 5 5\n3\n5 5 5\n", "2\n4\n5 5 5 5\n2\n5 5\n", "2\n5\n1 1 1 1 1\n3\n1 1 1\n", "2\n3\n4 4 4\n2\n4 4\n", "2\n5\n9 3 3 4 100\n4\n100 100 100 100\n", "2\n5\n1 1 1 1 1\n4\n1 1 1 1\n", "2\n6\n6 6 6 6 6 6\n5\n...
800
0
2
9
1538_C. Number of Pairs
You are given an array a of n integers. Find the number of pairs (i, j) (1 ≀ i < j ≀ n) where the sum of a_i + a_j is greater than or equal to l and less than or equal to r (that is, l ≀ a_i + a_j ≀ r). For example, if n = 3, a = [5, 1, 2], l = 4 and r = 7, then two pairs are suitable: * i=1 and j=2 (4 ≀ 5 + 1 ≀ 7...
{ "input": [ "4\n3 4 7\n5 1 2\n5 5 8\n5 1 2 4 3\n4 100 1000\n1 1 1 1\n5 9 13\n2 5 5 1 1\n" ], "output": [ "\n2\n7\n0\n1\n" ] }
{ "input": [ "1\n100 120 130\n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 ...
0
0
2
11
231_E. Cactus
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle. A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≀ i < t) exists an edge between vertices vi and vi + 1, and also exists an ed...
{ "input": [ "10 11\n1 2\n2 3\n3 4\n1 4\n3 5\n5 6\n8 6\n8 7\n7 6\n7 9\n9 10\n6\n1 2\n3 5\n6 9\n9 2\n9 3\n9 10\n" ], "output": [ "2\n2\n2\n4\n4\n1\n" ] }
{ "input": [ "2 1\n1 2\n3\n1 2\n1 2\n2 1\n", "5 4\n1 3\n2 3\n4 3\n1 5\n3\n1 3\n2 4\n5 2\n", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n4\n1 2\n1 6\n6 5\n4 3\n", "40 43\n1 2\n1 3\n1 4\n4 5\n5 6\n1 7\n5 8\n7 9\n2 10\n10 11\n11 12\n2 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 2...
2,100
2,500
2
10
257_D. Sum
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≀ ai + 1 ≀ 2Β·ai for any positive integer i (i < n). Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will ge...
{ "input": [ "3\n3 3 5\n", "4\n1 2 3 5\n" ], "output": [ "++-\n", "+--+\n" ] }
{ "input": [ "42\n2 2 2 3 6 8 14 22 37 70 128 232 330 472 473 784 1481 2008 3076 4031 7504 8070 8167 11954 17832 24889 27113 41190 48727 92327 148544 186992 247329 370301 547840 621571 868209 1158781 1725242 3027208 4788036 5166155\n", "44\n4 6 8 14 28 36 43 76 78 151 184 217 228 245 469 686 932 1279 2100 237...
1,900
2,000
2
10
32_D. Constellation
A star map in Berland is a checked field n Γ— m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is t...
{ "input": [ "5 6 1\n....*.\n...***\n....*.\n..*...\n.***..\n", "7 7 2\n...*...\n.......\n...*...\n*.***.*\n...*...\n.......\n...*...\n", "5 6 2\n....*.\n...***\n....*.\n..*...\n.***..\n" ], "output": [ "2 5\n1 5\n3 5\n2 4\n2 6\n", "4 4\n1 4\n7 4\n4 1\n4 7\n", "-1\n" ] }
{ "input": [ "5 5 3\n*.***\n.****\n..***\n*.***\n.**.*\n", "5 5 1\n.....\n.....\n.*..*\n*.*..\n....*\n", "10 10 40\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n", "10 10 6\n.*..**.**.\n**********\n****.*****\n**.***....\n***.*...
1,600
2,000
2
8
351_B. Jeff and Furik
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjace...
{ "input": [ "5\n3 5 2 4 1\n", "2\n1 2\n" ], "output": [ "13", "0" ] }
{ "input": [ "2\n2 1\n", "95\n68 56 24 89 79 20 74 69 49 59 85 67 95 66 15 34 2 13 92 25 84 77 70 71 17 93 62 81 1 87 76 38 75 31 63 51 35 33 37 11 36 52 23 10 27 90 12 6 45 32 86 26 60 47 91 65 58 80 78 88 50 9 44 4 28 29 22 8 48 7 19 57 14 54 55 83 5 30 72 18 82 94 43 46 41 3 61 53 73 39 40 16 64 42 21\n", ...
1,900
1,000
2
7
420_A. Start Up
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
{ "input": [ "AHA\n", "Z\n", "XO\n" ], "output": [ "YES\n", "NO\n", "NO\n" ] }
{ "input": [ "HNCMEEMCNH\n", "AABAA\n", "NNN\n", "WWS\n", "X\n", "D\n", "AAAKTAAA\n", "QOQ\n", "G\n", "AHHA\n", "WYYW\n", "SSS\n", "JL\n", "H\n", "ZZ\n", "VO\n", "VIYMAXXAVM\n", "C\n", "AZA\n", "L\n", "BAB\n", "I\n", "OVWIHIWV...
1,000
500
2
11
490_E. Restoring Increasing Sequence
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit. Restore the the original sequence knowing digits remaining on the board. Inpu...
{ "input": [ "3\n?\n18\n1?\n", "2\n??\n?\n", "5\n12224\n12??5\n12226\n?0000\n?00000\n" ], "output": [ "YES\n1\n18\n19\n", "NO\n", "YES\n12224\n12225\n12226\n20000\n100000\n" ] }
{ "input": [ "98\n?\n?0\n2?\n6?\n6?\n69\n??\n??\n96\n1?2\n??3\n104\n??4\n1?9\n??2\n18?\n?01\n205\n?19\n244\n??8\n?5?\n?5?\n276\n??3\n???\n???\n?28\n?3?\n3??\n??8\n355\n4?0\n4??\n?10\n??1\n417\n4?9\n?3?\n4?4\n?61\n?8?\n???\n507\n?2?\n???\n??6\n5?7\n540\n5?9\n???\n?7?\n5??\n591\n?9?\n6?0\n620\n??4\n??1\n?35\n65?\n6...
2,000
2,000
2
11
514_E. Darth Vader and Tree
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to di. The Sith Lord loves counting the number of nodes in the tree that are at a distance at most...
{ "input": [ "3 3\n1 2 3\n" ], "output": [ "8" ] }
{ "input": [ "2 1\n2 2\n", "39 93585\n2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", "97 78153\n2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
2,200
2,500
2
8
569_B. Inventory
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the...
{ "input": [ "3\n1 3 2\n", "4\n2 2 3 3\n", "1\n2\n" ], "output": [ "1 3 2 \n", "2 1 3 4 \n", "1 \n" ] }
{ "input": [ "2\n1 4\n", "5\n1 1 1 1 1\n", "7\n45301 14370 61599 42695 46301 24556 26812\n", "5\n19 11 8 8 10\n", "3\n3 3 1\n", "5\n5 3 4 4 2\n", "15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2\n", "18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9\n", "111\n15 45 14 65 49 25 102 86 14 80 54 73 43 78 ...
1,200
1,000
2
10
631_D. Messenger
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature ...
{ "input": [ "6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a\n", "5 5\n1-h 1-e 1-l 1-l 1-o\n1-w 1-o 1-r 1-l 1-d\n", "5 3\n3-a 2-b 4-c 3-a 2-c\n2-a 2-b 1-c\n" ], "output": [ "6\n", "0\n", "1\n" ] }
{ "input": [ "9 3\n1-h 1-e 2-l 1-o 1-w 1-o 1-r 1-l 1-d\n2-l 1-o 1-w\n", "9 2\n1-a 2-b 1-o 1-k 1-l 1-m 1-a 3-b 3-z\n1-a 2-b\n", "2 2\n1-a 1-b\n2-a 1-b\n", "10 3\n1-b 1-a 2-b 1-a 1-b 1-a 4-b 1-a 1-a 2-b\n1-b 1-a 1-b\n", "5 2\n7-a 6-b 6-a 5-b 2-b\n6-a 7-b\n", "1 1\n6543-o\n34-o\n", "15 7\n1-b...
2,100
2,000
2
8
660_B. Seating On Bus
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n. Consider that m (m ≀ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order...
{ "input": [ "2 7\n", "9 36\n" ], "output": [ "5 1 6 2 7 3 4\n", "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18\n" ] }
{ "input": [ "100 199\n", "10 10\n", "10 39\n", "1 1\n", "100 1\n", "100 200\n", "77 13\n", "100 103\n", "10 40\n", "3 9\n", "100 399\n", "1 4\n", "77 280\n", "77 1\n", "100 13\n", "10 1\n", "100 201\n", "100 400\n", "100 77\n", "77 53\n"...
1,000
0
2
9
74_C. Chessboard Billiard
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving. More formally, first one of four diagonal directions is chosen and the billiard ball moves ...
{ "input": [ "3 4\n", "3 3\n" ], "output": [ "2\n", "3\n" ] }
{ "input": [ "8 50\n", "302237 618749\n", "999999 1000000\n", "893011 315181\n", "4449 1336\n", "871866 348747\n", "999 999\n", "2311 7771\n", "429181 515017\n", "21 15\n", "201439 635463\n", "977965 896468\n", "1000000 1000000\n", "384 187\n", "720 972\n", ...
2,100
1,500
2
8
773_B. Dynamic Problem Scoring
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends...
{ "input": [ "4\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\n117 65 -1 -1 -1\n", "5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62\n", "2\n5 15 40 70 115\n50 45 40 30 15\n", "3\n55 80 10 -1 -1\n15 -1 79 60 -1\n42 -1 13 -1 -1\n" ], "output": [ "-1\n", ...
{ "input": [ "2\n33 15 51 7 101\n41 80 40 13 46\n", "3\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62\n", "9\n57 52 60 56 91\n32 40 107 89 36\n80 0 45 92 119\n62 9 107 24 61\n43 28 4 26 113\n31 91 86 13 95\n4 2 88 38 68\n83 35 57 101 28\n12 40 37 56 73\n", "26\n3 -1 71 -1 42\n85 72 48 38 -1\n-1 -1 6...
2,000
1,000
2
7
798_A. Mike and palindrome
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforc...
{ "input": [ "abbcca\n", "abcda\n", "abccaa\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "abcdmnp\n", "ucnolsloncw\n", "acbb\n", "typayzzyapyt\n", "abcde\n", "eusneioiensue\n", "ecabd\n", "afghqwe\n", "abcdabcde\n", "guayhmg\n", "ww\n", "abcb\n", "lkvhhvkl\n", "abbcs\n", "cbacb\n", "galjjtyw\n", "czhfc\n", "aanbb\n", ...
1,000
500
2
9
818_C. Sofa Thief
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ...
{ "input": [ "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n", "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n", "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n" ], "output": [ "1\n", "-1\n", "2\n" ] }
{ "input": [ "2\n5 7\n2 7 1 7\n2 4 3 4\n0 0 0 1\n", "3\n7 3\n2 3 3 3\n5 1 6 1\n7 2 7 1\n0 2 2 0\n", "2\n6 4\n6 4 5 4\n4 3 4 2\n1 0 1 0\n", "1\n3 3\n2 3 3 3\n0 0 0 0\n", "3\n6 3\n2 2 2 3\n3 3 4 3\n4 2 4 1\n1 1 1 0\n", "1\n1 6\n1 6 1 5\n0 0 0 0\n", "2\n5 4\n4 4 4 3\n4 2 5 2\n0 0 0 1\n", ...
2,000
0
2
8
864_B. Polycarp and Letters
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; ...
{ "input": [ "11\naaaaBaabAbA\n", "3\nABC\n", "12\nzACaAbbaazzC\n" ], "output": [ "2\n", "0\n", "3\n" ] }
{ "input": [ "100\nchMRWwymTDuZDZuSTvUmmuxvSscnTasyjlwwodhzcoifeahnbmcifyeobbydwparebduoLDCgHlOsPtVRbYGGQXfnkdvrWKIwCRl\n", "200\neLCCuYMPPwQoNlCpPOtKWJaQJmWfHeZCKiMSpILHSKjFOYGpRMzMCfMXdDuQdBGNsCNrHIVJzEFfBZcNMwNcFjOFVJvEtUQmLbFNKVHgNDyFkFVQhUTUQDgXhMjJZgFSSiHhMKuTgZQYJqAqKBpHoHddddddddddddddddXSSYNKNnRrKuOj...
1,000
1,000
2
7
88_A. Chord
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft...
{ "input": [ "A B H\n", "C E G\n", "C# B F\n" ], "output": [ "strange\n", "major\n", "minor\n" ] }
{ "input": [ "E G# C\n", "D# C G\n", "F# H C\n", "C C# D\n", "D B E\n", "F# H D\n", "C F A\n", "D B B\n", "A F F#\n", "A F D\n", "G# G# A\n", "A H B\n", "E A C#\n", "A B C\n", "F E A\n", "A D F\n", "C G D#\n", "D# A E\n", "G F# A\n", "B E...
1,200
500
2
10
912_D. Fishes
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n Γ— m, divided into cells of size 1 Γ— 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!). The gift bundle also includes a square scoop of size r Γ— r, designed for fishing....
{ "input": [ "12 17 9 40\n", "3 3 2 3\n" ], "output": [ "32.8333333333", "2.0000000000" ] }
{ "input": [ "20 78 8 997\n", "88888 99999 77777 1\n", "9199 8137 4561 82660\n", "100000 100000 1000 100000\n", "20 59 2 88\n", "2 20 1 14\n", "1 1 1 1\n", "90706 97197 90706 96593\n", "51133 7737 2779 83291\n", "90755 85790 85790 98432\n", "6439 5463 3240 91287\n", "89...
2,100
2,000
2
10
934_D. A Determined Cleanup
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients stric...
{ "input": [ "46 2\n", "2018 214\n" ], "output": [ "7\n 0 1 0 ...
{ "input": [ "9 3\n", "3 2\n", "1000000000000000000 2000\n", "10 3\n", "20180214 5\n", "998244353998244353 2000\n", "8 3\n", "1562 862\n", "7 2\n", "5 3\n", "6 3\n", "1000000000000000000 2\n", "250 1958\n", "7 3\n", "1314 520\n", "314159265358979323 846\...
2,000
750
2
9
988_C. Equal Sums
You are given k sequences of integers. The length of the i-th sequence equals to n_i. You have to choose exactly two sequences i and j (i β‰  j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the...
{ "input": [ "2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n", "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n", "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n" ], "output": [ "YES\n1 4\n2 1\n", "YES\n2 5\n4 1\n", "NO\n" ] }
{ "input": [ "2\n2\n0 -10000\n2\n10000 0\n", "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n", "2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n" ], "output": [ "YES\n1 2\n2 1\n", "YES\n2 5\n4 1\n", "YES\n1 4\n2 1\n" ] }
1,400
0
2
11
1077_E. Thematic Contests
Polycarp has prepared n competitive programming problems. The topic of the i-th problem is a_i, and some problems' topics may coincide. Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and all contests should have pairwise distinct topics. He may not use all the ...
{ "input": [ "10\n6 6 6 3 6 1000000000 3 3 6 6\n", "3\n1337 1337 1337\n", "18\n2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10\n" ], "output": [ "9", "3", "14" ] }
{ "input": [ "55\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3\n", "3\n1 2 3\n", "2\n1 1\n", "1\n1000000000\n" ], "output": [ "49", "1", "2", "1" ] }
1,800
0
2
11
1119_E. Pavel and Triangles
Pavel has several sticks with lengths equal to powers of two. He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be ...
{ "input": [ "5\n1 2 2 2 2\n", "3\n1 1 1\n", "3\n3 3 3\n" ], "output": [ "3", "0", "3" ] }
{ "input": [ "1\n963837006\n", "57\n28 57 82 64 59 54 23 13 19 67 77 46 100 73 59 21 72 81 53 73 92 86 14 100 9 17 77 96 46 41 24 29 60 100 89 47 8 25 24 64 3 32 14 53 80 70 87 1 99 77 41 60 8 95 2 1 78\n", "5\n1 3 3 5 3\n", "3\n1 2 2\n", "100\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,900
2,500
2
8
1146_B. Hate "A"
Bob has a string s consisting of lowercase English letters. He defines s' to be the string after removing all "a" characters from s (keeping all other characters in the same order). He then generates a new string t by concatenating s and s'. In other words, t=s+s' (look at notes for an example). You are given a string...
{ "input": [ "ababacacbbcc\n", "aacaababc\n", "baba\n", "aaaaa\n" ], "output": [ "ababacac", ":(", ":(", "aaaaa" ] }
{ "input": [ "abbbb\n", "aeaaaaravazyzaadwaarzajaaawvcakaanbparauaoaaamsmjaaaayaylhaaaxegasgaaaipaakalaspkbaaaaazfacaaafzypraervzyzdwrzjwvcknbpruomsmjyylhxegsgipklspkbzfcfzypr\n", "aaautkayaeaaatyogasaavnkkoaaaaoaaoipvaaaafamaajaaajmadagaaxaapoaaaiadvyvtpagbnacadtbamahwsaraaaaaaxautkyetyogsvnkkoooipvfmjjm...
1,100
1,000
2
8
1167_B. Lost Numbers
This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You m...
{ "input": [ "16\n64\n345\n672" ], "output": [ "? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 8...
{ "input": [ "16 8 4 15 23 42\n", "15 42 16 4 8 23\n", "15 23 42 16 8 4\n", "ADAPTIVE 16379\n", "23 16 42 8 4 15\n", "ADAPTIVE 16381\n", "ADAPTIVE 2\n", "42 23 8 15 16 4\n", "15 23 8 4 16 42\n", "15 23 42 16 4 8\n", "23 42 4 16 8 15\n", "ADAPTIVE 1\n", "ADAPTIVE 389...
1,400
0
2
11
1185_E. Polycarp and Snakes
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size n Γ— m (where n is the number of rows, m is the number of columns) and starts to draw snakes in cells. Polycarp draws snakes with lowercase Latin letters. ...
{ "input": [ "3\n3 3\n...\n...\n...\n4 4\n..c.\nadda\nbbcb\n....\n3 5\n..b..\naaaaa\n..b..\n", "2\n3 3\n...\n.a.\n...\n2 2\nbb\ncc\n", "1\n5 6\n...a..\n..bbb.\n...a..\n.cccc.\n...a..\n" ], "output": [ "YES\n0\nYES\n4\n2 1 2 4\n3 1 3 4\n1 3 3 3\n2 2 2 3\nNO\n", "YES\n1\n2 2 2 2\nYES\n3\n1 1 1 2...
{ "input": [ "2\n1 1\na\n1 1\nz\n" ], "output": [ "YES\n1\n1 1 1 1\nYES\n26\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 ...
2,000
2,250
2
9
1204_C. Anna, Svyatoslav and Maps
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given by a sequence p_1, p_2, …, p_m of m vertexes; for each 1 ≀ i < m there is an arc from p_i to p_{i+1}. Define the sequence v_1, v_2, …, v...
{ "input": [ "3\n011\n101\n110\n7\n1 2 3 1 3 2 1\n", "4\n0110\n0001\n0001\n1000\n3\n1 2 4\n", "4\n0110\n0010\n1001\n1000\n20\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n", "4\n0110\n0010\n0001\n1000\n4\n1 2 3 4\n" ], "output": [ "7\n1 2 3 1 3 2 1 \n", "2\n1 4 \n", "11\n1 2 4 2 4 2 4 2 4 ...
{ "input": [ "16\n0100001011000101\n0001010100010111\n1100010111110111\n0000010011111101\n1001010110011110\n0011001110110110\n0011110011111010\n0010100011100101\n1001010101100100\n1001110110111111\n1000010011001010\n1010001011000001\n1100011010000111\n1111110110110001\n0101111100000000\n0001100100110100\n20\n3 16...
1,700
1,250
2
10
1287_D. Numbers on Tree
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer a_i written on it. For each vertex i, Evlampiy calculated c_i β€” the number of vertices j in the subtree of vertex i, such that a_j < a_i. <image>Illustration for the second example, the first...
{ "input": [ "3\n2 0\n0 2\n2 0\n", "5\n0 1\n1 3\n2 1\n3 0\n2 0\n" ], "output": [ "YES\n1 3 2 \n", "YES\n2 5 3 1 4 \n" ] }
{ "input": [ "3\n2 0\n0 2\n2 0\n", "3\n2 1\n0 0\n1 1\n", "2\n0 1\n1 0\n", "3\n3 1\n1 0\n0 1\n", "2\n2 1\n0 1\n", "1\n0 0\n", "3\n0 0\n1 0\n1 0\n", "3\n0 1\n3 0\n1 0\n", "5\n0 1\n1 3\n2 1\n3 0\n2 0\n", "2\n2 0\n0 0\n" ], "output": [ "YES\n1 3 2 \n", "NO\n", "YES\...
1,800
1,000
2
10
1307_D. Cow and Fields
Bessie is out grazing on the farm, which consists of n fields connected by m bidirectional roads. She is currently at field 1, and will return to her home at field n at the end of the day. The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has k special fields and he h...
{ "input": [ "5 4 2\n2 4\n1 2\n2 3\n3 4\n4 5\n", "5 5 3\n1 3 5\n1 2\n2 3\n3 4\n3 5\n2 4\n" ], "output": [ "3\n", "3\n" ] }
{ "input": [ "5 4 2\n3 4\n2 1\n2 3\n1 4\n4 5\n", "4 3 2\n3 4\n1 2\n2 3\n1 4\n", "16 15 3\n12 14 16\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n1 13\n13 14\n14 15\n15 16\n", "10 10 2\n3 6\n1 2\n2 3\n3 4\n4 10\n1 5\n5 6\n6 7\n7 8\n8 9\n9 10\n", "6 5 3\n1 4 6\n1 5\n5 6\n1 2\n2 3\n3 4...
1,900
2,000
2
10
1350_D. Orac and Medians
Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}. In this problem, for the integer multiset s, the median of s is equal to th...
{ "input": [ "5\n5 3\n1 5 2 6 1\n1 6\n6\n3 2\n1 2 3\n4 3\n3 1 2 3\n10 3\n1 2 3 4 5 6 7 8 9 10\n" ], "output": [ "no\nyes\nyes\nno\nyes\n" ] }
{ "input": [ "1\n7 2\n5 5 1 1 2 1 1\n", "1\n26 2\n2 1 1 1 3 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1\n", "1\n17 15\n3 5 4 6 10 2 16 10 18 8 5 1 2 7 15 14 8\n", "1\n10 10\n10 1 1 1 1 1 1 11 1 11\n", "1\n7 3\n3 1 1 1 4 1 4\n", "1\n7 2\n3 3 1 1 2 1 1\n", "1\n9 5\n6 4 6 1 1 1 1 1 5\n", "...
2,000
1,250
2
9
1393_C. Pinkie Pie Eats Patty-cakes
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling. Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat t...
{ "input": [ "4\n7\n1 7 1 6 4 4 6\n8\n1 1 4 6 4 6 4 7\n3\n3 3 3\n6\n2 5 2 3 1 4\n" ], "output": [ "3\n2\n0\n4\n" ] }
{ "input": [ "1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n" ], "output": [ "4\n" ] }
1,700
1,500
2
8
1418_B. Negative Prefixes
You are given an array a, consisting of n integers. Each position i (1 ≀ i ≀ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new ones or rearra...
{ "input": [ "5\n3\n1 3 2\n0 0 0\n4\n2 -3 4 -1\n1 1 1 1\n7\n-8 4 -2 -6 4 7 1\n1 0 0 0 1 1 0\n5\n0 1 -4 6 3\n0 0 0 1 1\n6\n-1 7 10 4 -8 -1\n1 0 0 0 0 1\n" ], "output": [ "3 2 1 \n2 -3 4 -1 \n-8 4 1 -2 4 7 -6 \n1 0 -4 6 3 \n-1 10 7 4 -8 -1 \n" ] }
{ "input": [ "5\n3\n1 3 2\n0 0 0\n4\n2 -3 4 -1\n1 1 1 1\n7\n-8 4 -2 -6 4 7 1\n1 0 0 0 1 1 0\n5\n0 1 -4 6 3\n0 0 0 1 1\n6\n-1 7 10 4 -8 -1\n1 0 0 0 0 1\n" ], "output": [ "3 2 1 \n2 -3 4 -1 \n-8 4 1 -2 4 7 -6 \n1 0 -4 6 3 \n-1 10 7 4 -8 -1 \n" ] }
1,300
0
2
7
1436_A. Reorder
For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that βˆ‘_{i=1}^{n}{βˆ‘_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for exampl...
{ "input": [ "2\n3 8\n2 5 1\n4 4\n0 1 2 3\n" ], "output": [ "YES\nNO\n" ] }
{ "input": [ "1\n3 6\n4 4 4\n", "1\n3 2\n1 2 3\n", "1\n3 16\n2 5 1\n", "1\n1 2\n4\n", "1\n4 8\n4 4 4 4\n", "1\n3 2\n2 2 2\n", "1\n2 8\n8 8\n", "1\n1 0\n5\n", "1\n1 0\n1\n", "2\n3 18\n3 3 3\n4 26\n10 10 2 4\n", "1\n3 8\n2 4 10\n", "2\n4 5\n5 5 5 5\n6 3\n3 3 3 3 3 3\n", ...
800
500
2
8
1536_B. Prinzessin der Verurteilung
I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an β€” Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me. It is no surprise Fischl speaks with a strange choice of words. However, this time, not even Oz, her raven friend, can interpret h...
{ "input": [ "3\n28\nqaabzwsxedcrfvtgbyhnujmiklop\n13\ncleanairactbd\n10\naannttoonn\n" ], "output": [ "\nac\nf\nb\n" ] }
{ "input": [ "1\n41\nsugimotomikasaackermannelectromasterjsoap\n", "1\n25\nabcdefghijklmnopqrstuvwxy\n", "4\n5\noisha\n10\niloveoisha\n16\nshahromloveoisha\n16\noishaloveshahrom\n" ], "output": [ "b\n", "z\n", "b\nb\nb\nb\n" ] }
1,200
1,000
2
7
163_A. Substring and Subsequence
One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the s...
{ "input": [ "codeforces\nforceofcode\n", "aa\naa\n" ], "output": [ "60\n", "5\n" ] }
{ "input": [ "bbabb\nbababbbbab\n", "ab\nbbbba\n", "xzzxxxzxzzzxzzzxxzzxzzxzxzxxzxxzxxzxzzxxzxxzxxxzxzxzxxzzxxxxzxzzzxxxzxzxxxzzxxzxxzxxzzxxzxxzxzxzzzxzzzzxzxxzzxzxxzxxzzxzxzx\nzzx\n", "a\nb\n", "zxzxzxzxzxzxzx\nd\n", "pfdempfohomnpgbeegikfmflnalbbajpnpgeacaicoehopgnabnklheepnlnflohjegcciflmfj...
1,700
1,000
2
8
183_B. Zoo
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates....
{ "input": [ "5 5\n2 1\n4 1\n3 2\n4 3\n4 4\n" ], "output": [ "11\n" ] }
{ "input": [ "1000000 2\n194305 1024\n4388610 1023\n", "3 3\n227495634 254204506\n454991267 508409012\n217792637 799841973\n", "1000000 2\n136395332 110293751\n568110113 459392523\n", "3 3\n1 1\n2 10\n3 100\n", "1000000 2\n881456674 979172365\n878302062 975668042\n", "3 3\n333333334 1\n6666666...
1,700
1,000
2
9
230_C. Shifts
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right. To cyclically shift a table row one cell to the right means to move the valu...
{ "input": [ "3 6\n101010\n000100\n100000\n", "2 3\n111\n000\n" ], "output": [ "3", "-1" ] }
{ "input": [ "6 6\n111000\n011100\n001110\n000111\n100011\n110001\n", "3 3\n001\n010\n100\n", "2 9\n101010101\n010101010\n", "10 10\n0001001101\n0010001010\n1100000000\n0110110110\n1011011010\n1001001001\n0100010001\n0110000100\n0000100000\n1000010000\n", "5 5\n10001\n00100\n01000\n01001\n11111\n"...
1,500
500
2
8
256_B. Mr. Bender and Square
Mr. Bender has a digital table of size n Γ— n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns β€” numbered from left to right f...
{ "input": [ "9 3 8 10\n", "6 4 3 1\n" ], "output": [ "2\n", "0\n" ] }
{ "input": [ "1000000000 44 30 891773002\n", "1000000000 999999938 999999936 384381709\n", "1000000000 999999946 60 715189365\n", "1000000000 999999946 999999941 715189365\n", "1000000 951981 612086 60277\n", "1000000000 6 999999904 272656295\n", "1000000000 85 999999940 857945620\n", ...
1,800
2,000
2
8
27_B. Tournament
The tournament Β«Sleepyhead-2010Β» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. nΒ·(n - 1) / 2 games were played during the tournament, and each participant had a m...
{ "input": [ "4\n4 2\n4 1\n2 3\n2 1\n3 1\n" ], "output": [ "4 3\n" ] }
{ "input": [ "4\n3 1\n4 1\n4 2\n3 2\n3 4\n", "5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2\n", "6\n3 1\n5 4\n2 1\n6 2\n5 2\n3 6\n6 4\n3 2\n3 4\n6 1\n6 5\n5 1\n2 4\n3 5\n", "5\n4 5\n1 5\n4 3\n2 5\n2 1\n2 4\n3 5\n2 3\n1 3\n", "5\n2 1\n4 1\n5 1\n4 5\n3 5\n2 3\n3 1\n2 5\n2 4\n", "6\n5 3\n6 5\n3 ...
1,300
1,000
2
7
302_A. Eugeny and Array
Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries: * Query number i is given as a pair of integers li, ri (1 ≀ li ≀ ri ≀ n). * The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum ali + a...
{ "input": [ "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n", "2 3\n1 -1\n1 1\n1 2\n2 2\n" ], "output": [ "0\n1\n0\n1\n0\n", "0\n1\n0\n" ] }
{ "input": [ "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4\n", "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7\n", "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5\n", "3 3\n1 1 1\n2 2\n1 1\n1 1\n", "1 1\n-1\n1 1\n", "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n...
800
500
2
11
34_E. Collisions
On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored. The balls collide elastically, i.e. if two balls weighing m1 and m2 and with speeds v1 and v2 collide, their new speeds...
{ "input": [ "2 9\n3 4 5\n0 7 8\n", "3 10\n1 2 3\n4 -5 6\n7 -8 9\n" ], "output": [ "68.538461538\n44.538461538\n", "-93.666666667\n-74.666666667\n-15.666666667\n" ] }
{ "input": [ "10 100\n0 100 1\n1 -100 1\n2 100 1\n3 -100 1\n4 100 1\n5 -100 1\n6 100 1\n7 -100 1\n8 100 1\n9 -100 1\n", "10 48\n99 87 97\n95 94 100\n92 100 93\n98 98 92\n100 99 96\n69 76 97\n96 97 100\n94 100 96\n89 99 95\n97 87 100\n", "2 1\n-61 -27 64\n1 22 92\n", "4 2\n0 1 1\n2 -1 1\n3 1 1\n4 -1 1\...
2,000
2,500
2
7
374_A. Inna and Pink Pony
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n Γ— m chessboard, a very tasty candy and two numbers a and b. Dima put the chessboard in front of Inna and placed the candy in position (i, j) on the board. The boy said h...
{ "input": [ "5 5 2 3 1 1\n", "5 7 1 3 2 2\n" ], "output": [ "Poor Inna and pony!\n", "2\n" ] }
{ "input": [ "2 6 1 2 2 2\n", "100 100 50 50 500 500\n", "1000000 2 2 2 2 1\n", "33999 99333 33000 99000 3 9\n", "5 1 3 1 1 1\n", "6 1 5 1 2 2\n", "100 100 70 5 1 1\n", "1 100 1 50 1 50\n", "11 11 3 3 4 4\n", "5 8 4 2 1 2\n", "1000000 1000000 1000000 1000000 1000000 1000000...
2,000
500
2
8
445_B. DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pour...
{ "input": [ "3 2\n1 2\n2 3\n", "2 1\n1 2\n", "1 0\n" ], "output": [ "4\n", "2\n", "1\n" ] }
{ "input": [ "26 17\n1 2\n2 3\n1 6\n6 7\n7 8\n2 9\n4 10\n3 11\n11 12\n9 13\n6 14\n2 16\n5 18\n6 19\n11 22\n15 24\n6 26\n", "8 5\n1 2\n1 3\n1 4\n5 6\n7 8\n", "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7\n", "40 28\n1 2\n2 4\n3 5\n1 7\n1 8\n7 9\n6 10\n7 11\n2 12\n9 13\n11 15\n12 16\n1 18\n...
1,400
1,000
2
9
467_C. George and Job
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work. Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2...
{ "input": [ "5 2 1\n1 2 3 4 5\n", "7 1 3\n2 10 7 18 5 33 0\n" ], "output": [ "9", "61" ] }
{ "input": [ "10 1 10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "23 2 4\n965481468 524609549 327408602 598336282 745920261 141281382 661619186 475657944 798069657 19918618 428716536 140019227 432712846 201739661 639584480 639986280 12511...
1,700
1,500
2
13
513_G1. Inversions problem
You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≀ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the expected value of the number of inversions in the resulting permutation. In...
{ "input": [ "3 1\n1 2 3\n", "3 4\n1 3 2\n" ], "output": [ "0.83333333333333\n", "1.45833333333333\n" ] }
{ "input": [ "29 121\n1 25 15 18 29 26 3 9 16 8 7 5 12 11 24 28 10 13 27 14 21 17 22 20 6 23 19 4 2\n", "1 1\n1\n", "29 124\n25 17 19 13 18 10 4 15 27 26 23 12 3 7 29 9 22 6 5 20 24 28 11 14 8 16 2 1 21\n", "30 187\n4 18 2 8 5 9 15 14 25 16 30 12 7 24 13 27 29 26 6 3 20 1 10 28 17 21 22 19 23 11\n", ...
1,800
3
2
10
53_D. Physical Education
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line...
{ "input": [ "2\n1 100500\n1 100500\n", "4\n1 2 3 2\n3 2 1 2\n" ], "output": [ "0\n", "3\n2 3\n1 2\n2 3\n" ] }
{ "input": [ "1\n800950546\n800950546\n", "1\n873725529\n873725529\n", "2\n344379439 344379439\n344379439 344379439\n", "5\n470138369 747764103 729004864 491957578 874531368\n874531368 729004864 491957578 747764103 470138369\n", "4\n681106577 681106577 675077178 675077178\n675077178 681106577 6811...
1,500
2,000
2
12
567_F. Mausoleum
King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital. The mausoleum will be constructed from 2n blocks, each of them has the shape of a cuboid. Each block has th...
{ "input": [ "3 0\n", "4 1\n3 = 6\n", "3 1\n2 &gt; 3\n" ], "output": [ "9\n", "3\n", " 9\n" ] }
{ "input": [ "1 1\n1 <= 2\n", "8 5\n2 <= 4\n5 > 10\n3 < 9\n4 = 8\n12 >= 16\n", "10 5\n17 <= 10\n16 >= 18\n9 > 18\n8 = 8\n6 >= 13\n", "1 1\n1 > 2\n", "5 8\n8 = 9\n7 >= 7\n3 <= 9\n4 > 10\n5 >= 1\n7 = 7\n2 < 6\n4 <= 7\n", "5 5\n10 <= 8\n5 >= 7\n10 < 4\n5 = 5\n10 <= 2\n", "30 50\n46 <= 27\n19 ...
2,400
2,500
2
22
630_O. Arrow
Petya has recently started working as a programmer in the IT city company that develops computer games. Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to pa...
{ "input": [ "8 8 0 2 8 3 4 5\n" ], "output": [ "8.0000000000000000000000000 11.0000000000000000000000000\n4.0000000000000000000000000 8.0000000000000000000000000\n6.0000000000000000000000000 8.0000000000000000000000000\n6.0000000000000000000000000 3.0000000000000000000000000\n10.0000000000000000000000000...
{ "input": [ "10 10 -7 0 5 8 2 11\n", "870 396 187 223 444 202 222 732\n", "10 10 -7 -7 5 8 2 11\n", "254 578 251 809 412 966 92 984\n", "767 238 263 303 155 351 21 686\n", "10 10 7 7 5 8 2 11\n", "10 10 7 -7 5 8 2 11\n", "403 24 708 984 850 765 344 865\n", "380 171 865 522 392 242...
2,000
0
2
13
659_G. Fence Divercity
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the i-th board to the left is hi. Today Vasily de...
{ "input": [ "3\n3 4 2\n", "2\n1 1\n" ], "output": [ "13", "0" ] }
{ "input": [ "10\n529280935 122195401 684409084 743180136 724768643 211207376 167236398 696535490 425348743 1\n", "5\n483078839 692549116 1 458438081 1\n", "15\n2 72 77 69 62 73 58 9 4 95 97 14 41 79 34\n", "50\n1 3083990 976356336 922018335 1 170272482 1 547248035 1 1 1 1 1 928379588 1 1 1 270052499 ...
2,300
2,500
2
10
682_D. Alyona and Strings
After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pay her attention to strings s and t, which she considered very similar. Alyona has her favourite positive integer k and because she is to...
{ "input": [ "9 12 4\nbbaaababb\nabbbabbaaaba\n", "3 2 2\nabc\nab\n" ], "output": [ "7", "2" ] }
{ "input": [ "120 362 6\ncaaccbbbabbbcbaacbaccacaaccacaaababccaccaabaccacccbbaaaaababbccbbacccaacabacbaaacabbacbabcccbccbcbbcaabaaabaabcccaabacbb\nabcbbaaccbbcabbcbbcacbabaacbaaacabcbabcabbabccbcaaacaccaaabbcbaacccccbcabacaacabbbcabaabcbbccabacbaaaacbbbbbccabccccbababcbacbbbcbbaabcaabcacbaaaaaccbaabbabacbcbbbaabb...
1,900
2,000
2
9
705_C. Thor
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
{ "input": [ "4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n", "3 4\n1 3\n1 1\n1 2\n2 3\n" ], "output": [ "1\n2\n3\n0\n1\n2\n", "1\n2\n3\n2\n" ] }
{ "input": [ "300000 1\n1 300000\n", "10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n3 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 10\n2 1\n2 10\n1 10\n1 1\n1 10\n1 6\n1 2\n1 8\n1 3\n1 4\n1 9\n1 5\n1 5\n2 2\n2 4\n1 7\n1 1\n2 4\n1 9\n1 1\n1 7\n1 8\n3 33\n1 10\n2 2\n1 3\n1 ...
1,600
500
2
7
749_A. Bachgold Problem
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divi...
{ "input": [ "6\n", "5\n" ], "output": [ "3\n2 2 2 \n", "2\n2 3\n" ] }
{ "input": [ "15326\n", "23\n", "11110\n", "99544\n", "99993\n", "99996\n", "9\n", "90672\n", "100000\n", "99995\n", "90472\n", "10\n", "8\n", "774\n", "14\n", "99999\n", "14878\n", "99998\n", "93\n", "2422\n", "7\n", "61\n", ...
800
500
2
8
817_B. Makes And The Product
After returning from the army Makes received a gift β€” an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that aiΒ·ajΒ·ak is minimum possible, are there in the...
{ "input": [ "5\n1 3 2 3 4\n", "6\n1 3 3 1 3 2\n", "4\n1 1 1 1\n" ], "output": [ "2\n", "1\n", "4\n" ] }
{ "input": [ "4\n1 1 3 3\n", "3\n5 9 5\n", "9\n10 10 4 10 7 9 6 7 3\n", "6\n2 2 2 1 2 2\n", "9\n2 2 3 3 3 3 3 3 3\n", "5\n9 10 10 3 8\n", "10\n1 2 1 2 3 2 3 2 2 2\n", "8\n3 2 2 5 2 2 1 2\n", "3\n1 3 1\n", "3\n3 1 3\n", "6\n1 2 2 2 3 3\n", "5\n3 4 4 4 5\n", "5\n1 2 3...
1,500
0
2
8
842_B. Gleb And Pizza
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust. The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β€” circle of radius r - d with center at the origin, an...
{ "input": [ "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n", "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n" ], "output": [ "0\n", "2\n" ] }
{ "input": [ "1 0\n1\n1 1 0\n", "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1\n", "5 3\n1\n500 500 10\n", "9 0\n5\n8 1 0\n8 2 0\n8 3 0\n-8 3 0\n-8 2 0\n", "10 2\n11\n1 1 0\n2 2 3\n3 3 0\n4 4 0\n5 5 0\n6 6 0\n7 7 4\n8 8 7\n9 9 3\n10 10 100\n9 0 1\n" ], "output": [ "0\n", "4\n", "0\n"...
1,100
1,000
2
8
863_B. Kayaking
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2Β·n people in the group (including Vadim), and they have exactly...
{ "input": [ "4\n1 3 4 6 3 4 100 200\n", "2\n1 2 3 4\n" ], "output": [ "5\n", "1\n" ] }
{ "input": [ "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 941 376 611 332 758 504 40 477 263 708 434 38 596 650 ...
1,500
0
2
12
888_F. Connecting Vertices
There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with e...
{ "input": [ "3\n0 0 1\n0 0 1\n1 1 0\n", "4\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 1 1 0\n", "3\n0 0 0\n0 0 1\n0 1 0\n" ], "output": [ "1\n", "12\n", "0\n" ] }
{ "input": [ "4\n0 0 1 0\n0 0 0 1\n1 0 0 0\n0 1 0 0\n", "4\n0 0 0 1\n0 0 0 0\n0 0 0 1\n1 0 1 0\n", "10\n0 0 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n1 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0...
2,500
0
2
10
911_D. Inversion Counting
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and ai < aj. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a per...
{ "input": [ "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n", "3\n1 2 3\n2\n1 2\n2 3\n" ], "output": [ "odd\nodd\nodd\neven\n", "odd\neven\n" ] }
{ "input": [ "1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "3\n2 1 3\n3\n2 3\n1 1\n1 3\n", "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5\n" ], "output": [ "even\neven\neven\neven\neven\neven\neven\neven\neven\neven\n", "even\neven\nodd\n", "odd\nodd\neven\nodd\neven\n" ...
1,800
0
2
8
933_B. A Determined Cleanup
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients stric...
{ "input": [ "46 2\n", "2018 214\n" ], "output": [ "7\n0 1 0 0 1 1 1 \n", "3\n92 205 1 \n" ] }
{ "input": [ "2 3\n", "393939393939393939 393\n", "1000000000000000000 3\n", "1000000000000000000 2\n", "7 2\n", "4 3\n", "1562 862\n", "5 3\n", "10 3\n", "2 2\n", "7 3\n", "1314 520\n", "20180214 5\n", "6666666666666666 3\n", "3 3\n", "1317 221\n", ...
2,000
750
2
8
987_B. High School: Become Human
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before. It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl...
{ "input": [ "5 8\n", "6 6\n", "10 3\n" ], "output": [ ">\n", "=\n", "<\n" ] }
{ "input": [ "15657413 15657414\n", "4 1000000000\n", "4 4\n", "27 3\n", "620537015 620537016\n", "1 100\n", "3 2\n", "3 5\n", "1000000000 1000000000\n", "5 3\n", "10 3\n", "56498103 56498102\n", "2 6\n", "17 18\n", "1 10\n", "2 3\n", "3 9\n", "4...
1,100
1,000
2
8
1019_B. The hat
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game Β«The hatΒ». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
{ "input": [ "6\n<span class=\"tex-span\"></span>\n1\n<span class=\"tex-span\"></span>\n2\n<span class=\"tex-span\"></span>\n3 \n<span class=\"tex-span\"></span>\n2\n<span class=\"tex-span\"></span>\n1\n<span class=\"tex-span\"></span>\n0", "8\n<span class=\"tex-span\"></span>\n2\n<span class=\"tex-span\"></s...
{ "input": [ "10\n1 2 3 4 5 4 3 2 1 0\n", "10\n1 2 1 0 -1 0 -1 -2 -1 0\n", "100\n-1 -2 -1 -2 -3 -2 -1 0 1 0 -1 0 1 0 1 2 1 0 1 0 1 0 1 0 -1 -2 -1 -2 -3 -4 -5 -6 -5 -6 -7 -6 -5 -4 -3 -2 -1 -2 -3 -4 -3 -4 -3 -4 -3 -2 -3 -4 -5 -6 -7 -6 -7 -6 -5 -6 -7 -6 -5 -6 -7 -6 -7 -8 -7 -6 -7 -6 -5 -6 -5 -4 -3 -4 -3 -2 -...
2,000
1,000
2
7
1042_A. Benches
There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people c...
{ "input": [ "4\n6\n1\n1\n1\n1\n", "1\n10\n5\n", "3\n6\n1\n6\n5\n", "3\n7\n1\n6\n5\n" ], "output": [ "3 7\n", "15 15\n", "6 12\n", "7 13\n" ] }
{ "input": [ "100\n66\n95\n19\n88\n15\n29\n52\n37\n75\n21\n90\n93\n75\n91\n71\n53\n55\n90\n78\n19\n63\n43\n25\n52\n10\n55\n76\n47\n42\n57\n45\n35\n53\n2\n62\n61\n99\n59\n59\n43\n45\n31\n37\n50\n68\n51\n91\n34\n48\n40\n69\n77\n33\n16\n64\n19\n82\n76\n35\n41\n41\n79\n29\n69\n100\n30\n81\n47\n55\n79\n21\n59\n3\n11\n...
1,100
500
2
10
1106_D. Lunar New Year and a Wander
Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at the node 1 and he records 1 on his notebook. He can wander from one node to another through those bidirectional edges. Whenever ...
{ "input": [ "3 2\n1 2\n1 3\n", "10 10\n1 4\n6 8\n2 5\n3 7\n9 4\n5 6\n3 4\n8 10\n8 9\n1 10\n", "5 5\n1 4\n3 4\n5 4\n3 2\n1 5\n" ], "output": [ "1 2 3 ", "1 4 3 7 9 8 6 5 2 10 ", "1 4 3 2 5 " ] }
{ "input": [ "2 1\n1 2\n", "1 1\n1 1\n" ], "output": [ "1 2 ", "1 " ] }
1,500
1,500
2
11
1133_E. K Balanced Teams
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i. You have to form k teams for yet another new programming competition. As you know, the more students are involved in competition the more probable the victory of your university is! ...
{ "input": [ "4 4\n1 10 100 1000\n", "6 1\n36 4 1 25 9 16\n", "5 2\n1 2 15 15 15\n" ], "output": [ "4\n", "2\n", "5\n" ] }
{ "input": [ "10 9\n1034 1043 4739 2959 4249 4246 582 4584 3762 4027\n", "50 1\n849 1987 4384 4180 1393 97 1596 2522 451 4037 2186 2421 633 4882 4044 225 1569 4998 4915 2296 3509 1788 4713 4774 810 4732 2031 907 514 3342 3296 1973 4858 315 3140 3651 3212 4996 1390 1323 862 872 438 1533 1378 1411 3232 1565 372...
1,800
0
2
8
1154_B. Make Them Equal
You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i. e. perform a_i := a_i - D, or * leave the value of a_i unchanged. It is...
{ "input": [ "2\n2 8\n", "4\n1 3 3 7\n", "5\n2 2 5 2 5\n", "6\n1 4 4 7 4 1\n" ], "output": [ "3\n", "-1\n", "3\n", "3\n" ] }
{ "input": [ "5\n4 2 6 6 6\n", "4\n2 4 4 4\n", "4\n4 4 4 4\n", "3\n1 3 5\n", "4\n1 2 3 6\n", "4\n2 4 6 8\n", "5\n2 4 6 8 10\n", "3\n2 3 4\n", "3\n1 7 4\n", "3\n4 3 5\n", "3\n4 6 8\n", "2\n5 3\n", "5\n1 3 2 1 4\n", "3\n1 50 99\n", "2\n1 4\n", "2\n2 1\n", ...
1,200
0
2
12
1194_F. Crossword Expert
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time witho...
{ "input": [ "3 5\n2 2 2\n", "3 5\n2 1 2\n" ], "output": [ "750000007\n", "125000003\n" ] }
{ "input": [ "20 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "20 31\n2 2 1 2 1 1 2 1 2 2 1 2 1 2 1 1 1 2 1 2\n", "20 26\n1 2 1 1 1 2 1 1 2 2 2 1 2 1 2 1 1 2 2 1\n", "20 28\n2 1 1 2 2 1 2 2 2 1 2 1 1 1 1 2 1 1 2 1\n", "5 10\n2 2 2 2 1\n", "20 25\n1 1 1 1 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 2\n", ...
2,400
0
2
8
1234_B1. Social Network (easy version)
The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0...
{ "input": [ "10 4\n2 3 3 1 1 2 1 2 3 3\n", "7 2\n1 2 3 2 1 3 2\n" ], "output": [ "3\n1 3 2\n", "2\n2 1\n" ] }
{ "input": [ "9 2\n1 2 3 4 5 6 7 8 9\n", "1 4\n1\n", "1 1\n5\n", "3 4\n1 1 2\n", "1 5\n1\n" ], "output": [ "2\n9 8\n", "1\n1\n", "1\n5\n", "2\n2 1\n", "1\n1\n" ] }
1,000
0
2
11
1276_E. Four Stones
There are four stones on an infinite line in integer coordinates a_1, a_2, a_3, a_4. The goal is to have the stones in coordinates b_1, b_2, b_3, b_4. The order of the stones does not matter, that is, a stone from any position a_i can end up in at any position b_j, provided there is a required number of stones in each ...
{ "input": [ "0 1 2 3\n3 5 6 8\n", "0 0 0 1\n0 1 0 1\n", "0 0 0 0\n1 1 1 1\n" ], "output": [ "\n3\n1 3\n2 5\n0 3\n", "-1\n", "-1\n" ] }
{ "input": [ "-1 1 2 0\n1 1 0 -2\n", "0 2 -4 3\n2 4 0 0\n", "-999999998 1 999999998 999999998\n-1 0 0 0\n", "0 0 0 1\n1000000000 1000000000 1000000000 999999999\n", "0 1 2 1000000000\n0 1 999999999 1000000000\n", "1 1 1 3\n1 1 1 3\n", "-2 0 3 4\n-2 -2 4 0\n", "0 2 900000000 900000002\n...
3,500
2,250
2
11
1296_E2. String Coloring (hard version)
This is a hard version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string s consisting of n lowercase Latin letters. You have to color all its characters the minimum numb...
{ "input": [ "8\naaabbcbb\n", "5\nabcde\n", "7\nabcdedc\n", "9\nabacbecfd\n" ], "output": [ "2\n1 1 1 1 1 1 2 2 \n", "1\n1 1 1 1 1 \n", "3\n1 1 1 1 1 2 3 \n", "2\n1 1 2 1 2 1 2 1 2 \n" ] }
{ "input": [ "200\naaaaabbaaaaabcbebebbccecccffgjklccmcmnccoccooddoqqqdddqderreerrsfffsfsfghuuhhhvhhhhvviwixixixxixijjjxjyjzzjzkkklllllmmmmmmmnnnnnnnoooooppppppppppppqqqqqrrrrrrrsssssstttuuuvvvvvvvwwwwwwxxxyyyyyyyyyzzzz\n", "200\ntoimpgygoklxroowdhpacrtrrwmkhcgcpidapeyxrjmiqgilveimnazyydvnujtqpenfkeqdbylfdino...
2,000
0
2
9
1339_C. Powered Addition
You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x-1} to each corresponding position of a. Formally, a_{i_{j}} := a_{i_{j}} + 2^{...
{ "input": [ "3\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -4\n" ], "output": [ "2\n0\n3\n" ] }
{ "input": [ "6\n3\n1000000000 0 -1000000000\n1\n6\n2\n-1000000000 1000000000\n2\n1000000000 -1000000000\n2\n1000000000 1000000000\n2\n-1000000000 -1000000000\n" ], "output": [ "31\n0\n0\n31\n0\n0\n" ] }
1,500
500
2
13
1360_G. A/B Matrix
You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each column of the matrix contains exactly b ones; * all other elements are zeros....
{ "input": [ "5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2\n" ], "output": [ "YES\n110000\n001100\n000011\nNO\nYES\n11\n11\nYES\n1100\n0011\n1100\n0011\nYES\n1\n1\n" ] }
{ "input": [ "5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2\n" ], "output": [ "YES\n110000\n001100\n000011\nNO\nYES\n11\n11\nYES\n1100\n0011\n1100\n0011\nYES\n1\n1\n" ] }
1,900
0
2
7
1381_A1. Prefix Flip (Easy Version)
This is the easy version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings a and b of length n (a binary string is a string consisting of symbols 0 and 1). In ...
{ "input": [ "5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1\n" ], "output": [ "3 1 2 1\n3 1 5 2\n0\n7 1 10 8 7 1 2 1\n1 1\n" ] }
{ "input": [ "5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1\n" ], "output": [ "3 1 2 1\n3 1 5 2\n0\n7 1 10 8 7 1 2 1\n1 1\n" ] }
1,300
500
2
7
1401_A. Distance and Axis
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k. <image> The description of the first test case. Since sometimes it's impossible to find such point ...
{ "input": [ "6\n4 0\n5 8\n0 1000000\n0 0\n1 0\n1000000 1000000\n" ], "output": [ "0\n3\n1000000\n0\n1\n0\n" ] }
{ "input": [ "1\n5 0\n", "1\n7 0\n", "1\n15 0\n", "1\n1000000 0\n", "1\n3 0\n" ], "output": [ "1\n", "1\n", "1\n", "0\n", "1\n" ] }
900
500
2
10
1445_D. Divide and Sum
You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order, and q in non-increasing order, we can denote the sorted versions by x and y, r...
{ "input": [ "5\n13 8 35 94 9284 34 54 69 123 846\n", "2\n2 1 2 1\n", "3\n2 2 2 2 2 2\n", "1\n1 4\n" ], "output": [ "2588544", "12", "0", "6" ] }
{ "input": [ "7\n2 5 6 25 22 21 7 9 7 22 25 25 22 24\n", "16\n998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244363 998244363 998244363 998244363 998244363 998244363 998244363 998244363 99824436...
1,900
1,000
2
10
146_D. Lucky Number 2
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meet...
{ "input": [ "2 2 1 1\n", "4 7 3 1\n" ], "output": [ "4774\n", "-1\n" ] }
{ "input": [ "1 10 1 2\n", "2 1 3 1\n", "4 7 2 1\n", "1 4 1 1\n", "45 65 31 32\n", "1 1000000 4 5\n", "25 94 11 12\n", "7 1000 1 2\n", "70 60 20 21\n", "69 84 25 24\n", "5 10 2 3\n", "1 2 1 1\n", "6 6 2 3\n", "2 1 2 1\n", "100 100 4 5\n", "1 10 1 1\n", ...
1,800
1,000
2
9
1546_C. AquaMoon and Strange Sort
AquaMoon has n friends. They stand in a row from left to right, and the i-th friend from the left wears a T-shirt with a number a_i written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaM...
{ "input": [ "3\n4\n4 3 2 5\n4\n3 3 2 2\n5\n1 2 3 5 4\n" ], "output": [ "YES\nYES\nNO\n" ] }
{ "input": [ "1\n64\n8 7 7 2 4 9 3 7 9 4 7 10 6 7 6 4 9 9 10 2 2 2 10 3 8 9 3 1 5 10 6 5 7 4 3 5 7 10 7 5 8 4 5 7 10 7 10 8 2 3 8 10 1 3 8 3 9 2 9 2 5 10 5 5\n", "1\n2\n4 3\n", "1\n5\n1 1 1 3 2\n", "2\n6\n3 2 3 2 3 2\n6\n1 1 4 5 1 4\n", "1\n6\n9 1 9 1 9 1\n", "1\n10\n4 1 4 1 4 1 2 1 2 2\n", ...
1,500
500
2
11
193_E. Fibonacci Number
John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when div...
{ "input": [ "13\n", "377\n" ], "output": [ "7\n", "14\n" ] }
{ "input": [ "53824509026\n", "6138242440179\n", "10\n", "9999999999945\n", "3153355924376\n", "9999999999998\n", "9999999999999\n", "9137820308201\n", "4917874132879\n", "2755560887426\n", "9\n", "1\n", "113\n", "112\n", "5\n", "9972900390626\n", "4...
2,900
2,500
2
9
266_C. Below the Diagonal
You are given a square matrix consisting of n rows and n columns. We assume that 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. Some cells (n - 1 cells in total) of the the matrix are filled with ones, the remaining cells are filled with zeros. We can a...
{ "input": [ "3\n3 1\n1 3\n", "2\n1 2\n", "3\n2 1\n3 2\n" ], "output": [ "3\n2 2 3\n1 1 3\n1 1 2\n", "2\n2 1 2\n1 1 2\n", "0\n" ] }
{ "input": [ "15\n5 12\n4 5\n1 2\n1 5\n12 11\n11 14\n15 3\n7 2\n10 6\n3 10\n1 4\n9 9\n8 13\n11 5\n", "4\n2 1\n1 4\n1 1\n", "50\n4 24\n7 26\n39 28\n3 37\n29 38\n16 17\n48 49\n27 34\n28 22\n48 47\n34 11\n11 43\n46 34\n33 41\n31 29\n50 36\n43 46\n15 34\n47 22\n36 11\n20 18\n1 39\n18 12\n17 33\n43 30\n45 33\n...
2,100
2,500
2
9
28_C. Bath Queue
There are n students living in the campus. Every morning all students wake up at the same time and go to wash. There are m rooms with wash basins. The i-th of these rooms contains ai wash basins. Every student independently select one the rooms with equal probability and goes to it. After all students selected their ro...
{ "input": [ "2 2\n1 1\n", "2 3\n1 1 1\n", "7 5\n1 1 2 3 1\n", "1 1\n2\n" ], "output": [ "1.500000000000000\n", "1.333333333333333\n", "2.502169600000002\n", "1.000000000000000\n" ] }
{ "input": [ "35 40\n12 1 4 8 1 9 1 11 1 1 8 8 16 1 6 5 3 1 6 4 6 2 4 6 2 1 1 16 2 2 3 1 1 2 2 3 8 12 1 4\n", "7 4\n1 2 3 4\n", "1 50\n9 1 1 4 1 9 7 4 3 10 1 7 4 7 2 5 13 2 3 3 2 1 2 1 1 7 7 5 2 6 1 8 2 6 2 15 2 3 1 2 4 8 6 2 6 11 1 2 1 1\n", "50 50\n50 48 38 45 50 48 38 48 49 49 50 50 49 50 38 48 45 ...
2,200
1,500
2
10
404_D. Minesweeper 1D
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 β€” the total number of bombs in adjacent squares. For example, the correct field to play looks ...
{ "input": [ "?01???\n", "1\n", "**12\n", "?\n" ], "output": [ "4\n", "0\n", "0\n", "2\n" ] }
{ "input": [ "0\n", "01\n", "1?\n", "*\n", "?01*??****\n", "0?\n", "21?20*0000?2?22??0001*?1??12?20020200?**0*12?*221*0*1200*?0*11?022*110*2*2022120*2*2100*0?0*02?012?1\n", "1*\n", "2\n", "2?\n", "2*\n", "0*\n", "?2?\n", "?2*?2*??1*2**?2*1???*2???100?????*???*?*...
1,900
2,000
2
8
454_B. Little Pony and Sort by Shift
One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: a1, a2, ..., an β†’ an, a1, a2, ..., an - 1. Help Twi...
{ "input": [ "3\n1 3 2\n", "2\n1 2\n", "2\n2 1\n" ], "output": [ "-1\n", "0\n", "1\n" ] }
{ "input": [ "6\n5 6 7 5 5 5\n", "5\n1 1 2 1 1\n", "7\n2 3 4 1 2 3 4\n", "6\n4 5 6 1 2 7\n", "5\n2 2 1 2 2\n", "6\n1 2 1 2 1 2\n", "3\n3 4 2\n", "5\n5 4 3 2 1\n", "4\n2 4 1 3\n", "4\n6 1 2 7\n", "6\n1 1 2 2 1 1\n", "4\n1 4 4 1\n", "4\n1 2 2 1\n", "2\n1 1\n", ...
1,200
1,000
2
11
476_E. Dreamoon and Strings
Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates <image> that is defined as the maximal number of non-overlapping substrings equal to p that can be found in s'. He wants to make this number as big as possible. More formally...
{ "input": [ "axbaxxb\nab\n", "aaaaa\naa\n" ], "output": [ "0 1 1 2 1 1 0 0 \n", "2 2 1 1 0 0 \n" ] }
{ "input": [ "aabb\nab\n", "a\nab\n", "a\na\n", "axxbaxxbaxxb\nab\n", "a\naa\n", "ababababababababa\naba\n", "axaxxbaxabxbaxxbxb\nab\n", "ababcc\nabc\n", "aaaaaaaaaaa\nb\n", "a\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
2,200
2,500
2
7
4_A. Watermelon
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
{ "input": [ "8\n" ], "output": [ "YES\n" ] }
{ "input": [ "3\n", "98\n", "7\n", "90\n", "67\n", "4\n", "99\n", "6\n", "1\n", "2\n", "10\n", "77\n", "100\n", "5\n", "32\n", "88\n", "9\n", "53\n", "44\n" ], "output": [ "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", ...
800
0
2
7
550_A. Two Substrings
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters. Output Print "YES" (without the quot...
{ "input": [ "ABA\n", "AXBYBXA\n", "BACFAB\n" ], "output": [ "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "BAAA\n", "BAA\n", "ABABA\n", "BABAB\n", "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC\n", "BABXXAB\n", "AAABAAACBBBC\n", "BBBB\n", "ABYFAB\n", "BAAB\n", "BBB\n", "BB\n", "BA\n", "AB\n", "Q...
1,500
1,000
2
8
577_B. Modulo Sum
You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m. Input The first line contains two numbers, n and m (1 ≀ n ≀ 106, 2 ≀ m ≀ 103) β€” the size of the original sequence and ...
{ "input": [ "4 6\n3 1 1 3\n", "1 6\n5\n", "6 6\n5 5 5 5 5 5\n", "3 5\n1 2 3\n" ], "output": [ "YES\n", "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "100 951\n950 949 949 949 949 950 950 949 949 950 950 949 949 949 496 949 950 949 950 159 950 949 949 950 950 949 950 949 949 950 949 950 949 949 950 949 950 950 950 950 949 949 949 949 949 950 950 950 950 950 950 950 949 950 949 949 950 949 950 950 949 950 950 950 949 950 949 950 950 950 950 949 949...
1,900
1,250
2
10
620_D. Professor GukiZ and Two Arrays
Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|. In one operation professor can swap some element from the array a and some element f...
{ "input": [ "5\n1 2 3 4 5\n4\n1 2 3 4\n", "5\n1 2 3 4 5\n1\n15\n", "5\n5 4 3 2 1\n4\n1 1 1 1\n" ], "output": [ "1\n1\n3 1\n", "0\n0\n", " 1\n2\n1 1\n3 2" ] }
{ "input": [ "6\n1 2 3 4 5 11\n1\n3\n", "2\n-2 -17\n2\n11 -9\n", "1\n-21\n10\n-43 6 -46 79 -21 93 -36 -38 -67 1\n", "10\n87 -92 -67 -100 -88 80 -82 -59 81 -72\n10\n-50 30 30 77 65 92 -60 -76 -29 -15\n", "1\n-42\n1\n-86\n" ], "output": [ "7\n1\n6 1\n", "5\n1\n1 1\n", "1\n1\n1 3\n", ...
2,200
0
2
9
641_C. Little Artem and Dance
Little Artem is fond of dancing. Most of all dances Artem likes rueda β€” Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together. More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a g...
{ "input": [ "2 3\n1 1\n2\n1 -2\n", "4 2\n2\n1 3\n", "6 3\n1 2\n2\n1 2\n" ], "output": [ "1 2\n", "1 4 3 2\n", "4 3 6 5 2 1\n" ] }
{ "input": [ "24 8\n1 17\n2\n1 -10\n2\n2\n2\n2\n1 19\n", "6 9\n2\n1 -2\n2\n1 -6\n1 -6\n1 4\n2\n1 -1\n2\n", "10 10\n1 2\n1 -10\n1 -5\n2\n2\n1 -4\n2\n2\n1 -10\n1 -9\n", "364 57\n1 -101\n1 110\n1 -76\n1 329\n2\n2\n2\n1 -191\n1 97\n1 189\n1 305\n1 -313\n1 312\n1 -148\n2\n1 -104\n1 85\n1 -55\n1 -79\n1 230\...
1,800
1,000
2
7
66_A. Petya and Java
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger. But h...
{ "input": [ "123456789101112131415161718192021222324\n", "127\n", "130\n" ], "output": [ "BigInteger\n", "byte\n", "short\n" ] }
{ "input": [ "7330105816139991597267787581532092408135003429259616955239761315950805521264994021242873979309182812\n", "126\n", "2147483649\n", "4596620932866717074931903995027173085744596193421095444317407919730992986418713478580824584919587030\n", "6911378\n", "9223372036854775807\n", "7...
1,300
500
2
12
690_F1. Tree of Life (easy)
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (...
{ "input": [ "4\n1 2\n1 3\n1 4\n", "5\n1 2\n2 3\n3 4\n3 5\n" ], "output": [ "3\n", "4\n" ] }
{ "input": [ "2\n1 2\n", "3\n2 1\n3 2\n", "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4\n" ], "output": [ "0\n", "1\n", "11\n" ] }
1,300
0
2
11
735_E. Ostap and Tree
Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no m...
{ "input": [ "7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n", "4 1\n1 2\n2 3\n3 4\n", "2 0\n1 2\n", "2 1\n1 2\n" ], "output": [ "91\n", "9\n", "1\n", "3\n" ] }
{ "input": [ "10 1\n6 3\n1 5\n10 7\n4 10\n2 4\n5 9\n8 1\n1 3\n7 3\n", "10 0\n9 10\n5 1\n10 5\n8 6\n8 2\n7 8\n8 1\n8 3\n4 3\n", "10 4\n4 6\n3 5\n7 3\n4 9\n10 2\n1 9\n4 8\n10 3\n8 7\n", "10 1\n6 8\n1 9\n1 5\n6 10\n3 9\n9 4\n10 9\n2 4\n7 4\n", "10 4\n9 6\n10 8\n9 2\n7 10\n3 7\n7 9\n10 4\n1 7\n9 5\n",...
2,500
2,500
2
10
780_D. Innokenty and a Football League
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters. Each club's full name consist of two wo...
{ "input": [ "3\nABC DEF\nABC EFG\nABD OOO\n", "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW\n", "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP\n", "2\nDINAMO BYTECITY\nDINAMO BITECITY\n" ], "output": [ "YES\nABD\nABE\nABO\n", "YES\nDIN\nFOO\n", "YES\nPLM\nPLS\nGOG\n", "NO\n" ...
{ "input": [ "5\nADAC BABC\nABB DCB\nABB BCDC\nDBAC BAC\nDBBC DBC\n", "5\nIAH HJIE\nIAH FJK\nIAH BIAA\nIAH AFG\nIAH DEFF\n", "3\nABC DEF\nABC EFG\nABC EEEEE\n", "4\nABA DEF\nABB DEF\nABC DEF\nABE DEF\n", "10\nEDBG IGGAC\nEDBG GIKAG\nEDBG IKGEI\nEDBG AJEG\nEDBG HAD\nEDBG ACKK\nEDBG FEDE\nEDBG DAB\n...
1,900
1,500
2
7
804_A. Find Amir
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j co...
{ "input": [ "10\n", "2\n" ], "output": [ "4\n", "0\n" ] }
{ "input": [ "60397\n", "53022\n", "32866\n", "40873\n", "100000\n", "79227\n", "31809\n", "33377\n", "17879\n", "20289\n", "1\n", "31775\n", "86539\n", "99996\n", "82801\n", "4\n", "99998\n", "4217\n", "77859\n", "99997\n", "99999\n"...
1,000
500