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
7
2_A. Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
{ "input": [ "3\nandrew 3\nandrew 2\nmike 5\n", "3\nmike 3\nandrew 5\nmike 2\n" ], "output": [ "andrew\n", "andrew\n" ] }
{ "input": [ "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 9...
1,500
0
2
7
325_A. Square and Rectangles
You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the rectan...
{ "input": [ "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "3\n25784 0 31400 20408\n0 20408 31400 20582\n15802 0 18106 20408\n", "2\n1 1 5 5\n1 5 5 7\n", "5\n1 1 3 5\n3 3 5 5\n4 1 5 3\n3 1 4 2\n2 5 3 6\n", "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400\n", "1\n0 3006 1 17592\n", ...
1,500
500
2
9
371_C. Hamburgers
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
{ "input": [ "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n", "BBBSSC\n6 4 1\n1 2 3\n4\n" ], "output": [ "7\n", "200000000001\n", "2\n" ] }
{ "input": [ "B\n100 100 100\n1 1 1\n1\n", "SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\n94 16 85\n14 18 91\n836590091442\n", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n1 1 1\n100 100 100\n...
1,600
1,500
2
7
416_A. Guess a number!
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: * Is it true that y is stric...
{ "input": [ "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N\n", "2\n> 100 Y\n< -100 Y\n" ], "output": [ "-2000000000\n", "-2000000000\n" ] }
{ "input": [ "1\n<= -999999999 Y\n", "1\n< -1000000000 Y\n", "4\n> 5 N\n>= -5 Y\n> -9 Y\n> -9 Y\n", "10\n<= -60 N\n>= -59 Y\n> 22 Y\n> 95 N\n<= 91 Y\n> 77 Y\n>= -59 Y\n> -25 Y\n> -22 Y\n>= 52 Y\n", "1\n<= 15 Y\n", "3\n>= 4 Y\n> 4 Y\n<= 4 Y\n", "1\n> 10000000 Y\n", "8\n< -1000000000 Y\n...
1,400
500
2
10
488_D. Strip
Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: * Each piece should contain at least l numbers. * The difference between the maximal and the minimal number on the piece...
{ "input": [ "7 2 2\n1 3 1 2 4 1 2\n", "7 2 2\n1 100 1 100 1 100 1\n" ], "output": [ "3", "-1" ] }
{ "input": [ "1 100 2\n42\n", "6 565 2\n31 76 162 -182 -251 214\n", "2 1000000000 1\n-1000000000 1000000000\n", "1 0 1\n0\n", "10 3 3\n1 1 1 1 1 5 6 7 8 9\n", "1 0 1\n-1000000000\n", "10 3 3\n1 1 1 2 2 5 6 7 8 9\n", "2 1000000000 2\n-1000000000 1000000000\n" ], "output": [ "-1"...
2,000
1,500
2
9
512_C. Fox And Dinner
Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting at some table. 2. Each table has at least 3 foxes sitting around it. 3...
{ "input": [ "5\n2 2 2 2 2\n", "4\n3 4 8 9\n", "12\n2 3 4 5 6 7 8 9 10 11 12 13\n", "24\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\n" ], "output": [ "Impossible\n", "1\n4 1 2 4 3\n", "1\n12 1 2 3 6 5 12 9 8 7 10 11 4\n", "3\n8 1 2 3 24 5 6 23 4\n10 7 8 9 12 15...
{ "input": [ "15\n3 3 3 3 3 3 3 4 2 4 2 2 2 4 2\n", "152\n29 23 17 25 13 29 29 29 25 23 25 29 19 25 13 25 13 23 21 27 15 29 29 25 27 17 17 19 25 19 13 19 15 13 19 13 17 17 19 17 17 13 25 21 17 13 21 17 25 21 19 23 17 17 29 15 15 17 25 13 25 13 21 13 19 19 13 13 21 25 23 19 19 21 29 29 26 30 22 20 22 28 24 28 ...
2,300
2,500
2
11
560_E. Gerald and Giant Chess
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of gia...
{ "input": [ "100 100 3\n15 16\n16 15\n99 88\n", "3 4 2\n2 2\n2 3\n" ], "output": [ "545732279\n", "2\n" ] }
{ "input": [ "100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\n9 4\n11 1\n20 3\n47 3\n2 4\n68 3\n90 5\n85 2\n88 1\n88 5\n86 3\n70 9\n49 3\n34 4\n5 7\n77 5\n50 1\n87 5\n", "100000 100000 2\n1 2\n2 1\n", "100000 100000 2\n99999 100000\n100000 99999\n", "100000 100000 4...
2,200
1,500
2
7
587_A. Duff and Weight Lifting
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
{ "input": [ "5\n1 1 2 3 3\n", "4\n0 1 2 3\n" ], "output": [ "2\n", "4\n" ] }
{ "input": [ "2\n95745 95745\n", "100\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 7302 0 19579 4142 11 1354 75252 93 311 1278 0 79475 1...
1,500
500
2
9
609_C. Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
{ "input": [ "2\n1 6\n", "7\n10 11 10 11 10 11 11\n", "5\n1 2 3 4 5\n" ], "output": [ "2\n", "0\n", "3\n" ] }
{ "input": [ "2\n10 3\n", "5\n2 10 20 30 50\n", "1\n0\n", "10\n19999 19999 20000 20000 19999 20000 20000 20000 19999 19999\n", "1\n20000\n", "5\n6 5 9 7 6\n", "7\n2 2 2 2 2 3 4\n", "10\n0 0 0 0 0 0 0 0 0 0\n", "3\n1 10000 20000\n", "10\n8 5 5 5 6 6 6 6 5 5\n" ], "output": [...
1,500
0
2
8
630_B. Moore's Law
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately ev...
{ "input": [ "1000 1000000\n" ], "output": [ "1011.060722405749039" ] }
{ "input": [ "4907 244618708\n", "4054 287739817\n", "1000 0\n", "1000 1\n", "1000 2\n", "1587 1941728048\n", "9030 982505993\n", "10000 3\n", "10000 2000000000\n" ], "output": [ "72346.605605857597617", "96047.419624953886704", "1000.000000000000000", "1000.000...
1,200
0
2
12
656_F. Ace It!
Input The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output Output a single integer. Examples Input A221033 Output 21 Input A223635 Output 22 Input A232726 Outpu...
{ "input": [ "A232726\n", "A223635\n", "A221033\n" ], "output": [ "23\n", "22\n", "21\n" ] }
{ "input": [ "A222222\n", "A101010\n", "A999999\n", "A910224\n", "A232232\n", "A767653\n", "A458922\n", "A764598\n", "A987654\n", "A332567\n", "A638495\n", "A234567\n", "A292992\n", "A102222\n", "A710210\n", "A987623\n", "A342987\n", "A101099\n",...
1,900
0
2
7
680_A. Bear and Five Cards
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards wi...
{ "input": [ "7 9 3 1 8\n", "7 3 7 3 20\n", "10 10 10 10 10\n" ], "output": [ "28\n", "26\n", "20\n" ] }
{ "input": [ "1 2 2 2 2\n", "20 21 22 23 24\n", "8 8 8 2 2\n", "1 90 1 91 1\n", "1 1 1 1 4\n", "1 1 1 1 2\n", "2 2 2 100 100\n", "1 2 3 4 5\n", "98 99 100 99 100\n", "1 1 1 8 1\n", "100 100 100 100 100\n", "1 1 1 1 1\n", "1 1 2 2 5\n", "98 98 98 98 23\n", "6...
800
500
2
13
746_G. New Roads
There are n cities in Berland, each of them has a unique id — an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads. That is why there was a decision to build n - 1 roads so that there will be exactly one simple path between each pair of cit...
{ "input": [ "7 3 3\n2 3 1\n", "3 1 1\n2\n", "14 5 6\n4 4 2 2 1\n" ], "output": [ "7\n1 2\n1 3\n2 4\n3 5\n2 6\n4 7\n", "-1\n", "14\n1 2\n1 3\n1 4\n1 5\n2 6\n3 7\n4 8\n5 9\n6 10\n6 11\n10 12\n10 13\n12 14\n" ] }
{ "input": [ "2000 3 1337\n970 632 397\n", "2001 34 1714\n28 91 43 47 52 42 69 95 11 70 59 68 88 92 71 19 7 70 100 66 1 38 36 88 58 52 87 85 40 75 26 42 85 99\n", "2 1 1\n1\n", "17 5 11\n5 3 2 5 1\n", "5 4 4\n1 1 1 1\n", "11 6 4\n1 2 2 1 3 1\n", "5 4 3\n1 1 1 1\n", "14 5 6\n4 4 2 2 1\n...
2,100
3,000
2
10
814_D. An overnight dance in discotheque
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which i...
{ "input": [ "5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1\n", "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8\n" ], "output": [ "138.230076757951\n", "289.026524130261\n" ] }
{ "input": [ "2\n281573 0 281573\n706546 0 706546\n", "1\n72989 14397 49999\n", "20\n-961747 0 961747\n-957138 0 957138\n-921232 0 921232\n-887450 0 887450\n-859109 0 859109\n-686787 0 686787\n-664613 0 664613\n-625553 0 625553\n-464803 0 464803\n-422784 0 422784\n-49107 0 49107\n-37424 0 37424\n134718 0 ...
2,000
1,750
2
10
83_D. Numbers
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ...
{ "input": [ "12 23 3\n", "1 10 2\n", "6 19 5\n" ], "output": [ "2\n", "5\n", "0\n" ] }
{ "input": [ "1 2000000000 10007\n", "19431 20000000 17\n", "1570000 800000000 30011\n", "1000 2000000000 211\n", "1999999000 2000000000 23\n", "1 2000000000 23\n", "44711 44711 44711\n", "1 2000000000 44711\n", "300303 600000 503\n", "1000000000 2000000000 4001\n", "500223...
2,400
2,000
2
11
909_E. Coprocessor
You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular dependencies between tasks. A task can only be executed if all tasks it depen...
{ "input": [ "4 3\n1 1 1 0\n0 1\n0 2\n3 0\n", "4 3\n0 1 0 1\n0 1\n1 2\n2 3\n" ], "output": [ "1", "2" ] }
{ "input": [ "2 1\n0 1\n0 1\n", "10 14\n1 1 0 0 1 0 1 0 1 1\n0 1\n0 2\n0 4\n0 9\n1 3\n2 5\n3 4\n3 6\n3 8\n4 9\n5 6\n6 7\n7 8\n7 9\n", "10 19\n0 0 0 0 0 0 0 0 1 1\n0 1\n0 3\n0 4\n1 2\n1 3\n1 4\n1 5\n1 7\n1 8\n1 9\n2 3\n2 4\n3 4\n3 5\n4 6\n4 8\n5 7\n6 7\n7 9\n", "10 9\n1 1 1 0 1 1 0 1 0 1\n0 1\n0 4\n0 5...
1,900
2,000
2
8
931_B. World Cup
The last stage of Football World Cup is played using the play-off system. There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the four...
{ "input": [ "4 1 2\n", "8 7 5\n", "8 2 6\n" ], "output": [ "1", "2", "Final!" ] }
{ "input": [ "4 1 4\n", "16 2 4\n", "4 1 3\n", "4 3 4\n", "8 8 5\n", "4 4 2\n", "256 178 166\n", "16 4 3\n", "8 8 7\n", "256 255 129\n", "4 2 4\n", "16 3 11\n", "256 2 127\n", "4 4 3\n", "4 2 1\n", "8 2 3\n", "64 50 43\n", "8 7 8\n", "64 60 5...
1,200
1,000
2
8
985_B. Switches and Lamps
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are t...
{ "input": [ "4 5\n10100\n01000\n00110\n00101\n", "4 5\n10101\n01000\n00111\n10000\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "3 5\n11100\n00110\n00011\n", "3 4\n1010\n0100\n1101\n", "2 5\n01000\n11111\n", "2 3\n101\n111\n", "2 5\n10000\n11111\n", "4 2\n10\n01\n10\n01\n", "3 3\n010\n101\n000\n", "2 6\n111111\n000000\n", "3 5\n00000\n10101\n01010\n", "2 3\n100\n111\n", "1 1\n1\n", ...
1,200
0
2
7
1012_A. Photo of The Sky
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x...
{ "input": [ "4\n4 1 3 2 3 2 1 3\n", "3\n5 8 5 5 7 5\n" ], "output": [ "1", "0" ] }
{ "input": [ "2\n81475384 79354071 83089784 94987161\n", "2\n229872385 40870434 490042790 160550871\n", "2\n95988141 53257147 119443802 199984654\n", "2\n100000001 95312501 97600001 1\n", "2\n186213023 151398020 526707498 169652181\n", "1\n1 1\n", "2\n1 499999999 705032704 1000000000\n", ...
1,500
500
2
7
1037_A. Packets
You have n coins, each of the same value of 1. Distribute them into packets such that any amount x (1 ≤ x ≤ n) can be formed using some (possibly one or all) number of these packets. Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single x, howeve...
{ "input": [ "6\n", "2\n" ], "output": [ "3\n", "2\n" ] }
{ "input": [ "723061816\n", "40052789\n", "8\n", "1\n", "33554432\n", "517188853\n", "237913214\n", "1023\n", "536870911\n", "781222222\n", "952679912\n", "56546546\n", "33554434\n", "33554430\n", "543654364\n", "1000000000\n", "96145460\n", "654...
1,300
500
2
8
105_B. Dark Assembly
Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed. The Dark Assembly consists of n senators. Each of...
{ "input": [ "5 3 100\n11 80\n14 90\n23 70\n80 30\n153 70\n", "5 6 100\n11 80\n14 90\n23 70\n80 30\n153 70\n", "1 3 20\n20 20\n" ], "output": [ "0.9628442962\n", "1.0000000000\n", "0.7500000000\n" ] }
{ "input": [ "1 7 10\n40 40\n", "1 4 30\n10 20\n", "8 1 9999\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n", "2 4 345\n323 40\n234 20\n", "8 7 1\n1 90\n2 0\n3 80\n4 0\n5 80\n6 0\n7 80\n8 90\n", "3 1 4887\n5 60\n9 80\n6 40\n", "8 3 6395\n8159 90\n4143 50\n6954 50\n5011 20\n9872 10\n7689 90\n881...
1,800
1,000
2
9
1081_C. Colorful Bricks
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was s...
{ "input": [ "3 3 0\n", "3 2 1\n" ], "output": [ "3\n", "4\n" ] }
{ "input": [ "1859 96 1471\n", "555 1594 412\n", "1987 237 1286\n", "1 1 0\n", "3 3 2\n", "369 511 235\n", "918 1704 848\n", "1 534 0\n", "1939 407 1072\n", "22 1481 21\n", "289 393 19\n", "1446 1030 111\n", "1969 30 744\n", "50 2000 40\n", "1894 637 1635\n"...
1,500
1,500
2
9
1100_C. NN and the Optical Illusion
NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles: <image> It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar pi...
{ "input": [ "3 1\n", "100 100\n", "6 1\n" ], "output": [ "6.464101615", "3.242939086", "1" ] }
{ "input": [ "94 9\n", "4 35\n", "93 67\n", "45 52\n", "63 1\n", "4 2\n", "8 3\n", "25 2\n", "10 25\n", "5 6\n", "100 1\n", "16 9\n", "84 7\n", "10 5\n", "4 9\n", "4 90\n", "33 3\n", "13 13\n", "15 5\n", "83 1\n", "11 26\n", "7 3\...
1,200
1,500
2
7
1129_A1. Toy Train (Simplified)
This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled. 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...
{ "input": [ "5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n", "2 3\n1 2\n1 2\n1 2\n" ], "output": [ "10 9 10 10 9\n", "5 6\n" ] }
{ "input": [ "3 1\n3 1\n", "3 2\n2 1\n2 3\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 23\n19 39\n25 12\n", "10 8\n5 2\n6 5\n3 8\n9 10\n4 3\n9 5\n2 6\n9 10\n", "10 2\n9 2\n10 8\n", "3 2\n3 2\n1 2\n", "10 10\n6 1...
1,700
250
2
7
1149_A. Prefix Sum Primes
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in a...
{ "input": [ "9\n1 1 2 1 1 1 2 1 1\n", "5\n1 2 1 2 1\n" ], "output": [ "2 1 2 1 1 1 1 1 1\n", "2 1 2 1 1\n" ] }
{ "input": [ "10\n1 1 1 2 1 1 1 2 2 2\n", "1\n2\n", "10\n1 1 1 1 2 2 2 2 2 2\n", "5\n2 1 1 1 1\n", "4\n1 1 1 1\n", "5\n1 2 2 2 2\n", "214\n1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 1 1 2...
1,200
500
2
9
124_C. Prime Permutation
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1...
{ "input": [ "abcd\n", "abc\n", "xxxyxxx\n" ], "output": [ "NO\n", "YES\nabc", "YES\nxxxxxxy\n" ] }
{ "input": [ "xxxxxxxxxxfxxxxxxxxxxxxxxxxxxxxxxxxxxxrxtxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxexxxxmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoxxxxxxxxxxexxxxxxxxixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxtxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxuxxxxxxxxxxxxxxxxxxxx...
1,300
1,000
2
7
1269_A. Equation
Let's call a positive integer composite if it has at least one divisor other than 1 and itself. For example: * the following numbers are composite: 1024, 4, 6, 9; * the following numbers are not composite: 13, 1, 2, 3, 37. You are given a positive integer n. Find two composite integers a,b such that a-b=n. I...
{ "input": [ "512\n", "1\n" ], "output": [ "516 4\n", "9 8\n" ] }
{ "input": [ "100\n", "6767476\n", "7365657\n", "9999889\n", "14\n", "6415292\n", "9999999\n", "5\n", "19\n", "819893\n", "267\n", "9946581\n", "253574\n", "9999991\n", "12\n", "16\n", "865176\n", "107\n", "15\n", "2\n", "6\n", "9...
800
500
2
7
1291_A. Even But Not Even
Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by 2 but the number itself is not divisible by 2. For example, 13, 1227, 185217 are ebne numbers, while 12, 2, 177013, 265918 are not. If you're still unsure what ebne numbers are, you can look at the sample notes for more clar...
{ "input": [ "4\n4\n1227\n1\n0\n6\n177013\n24\n222373204424185217171912\n" ], "output": [ "17\n-1\n17\n37\n" ] }
{ "input": [ "36\n6\n165310\n6\n177978\n6\n211759\n6\n212643\n6\n229540\n6\n250029\n6\n211519\n6\n256097\n6\n163478\n5\n91505\n5\n79280\n6\n260629\n6\n128051\n6\n121972\n6\n261633\n6\n172044\n6\n119055\n6\n208323\n6\n149942\n6\n161236\n6\n177150\n6\n233766\n5\n97949\n6\n230107\n6\n175822\n6\n213545\n6\n232837\n6\...
900
500
2
8
1311_B. WeirdSort
You are given an array a of length n. You are also given a set of distinct positions p_1, p_2, ..., p_m, where 1 ≤ p_i < n. The position p_i means that you can swap elements a[p_i] and a[p_i + 1]. You can apply this operation any number of times for each of the given positions. Your task is to determine if it is poss...
{ "input": [ "6\n3 2\n3 2 1\n1 2\n4 2\n4 1 2 3\n3 2\n5 1\n1 2 3 4 5\n1\n4 2\n2 1 4 3\n1 3\n4 2\n4 3 2 1\n1 3\n5 2\n2 1 2 3 3\n1 4\n" ], "output": [ "YES\nNO\nYES\nYES\nNO\nYES\n" ] }
{ "input": [ "1\n7 4\n99 1 2 3 4 12 43\n1 3 4 2\n", "1\n6 4\n5 5 6 6 4 5\n1 4 5 3\n", "1\n9 7\n1 7 7 7 7 4 7 9 3\n1 8 2 4 7 6 3\n", "1\n5 3\n3 2 3 2 5\n1 4 2\n", "1\n3 1\n3 1 1\n1\n", "1\n8 6\n5 5 7 7 8 7 5 2\n3 5 4 1 7 6\n", "1\n4 2\n4 4 1 2\n2 1\n" ], "output": [ "NO\n", "NO\...
1,200
0
2
12
1333_F. Kate and imperfection
Kate has a set S of n integers \{1, ..., n\} . She thinks that imperfection of a subset M ⊆ S is equal to the maximum of gcd(a, b) over all pairs (a, b) such that both a and b are in M and a ≠ b. Kate is a very neat girl and for each k ∈ \{2, ..., n\} she wants to find a subset that has the smallest imperfection am...
{ "input": [ "3\n", "2\n" ], "output": [ "1 1", "1" ] }
{ "input": [ "6310\n", "11751\n", "40081\n", "6\n", "6209\n", "1002\n", "100\n", "102\n", "1004\n", "101\n", "4\n", "502\n", "500\n", "27287\n", "503\n", "501\n", "1003\n", "104\n", "54\n", "504\n", "23487\n", "1001\n", "6198\...
2,200
2,500
2
9
1354_C1. Simple Polygon Embedding
The statement of this problem is the same as the statement of problem C2. 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\n2\n4\n200\n" ], "output": [ "1.0000000000000002\n2.414213562373095\n127.32133646887215\n" ] }
{ "input": [ "100\n2\n4\n6\n8\n10\n12\n14\n16\n18\n20\n22\n24\n26\n28\n30\n32\n34\n36\n38\n40\n42\n44\n46\n48\n50\n52\n54\n56\n58\n60\n62\n64\n66\n68\n70\n72\n74\n76\n78\n80\n82\n84\n86\n88\n90\n92\n94\n96\n98\n100\n102\n104\n106\n108\n110\n112\n114\n116\n118\n120\n122\n124\n126\n128\n130\n132\n134\n136\n138\n140...
1,400
0
2
7
1374_A. Required Remainder
You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 ≤ k ≤ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it. In other words, with given x, y and n you need to find the maximum possible integer from 0 to n tha...
{ "input": [ "7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999\n" ], "output": [ "12339\n0\n15\n54306\n999999995\n185\n999999998\n" ] }
{ "input": [ "1\n31 2 104\n", "1\n43284 1 33424242\n", "1\n943643 1 23522222\n", "1\n33 6 100\n", "1\n1000000000 0 999999999\n", "1\n4452384 1 3573842\n" ], "output": [ "95\n", "33415249\n", "22647433\n", "72\n", "0\n", "1\n" ] }
800
0
2
8
1397_B. Power Sequence
Let's call a list of positive integers a_0, a_1, ..., a_{n-1} a power sequence if there is a positive integer c, so that for every 0 ≤ i ≤ n-1 then a_i = c^i. Given a list of n positive integers a_0, a_1, ..., a_{n-1}, you are allowed to: * Reorder the list (i.e. pick a permutation p of \{0,1,...,n - 1\} and change...
{ "input": [ "3\n1 3 2\n", "3\n1000000000 1000000000 1000000000\n" ], "output": [ "1\n", "1999982505\n" ] }
{ "input": [ "3\n377 9052790 230\n", "5\n1 1 912380429 929219321 1000000000\n", "3\n1 912387428 4\n", "16\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "4\n1 3 9 1...
1,500
1,000
2
9
1420_C2. Pokémon Army (hard version)
This is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved. Pikachu is a cute and friendly pokémon living in the wild pikachu herd. But it has become known recently that infamous team R...
{ "input": [ "3\n3 1\n1 3 2\n1 2\n2 2\n1 2\n1 2\n1 2\n7 5\n1 2 5 4 3 6 7\n1 2\n6 7\n3 4\n1 2\n2 3\n" ], "output": [ "3\n4\n2\n2\n2\n9\n10\n10\n10\n9\n11\n" ] }
{ "input": [ "5\n2 0\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n3 9\n1 2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n3 0\n3 2 1\n" ], "output": [ "2\n2\n2\n2\n2\n3\n4\n4\n3\n3\n3\n3\n4\n4\n3\n3\n" ] }
2,100
1,250
2
8
1439_B. Graph Subset Problem
You are given an undirected graph with n vertices and m edges. Also, you are given an integer k. Find either a clique of size k or a non-empty subset of vertices such that each vertex of this subset has at least k neighbors in the subset. If there are no such cliques and subsets report about it. A subset of vertices ...
{ "input": [ "3\n5 9 4\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n10 15 3\n1 2\n2 3\n3 4\n4 5\n5 1\n1 7\n2 8\n3 9\n4 10\n5 6\n7 10\n10 8\n8 6\n6 9\n9 7\n4 5 4\n1 2\n2 3\n3 4\n4 1\n1 3\n" ], "output": [ "2\n4 1 2 3 \n1 10\n1 2 3 4 5 6 7 8 9 10 \n-1\n" ] }
{ "input": [ "1\n15 17 4\n1 4\n1 3\n1 2\n2 3\n2 4\n3 4\n1 15\n1 14\n1 13\n1 12\n1 11\n1 10\n1 9\n1 8\n1 7\n1 6\n1 5\n" ], "output": [ "2\n2 1 3 4 \n" ] }
2,600
1,250
2
9
1490_C. Sum of Cubes
You are given a positive integer x. Check whether the number x is representable as the sum of the cubes of two positive integers. Formally, you need to check if there are two integers a and b (1 ≤ a, b) such that a^3+b^3=x. For example, if x = 35, then the numbers a=2 and b=3 are suitable (2^3+3^3=8+27=35). If x=4, t...
{ "input": [ "7\n1\n2\n4\n34\n35\n16\n703657519796\n" ], "output": [ "\nNO\nYES\nNO\nNO\nYES\nYES\nYES\n" ] }
{ "input": [ "3\n999998011905\n999998011906\n999998011907\n", "8\n420587971613\n681238648792\n817378345476\n509923060101\n202232821384\n387799635832\n215157629382\n698361920355\n", "3\n999700029999\n999700030000\n999700030001\n", "4\n997921168127\n998109323136\n236281750946\n998109513504\n", "2\n9...
1,100
0
2
8
167_B. Wizards and Huge Prize
One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees. One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've b...
{ "input": [ "3 1 0\n10 20 30\n-1 -1 2\n", "1 1 1\n100\n123\n" ], "output": [ "0.3000000\n", "1.0000000\n" ] }
{ "input": [ "17 5 17\n69 43 30 9 17 75 43 42 3 10 47 90 82 47 1 51 31\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "12 6 12\n98 44 95 72 87 100 72 60 34 5 30 78\n6 1 3 1 3 1 1 1 1 3 1 5\n", "82 77 11\n100 56 83 61 74 15 44 60 25 4 78 16 85 93 4 10 40 16 74 89 73 20 75 20 57 48 19 46 44 43 48 4...
1,800
1,000
2
7
209_A. Multicolored Marbles
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebr...
{ "input": [ "3\n", "4\n" ], "output": [ "6", "11" ] }
{ "input": [ "11500\n", "999999\n", "7\n", "10\n", "19\n", "4994\n", "2\n", "3410\n", "12\n", "999996\n", "838069\n", "1000000\n", "999997\n", "5\n", "40\n", "63405\n", "8\n", "999998\n", "21\n", "18\n", "22\n", "100\n", "17\n...
1,600
500
2
9
25_C. Roads in Berland
There are n cities numbered from 1 to n in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance betw...
{ "input": [ "2\n0 5\n5 0\n1\n1 2 3\n", "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n" ], "output": [ "3\n", "17 12\n" ] }
{ "input": [ "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763\n", "5\n0 954 1255 266 751\n954 0 1677 688 1173\n1255 1677 0 989 504\n266 688 989 0 485\n751 1173 504 485 0\n5\n5 2 837\n3 4 692\n3 5 756\n3 1 151\n2 5 262\n", "4\n0 537 1064 656\n537 0 527 119\n1064 527 0 408\n656 119 408 0\n4...
1,900
0
2
7
354_A. Vasya and Robot
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms. Vasya needs to collect all these items, however he won't do it by himself. He us...
{ "input": [ "3 4 4 19 1\n42 3 99\n", "4 7 2 3 9\n1 2 3 4\n" ], "output": [ "576\n", "34\n" ] }
{ "input": [ "2 3 4 5 6\n1 2\n", "5 1 100 10000 1\n1 2 3 4 5\n", "2 100 100 10000 10000\n100 100\n", "7 13 3 978 30\n7 1 5 4 3 2 1\n", "7 3 13 30 978\n1 2 3 4 5 1 7\n", "5 1 100 1 10000\n1 2 3 4 5\n", "1 94 78 369 10000\n93\n", "6 32 47 965 897\n7 4 1 3 5 4\n", "5 100 1 10000 1\n1 ...
1,500
500
2
8
378_B. Semifinals
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in their semifinals and all other places in the finals go to the peopl...
{ "input": [ "4\n9840 9920\n9860 9980\n9930 10020\n10040 10090\n", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110\n" ], "output": [ "1110\n1100\n", "1100\n1100\n" ] }
{ "input": [ "3\n1 3\n2 4\n6 5\n", "3\n1 3\n2 5\n4 6\n", "4\n1 3\n2 4\n7 5\n8 6\n", "4\n5 1\n6 2\n7 3\n8 4\n", "3\n1 2\n4 3\n6 5\n", "4\n2 1\n3 4\n6 5\n7 8\n", "3\n2 1\n4 3\n5 6\n", "3\n1 3\n2 4\n5 6\n", "3\n1 4\n2 5\n3 6\n", "2\n3 1\n4 2\n", "3\n1 2\n3 4\n5 6\n", "3\n1...
1,300
1,000
2
10
39_D. Cubical Planet
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0, 0, 0) and (1, 1, 1). Two flies live on the planet. At the moment ...
{ "input": [ "0 0 0\n1 1 1\n", "0 0 0\n0 1 0\n", "1 1 0\n0 1 0\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "1 0 0\n0 0 0\n", "1 1 0\n0 0 1\n", "1 1 1\n0 1 1\n", "0 0 1\n1 0 0\n", "1 1 1\n0 0 0\n", "1 0 0\n0 1 0\n", "1 0 0\n0 1 1\n", "0 0 1\n1 0 1\n", "0 1 0\n0 1 1\n", "1 0 1\n0 1 0\n", "1 0 0\n0 0 1\n", "1 0 1\n0 0 0\n", "0 0 1\n1 1 1\n", "0 1 1\n1 1 1\n...
1,100
0
2
9
449_C. Jzzhu and Apples
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store. Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater...
{ "input": [ "6\n", "9\n", "2\n" ], "output": [ "2\n3 6\n2 4\n", "3\n3 9\n2 4\n6 8\n", "0\n" ] }
{ "input": [ "10\n", "5\n", "3\n", "5249\n", "30011\n", "100\n", "10007\n", "1\n" ], "output": [ "4\n5 10\n3 9\n2 4\n6 8\n", "1\n2 4\n", "0\n", "2466\n3 9\n12 15\n18 21\n24 27\n30 33\n36 39\n42 45\n48 51\n54 57\n60 63\n66 69\n72 75\n78 81\n84 87\n90 93\n96 99\n102 1...
2,500
1,500
2
11
493_E. Vasya and Polynomial
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial. Vasya has made a bet with his friends that h...
{ "input": [ "2 3 3\n", "2 2 2\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "1 2 5\n", "1000000000000000000 1000000000000000000 1000000000000000000\n", "135645 1 365333453\n", "1 12 1728\n", "110 1000 998\n", "1 5 5\n", "1 3 6561\n", "563236 135645 356563\n", "1 10 999999999999999999\n", "5 5 4\n", "1 999999999 1000000000000000000\n", ...
2,800
3,000
2
10
518_D. Ilya and Escalator
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue ente...
{ "input": [ "1 0.50 1\n", "4 0.20 2\n", "1 0.50 4\n" ], "output": [ "0.500000000000\n", "0.400000000000\n", "0.937500000000\n" ] }
{ "input": [ "4 0.20 2\n", "1 0.01 2000\n", "87 0.95 156\n", "2000 0.01 234\n", "211 0.78 379\n", "1 0.50 4\n", "2000 1.00 2000\n", "639 0.81 1150\n", "300 0.99 1000\n", "539 0.54 970\n", "415 0.72 747\n", "2000 0.99 2000\n", "400 0.96 1754\n", "100 0.01 53\n", ...
1,700
2,000
2
10
544_D. Destroying Roads
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ...
{ "input": [ "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1\n", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n" ], "output": [ "-1\n", "0\n", "1\n" ] }
{ "input": [ "2 1\n1 2\n1 1 0\n1 2 0\n", "1 0\n1 1 0\n1 1 0\n", "2 1\n1 2\n1 1 0\n1 2 1\n", "6 5\n1 2\n2 3\n3 4\n3 5\n2 6\n1 4 3\n5 6 3\n", "9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\n3 6 3\n", "10 11\n1 3\n2 3\n3 4\n4 5\n4 6\n3 7\n3 8\n4 9\n4 10\n7 9\n8 10\n1 5 3\n6 2 3\n", ...
2,100
1,000
2
7
571_A. Lengthening Sticks
You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most l centimeters. In particular, it is allowed not to increase the l...
{ "input": [ "1 1 1 2\n", "1 2 3 1\n", "10 2 1 7\n" ], "output": [ "4\n", "2\n", "0\n" ] }
{ "input": [ "53553 262850 271957 182759\n", "5276 8562 1074 8453\n", "5 7 30 100\n", "3 5 7 300000\n", "17 28 19 5558\n", "300000 200000 100000 0\n", "2958 4133 233463 259655\n", "100000 300000 100000 100100\n", "100000 300000 100000 100003\n", "4 2 5 28\n", "100000 300000...
2,100
750
2
10
592_D. Super M
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go ...
{ "input": [ "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7\n", "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6\n" ], "output": [ "2\n3", "2\n4" ] }
{ "input": [ "10 3\n10 5\n3 2\n6 8\n1 5\n10 4\n6 1\n9 8\n2 9\n7 3\n3 9 1\n", "16 8\n16 12\n16 15\n15 9\n15 13\n16 3\n15 2\n15 10\n1 2\n6 16\n5 15\n2 7\n15 4\n14 15\n11 16\n8 5\n5 10 14 6 8 3 1 9\n", "8 5\n2 5\n1 8\n6 7\n3 4\n6 8\n8 5\n5 3\n1 6 7 3 8\n", "15 2\n7 12\n13 11\n6 8\n2 15\n10 9\n5 1\n13 5\n...
2,200
2,000
2
8
614_B. Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
{ "input": [ "3\n5 10 1\n", "5\n0 3 1 100 1\n", "4\n1 1 10 11\n" ], "output": [ "50", "0\n", "110" ] }
{ "input": [ "3\n500 1 10\n", "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000\n", "1\n0\n", "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 18...
1,400
1,000
2
8
662_B. Graph Coloring
You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edge...
{ "input": [ "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n", "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n", "3 3\n1 2 B\n3 1 R\n3 2 B\n" ], "output": [ "-1", "2\n3 4 ", "1\n2 " ] }
{ "input": [ "6 6\n1 2 R\n1 3 R\n2 3 R\n4 5 B\n4 6 B\n5 6 B\n", "2 1\n1 2 B\n", "3 3\n1 2 R\n1 3 R\n2 3 R\n", "11 7\n1 2 B\n1 3 R\n3 2 R\n4 5 R\n6 7 R\n8 9 R\n10 11 R\n" ], "output": [ "-1", "0\n", "0\n", "5\n3 4 6 8 10 \n" ] }
2,200
250
2
10
709_D. Recover the String
For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of the string s equal to the sequence {x, y}. In these problem you are given four integers a00, a01, a10, a11 and have to find any non-empty string s that matc...
{ "input": [ "1 2 3 4\n", "1 2 2 1\n" ], "output": [ "Impossible", "0110" ] }
{ "input": [ "999872121 999894480 999894481 999872121\n", "20946628 20410736 263003096 958497436\n", "499833153 999381744 0 499517028\n", "89253 254334 736333 2741312\n", "0 0 0 45\n", "499517028 999065664 0 499517028\n", "4950 51367 5033 158766\n", "10 0 0 6\n", "499580245 9988760...
1,900
1,000
2
7
754_A. Lesha and array splitting
One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one...
{ "input": [ "4\n1 2 3 -5\n", "1\n0\n", "8\n9 -12 3 4 -4 -10 7 3\n", "3\n1 2 -3\n" ], "output": [ "YES\n1\n1 4\n", "NO\n", "YES\n2\n1 1\n2 8\n", "YES\n2\n1 1\n2 3\n" ] }
{ "input": [ "8\n9 -12 3 4 -4 -10 7 3\n", "3\n0 0 0\n", "1\n1\n", "7\n0 0 0 0 3 -3 0\n", "4\n0 0 0 1\n", "4\n3 -2 -1 3\n", "5\n-3 2 2 0 -2\n", "3\n0 -1 0\n", "100\n-98 369 544 197 -991 231 399 521 582 -820 -650 -919 -615 -411 -843 -974 231 140 239 -209 721 84 -834 -27 162 460 -157 ...
1,200
500
2
16
774_J. Stepan's Series
Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the maximum num...
{ "input": [ "6 1\n????NN\n", "5 2\nNYNNY\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "100 1\nYYYYYYYYY??YYN?YYNYYYYYYYNYYYYYYYYYYY?YN?YYYYY?YYYYYYYYYYYYY?YYYYYYYYYYYYN?YYYYYYYY?YYYYY?YYNYYYYYNY\n", "100 3\n?YNNYYNYYYYYYNYYYYYNY?NNYYYYNYY??NYYNYNYYYY?YYNYYNYYYYYYYYYYNYYYYNYYYYNYYYYNYYNYYYYYYNYNYNYYYYYYNNYY\n", "100 74\nNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
2,000
0
2
9
79_C. Beaver
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly. However, Ciel fee...
{ "input": [ "unagioisii\n2\nioi\nunagi\n", "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse\n", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd\n" ], "output": [ "5 1", "12 4", "0 0" ] }
{ "input": [ "ahmed\n5\nahmed\nhmed\nmed\ned\nd\n", "iiiiii\n10\nii\niiii\niiiii\niii\niiii\n5avjcwIsDh\nGgiVQ9ylRz\newWmNAJAL9\nk83baq5H2U\nXRX3fJ4dH8\n", "7hh77hhhhhh7h\n10\nhhhh7\nhh77hhhhh\n7hhhhh\nhh7\nh77hhhhhh7\nC_t1uIxLWp\nHwH5EkVGCt\nyUgWASGwfR\nRfah5Fa12E\nS9CmGvTVKM\n", "x5x5\n10\nx5\nx5x\n...
1,800
1,500
2
7
846_A. Curriculum Vitae
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero)...
{ "input": [ "6\n0 1 0 0 1 0\n", "1\n0\n", "4\n1 1 0 1\n" ], "output": [ "4\n", "1\n", "3\n" ] }
{ "input": [ "4\n1 0 0 1\n", "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1\n", "1\n1\n", "3\n1 0 0\n", "3\n1 0 1\n", "100\n0 0 0 0 0 0...
1,500
0
2
9
867_C. Ordering Pizza
It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices. It is known that the i-th contestant will eat si slices of pizza, and gain ai ...
{ "input": [ "6 10\n7 4 7\n5 8 8\n12 5 8\n6 11 6\n3 3 7\n5 9 6\n", "3 12\n3 5 7\n4 6 7\n5 9 5\n" ], "output": [ "314\n", "84\n" ] }
{ "input": [ "25 6\n1 10 5\n1 8 4\n1 8 2\n4 8 9\n3 2 8\n1 9 5\n2 10 10\n3 9 6\n3 5 4\n2 7 8\n2 3 2\n2 6 8\n3 7 8\n4 3 7\n1 8 1\n3 6 4\n3 2 8\n2 2 1\n4 8 8\n4 8 4\n3 10 2\n3 6 6\n2 2 5\n1 6 2\n4 1 5\n", "3 5\n6 4 5\n6 5 5\n8 7 5\n", "2 9\n6 1 7\n6 7 1\n", "2 10\n7 2 1\n7 1 2\n", "2 3\n2 10 1\n2 1 1...
1,900
1,000
2
11
914_E. Palindromes in a Tree
You are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t. A path in the tree is said to be palindromic if at least one permutation of the labels in the path is a palindrome. For each vertex, output the number of pa...
{ "input": [ "7\n6 2\n4 3\n3 7\n5 2\n7 2\n1 4\nafefdfs\n", "5\n1 2\n2 3\n3 4\n3 5\nabcbb\n" ], "output": [ "1 4 1 1 2 4 2\n", "1 3 4 3 3\n" ] }
{ "input": [ "10\n10 8\n3 2\n9 7\n1 5\n5 3\n7 6\n8 4\n10 9\n2 6\nqbilfkqcll\n", "20\n10 9\n15 14\n11 12\n2 3\n15 16\n2 1\n18 19\n20 19\n8 9\n7 6\n8 7\n12 13\n5 6\n4 3\n13 14\n18 17\n11 10\n16 17\n5 4\naabbccddeeffgghhiijj\n", "5\n3 1\n3 5\n5 4\n5 2\nticdm\n" ], "output": [ "1 1 1 2 1 1 2 3 4 5\n",...
2,400
2,500
2
9
937_C. Save Energy!
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The s...
{ "input": [ "4 2 20\n", "3 2 6\n" ], "output": [ "20.0\n", "6.5\n" ] }
{ "input": [ "963276084 698548036 1000000000\n", "18036 47899 1000000000\n", "200 10 979220166595737684\n", "740 251 930540301905511549\n", "1000 1000 1000000000000000000\n", "9999999999 33333 1000000000\n", "121 395 621154158314692955\n", "20958318104 46685 253251869\n", "3950 738...
1,700
500
2
11
962_E. Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis Ox. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line Ox there are three types of cities: * the cities of Byteland, * the cities of Berland, * disputed cities. Recent...
{ "input": [ "5\n10 R\n14 B\n16 B\n21 R\n32 R\n", "4\n-5 R\n0 P\n3 P\n7 B\n" ], "output": [ "24\n", "12\n" ] }
{ "input": [ "2\n1 R\n2 R\n", "6\n0 B\n3 P\n7 B\n9 B\n11 P\n13 B\n", "9\n-105 R\n-81 B\n-47 P\n-25 R\n-23 B\n55 P\n57 R\n67 B\n76 P\n", "2\n-1000000000 P\n1000000000 P\n", "6\n-8401 R\n-5558 P\n-3457 P\n-2361 R\n6966 P\n8140 B\n", "6\n-13 R\n-10 P\n-6 R\n-1 P\n4 R\n10 P\n", "10\n61 R\n64 R...
2,200
0
2
7
990_A. Commentary Boxes
Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built n commentary boxes. m regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be...
{ "input": [ "30 6 17 19\n", "2 7 3 7\n", "9 7 3 8\n" ], "output": [ "0\n", "14\n", "15\n" ] }
{ "input": [ "29 6 1 2\n", "100000000000 3 1 1\n", "13 4 1 10\n", "16 7 3 2\n", "7 2 3 7\n", "999 2 1 1\n", "6 7 41 42\n", "999999999999 2 1 1\n", "7 3 100 10\n", "500000000001 1000000000000 100 100\n", "9 2 1 1\n", "10000 3 1 1\n", "1144108931 470211273 45 79\n", ...
1,000
0
2
9
1043_C. Smallest Word
IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting. Today, when IA looked at the fridge, she noticed that...
{ "input": [ "bbab\n", "aaaaa\n" ], "output": [ "0 1 1 0\n", "0 0 0 0 1\n" ] }
{ "input": [ "ababbbaaababbbaaaabb\n", "abaaba\n", "babbbbabbbbbbabababa\n", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "b\n", "aaaabaaaabaaaabaaaab\n", "babbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaababbaabab...
1,500
1,500
2
7
1066_A. Vova and Train
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2 and so on). There are lanterns on the...
{ "input": [ "4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000\n" ], "output": [ "3\n0\n1134\n0\n" ] }
{ "input": [ "1\n12599 3 1 2\n", "1\n2 5 1 1\n", "10\n10 1 1 1\n10 1 1 2\n10 1 1 3\n10 1 1 4\n10 1 1 5\n10 1 1 6\n10 1 1 7\n10 1 1 8\n10 1 1 9\n10 1 1 10\n", "1\n100 2 61 62\n", "1\n3 4 3 3\n", "1\n10 1 9 10\n", "10\n10 2 1 1\n10 2 1 2\n10 2 1 3\n10 2 1 4\n10 2 1 5\n10 2 1 6\n10 2 1 7\n10 ...
1,100
0
2
12
1107_F. Vasya and Endless Credits
Vasya wants to buy himself a nice new car. Unfortunately, he lacks some money. Currently he has exactly 0 burles. However, the local bank has n credit offers. Each offer can be described with three numbers a_i, b_i and k_i. Offers are numbered from 1 to n. If Vasya takes the i-th offer, then the bank gives him a_i bur...
{ "input": [ "4\n10 9 2\n20 33 1\n30 115 1\n5 3 2\n", "3\n40 1 2\n1000 1100 5\n300 2 1\n" ], "output": [ "32\n", "1337\n" ] }
{ "input": [ "1\n10 4 44\n", "8\n58 29 4\n40 74 5\n54 27 1\n18 74 4\n5 8 1\n25 18 3\n90 28 3\n3 7 5\n" ], "output": [ "10\n", "147\n" ] }
2,600
0
2
7
1137_A. Skyscrapers
Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by n streets along the Eastern direction and m streets across the Southern direction. Naturally, this city has nm intersections. At any intersection of i-th Eastern street and j-th Southern street there is a monument...
{ "input": [ "2 2\n1 2\n3 4\n", "2 3\n1 2 1\n2 1 2\n" ], "output": [ "2 3 \n3 2 \n", "2 2 2 \n2 2 2 \n" ] }
{ "input": [ "2 1\n179\n179\n", "1 2\n57 57\n", "2 2\n17 56\n12 8\n", "1 4\n1 5 4 3\n", "2 2\n1 2\n3 1\n", "2 2\n1 1\n1 1\n", "4 3\n1 2 3\n10 11 4\n9 12 5\n8 7 6\n", "5 5\n1 2 10 1 1\n2 1 20 2 1\n11 13 14 15 16\n2 5 10 3 7\n1 1 1 1 1\n", "2 1\n179\n1329\n", "1 1\n1543\n", "...
1,600
500
2
9
1155_C. Alarm Clocks Everywhere
Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the i-th of them will start during the x_i-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in such a way that it rings during minutes x_1, x_2, ..., x_n, so he will be awak...
{ "input": [ "3 5\n3 12 18\n2 6 5 3 3\n", "4 2\n1 5 17 19\n2 1\n", "4 2\n1 5 17 19\n4 5\n" ], "output": [ "YES\n 3 4\n", "YES\n 1 1\n", "NO\n" ] }
{ "input": [ "2 1\n500000000000000000 1000000000000000000\n700000000\n", "2 1\n1 999999998000000002\n999999999\n", "5 3\n6 24 25 31 121\n6 5 9\n", "2 2\n1 1000000000000000000\n1000000000000000000 1000000000000000000\n", "2 1\n500000000000000000 1000000000000000000\n567567\n", "4 1\n1 3 7 12\n2...
1,300
0
2
8
1177_B. Digits Sequence (Hard Edition)
Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the k-th digit of this sequence. Input The first and only lin...
{ "input": [ "21\n", "7\n" ], "output": [ "5\n", "7\n" ] }
{ "input": [ "511\n", "2879\n", "4\n", "2900\n", "100000000083\n", "417\n", "68888890\n", "9993\n", "2889\n", "9992\n", "99999999996\n", "6\n", "300\n", "8888888888\n", "521\n", "2883\n", "99999999997\n", "8888888893\n", "196\n", "1253123...
1,800
1,000
2
9
1236_C. Labs
In order to do some research, n^2 labs are built on different heights of a mountain. Let's enumerate them with integers from 1 to n^2, such that the lab with the number 1 is at the lowest place, the lab with the number 2 is at the second-lowest place, …, the lab with the number n^2 is at the highest place. To transpor...
{ "input": [ "3\n" ], "output": [ "1 6 7 \n2 5 8 \n3 4 9 \n" ] }
{ "input": [ "44\n", "91\n", "20\n", "131\n", "9\n", "63\n", "35\n", "75\n", "3\n", "87\n", "123\n", "115\n", "6\n", "29\n", "79\n", "26\n", "103\n", "50\n", "41\n", "99\n", "59\n", "107\n", "32\n", "5\n", "10\n", ...
1,300
1,000
2
8
1254_B1. Send Boxes to Alice (Easy Version)
This is the easier version of the problem. In this version, 1 ≤ n ≤ 10^5 and 0 ≤ a_i ≤ 1. You can hack this problem only if you solve and lock both problems. Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare n boxes o...
{ "input": [ "1\n1\n", "3\n1 0 1\n" ], "output": [ "-1", "2\n" ] }
{ "input": [ "6\n1 1 0 0 0 1\n", "100\n1 1 0 1 1 1 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1\n", "100\n1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0...
1,800
500
2
7
1278_A. Shuffle Hashing
Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems. Polycarp decided to store the hash of the password, generated by the following algorithm: 1. take the password p, consisting of lowercase Latin letters, and shuffle the l...
{ "input": [ "5\nabacaba\nzyxaabcaabkjh\nonetwothree\nthreetwoone\none\nzzonneyy\none\nnone\ntwenty\nten\n" ], "output": [ "YES\nYES\nNO\nYES\nNO\n" ] }
{ "input": [ "1\ndaaaaaaaa\nbbbbbbbbb\n", "1\na\nabcd\n", "2\nabacaba\nzyxaabcaabkjh\nonetwothree\nthreetwoone\n" ], "output": [ "NO\n", "YES\n", "YES\nYES\n" ] }
1,000
0
2
8
1321_B. Journey Planning
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n. Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to som...
{ "input": [ "7\n8 9 26 11 12 29 14\n", "6\n10 7 1 9 10 15\n", "1\n400000\n" ], "output": [ "55\n", "26\n", "400000\n" ] }
{ "input": [ "5\n2 2 4 5 5\n", "6\n1 3 3 5 6 8\n", "5\n2 2 4 4 8\n", "6\n3 2 5 6 8 10\n", "5\n2 4 4 4 5\n", "4\n1 3 3 5\n", "6\n4 4 4 8 6 8\n", "2\n2 2\n", "9\n1 3 1 2 6 3 4 5 9\n", "10\n10 60 12 13 14 15 16 66 18 130\n", "6\n2 3 4 8 8 9\n", "2\n399999 400000\n", "4...
1,400
500
2
7
1362_A. Johnny and Ancient Computer
Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can m...
{ "input": [ "10\n10 5\n11 44\n17 21\n1 1\n96 3\n2 128\n1001 1100611139403776\n1000000000000000000 1000000000000000000\n7 1\n10 8\n" ], "output": [ "1\n1\n-1\n0\n2\n2\n14\n0\n-1\n-1\n" ] }
{ "input": [ "1\n703687441776640 327680\n" ], "output": [ "11\n" ] }
1,000
500
2
9
1382_C1. 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
1471_A. Strange Partition
You are given an array a of length n, and an integer x. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was [3, 6, 9], in a single operation one can replace the last two elements by their ...
{ "input": [ "2\n3 3\n3 6 9\n3 3\n6 4 11\n" ], "output": [ "\n6 6\n7 8\n" ] }
{ "input": [ "1\n1 1234\n1\n", "1\n6 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "1\n10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "1\n20 2\n536870912 536870912 536870912 536870912 536870912 53687091...
900
500
2
11
1547_E. Air Conditioners
On a strip of land of length n there are k air conditioners: the i-th air conditioner is placed in cell a_i (1 ≤ a_i ≤ n). Two or more air conditioners cannot be placed in the same cell (i.e. all a_i are distinct). Each air conditioner is characterized by one parameter: temperature. The i-th air conditioner is set to ...
{ "input": [ "5\n\n6 2\n2 5\n14 16\n\n10 1\n7\n30\n\n5 5\n3 1 4 2 5\n3 1 4 2 5\n\n7 1\n1\n1000000000\n\n6 3\n6 1 3\n5 5 5\n" ], "output": [ "15 14 15 16 16 17 \n36 35 34 33 32 31 30 31 32 33 \n1 2 3 4 5 \n1000000000 1000000001 1000000002 1000000003 1000000004 1000000005 1000000006 \n5 6 5 6 6 5 \n" ] }
{ "input": [ "1\n\n10 1\n1\n1000000000\n", "1\n\n10 1\n10\n1000000000\n", "1\n\n100 1\n1\n1000000000\n", "1\n\n20 1\n20\n1000000000\n", "1\n\n13 1\n13\n1000000000\n", "5\n\n6 2\n2 5\n14 16\n\n10 1\n7\n30\n\n5 5\n3 1 4 2 5\n3 1 4 2 5\n\n70 1\n1\n1000000000\n\n6 3\n6 1 3\n5 5 5\n" ], "output...
1,500
0
2
8
175_B. Plane of Tanks: Pro
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He ha...
{ "input": [ "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250\n", "3\nvasya 200\nkolya 1000\nvasya 1000\n" ], "output": [ "4\nartem noob\nigor pro\nkolya random\nvasya random\n", "2\nkolya pro\nvasya pro\n" ] }
{ "input": [ "10\nj 10\ni 9\nh 8\ng 7\nf 6\ne 5\nd 4\nc 3\nb 2\na 1\n", "5\nvasya 1000\nvasya 100\nkolya 200\npetya 300\noleg 400\n", "1\nvasya 1000\n", "1\ntest 0\n", "10\na 1\nb 2\nc 3\nd 4\ne 5\nf 6\ng 7\nh 8\ni 9\nj 10\n" ], "output": [ "10\na noob\nb noob\nc noob\nd noob\ne random\nf ...
1,400
500
2
9
195_C. Try and Catch
Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that. The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks: 1. The try op...
{ "input": [ "8\ntry\n try\n throw ( AE ) \n catch ( BE, \"BE in line 3\")\n\n try\n catch(AE, \"AE in line 5\") \ncatch(AE,\"AE somewhere\")\n", "8\ntry\n try\n throw ( AE ) \n catch ( AE, \"AE in line 3\")\n\n try\n catch(BE, \"BE in line 5\") \ncatch(AE,\"AE somewhere\...
{ "input": [ "3\ntry\nthrow ( X )\ncatch ( X, \"try again\")\n", "3\ntry\nthrow ( try )\ncatch ( try, \"try again\")\n", "11\ntry\n try\n catch (B, \"b\")\n \n try\n throw ( U )\n catch (U, \"try\")\n \n try\n catch (C, \"c\")\ncatch (A, \"a\")\n", "3\ntry\n throw(try)\ncatch(try,\"asd\")\n...
1,800
1,500
2
9
219_C. Color Stripe
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
{ "input": [ "3 2\nBBB\n", "6 3\nABBACC\n" ], "output": [ "1\nBAB", "2\nABCACA\n" ] }
{ "input": [ "6 2\nAABABA\n", "3 2\nBBA\n", "100 2\nBBBBBBBAAABBAAAABAABBBAABABAAABBBABBAAAABBABAAAAAAAAAAAAABAAABBBAAABAABBBBBBBABBBBAABAAABBBAABBAAAAB\n", "10 2\nBBABABABAB\n", "1 26\nZ\n", "8 3\nAABBABBB\n", "41 2\nAABAAABBBBBBAAAABBBAAAAAABBBBBBBBAAAAAAAA\n", "20 3\nCCCCAAAAAAAAAAA...
1,600
1,500
2
9
268_C. Beautiful Sets of Points
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all poi...
{ "input": [ "2 2\n", "4 3\n" ], "output": [ "3\n0 2\n1 1\n2 0\n", "4\n0 3\n1 2\n2 1\n3 0\n" ] }
{ "input": [ "9 6\n", "3 4\n", "6 6\n", "85 48\n", "1 5\n", "30 40\n", "88 88\n", "100 11\n", "10 6\n", "6 4\n", "21 21\n", "10 100\n", "80 91\n", "77 77\n", "96 96\n", "5 100\n", "3 19\n", "5 5\n", "16 55\n", "2 10\n", "13 13\n", ...
1,500
1,500
2
9
339_C. Xenia and Weights
Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes ...
{ "input": [ "0000000101\n3\n", "1000000000\n2\n" ], "output": [ "YES\n8 10 8\n", "NO\n" ] }
{ "input": [ "1110001001\n642\n", "0001110010\n1000\n", "1100000000\n3\n", "0111110111\n1000\n", "1110000000\n4\n", "0111100111\n32\n", "1101000011\n1000\n", "0110010001\n1000\n", "0110110000\n12\n", "1101010000\n1000\n", "1100100011\n494\n", "1101000001\n1000\n", "...
1,700
1,500
2
9
385_C. Bear and Prime Numbers
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represent the number of such indexes k, that xk is divisible by p. The answe...
{ "input": [ "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n", "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n" ], "output": [ "0\n7\n", "9\n7\n0\n" ] }
{ "input": [ "1\n6\n1\n2 3\n", "9\n9999991 9999943 9999883 4658161 4657997 2315407 2315263 1000003 1000033\n13\n9999991 9999991\n9999943 9999943\n9999883 9999883\n4658161 4658161\n4657997 4657997\n2315407 2315407\n2315263 2315263\n1000003 1000003\n1000033 1000033\n2 2000000000\n2000000000 2000000000\n9999992 ...
1,700
1,500
2
8
406_B. Toy Sum
Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris. There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them bac...
{ "input": [ "1\n1\n", "3\n1 4 5\n" ], "output": [ "1\n1000000 ", "3\n1000000 999997 999996 " ] }
{ "input": [ "4\n1 2 999999 1000000\n", "6\n1 10 100 1000 10000 1000000\n", "9\n1 2 3 100 500000 500001 999901 999997 999999\n", "10\n1 100000 199999 299998 399997 499996 599995 699994 799993 899992\n", "3\n1 2 3\n", "3\n5 345435 999996\n", "3\n1 4 5\n", "2\n2 999999\n", "2\n1 1000...
1,700
2,000
2
9
433_C. Ryouko's Memory Note
Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory. Though Ryouko is forgetful, she is also bo...
{ "input": [ "10 5\n9 4 3 8 8\n", "4 6\n1 2 3 4 3 2\n" ], "output": [ " 6\n", " 3\n" ] }
{ "input": [ "10 10\n8 8 8 7 7 7 6 1 1 1\n", "100000 50\n43104 45692 17950 43454 99127 33540 80887 7990 116 79790 66870 61322 5479 24876 7182 99165 81535 3498 54340 7460 43666 921 1905 68827 79308 59965 8437 13422 40523 59605 39474 22019 65794 40905 35727 78900 41981 91502 66506 1031 92025 84135 19675 67950 8...
1,800
1,500
2
9
478_C. Table Decorations
You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color? Your task is to write a program tha...
{ "input": [ "1 1 1\n", "5 4 3\n", "2 3 3\n" ], "output": [ "1\n", "4\n", "2\n" ] }
{ "input": [ "3 5 2\n", "0 1 0\n", "500000002 2000000000 500000001\n", "0 0 0\n", "1 1 9\n", "500000000 1000000000 500000000\n", "2000000000 1999999999 1999999999\n", "1000000000 1000000000 1000000000\n", "1000000000 2000000000 1000000000\n", "3 3 6\n", "0 3 3\n", "100 ...
1,800
1,500
2
11
500_E. New Year Domino
Celebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos User ainta, who lives in a 2D world, is going to post a video as well. There are n dominoes on a 2D Cartesian plane. i-th domino (1 ≤ i ≤ n) can be represented a...
{ "input": [ "6\n1 5\n3 3\n4 4\n9 2\n10 1\n12 1\n4\n1 2\n2 4\n2 5\n2 6\n" ], "output": [ "0\n1\n1\n2\n" ] }
{ "input": [ "3\n1 1000000000\n999999999 1000000000\n1000000000 1000000000\n4\n1 2\n1 2\n2 3\n1 3\n", "2\n304 54\n88203 83\n1\n1 2\n", "20\n4524 38\n14370 10\n22402 37\n34650 78\n50164 57\n51744 30\n55372 55\n56064 77\n57255 57\n58862 64\n59830 38\n60130 68\n66176 20\n67502 39\n67927 84\n68149 63\n71392 6...
2,300
2,750
2
9
526_C. Om Nom and Candies
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? <image> One day, when he came to his friend Evan, Om Nom didn't find him at h...
{ "input": [ "10 3 5 2 3\n" ], "output": [ "16" ] }
{ "input": [ "922784684 566833132 755777509 3 4\n", "907995862 367493085 293994468 5 4\n", "100000001 3 100000000 3 100000001\n", "1000000000 1000 999 100 1000000000\n", "3 100 101 2 3\n", "947904756 540408420 270204210 4 2\n", "970423020 540551739 540551739 4 4\n", "977983517 9009 910...
2,000
1,250
2
10
551_D. GukiZ and Binary Operations
We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: <image>? Here operation <image> means bitwise AND (in Pascal it is equivalent to and, in C/C++/Java/Python it is equival...
{ "input": [ "2 1 2 10\n", "2 1 1 3\n", "3 3 2 10\n" ], "output": [ "3\n", "1\n", "9\n" ] }
{ "input": [ "131231231 35435 63 153459\n", "165467464 5416516 45 364545697\n", "64 64 64 64\n", "1000000000000000000 1 64 911\n", "999999999999999999 999999999999999999 63 3\n", "154165741654 154168764 54 546546\n", "13713712721 13458749846 38 546863217\n", "6 0 0 1\n", "2 0 0 100...
2,100
2,000
2
9
5_C. Longest Regular Bracket Sequence
This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not....
{ "input": [ ")((())))(()())\n", "))(\n" ], "output": [ "6 2\n", "0 1\n" ] }
{ "input": [ "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((\n", "))))()())))\n", ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))\n", "))(((((((()((((())(((((((((()()))))(()())()((())())))((((()...
1,900
0
2
7
622_A. Infinite Sequence
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not d...
{ "input": [ "56\n", "5\n", "55\n", "3\n", "10\n" ], "output": [ "1\n", "2\n", "10\n", "2\n", "4\n" ] }
{ "input": [ "1000000000000\n", "99994\n", "99993\n", "99996\n", "100\n", "99999998250180\n", "99998\n", "99999\n", "99990\n", "1021\n", "99995\n", "6\n", "847194127849\n", "99991\n", "4\n", "101\n", "99939\n", "99997\n", "23\n", "9994\n"...
1,000
0
2
10
670_D1. Magic Powder - 1
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only. Waking up in the ...
{ "input": [ "4 3\n4 3 5 6\n11 12 14 20\n", "3 1\n2 1 4\n11 3 16\n" ], "output": [ "3\n", "4\n" ] }
{ "input": [ "60 735\n3 1 4 7 1 7 3 1 1 5 4 7 3 3 3 2 5 3 1 2 3 6 1 1 1 1 1 2 5 3 2 1 3 5 2 1 2 2 2 2 1 3 3 3 6 4 3 5 1 3 2 2 1 3 1 1 1 7 1 2\n596 968 975 493 665 571 598 834 948 941 737 649 923 848 950 907 929 865 227 836 956 796 861 801 746 667 539 807 405 355 501 879 994 890 573 848 597 873 130 985 924 426 999...
1,400
1,000
2
9
737_C. Subordinates
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior. There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate ...
{ "input": [ "5 3\n1 0 0 4 1\n", "3 2\n2 0 2\n" ], "output": [ "2\n", "1\n" ] }
{ "input": [ "3 2\n2 1 1\n", "3 3\n2 1 2\n", "7 1\n4 4 6 6 6 6 5\n", "3 2\n2 0 1\n", "3 1\n2 1 1\n", "3 1\n0 1 2\n", "10 6\n3 0 0 0 0 0 0 1 0 0\n", "5 5\n0 1 1 0 0\n", "3 2\n2 2 1\n", "5 1\n0 0 1 3 4\n", "2 1\n1 1\n", "9 1\n0 0 0 2 5 5 5 5 5\n", "6 1\n0 1 2 2 0 0\n"...
1,900
2,000
2
8
761_B. Dasha and friends
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you...
{ "input": [ "4 9\n2 3 5 8\n0 1 3 6\n", "2 4\n1 3\n1 2\n", "3 8\n2 4 6\n1 5 7\n" ], "output": [ "YES\n", "NO\n", "YES\n" ] }
{ "input": [ "5 10\n0 1 3 5 7\n0 1 2 4 7\n", "30 63\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61\n", "49 97\n0 1 2 3 6 8 11 14 19 23 26 29 32 34 35 37 39 41 43 44 45 46 51 53 63 64 65...
1,300
1,000
2
10
784_D. Touchy-Feely Palindromes
Input The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output Output "Yes" or "No". Examples Input 373 Output Yes Input 121 Output No Input 436 Output Yes
{ "input": [ "436\n", "121\n", "373\n" ], "output": [ "YES", "NO", "YES" ] }
{ "input": [ "90785\n", "531816\n", "314729\n", "4357087936\n", "992045\n", "116325\n", "7\n", "004176110\n", "673902416\n", "880089713\n", "69154\n", "363567\n", "64\n", "320432\n", "584609\n", "557654\n", "788958\n", "806975480\n", "8\n", ...
1,900
0
2
9
805_C. 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", "0" ] }
{ "input": [ "20289\n", "31775\n", "1\n", "82801\n", "32866\n", "99996\n", "99997\n", "43670\n", "79227\n", "3\n", "86539\n", "5188\n", "99998\n", "100000\n", "4\n", "99999\n", "31809\n", "77859\n", "53022\n", "4217\n", "60397\n", ...
1,000
500
2
9
830_C. Bamboo Partition
Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is ai meters high. Vladimir has just planted n bamboos in a row, each of...
{ "input": [ "3 40\n10 30 50\n", "3 4\n1 3 5\n" ], "output": [ "32\n", "3\n" ] }
{ "input": [ "27 56379627\n67793612 34811850 20130370 79625926 35488291 62695111 76809609 2652596 18057723 61935027 62863641 43354418 50508660 29330027 28838758 19040655 19092404 56094994 69200145 36483441 18502131 77853701 20991083 67819468 32956589 80681963 41432161\n", "100 5\n5 2 4 5 4 4 4 4 2 5 3 4 2 4 4...
2,300
1,500
2
11
89_E. Fire and Ice
The Fire Lord attacked the Frost Kingdom. He has already got to the Ice Fortress, where the Snow Queen dwells. He arranged his army on a segment n in length not far from the city walls. And only the frost magician Solomon can save the Frost Kingdom. <image> The n-long segment is located at a distance equal exactly to...
{ "input": [ "3\n0 2 0\n", "3\n1 0 1\n" ], "output": [ "ARARALAARALA\n", "ARARARALLLA\n" ] }
{ "input": [ "3\n1 0 100\n", "3\n100 0 100\n", "2\n2 1\n", "1\n1\n", "10\n1 0 0 0 0 0 0 1 0 1\n", "4\n2 2 2 2\n", "1\n52\n", "2\n0 100\n", "23\n99 100 99 100 100 100 100 99 100 99 99 100 100 100 99 99 100 100 100 99 99 99 99\n", "20\n2 0 0 0 0 0 0 1 0 0 0 1 0 100 100 100 100 1 ...
2,900
2,500
2
10
977_D. Divide by three, multiply by two
Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n - 1 operations of the two kinds: * divide the number x by 3 (x must be divisible by 3); * multiply the number x by 2. After each operation, Polycarp writes down the result on the boar...
{ "input": [ "4\n42 28 84 126\n", "2\n1000000000000000000 3000000000000000000\n", "6\n4 8 6 3 12 9\n" ], "output": [ "126 42 84 28 \n", "3000000000000000000 1000000000000000000 \n", "9 3 6 12 4 8 \n" ] }
{ "input": [ "2\n1999999999999999998 999999999999999999\n", "2\n2999999999999999997 999999999999999999\n", "3\n9000 1000 3000\n", "2\n3000 9000\n", "6\n558 744 1488 279 2232 1116\n", "2\n3000000000000000000 1000000000000000000\n", "19\n46875000000000000 732421875000000 5859375000000000 114...
1,400
0
2
8
997_B. Roman Digits
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as...
{ "input": [ "2\n", "10\n", "1\n" ], "output": [ "10", "244", "4" ] }
{ "input": [ "7\n", "292\n", "100000000\n", "2000\n", "8\n", "198\n", "116\n", "5000\n", "100\n", "9\n", "55\n", "83\n", "14\n", "9999999\n", "500000000\n", "709000900\n", "111199\n", "244\n", "20\n", "1200\n", "4\n", "1000000000\...
2,000
1,250
2
10
1056_D. Decorate Apple Tree
There is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enumerated from 1 to n, the junction 1 is called the root. A subtree of a junction v is a set of junc...
{ "input": [ "5\n1 1 3 3\n", "3\n1 1\n" ], "output": [ "1 1 1 2 3 \n", "1 1 2 \n" ] }
{ "input": [ "2\n1\n", "10\n1 2 2 3 3 4 4 5 5\n", "10\n1 1 1 1 1 1 1 1 1\n", "1\n\n", "10\n1 1 2 4 2 4 1 8 8\n" ], "output": [ "1 1 \n", "1 1 1 1 1 2 2 3 5 5 \n", "1 1 1 1 1 1 1 1 1 9 \n", "1 \n", "1 1 1 1 1 1 2 2 3 6\n" ] }
1,600
2,000
2
10
111_D. Petya and Coloring
Little Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size n × m (n rows, m columns) in k colors. Besides, the coloring should have the following property: for any vertical line that passes along the grid lines and divides the board in two non-empty parts the number...
{ "input": [ "2 2 1\n", "2 2 2\n", "3 2 2\n" ], "output": [ " 1\n", " 8\n", " 40\n" ] }
{ "input": [ "182 314 814124\n", "5 100 1\n", "892 996 619800\n", "663 904 329049\n", "1000 1 992929\n", "991 301 743241\n", "385 978 699604\n", "287 915 864740\n", "1000 1000 1000000\n", "990 800 43771\n", "837 874 229034\n", "5 20 25\n", "6 6 8\n", "793 840 67...
2,300
2,000
2
7
1147_A. Hide and Seek
Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent. Alice initially has a token on some cell on the line, and Bob tries to guess where it is. Bob guesses a sequence of line cell numbers x_1, x_2, …, x_k in order....
{ "input": [ "5 3\n5 1 4\n", "100000 1\n42\n", "4 8\n1 2 3 4 4 3 2 1\n" ], "output": [ "9\n", "299997\n", "0\n" ] }
{ "input": [ "50 75\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50\n", "300 20\n283 157 216 37 287 120 17 154 90 138 96 222 171 273 269 230 198 ...
1,500
500