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
787_A. The Monster
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... <image> The Monster will catch them if at any point they scream at the same tim...
{ "input": [ "20 2\n9 19\n", "2 1\n16 12\n" ], "output": [ "82\n", "-1\n" ] }
{ "input": [ "84 82\n38 6\n", "2 3\n2 2\n", "2 3\n4 99\n", "3 7\n3 6\n", "11 81\n49 7\n", "1 1\n1 100\n", "6 10\n12 14\n", "2 10\n6 20\n", "97 2\n99 100\n", "17 19\n44 75\n", "39 52\n88 78\n", "4 2\n4 4\n", "1 1\n1 1\n", "46 71\n16 49\n", "3 2\n7 2\n", "...
1,200
500
2
11
808_E. Selling Souvenirs
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market. This morning, as us...
{ "input": [ "4 3\n3 10\n2 7\n2 8\n1 1\n", "2 2\n1 3\n2 2\n", "1 1\n2 1\n" ], "output": [ "10\n", "3\n", "0\n" ] }
{ "input": [ "52 102\n3 199\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100...
2,300
0
2
7
833_A. The Meaningless Game
<image> Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's s...
{ "input": [ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n" ], "output": [ "Yes\nYes\nYes\nNo\nNo\nYes\n" ] }
{ "input": [ "1\n1062961 1031\n", "1\n3331 11095561\n", "1\n2 3\n", "3\n1 1\n8 27\n1000 1331\n", "1\n90 72\n", "1\n12004 18012002\n", "1\n3 10\n", "1\n16 8\n", "1\n3 1\n", "1\n31159 970883281\n", "1\n6 12\n", "1\n9907 98148649\n" ], "output": [ "Yes\n", "Yes...
1,700
500
2
8
878_B. Teams Formation
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ...
{ "input": [ "4 2 5\n1 2 3 1\n", "1 9 10\n1\n", "3 2 10\n1 2 1\n" ], "output": [ "12\n", "1\n", "0\n" ] }
{ "input": [ "10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n", "5 3 3\n1 2 2 1 1\n", "2 4 1\n1 1\n", "1 1000000000 1000000000\n100000\n", "5 3 2\n1 1 2 1 1\n", "5 2 4\n1 2 3 2 1\n", "1 10 10\n1\n" ], "output": [ "10000000000\n", "0\n", "2\n", "0\n", "7\n", "0\n", "0...
2,300
1,250
2
10
901_D. Weighting a Tree
You are given a connected undirected graph with n vertices and m edges. The vertices are enumerated from 1 to n. You are given n integers c1, c2, ..., cn, each of them is between - n and n, inclusive. It is also guaranteed that the parity of cv equals the parity of degree of vertex v. The degree of a vertex is the n...
{ "input": [ "6 6\n3 5 5 5 1 5\n1 4\n3 2\n4 3\n4 5\n3 5\n5 6\n", "4 4\n4 4 2 4\n1 2\n2 3\n3 4\n4 1\n", "3 3\n2 2 2\n1 2\n2 3\n1 3\n", "4 3\n-1 0 2 1\n1 2\n2 3\n3 4\n" ], "output": [ "YES\n 3\n ...
{ "input": [ "2 1\n1 1\n2 1\n", "8 12\n-6 2 -3 2 6 -7 1 -5\n2 1\n5 6\n1 6\n1 4\n8 2\n2 7\n2 5\n8 3\n8 4\n3 7\n7 6\n3 1\n", "10 13\n3 4 -3 8 6 4 -5 1 3 -7\n9 5\n9 2\n10 3\n1 4\n3 5\n9 1\n6 10\n10 4\n3 1\n2 7\n1 6\n1 7\n7 8\n", "43 52\n-23 -18 -35 21 -12 38 -35 -11 28 -20 27 -5 9 -19 -39 -25 -32 32 -36 ...
2,700
2,000
2
7
924_A. Mystical Mosaic
There is a rectangular grid of n rows of m initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and...
{ "input": [ "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n", "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n", "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n" ], "output": [ "No\n", "No\n", "Yes\n" ] }
{ "input": [ "9 5\n.....\n#....\n..#..\n.....\n.#..#\n...#.\n.#...\n....#\n.....\n", "4 10\n..#......#\n.....##...\n#.........\n.#.......#\n", "50 2\n..\n..\n#.\n..\n.#\n..\n..\n..\n.#\n..\n..\n.#\n##\n..\n..\n..\n.#\n..\n..\n.#\n..\n..\n.#\n..\n..\n.#\n..\n.#\n..\n.#\n..\n.#\n.#\n.#\n..\n..\n..\n.#\n.#\n...
1,300
500
2
9
952_C. Ravioli Sort
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with...
{ "input": [ "3\n3 1 2\n", "3\n1 2 3\n" ], "output": [ "NO", "YES" ] }
{ "input": [ "4\n90 91 90 91\n", "4\n54 54 54 55\n", "10\n55 39 93 42 97 40 36 38 11 97\n", "3\n90 39 98\n", "5\n21 57 40 94 17\n", "8\n46 4 30 85 52 6 84 13\n", "6\n47 100 96 2 96 43\n", "4\n61 28 3 81\n", "5\n14 91 91 91 84\n", "3\n22 23 24\n", "1\n13\n", "9\n13 80 13...
1,600
0
2
11
979_E. Kuro and Topological Parity
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games. Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot o...
{ "input": [ "3 1\n-1 0 1\n", "2 1\n1 0\n", "1 1\n-1\n" ], "output": [ "6\n", "1\n", "2\n" ] }
{ "input": [ "9 1\n0 1 -1 -1 -1 -1 1 1 1\n", "16 0\n-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1\n", "36 0\n-1 0 0 -1 -1 -1 0 -1 0 1 -1 -1 1 1 -1 1 0 0 1 -1 1 1 -1 0 0 1 1 1 -1 1 1 -1 1 1 1 -1\n", "37 0\n0 -1 0 0 0 -1 0 1 0 0 -1 0 -1 -1 0 1 1 0 -1 -1 -1 -1 1 -1 0 0 0 1 -1 -1 1 -1 1 1 -1 -1 -1\n", "42 1\n0...
2,400
2,250
2
12
999_F. Cards and Joy
There are n players sitting at the card table. Each player has a favorite number. The favorite number of the j-th player is f_j. There are k β‹… n cards on the table. Each card contains a single integer: the i-th card contains number c_i. Also, you are given a sequence h_1, h_2, ..., h_k. Its meaning will be explained b...
{ "input": [ "4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n", "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3\n" ], "output": [ "21\n", "0\n" ] }
{ "input": [ "1 1\n1\n2\n1\n", "1 1\n1\n1\n100000\n", "50 1\n995 1815 941 1716 725 1098 747 627 1728 1007 34 1001 679 1742 22 1495 1299 1696 507 631 1971 775 1052 1665 1035 203 1564 1329 1592 1295 983 177 734 1442 172 943 33 486 1078 946 947 592 1524 563 396 1541 1670 326 543 79\n176 214 1601 1758 1468 97...
2,000
0
2
11
1003_E. Tree Constructing
You are given three integers n, d and k. Your task is to construct an undirected tree on n vertices with diameter d and degree of each vertex at most k, or say that it is impossible. An undirected tree is a connected undirected graph with n - 1 edges. Diameter of a tree is the maximum length of a simple path (a path...
{ "input": [ "8 5 3\n", "6 3 3\n", "10 4 3\n", "6 2 3\n" ], "output": [ "YES\n1 2\n2 3\n3 4\n4 5\n5 6\n2 7\n3 8\n", "YES\n1 2\n2 3\n3 4\n2 5\n3 6\n", "YES\n1 2\n2 3\n3 4\n4 5\n2 6\n3 7\n7 8\n7 9\n4 10\n", "NO\n" ] }
{ "input": [ "400000 3 199999\n", "20 6 3\n", "5 5 3\n", "2 3 1\n", "10 9 1\n", "7 5 2\n", "2 1 4\n", "3 2 1\n", "1 1 1\n", "2 2 1\n", "2 3 3\n", "6 4 2\n", "7 4 3\n", "2 10 1\n", "6 5 3\n", "15 5 3\n", "5 4 2\n", "6 5 2\n", "5 4 3\n", "2...
2,100
0
2
10
1070_D. Garbage Disposal
Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it. For each of next n days Vasya knows a_i β€” number of units of garbage he will produce on the i-th day. Each unit of garbage must be dis...
{ "input": [ "3 2\n1 0 1\n", "4 4\n2 8 4 1\n", "3 2\n3 2 1\n", "5 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n" ], "output": [ "2\n", "4\n", "3\n", "5000000000\n" ] }
{ "input": [ "3 10\n5 5 0\n", "1 1\n1\n", "4 4\n3 6 2 3\n", "1 10\n1\n", "185 2\n0 14 2 11 5 17 9 11 8 12 8 17 17 0 4 15 4 17 8 1 2 10 8 0 8 16 1 7 10 4 0 18 2 15 2 1 4 1 10 11 6 10 19 5 5 18 2 1 15 17 0 4 12 19 12 8 11 4 7 15 13 0 9 6 2 6 5 2 17 4 7 9 11 17 1 13 4 6 4 10 1 14 0 13 17 16 10 5 7 19...
1,300
0
2
9
1140_C. Playlist
You have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i β€” its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to...
{ "input": [ "5 3\n12 31\n112 4\n100 100\n13 55\n55 50\n", "4 3\n4 7\n15 1\n3 6\n6 8\n" ], "output": [ "10000", "78" ] }
{ "input": [ "5 1\n11 3\n10 2\n7 4\n6 1\n9 1\n", "8 1\n769 58454\n48687 67740\n51730 90641\n39410 27719\n63633 23862\n39951 40870\n56520 69058\n15454 9033\n", "2 1\n1 2\n2 1\n", "2 2\n100 100\n100 100\n", "10 1\n74069 59157\n2735 28902\n43406 39542\n24166 93361\n18565 14980\n69958 53925\n23473 818...
1,600
0
2
7
1159_A. A pile of stones
Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile. You are given n operations which Vasya has made. Find the minimal possible number of stones that can b...
{ "input": [ "2\n-+\n", "3\n---\n", "5\n++-++\n", "4\n++++\n" ], "output": [ "1\n", "0\n", "3\n", "4\n" ] }
{ "input": [ "4\n-+--\n", "2\n++\n", "98\n----+-+--+-+-++-++++---+-++++-+--++-++++++-+++--+++-+-----+-+--+-----+++++--+-++-+++-+-+++-+---++-\n", "3\n+-+\n", "100\n---+-----------+-++---+----------++++++++++++++++++++++++++++++++++++++++++++-----------------------\n", "100\n--------------------...
800
500
2
7
1181_A. Chunga-Changa
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now. Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per cocon...
{ "input": [ "6 8 2\n", "5 4 3\n" ], "output": [ "7 0\n", "3 1\n" ] }
{ "input": [ "5000000000000 6000000000000 10000000000000\n", "2778787205 1763925790 48326734\n", "582426543750017 789023129080207 4395672028302\n", "0 0 1\n", "1000000000000000000 999999999999999999 3\n", "7 14 5\n", "1 0 1\n", "132940 345844 5\n", "20021126 20031111 20031208\n", ...
1,000
500
2
11
1216_E1. Numerical Sequence (easy version)
The only difference between the easy and the hard versions is the maximum value of k. You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one β€” from 1 to 2...
{ "input": [ "4\n2132\n506\n999999999\n1000000000\n", "5\n1\n3\n20\n38\n56\n" ], "output": [ "8\n2\n9\n8\n", "1\n2\n5\n2\n0\n" ] }
{ "input": [ "1\n755045\n", "19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n10000000000\n100000000000\n1000000000000\n10000000000000\n100000000000000\n1000000000000000\n10000000000000000\n100000000000000000\n1000000000000000000\n", "1\n388645\n", "1\n9124\n", "1\n12...
1,900
0
2
7
125_A. Measuring Lengths in Baden
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The re...
{ "input": [ "42\n", "5\n" ], "output": [ "1 2\n", "0 2\n" ] }
{ "input": [ "4\n", "71\n", "9999\n", "35\n", "199\n", "10000\n", "10\n", "2\n", "9876\n", "8\n", "120\n", "3\n", "1233\n", "501\n", "24\n", "12\n", "13\n", "1000\n", "1\n", "100\n" ], "output": [ "0 1\n", "2 0\n", "277 9\...
1,400
1,000
2
9
1281_C. Cut and Paste
We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i. There is one cursor. The cursor's location β„“ is denoted by an integer in \{0, …, |s|\}, with the following meaning: * If β„“ = 0, then the cursor...
{ "input": [ "4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n" ], "output": [ "25\n1438\n1101\n686531475\n" ] }
{ "input": [ "9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\n", "1\n1000000\n22\n", "1\n941759\n1223231111\n", "1\n1000000\n2211\n", "1\n1000000\n221\n", "1\n1000000\n1212\n", "1\n...
1,700
500
2
9
1325_C. Ehab and Path-etic MEXs
You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold: * Every label is an integer between 0 and n-2 inclusive. * All the written labels are distinct. * The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as ...
{ "input": [ "6\n1 2\n1 3\n2 4\n2 5\n5 6\n", "3\n1 2\n1 3\n" ], "output": [ "0\n3\n1\n2\n4\n", "0\n1\n" ] }
{ "input": [ "6\n1 2\n2 3\n3 4\n3 5\n3 6\n", "7\n6 4\n3 7\n3 5\n1 3\n4 2\n7 4\n", "7\n3 2\n5 7\n4 2\n7 6\n6 3\n1 6\n", "2\n1 2\n", "13\n1 4\n2 4\n3 4\n4 5\n5 11\n11 12\n12 13\n13 6\n6 7\n7 8\n7 9\n7 10\n", "4\n2 3\n2 4\n2 1\n", "5\n1 3\n4 3\n2 5\n3 2\n", "2\n2 1\n", "7\n2 1\n4 7\n2...
1,500
1,250
2
8
1344_B. Monopole Magnets
A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an nΓ— m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowe...
{ "input": [ "3 3\n.#.\n###\n##.\n", "4 5\n....#\n####.\n.###.\n.#...\n", "4 2\n##\n.#\n.#\n##\n", "3 5\n.....\n.....\n.....\n", "2 1\n.\n#\n" ], "output": [ "1\n", "2\n", "-1\n", "0\n", "-1\n" ] }
{ "input": [ "19 19\n##############.....\n.#############.....\n.###########.......\n.###########.......\n.....#######.......\n.....###...........\n...................\n...................\n...................\n...................\n...................\n...................\n...................\n...................\...
2,000
1,000
2
8
1366_B. Shuffle
You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0. You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≀ c, d ≀ r_i, and swap a_c and a_d. Calculate the number of indices k such that it is poss...
{ "input": [ "3\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2\n" ], "output": [ "6\n2\n3\n" ] }
{ "input": [ "9\n100 50 6\n1 49\n51 100\n40 60\n30 70\n20 30\n70 80\n100 1 11\n1 1\n1 1\n1 1\n2 2\n2 100\n1 2\n2 3\n3 4\n5 6\n6 100\n4 5\n1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n11 6 4\n6 6\n1 5\n7 11\n6 6\n3 3 2\n1 2\n2 3\n1000000000 1 1\n1 1000000000\n1000000000 1 1\n1 999999999\n1000000000 1 1\n2 1000000000\n100000000...
1,300
0
2
8
1408_B. Arrays Sum
You are given a non-decreasing array of non-negative integers a_1, a_2, …, a_n. Also you are given a positive integer k. You want to find m non-decreasing arrays of non-negative integers b_1, b_2, …, b_m, such that: * The size of b_i is equal to n for all 1 ≀ i ≀ m. * For all 1 ≀ j ≀ n, a_j = b_{1, j} + b_{2, j}...
{ "input": [ "6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6\n" ], "output": [ "-1\n1\n2\n2\n2\n1\n" ] }
{ "input": [ "1\n3 2\n3 3 3\n", "1\n3 3\n1 1 1\n", "1\n5 5\n5 5 5 5 5\n", "1\n5 3\n1 1 1 1 1\n", "1\n5 2\n5 5 5 5 5\n", "1\n2 2\n3 3\n", "1\n4 2\n1 1 1 1\n", "1\n2 2\n1 1\n", "1\n3 3\n3 3 3\n", "1\n3 2\n5 5 5\n", "1\n2 2\n2 2\n", "1\n5 2\n1 1 1 1 1\n", "1\n3 2\n2 2 ...
1,400
1,000
2
11
1428_E. Carrots for Rabbits
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots...
{ "input": [ "1 4\n19\n", "3 6\n5 3 1\n" ], "output": [ "91\n", "15\n" ] }
{ "input": [ "10 23\n343 984 238 758983 231 74 231 548 893 543\n", "1 1\n1\n", "29 99047\n206580 305496 61753 908376 272137 803885 675070 665109 995787 667887 164508 634877 994427 270698 931765 721679 518973 65009 804367 608526 535640 117656 342804 398273 369209 298745 365459 942772 89584\n", "1 10000...
2,200
1,750
2
12
1451_F. Nullify The Matrix
Jeel and Ashish play a game on an n Γ— m matrix. The rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right. They play turn by turn. Ashish goes first. Initially, each cell of the matrix contains a non-negative integer. Each turn, a player must perform all of the following ac...
{ "input": [ "4\n1 1\n0\n1 3\n0 0 5\n2 2\n0 1\n1 0\n3 3\n1 2 3\n4 5 6\n7 8 9\n" ], "output": [ "\nJeel\nAshish\nJeel\nAshish\n" ] }
{ "input": [ "3\n5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n4 4\n0 0 3 0\n0 2 0 0\n2 0 0 0\n0 0 0 0\n5 5\n0 3 4 5 0\n7 8 9 10 11\n12 13 14 15 16\n17 18 19 20 21\n0 22 23 24 0\n", "5\n5 5\n0 126 30 105 44\n126 98 21 0 108\n124 30 110 115 31\n98 117 87 99 61\n55 72 124 61 0\n5 5\n0 82 44 96 5\n...
2,700
3,000
2
11
1525_E. Assimilation IV
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has n cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monum...
{ "input": [ "3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3\n" ], "output": [ "\n166374062\n" ] }
{ "input": [ "1 1\n1\n", "1 1\n2\n", "3 1\n1\n1\n1\n" ], "output": [ "1\n", "0\n", "1\n" ] }
2,100
0
2
8
157_B. Trace
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,...
{ "input": [ "1\n1\n", "3\n1 4 2\n" ], "output": [ "3.141592653589793\n", "40.840704496667314\n" ] }
{ "input": [ "6\n258 877 696 425 663 934\n", "37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637\n", "100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 639 638 260 419 8 142 403 298 20...
1,000
1,000
2
7
178_A2. Educational Game
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc...
{ "input": [ "8\n1 2 3 4 5 6 7 8\n", "4\n1 0 1 2\n" ], "output": [ "1\n3\n6\n10\n16\n24\n40\n", "1\n1\n3\n" ] }
{ "input": [ "9\n13 13 7 11 3 9 3 5 5\n", "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 20 36 70 66 75 12 54 96\n", "80\n72 66 82 46 ...
1,000
30
2
9
19_C. Deletion of Repeats
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coin...
{ "input": [ "6\n1 2 3 1 2 3\n", "7\n4 5 6 5 6 7 7\n" ], "output": [ "3\n1 2 3 ", "1\n7 " ] }
{ "input": [ "100\n8 43 55 27 70 81 66 10 49 67 24 61 53 0 2 76 96 16 16 1 78 1 69 69 4 59 6 87 98 14 98 20 12 48 20 41 67 90 20 96 44 8 77 94 84 2 61 27 90 42 66 84 5 19 68 13 5 53 13 87 70 41 48 40 19 61 72 31 4 4 59 100 50 64 84 10 96 16 73 3 63 85 67 91 74 63 22 34 6 96 78 42 61 85 3 95 98 84 66 78\n", "1...
2,200
0
2
8
248_B. Chilly Willy
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length n, such that it is simultaneously...
{ "input": [ "5\n", "1\n" ], "output": [ "10080\n", "-1\n" ] }
{ "input": [ "99996\n", "99999\n", "88888\n", "99987\n", "7\n", "99987\n", "21\n", "31\n", "13\n", "99995\n", "123\n", "5000\n", "20\n", "10\n", "45332\n", "14\n", "8\n", "33\n", "9\n", "8824\n", "27324\n", "18\n", "99990\n", ...
1,400
1,000
2
9
272_C. Dima and Staircase
Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≀ a1 ≀ a2 ≀ ... ≀ an). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws eac...
{ "input": [ "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n", "3\n1 2 3\n2\n1 1\n3 1\n", "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n" ], "output": [ "1\n3\n13\n23\n33\n", "1\n3\n", "1\n3\n4\n6\n" ] }
{ "input": [ "2\n1 6\n5\n2 6\n1 2\n1 1\n1 2\n1 7\n", "3\n2 10 15\n1\n1 830\n", "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6\n", "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2\n", "1\n1000000000\n6\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n", "1\n8\n1\n1 42\n", ...
1,500
1,500
2
9
343_C. Read Time
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the...
{ "input": [ "3 4\n2 5 6\n1 3 6 8\n", "3 3\n1 2 3\n1 2 3\n", "1 2\n165\n142 200\n" ], "output": [ "2\n", "0\n", "81\n" ] }
{ "input": [ "10 11\n1 909090909 1818181817 2727272725 3636363633 4545454541 5454545449 6363636357 7272727265 8181818173\n454545455 1363636363 2272727271 3181818179 4090909087 4999999995 5909090903 6818181811 7727272719 8636363627 9545454535\n", "2 4\n3 12\n1 7 8 14\n", "3 3\n2 3 4\n1 3 5\n", "3 3\n1 ...
1,900
1,500
2
11
366_E. Dima and Magic Guitar
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the i-th string holding it on the j-th fret...
{ "input": [ "4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1\n", "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5\n" ], "output": [ "8\n", "4\n" ] }
{ "input": [ "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "11 11 9 11\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 2 2 1\n1 1 1 1 1 1 1 1 3 1 1\n1 1 1 1 1 1 1 3 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 2 1 1 1 1 1 1 1\...
2,200
2,500
2
10
38_D. Vasya the Architect
Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart. Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides ...
{ "input": [ "3\n0 0 3 3\n1 0 4 3\n2 0 5 3\n", "2\n0 0 3 3\n1 0 4 3\n", "2\n0 0 3 3\n2 0 5 3\n" ], "output": [ "3", "2", "1" ] }
{ "input": [ "7\n4 6 1 9\n-1 4 6 11\n8 13 -3 2\n-5 0 45 50\n-2 50 45 3\n45 50 -4 1\n45 50 -1 4\n", "11\n12 12 -12 -12\n11 8 -11 -14\n-15 -11 -3 1\n-16 -3 -14 -1\n-7 -8 -21 6\n37 -6 -19 50\n-21 -12 41 50\n48 -13 -15 50\n48 -14 -16 50\n-21 -18 47 50\n40 50 -15 -5\n", "20\n9 -3 16 4\n11 2 14 -1\n6 -6 19 7\n1...
1,900
0
2
9
40_C. Berland Square
Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1, 2, ..., K and the center i...
{ "input": [ "3 3 4 7\n", "1 0 1 2\n", "1 0 1 1\n" ], "output": [ " 17\n", " 3\n", " 4\n" ] }
{ "input": [ "99085 7738 98097 -6487\n", "1 2 2 1\n", "93430 5720 93581 -2371\n", "97530 -7728 92184 -755\n", "93564 -4520 99118 -52061\n", "100000 100 100000 70000\n", "98405 -62879 99461 -33688\n", "5 4 3 -2\n", "93564 8371 99118 6409\n", "91125 7374 92925 -5261\n", "9844...
2,300
1,500
2
8
438_B. The Child and Zoo
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains ai animals in it. Also there are m roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so you can reach any area of the zoo from any other area using the roads....
{ "input": [ "7 8\n40 20 10 30 20 50 40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 4\n5 7\n", "3 3\n10 20 30\n1 2\n2 3\n3 1\n", "4 3\n10 20 30 40\n1 3\n2 3\n4 3\n" ], "output": [ "18.5714285714\n", "13.3333333333\n", "16.6666666667\n" ] }
{ "input": [ "10 19\n13637 26970 19043 3616 12880 19387 12539 25190 2452 1261\n1 2\n1 3\n1 4\n2 5\n3 6\n6 7\n3 8\n5 9\n3 10\n4 10\n9 3\n2 8\n4 3\n2 3\n7 10\n7 8\n5 10\n5 6\n7 4\n", "10 19\n15704 19758 26631 25050 22778 15041 8487 26418 5136 4199\n1 2\n1 3\n1 4\n2 5\n1 6\n2 7\n2 8\n7 9\n6 10\n7 3\n4 7\n6 4\n6 ...
1,900
2,000
2
15
45_I. TCMCF+++
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost β€” a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin...
{ "input": [ "4\n-2 -2 -2 -2\n", "13\n100 100 100 100 100 100 100 100 100 100 100 100 100\n", "5\n1 2 -3 3 3\n" ], "output": [ "-2 -2 -2 -2\n", "100 100 100 100 100 100 100 100 100 100 100 100 100\n", "1 2 3 3\n" ] }
{ "input": [ "100\n-93 -100 -99 -100 -99 -100 -99 -99 -99 -100 -99 -99 -100 -98 -98 -100 -99 -100 -95 -100 -100 -99 -98 -100 -96 -99 -99 -100 -97 -98 -100 -98 -98 -93 -100 -100 -99 -100 -100 -98 -100 -98 -100 -98 -97 -99 -98 -99 -99 -99 -100 -100 -100 -100 -98 -93 -100 -100 -97 -100 -100 -100 -98 -99 -100 -95 -98...
1,400
0
2
9
483_C. Diverse Permutation
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn. Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k d...
{ "input": [ "5 2\n", "3 1\n", "3 2\n" ], "output": [ "1 3 2 4 5 ", "1 2 3 \n", "1 3 2 " ] }
{ "input": [ "29857 9843\n", "10 3\n", "2 1\n", "10931 8824\n", "4 2\n", "6591 407\n", "10 9\n", "5 4\n", "3222 311\n", "27687 4031\n", "23347 20494\n", "10 4\n", "7 5\n", "25517 1767\n", "4 1\n", "9 8\n", "1111 122\n", "32342 1221\n", "32244...
1,200
500
2
9
507_C. Guess Your Way Out!
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the leaf nodes from the left to ...
{ "input": [ "1 2\n", "10 1024\n", "3 6\n", "2 3\n" ], "output": [ "2\n", "2046\n", "10\n", "5\n" ] }
{ "input": [ "49 295606900104348\n", "1 1\n", "29 113463931\n", "40 615535158153\n", "50 905353992267944\n", "22 3343393\n", "20 589266\n", "19 12783\n", "30 414940886\n", "32 3786259360\n", "35 12080044014\n", "13 4796\n", "50 562949953421312\n", "33 2599588275...
1,700
1,500
2
10
556_D. Case of Fugitive
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: ...
{ "input": [ "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n", "2 2\n11 14\n17 18\n2 9\n", "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999\n" ], "output": [ "Yes\n2 3 1 ", "No", "Yes\n1 " ] }
{ "input": [ "2 1\n1 1\n100 100\n5\n", "3 2\n1000000000000000 1000000000000000\n3000000000000000 4000000000000000\n6000000000000000 7000000000000000\n2000000000000000 4000000000000000\n", "6 9\n1 2\n8 16\n21 27\n31 46\n49 57\n59 78\n26 27 28 13 2 4 2 2 24\n", "20 10\n4 9\n10 15\n17 18\n20 21\n25 27\n2...
2,000
750
2
8
582_B. Once Again...
You are given an array of positive integers a1, a2, ..., an Γ— T of length n Γ— T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array. Input The first line contains two space-separated integers: n, T (1 ≀ n ≀ 100, 1 ≀ T ≀ 107). The second li...
{ "input": [ "4 3\n3 1 4 2\n" ], "output": [ "5\n" ] }
{ "input": [ "100 10000000\n1 2 2 1 2 2 1 1 2 2 1 2 1 1 1 1 1 2 2 2 1 2 1 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 1 2 2 1 1 2 2 2 2 2 2 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 2 2 1 2 1 1 2 2 1 1 1 2 1 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1\n", "99 10000000\n96 97 98 93 94 95 90 91 92 87 88 89 84 85 86 81 82 83 78 79 80 7...
1,900
1,250
2
8
604_B. More Cowbell
Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single ...
{ "input": [ "4 3\n2 3 5 9\n", "2 1\n2 5\n", "3 2\n3 5 7\n" ], "output": [ "9\n", "7\n", "8\n" ] }
{ "input": [ "10 5\n15 15 20 28 38 44 46 52 69 94\n", "100 89\n474 532 759 772 803 965 1043 1325 1342 1401 1411 1452 1531 1707 1906 1928 2034 2222 2335 2606 2757 2968 2978 3211 3513 3734 3772 3778 3842 3948 3976 4038 4055 4113 4182 4267 4390 4408 4478 4595 4668 4792 4919 5133 5184 5255 5312 5341 5476 5628 568...
1,400
1,000
2
11
626_E. Simple Skewness
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a colle...
{ "input": [ "2\n1 2\n", "4\n1 1 2 2\n", "4\n1 2 3 12\n" ], "output": [ "1\n 1 \n", "3\n 1 1 ...
{ "input": [ "21\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712 1000000\n", "1\n412237\n", "3\n76427 184396 963319\n", "5\n741304 281944 258539 54430 284591\n", "2\n725491 635622\n", "40\n999999 99999...
2,400
2,000
2
7
676_A. Nicholas and Permutation
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance...
{ "input": [ "6\n6 5 4 3 2 1\n", "7\n1 6 5 3 4 7 2\n", "5\n4 5 1 3 2\n" ], "output": [ "5\n", "6\n", "3\n" ] }
{ "input": [ "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68\n", "12\n3 6 7 8 9 10 12 5 4 2 11 1\n", "81\n63 22 4 41 43 74 64 39 1...
800
500
2
7
69_A. Young Physicist
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
{ "input": [ "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n", "3\n4 1 7\n-2 4 -1\n1 -5 -3\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0\n", "3\n1 2 3\n3 2 1\n0 0 0\n", "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-...
1,000
500
2
7
742_A. Arpa’s hard exam and Mehrdad’s naive cheat
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n. <image> Mehrdad has become quite confused and wants you to help him. Please hel...
{ "input": [ "2\n", "1\n" ], "output": [ "4\n", "8\n" ] }
{ "input": [ "12\n", "1378\n", "51202278\n", "989898989\n", "4\n", "7\n", "9\n", "6\n", "8\n", "12193721\n", "999999995\n", "999999999\n", "11\n", "999999996\n", "999999998\n", "3\n", "14\n", "15\n", "10\n", "999999994\n", "1000\n", ...
1,000
500
2
11
765_E. Tree Folding
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent verti...
{ "input": [ "6\n1 2\n2 3\n2 4\n4 5\n1 6\n", "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n" ], "output": [ "3\n", "-1\n" ] }
{ "input": [ "10\n4 2\n7 4\n2 6\n2 5\n4 8\n10 3\n2 9\n9 1\n5 10\n", "10\n5 10\n7 8\n8 3\n2 6\n3 2\n9 7\n4 5\n10 1\n6 4\n", "4\n4 1\n4 3\n4 2\n", "3\n3 1\n1 2\n", "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n6 8\n8 9\n", "5\n1 5\n2 3\n2 4\n1 2\n", "8\n6 1\n4 7\n4 8\n8 5\n7 6\n4 3\n4 2\n", "7\n5 6\...
2,200
2,500
2
8
789_B. Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ...
{ "input": [ "123 1 2143435 4\n123 11 -5453 141245\n", "3 2 30 4\n6 14 25 48\n", "123 1 2143435 4\n54343 -13 6 124\n" ], "output": [ "0\n", "3\n", "inf\n" ] }
{ "input": [ "-100 0 50 1\n0\n", "-1000 0 10 1\n5\n", "-3 1 100 1\n3\n", "1000000000 100000 1000000000 4\n5433 13 6 0\n", "5 1 5 5\n1 2 3 4 0\n", "2 -1 6 1\n2\n", "3 2 30 3\n-691070108 -934106649 -220744807\n", "0 8 5 1\n9\n", "2 -1 1 1\n1\n", "3 2 115 16\n24 48 12 96 3 7200311...
1,700
1,000
2
10
80_D. Falling Anvils
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all. Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who ...
{ "input": [ "2\n4 2\n1 2\n" ], "output": [ "0.6250000000\n0.5312500000\n" ] }
{ "input": [ "90\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n1 2\n2 2\n3 2\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n1 3\n2 3\n3 3\n4 3\n5 3\n6 3\n7 3\n8 3\n9 3\n1 4\n2 4\n3 4\n4 4\n5 4\n6 4\n7 4\n8 4\n9 4\n1 5\n2 5\n3 5\n4 5\n5 5\n6 5\n7 5\n8 5\n9 5\n1 6\n2 6\n3 6\n4 6\n5 6\n6 6\n7 6\n8 6\n9 6\n1 7\n2 7\n3 7\n4 7\n5 7\n6...
1,800
1,000
2
8
835_B. The number on the board
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change. You have to find the minimum number of digits in which these two numbers c...
{ "input": [ "3\n11\n", "3\n99\n" ], "output": [ "1\n", "0\n" ] }
{ "input": [ "3\n21\n", "3\n111\n", "6\n33\n", "6\n222\n", "5\n5\n", "2\n11\n", "1\n1\n", "500\n1899337170458531693764539600958943248270674811247191310452938511077656066239840703432499357537079035\n", "900\n757042381727296702755308246486396202463521737230791950659419305557230065773...
1,100
750
2
9
87_C. Interesting Game
Two best friends Serozha and Gena play a game. Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak =...
{ "input": [ "6\n", "100\n", "3\n" ], "output": [ "-1\n", "8\n", "2\n" ] }
{ "input": [ "56\n", "1\n", "46\n", "63478\n", "7578\n", "56056\n", "78\n", "66873\n", "8149\n", "35708\n", "81207\n", "41385\n", "37317\n", "74424\n", "67817\n", "684\n", "15\n", "96992\n", "38798\n", "19715\n", "627\n", "39509\n...
2,000
1,500
2
11
903_E. Swapping Characters
We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string). You are gi...
{ "input": [ "5 4\nabcd\ndcba\nacbd\ndbca\nzzzz\n", "3 4\nabac\ncaab\nacba\n", "3 4\nkbbu\nkbub\nubkb\n" ], "output": [ "-1\n", "acab\n", "kbub\n" ] }
{ "input": [ "3 4\nkbub\nkbbu\nubkb\n", "5 5\nzbibx\nzbbix\nzbibx\nxbibz\nxbibz\n", "100 2\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz...
2,200
0
2
13
954_G. Castle Defense
Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the...
{ "input": [ "4 2 0\n1 2 3 4\n", "5 0 6\n5 4 3 4 9\n", "5 1 1\n2 1 2 1 2\n" ], "output": [ "6\n", "5\n", "3\n" ] }
{ "input": [ "1 0 0\n1\n", "1 1 10\n23\n", "100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 430 310 634 253 281 938 975 272 821 247 626 294 25 829 919 340 728 461 864 756 157 798 474 513 760 107 519 102 69 ...
2,000
0
2
7
1016_A. Death Note
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo...
{ "input": [ "1 100\n99\n", "4 20\n10 9 19 2\n", "3 5\n3 7 9\n" ], "output": [ "0\n", "0 0 1 1\n", "0 2 1\n" ] }
{ "input": [ "1 1\n2\n", "10 4\n9 5 6 4 3 9 5 1 10 7\n", "9 9\n1 7 1 8 4 7 9 8 8\n", "1 1\n1\n", "16 2\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999\n" ], "output": [ "2\n", ...
900
0
2
7
103_A. Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
{ "input": [ "2\n2 2\n", "2\n1 1\n", "1\n10\n" ], "output": [ "5", "2", "10" ] }
{ "input": [ "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1\n", "1\n84355694\n", "3\n2 4 1\n", "50\n515844718 503470143 928669067 209884122 322...
1,100
500
2
8
1062_B. Math
JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times: * mul x: multiplies n by x (where x is an arbitrary positive integer). * sqrt: replaces n with √...
{ "input": [ "20\n", "5184\n" ], "output": [ "10 2\n", "6 4\n" ] }
{ "input": [ "2\n", "328509\n", "279936\n", "341\n", "605000\n", "11\n", "4\n", "786432\n", "982081\n", "52488\n", "6444\n", "12\n", "1105\n", "49\n", "252601\n", "1000000\n", "162000\n", "29341\n", "1729\n", "30492\n", "994009\n", ...
1,500
1,000
2
7
1084_A. The Fair Nut and Elevator
The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided ...
{ "input": [ "2\n1 1\n", "3\n0 2 1\n" ], "output": [ "4\n", "16\n" ] }
{ "input": [ "5\n6 1 1 8 3\n", "5\n4 9 4 2 6\n", "3\n1 2 2\n", "100\n23 94 2 59 41 51 92 74 92 76 37 98 76 47 60 4 22 32 22 32 57 39 68 60 38 41 61 7 34 98 42 44 52 100 81 24 16 51 10 84 34 52 73 100 69 38 14 77 32 4 59 37 68 81 6 37 52 6 96 22 12 23 63 57 59 18 20 1 57 87 22 68 65 7 70 39 55 49 41 54...
1,000
500
2
9
1131_C. Birthday
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing n...
{ "input": [ "3\n30 10 20\n", "5\n2 1 1 3 2\n" ], "output": [ "10 30 20 ", "1 2 3 2 1 " ] }
{ "input": [ "5\n7318577 1728333 8514304 9971719 9004162\n", "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 ...
1,200
1,500
2
11
1151_E. Number of Components
The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≀ i < n there is an edge between the vertices of i and i+1. Denote the function f(l, r), which takes two in...
{ "input": [ "3\n2 1 3\n", "10\n1 5 2 5 5 3 10 6 5 1\n", "4\n2 1 1 3\n" ], "output": [ "7\n", "104\n", "11\n" ] }
{ "input": [ "9\n1 9 1 1 4 5 9 9 1\n", "44\n42 44 4 24 29 17 32 30 30 9 28 9 22 16 20 41 17 19 41 23 28 19 38 44 1 34 41 34 19 36 32 37 22 31 4 3 27 23 21 21 26 39 20 8\n", "40\n35 33 20 13 21 4 16 21 22 35 20 39 32 29 27 5 24 3 12 10 15 13 2 31 1 11 20 39 17 37 21 10 36 4 29 22 9 22 22 1\n", "1\n1\n"...
2,100
2,250
2
10
1173_D. Nauuo and Circle
Nauuo is a girl who loves drawing circles. One day she has drawn a circle and wanted to draw a tree on it. The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n. Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points o...
{ "input": [ "4\n1 2\n1 3\n1 4\n", "4\n1 2\n1 3\n2 4\n" ], "output": [ "24\n", "16\n" ] }
{ "input": [ "8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n", "7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n", "3\n1 2\n3 2\n", "2\n2 1\n", "10\n5 4\n5 2\n3 7\n9 3\n3 2\n3 1\n3 8\n9 10\n1 6\n", "6\n2 1\n3 2\n4 1\n5 4\n1 6\n", "5\n3 5\n4 3\n2 4\n1 2\n", "6\n4 6\n1 5\n5 4\n5 3\n2 4\n", "9\n5 6\n1 3\n2 ...
1,900
750
2
7
1191_A. Tokitsukaze and Enhancement
Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute β€” health points, shortened to HP. In general, different values of HP are grouped into 4 categories: * Category A if HP is in the form of (4 n + 1), that is, when divided by 4, the remainder is ...
{ "input": [ "33\n", "98\n" ], "output": [ "0 A\n", "1 B\n" ] }
{ "input": [ "85\n", "99\n", "50\n", "100\n", "59\n", "60\n", "95\n", "93\n", "91\n", "30\n", "88\n", "83\n", "32\n", "52\n", "43\n", "67\n", "42\n", "36\n", "76\n" ], "output": [ "0 A\n", "2 A\n", "1 B\n", "1 A\n", "2...
800
500
2
10
122_D. Lucky Transformation
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consisting of n digits without leading zeroes. He represented it as an array of d...
{ "input": [ "4 2\n4478\n", "7 4\n4727447\n" ], "output": [ "4478\n", "4427477\n" ] }
{ "input": [ "7 74\n4777774\n", "3 99\n447\n", "47 7\n77774477747474477477477774747747447447774777474\n", "74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444\n", "10 200\n6860544593\n", "100 1000000000\n5849347454478644774747479437170493249634474874684784...
1,500
1,000
2
9
1251_C. Minimize The Integer
You are given a huge integer a consisting of n digits (n is between 1 and 3 β‹… 10^5, inclusive). It may contain leading zeros. You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 2). For example, if a = 032...
{ "input": [ "3\n0709\n1337\n246432\n" ], "output": [ "0079\n1337\n234642\n" ] }
{ "input": [ "1\n1003\n" ], "output": [ "0013\n" ] }
1,600
0
2
7
1271_A. Suits
A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets. The store does not sell single clothing items β€” instead, it sells suits of two types: * a suit of the first type consists of one tie and one jacket; * a suit of the second type ...
{ "input": [ "4\n5\n6\n3\n1\n2\n", "17\n14\n5\n21\n15\n17\n", "12\n11\n13\n20\n4\n6\n" ], "output": [ "6\n", "325\n", "102\n" ] }
{ "input": [ "88\n476\n735\n980\n731\n404\n", "844\n909\n790\n209\n809\n949\n", "406\n847\n512\n65\n86\n990\n", "91\n75\n768\n322\n530\n291\n", "58967\n2953\n35483\n681\n780\n304\n", "58253\n17658\n9101\n94990\n625\n178\n", "66\n393\n648\n651\n6\n648\n", "5771\n19397\n45992\n46525\n336...
800
500
2
8
1294_B. Collecting Packages
There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ...
{ "input": [ "3\n5\n1 3\n1 2\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n" ], "output": [ "YES\nRUUURRRRUU\nNO\nYES\nRRRRUUU\n" ] }
{ "input": [ "2\n1\n1 1\n1\n1 1\n" ], "output": [ "YES\nRU\nYES\nRU\n" ] }
1,200
0
2
11
1336_E1. Chiori and Doll Picking (easy version)
This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
{ "input": [ "6 7\n11 45 14 9 19 81\n", "4 4\n3 5 8 14\n" ], "output": [ "1 2 11 20 15 10 5 0 \n", "2 2 6 6 0 \n" ] }
{ "input": [ "30 30\n65536 536870912 2097152 512 32768 16384 8388608 16777216 524288 4194304 1 1048576 2048 262144 64 4096 8192 256 131072 2 268435456 33554432 32 16 134217728 8 67108864 128 4 1024\n", "6 35\n23601314651 29074846252 10638992479 32779777411 26378409257 33108582487\n", "54 53\n8192 21474836...
2,700
1,750
2
8
1359_B. New Theatre Square
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved. The square still has a rectangular shape of n Γ— m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav...
{ "input": [ "4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1 10 1\n.\n.\n3 3 3 7\n..*\n*..\n.*.\n" ], "output": [ "10\n1\n20\n18\n" ] }
{ "input": [ "1\n3 3 2 4\n**.\n***\n***\n", "1\n9 9 9 9\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n" ], "output": [ "2\n", "405\n" ] }
1,000
0
2
10
1379_D. New Passenger Trams
There are many freight trains departing from Kirnes planet every day. One day on that planet consists of h hours, and each hour consists of m minutes, where m is an even number. Currently, there are n freight trains, and they depart every day at the same time: i-th train departs at h_i hours and m_i minutes. The gover...
{ "input": [ "2 24 60 16\n16 0\n17 15\n", "2 24 60 15\n16 0\n17 15\n" ], "output": [ "1 0\n2 ", "0 0\n" ] }
{ "input": [ "9 3 24 9\n1 15\n0 6\n0 22\n2 22\n2 7\n1 7\n1 23\n2 14\n0 14\n", "10 11 12 6\n9 5\n8 5\n9 11\n7 5\n10 5\n1 5\n2 11\n3 5\n2 5\n3 11\n", "10 24 60 8\n10 59\n21 56\n0 42\n21 27\n5 24\n5 53\n16 5\n5 22\n10 11\n10 46\n", "9 24 60 21\n1 36\n2 35\n2 16\n2 55\n1 16\n0 35\n0 55\n1 56\n0 15\n", ...
2,300
1,500
2
8
139_B. Wallpaper
Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height). Boris cho...
{ "input": [ "1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n" ], "output": [ "640\n" ] }
{ "input": [ "1\n9 10 7\n1\n7 1 3\n", "20\n110 466 472\n112 153 152\n424 492 490\n348 366 113\n208 337 415\n491 448 139\n287 457 403\n444 382 160\n325 486 284\n447 454 136\n216 412 418\n217 208 228\n109 436 291\n293 382 421\n483 339 174\n213 327 183\n278 268 147\n181 424 457\n388 289 430\n174 269 305\n20\n221...
1,600
1,000
2
12
1423_F. Coins
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them: All of them take a sit at their round table, some of them with the golde...
{ "input": [ "4 2\n1 2\n2 2\n", "3 2\n1 1\n2 2\n", "6 2\n2 3\n4 1\n" ], "output": [ "1", "-1", "1" ] }
{ "input": [ "25 2\n1 23\n3 1\n", "178279081 0\n", "999999999 1\n100 1000000000\n", "1 1\n1 1\n", "1001 1\n60 10001\n", "10 4\n4 1\n6 5\n7 1\n8 3\n", "999999999 1\n999999999 999999999\n", "1000 1\n1 1000\n", "1000000000 3\n30490 19232\n45250 999980767\n264372930 1\n", "10000000...
2,700
0
2
13
1468_G. Hobbits
The hobbits Frodo and Sam are carrying the One Ring to Mordor. In order not to be spotted by orcs, they decided to go through the mountains. The mountain relief can be represented as a polyline with n points (x_i, y_i), numbered from 1 to n (x_i < x_{i + 1} for 1 ≀ i ≀ n - 1). Hobbits start their journey at the point ...
{ "input": [ "6 10\n10 40\n20 10\n25 30\n30 15\n50 15\n65 30\n", "2 10000\n0 10000\n400000 0\n", "9 5\n0 0\n5 10\n15 10\n20 0\n25 11\n30 0\n35 10\n50 10\n60 5\n" ], "output": [ "\n70.4034587602\n", "\n400124.9804748512\n", "\n27.2787986124\n" ] }
{ "input": [ "4 6\n0 0\n2 4\n7 5\n10 0\n", "5 2\n1 3\n4 4\n5 7\n7 5\n10 4\n", "5 2\n1 3\n4 4\n5 1\n7 5\n10 4\n", "4 6\n0 0\n4 4\n7 5\n10 0\n", "5 1\n1 5\n4 4\n6 7\n7 3\n10 1\n", "4 1\n0 0\n1 4\n7 2\n10 0\n", "4 6\n0 0\n2 1\n7 5\n10 0\n", "2 1\n0 0\n1 0\n", "5 1\n1 5\n4 4\n5 1\n7 3\...
2,500
0
2
7
1493_A. Anti-knapsack
You are given two integers n and k. You are asked to choose maximum number of distinct integers from 1 to n so that there is no subset of chosen numbers with sum equal to k. A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it. Input The first line c...
{ "input": [ "3\n3 2\n5 3\n1 1\n" ], "output": [ "\n2\n3 1 \n3\n4 5 2 \n0\n\n" ] }
{ "input": [ "70\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n4 1\n4 2\n4 3\n4 4\n5 1\n5 2\n5 3\n5 4\n5 5\n6 1\n6 2\n6 3\n6 4\n6 5\n6 6\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n8 8\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n9 9\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9\n10 10\n15 1\n15 2...
800
750
2
13
1515_G. Phoenix and Odometers
In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles. There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer that begins at s_i, increments for each mile driven, and resets to ...
{ "input": [ "4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n4 3 5\n", "4 4\n1 2 1\n2 3 1\n3 1 2\n1 4 3\n3\n1 1 3\n1 2 4\n4 0 1\n" ], "output": [ "\nYES\nYES\n", "\nYES\nNO\nYES\n" ] }
{ "input": [ "2 1\n2 1 1\n1\n2 1 2\n" ], "output": [ "NO\n" ] }
2,700
3,500
2
7
171_A. Mysterious numbers - 1
Input The input contains two integers a1, a2 (0 ≀ ai ≀ 109), separated by a single space. Output Output a single integer. Examples Input 3 14 Output 44 Input 27 12 Output 48 Input 100 200 Output 102
{ "input": [ "27 12\n", "3 14\n", "100 200\n" ], "output": [ "48\n", "44\n", "102\n" ] }
{ "input": [ "59961393 89018456\n", "937477084 827336327\n", "0 0\n", "957747793 424238335\n", "859484421 914544919\n", "365180540 540383426\n", "35005211 521595368\n", "369133069 125898167\n", "911759956 749241873\n", "336465782 861021530\n", "304089172 303455736\n", "...
1,200
0
2
10
190_D. Non-Secret Cypher
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the informati...
{ "input": [ "5 3\n1 2 1 1 3\n", "4 2\n1 2 1 2\n", "3 1\n1 1 1\n" ], "output": [ " 2\n", " 3\n", " 6\n" ...
{ "input": [ "63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 79919 76826 79919 79919 76826 76826 46132 76826 40347 79919 46132 76826 83599 79919 79919 46132 46132 46132 83599 83599 79919 46132 83599 93821 76826 81314 79919 79919 83599 76826 76826 76826 76826 46132 76826 46132 79919 76826 ...
1,900
2,000
2
10
238_D. Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. * Current character pointer (CP); *...
{ "input": [ "7 4\n1&gt;3&gt;22&lt;\n1 3\n4 7\n7 7\n1 7\n" ], "output": [ "0 1 0 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 0 0 0 0 0\n" ] }
{ "input": [ "5 1\n1>3><\n4 5\n", "4 1\n34><\n1 4\n", "3 10\n<<<\n2 3\n3 3\n2 3\n3 3\n1 3\n1 1\n1 2\n3 3\n1 1\n2 2\n", "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7\n", "1 1\n0\n1 1\n", "10 30\n306<<>4>04\n2 2\n6 6\n1 10\n1 8\n2 4\n9 10\n2 8\n3 5\n7 7\n2 6\n1 3\n3 7\n4 9\n3 10\n5 9\n7 10\n1 3\n5 7\n4 10\n...
2,900
2,000
2
8
263_B. Squares
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square. Vasya wants to find such...
{ "input": [ "3 1\n2 4 1\n", "4 3\n5 1 3 4\n", "4 50\n5 1 10 2\n" ], "output": [ "4 4\n", "3 3\n", "-1\n" ] }
{ "input": [ "20 17\n407 2799 2032 2154 8119 9404 6718 7914 916 4720 1267 9403 5497 4518 9072 7828 8364 8230 3057 7770\n", "2 1\n1 2\n", "1 2\n10\n", "2 1\n8 20\n", "5 1\n1 2 3 4 5\n", "50 25\n1498786 501094 6396443 1167317 719496 636212 1912961 3111395 9572144 6277130 9288513 7311574 4038261 ...
900
500
2
8
287_B. Pipeline
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only on...
{ "input": [ "4 3\n", "8 4\n", "5 5\n" ], "output": [ "2\n", "-1\n", "1\n" ] }
{ "input": [ "1000000000000000000 1000000000\n", "525 34\n", "1000000000 999999999\n", "1 1000000000\n", "223265034477 726990\n", "499999998500000000 1000000000\n", "499999999500000000 1000000000\n", "499999998500000001 1000000000\n", "462498979 204468265\n", "49999999950000000...
1,700
1,500
2
8
312_B. Archer
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability th...
{ "input": [ "1 2 1 2\n" ], "output": [ "0.666666667\n" ] }
{ "input": [ "719 735 626 990\n", "1 3 1 3\n", "64 704 148 603\n", "486 868 929 999\n", "533 773 823 998\n", "897 957 92 898\n", "933 977 266 450\n", "518 816 243 359\n", "3 4 3 4\n", "699 925 441 928\n", "450 885 755 836\n", "882 962 311 811\n", "1 3 2 3\n", "4...
1,300
1,000
2
9
401_C. Team
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ...
{ "input": [ "4 8\n", "1 5\n", "1 2\n", "4 10\n" ], "output": [ "110110110110\n", "-1\n", "110\n", "11011011011011\n" ] }
{ "input": [ "5 4\n", "4247 8495\n", "3 2\n", "6 5\n", "1 4\n", "7101 14204\n", "8826 12432\n", "4 3\n", "2 5\n", "3830 6966\n", "1027 2030\n", "4610 4609\n", "2 3\n", "42346 51898\n", "3 1\n", "32342 64687\n", "954 1788\n", "19 30\n", "4 100...
1,400
1,500
2
10
429_D. Tricky Function
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t...
{ "input": [ "4\n1 0 0 -1\n", "2\n1 -1\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "5\n10 11 12 13 -40\n", "3\n0 2 3\n", "5\n0 4 10 -5 -5\n", "4\n0 100 100 -200\n", "4\n10 10 -10 -10\n", "2\n1 10000\n", "3\n10 10 -10\n", "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 6...
2,200
2,000
2
8
451_B. Sort the Array
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:...
{ "input": [ "2\n1 2\n", "4\n2 1 3 4\n", "4\n3 1 2 4\n", "3\n3 2 1\n" ], "output": [ "yes\n1 1\n", "yes\n1 2\n", "no\n", "yes\n1 3\n" ] }
{ "input": [ "6\n19517752 43452931 112792556 68417469 779722934 921694415\n", "4\n1 4 2 3\n", "5\n226959376 840957605 833410429 273566427 872976052\n", "6\n169793171 335736854 449917902 513287332 811627074 938727967\n", "6\n509329 173849943 297546987 591032670 796346199 914588283\n", "2\n69957...
1,300
1,000
2
7
474_A. Keyboard
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally move...
{ "input": [ "R\ns;;upimrrfod;pbr\n" ], "output": [ "allyouneedislove\n" ] }
{ "input": [ "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n", "L\nq\n", "R\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", "R\n.\n", "L\ngggggggggggggggggggggggggggggggggggggggggg\...
900
500
2
7
521_A. DNA Alignment
Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences. Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in whic...
{ "input": [ "2\nAG\n", "3\nTTT\n", "1\nC\n" ], "output": [ "4\n", "1\n", "1\n" ] }
{ "input": [ "20\nTAAGCGACCAGGTGCTTTAC\n", "15\nAGCGAATCCCATTGT\n", "4\nGACT\n", "1\nT\n", "3\nGCA\n", "318\nTATCAATCGGTACGTGCGCATCATTGTCAATCGGGCTTCATGGCTTGCGGGCGCTACCCGAGGGGAAGCTGCGGACAGGTAGGTAAGATACACACGAACCAAACGGAGTTATGTTGGATAAATTGGCTGGAAGGGCGTAGGTATATCGAGTCGCGGACCTGGCATAGACTATCAGGGGCAGCGGT...
1,500
1,500
2
9
596_C. Wilbur and Points
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≀ x' ≀ x and 0 ≀ y' ≀ y also belong to this set. Now Wilbur wants to number the points in the set he has, that is ...
{ "input": [ "5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0\n", "3\n1 0\n0 0\n2 0\n0 1 2\n" ], "output": [ "YES\n0 0\n1 0\n2 0\n0 1\n1 1\n", "NO\n" ] }
{ "input": [ "1\n0 0\n-9876\n", "9\n0 0\n1 0\n2 0\n0 1\n1 1\n2 1\n1 2\n2 2\n0 2\n0 0 0 -1 -1 -2 1 1 2\n", "40\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n1 0\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\...
1,700
1,500
2
8
638_B. Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
{ "input": [ "3\nbcd\nab\ncdef\n", "4\nx\ny\nz\nw\n" ], "output": [ "abcdef\n", "wxyz\n" ] }
{ "input": [ "4\nrz\nvu\nxy\npg\n", "70\nxv\nlu\ntb\njx\nseh\nc\nm\ntbr\ntb\ndl\ne\nd\nt\np\nn\nse\nna\neh\nw\np\nzkj\nr\nk\nrw\nqf\ndl\ndl\ns\nat\nkjx\na\nz\nmig\nu\nse\npse\nd\ng\nc\nxv\nv\ngo\nps\ncd\nyqf\nyqf\nwzk\nxv\nat\nw\no\nl\nxvm\nfpse\nz\nk\nna\nv\nseh\nk\nl\nz\nd\nz\nn\nm\np\ng\nse\nat\n", "10...
1,500
1,000
2
8
712_B. Memory and Trident
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: * An 'L' indicates he should move one unit left. * An 'R' indicates he should move one unit right. * A 'U' indicates he should move one unit up. * A 'D' indicates he shoul...
{ "input": [ "UDUR\n", "RUUR\n", "RRU\n" ], "output": [ "1\n", "2\n", "-1\n" ] }
{ "input": [ "RDDLLDLUUUDDRDRURLUUURLLDDLRLUURRLLRRLDRLLUDRLRULLDLRRLRLRLRUDUUDLULURLLDUURULURLLRRRURRRDRUUDLDRLRDRLRRDDLDLDLLUDRUDRLLLLDRDUULRUURRDLULLULDUDULRURRDDDLLUDRLUDDLDDDRRDDDULLLLDLDRLRRLRRDDRLULURRUDRDUUUULDURUDRDLDDUDUDRRURDULRRUDRLRRDLUURURDLDRLRDUDDDLDDDURURLUULRDUUULRURUDUDRRUDULLLUUUDRLLDRRDDLRUDR...
1,100
1,000
2
7
733_A. Grasshopper And the String
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
{ "input": [ "ABABBBACFEYUKOTT\n", "AAA\n" ], "output": [ "4\n", "1\n" ] }
{ "input": [ "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS\n", "AABBYYYYYYYY\n", "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA\n", "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRL...
1,000
500
2
8
757_B. Bash's Big Day
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, ...
{ "input": [ "5\n2 3 4 6 7\n", "3\n2 3 4\n" ], "output": [ "3\n", "2\n" ] }
{ "input": [ "3\n49999 49999 99998\n", "3\n457 457 457\n", "2\n4 9\n", "3\n49999 99998 99998\n", "10\n1 1 1 1 1 1 1 1 1 1\n", "2\n88258 44129\n", "7\n9 4 2 3 3 9 8\n", "3\n2 1 1\n", "3\n1 1 2\n", "4\n49441 25225 9081 4036\n", "6\n1623 45906 37856 34727 27156 12598\n", "...
1,400
1,000
2
10
778_D. Parquet Re-laying
Peter decided to lay a parquet in the room of size n Γ— m, the parquet consists of tiles of size 1 Γ— 2. When the workers laid the parquet, it became clear that the tiles pattern looks not like Peter likes, and workers will have to re-lay it. The workers decided that removing entire parquet and then laying it again is v...
{ "input": [ "4 3\nULR\nDLR\nLRU\nLRD\nULR\nDUU\nUDD\nDLR", "2 3\nULR\nDLR\nLRU\nLRD\n" ], "output": [ "5\n1 2\n3 1\n3 2\n1 2\n2 2\n", "2\n1 2\n1 1\n" ] }
{ "input": [ "34 5\nLRUUU\nUUDDD\nDDULR\nLRDUU\nULRDD\nDULRU\nUDLRD\nDULRU\nUDLRD\nDLRUU\nULRDD\nDLRLR\nLRUUU\nLRDDD\nUUULR\nDDDLR\nLRULR\nLRDLR\nLRLRU\nULRUD\nDLRDU\nLRLRD\nULRUU\nDUUDD\nUDDUU\nDLRDD\nLRLRU\nUUUUD\nDDDDU\nLRUUD\nUUDDU\nDDUUD\nUUDDU\nDDLRD\nULRLR\nDLRUU\nUUUDD\nDDDLR\nULRLR\nDLRUU\nULRDD\nDLRUU\n...
2,700
2,250
2
13
802_G. Fake News (easy)
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... In...
{ "input": [ "abcheaibcdi\n", "hiedi\n" ], "output": [ "YES", "NO" ] }
{ "input": [ "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbva...
800
0
2
9
825_C. Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty β€” a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). M...
{ "input": [ "4 20\n10 3 6 3\n", "3 3\n2 1 9\n" ], "output": [ "0", "1" ] }
{ "input": [ "1 2\n9\n", "7 6\n4 20 16 14 3 17 4\n", "1 1\n1000000000\n", "4 2\n45 44 35 38\n", "2 1\n4 1000000000\n", "2 1\n1 4\n", "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 488 416 659 988 998 93 662 92 749 889 78 214 786 735 625 921 372 7...
1,600
0
2
7
848_A. From Y to Y
From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times: * Remove any two elements s and t...
{ "input": [ "12\n", "3\n" ], "output": [ "aaaaabbcc\n", "aaa\n" ] }
{ "input": [ "99681\n", "8\n", "831\n", "9\n", "233\n", "1926\n", "7\n", "39393\n", "4\n", "2\n", "5\n", "1\n", "14514\n", "99998\n", "418\n", "82944\n", "11\n", "100000\n", "1317\n", "6\n", "10\n", "0\n", "25252\n" ], "ou...
1,600
500
2
8
967_B. Watering System
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for n flowers and so it looks like a pipe with n holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour A liters of water into the pipe. After that,...
{ "input": [ "4 10 3\n2 2 2 2\n", "5 10 10\n1000 1 1 1 1\n", "4 80 20\n3 2 1 4\n" ], "output": [ "1\n", "4\n", "0\n" ] }
{ "input": [ "2 10000 1\n1 9999\n", "10 300 100\n20 1 3 10 8 5 3 6 4 3\n", "1 2 1\n1\n", "2 2 2\n1 10000\n", "10 300 100\n20 25 68 40 60 37 44 85 23 96\n", "1 1 1\n1\n" ], "output": [ "0\n", "1\n", "0\n", "1\n", "8\n", "0\n" ] }
1,000
1,000
2
8
993_B. Open Communication
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set ...
{ "input": [ "2 3\n1 2 4 5\n1 2 1 3 2 3\n", "2 2\n1 2 3 4\n1 5 3 4\n", "2 2\n1 2 3 4\n1 5 6 4\n" ], "output": [ "-1", "1", "0" ] }
{ "input": [ "2 3\n1 2 1 3\n1 2 1 3 2 3\n", "3 7\n8 2 7 9 8 1\n3 1 8 1 2 7 4 7 4 2 1 4 4 6\n", "1 10\n3 9\n3 2 3 4 5 3 5 7 8 6 2 5 7 8 2 4 1 7 5 1\n", "12 1\n6 2 6 4 8 6 6 9 5 6 6 1 9 1 1 3 3 9 2 4 5 2 8 1\n6 7\n", "2 3\n1 2 7 8\n1 3 2 4 7 9\n", "3 2\n1 2 1 3 2 3\n1 2 4 5\n", "3 8\n8 9 8 5...
1,900
1,000
2
7
1027_A. Palindromic Twist
You are given a string s consisting of n lowercase Latin letters. n is even. For each position i (1 ≀ i ≀ n) in string s you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every posi...
{ "input": [ "5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml\n" ], "output": [ "YES\nNO\nYES\nNO\nNO\n" ] }
{ "input": [ "1\n4\nyaaa\n", "1\n6\ndazbyd\n", "4\n2\nay\n2\nbz\n2\nya\n2\nzb\n", "1\n4\nauux\n", "3\n2\nab\n2\nbc\n26\nabcdefghijklmnopqrstuvwxyz\n", "1\n2\nba\n", "2\n2\nzb\n2\nza\n", "3\n2\nbz\n2\nyz\n2\nab\n", "1\n4\nauuy\n", "1\n2\nza\n", "50\n6\nbxyxcz\n4\nzzcy\n2\nzb...
1,000
0
2
10
106_D. Treasure Island
Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map. The treasure map can be represented as a rectangle n Γ— m in size. Each cell stands for an islands' square (the square's side length equals...
{ "input": [ "3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n", "6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2\n" ], "output": [ "no solution\n", "AD\n" ] }
{ "input": [ "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nW 3\n", "10 19\n###################\n#######QR..H#######\n#M##O...G....U#####\n#.##AK#Z.......##I#\n#L.#######Y.J.V##.#\n##..W######..#.#..#\n##.D.....N#..#..P##\n####.E.#...B..X####\n#T##F#####S...###C#\n###################\n14\nN 1\nE 3\nS 1\...
1,700
2,000
2
9
1091_C. New Year and the Sphere Transmission
There are n people sitting in a circle, numbered from 1 to n in the order in which they are seated. That is, for all i from 1 to n-1, the people with id i and i+1 are adjacent. People with id n and 1 are adjacent as well. The person with id 1 initially has a ball. He picks a positive integer k at most n, and passes th...
{ "input": [ "6\n", "16\n" ], "output": [ "1 5 9 21\n", "1 10 28 64 136\n" ] }
{ "input": [ "536870912\n", "88888888\n", "798324712\n", "800000000\n", "669278610\n", "999999999\n", "900000000\n", "25\n", "551350800\n", "735134400\n", "11\n", "5\n", "14732891\n", "4\n", "17239871\n", "400000000\n", "36\n", "698377680\n", ...
1,400
1,750
2
7
1110_A. Parity
You are given an integer n (n β‰₯ 0) represented with k digits in base (radix) b. So, $$$n = a_1 β‹… b^{k-1} + a_2 β‹… b^{k-2} + … a_{k-1} β‹… b + a_k.$$$ For example, if b=17, k=3 and a=[11, 15, 7] then n=11β‹…17^2+15β‹…17+7=3179+255+7=3441. Determine whether n is even or odd. Input The first line contains two integers b and...
{ "input": [ "13 3\n3 2 7\n", "99 5\n32 92 85 74 4\n", "2 2\n1 0\n", "10 9\n1 2 3 4 5 6 7 8 9\n" ], "output": [ "even\n", "odd\n", "even\n", "odd\n" ] }
{ "input": [ "6 1\n0\n", "10 3\n4 4 4\n", "99 20\n97 97 97 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97\n", "99 10\n97 97 97 97 97 97 97 97 97 97\n", "97 21\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "3 1\n0\n", "3 1\n2\n", "13 3\n2 2 1\n", "4 2\n1 2\n", "5 2\n3 1\n",...
900
500
2
8
1158_B. The minimal unique substring
Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010...
{ "input": [ "4 4\n", "7 3\n", "5 3\n" ], "output": [ "1111\n", "0010010\n", "01010\n" ] }
{ "input": [ "101 3\n", "2 2\n", "100000 32194\n", "99999 33333\n", "5 5\n", "99991 70227\n", "100000 4\n", "3 1\n", "22359 1593\n", "1 1\n", "99999 1\n", "99999 50719\n", "3 3\n", "79 61\n", "88759 13661\n", "100000 100000\n", "99997 69087\n", "...
2,200
1,000
2
7
1180_A. Alex and a Rhombus
While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid. A 1-st order rhombus is just a square 1 Γ— 1 (i.e just a cell). A n-th order rhombus for all n β‰₯ 2 one obtains from a n-1-th order rhombus adding all cells which have a common side with it to it (look ...
{ "input": [ "3\n", "1\n", "2\n" ], "output": [ "13\n", "1\n", "5\n" ] }
{ "input": [ "37\n", "25\n", "64\n", "72\n", "11\n", "22\n", "8\n", "34\n", "38\n", "94\n", "77\n", "15\n", "49\n", "86\n", "57\n", "68\n", "98\n", "50\n", "75\n", "16\n", "80\n", "62\n", "47\n", "31\n", "74\n", "4...
800
500
2
7
1199_A. City Day
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, a_i millimeters of rain will fall. All values a_i are distinct. The mayor k...
{ "input": [ "5 5 5\n100000 10000 1000 100 10\n", "10 2 2\n10 9 6 7 8 3 2 1 4 5\n", "10 2 3\n10 9 6 7 8 3 2 1 4 5\n" ], "output": [ "5\n", "3\n", "8\n" ] }
{ "input": [ "100 7 4\n100 99 98 97 96 95 94 70 88 73 63 40 86 28 20 39 74 82 87 62 46 85 58 49 89 19 17 55 90 2 1 4 69 77 35 76 79 31 78 91 26 47 64 67 68 23 37 10 72 59 54 80 14 93 27 38 24 18 51 66 52 25 16 22 7 84 57 61 92 30 3 45 83 71 65 53 48 36 43 33 12 9 6 41 32 15 13 44 34 50 56 42 5 11 8 60 75 29 21 81...
1,000
500