problem_statement
stringlengths
147
8.53k
input
stringlengths
1
771
output
stringlengths
1
592
time_limit
stringclasses
32 values
memory_limit
stringclasses
21 values
tags
stringlengths
6
168
G. New Year and the Factorisation Collaborationtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInteger factorisation is hard. The RSA Factoring Challenge offered $100\,000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was...
Input21717151711-115
Output+ 12 16- 6 10* 8 15/ 5 4sqrt 16sqrt 5^ 6 12! 2 3 7
6 seconds
256 megabytes
['interactive', 'math', 'number theory', '*3200']
F. New Year and the Mallard Expeditiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is a duck. He wants to get to Alice's nest, so that those two can duck! Duck is the ultimate animal! (Image courtesy of See Bang) The journey can be represented as a straight l...
1 10 G
30
1 second
256 megabytes
['constructive algorithms', 'greedy', '*2600']
E. New Year and the Acquaintance Estimationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if a is a friend of b, then b is also a frien...
Input33 3 3
Output3
2 seconds
256 megabytes
['binary search', 'data structures', 'graphs', 'greedy', 'implementation', 'math', 'sortings', '*2400']
D. New Year and the Permutation Concatenationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence p. For example, if n = 3, then p = [1, 2...
3
9
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*1700']
C. New Year and the Sphere Transmissiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere 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. Peo...
6
1 5 9 21
1 second
256 megabytes
['math', 'number theory', '*1400']
B. New Year and the Treasure Geolocationtime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out.Bob travelled around the wo...
2 2 5 -6 4 7 -2 -1 -3
1 2
1.5 seconds
256 megabytes
['brute force', 'constructive algorithms', 'greedy', 'implementation', '*1200']
A. New Year and the Christmas Ornamenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob are decorating a Christmas Tree. Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have y yellow ornaments, b blue orn...
8 13 9
24
1 second
256 megabytes
['brute force', 'implementation', 'math', '*800']
M. The Pleasant Walktime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n houses along the road where Anya lives, each one is painted in one of k possible colors.Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have ...
8 3 1 2 3 3 2 1 2 2
4
1 second
512 megabytes
['implementation', '*1000']
J. Two Prefixestime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputMisha didn't do his math homework for today's lesson once again. As a punishment, his teacher Dr. Andrew decided to give him a hard, but very useless task.Dr. Andrew has written two strings s and t of low...
Inputabaaa
Output5
1 second
512 megabytes
['strings', '*2600']
D. Similar Arraystime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these po...
1 0
NO
1 second
512 megabytes
['constructive algorithms', '*1800']
C. New Year Presentstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSanta has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two pre...
3 5 5 1 2 3 4 5 2 1 2 2 3 4
2 1 3 5 1 2 3
2 seconds
512 megabytes
['constructive algorithms', 'data structures', '*2400']
A. Company Mergingtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputA conglomerate consists of n companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to sel...
3 2 4 3 2 2 1 3 1 1 1
13
1 second
512 megabytes
['greedy', '*1300']
L. Lazylandtime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe kingdom of Lazyland is the home to n idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland. Today k important jobs for the kingdom (k \le n) shou...
8 7 1 1 3 1 5 3 7 1 5 7 4 8 1 3 5 2
10
1.5 seconds
512 megabytes
['*900']
K. King Kog's Receptiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKing Kog got annoyed of the usual laxity of his knights — they can break into his hall without prior notice! Thus, the King decided to build a reception with a queue where each knight chooses in ...
19 ? 3 + 2 2 ? 3 ? 4 + 5 2 ? 5 ? 6 + 1 2 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 9 - 8 ? 2 ? 3 ? 6
0 1 0 2 1 3 2 1 2 1 0 0 2 1 1
2 seconds
512 megabytes
['data structures', '*2400']
J. JS Minificationtime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputInternational 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 cont...
16 fun while return var { } ( ) , ; > = + ++ - -- 9 fun fib(num) { # compute fibs var return_value = 1, prev = 0, temp; while (num > 0) { temp = return_value; return_value = return_value + prev; prev = temp; num--; } return return_value; }
fun a(b){var c=1,d=0,e;while(b>0){e=c;c=c+d;d=e;b--;}return c;}
1.5 seconds
512 megabytes
['greedy', 'implementation', '*3200']
I. Interval-Free Permutationstime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider a permutation p_1, p_2, \dots p_n of integers from 1 to n. We call a sub-segment p_l, p_{l+1}, \dots, p_{r-1}, p_{r} of the permutation an interval if it is a reordering of some ...
4 998244353 1 4 5 9
1 2 6 28146
1.5 seconds
512 megabytes
['combinatorics', '*2600']
G. Guest Studenttime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBerland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country.Berland State University works...
3 2 0 1 0 0 0 0 0 100000000 1 0 0 0 1 0 1 1 1 0 0 0 0 0 0
8 233333332 1
1.5 seconds
512 megabytes
['math', '*1500']
F. Fractionstime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a positive integer n.Find a sequence of fractions \frac{a_i}{b_i}, i = 1 \ldots k (where a_i and b_i are positive integers) for some k such that: \begin{cases} \text{$b_i$ divides $n$, $1 < ...
2
NO
1.5 seconds
512 megabytes
['math', '*1900']
A. Alice the Fantime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAlice is a big fan of volleyball and especially of the very strong "Team A".Volleyball match consists of up to five sets. During each set teams score one point for winning a ball. The first four sets ...
6 75 0 90 90 20 0 0 75 78 50 80 100
3:0 25:0 25:0 25:0 3:1 25:22 25:22 15:25 25:21 Impossible 0:3 0:25 0:25 0:25 3:0 25:11 28:26 25:13 3:2 25:17 0:25 25:22 15:25 15:11
1.5 seconds
512 megabytes
['dp', '*2200']
F. Ehab and a weird weight formulatime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given a tree consisting of n nodes. Every node u has a weight a_u. It is guaranteed that there is only one node with minimum weight in the tree. For every node u (except for t...
Input31 2 31 21 3
Output7
2.5 seconds
256 megabytes
['data structures', 'trees', '*2800']
E. Ehab and a component choosing problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given a tree consisting of n nodes. Every node u has a weight a_u. You want to choose an integer k (1 \le k \le n) and then choose k connected components of nodes that don'...
3 1 2 3 1 2 1 3
6 1
1 second
256 megabytes
['dp', 'greedy', 'math', 'trees', '*2400']
D. Ehab and another another xor problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem!Ehab plays a game with Laggy. Ehab has 2 hidden integers (a,b). Laggy can ask a pair of integers (c,d) and Ehab will reply with: 1 if a \oplus c>b \...
Input1-10
Output? 2 1? 1 2? 2 0! 3 1
1 second
256 megabytes
['bitmasks', 'constructive algorithms', 'implementation', 'interactive', '*2000']
C. Ehab and a 2-operation tasktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given an array a of length n. You can perform the following operations on it: choose an index i (1 \le i \le n), an integer x (0 \le x \le 10^6), and replace a_j with a_j+x for all ...
Input31 2 3
Output0
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', '*1400']
B. Ehab and subtractiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given an array a. You should repeat the following operation k times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the arr...
Input3 51 2 3
Output11100
1 second
256 megabytes
['implementation', 'sortings', '*1000']
A. Ehab and another construction problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an integer x, find 2 integers a and b such that: 1 \le a,b \le x b divides a (a is divisible by b). a \cdot b>x. \frac{a}{b}<x. InputThe only line contains the integer ...
Input10
Output6 3
1 second
256 megabytes
['brute force', 'constructive algorithms', '*800']
F. Forest Firestime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland forest was planted several decades ago in a formation of an infinite grid with a single tree in every cell. Now the trees are grown up and they form a pretty dense structure.So dense, actually,...
1 2 10 11
40
2.5 seconds
256 megabytes
['math', '*3500']
G. Beautiful Matrixtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya collects beautiful matrix.A matrix of size n \times n is beautiful if: All elements of the matrix are integers between 1 and n; For every row of the matrix, all elements of this row are diff...
2 2 1 1 2
1
4 seconds
256 megabytes
['combinatorics', 'data structures', 'dp', '*2900']
F. Rock-Paper-Scissors Championtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn players are going to play a rock-paper-scissors tournament. As you probably know, in a one-on-one match of rock-paper-scissors, two players choose their shapes independently. The outcom...
3 5 RPS 1 S 2 R 3 P 1 P 2 P
2 2 1 2 2 3
2 seconds
256 megabytes
['*2500']
E. Vasya and Templatestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya owns three strings s , a and b, each of them consists only of first k Latin letters.Let a template be such a string of length k that each of the first k Latin letters appears in it exactly o...
Input24bbcbaadaaada3abcbbbbbb
OutputYESbadcNO
5 seconds
256 megabytes
['greedy', 'implementation', 'strings', '*2300']
D. Minimum Diameter Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (an undirected connected graph without cycles) and an integer s.Vanya wants to put weights on all edges of the tree so that all weights are non-negative real numbers and thei...
4 3 1 2 1 3 1 4
2.000000000000000000
1 second
256 megabytes
['constructive algorithms', 'implementation', 'trees', '*1700']
C. Connect Threetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Squareland national forest is divided into equal 1 \times 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y)...
0 0 1 1 2 2
5 0 0 1 0 1 1 1 2 2 2
1 second
256 megabytes
['implementation', 'math', '*1600']
B. Div Times Modtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya likes to solve equations. Today he wants to solve (x~\mathrm{div}~k) \cdot (x \bmod k) = n, where \mathrm{div} and \mathrm{mod} stand for integer division and modulo operations (refer to the Notes ...
6 3
11
1 second
256 megabytes
['math', '*1100']
A. Right-Left Ciphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp loves ciphers. He has invented his own cipher called Right-Left.Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} \dots s_{n} Polycarp uses the following algorithm: ...
ncteho
techno
1 second
256 megabytes
['implementation', 'strings', '*800']
C. The Fair Nut and Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, \ldots, p_k, s...
Inputabbaa
Output5
1 second
256 megabytes
['combinatorics', 'dp', 'implementation', '*1500']
B. Kvass and the Fair Nuttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly...
Input3 34 3 5
Output3
1 second
256 megabytes
['greedy', 'implementation', '*1200']
A. The Fair Nut and Elevatortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe 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) flo...
Input30 2 1
Output16
1 second
256 megabytes
['brute force', 'implementation', '*1000']
F. The Fair Nut and Amusing Xortime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Fair Nut has two arrays a and b, consisting of n numbers. He found them so long ago that no one knows when they came to him.The Fair Nut often changes numbers in his arrays. He also i...
Input3 3 10 4 21 2 3b 2 5
Output-11
4 seconds
256 megabytes
['data structures', '*3300']
E. The Fair Nut and Rectanglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Fair Nut got stacked in planar world. He should solve this task to get out.You are given n rectangles with vertexes in (0, 0), (x_i, 0), (x_i, y_i), (0, y_i). For each rectangle, you a...
3 4 4 8 1 5 0 5 2 10
9
2 seconds
256 megabytes
['data structures', 'dp', 'geometry', '*2400']
D. The Fair Nut's getting crazytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Fair Nut has found an array a of n integers. We call subarray l \ldots r a sequence of consecutive elements of an array with indexes from l to r, i.e. a_l, a_{l+1}, a_{l+2}, \ldots, a...
Input31 2 3
Output1
4 seconds
256 megabytes
['data structures', 'implementation', '*3500']
C. Max Mextime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Grisha found a tree (connected graph without cycles) with a root in node 1.But this tree was not just a tree. A permutation p of integers from 0 to n - 1 is written in nodes, a number p_i is written in n...
6 2 5 0 3 1 4 1 1 3 3 3 3 2 1 6 3 2
3 2
3 seconds
256 megabytes
['data structures', 'trees', '*2900']
B. The Fair Nut and Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c — the number of strings that are prefixes of at least one of the written strings. E...
2 4 aa bb
6
1 second
256 megabytes
['greedy', 'strings', '*2000']
A. The Fair Nut and the Best Pathtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree ...
Input31 3 31 2 21 3 2
Output3
3 seconds
256 megabytes
['data structures', 'dp', 'trees', '*1800']
G. Petya and Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has a simple graph (that is, a graph without loops or multiple edges) consisting of n vertices and m edges.The weight of the i-th vertex is a_i.The weight of the i-th edge is w_i.A subgraph of a...
4 5 1 5 2 2 1 3 4 1 4 4 3 4 5 3 2 2 4 2 2
8
2 seconds
256 megabytes
['flows', 'graphs', '*2400']
F. Speed Dialtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp's phone book contains n phone numbers, each of them is described by s_i — the number itself and m_i — the number of times Polycarp dials it in daily.Polycarp has just bought a brand new phone with...
3 1 0001 5 001 4 01 1
14
2 seconds
256 megabytes
['dp', 'strings', 'trees', '*2800']
E. Increasing Frequencytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given array a of length n. You can choose one segment [l, r] (1 \le l \le r \le n) and integer value k (positive, negative or even zero) and change a_l, a_{l + 1}, \dots, a_r by k each (i...
6 9 9 9 9 9 9 9
6
2 seconds
256 megabytes
['binary search', 'dp', 'greedy', '*2000']
D. Maximum Diameter Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGraph 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 pa...
3 2 2 2
YES 2 2 1 2 2 3
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'implementation', '*1800']
C. Multi-Subject Competitiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA multi-subject competition is coming! The competition has m different subjects participants can choose from. That's why Alex (the coach) should form a competition delegation among his stude...
6 3 2 6 3 6 2 5 3 5 1 9 3 1
22
2 seconds
256 megabytes
['greedy', 'sortings', '*1600']
B. Vova and Trophiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova has won n trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row.The beauty of the arrangement is the length of the longest subsegment co...
10 GGGSGGGSGG
7
2 seconds
256 megabytes
['greedy', '*1600']
A. Vasya and Booktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two b...
3 10 4 5 2 5 1 3 4 20 4 19 3
4 -1 5
2 seconds
256 megabytes
['implementation', 'math', '*1200']
H. Palindromic Magictime limit per test2.5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputAfter learning some fancy algorithms about palindromes, Chouti found palindromes very interesting, so he wants to challenge you with this problem.Chouti has got two strings A and B. Since he like...
Inputaaaba
Output6
2.5 seconds
1024 megabytes
['data structures', 'hashing', 'strings', '*3500']
G. Mergesort Strikes Backtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputChouti thought about his very first days in competitive programming. When he had just learned to write merge sort, he thought that the merge sort is too slow, so he restricted the maximum depth ...
Input3 1 998244353
Output499122178
1 second
256 megabytes
['math', 'probabilities', '*3200']
F. Tricky Interactortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Chouti was tired of studying, so he opened the computer and started playing a puzzle game.Long long ago, the boy found a sequence s_1, s_2, \ldots, s_n of length n, kep...
Input4 2220
Output? 1 1? 1 1? 3 4! 0011
1 second
256 megabytes
['constructive algorithms', 'implementation', 'interactive', '*2600']
E. Missing Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputChouti is working on a strange math problem.There was a sequence of n positive integers x_1, x_2, \ldots, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x...
Input65 11 44
OutputYes4 5 16 11 64 44
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'greedy', 'math', 'number theory', '*1900']
D. Maximum Distancetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputChouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.You are given a connected undirected graph with n vertices and m weighted edges. There are k s...
Input2 3 22 11 2 31 2 22 2 1
Output2 2
1 second
256 megabytes
['dsu', 'graphs', 'shortest paths', 'sortings', '*1800']
C. Colorful Brickstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different...
3 3 0
3
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*1500']
B. Farewell Partytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputChouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.Chouti reme...
Input30 0 0
OutputPossible1 1 1
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1500']
A. Definite Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputChouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.He came up with the following game. The player...
8
1
1 second
256 megabytes
['constructive algorithms', 'math', '*800']
F. Katya and Segments Setstime limit per test3.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt is a very important day for Katya. She has a test in a programming class. As always, she was given an interesting problem that she solved very fast. Can you solve that problem?You are giv...
5 5 9 3 6 3 1 3 1 2 4 2 1 2 3 4 6 5 2 5 3 7 9 4 2 3 1 4 10 4 1 2 2 3 1 2 2 4 1 3 1 5 2 3 3 6 2 4 2 9
no yes yes no yes
3.5 seconds
512 megabytes
['data structures', 'interactive', 'sortings', '*2400']
E. Sonya and Matrix Beautytime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSonya had a birthday recently. She was presented with the matrix of size n\times m and consist of lowercase Latin letters. We assume that the rows are numbered by integers from 1 to n from b...
1 3 aba
4
1.5 seconds
256 megabytes
['strings', '*2400']
D. Olya and magical squaretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Olya received a magical square with the size of 2^n\times 2^n.It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations.A S...
3 1 1 2 2 2 12
YES 0 YES 1 NO
1 second
256 megabytes
['constructive algorithms', 'implementation', 'math', '*2000']
C. Masha and two friendstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Masha was presented with a chessboard with a height of n and a width of m.The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m fr...
5 2 2 1 1 2 2 1 1 2 2 3 4 2 2 3 2 3 1 4 3 1 5 1 1 5 1 3 1 5 1 4 4 1 1 4 2 1 3 4 4 3 4 1 2 4 2 2 1 3 3
0 4 3 9 2 3 8 8 4 8
1 second
256 megabytes
['implementation', '*1500']
B. Margarite and the best presenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array a of the size of 1...
5 1 3 2 5 5 5 4 4 2 3
-2 -2 -5 4 -1
1 second
256 megabytes
['math', '*900']
A. Petya and Origamitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya is having a party soon, and he has decided to invite his n friends.He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eigh...
3 5
10
1 second
256 megabytes
['math', '*800']
E. Negative Time Summationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEveryone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!More specifically, it works as follows. It has an infi...
Input2123456789 987654321555555555 555555555
Output0l1l1l0l0l0l1l1l1l0l1l0l1l1l0l0l0l1l0l1l1l1l0l0l0l1l0l0l0l0l1l0lr
1 second
256 megabytes
['constructive algorithms', '*3400']
F2. Pictures with Kittens (hard version)time limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraints.Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an arr...
5 2 3 5 1 3 10 1
18
2.5 seconds
512 megabytes
['data structures', 'dp', '*2100']
F1. Pictures with Kittens (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraints.Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array...
5 2 3 5 1 3 10 1
18
2 seconds
256 megabytes
['dp', '*1900']
E. Thematic Conteststime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has prepared n competitive programming problems. The topic of the i-th problem is a_i, and some problems' topics may coincide.Polycarp has to host several thematic contests. All problems in ...
18 2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10
14
1 second
256 megabytes
['greedy', 'sortings', '*1800']
D. Cutting Outtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array s consisting of n integers.You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.Cutting out the copy of t means that f...
7 3 1 2 3 2 4 3 1
1 2 3
3 seconds
256 megabytes
['binary search', 'sortings', '*1600']
C. Good Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1, 3, 3, 7] is good because there is the element a_4=7 which equals to th...
5 2 5 1 2 2
3 4 1 5
1 second
256 megabytes
['*1300']
B. Disturbed Peopletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere 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, \dots, a_n, wher...
10 1 1 0 1 1 0 1 0 1 0
2
1 second
256 megabytes
['greedy', '*1000']
A. Frog Jumpingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA frog is currently at the point 0 on a coordinate axis Ox. It jumps by the following algorithm: the first jump is a units to the right, the second jump is b units to the left, the third jump is a units t...
6 5 2 3 100 1 4 1 10 5 1000000000 1 6 1 1 1000000000 1 1 999999999
8 198 -17 2999999997 0 1
1 second
256 megabytes
['math', '*800']
G. Array Gametime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider a following game between two players:There is an array b_1, b_2, ..., b_k, consisting of positive integers. Initially a chip is placed into the first cell of the array, and b_1 is decreased by 1. ...
5 2 4 1 2 3 4 5 1 3 5 6 2 2 5 1 1 2 3 2 1 5
1 1
6 seconds
512 megabytes
['data structures', 'games', '*3000']
F. Summer Practice Reporttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova has taken his summer practice this year and now he should write a report on how it went.Vova has already drawn all the tables and wrote down all the formulas. Moreover, he has already deci...
2 2 5 5 2 2
YES
2 seconds
256 megabytes
['dp', 'greedy', '*2500']
E. Vasya and a Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a tree consisting of n vertices with root in vertex 1. At first all vertices has 0 written on it.Let d(i, j) be the distance between vertices i and j, i.e. number of edges in the shortest p...
5 1 2 1 3 2 4 2 5 3 1 1 1 2 0 10 4 10 100
1 11 1 100 0
2 seconds
256 megabytes
['data structures', 'trees', '*1900']
D. Edge Deletiontime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected connected weighted graph consisting of n vertices and m edges. Let's denote the length of the shortest path from vertex 1 to vertex i as d_i. You have to erase some edges o...
3 3 2 1 2 1 3 2 1 1 3 3
2 1 2
2.5 seconds
256 megabytes
['graphs', 'greedy', 'shortest paths', '*1800']
C. Meme Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTry guessing the statement from this picture: You are given a non-negative integer d. You have to find two non-negative real numbers a and b such that a + b = d and a \cdot b = d.InputThe first line con...
7 69 0 1 4 5 999 1000
Y 67.985071301 1.014928699 Y 0.000000000 0.000000000 N Y 2.000000000 2.000000000 Y 3.618033989 1.381966011 Y 997.998996990 1.001003010 Y 998.998997995 1.001002005
1 second
256 megabytes
['binary search', 'math', '*1300']
B. Divisor Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer number n. The following algorithm is applied to it: if n = 0, then end algorithm; find the smallest prime divisor d of n; subtract d from n and go to step 1. Determine ...
5
1
2 seconds
256 megabytes
['implementation', 'math', 'number theory', '*1200']
A. Minimizing the Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of n lowercase Latin letters.You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexico...
3 aaa
aa
1 second
256 megabytes
['greedy', 'strings', '*1200']
B. Taxi drivers and Lyfttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPalo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.Lyft has become so popular so that it is now used by all m taxi drivers in t...
Input3 11 2 3 100 0 1 0
Output3
1 second
256 megabytes
['implementation', 'sortings', '*1200']
A. The King's Racetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, y...
Input42 3
OutputWhite
1 second
256 megabytes
['implementation', 'math', '*800']
G. Yet Another LCP Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet \text{LCP}(s, t) be the length of the longest common prefix of strings s and t. Also let s[x \dots y] be the substring of s from index x to index y (inclusive). For example, if s = "abcde...
Input7 4abacaba2 21 21 23 11 2 371 711 2 3 4 5 6 72 21 51 5
Output1321216
2 seconds
256 megabytes
['data structures', 'string suffix structures', '*2600']
F. Choosing Two Pathstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected unweighted tree consisting of n vertices.An undirected tree is a connected undirected graph with n - 1 edges.Your task is to choose two pairs of vertices of this tree (a...
Input71 41 51 62 32 44 7
Output3 67 5
2 seconds
256 megabytes
['dfs and similar', 'dp', 'greedy', 'trees', '*2500']
E. Segment Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers l and r (l \le r). Your task is to calculate the sum of numbers from l to r (including l and r) such that each number contains at most k different digits, and print this sum modu...
Input10 50 2
Output1230
1 second
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'math', '*2300']
D. Berland Fairtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXXI Berland Annual Fair is coming really soon! Traditionally fair consists of n booths, arranged in a circle. The booths are numbered 1 through n clockwise with n being adjacent to 1. The i-th booths sel...
Input3 385 2 5
Output10
2 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'greedy', '*1700']
C. Vasya and Robottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0, 0). Robot can perform the following four kinds of operations: U — move from (x, y) to (x, y + 1); D ...
Input5RURUU-2 3
Output3
1 second
256 megabytes
['binary search', 'two pointers', '*1800']
B. Vasya and Bookstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one — a_2, and so on. The book at the bottom of the stack has number a_n. All numbers are dis...
Input31 2 32 1 3
Output2 0 1
1 second
256 megabytes
['implementation', 'math', '*1000']
A. Diverse Substringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s, consisting of n lowercase Latin letters.A substring of string s is a continuous segment of letters from s. For example, "defor" is a substring of "codeforces" and "fors" is ...
Input10codeforces
OutputYEScode
1 second
256 megabytes
['implementation', 'strings', '*1000']
E. Rain Protectiontime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA lot of people dream of convertibles (also often called cabriolets). Some of convertibles, however, don't have roof at all, and are vulnerable to rain. This is why Melon Ask, the famous inventor, dec...
Input3 5 50 01 1 42 2 43 3 4
Output1.0000000019
7 seconds
256 megabytes
['binary search', 'geometry', '*3500']
M. Algoland and Berlandtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputOnce upon a time Algoland and Berland were a single country, but those times are long gone. Now they are two different countries, but their cities are scattered on a common territory.All cities a...
Input22 31 1 20 01 11 23 24 01 110 00 1
OutputYES2 21 23 23 1YES1 1
5 seconds
512 megabytes
['constructive algorithms', 'divide and conquer', 'geometry', '*3000']
L. Odd Federalizationtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them.The president o...
Input2 5 31 22 51 5 6 51 22 33 44 24 1
Output11 1 1 1 1 22 1 1 1 1 1
5 seconds
256 megabytes
['constructive algorithms', '*2600']
K. Video Poststime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th vide...
Input6 33 3 1 4 1 6
OutputYes2 3 1
3 seconds
256 megabytes
['implementation', '*1100']
J. Streets and Avenues in Berhattantime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerhattan is the capital of Berland. There are n streets running parallel in the east-west direction (horizontally), and there are m avenues running parallel in the south-north direct...
Input22 3 9EEZZEEZZZ2 7 9EEZZEEZZZ
Output04
3 seconds
256 megabytes
['dp', '*2300']
I. Privatization of Roads in Berlandtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities and m two-way roads in Berland, each road connecting two distinct cities.Recently the Berland government has made a tough decision to transfer ownership of the roa...
Input33 3 21 22 33 14 5 21 21 31 42 32 44 6 21 21 31 42 32 43 4
Output1 2 3 2 1 1 2 3 0 0 0 0 0 0
3 seconds
256 megabytes
['flows', 'graph matchings', 'graphs', '*2400']
H. BerOS File Suggestiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature.There are n files on hard drive and their names are f_1, f_2, \do...
Input4testconteststest..test6ts.st..testcontes.st
Output1 contests2 .test1 test.1 .test0 -4 test.
3 seconds
256 megabytes
['brute force', 'implementation', '*1500']
G. Monsters and Potionstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is an introvert person. In fact he is so much of an introvert that he plays "Monsters and Potions" board game alone. The board of the game is a row of n cells. The cells are numbered fro...
Input8 38 21 34 90 3 -5 0 -5 -4 -1 0
Output63 1 2
3 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'implementation', '*2300']
F. Debatetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputElections in Berland are coming. There are only two candidates — Alice and Bob.The main Berland TV channel plans to show political debates. There are n people who want to take part in the debate as a spectator...
Input611 610 401 300 300 700 9
Output22
3 seconds
256 megabytes
['greedy', '*1500']
E. Getting Deals Donetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has a lot of work to do. Recently he has learned a new time management rule: "if a task takes five minutes or less, do it immediately". Polycarp likes the new rule, however he is not sure ...
Input45 2 165 6 1 4 75 3 305 6 1 4 76 4 1512 5 15 7 20 171 1 50100
Output3 54 72 100 25
3 seconds
256 megabytes
['binary search', 'data structures', '*2100']
D. Garbage Disposaltime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEnough 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 nex...
Input3 23 2 1
Output3
3 seconds
256 megabytes
['greedy', '*1300']
C. Cloud Computingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBuber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the clou...
Input5 7 31 4 5 31 3 5 22 5 10 1
Output44
3 seconds
256 megabytes
['data structures', 'greedy', '*2000']
B. Berkomnadzortime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerkomnadzor — Federal Service for Supervision of Communications, Information Technology and Mass Media — is a Berland federal executive body that protects ordinary residents of Berland from the threats ...
Input1-149.154.167.99
Output10.0.0.0/0
3 seconds
256 megabytes
['data structures', 'greedy', '*2400']