source
int64
2
2
difficulty
int64
7
25
name
stringlengths
9
60
description
stringlengths
164
7.12k
public_tests
dict
private_tests
dict
cf_rating
int64
0
3.5k
cf_points
float64
0
4k
2
11
1037_E. Trips
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: * ...
{ "input": [ "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n" ], "output": [ "0\n0\n3\n3\n", "0\n0\n0\n3\n3\n4\n4\n5\n", "0\n0\n0\n0\n3\n4\n4\n" ] }
{ "input": [ "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 1\n2 1\n" ], "output": [ "0\n0\n3\n3\n3\n3\n7\n7\n7\n7\n7\n11\n11\n11\n11\n15\n15\n15\n15\n16\n", "2\n" ] }
2,200
2,250
2
7
1060_A. Phone Numbers
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have n cards with digits, and you want to use them to make as many phone n...
{ "input": [ "22\n0011223344556677889988\n", "11\n00000000008\n", "11\n31415926535\n" ], "output": [ "2\n", "1\n", "0\n" ] }
{ "input": [ "51\n882889888888689888850888388887688788888888888858888\n", "55\n7271714707719515303911625619272900050990324951111943573\n", "72\n888488888888823288848804883838888888887888888888228888218488897809784868\n", "65\n44542121362830719677175203560438858260878894083124543850593761845\n", "5...
800
500
2
7
1101_A. Minimum Integer
You are given q queries in the following form: Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i]. Can you answer all the queries? Recall that a number x belongs to segment [l, r] if l ≀ x ≀ r. Input The first l...
{ "input": [ "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n" ], "output": [ "6\n4\n1\n3\n10\n" ] }
{ "input": [ "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 100000...
1,000
0
2
10
1189_D1. Add on a Tree
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al...
{ "input": [ "2\n1 2\n", "3\n1 2\n2 3\n", "5\n1 2\n1 3\n1 4\n2 5\n", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n" ], "output": [ "YES", "NO", "NO", "YES" ] }
{ "input": [ "50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2\n24 46\n2 13\n8 45\n41 3\n32 17\n4 7\n47 26\n28 8\n41 50\n34 44\n33 21\n25 5\n16 40\n3 14\n8 18\n28 11\...
1,600
250
2
10
1208_D. Restore Permutation
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4]. There is a hidden permutation of length n. ...
{ "input": [ "3\n0 0 0\n", "5\n0 1 1 1 10\n", "2\n0 1\n" ], "output": [ "3 2 1 ", "1 4 3 2 5 ", "1 2 " ] }
{ "input": [ "100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139 1249 1997 1635 1309 661 334 3307 2691 21 3 533 1697 250 ...
1,900
2,000
2
10
1227_D1. Optimal Subsequences (Easy Version)
This is the easier version of the problem. In this version 1 ≀ n, m ≀ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily...
{ "input": [ "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n" ], "output": [ "20\n10\n20\n10\n20\n10\n", "2\n3\n2\n3\n2\n3\n1\n1\n3\n" ] }
{ "input": [ "2\n1 10\n3\n2 2\n2 1\n1 1\n", "2\n3922 3922\n3\n2 2\n2 1\n1 1\n", "1\n1000000000\n1\n1 1\n", "1\n1\n3\n1 1\n1 1\n1 1\n", "5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 1\n1 1\n", "2\n392222 322\n3\n2 2\n2 1\n1 1\n" ], "output": [ "10...
1,600
500
2
11
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≀ i ≀ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
2,300
1,500
2
11
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
2,400
1,750
2
10
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of...
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", ...
1,800
0
2
12
1354_F. Summoning Minions
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other. Polycarp can summon n different minions. The initial power level of the i-th minion is a_i, and when it is summoned, all previously summoned minions' power levels are increased by b_i. The minions c...
{ "input": [ "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n" ], "output": [ "8\n2 3 -3 4 -4 1 -1 5\n3\n1 -1 2\n5\n5 4 3 2 1\n" ] }
{ "input": [ "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n" ], "output": [ "8\n2 3 -3 4 -4 1 -1 5\n3\n1 -1 2\n5\n5 4 3 2 1\n" ] }
2,500
0
2
11
1374_E1. Reading Books (easy version)
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will ...
{ "input": [ "8 4\n7 1 1\n2 1 1\n4 0 1\n8 1 1\n1 0 1\n1 1 1\n1 0 1\n3 0 0\n", "5 2\n6 0 0\n9 0 0\n1 0 1\n2 1 1\n5 1 0\n", "5 3\n3 0 0\n2 1 0\n3 1 0\n5 0 1\n3 0 1\n" ], "output": [ "18\n", "8\n", "-1\n" ] }
{ "input": [ "2 1\n7 1 1\n2 1 1\n", "5 1\n2 1 0\n2 0 1\n1 0 1\n1 1 0\n1 0 1\n", "6 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n", "3 1\n3 0 1\n3 1 0\n3 0 0\n", "6 3\n7 1 1\n8 0 0\n9 1 1\n6 1 0\n10 1 1\n5 0 0\n", "8 4 3\n1 1 1\n3 1 1\n12 1 1\n12 1 1\n4 0 0\n4 0 0\n5 1 0\n5 0 1\n", "6 3 ...
1,600
0
2
7
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to...
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 2000...
800
0
2
8
1421_B. Putting Bricks in the Wall
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid. Roger Waters has a square grid of size nΓ— n and he wants to traverse his grid f...
{ "input": [ "3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n" ], "output": [ "1\n3 4\n2\n1 2\n2 1\n0\n" ] }
{ "input": [ "1\n3\nS01\n111\n00F\n", "1\n5\nS0000\n00000\n00000\n00000\n0000F\n", "1\n3\nS10\n010\n11F\n", "1\n3\nS11\n011\n01F\n", "1\n3\nS10\n010\n01F\n", "1\n10\nS000000000\n0000000000\n0000000000\n0000000000\n0000001000\n0000000101\n0000000000\n0000000000\n0000000000\n000000000F\n" ], ...
1,100
1,000
2
7
143_A. Help Vasilisa the Wise 2
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
{ "input": [ "1 2\n3 4\n5 6\n", "11 10\n13 8\n5 16\n", "3 7\n4 6\n5 5\n", "10 10\n10 10\n10 10\n" ], "output": [ "-1\n", "4 7\n9 1\n", "1 2\n3 4\n", "-1\n" ] }
{ "input": [ "3 14\n8 9\n10 7\n", "12 11\n11 12\n16 7\n", "12 17\n10 19\n13 16\n", "9 12\n3 17\n10 10\n", "10 7\n4 13\n11 6\n", "7 9\n4 12\n5 11\n", "2 4\n1 5\n3 3\n", "13 8\n15 6\n11 10\n", "8 10\n9 9\n13 5\n", "12 7\n5 14\n8 11\n", "9 6\n5 10\n3 12\n", "16 5\n13 8\n10...
1,000
500
2
12
1466_F. Euclid's nightmare
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare. In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words h...
{ "input": [ "3 2\n1 1\n1 2\n2 2 1\n", "3 5\n2 1 2\n1 3\n1 4\n", "2 3\n2 1 3\n2 1 2\n" ], "output": [ "\n4 2\n1 2 \n", "\n8 3\n1 2 3 \n", "\n4 2\n1 2 \n" ] }
{ "input": [ "50 5000\n2 35 46\n2 43 92\n2 16 88\n2 67 99\n2 36 93\n2 12 20\n2 33 96\n2 55 82\n2 18 32\n2 48 87\n2 29 83\n2 19 37\n2 68 100\n2 13 76\n2 73 90\n2 25 86\n2 17 61\n2 10 27\n2 70 94\n2 28 41\n2 14 53\n2 15 72\n2 8 95\n2 23 60\n2 3 98\n2 6 34\n2 44 56\n2 2 66\n2 5 91\n2 49 74\n2 38 77\n2 64 71\n2 65 89...
2,100
1,750
2
9
1513_C. Add One
You are given an integer n. You have to apply m operations to it. In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once. You have to find the length of n after applying m operations. Since...
{ "input": [ "5\n1912 1\n5 6\n999 1\n88 2\n12 100\n" ], "output": [ "\n5\n2\n6\n4\n2115\n" ] }
{ "input": [ "5\n90 94\n26 25\n64 84\n14 6\n20 96\n" ], "output": [ "1842\n12\n1015\n3\n1908\n" ] }
1,600
1,500
2
9
1540_C1. Converging Array (Easy Version)
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 respectively. The process is an infinite sequence of operations. Each operat...
{ "input": [ "3\n2 3 4\n2 1\n1\n-1\n" ], "output": [ "56\n" ] }
{ "input": [ "100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 96 7 5 42 52 87 24 82 14 88 4 69 7 69 4 16 55 14 27 89 32 42\n0 0 0 0 ...
2,700
1,500
2
7
168_A. Wizards and Demonstration
Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administr...
{ "input": [ "1000 352 146\n", "10 1 14\n", "20 10 50\n" ], "output": [ "1108\n", "1\n", "0\n" ] }
{ "input": [ "7879 2590 2818\n", "78 28 27\n", "9178 2255 7996\n", "6571 6449 8965\n", "6151 6148 3746\n", "6487 5670 8\n", "4890 1112 5\n", "4909 2111 8860\n", "10000 10000 10000\n", "78 55 96\n", "3271 5 50\n", "1 1 10000\n", "8484 6400 547\n", "10000 10000 1\...
900
500
2
8
20_B. Equation
You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input The first line contains three integer numbers A, B and C ( - 105 ≀ A, B, C ≀ 105). Any coefficient may be equal to 0. Output In case of infinite root cou...
{ "input": [ "1 -5 6\n" ], "output": [ "2\n2.000000\n3.000000\n" ] }
{ "input": [ "0 -2 0\n", "1223 -23532 1232\n", "0 1 0\n", "-1 10 20\n", "0 3431 43123\n", "-50000 100000 -50000\n", "1 1 0\n", "50000 100000 50000\n", "0 -2 1\n", "0 -4 -4\n", "1 1 1\n", "1 -100000 0\n", "-2 -5 0\n", "0 1 -1\n", "1 0 0\n", "-2 -4 0\n", ...
2,000
1,000
2
8
260_B. Ancient Prophesy
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha...
{ "input": [ "777-444---21-12-2013-12-2013-12-2013---444-777\n" ], "output": [ "13-12-2013\n" ] }
{ "input": [ "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n", "01--01--2013-12-2013-01--01--2013\n", "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08-20159533-45-00-1212\n", "00-12-2014-00-12-2014-00-1...
1,600
1,000
2
8
284_B. Cows and Poker Game
There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any bett...
{ "input": [ "3\nAFI\n", "6\nAFFAAA\n" ], "output": [ "1", "4" ] }
{ "input": [ "2\nFF\n", "5\nIIIIF\n", "5\nFAFFF\n", "2\nFA\n", "3\nAAA\n", "5\nFAIAF\n", "5\nAIFFF\n", "3\nFFF\n", "3\nFIF\n", "3\nIII\n", "5\nFAAII\n", "2\nIF\n", "8\nAFFFFIAF\n", "5\nIIIII\n", "3\nIAA\n", "10\nAAAAAAAAAA\n", "3\nIIF\n", "8\nIAA...
1,000
1,000
2
7
379_A. New Year Candles
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like...
{ "input": [ "4 2\n", "6 3\n" ], "output": [ "7\n", "8\n" ] }
{ "input": [ "5 3\n", "1000 3\n", "777 17\n", "4 3\n", "2 2\n", "100 4\n", "10 4\n", "999 2\n", "6 4\n", "1 2\n", "17 3\n", "1 4\n", "26 8\n", "91 5\n", "1 3\n", "1000 2\n", "20 3\n", "9 4\n", "123 5\n", "1000 1000\n", "3 2\n", "3...
1,000
500
2
14
39_H. Multiplication Table
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action β€” multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn...
{ "input": [ "10\n", "3\n" ], "output": [ "1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7 14 21 28 35 42 49 56 63 \n8 16 24 32 40 48 56 64 72 \n9 18 27 36 45 54 63 72 81 \n", ...
{ "input": [ "9\n", "8\n", "6\n", "4\n", "7\n", "5\n", "2\n" ], "output": [ "1 2 3 4 5 6 7 8 \n2 4 6 8 11 13 15 17 \n3 6 10 13 16 20 23 26 \n4 8 13 17 22 26 31 35 \n5 11 16 22 27 33 38 44 \n6 13 20 26 33 40 46 53 \n7 15 23 31 38 46 54 62 \n8 17 26 35 44 53 62 71 \n", ...
1,300
0
2
8
44_B. Cola
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two...
{ "input": [ "10 5 5 5\n", "3 0 0 2\n" ], "output": [ "9\n", "0\n" ] }
{ "input": [ "10 20 10 5\n", "20 1 2 3\n", "7 2 2 2\n", "25 10 5 10\n", "999 999 899 299\n", "10000 5000 0 5000\n", "2 2 2 2\n", "1 0 2 0\n", "3 3 2 1\n", "1 1 0 0\n", "1 0 0 1\n", "20 10 20 30\n", "505 142 321 12\n", "101 10 10 50\n", "10 19 15 100\n", ...
1,500
0
2
8
519_B. A and B and Compilation Errors
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s...
{ "input": [ "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n", "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n" ], "output": [ "1\n3\n", "8\n123\n" ] }
{ "input": [ "3\n1 2 3\n3 2\n2\n", "3\n84 30 9\n9 84\n9\n", "4\n1 5 7 8\n1 5 7\n1 5\n", "3\n796067435 964699482 819602309\n964699482 796067435\n964699482\n", "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 4606264...
1,100
1,000
2
9
545_C. Woodcutters
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ...
{ "input": [ "5\n1 2\n2 1\n5 10\n10 9\n20 1\n", "5\n1 2\n2 1\n5 10\n10 9\n19 1\n" ], "output": [ "4\n", "3\n" ] }
{ "input": [ "4\n10 4\n15 1\n19 3\n20 1\n", "2\n1 999999999\n1000000000 1000000000\n", "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n7...
1,500
1,750
2
9
593_C. Beautiful Function
Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i...
{ "input": [ "3\n0 10 4\n10 0 4\n20 10 4\n" ], "output": [ "(((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(5*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(10*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((5*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(5*((1-abs((t-2)))+abs((abs((t-2...
{ "input": [ "3\n9 5 8\n8 9 10\n9 5 2\n", "50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24 23 24\n11 29 5\n38 44 9\n49 22 42\n1 15 32\n18 25 21\n8 48 39\n48 7 26\n3 30 26\n3...
2,200
3,000
2
7
615_A. Bulbs
Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Va...
{ "input": [ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "3 4\n1 1\n1 2\n1 3\n", "1 100\n99 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 9...
800
500
2
9
634_C. Factory Repairs
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ...
{ "input": [ "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n", "5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n" ], "output": [ "7\n1\n", "3\n6\n4\n" ] }
{ "input": [ "1 1 2 1 1\n2 1\n" ], "output": [ "0\n" ] }
1,700
1,000
2
7
663_A. Rebus
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds. Input The only line of the input contains a re...
{ "input": [ "? - ? = 1\n", "? + ? - ? + ? + ? = 42\n", "? = 1000000\n" ], "output": [ "Impossible\n", "Possible\n40 + 1 - 1 + 1 + 1 = 42\n", "Possible\n1000000 = 1000000\n" ] }
{ "input": [ "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 33\n", "? - ? - ? - ? - ? - ...
1,800
500
2
16
730_J. Bottles
Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≀ bi). Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda...
{ "input": [ "2\n1 1\n100 100\n", "5\n10 30 5 6 24\n10 41 7 8 24\n", "4\n3 3 4 3\n4 7 6 5\n" ], "output": [ "1 1\n", "3 11\n", "2 6\n" ] }
{ "input": [ "30\n10 1 8 10 2 6 45 7 3 7 1 3 1 1 14 2 5 19 4 1 13 3 5 6 1 5 1 1 23 1\n98 4 43 41 56 58 85 51 47 55 20 85 93 12 49 15 95 72 20 4 68 24 16 97 21 52 18 69 89 15\n", "20\n8 1 44 1 12 1 9 11 1 1 5 2 9 16 16 2 1 5 4 1\n88 2 80 33 55 3 74 61 17 11 11 16 42 81 88 14 4 81 60 10\n", "40\n31 72 17 63...
1,900
0
2
7
776_A. A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
{ "input": [ "icm codeforces\n1\ncodeforces technex\n", "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n" ], "output": [ "icm codeforces\nicm technex\n", "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n" ] }
{ "input": [ "wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww\n", "k d\n17\nk l\nd v\nv z\nl r\nz i\nr s\ns p\np w\nw j\nj h\ni c\nh m\nm q\nc o\no g\nq x\nx n\n", "wxz hbeqwqp\n7\nhbeqwqp cpieghnszh\ncpieghnszh tlqrpd\ntlqr...
900
500
2
8
7_B. Memory Manager
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet β€” the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations: ...
{ "input": [ "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n" ], "output": [ "1\n2\nNULL\n3\n" ] }
{ "input": [ "3 1\nerase -1\nerase 0\nerase -2147483648\n", "26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2121605039\nerase 3\nalloc 51\nalloc 65\ndefragment\nerase 2\nerase 4\na...
1,600
0
2
10
820_D. Mister B and PR Shifts
Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation whi...
{ "input": [ "3\n3 2 1\n", "3\n1 2 3\n", "3\n2 3 1\n" ], "output": [ "2 1\n", "0 0\n", "0 1\n" ] }
{ "input": [ "4\n1 2 4 3\n", "4\n2 1 4 3\n", "10\n1 2 10 9 7 4 8 3 6 5\n", "10\n1 7 10 6 5 2 3 8 9 4\n", "4\n4 3 2 1\n", "4\n2 1 3 4\n", "10\n1 10 9 5 3 2 4 7 8 6\n", "4\n2 3 1 4\n", "4\n2 4 3 1\n", "10\n1 5 10 8 4 3 9 2 7 6\n", "4\n1 4 3 2\n", "10\n1 8 10 6 2 4 9 3 7 5...
1,900
1,000
2
11
846_E. Chemistry in Berland
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment. Fortunately, chemical laws allow material transformations (yes, chemistry i...
{ "input": [ "3\n3 2 1\n1 2 3\n1 1\n1 2\n", "3\n1 2 3\n3 2 1\n1 1\n1 1\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n", "5\n78188 56310 79021 70050 65217\n115040 5149 128449 98357 36580\n1 451393770\n2 574046602\n3 590130784\n4 112514248\n", "7\n1 1 1 1 1 1 1\n1 3000000000 3000000000 3000...
2,300
0
2
7
868_A. Bark to Unlock
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p...
{ "input": [ "ah\n1\nha\n", "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n" ], "output": [ "YES", "YES", "NO" ] }
{ "input": [ "ab\n2\nbb\nbc\n", "bc\n1\nab\n", "th\n1\nth\n", "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza...
900
250
2
10
893_D. Credit Card
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ...
{ "input": [ "5 10\n-5 0 10 -11 0\n", "5 10\n-1 5 0 -5 3\n", "3 4\n-10 0 20\n" ], "output": [ "2\n", "0\n", "-1\n" ] }
{ "input": [ "9 13\n6 14 19 5 -5 6 -10 20 8\n", "8 9\n6 -1 5 -5 -8 -7 -8 -7\n", "10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2\n", "6 2\n-2 3 0 -2 0 0\n", "5 10\n-8 -24 0 -22 12\n", "5 13756\n-2 -9 -10 0 10\n", "7 3\n1 -3 0 3 -1 0 2\n", "9 9\n-3 2 0 -2 -7 -1 0 5 3\n", "2 3\n2 0\n", "19 78...
1,900
0
2
7
915_A. Garden
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro...
{ "input": [ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ], "output": [ "2\n", "7\n" ] }
{ "input": [ "3 7\n3 2 1\n", "4 97\n97 1 50 10\n", "5 25\n24 5 15 25 23\n", "3 3\n3 2 1\n", "4 18\n3 1 1 2\n", "5 97\n1 10 50 97 2\n", "1 88\n1\n", "3 18\n1 9 3\n", "8 8\n8 7 6 5 4 3 2 1\n", "2 1\n2 1\n", "5 16\n8 4 2 1 7\n", "2 16\n8 4\n", "1 25\n25\n", "2 2\n2...
900
0
2
8
938_B. Run For Your Prize
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend β€” at position 106 (and there is no prize in any of these two positi...
{ "input": [ "2\n2 999995\n", "3\n2 3 9\n" ], "output": [ "5\n", "8\n" ] }
{ "input": [ "3\n500000 500001 500002\n", "1\n505050\n", "2\n999998 999999\n", "2\n500000 500001\n", "1\n999995\n", "1\n753572\n", "2\n2 999999\n", "1\n999998\n", "4\n2 3 4 5\n", "1\n500002\n", "2\n100 999900\n", "1\n500001\n", "2\n499999 500001\n", "2\n2 500000...
1,100
0
2
8
963_B. Destruction of a Tree
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or...
{ "input": [ "5\n0 1 2 1 2\n", "4\n0 1 2 3\n" ], "output": [ "YES\n1\n2\n3\n5\n4\n", "NO\n" ] }
{ "input": [ "21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\n", "100\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 32 23 79 44 0 67 44 23 48 96 48 56 86 75 9...
2,000
1,000
2
11
990_E. Post Lamps
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked an...
{ "input": [ "5 1 5\n0\n3 3 3 3 3\n", "4 3 4\n1 2 3\n1 10 100 1000\n", "7 4 3\n2 4 5 6\n3 14 15\n", "6 2 3\n1 3\n1 2 3\n" ], "output": [ "-1\n", "1000\n", "-1\n", "6\n" ] }
{ "input": [ "3 1 2\n2\n1 1\n", "3 1 2\n1\n8 61\n", "3 0 3\n\n334 500 1001\n", "20 16 16\n1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 19\n2 1 1 1 1 1 3 3 2 2 1 3 3 3 3 2\n", "1 1 1\n0\n1000\n", "4 1 3\n3\n838 185 210\n", "3 1 1\n2\n1\n", "3 0 3\n\n333 500 1001\n", "6 2 3\n2 3\n1 1 3\n", ...
2,100
0
2
9
101_C. Vectors
At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А: * Turn the vector by 90 degrees clockwise. * Add to the vector a certain vector C. Operations could be performed in any order any number of times. ...
{ "input": [ "0 0\n1 1\n1 1\n", "0 0\n1 1\n0 1\n", "0 0\n1 1\n2 2\n" ], "output": [ "YES\n", "YES\n", "NO\n" ] }
{ "input": [ "3 1\n-2 3\n-2 -2\n", "-8916 9282\n2666 2344\n9109 -2730\n", "0 45\n42 -47\n-51 -82\n", "45 6\n65 5\n0 5\n", "3 4\n-4 3\n1 7\n", "-75629161 -68114618\n23285096 90997125\n84795646 72358903\n", "2 3\n2 3\n0 0\n", "-3 11\n6154942 80496611\n5 0\n", "1 0\n0 1\n2 1\n", "...
2,000
1,500
2
7
1043_A. Elections
Awruk is taking part in elections in his school. It is the final round. He has only one opponent β€” Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t...
{ "input": [ "5\n2 2 3 2 2\n", "5\n1 1 1 5 1\n" ], "output": [ "5\n", "5\n" ] }
{ "input": [ "3\n1 2 6\n", "10\n7 7 7 7 7 7 7 7 7 7\n", "76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11 9\n", "100\n100 100 100 100 100 100 100 100 100 10...
800
500
2
10
1107_D. Compression
You are given a binary matrix A of size n Γ— n. Let's denote an x-compression of the given matrix as a matrix B of size n/x Γ— n/x such that for every i ∈ [1, n], j ∈ [1, n] the condition A[i][j] = B[⌈ i/x βŒ‰][⌈ j/x βŒ‰] is met. Obviously, x-compression is possible only if x divides n, but this condition is not enough. For...
{ "input": [ "8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n", "4\n7\nF\nF\nF\n" ], "output": [ "1", "1" ] }
{ "input": [ "8\nFF\nFF\n00\n00\nFF\nFF\n00\n00\n", "4\n0\n0\n0\n1\n", "8\n33\n33\n33\n33\n33\n33\n11\n11\n", "16\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\n", "12\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\n", "4\nA\nA\nA\...
1,800
0
2
10
1136_D. Nastya Is Buying Lunch
At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to de...
{ "input": [ "5 2\n3 1 5 4 2\n5 2\n5 4\n", "3 3\n3 1 2\n1 2\n3 1\n3 2\n", "2 1\n1 2\n1 2\n" ], "output": [ "1\n", "2\n", "1\n" ] }
{ "input": [ "10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1\n6 1\n10 2\n8 2\n10 1\n7 4\n10 5\n6 9\n6 5\n9 1\n10 4\n", "2 0\n1 2\n", "3 2\n1 2 3\n1 2\n2 1\n", "10 20\n2 1 3 9 5 4 7 8 6 10\n4 7\n6 4\n1 4\n2 8\n1 6\n7 9\n1 9\n5 4\n1 3\n10 6\n8 6\n5 6\n7 6\...
1,800
2,000
2
7
1155_A. Reverse a Substring
You are given a string s consisting of n lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po...
{ "input": [ "7\nabacaba\n", "6\naabcfg\n" ], "output": [ "YES\n2 3\n", "NO\n" ] }
{ "input": [ "6\nbabcdc\n", "5\nbadec\n", "3\naba\n", "7\nbaaaccb\n", "3\naaa\n", "4\npara\n", "3\nbac\n", "7\nbdadccd\n", "2\nba\n", "7\nstoopid\n", "7\nyxyzyyx\n", "3\nacb\n", "7\nbcbcbdc\n", "7\nabacaba\n", "2\naa\n", "12\nparapapapaaa\n" ], "outp...
1,000
0
2
12
1176_F. Destroy it!
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game. The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn i...
{ "input": [ "5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n" ], "output": [ "263\n" ] }
{ "input": [ "5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n", "1\n4\n1 1\n1 1\n2 2\n3 4\n" ], "output": [ "211\n", "4\n" ] }
2,100
0
2
10
1195_D2. Submarine in the Rybinsk Sea (hard edition)
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st...
{ "input": [ "3\n12 3 45\n", "2\n123 456\n" ], "output": [ "12330\n", "1115598\n" ] }
{ "input": [ "20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n", "100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7912 1245 9287 3059 8964 785 2614 4226 70...
1,800
1,500
2
7
1236_A. Stones
Alice is playing with some stones. Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones. Each time she can do one of two operations: 1. take one stone from the first heap and two stones from the second heap (...
{ "input": [ "3\n3 4 5\n1 0 5\n5 3 2\n" ], "output": [ "9\n0\n6\n" ] }
{ "input": [ "20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n", "64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 3 3\n1 0 0\n1 0 1\n1 0 2\n1 0 3\...
800
500
2
7
1382_A. Common Subsequence
You are given two arrays of integers a_1,…,a_n and b_1,…,b_m. Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f...
{ "input": [ "5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n" ], "output": [ "YES\n1 4\nYES\n1 3\nNO\nYES\n1 3\nYES\n1 1\n" ] }
{ "input": [ "1\n2 2\n1 1\n1 2\n", "1\n1 3\n3\n1 2 3\n", "1\n1 1\n1000\n1000\n", "1\n2 2\n2 2\n2 2\n", "5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n", "1\n4 4\n1 1 1 1\n1 2 3 4\n", "1\n2 3\n1 1\n1 2 3\n" ], "output": [ "YE...
800
500
2
9
151_C. Win or Freeze
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl...
{ "input": [ "1\n", "6\n", "30\n" ], "output": [ "1\n0", "2", "1\n6" ] }
{ "input": [ "8587340257\n", "9\n", "81\n", "27\n", "1408514752349\n", "25\n", "49380563\n", "266418\n", "319757451841\n", "6599669076000\n", "8\n", "1000000000000\n", "30971726\n", "274875809788\n", "64\n", "34280152201\n", "236\n", "47267021439...
1,400
500
2
9
1547_C. Pair Programming
Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming. It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file. Ever...
{ "input": [ "5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n" ], "output": [ "0 2 0 5\n0 2 0 5 6\n-1\n0 6 0 7 0 8 0 9\n-1\n" ] }
{ "input": [ "5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n" ], "output": [ "0 2 0 5\n0 2 0 5 6\n-1\n0 6 0 7 0 8 0 9\n-1\n" ] }
1,100
0
2
7
195_A. Let's Watch Football
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si...
{ "input": [ "10 3 2\n", "13 12 1\n", "4 1 1\n" ], "output": [ "5\n", "1\n", "3\n" ] }
{ "input": [ "993 992 991\n", "100 1 10\n", "960 935 994\n", "99 8 99\n", "60 16 1\n", "759 10 258\n", "24 19 9\n", "196 169 144\n", "1000 999 1\n", "945 812 917\n", "1000 100 10\n", "500 300 300\n", "888 777 1000\n", "2 1 4\n", "24 12 12\n", "767 2 514\...
1,000
500
2
7
219_A. k-String
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
{ "input": [ "2\naazz\n", "3\nabcabcabz\n" ], "output": [ "azaz", "-1\n" ] }
{ "input": [ "2\naaab\n", "2\nbabac\n", "2\naaaaaabbbb\n", "1\naabaab\n", "2\naabbbbccccccdddddddd\n", "2\nabba\n", "2\naaaazzzz\n", "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececec...
1,000
500
2
9
242_C. King's Path
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the...
{ "input": [ "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n", "1 1 2 10\n2\n1 1 3\n2 6 10\n", "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n" ], "output": [ "6\n", "-1\n", "4\n" ] }
{ "input": [ "1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n", "6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15\n7 14 14\n8 15 15\n", "1 1 1000000000 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 1...
1,800
1,500
2
7
268_A. Games
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
{ "input": [ "2\n1 2\n1 2\n", "4\n100 42\n42 100\n5 42\n100 5\n", "3\n1 2\n2 4\n3 4\n" ], "output": [ "0\n", "5\n", "1\n" ] }
{ "input": [ "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9\n", "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n...
800
500
2
10
290_D. Orange
<image> Input The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase. The second line of the input is an integer between 0 and 26, inclusive. Output Output the required string. Examples Input AprilFool 14...
{ "input": [ "AprilFool\n14\n" ], "output": [ "AprILFooL" ] }
{ "input": [ "qH\n2\n", "nifzlTLaeWxTD\n0\n", "WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5\n", "LiqWMLEULRhW\n1\n", "kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26\n", "DuFhhnq\n4\n", "aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4\n", "VtQISIHREYaEGPustEkzJRN\n20\n", "aaaaaaAAAaaaaAa...
1,400
0
2
8
316_B2. EKG
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another. (Cultural note: standing in huge and disorganized queues for hours is a native ...
{ "input": [ "6 2\n2 3 0 5 6 0\n", "6 2\n0 0 1 0 4 5\n", "6 1\n2 0 4 0 6 0\n", "4 1\n0 0 0 0\n" ], "output": [ "2\n5\n", "1\n3\n4\n6\n", "2\n4\n6\n", "1\n2\n3\n4\n" ] }
{ "input": [ "20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "10 4\n0 1 4 2 7 0 10 0 5 8\n", "10 7\n10 8 6 5 0 0 0 4 3 9\n", "10 1\n8 7 0 2 0 10 0 0 3 5\n", "10 7\n7 9 2 10 0 0 0 3 5 1\n", "10 2\n10 0 9 0 0 4 2 6 8 0\n", "10 2\n0 7 0 10 8 0 4 2 3 0\n" ], "output": [ "1\n2\n3\n4...
1,600
70
2
7
339_A. Helpful Maths
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
{ "input": [ "2\n", "3+2+1\n", "1+1+3+1+3\n" ], "output": [ "2\n", "1+2+3\n", "1+1+1+3+3\n" ] }
{ "input": [ "2+2+1+1+3\n", "3+1\n", "1+3\n", "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\n", "2+2\n", "1+1\n", "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1\n", "1\n", "...
800
500
2
9
361_C. Levko and Array Recovery
Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types: 1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ...
{ "input": [ "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n" ], "output": [ "YES\n8 7 4 7 ", "NO\n" ] }
{ "input": [ "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n", "2 2\n2 1 2 8\n2 1 2 7\n", "97 29\n2 78 82 356152\n2 14 29 430177\n1 59 84 3680\n1 49 89 -2247\n1 92 96 3701\n2 54 89 377271\n1 62 70 -507\n2 94 97 431563\n1 46 55 -9257\n1 51 83 1627\n1 10 ...
1,700
500
2
7
385_A. Bear and Raspberry
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≀ i ≀ n) day, the price for one barrel of honey is going to is xi kilos of raspberry. Unfortunately, the b...
{ "input": [ "6 2\n100 1 10 40 10 40\n", "5 1\n5 10 7 3 20\n", "3 0\n1 2 3\n" ], "output": [ "97\n", "3\n", "0\n" ] }
{ "input": [ "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24\n", "10 5\n10 1 11 2 12 3 13 4 1...
1,000
500
2
11
405_E. Graph Cutting
Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest. Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partiti...
{ "input": [ "3 2\n1 2\n2 3\n", "3 3\n1 2\n2 3\n3 1\n", "8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n" ], "output": [ "1 2 3\n", "No solution\n", "6 7 8 5 6 8 4 3 5 2 3 6 1 2 4 4 1 3 " ] }
{ "input": [ "9 12\n1 2\n2 3\n4 5\n5 6\n6 7\n7 8\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n", "5 4\n2 1\n3 2\n4 3\n5 4\n", "4 4\n1 2\n2 3\n3 1\n1 4\n", "9 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n7 9\n8 9\n", "4 3\n3 2\n2 1\n1 4\n", "8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n", "9 8\n...
2,300
3,000
2
7
433_A. Kitahara Haruki's Gift
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ...
{ "input": [ "4\n100 100 100 200\n", "3\n100 200 100\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "9\n100 100 100 200 100 100 200 100 200\n", "3\n100 100 100\n", "7\n200 200 200 100 200 200 200\n", "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100...
1,100
500
2
7
478_A. Initial Bet
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player. Your task is to write a program that...
{ "input": [ "2 5 4 0 4\n", "4 5 9 2 1\n" ], "output": [ "3\n", "-1\n" ] }
{ "input": [ "99 100 100 100 100\n", "57 83 11 4 93\n", "99 99 99 99 99\n", "100 0 0 0 0\n", "0 1 2 3 4\n", "93 100 99 90 98\n", "87 38 19 33 100\n", "1 1 1 1 1\n", "0 0 0 0 1\n", "2 3 4 5 6\n", "1 2 1 2 3\n", "0 0 0 0 0\n", "100 100 100 100 100\n", "43 83 1 0 2...
1,100
500
2
9
500_C. New Year Book Reading
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≀ i ≀ n) book is wi. As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a...
{ "input": [ "3 5\n1 2 3\n1 3 2 3 1\n" ], "output": [ "12\n" ] }
{ "input": [ "50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41 2 7 9 24 27 23 3 44 15 14\n", ...
1,600
1,000
2
7
526_A. King of Thieves
In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. <image> An interesting feature of the game is that you can design your own levels...
{ "input": [ "16\n.**.*..*.***.**.\n", "11\n.*.*...*.*.\n" ], "output": [ "yes", "no" ] }
{ "input": [ "20\n.*..*...*....*.....*\n", "97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.\n", "5\n*.***\n", "4\n****\n", "11\n.*.*.*.*...\n", "72\n.***.**.*.*...*****.*.*.*.*.**....**.*.**..*.*...**..***.**.**..*.**..**\n", "89\n..**....
1,300
500
2
8
551_B. ZgukistringZ
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x...
{ "input": [ "pozdravstaklenidodiri\nniste\ndobri\n", "aaa\na\nb\n", "abbbaaccca\nab\naca\n" ], "output": [ "nisteaadddiiklooprrvz\n", "aaa\n", "ababacabcc\n" ] }
{ "input": [ "brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n", "aleksandrehteosidatedodam\nevo\nsi\n", "goodbyeihopecontestisntsohar\noh\ngod\n", "duxidimkeetoivas\ndd\n...
1,800
1,250
2
9
578_C. Weakness and Poorness
You are given a sequence of n integers a1, a2, ..., an. Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible. The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence. The poor...
{ "input": [ "10\n1 10 2 9 3 8 4 7 5 6\n", "4\n1 2 3 4\n", "3\n1 2 3\n" ], "output": [ "4.500000000000024\n", "2.000000000000003\n", "1.000000000000000\n" ] }
{ "input": [ "10\n-405 -230 252 -393 -390 -259 97 163 81 -129\n", "3\n10000 -10000 10000\n", "1\n-10000\n", "20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0\n" ], "output": [ "702.333333333333712\n", "10000.000000000016371\n", "0.000000000000000\n", "113.87...
2,000
750
2
7
5_A. Chat Server's Outgoing Traffic
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: * Include a perso...
{ "input": [ "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n" ], "output": [ "9\n", "14\n" ] }
{ "input": [ "+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n", "+cab\n+abac\n-abac\n+baca\n", "+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8UjgAJ\n+zdi\n-zdi\n", "+acabadab\n+caba0aba\n", "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm Q...
1,000
0
2
10
621_D. Rat Kwesh and Cheese
Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point. Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ...
{ "input": [ "1.1 3.4 2.5\n", "1.9 1.8 1.7\n", "2.0 2.0 2.0\n" ], "output": [ "z^y^x\n", "(x^y)^z\n", "x^y^z\n" ] }
{ "input": [ "1.0 200.0 200.0\n", "0.2 0.1 0.6\n", "1.9 3.0 4.1\n", "51.8 51.8 7.1\n", "113.9 125.2 88.8\n", "1.9 4.8 3.9\n", "2.2 148.1 138.0\n", "1.0 200.0 1.0\n", "1.7 4.5 4.2\n", "0.2 0.6 0.3\n", "200.0 200.0 0.1\n", "3.9 0.2 3.8\n", "7.0 131.1 7.4\n", "4.6 ...
2,400
2,000
2
8
643_B. Bear and Two Paths
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities. Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting ea...
{ "input": [ "1000 999\n10 20 30 40\n", "7 11\n2 4 7 3\n" ], "output": [ "-1", "2 7 1 5 6 3 4 \n7 2 1 5 6 4 3 " ] }
{ "input": [ "1000 1001\n217 636 713 516\n", "1000 1998\n833 681 19 233\n", "4 5\n1 3 4 2\n", "6 7\n3 1 2 4\n", "5 7\n4 3 2 1\n", "55 56\n53 54 52 55\n", "1000 1000\n89 983 751 38\n", "1000 1002\n641 480 458 289\n", "6 5\n3 2 5 4\n", "999 999\n289 384 609 800\n", "5 4\n2 3 ...
1,600
1,000
2
8
670_B. Game of Robots
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β€” an integer from 1 to 109. At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. Aft...
{ "input": [ "4 5\n10 4 18 3\n", "2 2\n1 2\n" ], "output": [ "4", "1" ] }
{ "input": [ "4 9\n5 1000000000 999999999 12\n", "4 6\n5 1000000000 999999999 12\n", "1 1\n4\n", "3 5\n4 5 6\n", "3 4\n4 5 6\n", "3 6\n4 5 6\n", "4 2\n5 1000000000 999999999 12\n", "2 3\n6 7\n", "2 1\n5 1\n", "4 1\n5 1000000000 999999999 12\n", "4 3\n5 1000000000 999999999 ...
1,000
750
2
10
691_D. Swaps in Permutation
You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get? Let p and q be two permutations of the numbers 1, 2, ..., n. p i...
{ "input": [ "9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n" ], "output": [ "7 8 9 4 5 6 1 2 3 \n" ] }
{ "input": [ "3 10\n2 3 1\n1 1\n3 3\n3 3\n3 2\n1 1\n2 2\n3 1\n1 3\n2 1\n3 3\n", "7 20\n6 2 5 7 3 1 4\n7 7\n1 1\n2 2\n6 1\n4 4\n2 2\n2 2\n6 6\n3 5\n7 4\n1 6\n4 4\n6 1\n1 1\n3 3\n5 3\n3 5\n5 3\n2 2\n4 4\n", "4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3\n3 3\n1 4\n3 3\n2 2\n3 3\n4 1\n2 2\n1 4\n3 3\n4 1\n1 1\n3 3\n...
1,700
0
2
10
716_D. Complete The Graph
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg...
{ "input": [ "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n", "2 1 123456789 0 1\n0 1 0\n", "2 1 999999999 1 0\n0 1 1000000000\n" ], "output": [ "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n", "YES\n0 1 123456789\n", "NO" ] }
{ "input": [ "7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n", "7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61\n", "4 5 7 0 3\n0 1 0\n1 2 3\n2 3 0\n0 2 5\n1 3 5\n", "8 9 10 1 0\n1 2 1\n2 4 1\n1 3 0\n3 4 0\n4 5 0\n5 6...
2,300
1,000
2
7
737_A. Road to Cinema
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s. ...
{ "input": [ "3 1 8 10\n10 8\n5 7\n11 9\n3\n", "2 2 10 18\n10 4\n20 6\n5 3\n" ], "output": [ "10\n", "20\n" ] }
{ "input": [ "1 1 2 2\n1000000000 1000000000\n1\n", "1 1 1000000000 1000000000\n100 1000000000\n1\n", "1 1 10 18\n5 6\n5\n", "2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1\n", "4 13 400 600\n13 30\n1 19\n1 160\n1 113\n58 73 15 319 194 362 128 157 336 162 77 90 96\n", "1 15 100 200...
1,700
1,750
2
8
784_B. Kids' Riddle
Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it? Input The input contains a single integer n (0 ≀ n ≀ 2000000000). Output Output a single integer. Examples Input 11 Output 2 Input 14 Output 0 Input 61441 Output 2 Input 571576 Output 10 Input 2128506 Output 3
{ "input": [ "14\n", "2128506\n", "11\n", "571576\n", "61441\n" ], "output": [ "0", "3", "2", "10", "2" ] }
{ "input": [ "143165576\n", "1919020031\n", "1204252996\n", "210637432\n", "724264821\n", "1741\n", "619489590\n", "1199537418\n", "1075765759\n", "747976826\n", "638486017\n", "58438190\n", "1285316221\n", "186925426\n", "1180540990\n", "833393692\n", ...
2,000
0
2
7
805_A. Fake NP
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve...
{ "input": [ "19 29\n", "3 6\n" ], "output": [ "2\n", "2\n" ] }
{ "input": [ "252662256 252662260\n", "141650963 141650963\n", "4 12\n", "1002523 1002523\n", "93 95\n", "331900277 331900277\n", "56 92\n", "10 100\n", "3 1000000000\n", "13 13\n", "2 879190747\n", "999900001 1000000000\n", "820844234 892579936\n", "419873015 4...
1,000
500
2
7
830_A. Office Keys
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine the mi...
{ "input": [ "1 2 10\n11\n15 7\n", "2 4 50\n20 100\n60 10 40 80\n" ], "output": [ "7", "50" ] }
{ "input": [ "1 1 10\n10\n10\n", "2 2 10\n9 11\n11 8\n", "1 1 1000000000\n1000000000\n1\n", "1 1 50\n1\n1000000000\n", "2 2 5\n2 3\n4 6\n", "5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88\n", "1 1 1\n2\n1000000000\n", "2 2 10\n5 6\n4 6\n", "...
1,800
500
2
8
851_B. Arpa and an exam about geometry
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points a, b, c. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c....
{ "input": [ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ], "output": [ "Yes\n", "No\n" ] }
{ "input": [ "264193194 -448876521 736684426 -633906160 -328597212 -47935734\n", "-357531221 381512519 -761132895 -224448284 328888775 -237692564\n", "-1000000000 -1000000000 0 0 1000000000 999999999\n", "0 2 4 5 4 0\n", "0 0 2 45 0 90\n", "-1000000000 -1000000000 0 1000000000 1000000000 -1000...
1,400
1,000
2
11
920_E. Connected Components?
You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices. ...
{ "input": [ "5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n" ], "output": [ "2\n1 4 \n" ] }
{ "input": [ "7 20\n4 6\n6 7\n4 5\n1 2\n2 4\n1 7\n3 5\n2 1\n6 2\n6 1\n7 3\n3 2\n3 6\n3 1\n3 4\n2 5\n1 6\n7 4\n6 3\n7 5\n", "8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8\n", "4 4\n2 1\n3 1\n1 4\n3 2\n", "8 18\n1 4\n1 6\n1 7\n2 3...
2,100
0
2
9
949_C. Data Center Maintenance
BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!). Main feature of services offered by BigData Inc. is the access availability guarantee even under the ci...
{ "input": [ "3 3 5\n4 4 0\n1 3\n3 2\n3 1\n", "4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3\n" ], "output": [ "1\n3 \n", "4\n1 2 3 4 \n" ] }
{ "input": [ "10 9 5\n0 0 0 0 0 0 0 0 0 4\n10 3\n10 7\n10 5\n10 8\n10 9\n10 1\n10 4\n10 6\n10 2\n", "10 20 5\n2 2 1 4 0 3 0 4 1 3\n6 1\n8 5\n2 10\n3 5\n1 9\n4 6\n9 7\n2 3\n7 4\n10 8\n4 9\n2 5\n4 10\n2 8\n10 3\n1 8\n8 10\n6 7\n5 1\n10 3\n", "10 9 2\n1 1 0 1 1 1 1 1 1 1\n3 10\n3 8\n3 6\n3 7\n3 5\n3 4\n3 1\n...
1,900
1,250
2
8
977_B. Two-gram
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" β€” three distinct two-grams. You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ...
{ "input": [ "5\nZZZAA\n", "7\nABACABA\n" ], "output": [ "ZZ\n", "AB\n" ] }
{ "input": [ "15\nMIRZOYANOVECLOX\n", "23\nAABBBAAACCCCCAAADDDDDDD\n", "2\nQA\n", "11\nGGRRAATTZZZ\n", "6\nAZAZAZ\n", "10\nSQSQSQSQTG\n", "3\nKEK\n", "100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC\n", "3\nLOL\n", "2\nW...
900
0
2
8
1012_B. Chemical table
Innopolis University scientists continue to investigate the periodic table. There are nΒ·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 ≀ r ≀ n, 1 ≀ c ≀ m) in the table. Recently scientists discovered that for every four...
{ "input": [ "1 5 3\n1 3\n1 1\n1 5\n", "2 2 3\n1 2\n2 2\n2 1\n", "4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3\n" ], "output": [ "2\n", "0\n", "1\n" ] }
{ "input": [ "20 20 20\n18 16\n4 20\n2 5\n7 4\n11 13\n6 10\n20 8\n14 6\n3 12\n5 1\n16 7\n10 9\n1 11\n12 18\n19 15\n13 19\n17 3\n9 17\n15 2\n8 14\n", "20 20 1\n17 13\n", "1 1 0\n", "10000 9999 1\n5717 9264\n", "20 10 5\n18 10\n19 10\n19 9\n20 9\n20 8\n", "1 20 3\n1 18\n1 12\n1 10\n", "20 10...
1,900
1,250
2
8
1037_B. Reach Median
You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the ...
{ "input": [ "3 8\n6 5 8\n", "7 20\n21 15 12 11 20 19 12\n" ], "output": [ "2\n", "6\n" ] }
{ "input": [ "3 1\n1 2 5\n", "1 1\n100000\n", "5 1\n2 2 4 6 1\n", "3 10\n5 5 10\n", "1 1\n1\n", "3 4\n1 2 5\n", "1 100\n88\n", "1 100\n105\n" ], "output": [ "1\n", "99999\n", "2\n", "5\n", "0\n", "2\n", "12\n", "5\n" ] }
1,300
750
2
9
105_C. Item World
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res). Each item belongs to one class. In this problem we will only consider three of such...
{ "input": [ "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n", "4\nsword weapon 10 2 3 2\npagstarmor a...
{ "input": [ "6\nc armor 0 13 0 3\na weapon 23 0 0 3\nb weapon 20 0 0 4\ne orb 0 0 13 3\nd armor 0 15 0 4\nf orb 0 0 17 5\n5\nj gladiator 7 a\nh gladiator 3 f\ng gladiator 4 e\ni gladiator 7 a\nk gladiator 1 b\n", "6\nc armor 0 13 0 3\na weapon 23 0 0 3\nb weapon 10 0 0 4\ne orb 0 0 19 3\nd armor 0 15 0 4\nf ...
2,200
1,500
2
10
1081_D. Maximum Distance
Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago. You are given a connected undirected graph with n vertices and m weighted edges. There are k special vertices: x_1, x_2, …, x_k. Let's define the cost of the path as the maximum weight of the edges in it. And th...
{ "input": [ "4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n", "2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n" ], "output": [ "3 3 3 ", "2 2 " ] }
{ "input": [ "4 4 3\n1 2 3\n1 2 1\n2 3 2\n1 3 3\n1 4 4\n", "4 3 2\n1 4\n1 2 1\n2 3 5\n3 4 1\n", "3 2 2\n1 2\n1 2 1\n2 3 47\n", "3 2 2\n1 2\n1 2 1\n2 3 1000\n", "3 2 2\n1 2\n1 2 10\n2 3 100\n", "3 3 2\n2 3\n1 2 100\n1 3 100\n2 3 1\n", "3 2 2\n1 2\n1 2 2\n2 3 3\n", "6 5 3\n1 2 4\n1 3 3\n...
1,800
2,000
2
7
1129_A2. Toy Train
Alice received a set of Toy Trainβ„’ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit afte...
{ "input": [ "2 3\n1 2\n1 2\n1 2\n", "5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n" ], "output": [ "5 6 ", "10 9 10 10 9 " ] }
{ "input": [ "5 1\n3 2\n", "3 3\n1 2\n1 2\n1 2\n", "5 3\n2 4\n5 4\n3 2\n", "20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n", "3 2\n3 1\n1 3\n", "3 1\n3 1\n", "3 2\n1 3\n2 1\n", "50 20\n4 18\n39 33\n49 32\n7 32\n38 1\n46 11\n8 1\n3 31\n30 47\n24 16\n33 5\n5 21\n3 48\n13 23\n49 50\n18 47\n40 32\n9...
1,800
250
2
8
1149_B. Three Religions
During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace. The Word of Uni...
{ "input": [ "6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n", "6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n" ], "output": [ "YES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\n", "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\n" ] }
{ "input": [ "1 1\nt\n+ 2 p\n", "2 12\naa\n+ 1 a\n+ 2 a\n+ 3 a\n- 1\n+ 1 a\n- 2\n+ 2 a\n- 3\n+ 3 a\n+ 2 a\n- 1\n- 3\n", "2 10\nuh\n+ 1 h\n+ 2 u\n+ 3 h\n- 1\n- 2\n+ 2 h\n+ 3 u\n- 2\n+ 1 u\n- 3\n", "1 1\nz\n+ 3 z\n" ], "output": [ "NO\n", "YES\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nYES...
2,200
1,250
2
7
1189_A. Keanu Reeves
After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem. Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa...
{ "input": [ "1\n1\n", "6\n100011\n", "2\n10\n" ], "output": [ "1\n1\n", "2\n1 00011\n", "2\n1 0\n" ] }
{ "input": [ "72\n111101100111001110000000100010100000011011100110001010111010101011111100\n", "3\n101\n", "18\n101111001111000110\n", "7\n1111000\n", "3\n010\n", "12\n101010100101\n", "1\n0\n", "4\n1010\n", "6\n101100\n", "100\n0010110000001111110111101011100111101000110011011...
800
500
2
7
1208_A. XORinacci
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: * f(0) = a; * f(1) = b; * f(n) = f(n-1) βŠ• f(n-2) when n > 1, where βŠ• de...
{ "input": [ "3\n3 4 2\n4 5 0\n325 265 1231232\n" ], "output": [ "7\n4\n76\n" ] }
{ "input": [ "10\n669924290 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 974275296\n400531973 205638174 323247740\n219131617 178762989 799964854\n825160173 502080627 60...
900
500
2
7
1227_A. Math Problem
Your math teacher gave you the following problem: There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], …, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ≀ x ≀ r. The length of the segment [l; r] is equal to r - l. Two segments [a; b] and [c; d] have a common point (inters...
{ "input": [ "4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1\n" ], "output": [ "2\n4\n0\n0\n" ] }
{ "input": [ "1\n2\n999999997 999999998\n999999999 1000000000\n", "4\n1\n1 1000000000\n5\n1 1\n12 18\n1000000000 1000000000\n1 1\n8888888 88888888\n5\n2 5\n3 6\n4 7\n5 8\n6 9\n3\n1 1000000000\n1 1\n1000000000 1000000000\n", "1\n10\n132182352 630066892\n323711215 923129673\n259700817 882571434\n226161845 3...
1,100
500
2
10
124_D. Squares
You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one. A square (x; y) is cons...
{ "input": [ "2 2 1 0 0 1\n", "2 2 10 11 0 1\n", "2 4 3 -1 3 7\n" ], "output": [ "1", "5", "2" ] }
{ "input": [ "605 297 -251700323 -366763764 -445828791 325081312\n", "14 9 44 45 -50 -9\n", "18 17 -26078453 -12853708 26705417 -4593122\n", "472555248 417950652 -897989583 -805741694 915661619 800897620\n", "1005 557 -451917708 -32771965 501646713 -357583032\n", "465 469 376765675 358805048 -...
1,800
1,000
2
8
1269_B. Modulo Equality
You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [...
{ "input": [ "3 2\n0 0 0\n1 1 1\n", "4 3\n0 0 2 1\n2 0 1 1\n", "5 10\n0 0 0 1 2\n2 1 0 0 0\n" ], "output": [ "1", "1", "0" ] }
{ "input": [ "20 10000000\n8861863 2169292 3484361 511558 5975675 1413584 774309 5847326 6668965 2531461 3337531 9484932 2648359 3710600 2232337 5474539 2785576 4119997 5005708 1717831\n247095 4003803 2013625 1177623 7391127 1314840 5198229 2239864 9942848 1060725 1866795 3534972 698556 9303573 761601 9040822 450...
1,500
1,000
2
9
1311_C. Perform the Combo
You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again. You know that you ...
{ "input": [ "3\n4 2\nabca\n1 3\n10 5\ncodeforces\n2 8 3 2 9\n26 10\nqwertyuioplkjhgfdsazxcvbnm\n20 10 1 2 3 5 10 5 9 4\n" ], "output": [ "4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n\n0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0 \n\n2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2 \...
{ "input": [ "2\n2 2\nyz\n1 1\n2 2\nyz\n1 1\n", "1\n11 2\nthisisatest\n3 5\n" ], "output": [ "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 \n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 \n\n", "1 0 0 0 1 0 0 3 5 0 0 0 0 0 0 0 0 0 4 5 0 0 0 0 0 0 \n\n" ] }
1,300
0
2
7
1334_A. Level Statistics
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases...
{ "input": [ "6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n" ], "output": [ "NO\nYES\nNO\nYES\nNO\nYES\n" ] }
{ "input": [ "1\n2\n110 2\n115 112\n", "10\n5\n88 60\n10 3\n48 21\n90 70\n40 88\n5\n20 81\n39 98\n34 87\n100 82\n21 21\n2\n46 91\n89 71\n2\n81 98\n25 36\n3\n84 97\n40 32\n17 29\n2\n56 16\n96 75\n5\n35 24\n82 73\n23 15\n45 95\n79 90\n2\n68 13\n70 100\n3\n94 35\n95 77\n31 86\n5\n99 14\n12 54\n81 60\n80 29\n46 5...
1,200
0
2
9
1354_C2. Not So Simple Polygon Embedding
The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd. You are given a regular polygon with 2 β‹… n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n...
{ "input": [ "3\n3\n5\n199\n" ], "output": [ "1.931851653\n3.196226611\n126.687663797\n" ] }
{ "input": [ "99\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99\n101\n103\n105\n107\n109\n111\n113\n115\n117\n119\n121\n123\n125\n127\n129\n131\n133\n135\n137\n139\n141\...
2,000
0
2
8
1374_B. Multiply by 2, divide by 6
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder). Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that. You have to answer t independent test cases. Input The fi...
{ "input": [ "7\n1\n2\n3\n12\n12345\n15116544\n387420489\n" ], "output": [ "0\n-1\n2\n-1\n-1\n12\n36\n" ] }
{ "input": [ "1\n999838675\n" ], "output": [ "-1\n" ] }
900
0
2
9
1397_C. Multiples of Length
You are given an array a of n integers. You want to make all elements of a equal to zero by doing the following operation exactly three times: * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different). It can...
{ "input": [ "4\n1 3 2 4\n" ], "output": [ "1 1\n-1\n2 4\n9 6 12 \n1 4\n0 -12 -8 -16 \n" ] }
{ "input": [ "2\n-492673762 -496405053\n", "13\n-958184557 -577042357 -616514099 -553646903 -719490759 -761325526 -210773060 -44979753 864458686 -387054074 546903944 638449520 299190036\n", "5\n450402558 -840167367 -231820501 586187125 -627664644\n", "32\n474784688 671671886 -592758087 -662585781 9970...
1,600
500
2
10
1420_D. Rescue Nibel!
Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened. Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional de...
{ "input": [ "3 3\n1 3\n2 3\n3 3\n", "3 1\n1 1\n2 2\n3 3\n", "7 3\n1 7\n3 8\n4 5\n6 7\n1 3\n5 10\n8 9\n", "3 2\n1 1\n2 2\n3 3\n", "5 2\n1 3\n2 4\n3 5\n4 6\n5 7\n" ], "output": [ "1\n", "3\n", "9\n", "0\n", "7\n" ] }
{ "input": [ "10 7\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n", "2 2\n1 1\n1 1\n", "20 12\n18525 35038\n15816 31586\n18641 46864\n35863 38632\n13563 35915\n41614 98684\n13573 35863\n25851 35985\n41687 55831\n31583 80871\n18525 35038\n15816 31586\n18641 46864\n35863 38632\n13563 35915\n41614 ...
1,800
2,000
2
9
167_C. Wizards and Numbers
In some country live wizards. They love playing with numbers. The blackboard has two numbers written on it β€” a and b. The order of the numbers is not important. Let's consider a ≀ b for the sake of definiteness. The players can cast one of the two spells in turns: * Replace b with b - ak. Number k can be chosen by...
{ "input": [ "4\n10 21\n31 10\n0 1\n10 30\n" ], "output": [ "First\nSecond\nSecond\nFirst\n" ] }
{ "input": [ "7\n576460752303423487 2\n82 9\n101 104\n10 21\n31 10\n0 1\n10 30\n", "1\n128817972817282999 327672410994637530\n", "66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\n0 5\n3 6\n7 3\n6 0\n5 2\n6 6\n1 7\n5 6\n2 2\n3 4\n2 1\n5 3\n4 6\n6 2\n3 3\n100000000000 1000000000000000000...
2,300
1,500