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
12
1215_F. Radio Stations
In addition to complaints about lighting, a lot of complaints about insufficient radio signal covering has been received by Bertown city hall recently. n complaints were sent to the mayor, all of which are suspiciosly similar to each other: in the i-th complaint, one of the radio fans has mentioned that the signals of ...
{ "input": [ "2 4 4 2\n1 3\n2 3\n1 4\n1 2\n3 4\n1 4\n1 2\n3 4\n", "2 4 4 2\n1 3\n2 4\n1 2\n1 2\n3 4\n3 4\n1 2\n3 4\n" ], "output": [ "2 3\n1 3 ", "-1" ] }
{ "input": [ "10 15 50 10\n6 8\n10 15\n9 12\n1 8\n4 8\n1 12\n14 15\n4 7\n5 9\n7 11\n7 50\n4 41\n10 50\n5 33\n10 26\n14 42\n8 37\n4 45\n5 48\n1 27\n1 8\n4 25\n3 29\n4 19\n3 36\n8 13\n2 5\n5 7\n4 6\n3 7\n2 13\n5 11\n2 10\n5 12\n5 13\n", "10 10 50 10\n2 10\n7 8\n2 3\n1 4\n1 3\n1 9\n2 6\n5 9\n1 2\n4 8\n38 43\n18 ...
2,700
3,000
2
7
1239_A. Ivan the Fool and the Probability Theory
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area. To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n r...
{ "input": [ "2 3\n" ], "output": [ "8\n" ] }
{ "input": [ "2 1\n", "3 6\n", "2 5\n", "1 2\n", "100000 100000\n", "1 3\n", "1 100000\n", "91697 91697\n", "1 99999\n", "100000 1\n", "91248 82914\n", "1 1\n", "52702 64157\n", "99998 1\n", "99411 90913\n", "99999 1\n", "3 1\n", "1 99998\n", ...
1,700
500
2
9
1257_C. Dominated Subarray
Let's call an array t dominated by value v in the next situation. At first, array t should have at least 2 elements. Now, let's calculate number of occurrences of each number num in t and define it as occ(num). Then t is dominated (by v) if (and only if) occ(v) > occ(v') for any other number v'. For example, arrays [1...
{ "input": [ "4\n1\n1\n6\n1 2 3 4 5 1\n9\n4 1 2 4 5 4 3 2 1\n4\n3 3 3 3\n" ], "output": [ "-1\n6\n3\n2\n" ] }
{ "input": [ "1\n11\n1 1 1 1 1 1 1 1 1 1 1\n", "1\n12\n1 1 1 1 1 1 1 1 1 1 1 1\n", "1\n2\n2 2\n" ], "output": [ "2\n", "2\n", "2\n" ] }
1,200
0
2
9
1300_C. Anu Has a Function
Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. She would like to r...
{ "input": [ "1\n13\n", "4\n4 0 11 6\n" ], "output": [ "13\n", "11 4 0 6 \n" ] }
{ "input": [ "5\n108499762 843249791 917433490 622172778 725664656\n", "6\n787704054 796688644 754725914 561572949 573891604 312543334\n", "4\n433189692 522048869 125182076 157942182\n", "5\n809571641 29322377 935888946 833709370 2457463\n", "2\n151282707 316934479\n", "6\n787704054 796688644 ...
1,500
500
2
10
1324_D. Pair of Topics
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students. The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher). Your task is to find the number...
{ "input": [ "4\n1 3 2 4\n1 3 2 4\n", "5\n4 8 2 6 2\n4 5 4 1 3\n" ], "output": [ "0\n", "7\n" ] }
{ "input": [ "4\n289148443 478308391 848805621 903326233\n164110294 114400164 187849556 86077714\n", "2\n335756331 677790822\n388993348 109229235\n", "7\n207890396 779834136 486233939 78683313 737666916 867859889 430916890\n641454151 744134965 708127703 230418753 31166164 407669156 956274630\n", "2\n3...
1,400
0
2
9
1343_C. Alternating Subsequence
Recall that the sequence b is a a subsequence of the sequence a if b can be derived from a by removing zero or more elements without changing the order of the remaining elements. For example, if a=[1, 2, 1, 3, 1, 2, 1], then possible subsequences are: [1, 1, 1, 1], [3] and [1, 2, 1, 3, 1, 2, 1], but not [3, 2, 3] and [...
{ "input": [ "4\n5\n1 2 3 -1 -2\n4\n-1 -2 -1 -3\n10\n-2 8 3 8 -4 -15 5 -2 -3 1\n6\n1 -1000000000 1 -1000000000 1 -1000000000\n" ], "output": [ "2\n-1\n6\n-2999999997\n" ] }
{ "input": [ "2\n2\n-1 -1\n1\n-2\n", "10\n10\n-1 5 6 2 -8 -7 -6 5 -3 -1\n10\n1 2 3 4 5 6 7 8 9 10\n1\n6\n1\n-7\n11\n5 -4 1 2 3 -5 -7 -10 -2 1 12\n4\n-4 -5 -6 1\n7\n1 2 6 3 2 -6 -2\n5\n-1 -5 4 -2 -9\n1\n9\n3\n1 -1 1\n", "4\n5\n1 2 3 -1 -1\n4\n-4 -2 -4 -3\n10\n-2 8 3 8 -4 -15 5 -2 -3 1\n6\n1 -1000000000 1 -...
1,200
0
2
10
1365_D. Solve The Maze
Vivek has encountered a problem. He has a maze that can be represented as an n Γ— m grid. Each of the grid cells may represent the following: * Empty β€” '.' * Wall β€” '#' * Good person β€” 'G' * Bad person β€” 'B' The only escape from the maze is at cell (n, m). A person can move to a cell only if it shares a...
{ "input": [ "6\n1 1\n.\n1 2\nG.\n2 2\n#B\nG.\n2 3\nG.#\nB#.\n3 3\n#B.\n#..\nGG.\n2 2\n#B\nB.\n" ], "output": [ "Yes\nYes\nNo\nNo\nYes\nYes\n" ] }
{ "input": [ "5\n2 5\nB.GGG\n.B.G.\n3 6\nBB#.GG\nB.#B.G\n.#.#G.\n3 2\n..\n..\n..\n1 4\nBBB.\n4 9\n###B##.B#\n.####.##G\n##.###.#.\n...B#.B#.\n", "1\n1 1\n.\n", "4\n1 2\nG.\n1 2\n#.\n1 2\n..\n1 2\nB.\n" ], "output": [ "Yes\nYes\nYes\nYes\nYes\n", "Yes\n", "Yes\nYes\nYes\nYes\n" ] }
1,700
1,500
2
8
1407_B. Big Vova
Alexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace "Zmey-Gorynych", and offers Alex a job: if he shows his pro...
{ "input": [ "7\n2\n2 5\n4\n1 8 2 3\n3\n3 8 9\n5\n64 25 75 100 50\n1\n42\n6\n96 128 88 80 52 7\n5\n2 4 8 16 17\n" ], "output": [ "5 2\n8 2 1 3\n9 3 8\n100 50 25 75 64\n42\n128 96 80 88 52 7\n17 2 4 8 16\n" ] }
{ "input": [ "1\n32\n660 510 840 483 805 140 280 476 474 70 120 728 449 210 111 645 105 580 420 84 798 520 132 168 814 329 552 145 332 602 296 430\n", "1\n16\n1000 50 643 72 726 500 250 790 925 700 600 572 365 375 260 40\n", "1\n27\n850 225 180 105 150 742 450 90 525 725 129 387 612 300 60 348 18 786 340 ...
1,300
1,000
2
12
1474_F. 1 2 3 4 ...
Igor had a sequence d_1, d_2, ..., d_n of integers. When Igor entered the classroom there was an integer x written on the blackboard. Igor generated sequence p using the following algorithm: 1. initially, p = [x]; 2. for each 1 ≀ i ≀ n he did the following operation |d_i| times: * if d_i β‰₯ 0, then he looke...
{ "input": [ "3\n100\n5 -3 6\n", "3\n3\n1 -1 2\n", "5\n34\n1337 -146 42 -69 228\n", "3\n1\n999999999 0 1000000000\n" ], "output": [ "\n9 7\n", "\n3 3\n", "\n1393 3876\n", "\n2000000000 1\n" ] }
{ "input": [ "50\n834035286\n1000000000 1000000000 1000000000 244981634 0 -1000000000 -208185761 0 0 0 1000000000 126125866 0 0 0 -385821645 0 0 0 0 1000000000 1000000000 1000000000 974558309 0 -1000000000 -1000000000 -89717833 0 0 1000000000 1000000000 1000000000 183747708 0 -582665874 0 0 0 0 590691184 0 0 0 0 ...
3,000
3,000
2
9
14_C. Four Segments
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr...
{ "input": [ "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n", "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "2 -1 -2 -1\n2 -1 2 -1\n2 -1 -2 -1\n2 -1 2 -1\n", "0 0 0 1\n0 1 0 1\n0 1 0 0\n0 1 0 1\n", "0 0 2 2\n0 0 2 0\n2 2 2 2\n0 2 0 2\n", "130120899 550158649 130120899 831843953\n130120899 550158649 130120899 831843953\n130120899 550158649 434006978 831843953\n434006978 550158649 434006978 55015...
1,700
0
2
8
156_B. Suspects
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe...
{ "input": [ "4 1\n+2\n-3\n+4\n-1\n", "1 1\n+1\n", "3 2\n-1\n-2\n-3\n" ], "output": [ "Lie\nNot defined\nLie\nNot defined\n", "Truth\n", "Not defined\nNot defined\nNot defined\n" ] }
{ "input": [ "10 4\n-8\n+1\n-6\n-10\n+5\n-6\n-8\n-8\n-4\n-8\n", "28 12\n+10\n-7\n+17\n-20\n+7\n-7\n+13\n-21\n-7\n-7\n-18\n+7\n+7\n+3\n+6\n+14\n+7\n-24\n-21\n-7\n-7\n+4\n+7\n-7\n+21\n-7\n-26\n+7\n", "10 6\n+10\n+10\n+10\n+3\n+10\n+10\n+6\n+6\n+10\n+8\n", "10 3\n+10\n+2\n+10\n+9\n+1\n+9\n+4\n+9\n+3\n+2\...
1,600
1,000
2
12
177_F1. Script Generation
The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series. There are n single men and n single women among the main characters. An opinion poll showed that viewers lik...
{ "input": [ "2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n", "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n" ], "output": [ "2\n", "8\n" ] }
{ "input": [ "4 16 105\n2 4 15\n1 1 16\n2 2 57\n3 4 31\n1 2 47\n2 3 28\n1 3 70\n4 2 50\n3 1 10\n4 1 11\n4 4 27\n1 4 56\n3 3 28\n3 2 28\n2 1 33\n4 3 63\n", "5 15 90\n2 3 71\n5 1 72\n3 2 29\n2 5 35\n5 4 49\n2 1 5\n3 3 37\n5 2 3\n1 1 24\n1 3 50\n5 3 45\n2 2 31\n4 3 71\n3 1 30\n2 4 18\n", "3 9 21\n3 2 40\n1 3...
1,800
30
2
9
199_C. About Bacteria
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning of the first experiment there is a single bacterium in the test tub...
{ "input": [ "2 2 4 100\n", "3 1 3 5\n", "1 4 4 7\n" ], "output": [ "0\n", "2\n", "3\n" ] }
{ "input": [ "5 5 2 10\n", "1000000 1000000 1 1\n", "5 5 2 1\n", "1 1 2 2\n", "1 1 1000000 1\n", "2 1 371319 775111\n", "1000000 1 1 1\n", "5 2 68 144841\n", "702841 39 622448 218727\n", "1 1 1 1\n", "1 1 100 2\n", "1 1 1000000 553211\n", "5 2 100 38\n", "1 9684...
1,700
500
2
10
222_D. Olympiad
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances. ...
{ "input": [ "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4\n", "5 2\n1 1 1 1 1\n1 1 1 1 1\n" ], "output": [ "1 5\n", "1 5\n" ] }
{ "input": [ "1 100\n56\n44\n", "3 10\n9 9 0\n0 0 10\n", "5 45\n1 2 3 4 5\n10 20 30 40 50\n", "10 26872\n84744 76378 25507 49544 44949 65159 78873 9386 2834 83577\n43277 76228 210 44539 72154 22876 94528 90143 3059 2544\n", "10 16\n8 4 2 5 4 8 3 5 6 9\n5 3 8 6 2 10 10 8 9 3\n", "3 3\n1 50 2\n2...
1,900
2,000
2
8
246_B. Increase and Decrease
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); ...
{ "input": [ "3\n1 4 1\n", "2\n2 1\n" ], "output": [ "3\n", "1\n" ] }
{ "input": [ "6\n-1 1 0 0 -1 -1\n", "4\n2 0 -2 -1\n", "4\n2 -7 -2 -6\n", "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56 -673 440 -79...
1,300
1,000
2
9
271_C. Secret
The Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let's index them by positive integers from 1 to k), the i-th Keeper gets a non-empty set of words with numbers from the set Ui = (ui, 1, ui, 2, ..., ui, |Ui|). Here and below we'll presup...
{ "input": [ "11 3\n", "5 2\n" ], "output": [ "1 1 2 2 3 3 1 2 3 1 1\n", "-1" ] }
{ "input": [ "950059 419028\n", "18 6\n", "13141 3789\n", "2 2\n", "20354 1334\n", "999999 333334\n", "13141 3789\n", "10 2\n", "9 3\n", "20354 1334\n", "6 2\n", "20354 8642\n", "3 2\n", "365561 143151\n" ], "output": [ "-1", "1 1 2 2 3 3 4 4 5 5 6 6...
1,500
1,500
2
9
318_C. Perfect Pair
Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers x, y are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the number...
{ "input": [ "-1 4 15\n", "1 2 5\n", "0 -1 5\n" ], "output": [ "4\n", " 2\n", "-1\n" ] }
{ "input": [ "-99 -91 523666385\n", "1 -999999999 239239239\n", "-1000000000000000000 -1000000000000000000 -999999999999999999\n", "-100000000000000 1 233\n", "-134 -345 -133\n", "36 -58 428518679\n", "-47 -31 -669106932\n", "171 185 534908267\n", "-1000000000 -1000000000 -10000000...
1,600
500
2
9
342_C. Cupboard and Balloons
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h + r from the sides. The figure below shows what...
{ "input": [ "1 1\n", "2 1\n", "1 2\n" ], "output": [ "3", "2", "5" ] }
{ "input": [ "5 3\n", "1526002 6904227\n", "4 1\n", "674098 1358794\n", "5 5\n", "100 87\n", "10000000 8660255\n", "100 199\n", "100 49\n", "2 6904227\n", "6552194 8371814\n", "10000000 866254\n", "2 2\n", "5 10\n", "3983458 7761504\n", "5 11\n", "23...
1,900
1,500
2
10
389_D. Fox and Minimal path
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output...
{ "input": [ "2", "1", "9" ], "output": [ "4\nNNYY\nNNYY\nYYNN\nYYNN\n", "2\nNY\nYN\n", "11\nNNYYNNNNYNN\nNNNNNNYYNNY\nYNNNYYNNNNN\nYNNNYYNNNNN\nNNYYNNYYNNN\nNNYYNNYYNNN\nNYNNYYNNNNN\nNYNNYYNNNNN\nYNNNNNNNNYN\nNNNNNNNNYNY\nNYNNNNNNNYN\n" ] }
{ "input": [ "1000000\n", "999983\n", "9999991\n", "2\n", "73939133\n", "16\n", "9\n", "29\n", "27\n", "29000087\n", "2691939\n", "13567\n", "15485863\n", "666013\n", "10\n", "58376259\n", "41313494\n", "1\n", "1000003\n", "31\n", "7\...
1,900
1,000
2
13
409_G. On a plane
Input The first line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of points on a plane. Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive. Output Output a single real...
{ "input": [ "8\n16.94 2.42\n15.72 2.38\n14.82 1.58\n14.88 0.50\n15.76 -0.16\n16.86 -0.20\n17.00 0.88\n16.40 0.92\n", "5\n2.26 1.44\n2.28 0.64\n2.30 -0.30\n1.58 0.66\n3.24 0.66\n", "8\n6.98 2.06\n6.40 1.12\n5.98 0.24\n5.54 -0.60\n7.16 0.30\n7.82 1.24\n8.34 0.24\n8.74 -0.76\n", "5\n10.44 2.06\n10.90 0....
{ "input": [ "1\n0.00 0.01\n", "2\n792.70 540.07\n-865.28 -699.23\n", "14\n99.19 -882.27\n468.09 310.41\n-539.17 665.55\n-355.65 -90.01\n490.35 -966.88\n-102.77 252.03\n981.63 -976.33\n-363.05 -435.09\n-44.93 -37.28\n947.69 530.68\n49.38 -299.65\n503.33 684.17\n199.13 328.89\n31.24 65.36\n", "1\n1.00 ...
2,200
0
2
8
437_B. The Child and Set
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set S: * its elements were distinct integers from 1 to limit; * the value of <ima...
{ "input": [ "4 3\n", "5 1\n", "5 5\n" ], "output": [ "3\n3 2 1 ", "-1", "2\n5 4 " ] }
{ "input": [ "62658 10881\n", "66947 17657\n", "1997 508\n", "5499 1023\n", "100000 14047\n", "21741 3575\n", "61897 33128\n", "54321 12345\n", "58934 6404\n", "89829 8298\n", "83451 17526\n", "47283 15757\n", "40287 17817\n", "58413 1253\n", "49940 18445\n"...
1,500
1,500
2
10
45_D. Event Dates
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose...
{ "input": [ "3\n1 2\n2 3\n3 4\n", "2\n1 3\n1 3\n" ], "output": [ "1 2 3 ", "1 2 " ] }
{ "input": [ "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4\n", "10\n1 4\n1 12\n5 7\n5 5\n2 5\n1 7\n1 10\n7 9\n8 9\n9 11\n", "10\n6 7\n5 11\n5 10\n9 10\n11 12\n6 12\n7 11\n1 1\n5 9\n2 8\n", "10\n6 9\n1 8\n6 12\n8 15\n2 5\n1 2\n7 15\n12 15\n5 12\n8 15\n", "10\n2 4\n10 13\n1 10\n6 13\n9 12\...
1,900
0
2
8
52_B. Right Triangles
You are given a n Γ— m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle). Input...
{ "input": [ "3 4\n*..*\n.**.\n*.**\n", "2 2\n**\n*.\n" ], "output": [ "9", "1" ] }
{ "input": [ "1 3\n*.*\n", "5 2\n*.\n**\n.*\n..\n.*\n", "5 2\n**\n**\n**\n*.\n*.\n", "4 2\n.*\n.*\n..\n..\n", "10 26\n..**..***.**.*.***.*.***.*\n*.*.*..***.*.**..*********\n*.*.*...***.*.*.*.**....*.\n..**.**.....*....***..***.\n**..*******.*..**.********\n*.**..****.***....***..***\n.*..**.*****...
1,600
1,000
2
9
581_C. Developing Skills
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is...
{ "input": [ "2 2\n99 100\n", "2 4\n7 9\n", "3 8\n17 15 19\n" ], "output": [ "20\n", "2\n", "5\n" ] }
{ "input": [ "100 9455943\n44 8 21 71 7 29 40 65 91 70 48 19 77 48 16 22 54 4 29 34 9 22 73 34 47 41 5 83 32 91 52 6 74 64 18 23 9 4 36 78 98 20 20 3 69 86 41 67 54 76 87 84 47 6 52 87 61 100 98 80 14 14 24 99 90 73 97 79 22 65 65 51 29 44 15 67 21 58 79 80 96 40 63 73 96 59 72 24 87 85 74 49 81 30 16 61 87 30 0 ...
1,400
1,500
2
8
603_B. Moodular Arithmetic
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where...
{ "input": [ "3 2\n", "5 4\n" ], "output": [ "3", "25" ] }
{ "input": [ "69833 569\n", "6907 2590\n", "463 408\n", "95531 94787\n", "13 4\n", "807689 9869\n", "4649 4648\n", "437071 24705\n", "7 2\n", "40867 37466\n", "375103 52131\n", "203317 12108\n", "613463 269592\n", "5 3\n", "5 0\n", "586189 189159\n", ...
1,800
1,000
2
7
675_A. Infinite Sequence
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, the...
{ "input": [ "1 -4 5\n", "1 7 3\n", "0 60 50\n", "10 10 0\n" ], "output": [ "NO\n", "YES\n", "NO\n", "YES\n" ] }
{ "input": [ "1 6 1\n", "-2 -2 0\n", "0 -2 -2\n", "0 -1 -1\n", "-2 0 1\n", "1 -2 0\n", "0 2 -2\n", "3 2 1\n", "0 2 -1\n", "1000000000 0 -1000000000\n", "0 -5 -3\n", "-1 -1 -2\n", "10 9 -1\n", "2 -1 2\n", "1 1 0\n", "-2 2 -1\n", "2 0 -2\n", "0 -2 ...
1,100
500
2
8
699_B. One Bomb
You are given a description of a depot. It is a rectangular checkered field of n Γ— m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column...
{ "input": [ "3 3\n..*\n.*.\n*..\n", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n", "3 4\n.*..\n....\n.*..\n" ], "output": [ "NO\n", "YES\n3 3\n", "YES\n1 2\n" ] }
{ "input": [ "3 3\n*..\n**.\n...\n", "3 3\n*..\n*..\n***\n", "10 10\n........*.\n*.........\n........*.\n........*.\n..........\n..........\n..........\n........*.\n.....*..*.\n***.......\n", "3 3\n.*.\n.*.\n.**\n", "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n", "1 3\n...\n", "3 3\n...\n.*.\n...\...
1,400
1,000
2
10
71_D. Solitaire
Vasya has a pack of 54 cards (52 standard cards and 2 distinct jokers). That is all he has at the moment. Not to die from boredom, Vasya plays Solitaire with them. Vasya lays out nm cards as a rectangle n Γ— m. If there are jokers among them, then Vasya should change them with some of the rest of 54 - nm cards (which a...
{ "input": [ "4 6\n2S 3S 4S 7S 8S AS\n5H 6H 7H 5S TC AC\n8H 9H TH 7C 8C 9C\n2D 2C 3C 4C 5C 6C\n", "4 6\n2S 3S 4S 7S 8S AS\n5H 6H 7H QC TC AC\n8H 9H TH 7C 8C 9C\n2D 2C 3C 4C 5C 6C\n", "4 6\n2S 3S 4S 7S 8S AS\n5H 6H 7H J1 TC AC\n8H 9H TH 7C 8C 9C\n2D 2C 3C 4C 5C 6C\n" ], "output": [ "No solution.\n"...
{ "input": [ "7 7\n6C 8C KH 8S 2H 7S JH\n3H QC QD TS 4C QH J2\n7C 6S 6D 8D 7D 4S JS\n3S 3D 9S 3C J1 2D 7H\nAH KD AS 9C 2S 5D QS\n2C JD 8H 9D 4D 5H 5C\nJC KC 6H TH TD KS TC\n", "7 7\n2C 3C 4C 2D 3D 4D JC\n5C 6C 7C 5D 6D 7D QC\n8C 9C TC 8D J2 TD KC\n2H 3H 4H J1 3S 4S AC\n5H 6H 7H 5S 6S 7S KH\n8H 9H TH 8S 9S TS ...
2,200
2,000
2
7
741_A. Arpa's loud Owf and Mehrdad's evil plan
As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are a...
{ "input": [ "4\n2 1 4 3\n", "4\n4 4 4 4\n", "4\n2 3 1 4\n" ], "output": [ "1\n", "-1\n", "3\n" ] }
{ "input": [ "100\n99 7 60 94 9 96 38 44 77 12 75 88 47 42 88 95 59 4 12 96 36 16 71 6 26 19 88 63 25 53 90 18 95 82 63 74 6 60 84 88 80 95 66 50 21 8 61 74 61 38 31 19 28 76 94 48 23 80 83 58 62 6 64 7 72 100 94 90 12 63 44 92 32 12 6 66 49 80 71 1 20 87 96 12 56 23 10 77 98 54 100 77 87 31 74 19 42 88 52 17\n",...
1,600
500
2
11
764_E. Timofey and remoduling
Little Timofey likes integers a lot. Unfortunately, he is very young and can't work with very big integers, so he does all the operations modulo his favorite prime m. Also, Timofey likes to look for arithmetical progressions everywhere. One of his birthday presents was a sequence of distinct integers a1, a2, ..., an. ...
{ "input": [ "17 5\n0 2 4 13 15\n", "5 3\n1 2 3\n", "17 5\n0 2 4 13 14\n" ], "output": [ " 13 2\n", " 1 ...
{ "input": [ "17 2\n8 3\n", "239 100\n178 74 144 43 201 189 40 175 51 31 202 114 12 17 86 78 53 196 235 158 95 224 143 198 170 117 79 81 23 197 73 165 133 166 21 50 148 34 121 223 184 45 54 228 9 238 187 19 218 169 104 62 106 46 209 182 221 61 59 48 160 27 212 123 5 107 82 102 208 151 7 180 35 191 11 70 168 1...
2,600
1,500
2
8
834_B. The Festive Evening
<image> It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in th...
{ "input": [ "5 1\nAABBB\n", "5 1\nABABB\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQ...
1,100
1,000
2
9
879_C. Short Program
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an...
{ "input": [ "3\n&amp; 1\n&amp; 3\n&amp; 5\n", "3\n^ 1\n^ 2\n^ 3\n", "3\n| 3\n^ 2\n| 1\n" ], "output": [ "3\n& 0\n| 0\n^ 0\n", "3\n& 1023\n| 0\n^ 0\n", "3\n& 1021\n| 1\n^ 0\n" ] }
{ "input": [ "1\n& 0\n", "1\n^ 123\n", "10\n^ 218\n& 150\n| 935\n& 61\n| 588\n& 897\n| 411\n| 584\n^ 800\n| 704\n", "3\n& 1\n& 3\n& 5\n", "1\n| 123\n", "1\n^ 0\n", "1\n| 1023\n", "3\n& 242\n^ 506\n^ 522\n", "10\n^ 160\n& 1021\n& 510\n^ 470\n& 1022\n& 251\n& 760\n& 1016\n| 772\n| 51...
1,600
500
2
7
925_A. Stairs and Elevators
In the year of 30XX participants of some world programming championship live in a single large hotel. The hotel has n floors. Each floor has m sections with a single corridor connecting all of them. The sections are enumerated from 1 to m along the corridor, and all sections with equal numbers on different floors are l...
{ "input": [ "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n" ], "output": [ "7\n5\n4\n" ] }
{ "input": [ "2 10 1 1 1\n1\n10\n1\n1 5 1 8\n", "4 4 1 0 1\n1\n\n1\n1 2 1 4\n", "2 5 1 0 1\n2\n\n1\n1 4 1 5\n", "10 10 1 8 4\n10\n2 3 4 5 6 7 8 9\n10\n1 1 3 1\n2 1 7 1\n1 1 9 1\n7 1 4 1\n10 1 7 1\n2 1 7 1\n3 1 2 1\n5 1 2 1\n10 1 5 1\n6 1 9 1\n", "2 4 1 1 1\n1\n4\n1\n1 2 1 3\n", "2 2 0 1 1\n\n1...
1,600
500
2
8
954_B. String Typing
You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: * add a character to the end of the string. Besides, at most once you may perform one...
{ "input": [ "8\nabcdefgh\n", "7\nabcabca\n" ], "output": [ "8\n", "5\n" ] }
{ "input": [ "5\nababa\n", "8\naaabcabc\n", "7\nabcdabc\n", "29\nabbabbaabbbbaababbababbaabbaa\n", "5\nbaaaa\n", "54\ndgafkhlgdhjflkdafgjldjhgkjllfallhsggaaahkaggkhgjgflsdg\n", "7\nabcdbcd\n", "20\nccbbcbaabcccbabcbcaa\n", "11\nababcabcabc\n", "9\nazxcvzxcv\n", "10\nwvwlwvw...
1,400
0
2
7
980_A. Links and Pearls
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. <image> You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times...
{ "input": [ "<span class=\"tex-font-style-tt\">-o---o-</span>\n", "<span class=\"tex-font-style-tt\">-o-o--</span>", "ooo\n", "<span class=\"tex-font-style-tt\">-o---</span>\n" ], "output": [ "NO\n", "NO\n", "YES\n", "NO\n" ] }
{ "input": [ "-oo-oo------\n", "-----------------------------------o---------------------o--------------------------\n", "--o-o-----o----o--oo-o-----ooo-oo---o--\n", "---\n", "----------------------o---o----o---o-----------o-o-----o\n", "-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o...
900
500
2
7
9_A. Die Roll
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
{ "input": [ "4 2\n" ], "output": [ "1/2\n" ] }
{ "input": [ "6 6\n", "1 4\n", "4 4\n", "3 3\n", "6 4\n", "6 3\n", "5 4\n", "5 6\n", "3 4\n", "1 3\n", "3 2\n", "5 5\n", "1 1\n", "2 1\n", "3 1\n", "3 5\n", "1 6\n", "6 5\n", "2 3\n", "4 3\n", "2 2\n", "3 6\n", "1 2\n", "6...
800
0
2
9
1003_C. Intense Heat
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually cal...
{ "input": [ "4 3\n3 4 1 2\n" ], "output": [ "2.666666666666667" ] }
{ "input": [ "5 5\n4 6 6 6 2\n", "5 1\n3 10 9 10 6\n", "3 2\n2 1 2\n", "5 2\n7 3 3 1 8\n", "5 4\n5 1 10 6 1\n", "5 3\n1 7 6 9 1\n", "1 1\n5000\n" ], "output": [ "4.8", "10", "1.666666666666667", "5", "5.5", "7.333333333333333", "5000" ] }
1,300
0
2
10
1027_D. Mouse Hunt
Medicine faculty of Berland State University has just finished their admission campaign. As usual, about 80\% of applicants are girls and majority of them are going to live in the university dormitory for the next 4 (hopefully) years. The dormitory consists of n rooms and a single mouse! Girls decided to set mouse tra...
{ "input": [ "4\n1 10 2 10\n2 4 2 2\n", "5\n1 2 3 2 10\n1 3 4 3 3\n", "7\n1 1 1 1 1 1 1\n2 2 2 3 6 7 6\n" ], "output": [ "10", "3", "2" ] }
{ "input": [ "3\n1 2 4\n2 2 1\n", "5\n5 4 2 6 10\n2 4 3 3 2\n", "4\n2 1 2 2\n2 3 3 2\n", "8\n1 2 2 9 7 5 6 5\n8 4 1 5 5 1 1 8\n", "3\n76 74 84\n3 2 1\n", "3\n1 2 4\n2 3 3\n", "7\n2 1 64 8 32 4 16\n5 7 2 4 2 4 6\n", "3\n1 2 4\n3 2 3\n", "5\n1 1 10 10 10\n2 3 4 5 3\n", "4\n1 12 2...
1,700
0
2
9
1046_C. Space Formula
Formula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race. Given the current ranking in the competition and points distribution for the next race, your task is to calculate the best possible ranking for a given astronaut after the next r...
{ "input": [ "4 3\n50 30 20 10\n15 10 7 3\n" ], "output": [ "2" ] }
{ "input": [ "4 4\n29 25 13 10\n20 9 3 0\n", "4 2\n29 28 27 9\n1 1 1 0\n", "4 4\n29 25 13 9\n20 9 8 0\n", "4 1\n29 25 13 9\n3 2 1 0\n", "4 4\n29 25 13 0\n20 9 8 0\n", "1 1\n5\n5\n", "4 4\n29 25 13 10\n20 9 8 0\n", "4 2\n29 28 13 9\n1 1 1 0\n", "4 4\n29 25 13 9\n3 2 1 0\n" ], "o...
1,400
0
2
8
1070_B. Berkomnadzor
Berkomnadzor β€” Federal Service for Supervision of Communications, Information Technology and Mass Media β€” is a Berland federal executive body that protects ordinary residents of Berland from the threats of modern internet. Berkomnadzor maintains a list of prohibited IPv4 subnets (blacklist) and a list of allowed IPv4 ...
{ "input": [ "5\n-127.0.0.4/31\n+127.0.0.8\n+127.0.0.0/30\n-195.82.146.208/29\n-127.0.0.6/31\n", "4\n-149.154.167.99\n+149.154.167.100/30\n+149.154.167.128/25\n-149.154.167.120/29\n", "2\n+127.0.0.1/32\n-127.0.0.1\n", "1\n-149.154.167.99\n" ], "output": [ "2\n127.0.0.4/30\n128.0.0.0/1\n", ...
{ "input": [ "11\n-0.0.0.15/32\n-0.0.0.12/31\n-0.0.0.7/32\n-0.0.0.11/32\n-0.0.0.9/32\n-0.0.0.3\n-0.0.0.0/31\n-0.0.0.1/32\n-0.0.0.2/32\n-0.0.0.5\n-0.0.0.8/32\n", "7\n-0.0.0.11/32\n-0.0.0.1/32\n+0.0.0.25\n+0.0.0.29\n-0.0.0.2/32\n-0.0.0.12\n-0.0.0.16\n", "10\n-185.182.92.216/29\n-26.39.239.152/29\n-146.51.21...
2,400
0
2
12
1091_F. New Year and the Mallard Expedition
Bob is a duck. He wants to get to Alice's nest, so that those two can duck! <image> Duck is the ultimate animal! (Image courtesy of See Bang) The journey can be represented as a straight line, consisting of n segments. Bob is located to the left of the first segment, while Alice's nest is on the right of the last seg...
{ "input": [ "2\n1 2\nWL\n", "3\n10 10 10\nGLW\n", "2\n10 10\nWL\n", "1\n10\nG\n" ], "output": [ "8", "80", "40", "30" ] }
{ "input": [ "4\n1 1 1 1\nWGWL\n", "2\n2 10\nGL\n", "3\n10 10 50\nWGL\n", "2\n100 100\nWG\n", "10\n324839129156 133475576222 987711341463 185514358673 88712073883 243757012712 950854402304 21947060440 598567289966 674328002732\nGLLLLLLLLW\n", "2\n100 100\nGW\n", "5\n2 2 1 1 1\nWGLLW\n", ...
2,600
3,000
2
10
1110_D. Jongmah
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it. To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tile...
{ "input": [ "10 6\n2 3 3 3 4 4 4 5 5 6\n", "13 5\n1 1 5 1 2 3 3 2 4 2 3 4 5\n", "12 6\n1 5 3 3 3 4 3 5 3 2 3 3\n" ], "output": [ "3\n", "4\n", "3\n" ] }
{ "input": [ "14 9\n5 5 6 8 8 4 3 2 2 7 3 9 5 4\n", "14 11\n10 8 6 1 7 2 9 5 5 10 3 5 11 3\n", "1 1\n1\n", "3 3\n2 2 2\n", "10 4\n1 4 2 3 1 3 3 4 1 3\n", "3 4\n1 2 4\n", "10 5\n2 2 4 4 3 1 1 2 3 2\n", "19 5\n1 1 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 5 5\n", "2 2\n1 2\n", "3 4\n1 3 4\n"...
2,200
2,000
2
7
1140_A. Detective Book
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i β‰₯ i). Ivan wants to read the whole book. Each day, he reads the first page he didn'...
{ "input": [ "9\n1 3 3 6 7 6 8 8 9\n" ], "output": [ "4\n" ] }
{ "input": [ "1\n1\n", "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n", "11\n1 2 3 4 5 6 7 8 9 10 11\n", "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "10\n1 3 4 5 5 6 7 8 9 10\n", "12\n1 2 3 4 5 6 7 8 9 10 11 12\n", "4\n1 2 4 4\n", "17\n9 4 3 6 7 6 8 8 9 10 11 12 13 14 15 16 17\n", "10\n4 9 ...
1,000
0
2
10
1180_D. Tolik and His Uncle
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any...
{ "input": [ "1 1\n", "2 3\n" ], "output": [ "1 1\n", "1 1\n2 3\n1 2\n2 2\n1 3\n2 1\n" ] }
{ "input": [ "782 19\n", "1 2892\n", "61 389\n", "4830 1\n", "6354 1\n", "8 8\n", "6 8\n" ], "output": [ "1 1\n782 19\n1 2\n782 18\n1 3\n782 17\n1 4\n782 16\n1 5\n782 15\n1 6\n782 14\n1 7\n782 13\n1 8\n782 12\n1 9\n782 11\n1 10\n782 10\n1 11\n782 9\n1 12\n782 8\n1 13\n782 7\n1 14\n...
1,800
1,000
2
10
1199_D. Welfare State
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the governm...
{ "input": [ "5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20\n", "4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1\n" ], "output": [ "8 8 20 8 10\n", "3 2 3 4\n" ] }
{ "input": [ "4\n1 2 3 4\n2\n2 3\n2 2\n", "4\n1 2 3 4\n2\n2 1000\n2 1\n", "1\n1\n3\n2 4\n1 1 2\n2 10\n", "5\n1 2 3 4 5\n10\n1 1 0\n2 1\n1 2 0\n2 2\n1 3 0\n2 3\n1 4 0\n2 4\n1 5 0\n2 5\n", "10\n1 2 3 4 5 6 7 8 9 10\n10\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n", "10\n7 9 4 4 7 6 3 7 9...
1,600
750
2
9
1216_C. White Sheet
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bott...
{ "input": [ "0 0 1000000 1000000\n0 0 499999 1000000\n500000 0 1000000 1000000\n", "3 3 7 5\n0 0 4 6\n0 0 7 4\n", "5 2 10 5\n3 1 7 6\n8 1 11 7\n", "2 2 4 4\n1 1 3 5\n3 1 5 5\n" ], "output": [ "YES\n", "YES\n", "YES\n", "NO\n" ] }
{ "input": [ "7 1 8 3\n0 0 4 2\n2 1 18 21\n", "5 2 10 5\n8 1 11 7\n3 1 7 6\n", "3 3 4 4\n0 0 1 1\n3 3 4 4\n", "50 100 100000 99000\n0 0 1 1\n999999 999999 1000000 1000000\n", "4 6 6 7\n1 4 9 5\n4 5 6 10\n", "5 5 7 7\n0 0 2 9\n3 3 9 9\n", "11360 21479 13661 21563\n8924 9481 21073 27713\n167...
1,700
0
2
12
1257_F. Make Them Similar
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example: * 2 and 4 are similar (binary representations are 10 and 100); * 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101); * 3 and 2 are not similar (binary repr...
{ "input": [ "4\n3 17 6 0\n", "3\n1 2 3\n", "2\n7 2\n", "3\n43 12 12\n" ], "output": [ "5\n", "-1", "1\n", "1\n" ] }
{ "input": [ "2\n105953580 334230288\n", "2\n1073709056 32767\n", "10\n22 27 7 14 10 9 10 15 13 0\n", "10\n22 15 29 8 5 17 27 27 2 10\n", "100\n784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 784 78...
2,400
0
2
7
1281_A. Suffix Three
We just discovered a new data structure in our research group: a suffix three! It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in. It's super simple, 100% accurate, and doesn't involve advanced machine learni...
{ "input": [ "8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_okama_kenpo\nang_halaman_doon_ay_sarisari_singkamasu\nsi_roy_mustang_ay_namamasu\n" ], "output": [ "FILIPINO\nJAPANESE\nJAPANESE\nKOREAN\nFILIPINO\nFILIPINO\nJAPANESE\nJAPANESE\n" ...
{ "input": [ "30\nopo\np_po\npopo\ndesu\npo\nudesu\npodesu\ndesupo\nsddesu\nmumasu\nmmnida\nmmasu\nmasu\ndesu_po\npomnida\nmasumasu\npppo\nmnida\nmasu_po\ndesu_masu\na_masu\npo_po\nmasupo\nmasu_masu\nmnidamasu\npomasu\nmnida_po\nmnida_desu\nnakupo\npo_masu\n", "30\npo\nppo\nop_po\nmnida\nmasu\ndesu\npopo\nmsm...
800
500
2
7
1301_A. Three Strings
You are given three strings a, b and c of the same length n. The strings consist of lowercase English letters only. The i-th letter of a is a_i, the i-th letter of b is b_i, the i-th letter of c is c_i. For every i (1 ≀ i ≀ n) you must swap (i.e. exchange) c_i with either a_i or b_i. So in total you'll perform exactly...
{ "input": [ "4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim\n" ], "output": [ "NO\nYES\nYES\nNO\n" ] }
{ "input": [ "1\nab\nab\nbb\n" ], "output": [ "NO\n" ] }
800
500
2
7
1325_A. EhAb AnD gCd
You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x. As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b) is the smallest integer such that both a and b divide it. It's guaranteed that the solution always exists. If ther...
{ "input": [ "2\n2\n14\n" ], "output": [ "1 1\n1 13\n" ] }
{ "input": [ "100\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79...
800
500
2
12
1343_F. Restore the Permutation by Sorted Segments
We guessed a permutation p consisting of n integers. The permutation of length n is the array of length n where each element from 1 to n appears exactly once. This permutation is a secret for you. For each position r from 2 to n we chose some other index l (l < r) and gave you the segment p_l, p_{l + 1}, ..., p_r in s...
{ "input": [ "5\n6\n3 2 5 6\n2 4 6\n3 1 3 4\n2 1 3\n4 1 2 4 6\n5\n2 2 3\n2 1 2\n2 1 4\n2 4 5\n7\n3 1 2 6\n4 1 3 5 6\n2 1 2\n3 4 5 7\n6 1 2 3 4 5 6\n3 1 3 6\n2\n2 1 2\n5\n2 2 5\n3 2 3 5\n4 2 3 4 5\n5 1 2 3 4 5\n" ], "output": [ "3 1 4 6 2 5 \n3 2 1 4 5 \n2 1 6 3 5 4 7 \n1 2 \n2 5 3 4 1 \n" ] }
{ "input": [ "1\n6\n4 2 3 4 5\n2 1 2\n2 3 5\n2 2 5\n6 1 2 3 4 5 6\n" ], "output": [ "1 2 5 3 4 6 \n" ] }
2,400
0
2
11
1407_E. Egor in the Republic of Dagestan
Egor is a famous Russian singer, rapper, actor and blogger, and finally he decided to give a concert in the sunny Republic of Dagestan. There are n cities in the republic, some of them are connected by m directed roads without any additional conditions. In other words, road system of Dagestan represents an arbitrary d...
{ "input": [ "3 4\n1 2 0\n1 3 1\n2 3 0\n2 3 1\n", "5 10\n1 2 0\n1 3 1\n1 4 0\n2 3 0\n2 3 1\n2 5 0\n3 4 0\n3 4 1\n4 2 1\n4 5 0\n", "4 8\n1 1 0\n1 3 0\n1 3 1\n3 2 0\n2 1 0\n3 4 1\n2 4 0\n2 4 1\n" ], "output": [ "2\n010\n", "-1\n01010", "3\n1100" ] }
{ "input": [ "1 0\n", "10 40\n9 9 1\n4 10 0\n4 1 1\n6 4 1\n9 9 1\n6 4 1\n2 7 1\n3 7 1\n5 9 1\n1 9 0\n9 5 1\n1 3 0\n7 1 1\n5 6 1\n3 3 0\n9 5 0\n6 1 1\n6 6 0\n1 7 0\n3 9 0\n5 8 1\n2 8 1\n2 4 0\n10 8 1\n10 4 1\n2 1 0\n1 6 1\n1 2 0\n7 1 0\n9 9 0\n7 4 1\n7 7 1\n2 5 1\n9 9 1\n5 10 0\n8 5 0\n10 10 0\n7 1 0\n8 7 0\n8...
2,500
2,500
2
7
1500_A. Going Home
It was the third month of remote learning, Nastya got sick of staying at dormitory, so she decided to return to her hometown. In order to make her trip more entertaining, one of Nastya's friend presented her an integer array a. Several hours after starting her journey home Nastya remembered about the present. To ente...
{ "input": [ "5\n1 3 1 9 20\n", "6\n2 1 5 2 7 4\n" ], "output": [ "\nNO", "\nYES\n2 3 1 6 " ] }
{ "input": [ "5\n1 2 4 8 11\n", "6\n1 2 5 8 10 12\n", "5\n1 4 10 11 13\n", "6\n1 2 2 4 8 11\n", "60\n1147861 2041994 899052 683478 931002 704737 1406756 1283948 1952357 1238212 1164251 1507228 932218 731251 1289342 1308931 1577922 1763727 1747882 1005523 1051637 17947 2439716 1180023 1129402 14452...
1,800
750
2
9
1525_C. Robot Collisions
There are n robots driving along an OX axis. There are also two walls: one is at coordinate 0 and one is at coordinate m. The i-th robot starts at an integer coordinate x_i~(0 < x_i < m) and moves either left (towards the 0) or right with the speed of 1 unit per second. No two robots start at the same coordinate. Whe...
{ "input": [ "5\n7 12\n1 2 3 4 9 10 11\nR R L L R R R\n2 10\n1 6\nR R\n2 10\n1 3\nL L\n1 10\n5\nR\n7 8\n6 1 7 2 3 5 4\nR L R L L L L\n" ], "output": [ "\n1 1 1 1 2 -1 2 \n-1 -1 \n2 2 \n-1 \n-1 2 7 3 2 7 3 \n" ] }
{ "input": [ "1\n20 50\n4 6 8 9 10 13 14 16 18 20 23 25 30 32 33 38 42 43 45 46\nL L L L L L L L L L R R R L L R R L R R\n", "1\n10 20\n2 3 7 9 10 13 14 16 17 18\nL L R L L R R R L L\n" ], "output": [ "5 5 9 11 9 11 15 15 19 19 10 4 1 1 4 -1 6 10 -1 6 \n", "6 -1 1 1 6 2 -1 1 2 1 \n" ] }
2,000
0
2
13
177_G2. Fibonacci Strings
Fibonacci strings are defined as follows: * f1 = Β«aΒ» * f2 = Β«bΒ» * fn = fn - 1 fn - 2, n > 2 Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba". You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as...
{ "input": [ "6 5\na\nb\nab\nba\naba\n" ], "output": [ "3\n5\n3\n3\n1\n" ] }
{ "input": [ "2 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n", "1 10\nb\na\nb\na\nb\na\nb\na\nb\na\n", "10 10\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\n", "50 100\nb\naab\nab\naaa\na\naab\naaa\nbb\na\na\nb\naab\nbbb\naa\nbbb\nb\nab\nab\nbbb\nb\nbaa\na\nbab\nbbb\na\naba\n...
2,600
70
2
7
19_A. World Football Cup
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: * the final tournament features n teams (n is always even) * the first n / 2 teams ...
{ "input": [ "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n", "2\na\nA\na-A 2:1\n" ], "output": [ "A\nD\n", "a\n" ] }
{ "input": [ "2\nEULEUbCmfrmqxtzvg\nuHGRmKUhDcxcfqyruwzen\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\n", "4\nTeMnHVvWKpwlpubwyhzqvc\nAWJwc\nbhbxErlydiwtoxy\nEVASMeLpfqwjkke\nAWJwc-TeMnHVvWKpwlpubwyhzqvc 37:34\nbhbxErlydiwtoxy-TeMnHVvWKpwlpubwyhzqvc 38:99\nbhbxErlydiwtoxy-AWJwc 33:84\nEVASMeLpfqwjkke-TeMnH...
1,400
0
2
8
223_B. Two Strings
A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≀ k1 < k2 < ... < k|x| ≀ |s|). You've got two strings β€” s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occurs in at...
{ "input": [ "abc\nba\n", "abacaba\naba\n", "abab\nab\n" ], "output": [ "No\n", "No\n", "Yes\n" ] }
{ "input": [ "abcdadbcd\nabcd\n", "cctckkhatkgrhktihcgififfgfctctkrgiakrifazzggfzczfkkahhafhcfgacccfakkarcatkfiktczkficahgiriakccfiztkhkgrfkrimgamighhtamrhxftaadwxgfggytwjccgkdpyyatctfdygxggkyycpjyfxyfdwtgytcacawjddjdctyfgddkfkypyxftxxtaddcxxpgfgxgdfggfdggdcddtgpxpctpddcdcpc\nctkhagrifaztmnxhmqztzibnmzzkojizt...
1,900
1,000
2
7
272_A. Dima and Friends
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
{ "input": [ "1\n2\n", "2\n3 5\n", "1\n1\n" ], "output": [ "2\n", "3\n", "3\n" ] }
{ "input": [ "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1\n", "1\n5\n", "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3\n", "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2...
1,000
500
2
9
295_C. Greg and Friends
One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that the boat can hold pe...
{ "input": [ "3 100\n50 50 100\n", "1 50\n50\n", "2 50\n50 50\n" ], "output": [ "5\n 2\n", "1\n 1\n", "-1\n0\n" ] }
{ "input": [ "5 188\n50 50 50 50 50\n", "33 123\n50 100 100 100 50 100 50 50 50 50 50 100 100 50 100 50 100 50 50 50 50 50 50 50 100 100 50 50 100 100 100 100 100\n", "5 258\n100 100 50 50 50\n", "32 121\n100 100 100 100 100 50 100 100 50 100 50 100 50 100 50 100 50 50 50 100 100 50 100 100 100 100 50...
2,100
1,500
2
7
319_A. Malek Dance Club
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member o...
{ "input": [ "1\n", "01\n", "11\n" ], "output": [ "1\n", "2\n", "6\n" ] }
{ "input": [ "0111001111110010000001111100110100111110001100100001111111110000010010111010010010010111000110001111\n", "10110\n", "0110011110111000001101001010101000011011101001001101000000111101010101111101010011101001111010111001\n", "100111100\n", "0\n", "00001100100101000111111100110010001...
1,600
500
2
7
343_A. Rational Resistance
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value. However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will co...
{ "input": [ "3 2\n", "1 1\n", "199 200\n" ], "output": [ "3\n", "1\n", "200\n" ] }
{ "input": [ "4052739537881 6557470319842\n", "1 923438\n", "1 2\n", "1 3\n", "288565475053 662099878640\n", "18 55\n", "29906716 35911991\n", "10000000000 1000000001\n", "60236007668635342 110624799949034113\n", "4 43470202936783249\n", "123 1000000000000000000\n", "1 ...
1,600
500
2
9
366_C. Dima and Salad
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit sala...
{ "input": [ "5 3\n4 4 4 4 4\n2 2 2 2 2\n", "3 2\n10 8 1\n2 7 1\n" ], "output": [ "-1\n", "18\n" ] }
{ "input": [ "1 1\n1\n2\n", "19 2\n68 24 95 24 94 82 37 87 68 67 59 28 68 5 70 53 80 46 61\n60 74 46 9 40 45 58 51 96 4 42 33 12 40 34 9 58 84 91\n", "2 1\n75 65\n16 60\n", "21 8\n50 39 28 27 58 46 95 46 50 8 28 94 61 58 57 7 1 38 9 34 12\n94 1 77 1 17 40 99 31 26 1 1 1 15 7 6 1 85 3 32 65 78\n", ...
1,900
1,500
2
8
38_B. Chess
Two chess pieces, a rook and a knight, stand on a standard chessboard 8 Γ— 8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one. Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board bea...
{ "input": [ "a1\nb2\n", "a8\nd4\n" ], "output": [ "44\n", "38\n" ] }
{ "input": [ "c1\nd2\n", "g1\ne6\n", "h8\ng2\n", "a8\nf1\n", "e4\nc1\n", "b6\ng7\n", "a4\nd1\n", "h6\na1\n", "e3\ng5\n", "g2\nb7\n", "b2\ne1\n", "e1\nd6\n", "e8\nb6\n", "b6\nd8\n", "a1\nb7\n", "e6\nf2\n", "g8\nb7\n", "e5\nh6\n", "b5\nh8\n", ...
1,200
0
2
7
40_A. Find Color
Not so long ago as a result of combat operations the main Berland place of interest β€” the magic clock β€” was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond...
{ "input": [ "-2 1\n", "4 3\n", "2 1\n" ], "output": [ "white\n", "black\n", "black\n" ] }
{ "input": [ "-12 -35\n", "-215 -996\n", "-96 -556\n", "-1000 0\n", "20 -21\n", "0 0\n", "207 -224\n", "-668 970\n", "-496 -644\n", "253 -204\n", "-129 489\n", "15 -8\n", "-589 952\n", "0 2\n", "-216 -90\n", "-72 -646\n", "280 342\n", "0 1000\n",...
1,300
500
2
7
483_A. Counterexample
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the...
{ "input": [ "900000000000000009 900000000000000029\n", "2 4\n", "10 11\n" ], "output": [ "900000000000000010 900000000000000011 900000000000000012\n", "2 3 4\n", "-1\n" ] }
{ "input": [ "998169857863230068 998169857863230083\n", "996517375802030516 996517375802030518\n", "267367244641009850 267367244641009899\n", "648583102513043 648583102513053\n", "268193483524125978 268193483524125979\n", "997343614685146644 997343614685146644\n", "2 2\n", "1 4\n", ...
1,100
500
2
7
507_A. Amr and Music
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments. Amr asked for your help ...
{ "input": [ "5 6\n4 3 1 1 2\n", "1 3\n4\n", "4 10\n4 3 1 2\n" ], "output": [ "3\n3 4 5 ", "0\n", "4\n3 4 2 1 " ] }
{ "input": [ "2 100\n100 100\n", "5 49\n16 13 7 2 1\n", "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 6...
1,000
500
2
8
556_B. Case of Fake Numbers
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers f...
{ "input": [ "4\n0 2 3 1\n", "5\n4 2 1 4 3\n", "3\n1 0 0\n" ], "output": [ "No\n", "Yes\n", "Yes\n" ] }
{ "input": [ "3\n0 1 1\n", "4\n0 1 2 2\n", "100\n79 74 22 11 73 70 33 50 9 81 17 14 23 44 4 90 20 22 19 94 66 80 70 42 22 82 49 42 36 7 90 91 80 33 26 52 6 77 30 94 99 6 46 84 96 40 89 2 88 65 80 93 5 60 25 15 32 26 68 85 62 74 69 55 84 0 85 91 23 43 84 94 25 65 28 92 16 0 7 83 48 74 15 20 5 97 34 42 99 9...
1,100
250
2
9
626_C. Block Towers
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be uniq...
{ "input": [ "3 2\n", "5 0\n", "1 3\n" ], "output": [ "8\n", "10\n", "9\n" ] }
{ "input": [ "4 2\n", "984327 24352\n", "918273 219\n", "651 420\n", "5 3\n", "6 4\n", "192056 131545\n", "108752 129872\n", "1285 877\n", "817544 553980\n", "500000 167000\n", "961920 647392\n", "1515 1415\n", "32 16\n", "8 9\n", "0 5\n", "15 10\n",...
1,600
1,000
2
7
650_A. Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan consider...
{ "input": [ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ], "output": [ "2", "11" ] }
{ "input": [ "2\n1 0\n0 19990213\n", "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55\n", "2\n2 1\n1 2\n", "3\n8911 7861\n-6888 7861\n8911 7861\n", "2\n0 1000000000\n1 -7\n", "2\n1000000000 0\n-7 1\n", "1\n-5 -90\n", "2\n1 4\n2 1\n", "2\n1 1000000000\n2...
1,400
500
2
10
675_D. Tree Construction
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help. You are given a sequence a, consisting of n distinct integers, that is used to construct the binary search tree. Below is the formal d...
{ "input": [ "5\n4 2 3 1 6\n", "3\n1 2 3\n" ], "output": [ "4 2 2 4 ", "1 2 " ] }
{ "input": [ "2\n2 1\n", "10\n991309218 517452607 870021923 978357992 136426010 10601767 302627526 883615372 163475700 600546765\n", "3\n1 3 2\n", "4\n2 1 3 4\n", "3\n2 1 3\n", "4\n3 4 2 1\n", "4\n1 2 3 4\n", "2\n1 2\n", "3\n3 1 2\n", "3\n2 3 1\n", "4\n1 2 4 3\n", "2\n6...
1,800
2,000
2
9
765_C. Table Tennis Game 2
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins. Across all the sets Misha scored a points ...
{ "input": [ "11 2 3\n", "11 11 5\n" ], "output": [ "-1", "1" ] }
{ "input": [ "18 11 21\n", "6 5 7\n", "9 8 17\n", "6 7 4\n", "10 20 2\n", "11 8 23\n", "10 11 5\n", "11 15 2\n", "10 2 82\n", "4 0 2\n", "5 6 3\n", "10 1 11\n", "10 11 11\n", "5 11 1\n", "11 25 0\n", "11 10 19\n", "12938621 192872393 102739134\n", ...
1,200
1,250
2
8
80_B. Depression
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels! There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful ...
{ "input": [ "04:30\n", "08:17\n", "12:00\n" ], "output": [ "135 180\n", "248.5 102\n", "0 0\n" ] }
{ "input": [ "17:48\n", "08:31\n", "23:01\n", "06:36\n", "10:54\n", "00:24\n", "12:30\n", "11:32\n", "23:58\n", "07:20\n", "19:55\n", "23:00\n", "00:01\n", "20:45\n", "23:45\n", "11:59\n", "20:12\n", "04:11\n", "15:36\n", "16:37\n", "...
1,200
1,000
2
7
87_A. Trains
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,...
{ "input": [ "2 3\n", "3 7\n", "5 3\n" ], "output": [ "Equal\n", "Dasha\n", "Masha\n" ] }
{ "input": [ "999983 999979\n", "419 430\n", "51291 51292\n", "99087 99090\n", "906 912\n", "5036 5037\n", "9886 8671\n", "450766 610961\n", "999999 1000000\n", "99207 30728\n", "664690 630787\n", "999997 1000000\n", "638067 409048\n", "7660 7658\n", "2661 8...
1,500
500
2
9
903_C. Boxes Packing
Mishka has got n empty boxes. For every i (1 ≀ i ≀ n), i-th box is a cube with side length ai. Mishka can put a box i into another box j if the following conditions are met: * i-th box is not put into another box; * j-th box doesn't contain any other boxes; * box i is smaller than box j (ai < aj). Mishka ...
{ "input": [ "3\n1 2 3\n", "4\n4 2 4 3\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "10\n58 58 58 58 58 58 58 58 58 58\n", "8\n1 2 3 4 5 6 7 8\n", "1\n2\n", "1\n131\n", "11\n1 1 1 1 1 1 1 1 1 1 1\n", "10\n86 89 89 86 86 89 86 86 89 89\n", "8\n1 1 1 1 1 1 1 1\n", "1\n1\n", "1\n5\n", "9\n1 1 1 1 1 1 1 1 1\n", "100\n981 288 186 186 292 876 341 28...
1,200
0
2
11
954_E. Water Taps
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti. If for every <image> you set i-th tap to deliver exactly xi ml of ...
{ "input": [ "2 12\n1 3\n10 15\n", "2 100\n3 10\n50 150\n", "3 9\n5 5 30\n6 6 10\n" ], "output": [ "1.6666666667\n", "6.0000000000\n", "40\n" ] }
{ "input": [ "1 1000000\n1000000\n1000000\n", "1 200\n1000000\n100\n", "1 1\n1000000\n1\n", "20 30\n70 97 14 31 83 22 83 56 19 87 59 7 7 89 24 82 34 40 6 24\n10 4 47 46 11 18 32 55 16 32 53 37 43 32 41 46 57 14 60 44\n" ], "output": [ "1000000\n", "0.0000000000\n", "1000000\n", "91...
2,000
0
2
10
980_D. Perfect Groups
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square. Each integer must be in exactly one gro...
{ "input": [ "2\n5 5\n", "1\n0\n", "5\n5 -4 2 1 8\n" ], "output": [ "3 0 ", "1 ", "5 5 3 2 0 " ] }
{ "input": [ "30\n1 2 0 2 1 0 0 1 2 0 1 2 3 0 4 1 0 0 0 3 2 0 1 0 1 0 5 0 6 0\n", "2\n2 0\n", "80\n8861 -8846 -3257 8263 -8045 4549 9626 -8599 5755 -3559 5813 -7411 9151 -1847 2441 4201 2381 4651 -6571 199 -6737 -6333 -9433 -4967 9041 -9319 6801 5813 -2731 -8599 7681 -1303 -7333 6067 -1847 -6333 6047 -790...
2,100
2,000
2
10
9_D. How many trees?
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong β€” the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure β€” and then terribl...
{ "input": [ "3 2\n", "3 3\n" ], "output": [ "5\n", "4\n" ] }
{ "input": [ "21 12\n", "23 21\n", "16 5\n", "14 11\n", "16 11\n", "8 5\n", "28 23\n", "7 7\n", "35 35\n", "23 17\n", "22 22\n", "32 27\n", "15 5\n", "7 4\n", "27 11\n", "24 20\n", "33 17\n", "10 10\n", "33 26\n", "19 2\n", "12 8\n", ...
1,900
0
2
7
1008_A. Romaji
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
{ "input": [ "codeforces\n", "ninja\n", "sumimasen\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "s\n", "d\n", "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo\n", "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino\n", "king\n", "z\n", "yy\n", "aaz\n", "nbaaaaaaaa\n", "pya\n", "aeio...
900
500
2
11
1075_E. Optimal Polygon Perimeter
You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order. We define the distance between two points p_1 = (x_1...
{ "input": [ "4\n2 4\n4 3\n3 0\n1 3\n", "3\n0 0\n0 2\n2 0\n" ], "output": [ "12 14 ", "8 " ] }
{ "input": [ "3\n97972354 -510322\n97972814 -510361\n97972410 -510528\n", "12\n-83240790 -33942371\n-83240805 -33942145\n-83240821 -33941752\n-83240424 -33941833\n-83240107 -33942105\n-83239958 -33942314\n-83239777 -33942699\n-83239762 -33942925\n-83239746 -33943318\n-83240143 -33943237\n-83240460 -33942965\n...
2,100
1,500
2
12
1096_F. Inversion Expectation
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_i < a_j. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a p...
{ "input": [ "2\n1 2\n", "2\n-1 -1\n", "3\n3 -1 -1\n" ], "output": [ " 0", " 499122177", " 499122179" ] }
{ "input": [ "1\n1\n", "5\n-1 -1 5 -1 1\n", "69\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "1\n-1\n", "4\n3 1 4 2\n", "4\n-1 ...
2,300
0
2
9
1144_C. Two Shuffled Sequences
Two integer sequences existed initially β€” one of them was strictly increasing, and the other one β€” strictly decreasing. Strictly increasing sequence is a sequence of integers [x_1 < x_2 < ... < x_k]. And strictly decreasing sequence is a sequence of integers [y_1 > y_2 > ... > y_l]. Note that the empty sequence and th...
{ "input": [ "5\n4 3 1 5 3\n", "5\n0 1 2 3 4\n", "7\n7 2 7 3 3 1 4\n", "5\n1 1 2 1 2\n" ], "output": [ "YES\n4\n1 3 4 5\n1\n3\n", "YES\n5\n0 1 2 3 4\n0\n\n", "YES\n5\n1 2 3 4 7\n2\n7 3\n", "NO\n" ] }
{ "input": [ "12\n12 8 1 3 7 5 9 6 4 10 11 2\n", "6\n5 1 4 2 6 3\n", "8\n0 9 7 5 8 6 9 3\n", "1\n1337\n", "9\n5 1 3 6 8 2 9 0 10\n", "7\n3 2 0 1 0 1 2\n", "1\n0\n", "7\n1 2 3 3 3 3 4\n", "8\n3 2 0 1 0 1 2 3\n", "6\n1 2 100 3 101 4\n", "5\n1 2 4 0 2\n", "5\n1 4 2 5 3\n",...
1,000
0
2
8
1165_B. Polycarp Training
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day β€” exactly 2 problems, during the third day β€” exactly 3 problems, and so on. During the k-th day he should solve k problems. Polycarp has a list of n contests, th...
{ "input": [ "4\n3 1 4 1\n", "5\n1 1 1 2 2\n", "3\n1 1 1\n" ], "output": [ "3\n", "2\n", "1\n" ] }
{ "input": [ "5\n200000 200000 200000 200000 200000\n", "3\n5 6 7\n", "3\n100 100 100\n", "2\n2 3\n", "3\n10 10 10\n", "1\n2\n" ], "output": [ "5\n", "3\n", "3\n", "2\n", "3\n", "1\n" ] }
1,000
0
2
9
1184_C1. Heidi and the Turing Test (Easy)
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend the...
{ "input": [ "2\n0 0\n0 1\n0 2\n0 3\n1 0\n1 2\n2 0\n2 1\n2 2\n", "2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2\n" ], "output": [ "0 3\n", "1 1\n" ] }
{ "input": [ "10\n0 17\n0 24\n0 28\n0 30\n0 32\n0 33\n0 36\n0 39\n0 42\n0 43\n4 16\n7 16\n8 43\n9 16\n10 16\n10 43\n12 16\n12 43\n15 43\n16 16\n17 16\n19 43\n21 16\n22 43\n23 16\n23 43\n25 16\n25 43\n26 43\n27 21\n27 26\n27 27\n27 28\n27 31\n27 33\n27 34\n27 36\n27 40\n27 42\n27 43\n30 33\n", "3\n9 8\n23 15\n...
1,600
0
2
10
1202_D. Print a 1337-string...
The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You are given an integer n. You have to find a sequence s consisting of digits \{1, 3, 7\} such that it has exactly n subsequences equal to 1337. For example, seque...
{ "input": [ "2\n6\n1\n" ], "output": [ "133337\n1337\n" ] }
{ "input": [ "10\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n", "10\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n", "1\n999972121\n", "10\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n", "1\n999962735\n", "10\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n", "10\n111\...
1,900
0
2
10
1244_D. Paint the Tree
You are given a tree consisting of n vertices. A tree is an undirected connected acyclic graph. <image> Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color. You have to paint the vertices so that any path consisting of exactly th...
{ "input": [ "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 3\n", "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 4\n", "3\n3 2 3\n4 3 2\n3 1 3\n1 2\n2 3\n" ], "output": [ "-1\n", "9\n1 3 2 1 3 \n", "6\n1 3 2 \n" ] }
{ "input": [ "7\n1 8 3 2 6 3 2\n2 6 6 5 4 1 9\n6 4 7 1 5 5 2\n2 6\n1 6\n6 4\n3 4\n2 5\n7 1\n", "4\n2 3 5 2\n4 5 5 6\n4 2 4 3\n4 3\n1 4\n2 3\n", "10\n100 26 100 22 4 32 29 23 41 26\n54 20 97 84 12 13 45 73 91 41\n25 53 52 33 97 80 100 7 31 36\n5 4\n10 7\n3 9\n8 2\n3 1\n1 2\n6 10\n8 5\n4 6\n", "7\n2 3 1...
1,800
1,750
2
8
1264_B. Beautiful Sequence
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, …, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 ≀ i ≀ n - 1. Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequenc...
{ "input": [ "1 2 3 4\n", "2 2 2 3\n", "2 2 2 1\n" ], "output": [ "NO\n", "NO\n", "YES\n0 1 0 1 2 3 2 \n" ] }
{ "input": [ "344 345 155 154\n", "0 0 40000 40001\n", "0 0 40000 40002\n", "0 40000 39999 0\n", "0 20000 40001 20000\n", "3436 3436 46563 46564\n", "139 140 2362 2360\n", "94 95 906 906\n", "1 1 1 1\n", "0 0 2 1\n", "0 1 0 1\n", "0 40000 40002 0\n", "0 100000 0 0\n...
1,900
1,000
2
10
1285_D. Dr. Evil Underscores
Today, as a friendship gift, Bakry gave Badawy n integers a_1, a_2, ..., a_n and challenged him to choose an integer X such that the value \underset{1 ≀ i ≀ n}{max} (a_i βŠ• X) is minimum possible, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). As always, Badawy is too ...
{ "input": [ "2\n1 5\n", "3\n1 2 3\n" ], "output": [ "4", "2" ] }
{ "input": [ "1\n1073741823\n", "2\n0 1073741823\n", "5\n1073741823 1073741823 1073741823 1073741823 1073741823\n" ], "output": [ "0", "536870912", "0" ] }
1,900
1,750
2
7
1329_A. Dreamoon Likes Coloring
Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number ...
{ "input": [ "10 1\n1\n", "5 3\n3 2 2\n" ], "output": [ "-1", "1 2 4 " ] }
{ "input": [ "5 3\n3 2 2\n", "100000 10\n31191 100000 99999 99999 99997 100000 99996 99994 99995 99993\n", "99999 30\n31344 14090 93157 5965 57557 41264 93881 58871 57763 46958 96029 37297 75623 12215 38442 86773 66112 7512 31968 28331 90390 79301 56205 704 15486 63054 83372 45602 15573 78459\n", "200...
1,800
500
2
7
1349_A. Orac and LCM
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integ...
{ "input": [ "2\n1 1\n", "10\n540 648 810 648 720 540 594 864 972 648\n", "4\n10 24 40 80\n" ], "output": [ "1\n", "54\n", "40\n" ] }
{ "input": [ "2\n10007 20014\n", "2\n199999 200000\n", "2\n3 3\n", "2\n198761 199999\n", "3\n166299 110866 86856\n", "10\n972 972 324 972 324 648 1944 243 324 474\n", "2\n256 256\n", "2\n4 6\n", "5\n25 25 5 5 5\n" ], "output": [ "20014\n", "39999800000\n", "3\n", ...
1,600
500
2
11
1369_E. DeadLee
Lee bought some food for dinner time, but Lee's friends eat dinner in a deadly way. Lee is so scared, he doesn't want to die, at least not before seeing Online IOI 2020... There are n different types of food and m Lee's best friends. Lee has w_i plates of the i-th type of food and each friend has two different favorit...
{ "input": [ "3 2\n1 1 0\n1 2\n1 3\n", "4 4\n1 2 0 1\n1 3\n1 2\n2 3\n2 4\n", "5 5\n1 1 1 2 1\n3 4\n1 2\n2 3\n4 5\n4 5\n", "4 10\n2 4 1 4\n3 2\n4 2\n4 1\n3 1\n4 1\n1 3\n3 2\n2 1\n3 1\n2 4\n", "3 3\n1 2 1\n1 2\n2 3\n1 3\n" ], "output": [ "ALIVE\n2 1 \n", "ALIVE\n1 3 2 4\n", "ALIVE\n5...
{ "input": [ "50 50\n1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n25 30\n7 47\n42 15\n19 38\n16 10\n8 6\n26 50\n3 44\n41 26\n32 17\n48 23\n15 50\n39 12\n24 2\n11 13\n21 20\n44 19\n16 35\n43 45\n35 41\n38 34\n42 4\n40 9\n30 5\n24 21\n14 28\n7 46\n8 9\n12 20\n...
2,400
2,500
2
10
1391_D. 505
A binary matrix is called good if every even length square sub-matrix has an odd number of ones. Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all. All the terms above have their...
{ "input": [ "3 3\n101\n001\n110\n", "7 15\n000100001010010\n100111010110001\n101101111100100\n010000111111010\n111010010100001\n000011001111101\n111111011010011\n" ], "output": [ "2\n", "-1\n" ] }
{ "input": [ "2 58\n1100001110010010100001000000000110110001101001100010101110\n1110110010101111001110010001100010001010100011111110110100\n", "4 4\n1100\n0011\n1100\n0011\n", "1 1\n0\n", "1 1\n1\n" ], "output": [ "27\n", "-1\n", "0\n", "0\n" ] }
2,000
2,000
2
7
1416_A. k-Amazing Numbers
You are given an array a consisting of n integers numbered from 1 to n. Let's define the k-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length k (recall that a subsegment of a of length k is a contiguous part of a containing exactly k elements). If there i...
{ "input": [ "3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1\n" ], "output": [ "-1 -1 3 2 1\n-1 4 4 4 2\n-1 -1 1 1 1 1\n" ] }
{ "input": [ "3\n5\n4 4 4 4 2\n5\n1 2 3 4 5\n6\n1 3 1 5 3 1\n" ], "output": [ "-1 4 4 4 2\n-1 -1 3 2 1\n-1 -1 1 1 1 1\n" ] }
1,500
500
2
7
1480_A. Yet Another String Game
Homer has two friends Alice and Bob. Both of them are string fans. One day, Alice and Bob decide to play a game on a string s = s_1 s_2 ... s_n of length n consisting of lowercase English letters. They move in turns alternatively and Alice makes the first move. In a move, a player must choose an index i (1 ≀ i ≀ n) ...
{ "input": [ "3\na\nbbbb\naz\n" ], "output": [ "\nb\nazaz\nby\n" ] }
{ "input": [ "5\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nazazazazazazazazazazazazazazazazazazazazazazazazaz\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nzzazzazzazzazzazzazzazzazzazzazzazzazzazzazza\n", "1\na\n" ], "output": [ "bz...
800
500
2
13
1506_G. Maximize the Remaining String
You are given a string s, consisting of lowercase Latin letters. While there is at least one character in the string s that is repeated at least twice, you perform the following operation: * you choose the index i (1 ≀ i ≀ |s|) such that the character at position i occurs at least two times in the string s, and del...
{ "input": [ "6\ncodeforces\naezakmi\nabacaba\nconvexhull\nswflldjgpaxs\nmyneeocktxpqjpz\n" ], "output": [ "\nodfrces\nezakmi\ncba\nconvexhul\nwfldjgpaxs\nmyneocktxqjpz\n" ] }
{ "input": [ "1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" ], "output": [ "a\n" ] }
2,000
0
2
7
1534_A. Colour the Flag
Today we will be playing a red and white colouring game (no, this is not the Russian Civil War; these are just the colours of the Canadian flag). You are given an n Γ— m grid of "R", "W", and "." characters. "R" is red, "W" is white and "." is blank. The neighbours of a cell are those that share an edge with it (those ...
{ "input": [ "3\n4 6\n.R....\n......\n......\n.W....\n4 4\n.R.W\n....\n....\n....\n5 1\nR\nW\nR\nW\nR\n" ], "output": [ "\nYES\nWRWRWR\nRWRWRW\nWRWRWR\nRWRWRW\nNO\nYES\nR\nW\nR\nW\nR\n" ] }
{ "input": [ "1\n5 5\n.....\n.....\n.....\n.....\n....W\n", "1\n1 1\n.\n", "1\n3 1\n.\nR\n.\n" ], "output": [ "YES\nWRWRW\nRWRWR\nWRWRW\nRWRWR\nWRWRW\n", "YES\nR\n", "YES\nW\nR\nW\n" ] }
0
500
2
9
161_C. Abracadabra
Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm: * On the first step the string consists of a single character "a". * On the k-th step Polycarpus concatenates two copies of the string obtained on the (k - 1)-th step, while inserting the k-th character of ...
{ "input": [ "3 6 1 4\n", "1 1 4 4\n" ], "output": [ "2\n", "0\n" ] }
{ "input": [ "4 7 12 15\n", "1 463129088 536870913 1000000000\n", "1 4 4 7\n", "1 2 3 3\n", "1 1 2 1000000000\n", "8136 12821 10573 15189\n", "169720415 312105195 670978284 671296539\n", "654444727 988815385 77276659 644738371\n", "26733 47464 19138 46248\n", "42765 7043311 393...
2,400
2,000
2
11
180_E. Cubes
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) an...
{ "input": [ "3 1 2\n1 1 1\n", "10 2 2\n1 2 1 2 1 1 2 1 1 2\n", "10 3 2\n1 2 1 1 3 2 1 1 2 2\n" ], "output": [ "3", "5", "4" ] }
{ "input": [ "30 5 6\n4 2 2 1 3 4 2 3 2 4 3 1 1 4 4 3 5 1 4 5 5 1 2 2 1 2 4 4 1 2\n", "20 6 3\n4 1 2 6 3 3 2 5 2 5 2 1 1 4 1 2 2 1 1 4\n", "100 5 10\n4 4 4 4 4 4 4 4 4 4 4 4 2 4 4 4 4 4 4 4 4 4 2 2 2 3 3 3 3 3 3 3 4 4 4 3 3 2 1 1 1 2 3 3 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 4 4 4 4 5 4 4 4 ...
1,800
0
2
7
204_A. Little Elephant and Interval
The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r (l ≀ r). The Little Elephant has to find the number of such integers x (l ≀ x ≀ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu...
{ "input": [ "47 1024\n", "2 47\n" ], "output": [ "98\n", "12\n" ] }
{ "input": [ "645762257531682046 885295120956158518\n", "1 11\n", "47 8545\n", "10001 10000002\n", "1827171 232817181719384635\n", "9999999999999987 99999999999999711\n", "819875140559301752 946247219812473271\n", "2 3\n", "522842183413115088 853628713003942530\n", "235 236\n",...
1,500
500
2
11
228_E. The Road to Berland is Paved With Good Intentions
Berland has n cities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not. The King of Berland Valera II wants to asphalt all roads of Berland, for that he gathered a group of workers. Every day Valera chooses exactly one city and orders the crew to asphalt all roads...
{ "input": [ "3 3\n1 2 0\n2 3 0\n3 1 0\n", "4 4\n1 2 1\n2 4 0\n4 3 1\n3 2 0\n" ], "output": [ "Impossible\n", "2\n1 2\n" ] }
{ "input": [ "100 41\n3 89 1\n31 33 0\n88 83 0\n45 97 0\n32 86 0\n19 12 1\n75 74 0\n74 10 0\n69 73 1\n69 80 0\n97 61 1\n73 68 0\n70 51 1\n56 92 1\n95 42 0\n69 51 1\n2 51 0\n72 38 1\n86 10 1\n35 50 1\n81 58 0\n34 8 0\n93 82 1\n81 84 1\n68 61 0\n69 20 0\n77 25 1\n81 13 0\n21 20 1\n46 5 1\n71 60 1\n46 65 1\n29 54 1\...
1,900
2,500
2
9
252_C. Points on Line
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d. Note that the order of the points inside the group of three chosen point...
{ "input": [ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ], "output": [ "4\n", "2\n", "1\n" ] }
{ "input": [ "2 1000000000\n-14348867 1760823\n", "10 5\n31 36 43 47 48 50 56 69 71 86\n", "10 90\n24 27 40 41 61 69 73 87 95 97\n", "10 50\n1 4 20 27 65 79 82 83 99 100\n", "3 1000000000\n-5 -1 1\n", "2 1000000000\n-907894512 -289906312\n", "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -8...
1,300
500