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
1060_F. Shrinking Tree
Consider a tree T (that is, a connected graph without cycles) with n vertices labelled 1 through n. We start the following process with T: while T has more than one vertex, do the following: * choose a random edge of T equiprobably; * shrink the chosen edge: if the edge was connecting vertices v and u, erase both ...
{ "input": [ "4\n1 2\n1 3\n1 4\n", "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n" ], "output": [ "0.1250000000\n0.2916666667\n0.2916666667\n0.2916666667\n", "0.0850694444\n0.0664062500\n0.0664062500\n0.1955295139\n0.1955295139\n0.1955295139\n0.1955295139\n" ] }
{ "input": [ "50\n40 49\n15 19\n28 22\n35 37\n30 3\n12 33\n46 29\n4 41\n6 25\n50 32\n39 8\n31 12\n25 46\n5 47\n12 2\n3 50\n43 31\n1 45\n18 2\n21 14\n16 13\n1 11\n8 19\n11 23\n26 9\n38 8\n44 2\n25 9\n7 11\n43 20\n17 5\n21 35\n15 7\n19 36\n4 42\n44 4\n6 34\n10 41\n11 48\n32 31\n17 7\n26 24\n16 27\n3 49\n33 13\n49 2...
2,900
2,250
2
10
1082_D. Maximum Diameter Graph
Graph constructive problems are back! This time the graph you are asked to build should match the following properties. The graph is connected if and only if there exists a path between every pair of vertices. The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in...
{ "input": [ "3\n1 1 1\n", "5\n1 4 1 1 1\n", "3\n2 2 2\n" ], "output": [ "NO\n", "YES 2\n4\n1 2\n3 2\n4 2\n5 2\n", "YES 2\n2\n1 2\n2 3\n" ] }
{ "input": [ "4\n2 1 2 1\n", "17\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2\n", "3\n1 1 2\n", "5\n1 1 1 3 1\n", "100\n1 5 1 1 1 2 3 2 1 4 2 2 1 2 1 2 2 2 2 1 1 2 2 2 2 2 2 1 2 2 2 1 1 1 2 2 1 1 2 3 2 2 3 1 2 4 2 1 2 1 2 4 2 1 2 3 1 3 1 2 2 1 2 2 3 1 1 1 5 2 2 2 3 3 1 3 1 2 2 4 1 2 1 3 1 5 3 3 1 1 2...
1,800
0
2
10
112_D. Petya and Divisors
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem: You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him. Input The first line contains an int...
{ "input": [ "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3\n" ], "output": [ "3\n1\n1\n2\n2\n22\n" ] }
{ "input": [ "10\n54972 0\n48015 1\n7114 1\n68273 2\n53650 4\n1716 1\n16165 2\n96062 5\n57750 1\n21071 5\n", "20\n68260 0\n819 1\n54174 1\n20460 1\n25696 2\n81647 4\n17736 4\n91307 5\n5210 4\n87730 2\n4653 8\n11044 6\n15776 4\n17068 7\n73738 7\n36004 12\n83183 7\n75700 12\n84270 14\n16120 5\n", "11\n5059 ...
1,900
1,000
2
7
1172_A. Nauuo and Cards
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n...
{ "input": [ "3\n0 2 0\n3 0 1\n", "3\n0 2 0\n1 0 3\n", "11\n0 0 0 5 0 0 0 4 0 0 11\n9 2 6 0 8 1 7 0 3 0 10\n" ], "output": [ "2\n", "4\n", "18\n" ] }
{ "input": [ "2\n0 0\n2 1\n", "5\n0 0 0 0 0\n4 1 2 3 5\n", "20\n0 0 0 0 5 6 7 8 0 0 11 12 13 14 15 16 17 18 0 0\n20 9 19 0 0 0 0 0 0 10 0 0 0 0 0 0 1 2 3 4\n", "8\n0 0 0 0 0 0 7 8\n0 1 2 3 4 5 0 6\n", "17\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 5\n8 6 0 3 13 11 12 16 10 2 15 4 0 17 14 9 7\n", "8\n0 0...
1,800
500
2
8
118_B. Present from Lena
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handk...
{ "input": [ "3\n", "2\n" ], "output": [ " 0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0\n", " 0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0\n" ] }
{ "input": [ "4\n", "5\n", "9\n", "7\n", "8\n", "6\n" ], "output": [ " 0\n 0 1 0\n 0 1 2 1 0\n 0 1 2 3 2 1 0\n0 1 2 3 4 3 2 1 0\n 0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0\n", " 0\n 0 1 0\n 0 1 2 1 0\n 0 1 2 3 2 1 0\n 0 1 2 3 4 3...
1,000
1,000
2
7
1209_A. Paint the Numbers
You are given a sequence of integers a_1, a_2, ..., a_n. You need to paint elements in colors, so that: * If we consider any color, all elements of this color must be divisible by the minimal element of this color. * The number of used colors must be minimized. For example, it's fine to paint elements [40, 1...
{ "input": [ "6\n10 2 3 5 4 2\n", "8\n7 6 5 4 3 2 2 3\n", "4\n100 100 100 100\n" ], "output": [ "3\n", "4\n", "1\n" ] }
{ "input": [ "20\n6 8 14 8 9 4 7 9 7 6 9 10 14 14 11 7 12 6 11 6\n", "10\n7 70 8 9 8 9 35 1 99 27\n", "100\n17 23 71 25 50 71 85 46 78 72 89 26 23 70 40 59 23 43 86 81 70 89 92 98 85 88 16 10 26 91 61 58 23 13 75 39 48 15 73 79 59 29 48 32 45 44 25 37 58 54 45 67 27 77 20 64 95 41 80 53 69 24 38 97 59 94 ...
800
500
2
10
1292_D. Chaotic V.
[Γ†sir - CHAOS](https://soundcloud.com/kivawu/aesir-chaos) [Γ†sir - V.](https://soundcloud.com/kivawu/aesir-v) "Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect. The time right now...... 00:01:12...... It's time." The emotion samples are now sufficient. After almost 3 ...
{ "input": [ "4\n3 1 4 1\n", "4\n3 1 4 4\n", "5\n3 1 4 1 5\n", "3\n2 1 4\n" ], "output": [ "6", "6", "11", "5" ] }
{ "input": [ "59\n0 0 0 5000 0 0 0 5000 5000 0 5000 0 0 0 5000 0 0 0 0 0 0 0 0 0 5000 0 0 0 0 5000 0 5000 0 5000 0 0 5000 0 5000 0 0 0 0 0 0 5000 0 0 0 0 5000 0 0 0 5000 0 0 0 5000\n", "11\n5000 5000 5000 5000 5000 5000 0 1 0 1 0\n", "20\n0 5000 5000 5000 5000 5000 0 5000 5000 0 5000 5000 5000 0 5000 5000...
2,700
1,750
2
11
1312_E. Array Shrinking
You are given an array a_1, a_2, ..., a_n. You can perform the following operation any number of times: * Choose a pair of two neighboring equal elements a_i = a_{i + 1} (if there is at least one such pair). * Replace them by one element with value a_i + 1. After each such operation, the length of the array w...
{ "input": [ "1\n1000\n", "7\n3 3 4 4 4 3 3\n", "5\n4 3 2 2 3\n", "3\n1 3 5\n" ], "output": [ "1\n", "2\n", "2\n", "3\n" ] }
{ "input": [ "50\n1 1 1 1 1 2 1 1 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 1 2 2 2 2 2 1 2 2 2 1\n", "4\n1000 1000 1000 1000\n", "20\n1 13 12 7 25 25 46 39 39 18 25 18 8 8 18 42 29 34 34 3\n", "20\n34 20 41 21 45 30 4 42 42 21 21 41 43 36 25 49 25 25 44 28\n", "20\n21 21 21 21...
2,100
0
2
8
1335_B. Construct the String
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists. You have to answer t independent test cases. Recall that the substring s[l ...
{ "input": [ "4\n7 5 3\n6 1 1\n6 6 1\n5 2 2\n" ], "output": [ "abcabca\naaaaaa\naaaaaa\nababa\n" ] }
{ "input": [ "1\n30 26 25\n", "5\n400 400 2\n400 26 1\n400 26 26\n400 50 13\n400 400 26\n", "15\n7 5 3\n6 1 1\n6 6 1\n5 2 2\n26 1 1\n27 2 2\n27 27 26\n26 26 26\n55 26 26\n100 28 26\n100 55 26\n100 10 10\n100 26 10\n28 26 26\n100 1 1\n", "10\n88 46 8\n52 49 17\n99 43 17\n47 12 6\n69 1 1\n75 5 3\n25 6 1...
900
0
2
10
1355_D. Game With Array
Petya and Vasya are competing with each other in a new interesting game as they always do. At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0 ≀ K ≀ S. In order to win, Vasya ha...
{ "input": [ "3 8\n", "1 4\n", "3 4\n" ], "output": [ "YES\n2 2 4\n1\n", "YES\n4\n1\n", "NO\n" ] }
{ "input": [ "119698 122243\n", "65656 601337\n", "6 10\n", "9 10\n", "1 3\n", "6 7\n", "2 10\n", "10 20\n", "1 1\n", "6 8\n", "7 10\n", "3 10\n", "1 10\n", "5 5\n", "1 8\n", "697616 908764\n", "8 17\n", "677985 848241\n", "3 3\n", "15 17...
1,400
1,500
2
12
1398_F. Controversial Rounds
Alice and Bob play a game. The game consists of several sets, and each set consists of several rounds. Each round is won either by Alice or by Bob, and the set ends when one of the players has won x rounds in a row. For example, if Bob won five rounds in a row and x = 2, then two sets ends. You know that Alice and Bob...
{ "input": [ "5\n01?01\n", "12\n???1??????1?\n", "6\n11?000\n" ], "output": [ "5 1 0 0 0\n", "12 6 4 3 2 2 1 1 1 1 1 1\n", "6 3 2 1 0 0\n" ] }
{ "input": [ "1\n0\n", "1\n1\n", "1\n?\n" ], "output": [ "1\n", "1\n", "1\n" ] }
2,500
0
2
8
1422_B. Nice Matrix
A matrix of size n Γ— m is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers (a_1, a_2, ... , a_k) is a palindrome, if for any integer i (1 ≀ i ≀ k) the equality a_i = a_{k - i + 1} holds. Sasha owns a matrix a of size n Γ— m. In one operation he can increase or decrease any numb...
{ "input": [ "2\n4 2\n4 2\n2 4\n4 2\n2 4\n3 4\n1 2 3 4\n5 6 7 8\n9 10 11 18\n" ], "output": [ "8\n42\n" ] }
{ "input": [ "9\n1 1\n132703760\n1 1\n33227322\n1 1\n943066084\n1 1\n729139464\n1 1\n450488051\n1 1\n206794512\n1 1\n372520051\n1 1\n552003271\n1 1\n319080560\n" ], "output": [ "0\n0\n0\n0\n0\n0\n0\n0\n0\n" ] }
1,300
750
2
7
1440_A. Buy the String
You are given four integers n, c_0, c_1 and h and a binary string s of length n. A binary string is a string consisting of characters 0 and 1. You can change any character of the string s (the string should be still binary after the change). You should pay h coins for each change. After some changes (possibly zero) ...
{ "input": [ "6\n3 1 1 1\n100\n5 10 100 1\n01010\n5 10 1 1\n11111\n5 1 10 1\n11111\n12 2 1 10\n101110110101\n2 100 1 10\n00\n" ], "output": [ "3\n52\n5\n10\n16\n22\n" ] }
{ "input": [ "7\n10 3 1 1\n1000000110\n1 10 1 1000\n0\n1 1 10 2\n1\n4 4 4 1\n1001\n1 1 1 1\n1\n2 1000 500 1000\n11\n3 500 500 1\n101\n" ], "output": [ "17\n10\n3\n16\n1\n1000\n1500\n" ] }
800
500
2
11
1491_E. Fib-tree
Let F_k denote the k-th term of Fibonacci sequence, defined as below: * F_0 = F_1 = 1 * for any integer n β‰₯ 0, F_{n+2} = F_{n+1} + F_n You are given a tree with n vertices. Recall that a tree is a connected undirected graph without cycles. We call a tree a Fib-tree, if its number of vertices equals F_k for som...
{ "input": [ "3\n1 2\n2 3\n", "5\n1 3\n1 2\n4 5\n3 4\n", "5\n1 2\n1 3\n1 4\n1 5\n" ], "output": [ "\nYES\n", "\nYES\n", "\nNO\n" ] }
{ "input": [ "8\n2 5\n1 7\n4 1\n2 1\n8 7\n6 1\n3 1\n", "1\n", "2\n2 1\n", "8\n4 6\n6 7\n2 5\n4 5\n3 4\n1 2\n7 8\n", "3\n3 1\n3 2\n", "13\n1 2\n1 7\n7 8\n7 11\n8 9\n8 10\n11 12\n11 13\n1 3\n3 4\n3 5\n4 6\n", "4\n1 2\n2 3\n3 4\n" ], "output": [ "NO\n", "YES\n", "YES\n", "...
2,400
1,750
2
8
1514_B. AND 0, Sum Big
Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers n and k, count the number of arrays of length n such that: * all its elements are integers between 0 and 2^k-1 (inclusive); * the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of a...
{ "input": [ "2\n2 2\n100000 20\n" ], "output": [ "\n4\n226732710\n" ] }
{ "input": [ "10\n50 1\n40 7\n40 6\n40 5\n40 4\n40 3\n40 2\n40 1\n49 7\n49 6\n", "10\n6 4\n6 3\n6 2\n6 1\n1 1\n2 1\n10 1\n100000 1\n100000 20\n99999 20\n", "1\n10 20\n", "10\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n3 2\n3 1\n2 4\n2 3\n", "1\n2 3\n", "10\n49 5\n49 4\n49 3\n49 2\n100000 19\n100000 18\n100...
1,200
1,000
2
7
169_A. Chores
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β€” its complexity. The complexity of the i-th chore equals hi. As Petya is older, he wants to take the chores with complexity larger...
{ "input": [ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ], "output": [ "3", "0" ] }
{ "input": [ "4 1 3\n10 402 402 10\n", "102 101 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1\n", "4 3 1\n100 100 200 200\n", "4 2 2\n402 10 ...
800
500
2
8
261_B. Maxim and Restaurant
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters. Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (...
{ "input": [ "3\n1 2 3\n3\n" ], "output": [ "1.3333333333\n" ] }
{ "input": [ "23\n2 1 2 1 1 1 2 2 2 1 1 2 2 1 1 1 2 1 2 2 1 1 1\n37\n", "50\n1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2\n29\n", "28\n3 5 4 24 21 3 13 24 22 13 12 21 1 15 11 3 17 6 2 12 22 12 23 4 21 16 25 14\n25\n", "23\n16 21 14 27 15 30 13 10 ...
1,900
1,000
2
8
285_B. Find Marble
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position s. Then he performs some (pos...
{ "input": [ "4 3 4\n1 2 3 4\n", "4 3 3\n4 1 3 2\n", "4 2 1\n2 3 4 1\n", "3 1 3\n2 1 3\n" ], "output": [ "-1\n", "0\n", "3\n", "-1\n" ] }
{ "input": [ "100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 10 61 18 70 91 75 14 11 93 41 25 78 88 81 20 51 35 4 62 1 97 39 68 52 47 77 64 3 2 72 60 80 8 83 65 98 21 22 45 7 58 31 43 38 90 99 49 87 55 36 29 6 37 23 66 76 59 79 40 86 63 44 82 32 48 16 50 100 28 96 46 12 27 13 24 9 19 84 73 69 71 42 56 33 34 ...
1,200
1,000
2
8
30_B. Codeforces World Finals
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a...
{ "input": [ "20.10.20\n10.02.30\n", "28.02.74\n28.02.64\n", "01.01.98\n01.01.80\n" ], "output": [ "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "02.05.90\n08.03.50\n", "29.02.80\n29.02.60\n", "15.12.62\n17.12.21\n", "08.07.20\n27.01.01\n", "09.05.55\n25.09.42\n", "28.02.20\n11.01.29\n", "06.08.91\n05.12.73\n", "31.05.20\n02.12.04\n", "31.10.41\n27.12.13\n", "12.11.87\n14.08.42\n", "23.05.53\n31.10.34\n...
1,700
1,000
2
8
3_B. Lorry
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
{ "input": [ "3 2\n1 2\n2 7\n1 3\n" ], "output": [ "7\n2\n" ] }
{ "input": [ "20 19\n2 47\n1 37\n1 48\n2 42\n2 48\n1 38\n2 47\n1 48\n2 47\n1 41\n2 46\n1 28\n1 49\n1 45\n2 34\n1 43\n2 29\n1 46\n2 45\n2 18\n", "10 14\n2 230\n2 516\n2 527\n2 172\n2 854\n2 61\n1 52\n2 154\n2 832\n2 774\n", "5 3\n1 9\n2 9\n1 9\n2 10\n1 6\n", "1 1\n1 600\n", "8 4\n1 100\n1 100\n1 10...
1,900
0
2
9
471_C. MUH and House of Cards
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make: 1. The house consists of some non-zero number of floors. 2. Each ...
{ "input": [ "13\n", "6\n" ], "output": [ "1\n", "0\n" ] }
{ "input": [ "153\n", "99\n", "154\n", "3\n", "98\n", "1000000000000\n", "571684826707\n", "152\n", "663938115190\n", "903398973606\n", "420182289478\n", "155\n", "1\n", "4\n", "178573947413\n", "1894100308\n", "2\n", "156\n", "71\n", "14...
1,700
2,000
2
10
495_D. Obsessive String
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k β‰₯ 1 non-overlapping substrings from...
{ "input": [ "ababa\naba\n", "ddd\nd\n", "welcometoroundtwohundredandeightytwo\nd\n" ], "output": [ "5\n", "12\n", "274201\n" ] }
{ "input": [ "a\naa\n", "a\na\n", "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns\n", "ababababab\nabab\n", "a\nb\n", "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n", "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa\n" ], "output": [ "0\n...
2,000
1,000
2
8
51_B. bHTML Tables Analisys
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: TABLE ::= <table>ROWS</table> ROWS ::= ROW | ROW ROWS ROW ::= <tr>CELLS</tr> ...
{ "input": [ "&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;\n", "&lt;table&gt;\n&lt;tr&gt;\n&lt;td&gt;\n&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/\ntd\n&gt;&lt;/tr&gt;&lt;tr\n&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/t...
{ "input": [ "<table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table>...
1,700
1,000
2
9
546_C. Soldier and Cards
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fi...
{ "input": [ "4\n2 1 3\n2 4 2\n", "3\n1 2\n2 1 3\n" ], "output": [ "6 2\n", "-1\n" ] }
{ "input": [ "10\n8 1 6 5 3 8 7 10 4\n2 9 2\n", "9\n8 4 8 5 6 3 2 7 1\n1 9\n", "10\n2 7 5\n8 9 3 2 4 6 8 1 10\n", "7\n6 3 5 2 1 6 4\n1 7\n", "10\n9 8 7 6 2 3 5 4 10 1\n1 9\n", "5\n4 1 5 3 2\n1 4\n", "5\n2 2 1\n3 4 5 3\n", "3\n2 3 2\n1 1\n", "6\n2 6 5\n4 1 2 3 4\n", "3\n1 3\n2 2...
1,400
1,250
2
9
594_C. Edo and Magnets
Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit...
{ "input": [ "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n", "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n", "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n" ], "output": [ "64\n", "1\n", "249999999000000001\n" ] }
{ "input": [ "2 1\n1 1 1000000000 1000000000\n100 200 200 300\n", "1 0\n1 1 100 100\n", "2 1\n1 1 1000000000 2\n1 1 2 1000000000\n", "1 0\n1 1 1000000000 1000000000\n", "1 0\n1 1 2 2\n", "2 1\n1 1 999999999 1000000000\n1 1 1000000000 999999999\n", "1 0\n100 300 400 1000\n", "11 8\n9 1 ...
2,300
1,500
2
7
616_A. Comparing Two Long Integers
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge...
{ "input": [ "11\n10\n", "9\n10\n", "0123\n9\n", "0123\n111\n", "00012345\n12345\n" ], "output": [ ">\n", "<\n", ">\n", ">\n", "=\n" ] }
{ "input": [ "02\n01\n", "00\n01\n", "0\n0\n", "00\n10\n", "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479\n", "0000001\n00\n", "001\n...
900
0
2
8
635_B. Island Puzzle
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle β€” a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The center of each island contains an identical pedestal, and all but one o...
{ "input": [ "3\n1 0 2\n2 0 1\n", "4\n1 2 3 0\n0 3 2 1\n", "2\n1 0\n0 1\n" ], "output": [ "YES", "NO", "YES" ] }
{ "input": [ "10\n2 4 8 3 6 1 9 0 5 7\n3 6 1 9 0 5 7 2 8 4\n", "4\n1 2 3 0\n1 0 2 3\n", "4\n0 2 3 1\n1 2 3 0\n", "4\n0 1 2 3\n1 0 2 3\n", "9\n3 8 4 6 7 1 5 2 0\n6 4 8 5 3 1 2 0 7\n", "4\n1 0 2 3\n1 0 2 3\n", "10\n2 0 1 6 4 9 8 5 3 7\n6 4 9 0 5 3 7 2 1 8\n", "2\n0 1\n0 1\n", "3\n0 1...
1,300
500
2
7
664_A. Complicated GCD
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm. Formally, find the biggest integer d, such that all int...
{ "input": [ "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n", "1 2\n" ], "output": [ "61803398874989484820458683436563811772030917980576\n", "1\n" ] }
{ "input": [ "12345 67890123456789123457\n", "87 2938984237482934238\n", "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614\n", "1 100\n", "1 1\n", "8...
800
500
2
10
688_D. Remainders Game
Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winnin...
{ "input": [ "4 5\n2 3 5 12\n", "2 7\n2 3\n" ], "output": [ "Yes", "No" ] }
{ "input": [ "10 4\n2 2 2 2 2 2 2 2 2 2\n", "1 125\n5\n", "8 32\n2 2 2 2 2 2 2 2\n", "1 8\n2\n", "12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766\n", "2 16\n8 8\n", "1 1\n1\n", "2 16\n8 4\n", "91 4900\n630 630 70 630 910 630 630 630 770 70 770 630 630 770 70 630...
1,800
1,000
2
9
710_C. Magic Odd Square
Find an n Γ— n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≀ n ≀ 49). Output Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main di...
{ "input": [ "1\n", "3\n" ], "output": [ "1\n", "2 1 4\n3 5 7\n6 9 8\n" ] }
{ "input": [ "45\n", "11\n", "31\n", "7\n", "47\n", "19\n", "5\n", "49\n", "43\n", "33\n", "21\n", "9\n", "13\n", "35\n", "23\n", "17\n", "39\n", "15\n", "29\n", "37\n", "25\n", "27\n", "41\n" ], "output": [ "2 4 6 8 1...
1,500
0
2
9
731_C. Socks
Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clo...
{ "input": [ "3 2 3\n1 2 3\n1 2\n2 3\n", "3 2 2\n1 1 2\n1 2\n2 1\n" ], "output": [ "2", "0" ] }
{ "input": [ "10 3 2\n2 1 1 2 1 1 2 1 2 2\n4 10\n9 3\n5 7\n", "4 3 2\n1 1 2 2\n1 2\n3 4\n2 3\n", "4 2 4\n1 2 3 4\n1 2\n3 4\n", "3 3 3\n1 2 3\n1 2\n2 3\n3 1\n", "10 3 3\n2 2 1 3 1 2 1 2 2 2\n10 8\n9 6\n8 10\n", "4 3 4\n1 2 3 4\n1 2\n3 4\n4 1\n" ], "output": [ "2", "2", "2", ...
1,600
1,500
2
11
755_E. PolandBall and White-Red graph
PolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white...
{ "input": [ "4 1\n", "5 2\n" ], "output": [ "-1\n", "4\n1 2\n2 3\n3 4\n4 5\n" ] }
{ "input": [ "107 2\n", "3 2\n", "683 3\n", "3 1\n", "494 2\n", "1000 1\n", "5 4\n", "527 2\n", "750 3\n", "1000 2\n", "999 1\n", "2 2\n", "416 3\n", "3 3\n", "1000 4\n", "9 3\n", "101 2\n", "8 2\n", "10 2\n", "4 3\n", "999 5\n", ...
2,400
2,500
2
8
801_B. Valued Keys
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1...
{ "input": [ "ab\naa\n", "ab\nba\n", "nzwzl\nniwel\n" ], "output": [ "aa\n", "-1\n", "niwel\n" ] }
{ "input": [ "vkvkkv\nvkvkkv\n", "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej\n", "zzz\nzzz\n", "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgav...
900
1,000
2
10
847_D. Dog Show
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win! On the show a dog needs to eat as many bowls of dog food as poss...
{ "input": [ "1 1\n1\n", "3 5\n1 5 3\n", "1 2\n1\n" ], "output": [ "0\n", "2\n", "1\n" ] }
{ "input": [ "15 15\n2 1 2 3 2 3 4 5 6 5 6 5 6 5 6\n", "5 3\n2 3 4 5 6\n", "18 27\n2 3 4 3 4 5 6 7 8 9 10 9 8 9 8 9 10 9\n", "14 14\n2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "4 4\n2 3 2 3\n", "9 9\n2 1 2 3 4 5 6 5 6\n", "4 4\n2 1 2 3\n", "3 3\n2 1 2\n", "5 5\n2 1 2 3 4\n", "7 7\n2...
2,200
0
2
12
868_F. Yet Another Minimization Problem
You are given an array of n integers a1... an. The cost of a subsegment is the number of unordered pairs of distinct indices within the subsegment that contain equal elements. Split the given array into k non-intersecting non-empty subsegments so that the sum of their costs is minimum possible. Each element should be p...
{ "input": [ "10 2\n1 2 1 2 1 2 1 2 1 2\n", "13 3\n1 2 2 2 1 2 1 1 1 2 2 1 1\n", "7 3\n1 1 3 3 3 2 1\n" ], "output": [ "8", "9", "1" ] }
{ "input": [ "128 5\n116 8 116 116 119 39 116 116 119 116 8 119 119 119 39 116 39 119 39 119 119 39 8 39 8 119 8 116 116 116 119 119 8 39 39 8 116 119 119 119 119 8 8 8 119 39 119 116 119 119 39 39 119 8 116 116 116 116 116 119 116 116 119 116 39 39 119 8 8 119 39 116 39 39 119 119 116 116 119 119 119 119 8 8 116...
2,500
2,500
2
9
894_C. Marco and GCD Sequence
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be...
{ "input": [ "4\n2 4 6 12\n", "2\n2 3\n" ], "output": [ "8\n2 2 4 2 6 2 12 2\n", "-1\n" ] }
{ "input": [ "2\n999996 1000000\n", "3\n250000 750000 1000000\n", "2\n99997 399988\n", "4\n2 4 6 12\n", "12\n8 9 10 11 12 13 14 15 16 17 18 19\n", "6\n111111 222222 333333 666666 777777 999999\n", "4\n19997 339949 539919 719892\n", "3\n4 9 11\n", "14\n1 2 3 4 5 6 7 8 9 10 11 12 13 ...
1,900
1,500
2
8
964_B. Messages
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
{ "input": [ "4 5 5 3 5\n1 5 5 4\n", "5 3 1 1 3\n2 2 2 1 1\n", "5 5 3 4 5\n1 2 3 4 5\n" ], "output": [ "20\n", "15\n", "35\n" ] }
{ "input": [ "32 2 74 772 674\n598 426 358 191 471 667 412 44 183 358 436 654 572 489 79 191 374 33 1 627 154 132 101 236 443 112 77 93 553 53 260 498\n", "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3\n", "49 175 330 522 242\n109 81 215 5 134 185 60 242 154 148 14 221 146 229 45 120 142 43 202 176 231 105 212 69 109 2...
1,300
1,000
2
9
991_C. Candies
After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya choos...
{ "input": [ "68\n" ], "output": [ "3\n" ] }
{ "input": [ "505050505\n", "999999999999999973\n", "43\n", "67\n", "601\n", "123456789\n", "777777777\n", "999999999999999999\n", "257\n", "99999999999999959\n", "2\n", "888888888888888887\n", "99999999999999957\n", "888888888888888854\n", "9999999999999999...
1,500
1,250
2
7
1044_A. The Tower is Going Home
On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the coordinates (x,y), where x is the column number and y is the row number. Ever...
{ "input": [ "0 0\n", "2 3\n4\n6\n1 4 3\n1 5 2\n1 6 5\n", "2 3\n6\n8\n1 5 6\n1 9 4\n2 4 2\n", "0 2\n1 1000000000 4\n1 1000000000 2\n", "1 3\n4\n1 5 3\n1 9 4\n4 6 6\n" ], "output": [ "0", "2", "1", "2", "1" ] }
{ "input": [ "4 7\n1\n2\n3\n4\n1 1000000000 1\n1 1000000000 2\n1 1000000000 3\n1 1000000000 4\n1 1000000000 5\n1 1000000000 6\n1 1000000000 7\n", "0 5\n1 96762320 50510976\n243235878 312125306 50510976\n326016273 338641867 50510976\n385105810 445224816 50510976\n456157384 569789185 50510976\n", "0 1\n1 99...
1,700
750
2
12
1066_F. Yet another 2D Walking
Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (0, 1); * (-1, 0); * (0, -...
{ "input": [ "5\n2 1\n1 0\n2 0\n3 2\n0 3\n", "8\n2 2\n1 4\n2 3\n3 1\n3 4\n1 1\n4 3\n1 2\n" ], "output": [ "9\n", "15\n" ] }
{ "input": [ "9\n1 4\n2 3\n3 4\n4 3\n2 2\n1 2\n1 1\n3 1\n5 3\n", "1\n1000000000 1000000000\n", "9\n1 1\n3 4\n4 3\n1 4\n1 2\n3 1\n2 3\n2 2\n1 5\n", "39\n27 47\n30 9\n18 28\n49 16\n10 12\n25 13\n44 11\n13 9\n3 8\n30 2\n8 30\n38 32\n7 29\n38 43\n27 37\n6 13\n21 25\n31 18\n17 26\n51 52\n27 40\n10 43\n50 2...
2,100
0
2
16
1089_J. JS Minification
International Coding Procedures Company (ICPC) writes all its code in Jedi Script (JS) programming language. JS does not get compiled, but is delivered for execution in its source form. Sources contain comments, extra whitespace (including trailing and leading spaces), and other non-essential features that make them qu...
{ "input": [ "16\nfun while return var { } ( ) , ; &gt; = + ++ - --\n9\nfun fib(num) { # compute fibs\n var return_value = 1, prev = 0, temp;\n while (num &gt; 0) {\n temp = return_value; return_value = return_value + prev;\n prev = temp;\n num--;\n }\n return return_value;\n}\n", "10\n( ) + ++ :...
{ "input": [ "10\n+ - * / ^ a+ b- c* 1/ 01^\n5\nx + y + z + 1 + 01 + 001\nx - y - z - 1 - 01 - 001\nx * y * z * 1 * 01 * 001\nx / y / z / 1 / 01 / 001\nx ^ y ^ z ^ 1 ^ 01 ^ 001\n", "3\n+ = =+=\n1\n+ = + =\n", "2\nz 05c\n2\n01 x 02 y 03 z 05 xx 06 yy 07 zz 08 xxx 09 yyy 10 zzzz \n11 x...
3,200
0
2
10
1108_D. Diverse Garland
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garlan...
{ "input": [ "8\nBBBGBRRR\n", "9\nRBGRRBRGG\n", "13\nBBRRRRGGGGGRR\n" ], "output": [ "2\nBRBGBRGR", "2\nRBGRGBRGR", "6\nBGRGRBGRGRGRG" ] }
{ "input": [ "5\nGBBRG\n", "3\nRGG\n", "500\nBRGRRBBGGRBBRBBGGGRBGBGRGRRBRRRBGRBGBRGGGRBBRRBBBRGGBGBBBGGGRGRBBBRBGGBRGGGBRGGRBRGBBGBRRGGBGRGBGGGGGRBBRGBGGRBGGGRBRGGBBGRBBRRRGBRRBGGBGBGGGGRBGRGRRGGGBRBRRGBGGGRBRBBGBBGGBRBGBRRGGRRBGGRRRRBRGRBBBRRBGRBBGBGBRRGGBRRBBRRGGRRRBGBRBBGRRRRBGGGBRGRRBRRRRGGRBRRBBRRGR...
1,400
0
2
8
1156_B. Ugly Pairs
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions (1, 2) β€” "ab" and (2, 3) β€” "ba". Letters 'a' and 'z' aren't considered neighbou...
{ "input": [ "4\nabcd\ngg\ncodeforces\nabaca\n" ], "output": [ "bdac\ngg\ncceeoosdfr\nNo answer\n" ] }
{ "input": [ "1\nheaghhcgfb\n", "1\ndgeegbeabh\n", "1\neefbhgeabache\n", "1\nzcbacx\n", "4\nabcd\ngg\ncodeforces\nabaca\n", "1\nzyy\n", "100\nc\nda\na\nee\ned\ndb\nece\nab\nabe\nd\neeb\na\nbab\nbbd\nc\ncab\nc\nbda\ndb\ncca\nbcd\nbae\neb\nde\ndc\naee\nada\nba\nba\nde\ned\nae\nbc\nbec\ndae\n...
1,800
0
2
11
1178_E. Archaeology
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
{ "input": [ "cbacacacbcbababacbcb\n", "abc\n", "cacbac\n" ], "output": [ "cbaaacbcaaabc", "a\n", "cacac" ] }
{ "input": [ "bcacabcbabacacbcbcbcbabacbcacacbcacababc\n", "abababacacacbcbcbc\n", "babababcbcbacacac\n", "acab\n", "abacbc\n", "acbcbabacacbcbab\n", "bacbac\n", "abababcbacacacbcbc\n", "bcb\n", "ababacacacbc\n", "cbcacbcacacabcbcbaba\n", "ab\n", "abab\n", "abac...
1,900
2,000
2
12
1213_F. Unstable String Sort
Authors have come up with the string s consisting of n lowercase Latin letters. You are given two permutations of its indices (not necessary equal) p and q (both of length n). Recall that the permutation is the array of length n which contains each integer from 1 to n exactly once. For all i from 1 to n-1 the followi...
{ "input": [ "3 2\n1 2 3\n1 3 2\n" ], "output": [ "YES\nabb\n" ] }
{ "input": [ "3 2\n3 1 2\n3 2 1\n", "5 4\n1 3 2 4 5\n2 3 5 1 4\n", "5 2\n5 2 4 3 1\n5 4 3 1 2\n", "6 5\n5 6 1 2 3 4\n6 5 1 2 3 4\n" ], "output": [ "YES\nbba\n", "NO\n", "YES\nbbbba\n", "YES\nbcdeaa\n" ] }
2,100
0
2
12
1278_F. Cards
Consider the following experiment. You have a deck of m cards, and exactly one card is a joker. n times, you do the following: shuffle the deck, take the top card of the deck, look at it and return it into the deck. Let x be the number of times you have taken the joker out of the deck during this experiment. Assuming ...
{ "input": [ "998244352 1337 5000\n", "1 1 1\n", "1 1 5000\n", "2 2 2\n" ], "output": [ "326459680\n", "1\n", "1\n", "499122178\n" ] }
{ "input": [ "213292922 8067309 5000\n", "569716410 849619604 5000\n", "232213466 585535513 4789\n", "251134010 189925189 5000\n", "588636954 730833344 5000\n", "232213466 585535513 5000\n", "213292922 8067309 44\n", "588636954 730833344 4490\n", "251134010 189925189 3047\n", "...
2,600
0
2
9
1299_C. Water Balance
There are n water tanks in a row, i-th of them contains a_i liters of water. The tanks are numbered from 1 to n from left to right. You can perform the following operation: choose some subsegment [l, r] (1≀ l ≀ r ≀ n), and redistribute water in tanks l, l+1, ..., r evenly. In other words, replace each of a_l, a_{l+1},...
{ "input": [ "4\n7 5 5 7\n", "5\n7 8 8 10 12\n", "10\n3 9 5 5 1 7 5 3 8 7\n" ], "output": [ "5.666666666666667\n5.666666666666667\n5.666666666666667\n7\n", "7\n8\n8\n10\n12\n", "3\n5.0\n5.0\n5.0\n5.0\n5.0\n5.0\n5.0\n7.5\n7.5\n" ] }
{ "input": [ "3\n20 90 100\n", "65\n1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64\n", "2\n100 20\n", "3\n100 20 50\n", "12\n8 10 4 6 6 4 1 2 2 6 9 5\n", ...
2,100
1,250
2
7
1322_A. Unusual Competitions
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher gave Dmitry's class a very strange task β€” she asked every student...
{ "input": [ "3\n(()\n", "8\n))((())(\n" ], "output": [ "-1\n", "6" ] }
{ "input": [ "51\n))((((((((()))(())()(()(()())()(()(())(())()())))))\n", "4\n((()\n", "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n", "10\n))))((((()\n", "10\n)()()()()(\n", "100\n)))))))(((((((((((((((((((((((((((((((((((((((((((...
1,300
500
2
8
1404_B. Tree Tag
Alice and Bob are playing a fun game of tree tag. The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n-1 edges. Initially, Alice is located at vertex a, and Bob at vertex b. They take turns alternately, and Alice makes the first mov...
{ "input": [ "4\n4 3 2 1 2\n1 2\n1 3\n1 4\n6 6 1 2 5\n1 2\n6 5\n2 3\n3 4\n4 5\n9 3 9 2 5\n1 2\n1 6\n1 9\n1 3\n9 5\n7 9\n4 8\n4 3\n11 8 11 3 3\n1 2\n11 9\n4 9\n6 5\n2 10\n3 2\n5 9\n8 3\n7 4\n7 10\n" ], "output": [ "Alice\nBob\nAlice\nAlice\n" ] }
{ "input": [ "10\n10 9 10 6 6\n6 1\n7 6\n4 2\n4 10\n5 1\n9 5\n6 8\n3 4\n4 5\n2 1 2 1 1\n2 1\n9 7 4 2 3\n5 1\n2 4\n4 8\n8 6\n8 9\n7 8\n1 8\n1 3\n11 2 11 6 8\n1 10\n6 11\n8 2\n11 3\n1 7\n11 4\n5 8\n11 7\n1 9\n1 8\n5 3 2 1 2\n3 1\n2 1\n4 5\n1 5\n2 1 2 1 1\n2 1\n2 2 1 1 1\n2 1\n2 2 1 1 1\n1 2\n2 2 1 1 1\n2 1\n5 4 5 4...
1,900
1,000
2
11
1447_E. Xor Tree
For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find such j (1 ≀ j ≀ k, jβ‰  i), for which (b_i βŠ• b_j) is the smallest among all such j,...
{ "input": [ "5\n0 1 5 2 6\n", "7\n6 9 8 7 3 5 2\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "7\n32 35 2 20 52 59 28\n", "3\n4 9 1\n", "109\n74 18 237 179 195 112 156 11 72 68 173 202 78 250 224 251 107 55 186 144 57 62 28 210 132 64 93 6 211 0 174 163 248 226 167 246 46 102 253 180 121 56 151 35 150 254 168 201 242 118 190 158 196 30 75 116 187 96 215 244 192 73 12 175 33 222 131 25...
2,100
1,250
2
12
1498_F. Christmas Game
Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging from the i-th node. Before beginning the game, a special integer k is chosen. The game proceeds as follows: * Alice begin...
{ "input": [ "5 1\n1 2\n1 3\n5 2\n4 3\n0 3 2 4 4\n" ], "output": [ "\n1 0 0 1 1 " ] }
{ "input": [ "3 3\n1 3\n1 2\n1 2 3\n", "3 1\n3 1\n3 2\n1 2 3\n", "4 3\n1 2\n1 3\n3 4\n1000000000 999999999 0 1\n", "3 20\n1 2\n1 3\n1 2 3\n", "6 1\n1 2\n1 3\n3 4\n2 5\n5 6\n1 3 3 4 5 0\n" ], "output": [ "0 0 0 ", "1 1 1 ", "0 1 0 1 ", "0 0 0 ", "0 0 0 0 0 0 " ] }
2,500
3,000
2
11
1520_E. Arranging The Sheep
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length n, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the co...
{ "input": [ "5\n6\n**.*..\n5\n*****\n3\n.*.\n3\n...\n10\n*.*...*.**\n" ], "output": [ "\n1\n0\n0\n0\n9\n" ] }
{ "input": [ "2\n6\n**..**\n4\n**..\n", "2\n10\n*.*...*.**\n3\n...\n" ], "output": [ "4\n0\n", "9\n0\n" ] }
1,400
0
2
7
176_A. Trading Business
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin...
{ "input": [ "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5\n" ], "output": [ "16\n" ] }
{ "input": [ "2 2 1\nQwe\n900 800 1\n5 1 1\nEwq\n1000 999 0\n11 10 0\n", "3 2 11\nMars\n15 10 4\n7 6 3\nSnickers\n20 17 2\n10 8 0\nBounty\n21 18 5\n9 7 3\n", "2 2 5\nAbcdefghij\n20 15 20\n10 5 13\nKlmopqrstu\n19 16 20\n12 7 14\n", "2 1 1\nIeyxawsao\n2 1 0\nJhmsvvy\n2 1 0\n", "3 1 5\nTomato\n10 7 2...
1,200
500
2
9
21_C. Stripe 2
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
{ "input": [ "5\n1 2 3 4 5\n", "4\n1 2 3 3\n" ], "output": [ "0\n", "1\n" ] }
{ "input": [ "5\n-6 3 -1 2 -7\n", "4\n-2 3 3 2\n", "3\n0 0 0\n", "9\n-5 -2 1 1 5 0 -4 4 0\n", "100\n3 0 -5 2 -3 -1 -1 0 -2 -5 -4 2 1 2 -2 -1 -1 -4 3 -1 -3 -1 5 0 -4 -4 -1 0 -2 -2 0 1 -1 -2 -1 -5 -4 -2 3 1 -3 0 -1 1 0 -1 2 0 -2 -1 -3 1 -2 2 3 2 -3 -5 2 2 -2 -2 1 2 -2 -1 3 0 -4 7 -2 2 1 4 -9 -1 -2 -...
2,000
1,500
2
9
33_C. Wonderful Randomized Sum
Learn, learn and learn again β€” Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
{ "input": [ "5\n-4 2 0 5 0\n", "3\n-1 -2 -3\n", "5\n-1 10 -5 10 -2\n" ], "output": [ "11\n", "6\n", "18\n" ] }
{ "input": [ "4\n-83 -87 42 -96\n", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "100\n-43 0 -81 10 67 61 0 76 -16 1 -1 69 -59 -87 14 -20 -48...
1,800
1,500
2
8
407_B. Long Path
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (...
{ "input": [ "4\n1 1 2 3\n", "5\n1 1 1 1 1\n", "2\n1 2\n" ], "output": [ "20\n", "62\n", "4\n" ] }
{ "input": [ "3\n1 1 3\n", "1\n1\n", "30\n1 1 2 2 5 6 4 3 4 7 3 5 12 12 2 15 3 8 3 10 12 3 14 1 10 4 22 11 22 27\n", "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\n", "129\n1 1 3 3 1 4 7 4 3 5 8 11 3 9 15 4 11 17 1 6 18 9 11 13 17 22 8...
1,600
1,000
2
9
479_C. Exams
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a stud...
{ "input": [ "3\n5 2\n3 1\n4 2\n", "3\n6 1\n5 2\n4 3\n" ], "output": [ "2\n", "6\n" ] }
{ "input": [ "1\n1000000000 999999999\n", "5\n4 3\n4 2\n4 1\n4 1\n4 1\n", "6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1\n", "2\n3 1\n3 2\n", "3\n3 2\n4 1\n100 10\n", "2\n4 2\n4 1\n", "4\n7 1\n7 3\n8 2\n9 8\n", "3\n3 2\n4 1\n10 5\n", "2\n5 2\n5 1\n", "5\n6 5\n6 4\n6 3\n6 2\n6 1\n", "3...
1,400
1,500
2
9
501_C. Misha and Forest
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the secon...
{ "input": [ "2\n1 1\n1 0\n", "3\n2 3\n1 0\n1 0\n" ], "output": [ "1\n0 1\n", "2\n1 0\n2 0\n" ] }
{ "input": [ "12\n0 0\n1 3\n0 0\n1 1\n0 0\n1 7\n0 0\n1 5\n0 0\n0 0\n0 0\n0 0\n", "14\n1 10\n1 9\n3 4\n1 2\n0 0\n1 11\n1 12\n1 10\n1 10\n2 10\n3 15\n3 14\n2 4\n0 0\n", "13\n2 7\n0 0\n0 0\n2 11\n2 7\n2 14\n2 3\n2 1\n1 11\n3 15\n1 6\n2 11\n1 9\n", "19\n1 13\n0 0\n1 9\n1 11\n1 11\n2 3\n2 30\n0 0\n1 5\n1 2...
1,500
1,500
2
7
527_A. Playing with Paper
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm Γ— b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting t...
{ "input": [ "2 1\n", "10 7\n", "1000000000000 1\n" ], "output": [ "2\n", "6\n", "1000000000000\n" ] }
{ "input": [ "3 2\n", "4 2\n", "1000 998\n", "8 5\n", "442 42\n", "3 1\n", "695928431619 424778620208\n", "13 8\n", "1000000000000 3\n", "628625247282 464807889701\n", "293 210\n", "1000000000000 999999999998\n", "787878787878 424242424242\n", "1000 17\n", "...
1,100
500
2
10
552_D. Vanya and Triangles
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area. Input The first line contains integer ...
{ "input": [ "4\n0 0\n1 1\n2 0\n2 2\n", "1\n1 1\n", "3\n0 0\n1 1\n2 0\n" ], "output": [ "3\n", "0", "1" ] }
{ "input": [ "5\n-100 -100\n-100 100\n100 -100\n100 100\n0 0\n", "61\n83 52\n28 91\n-45 -68\n-84 -8\n-59 -28\n-98 -72\n38 -38\n-51 -96\n-66 11\n-76 45\n95 45\n-89 5\n-60 -66\n73 26\n9 94\n-5 -80\n44 41\n66 -22\n61 26\n-58 -84\n62 -73\n18 63\n44 71\n32 -41\n-50 -69\n-30 17\n61 47\n45 70\n-97 76\n-27 31\n2 -12\...
1,900
2,000
2
10
579_D. "Or" Game
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR. Find the maximum possible value of <image> after performing at most k operations optimally. I...
{ "input": [ "3 1 2\n1 1 1\n", "4 2 3\n1 2 4 8\n" ], "output": [ " 3\n", " 79\n" ] }
{ "input": [ "2 1 2\n12 9\n", "2 2 2\n60 59\n", "5 1 3\n1 5 13 8 16\n", "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "3 1 2\n20 17 8\n", "2 1 8\n18 17\n", "5 10 8\n0 0 0 0 0\n", "3 1 3\n3 2 0\n", "3 1 8\n10 17 18\n", "1 1 2\n1\n", "2 2 2\n9 10\n", ...
1,700
500
2
9
600_C. Make Palindrome
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
{ "input": [ "aabcd\n", "aabc\n" ], "output": [ "abcba\n", "abba\n" ] }
{ "input": [ "bbbcccddd\n", "asbbsha\n", "aabbcccdd\n", "qqqqaaaccdd\n", "abcd\n", "aaabbbcccdddeee\n", "aaabb\n", "acc\n", "azz\n", "aaaabbcccccdd\n", "aaacccb\n", "bababab\n", "ttttt\n", "aaadd\n", "aaabbbccc\n", "aaabbccdd\n", "ooooo\n", "abab...
1,800
0
2
8
644_B. Processing Queries
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment ti and needs to be processed for di units of time. All ti are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If server is free and...
{ "input": [ "4 1\n2 8\n4 8\n10 9\n15 2\n", "5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n" ], "output": [ "10 18 27 -1\n", "11 19 -1 21 22\n" ] }
{ "input": [ "6 3\n1 2\n2 3\n100 200\n200 300\n10000 20000\n20000 30000\n", "1 1\n1000000000 1000000000\n", "5 2\n2 7\n3 3\n7 4\n9 1\n10 2\n", "4 1\n1 2\n2 1\n3 1\n4 3\n", "10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8\n13 2\n20 2\n", "10 3\n1 14\n3 2\n5 4\n6 9\n9 1\n12 22\n15 11\n18 8\n28...
1,700
1,000
2
8
671_B. Robin Hood
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to t...
{ "input": [ "4 1\n1 1 4 2\n", "3 1\n2 2 2\n" ], "output": [ "2\n", "0\n" ] }
{ "input": [ "10 1000\n1000000000 999999994 999999992 1000000000 999999994 999999999 999999990 999999997 999999995 1000000000\n", "100 20\n2 5 3 3 2 7 6 2 2 2 6 7 2 1 8 10 2 4 10 6 10 2 1 1 4 7 1 2 9 7 5 3 7 4 6 3 10 10 3 7 6 8 2 2 10 3 1 2 1 3 1 6 3 1 4 10 3 10 9 5 10 4 3 10 3 3 5 3 10 2 1 5 10 7 8 7 7 2 4 2...
2,000
1,000
2
8
739_B. Alyona and a tree
Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges). Let's define dist(v, u) as the sum of the inte...
{ "input": [ "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1\n", "5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6\n" ], "output": [ "4 3 2 1 0 ", "1 0 1 0 0 " ] }
{ "input": [ "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000...
1,900
1,000
2
7
762_A. k-th divisor
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist. Divisor of n is any such natural number, that n can be divided by it without remainder. Input The first line contains two integers n and k (1 ≀ n ≀ 1015, 1 ≀ k ≀ 109). Output If n has less than k divisors, output ...
{ "input": [ "12 5\n", "4 2\n", "5 3\n" ], "output": [ "6\n", "2\n", "-1\n" ] }
{ "input": [ "4 3\n", "1998 1\n", "9 3\n", "99999999999931 2\n", "1234 2\n", "151491429961 4\n", "100 7\n", "1048576 12\n", "16 6\n", "1000000000000 100\n", "4567890 14\n", "1999967841 15\n", "1998 2\n", "1996 2\n", "1998 8\n", "21 3\n", "3 3\n", ...
1,400
0
2
8
785_B. Anton and Classes
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes. Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th v...
{ "input": [ "3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n", "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n" ], "output": [ "3\n", "0\n" ] }
{ "input": [ "1\n200000000 200000001\n1\n200000000 200000001\n", "1\n999999995 999999996\n1\n999999998 999999999\n", "1\n999999997 999999997\n1\n999999999 999999999\n", "1\n999999999 999999999\n1\n1000000000 1000000000\n", "6\n2 96\n47 81\n3 17\n52 52\n50 105\n1 44\n4\n40 44\n59 104\n37 52\n2 28\n...
1,100
1,000
2
8
807_B. T-Shirt Hunt
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p. Now the elimination rou...
{ "input": [ "493 8000 8000\n", "239 10880 9889\n", "329 19913 19900\n", "101 6800 6500\n", "26 7258 6123\n" ], "output": [ "24", "0", "8", "0", "2" ] }
{ "input": [ "186 18666 18329\n", "31 12956 10515\n", "198 6550 6549\n", "176 9670 9174\n", "26 20000 1\n", "180 4213 4207\n", "173 7017 4512\n", "412 5027 4975\n", "500 7030 7023\n", "500 18737 18069\n", "264 19252 10888\n", "42 11 6\n", "57 11066 9738\n", "364...
1,300
1,000
2
9
831_C. Jury Marks
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points. P...
{ "input": [ "4 1\n-5 5 0 20\n10\n", "2 2\n-2000 -2000\n3998000 4000000\n" ], "output": [ "3\n", "1\n" ] }
{ "input": [ "2 1\n614 -1943\n3874445\n", "1 1\n-577\n1273042\n", "1 1\n1\n-4000000\n", "3 1\n1416 -1483 1844\n3261895\n", "10 10\n-25 746 298 1602 -1453 -541 -442 1174 976 -1857\n-548062 -548253 -546800 -548943 -548402 -548794 -549236 -548700 -549446 -547086\n", "5 1\n1035 1861 1388 -622 1252...
1,700
1,000
2
11
876_E. National Property
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large ve...
{ "input": [ "6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4\n", "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1\n", "4 3\n1 2\n1 1\n3 1 3 2\n2 1 1\n" ], "output": [ "Yes\n0\n", "No\n", "Yes\n2\n2 3 " ] }
{ "input": [ "3 5\n2 1 2\n2 1 5\n2 4 4\n", "6 100\n1 3\n1 5\n2 7 5\n2 7 2\n3 7 7 2\n3 7 7 3\n", "10 4\n2 1 4\n2 1 4\n9 1 4 1 2 3 1 4 4 2\n1 4\n4 4 1 4 3\n7 4 4 4 4 1 4 2\n4 4 2 4 3\n4 2 4 4 4\n1 3\n9 3 3 3 4 2 3 3 2 4\n", "2 3\n2 1 3\n1 1\n", "3 3\n1 3\n1 2\n1 1\n", "2 100000\n5 1 2 3 1 5\n3 1...
2,100
1,500
2
11
8_E. Beads
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth β€” Masha. He knows that Masha likes two colours: blue and red, β€” and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on...
{ "input": [ "4 4\n" ], "output": [ "0101\n" ] }
{ "input": [ "3 2\n", "50 57129577186267\n", "6 12\n", "50 161245081749292\n", "5 3\n", "49 40394027154620\n", "7 15\n", "49 36309684494664\n", "50 250144743882708\n", "49 140149194635018\n", "5 10\n", "6 2\n", "6 19\n", "50 8840088596980\n", "6 4\n", "6...
2,600
0
2
10
922_D. Robot Vacuum Cleaner
Pushok the dog has been chasing Imp for a few hours already. <image> Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner. While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of strin...
{ "input": [ "2\nh\ns\n", "4\nssh\nhs\ns\nhhhs\n" ], "output": [ "1", "18" ] }
{ "input": [ "100\nh\nshh\nh\nhs\nshh\nhh\nh\nssh\nhss\nh\nhh\nh\nh\nh\nh\nh\nh\nh\nh\nh\nhh\nh\nh\nh\nh\nhhh\nh\nh\nhhh\nsh\nhh\nhs\nh\nh\nshs\nh\nh\nh\nshh\nhs\nhs\nh\nh\nh\nhhh\nh\nhhs\nhh\nh\nssh\nh\nh\nhh\nsh\nh\nhss\nh\nhh\nsh\nhh\nhh\nhhh\nhs\nh\nh\nh\nshs\nhs\nshs\nsh\nh\nh\nhs\nh\nh\nh\nh\nsh\nssh\nh\nh\...
1,800
1,500
2
9
978_C. Letters
There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in i-th dormitory are numbered from 1 to a_i. A postman delivers letters. Sometimes there is no specific dormitory and room number in it o...
{ "input": [ "2 3\n5 10000000000\n5 6 9999999999\n", "3 6\n10 15 12\n1 9 12 23 26 37\n" ], "output": [ "1 5\n2 1\n2 9999999994\n", "1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n" ] }
{ "input": [ "3 10\n1000000000 1000000000 1000000000\n543678543 567869543 1000000000 1000000001 1500000000 1999999999 2000000000 2000000001 2754432345 3000000000\n", "5 8\n10 1 1 1 10\n9 10 11 12 13 14 15 23\n", "4 18\n5 6 3 4\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18\n", "5 15\n10 20 30 20 10\n1 ...
1,000
0
2
8
998_B. Cutting
There are a lot of things which could be cut β€” trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
{ "input": [ "6 100\n1 2 3 4 5 6\n", "6 4\n1 2 5 10 15 20\n", "4 10\n1 3 2 4\n" ], "output": [ "2\n", "1\n", "0\n" ] }
{ "input": [ "100 50\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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\...
1,200
1,000
2
9
1032_C. Playing Piano
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: the more a number is, the closer it is to the right end of the piano keyboard. Paul is very clever and knows that the essential thing is...
{ "input": [ "7\n1 5 7 8 10 3 1\n", "19\n3 3 7 9 8 8 8 8 7 7 7 7 5 3 3 3 3 8 8\n", "5\n1 1 4 2 2\n" ], "output": [ "1 2 3 4 5 2 1 \n", "2 1 2 3 1 2 1 2 1 2 1 4 3 2 1 2 1 2 1 \n", "2 1 3 2 1 \n" ] }
{ "input": [ "20\n5 3 3 2 5 5 3 3 5 1 2 5 1 3 3 4 2 5 5 5\n", "1\n50\n", "100\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5 5 4 2 5\n", "33\n6 5 6 7 8 9 10...
1,700
1,500
2
7
1055_A. Metro
Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice ...
{ "input": [ "5 4\n1 0 0 0 1\n0 1 1 1 1\n", "5 3\n1 1 1 1 1\n1 1 1 1 1\n", "5 2\n0 1 1 1 1\n1 1 1 1 1\n" ], "output": [ "YES\n", "YES\n", "NO\n" ] }
{ "input": [ "4 2\n1 0 1 0\n0 1 1 0\n", "4 2\n1 0 1 1\n0 1 0 1\n", "5 3\n1 0 0 0 1\n1 0 1 0 0\n", "10 2\n1 0 0 1 0 1 1 0 1 1\n1 1 1 0 1 0 0 1 0 1\n", "7 4\n1 1 0 0 1 1 0\n1 1 1 1 1 1 1\n", "5 3\n1 0 0 0 1\n0 0 1 0 1\n", "4 2\n1 0 0 1\n0 1 0 1\n", "5 3\n1 1 0 1 0\n1 1 1 1 1\n", "5 2...
900
500
2
8
1077_B. Disturbed People
There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise. Vova thinks that people in the i-th flats are distur...
{ "input": [ "10\n1 1 0 1 1 0 1 0 1 0\n", "4\n1 1 1 1\n", "5\n1 1 0 0 0\n" ], "output": [ "2\n", "0\n", "0\n" ] }
{ "input": [ "5\n0 0 0 0 0\n", "5\n1 0 1 0 1\n", "62\n0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0\n", "85\n0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 1 0 1 0 1 0 1 0 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 0 1 0 0 1 1...
1,000
0
2
7
1098_A. Sum in the tree
Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v β‰₯ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v β€” the depth of vert...
{ "input": [ "3\n1 2\n2 -1 1\n", "5\n1 1 1 1\n1 -1 -1 -1 -1\n", "5\n1 2 3 1\n1 -1 2 -1 -1\n" ], "output": [ "-1\n", "1\n", "2\n" ] }
{ "input": [ "10\n1 1 2 4 4 5 6 3 3\n0 -1 -1 0 -1 -1 1 2 3 4\n", "2\n1\n1 -1\n", "2\n1\n0 -1\n", "10\n1 1 1 1 2 3 4 5 1\n3 -1 -1 -1 -1 3 3 3 3 -1\n", "5\n1 2 3 4\n5 -1 5 -1 7\n", "25\n1 2 1 4 4 4 1 2 8 5 1 8 1 6 9 6 10 10 7 10 8 17 14 6\n846 -1 941 -1 1126 1803 988 -1 1352 1235 -1 -1 864 -1 -1...
1,600
500
2
8
1119_B. Alyona and a Narrow Fridge
Alyona has recently bought a miniature fridge that can be represented as a matrix with h rows and 2 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but ...
{ "input": [ "5 10\n3 1 4 2 4\n", "10 10\n9 1 1 1 1 1 1 1 1 1\n", "5 7\n2 3 5 4 1\n" ], "output": [ "5", "4", "3" ] }
{ "input": [ "1 2\n2\n", "2 1\n1 1\n", "1 1\n1\n", "100 2000\n31 21 8 4 15 6 3 20 22 16 47 14 35 1 21 22 15 26 19 21 17 44 7 1 15 40 45 22 2 30 46 1 20 90 56 28 24 65 43 8 9 12 38 1 47 8 13 35 20 47 12 8 24 6 16 12 23 52 33 83 6 3 11 55 20 15 53 20 6 39 7 5 44 2 27 9 26 24 35 11 50 6 46 5 35 55 42 49 ...
1,300
1,000
2
12
1145_F. Neat Words
Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI O...
{ "input": [ "WORD\n", "APRILFOOL\n", "JUROR\n", "NEAT\n", "CODER\n", "YES\n", "AI\n" ], "output": [ "NO", "NO", "YES", "YES", "NO", "NO", "YES" ] }
{ "input": [ "BRIGHT\n", "SOURPUSS\n", "SUSHI\n", "WAYS\n", "DODO\n", "STATUSQUO\n", "KHAKI\n", "WEEVIL\n", "WAXY\n", "CROUP\n", "BURG\n", "PUZZLES\n", "PHRASE\n", "QUA\n", "WURM\n", "MAYFLY\n", "TEASE\n", "INFO\n", "Q\n", "RANDOMIZE\n", ...
0
0
2
11
1166_E. The LCMs Must be Large
Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia? There are n stores numbered from 1 to n in Nlogonia. The i-th of these stores offers a positive integer a_i. Each day among the last m days Dora bought a single integer from s...
{ "input": [ "10 10\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n", "2 5\n3 1 2 3\n3 3 4 5\n" ], "output": [ "impossible", "possible" ] }
{ "input": [ "4 4\n2 1 2\n2 2 3\n2 3 4\n2 4 1\n", "3 10\n4 6 10 1 9\n9 6 1 8 10 4 9 5 7 2\n8 3 10 6 8 2 4 5 1\n", "10 100\n4 51 22 73 78\n1 52\n5 49 74 100 14 80\n1 6\n2 98 65\n5 79 13 47 24 77\n6 47 57 35 24 59 94\n9 89 11 3 67 80 70 44 75 6\n7 12 9 92 30 10 29 70\n8 99 34 89 87 63 2 96 25\n" ], "out...
2,100
2,500
2
9
1185_C1. Exam in BerSU (easy version)
The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: *...
{ "input": [ "7 15\n1 2 3 4 5 6 7\n", "5 100\n80 40 40 40 60\n" ], "output": [ "0 0 0 0 0 2 3\n", "0 1 1 2 3\n" ] }
{ "input": [ "14 70\n2 8 10 1 10 6 10 6 9 4 10 10 10 9\n", "10 50\n9 9 9 9 9 9 9 9 9 9\n", "3 299\n100 100 100\n", "19 95\n1 9 5 5 9 8 9 6 3 7 1 1 6 7 4 4 4 2 10\n", "17 85\n1 2 10 3 10 9 1 6 6 5 9 2 10 1 3 3 7\n", "2 100\n1 99\n", "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 ...
1,200
1,000
2
12
1203_F2. Complete the Projects (hard version)
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is r units. Some very rich customers asked him to complete some projects for their companies. To complete ...
{ "input": [ "3 4\n4 6\n10 -2\n8 -1\n", "3 2\n300 -300\n1 299\n1 123\n", "5 20\n45 -6\n34 -15\n10 34\n1 27\n40 -45\n" ], "output": [ "3", "3", "5" ] }
{ "input": [ "20 1000\n29531 141\n29892 277\n29544 141\n29825 -194\n29846 164\n29595 25\n28975 -249\n29926 -108\n29920 -99\n29232 -238\n29892 -284\n29757 270\n29828 122\n29925 256\n29656 -128\n29052 -165\n29648 -65\n29713 226\n29903 -110\n29893 117\n", "50 30000\n241 -293\n284 -295\n99 -293\n307 -300\n254 -29...
2,300
0
2
11
1220_E. Tourism
Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to A...
{ "input": [ "5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2\n", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6\n" ], "output": [ "27\n", "61\n" ] }
{ "input": [ "3 2\n1 1335 2\n2 1\n3 2\n2\n", "28 31\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 2 1 0 1 0 0 1 1 1 0\n9 7\n24 10\n12 27\n3 20\n16 3\n27 8\n23 25\n19 20\n10 17\n7 13\n7 5\n15 11\n19 1\n25 4\n26 22\n21 3\n17 24\n27 11\n26 20\n22 24\n8 12\n25 6\n2 14\n22 28\n20 18\n2 21\n13 9\n23 4\n19 7\n22 25\n11 24\n2...
2,200
2,750
2
7
1246_A. p-binary
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binary numbers of the form 2^x + p, where x is a non-negative integer. For example,...
{ "input": [ "4 -7\n", "24 -1\n", "24 1\n", "24 0\n", "1 1\n" ], "output": [ "2\n", "4\n", "3\n", "2\n", "-1\n" ] }
{ "input": [ "536870812 1\n", "1 0\n", "1999 999\n", "1 -1000\n", "3 2\n", "21 10\n", "1000000000 1000\n", "1 1000\n", "1 -1\n", "2001 1000\n", "29 9\n", "13 6\n", "3 -179\n", "2 1\n", "100500 -179\n", "678 169\n", "536870912 0\n", "101 50\n", ...
1,600
1,500
2
11
1265_E. Beautiful Mirrors
Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability (p_i)/(100) for all 1 ≀ i ≀ n. Creatnx asks the mirrors one by one, starting from the 1-st mirror. Every day, if he asks i-th mirror, there ...
{ "input": [ "1\n50\n", "3\n10 20 50\n" ], "output": [ "2\n", "112\n" ] }
{ "input": [ "5\n30 48 49 17 25\n", "4\n42 20 51 84\n", "100\n60 79 48 35 18 24 87 1 44 65 60 78 11 43 71 79 90 6 94 49 22 91 58 93 55 21 22 31 7 15 17 65 76 9 100 89 50 96 14 38 27 87 29 93 54 12 99 35 27 51 36 44 6 26 91 1 53 8 49 63 18 4 31 55 95 15 77 1 16 98 75 26 26 43 2 11 18 70 3 65 11 74 64 69 26...
2,100
2,000
2
7
1287_A. Angry Students
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another. Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P": * "A" corresponds to an angry...
{ "input": [ "1\n4\nPPAP\n", "3\n12\nAPPAPPPAPPPP\n3\nAAP\n3\nPPA\n" ], "output": [ "1\n", "4\n1\n0\n" ] }
{ "input": [ "10\n1\nA\n1\nP\n2\nAP\n2\nPA\n8\nPPPPAPPP\n8\nPPPPPPPA\n8\nAPPPPPPP\n8\nPPPPPPAP\n8\nPPPPPAPP\n8\nPPPAPPPP\n", "16\n4\nPPPP\n4\nAPPP\n4\nPAPP\n4\nAAPP\n4\nPPAP\n4\nAPAP\n4\nPAAP\n4\nAAAP\n4\nPPPA\n4\nAPPA\n4\nPAPA\n4\nAAPA\n4\nPPAA\n4\nAPAA\n4\nPAAA\n4\nAAAA\n", "1\n100\nPAPPPAPAAPAAPAAPPAAA...
800
500
2
7
1330_A. Dreamoon and Ranking Collection
Dreamoon is a big fan of the Codeforces contests. One day, he claimed that he will collect all the places from 1 to 54 after two more rated contests. It's amazing! Based on this, you come up with the following problem: There is a person who participated in n Codeforces rounds. His place in the first round is a_1, hi...
{ "input": [ "5\n6 2\n3 1 1 5 7 10\n1 100\n100\n11 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1\n1\n4 57\n80 60 40 20\n" ], "output": [ "5\n101\n2\n2\n60\n" ] }
{ "input": [ "1\n5 2\n3 4 5 6 7\n", "1\n6 1\n1 3 4 5 6 7\n", "1\n4 3\n4 5 6 7\n", "1\n4 1\n1 3 4 5\n", "1\n1 1\n2\n", "1\n5 1\n1 3 4 6 6\n", "1\n3 3\n4 5 6\n", "1\n4 5\n6 6 7 7\n", "1\n9 1\n1 2 3 4 5 7 8 9 10\n", "1\n5 1\n1 2 4 5 6\n", "1\n13 1\n1 2 3 4 5 6 7 8 9 10 11 12 1...
900
500
2
7
1350_A. Orac and Factors
Orac is studying number theory, and he is interested in the properties of divisors. For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that aβ‹… c=b. For n β‰₯ 2, we will denote as f(n) the smallest positive divisor of n, except 1. For example, f(7)=7,f(10)=2,f(35)=5. ...
{ "input": [ "3\n5 1\n8 2\n3 4\n" ], "output": [ "10\n12\n12\n" ] }
{ "input": [ "5\n497347 19283\n2568 1000000000\n499979 123987\n93 19\n13 5\n", "1\n902059 999999997\n", "1\n66605 9996\n", "1\n100000 9997\n", "1\n19 6\n", "1\n1000000 100008\n", "1\n5 17\n", "1\n932531 999999995\n", "1\n999983 99999999\n", "1\n980051 999999995\n", "1\n9999...
900
500
2
10
1370_D. Odd-Even Subsequence
Ashish has an array a of size n. A subsequence of a is defined as a sequence that can be obtained from a by deleting some elements (possibly none), without changing the order of the remaining elements. Consider a subsequence s of a. He defines the cost of s as the minimum between: * The maximum among all elements...
{ "input": [ "4 2\n1 2 3 4\n", "4 3\n1 2 3 4\n", "6 4\n5 3 50 2 4 5\n", "5 3\n5 3 4 2 6\n" ], "output": [ "1\n", "2\n", "3\n", "2\n" ] }
{ "input": [ "4 2\n93648 34841 31096 95128\n", "10 4\n91239 51189 50977 96098 56330 55725 6448 7351 60071 93359\n", "4 4\n99402 47701 84460 34277\n", "7 7\n20569 28739 17283 56309 61086 8910 52918\n", "3 2\n60105 66958 8251\n", "6 3\n36914 69317 77398 81226 65499 13860\n", "9 6\n61893 4130...
2,000
2,000
2
11
1417_E. XOR Inverse
You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i βŠ• x (βŠ• denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)). An inversion i...
{ "input": [ "9\n10 7 9 10 7 5 5 3 5\n", "3\n8 10 3\n", "4\n0 1 3 2\n" ], "output": [ "4 14\n", "0 8\n", "1 0\n" ] }
{ "input": [ "94\n89 100 92 24 4 85 63 87 88 94 68 14 61 59 5 77 82 6 13 13 25 43 80 67 29 42 89 35 72 81 35 0 12 35 53 54 63 37 52 33 11 84 64 33 65 58 89 37 59 32 23 92 14 12 30 61 5 78 39 73 21 37 64 50 10 97 12 94 20 65 63 41 86 60 47 72 79 65 31 56 23 5 85 44 4 34 66 1 92 91 60 43 18 58\n", "96\n79 50 37...
2,000
1,250
2
9
1434_C. Solo mid Oracle
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of every second, for exactly c seconds, starting one second after the ability is used. That means that if the ability is used at time t, the ...
{ "input": [ "7\n1 1 1 1\n2 2 2 2\n1 2 3 4\n4 3 2 1\n228 21 11 3\n239 21 11 3\n1000000 1 1000000 1\n" ], "output": [ "1\n2\n1\n5\n534\n-1\n500000500000\n" ] }
{ "input": [ "1\n1000000 1000000 1 1000000\n", "4\n568133 729913 934882 371491\n916127 997180 932938 203988\n112133 793452 857041 842130\n572010 190716 396183 683429\n", "2\n395916 225366 921987 169483\n604656 668976 459504 264596\n", "6\n879274 712902 672766 383030\n997653 839911 351405 69197\n31160 ...
2,100
2,250
2
7
145_A. Lucky Conversion
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety...
{ "input": [ "774\n744\n", "47\n74\n", "777\n444\n" ], "output": [ "1\n", "1\n", "3\n" ] }
{ "input": [ "74747474\n77777777\n", "44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447\n", "44447774444474477747774774477777474774744744477444447777477477744747477774744444744777777777747777477447744774744444747477744744\n777774744774777477747777774744744774...
1,200
500
2
9
1485_C. Floor and Mod
A pair of positive integers (a,b) is called special if ⌊ a/b βŒ‹ = a mod b. Here, ⌊ a/b βŒ‹ is the result of the integer division between a and b, while a mod b is its remainder. You are given two integers x and y. Find the number of special pairs (a,b) such that 1≀ a ≀ x and 1 ≀ b ≀ y. Input The first line contains a s...
{ "input": [ "9\n3 4\n2 100\n4 3\n50 3\n12 4\n69 420\n12345 6789\n123456 789\n12345678 9\n" ], "output": [ "\n1\n0\n2\n3\n5\n141\n53384\n160909\n36\n" ] }
{ "input": [ "1\n3 1\n" ], "output": [ "0\n" ] }
1,700
1,500
2
7
150_A. Win or Freeze
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl...
{ "input": [ "30\n", "1\n", "6\n" ], "output": [ "1\n6\n", "1\n0\n", "2\n" ] }
{ "input": [ "8587340257\n", "7420738134810\n", "2975\n", "1000000000000\n", "236\n", "27\n", "9\n", "3047527844089\n", "16\n", "5\n", "614125\n", "9999925100701\n", "30971726\n", "266418\n", "401120980262\n", "319757451841\n", "1307514188557\n", ...
1,400
500
2
10
182_D. Common Divisors
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
{ "input": [ "aaa\naa\n", "abcdabcd\nabcdabcdabcdabcd\n" ], "output": [ "1", "2" ] }
{ "input": [ "aba\nabaaba\n", "ab\nab\n", "aaa\naaaaab\n", "aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa\n", "ab\naa\n", "ab\nac\n", "aa\nbb\n", "abcabc\nabdabdabd\n", "abcabcabc\nertert\n", "aa\naac\n", "aaaaaa\naaaaaaaaa\n", "aaa\nbbb\n", "aaaa\nbbbb\n", ...
1,400
1,000
2
11
22_E. Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
{ "input": [ "3\n3 3 2\n", "7\n2 3 1 3 4 4 1\n" ], "output": [ "1\n2 1\n", "3\n2 6\n6 7\n7 5\n" ] }
{ "input": [ "9\n2 5 6 7 4 1 9 6 8\n", "7\n3 1 2 5 6 7 4\n", "7\n2 3 1 3 4 4 1\n", "20\n20 10 16 14 9 20 6 20 14 19 17 13 16 13 14 8 8 8 8 19\n", "2\n2 1\n", "3\n2 3 1\n", "5\n5 3 5 2 3\n", "4\n2 4 4 3\n", "100\n13 71 16 92 25 53 97 63 70 83 51 16 51 84 5 10 54 89 18 95 48 29 82 27...
2,300
0
2
10
255_D. Mr. Bender and Square
Mr. Bender has a digital table of size n Γ— n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns β€” numbered from left to right f...
{ "input": [ "9 3 8 10\n", "6 4 3 1\n" ], "output": [ "2\n", "0\n" ] }
{ "input": [ "1000000000 63 65 384381709\n", "9 4 3 10\n", "847251738 695702891 698306947 648440371\n", "958 768 649 298927\n", "8 2 6 10\n", "9 8 2 50\n", "1000000000 55 999999916 423654797\n", "8 8 3 1\n", "8 1 2 10\n", "1000000000 6 999999904 272656295\n", "1000000000 99...
1,800
2,000
2
10
279_D. The Minimum Number of Variables
You've got a positive integer sequence a1, a2, ..., an. All numbers in the sequence are distinct. Let's fix the set of variables b1, b2, ..., bm. Initially each variable bi (1 ≀ i ≀ m) contains the value of zero. Consider the following sequence, consisting of n operations. The first operation is assigning the value of...
{ "input": [ "5\n1 2 3 6 8\n", "3\n3 6 5\n", "6\n2 4 8 6 10 18\n" ], "output": [ "2", "-1", "3" ] }
{ "input": [ "23\n26988535 53977070 107954140 161931210 323862420 215908280 431816560 647724840 269885350 242896815 755678980 485793630 863633120 404828025 539770700 134942675 593747770 377839490 917610190 809656050 620736305 971587260 458805095\n", "22\n1 2 4 3 8 6 12 14 16 18 24 7 22 20 11 32 13 19 64 30 26...
2,200
2,000
2
9
301_C. Yaroslav and Algorithm
Yaroslav likes algorithms. We'll describe one of his favorite algorithms. 1. The algorithm receives a string as the input. We denote this input string as a. 2. The algorithm consists of some number of command. Π‘ommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strin...
{ "input": [ "2\n10\n79\n" ], "output": [ "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" ] }
{ "input": [ "10\n630\n624\n85\n955\n757\n841\n967\n377\n932\n309\n", "10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "10\n392\n605\n903\n154\n293\n383\n422\n717\n719\n896\n", "10\n447\n806\n891\n730\n371\n351\n7\n102\n394\n549\n", "10\n317\n36\n191\n843\n289\n107\n41\n943\n265\n649\n", "10\n1\n2\n3\n4\...
2,500
1,500