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
A. Find a Numbertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integers d and s. Find minimal positive integer n which is divisible by d and has sum of digits equal to s.InputThe first line contains two positive integers d and s (1 \le d ...
Input13 50
Output699998
3 seconds
256 megabytes
['dp', 'graphs', 'number theory', 'shortest paths', '*2200']
C. Colored Rookstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan is a novice painter. He has n dyes of different colors. He also knows exactly m pairs of colors which harmonize with each other.Ivan also enjoy playing chess. He has 5000 rooks. He wants to take k r...
Input3 21 22 3
Output23 41 441 22 22 45 415 1
1 second
256 megabytes
['constructive algorithms', 'graphs', '*1700']
B. LCMtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes \frac{[a, \,\, b]}{a} on blackboard. Here [a, \,\, b] stands for least common multiple of a and b. Ivan is very lazy...
Input1
Output1
1 second
256 megabytes
['math', 'number theory', '*1200']
A. Birthdaytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three t...
Input20 15 2 3
Output1
1 second
256 megabytes
['math', '*1400']
E. Random Forest Ranktime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's define rank of undirected graph as rank of its adjacency matrix in \mathbb{R}^{n \times n}.Given a tree. Each edge of this tree will be deleted with probability 1/2, all these deletions are i...
Input31 22 3
Output6
3 seconds
512 megabytes
['dp', 'graph matchings', 'math', 'trees', '*2800']
D. Computer Gametime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan plays some computer game. There are n quests in the game. Each quest can be upgraded once, this increases the reward for its completion. Each quest has 3 parameters a_{i}, b_{i}, p_{i}: reward for ...
Input3 23 1000 0.51 2 0.483 20 0.3
Output252.2500000000000
3 seconds
256 megabytes
['dp', 'greedy', 'math', 'probabilities', '*3100']
C. Knightstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until ther...
Input4
Output1 13 11 54 4
1 second
256 megabytes
['constructive algorithms', '*2600']
B. Multihedgehogtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSomeone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan t...
Input14 21 42 43 44 1310 511 512 514 55 136 78 613 69 6
OutputYes
1 second
256 megabytes
['dfs and similar', 'graphs', 'shortest paths', '*1800']
A. Array Without Local Maximums time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIvan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all el...
Input31 -1 2
Output1
2 seconds
512 megabytes
['dp', '*1900']
F. Yet another 2D Walkingtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaksim 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...
Input82 21 42 33 13 41 14 31 2
Output15
4 seconds
256 megabytes
['dp', '*2100']
E. Binary Numbers AND Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two huge binary integer numbers a and b of lengths n and m respectively. You will repeat the following process: if b > 0, then add to the answer the value a~ \&~ b and divide b by ...
Input4 410101101
Output12
1 second
256 megabytes
['data structures', 'implementation', 'math', '*1700']
D. Boxes Packingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaksim has n objects and m boxes, each box has size exactly k. Objects are numbered from 1 to n in order from left to right, the size of the i-th object is a_i.Maksim wants to pack his objects into the b...
Input5 2 65 2 1 4 2
Output4
1 second
256 megabytes
['binary search', 'implementation', '*1800']
C. Books Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have got a shelf and want to put some books on it.You are given q queries of three types: L id — put a book having index id on the shelf to the left from the leftmost existing book; R id — put a b...
Input8L 1R 2R 3? 2L 4? 1L 5? 1
Output112
2 seconds
256 megabytes
['implementation', '*1400']
B. Heaterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova's house is an array consisting of n elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The i-th element of the array i...
Input6 20 1 1 0 0 1
Output3
1 second
256 megabytes
['greedy', 'two pointers', '*1500']
A. Vova and Traintime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the ...
Input410 2 3 7100 51 51 511234 1 100 1991000000000 1 1 1000000000
Output3011340
1 second
256 megabytes
['math', '*1100']
G. Fibonacci Suffixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote (yet again) the sequence of Fibonacci strings:F(0) = 0, F(1) = 1, F(i) = F(i - 2) + F(i - 1), where the plus sign denotes the concatenation of two strings.Let's denote the lexicographic...
Input4 5 3
Output110
1 second
256 megabytes
['strings', '*2700']
F. Up and Down the Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree with n vertices; its root is vertex 1. Also there is a token, initially placed in the root. You can move the token to other vertices. Let's assume current vertex of token is ...
Input7 11 1 3 3 4 4
Output4
3 seconds
256 megabytes
['dfs and similar', 'dp', 'trees', '*2500']
E. Side Transmutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider some set of distinct characters A and some string S, consisting of exactly n characters, where each character is present in A.You are given an array of m integers b (b_1 < b_2 < \dots < b...
Input3 1 21
Output6
2 seconds
256 megabytes
['combinatorics', 'strings', '*2300']
D. Three Piecestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily 8 \times 8, but it still is N \times N. Each square has some number written on it, all the numbers are from ...
Input31 9 38 6 74 2 5
Output12 1
2 seconds
256 megabytes
['dfs and similar', 'dp', 'shortest paths', '*2200']
C. Make It Equaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i.Let's define operation slice on so...
Input5 53 1 2 2 4
Output2
2 seconds
256 megabytes
['greedy', '*1600']
B. Vasya and Isolated Verticestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has got an undirected graph consisting of n vertices and m edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Mult...
Input4 2
Output0 1
1 second
256 megabytes
['constructive algorithms', 'graphs', '*1300']
A. Vasya and Chocolatetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a special offer in Vasya's favourite supermarket: if the customer buys a chocolate bars, he or she may take b additional bars for free. This special offer can be used any number of times.V...
Input210 3 1 11000000000 1 1000000000 1
Output131000000001000000000
1 second
256 megabytes
['implementation', 'math', '*800']
B. Equations of Mathematical Magictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputColossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.Arkadi and Boris Strugatsky. Monday starts on SaturdayReading the book "Equations of Mathematical...
Input3021073741823
Output121073741824
1 second
256 megabytes
['math', '*1200']
A. Make a triangle!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.Wh...
Input3 4 5
Output0
2 seconds
256 megabytes
['brute force', 'geometry', 'math', '*800']
F. String Journeytime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWe call a sequence of strings t1, ..., tk a journey of length k, if for each i > 1 ti is a substring of ti - 1 and length of ti is strictly less than length of ti - 1. For example, {ab, b} is a journey...
Input7abcdbcc
Output3
5 seconds
512 megabytes
['data structures', 'dp', 'string suffix structures', '*3300']
E. Lasers and Mirrorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOleg came to see the maze of mirrors. The maze is a n by n room in which each cell is either empty or contains a mirror connecting opposite corners of this cell. Mirrors in this maze reflect light i...
Input44 1 3 2
Output3.\..\\../../...\
1 second
256 megabytes
['constructive algorithms', 'math', '*3000']
D. Candies for Childrentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt the children's festival, children were dancing in a circle. When music stopped playing, the children were still standing in a circle. Then Lena remembered, that her parents gave her a candy box...
Input4 1 4 12
Output2
1 second
256 megabytes
['brute force', 'math', '*2600']
C. Dwarves, Hats and Extrasensory Abilitiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.In good old times dwarves tried to develop extrasensory abilities: Exactly n dwarves entered completely dark cave. Each dwarf received a hat —...
Input5blackblackwhitewhiteblack
Output0 03 12 34 40 21 3 4 1
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'geometry', 'interactive', '*1900']
B. Labyrinthtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is i...
Input4 53 21 2......***....***....
Output10
2 seconds
512 megabytes
['graphs', 'shortest paths', '*1800']
A. Oh Those Palindromestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "x...
Input5oolol
Outputololo
2 seconds
256 megabytes
['constructive algorithms', 'strings', '*1300']
F. Upgrading Citiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in the kingdom X, numbered from 1 through n. People travel between cities by some one-way roads. As a passenger, JATC finds it weird that from any city u, he can't start a trip in ...
Input7 71 22 33 44 72 55 46 4
Output4
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*2900']
E. Companytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe company X has n employees numbered from 1 through n. Each employee u has a direct boss p_u (1 \le p_u \le n), except for the employee 1 who has no boss. It is guaranteed, that values p_i form a tree. Empl...
Input11 51 1 3 3 3 4 2 7 7 64 64 81 119 118 11
Output4 18 11 011 38 1
2 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'greedy', 'trees', '*2300']
D. Fun with Integerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 \le |a|, |b| \le n), you can transform a into b if and only if there exists an integer x such that 1 <...
Input4
Output8
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'implementation', 'math', '*1800']
C. Banh-mitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.First, he sp...
Input4 210111 43 4
Output143
1 second
256 megabytes
['greedy', 'implementation', 'math', '*1600']
B. Mathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more t...
Input20
Output10 2
1 second
256 megabytes
['greedy', 'math', 'number theory', '*1500']
A. A Pranktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a_1, a_2, ..., a_n of integers, such that 1 \le a_1 < a_2 < \ldots < a_n \le 10^3, and ...
Input61 3 4 5 6 9
Output2
1 second
256 megabytes
['greedy', 'implementation', '*1300']
F. Lost Roottime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe graph is called tree if it is connected and has no cycles. Suppose the tree is rooted at some vertex. Then tree is called to be perfect k-ary tree if each vertex is either a leaf (has no children) or ha...
Input3 2NoYes
Output? 1 3 2? 1 2 3! 2
3 seconds
256 megabytes
['interactive', 'probabilities', '*2400']
E. Politicstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in the country. Two candidates are fighting for the post of the President. The elections are set in the future, and both candidates have already planned how they are going to connect the c...
Input4 1 21 2 3 41 21 33 41 22 31 421 34 112 3
Output9
4 seconds
256 megabytes
['flows', 'graphs', '*2600']
D. TV Showstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The i-th of the shows is going from l_i-th to r_i-th minute, both ends inclusive.You need a TV to wa...
Input5 4 31 24 102 410 115 9
Output60
2 seconds
256 megabytes
['data structures', 'greedy', 'implementation', 'sortings', '*2000']
C. Multiplicitytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer array a_1, a_2, \ldots, a_n.The array b is called to be a subsequence of a if it is possible to remove some elements from a to get b.Array b_1, b_2, \ldots, b_k is called to be g...
Input21 2
Output3
3 seconds
256 megabytes
['data structures', 'dp', 'implementation', 'math', 'number theory', '*1700']
B. Views Mattertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou came to the exhibition and one exhibit has drawn your attention. It consists of n stacks of blocks, where the i-th stack consists of a_i blocks resting on the surface.The height of the exhibit is equ...
Input5 63 3 3 3 3
Output10
2 seconds
256 megabytes
['greedy', 'implementation', 'sortings', '*1400']
A. Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have unlimited number of coins with values 1, 2, \ldots, n. You want to select some set of coins having the total value of S. It is allowed to have multiple coins with the same value in the set. What is the...
Input5 11
Output3
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*800']
G. Balls and Pocketstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a strip with an infinite number of cells. Cells are numbered starting with 0. Initially the cell i contains a ball with the number i.There are n pockets located at cells a_1, \ldots, a_n. E...
Input3 151 3 40 01 02 03 04 00 11 12 13 14 10 21 22 23 24 2
Output0123402567058910
2 seconds
512 megabytes
['data structures', '*3400']
F. Shrinking Treetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider 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 r...
Input41 21 31 4
Output0.12500000000.29166666670.29166666670.2916666667
2 seconds
512 megabytes
['combinatorics', 'dp', '*2900']
E. Sergey and Subwaytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been...
Input41 21 31 4
Output6
2 seconds
512 megabytes
['dfs and similar', 'dp', 'trees', '*2000']
D. Social Circlestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou invited n guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. Your guests h...
Input31 11 11 1
Output6
2 seconds
512 megabytes
['greedy', 'math', '*1900']
C. Maximum Subrectangletime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given two arrays a and b of positive integers, with length n and m respectively. Let c be an n \times m matrix, where c_{i,j} = a_i \cdot b_j. You need to find a subrectangle of the matri...
Input3 31 2 31 2 39
Output4
2 seconds
512 megabytes
['binary search', 'implementation', 'two pointers', '*1600']
B. Maximum Sum of Digitstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a positive integer n.Let S(x) be sum of digits in base 10 representation of x, for example, S(123) = 1 + 2 + 3 = 6, S(0) = 0.Your task is to find two integers a, b, such that 0 \le...
Input35
Output17
2 seconds
512 megabytes
['greedy', '*1100']
A. Phone Numberstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.For example, "80123456789" and "80000000000" are phone numbers, while "80...
Input1100000000008
Output1
2 seconds
512 megabytes
['brute force', '*800']
E. Split the Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree on n vertices, its root is the vertex number 1. The i-th vertex contains a number w_i. Split it into the minimum possible number of vertical paths in such a way that each pa...
Input3 1 31 2 31 1
Output3
2 seconds
256 megabytes
['binary search', 'data structures', 'dp', 'greedy', 'trees', '*2400']
D. Nature Reservetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a forest that we model as a plane and live n rare animals. Animal number i has its lair in the point (x_{i}, y_{i}). In order to protect them, a decision to build a nature reserve has been mad...
Input10 1
Output0.5
2 seconds
256 megabytes
['binary search', 'geometry', 'ternary search', '*2200']
C. Sequence Transformationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call the following process a transformation of a sequence of length n.If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements ...
Input3
Output1 1 3
2 seconds
256 megabytes
['constructive algorithms', 'math', '*1600']
B. Forgerytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudent Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey d...
Input3 3####.####
OutputYES
2 seconds
256 megabytes
['implementation', '*1300']
A. Cashiertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning ...
Input2 11 30 11 1
Output3
2 seconds
256 megabytes
['implementation', '*1000']
C. Tanya and Colored Candiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from 1 to n. The i-th box contains r_i candies, candies have the color c_i (the color ...
Input5 3 101 2 3 4 5RGBRR
Output4
2 seconds
256 megabytes
['*special problem', 'dp', '*2000']
B. DDoStime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe get more and more news about DDoS-attacks of popular websites.Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds 100 \cdot...
Input5100 200 1 1 1
Output3
2 seconds
256 megabytes
['*special problem', 'brute force', '*1400']
A. Bmail Computer Networktime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one...
Input81 1 2 2 3 2 5
Output1 2 5 8
4 seconds
256 megabytes
['*special problem', 'dfs and similar', 'trees', '*900']
H. Detect Robotstime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou successfully found poor Arkady near the exit of the station you've perfectly predicted. You sent him home on a taxi and suddenly came up with a question.There are n crossroads in your city and sever...
1 5 2 4 1 2 3 5 3 1 4 3
Human
1 second
1024 megabytes
['data structures', 'strings', '*3200']
G. Take Metrotime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputHaving problems with tram routes in the morning, Arkady decided to return home by metro. Fortunately for Arkady, there is only one metro line in the city.Unfortunately for Arkady, the line is circular. It...
10 4 3 1
4
2 seconds
1024 megabytes
['brute force', 'data structures', 'graphs', '*2900']
F. Write The Contesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two ...
Input241.000 31.00012 320 630 15 131.000 30.0001 1010 1020 8
Output720
2 seconds
256 megabytes
['binary search', 'dp', 'math', '*2500']
E. Check Transcriptiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal s towards a faraway galaxy. Recently they've received a response t which they believe to ...
01 aaaaaa
4
3 seconds
256 megabytes
['brute force', 'data structures', 'hashing', 'strings', '*2100']
D. Decorate Apple Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branche...
3 1 1
1 1 2
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'dp', 'graphs', 'greedy', 'sortings', 'trees', '*1600']
C. Pick Heroestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDon't you tell me what you think that I can beIf you say that Arkady is a bit old-fashioned playing checkers, you won't be right. There is also a modern computer game Arkady and his friends are keen on. We...
3 1 1 2 3 4 5 6 2 6 1 2 4 1
6 5 3
1 second
256 megabytes
['greedy', 'implementation', 'interactive', 'sortings', '*1700']
B. Divide Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady and his friends love playing checkers on an n \times n field. The rows and the columns of the field are enumerated from 1 to n.The friends have recently won a championship, so Arkady wants to ple...
3 3
1
1 second
256 megabytes
['math', 'number theory', '*1600']
A. Determine Linetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he re...
3 3 1 4 6 2 1 4 5 10 5 6 4 1
1 4
1 second
256 megabytes
['implementation', '*800']
G. Jellyfish Nightmaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob has put on some weight recently. In order to lose weight a bit, Bob has decided to swim regularly in the pool. However, the day before he went to the pool for the first time he had a weird dre...
Input4 40 02 02 20 231 1 13 5 11 9 1
Output0
2 seconds
256 megabytes
['*3500']
F. Tree and XORtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a connected undirected graph without cycles (that is, a tree) of n vertices, moreover, there is a non-negative integer written on every edge.Consider all pairs of vertices (v, u) (that is, ...
Input2 11 3
Output0
4 seconds
256 megabytes
['strings', 'trees', '*2900']
E. Segments on the Linetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a given a list of integers a_1, a_2, \ldots, a_n and s of its segments [l_j; r_j] (where 1 \le l_j \le r_j \le n).You need to select exactly m segments in such a way that the k-th order s...
Input4 3 2 23 1 3 21 22 34 4
Output2
2 seconds
256 megabytes
['binary search', 'dp', '*2500']
D. Refactoringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice has written a program and now tries to improve its readability. One of the ways to improve readability is to give sensible names to the variables, so now Alice wants to rename some variables in her p...
Input1topforcescodecoder
OutputYEStopforcescodecoder
1 second
256 megabytes
['greedy', 'implementation', 'strings', '*2400']
C. Lucky Daystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob and Alice are often participating in various programming competitions. Like many competitive programmers, Alice and Bob have good and bad days. They noticed, that their lucky and unlucky days are repeat...
Input0 2 51 3 5
Output2
1 second
256 megabytes
['math', 'number theory', '*1900']
B. Alice and Hairdressertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...To prevent this, Alice decided to go to the hairdresser. She wants ...
Input4 7 31 2 3 401 2 301 1 301 3 10
Output1221
1 second
256 megabytes
['dsu', 'implementation', '*1300']
A. Metrotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice 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 ...
Input5 31 1 1 1 11 1 1 1 1
OutputYES
1 second
256 megabytes
['graphs', '*900']
H. Epic Convolutiontime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two arrays a_0, a_1, \ldots, a_{n - 1} and b_0, b_1, \ldots, b_{m-1}, and an integer c.Compute the following sum:\sum_{i=0}^{n-1} \sum_{j=0}^{m-1} a_i b_j c^{i^2\,j^3}Since it's value c...
Input2 2 30 10 1
Output3
4 seconds
256 megabytes
['chinese remainder theorem', 'fft', 'math', 'number theory', '*3500']
G. New Road Networktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe king of some country N decided to completely rebuild the road network. There are n people living in the country, they are enumerated from 1 to n. It is possible to construct a road between the ho...
Input24 30011111001113 3011101110
OutputYES1 32 33 4NO
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'math', '*3300']
F. Electric Schemetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha is a young technician, nevertheless, he has already got a huge goal: to assemble a PC. The first task he has to become familiar with is to assemble an electric scheme.The scheme Pasha assembled y...
Input42 22 44 24 4
Output25 2 1 21 4 5 422 1 2 54 5 4 1
1 second
256 megabytes
['flows', 'graph matchings', '*2700']
E. Chips Puzzletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEgor came up with a new chips puzzle and suggests you to play.The puzzle has the form of a table with n rows and m columns, each cell can contain several black or white chips placed in a row. Thus, the st...
Input2 200 1001 1110 0110 01
Output42 1 1 11 1 1 21 2 2 22 2 2 1
1 second
256 megabytes
['constructive algorithms', 'implementation', 'math', '*2400']
D. Changing Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, \ldots, a_n on the board. An integer x is called a k-bit integer if 0 \leq x \leq 2^k - 1. Of course, Vanya was not able...
Input3 21 3 0
Output5
1 second
256 megabytes
['greedy', 'implementation', '*1900']
C. Candies Distributiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n children numbered from 1 to n in a kindergarten. Kindergarten teacher gave a_i (1 \leq a_i \leq n) candies to the i-th child. Children were seated in a row in order from 1 to n from le...
Input50 0 1 1 22 0 1 0 0
OutputYES1 3 1 2 1
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1500']
B. Appending Mextime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInitially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of i...
Input40 1 2 1
Output-1
1 second
256 megabytes
['implementation', '*1000']
A. Elevator or Stairs?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on ...
Input5 1 4 4 2 1
OutputYES
1 second
256 megabytes
['implementation', '*800']
E. Euler tourtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEuler is a little, cute squirrel. When the autumn comes, he collects some reserves for winter. The interesting fact is that Euler likes to collect acorns in a specific way. A tree can be described as n aco...
Input21 0 0
Outputyes1 2 1
2 seconds
256 megabytes
['constructive algorithms', 'trees', '*3500']
G. Distinctificationtime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSuppose you are given a sequence S of k pairs of integers (a_1, b_1), (a_2, b_2), \dots, (a_k, b_k).You can perform the following operations on it: Choose some position i and increase a_i by 1. Tha...
Input51 13 35 54 22 4
Output000-5-16
6 seconds
512 megabytes
['data structures', 'dsu', 'greedy', '*2900']
F. The Shortest Statementtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a weighed undirected connected graph, consisting of n vertices and m edges.You should answer q queries, the i-th query is to find the shortest distance between vertices u_i and v_...
Input3 31 2 32 3 13 1 531 21 32 3
Output341
4 seconds
256 megabytes
['graphs', 'shortest paths', 'trees', '*2400']
E. Vasya and Big Integerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya owns three big integers — a, l, r. Let's define a partition of x such a sequence of strings s_1, s_2, \dots, s_k that s_1 + s_2 + \dots + s_k = x, where + is a concatanation of strings. s_...
Input135115
Output2
1 second
256 megabytes
['binary search', 'data structures', 'dp', 'hashing', 'strings', '*2600']
D. Bicoloringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a grid, consisting of 2 rows and n columns. Each cell of this grid should be colored either black or white.Two cells are considered neighbours if they have a common border and share the same...
Input3 4
Output12
2 seconds
256 megabytes
['bitmasks', 'dp', '*1700']
C. Vasya and Multisetstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice number...
Input43 5 7 1
OutputYESBABA
1 second
256 megabytes
['brute force', 'dp', 'greedy', 'implementation', 'math', '*1500']
B. Relatively Prime Pairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of all integers from l to r inclusive, l < r, (r - l + 1) \le 3 \cdot 10^5 and (r - l) is always odd.You want to split these numbers into exactly \frac{r - l + 1}{2} pairs i...
Input1 8
OutputYES2 74 13 86 5
2 seconds
256 megabytes
['greedy', 'math', 'number theory', '*1000']
A. Vasya And Passwordtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.But since EatForces...
Input2abcDCEhtQw27
OutputabcD4EhtQw27
1 second
256 megabytes
['greedy', 'implementation', 'strings', '*1200']
B. Cover Pointstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n points on the plane, (x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n).You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies in...
Input31 11 22 1
Output3
1 second
256 megabytes
['geometry', 'math', '*900']
A. Little C Loves 3 Itime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle C loves number «3» very much. He loves all things about it.Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is...
Input3
Output1 1 1
1 second
256 megabytes
['math', '*800']
I. Say Hellotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo friends are travelling through Bubble galaxy. They say "Hello!" via signals to each other if their distance is smaller or equal than d_1 and it's the first time they speak to each other or at some p...
Input42 50 0 0 105 5 5 65 0 10 514 7 10 5
Output2
2 seconds
256 megabytes
['geometry', '*2300']
F. Splitting moneytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal curren...
Input313 7 66 2
Output4
1 second
256 megabytes
['implementation', '*1400']
C. Space Formulatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFormula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race.Given the current ranking in the competition and points distrib...
Input4 350 30 20 1015 10 7 3
Output2
1 second
256 megabytes
['greedy', '*1400']
J. Moonwalk challengetime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince astronauts from BubbleCup XI mission finished their mission on the Moon and are big fans of famous singer, they decided to spend some fun time before returning to the Earth and hence created ...
Input62 3 g3 4 n5 3 o6 1 n1 2 d71 6 n6 4 dg6 4 n2 5 og1 2 d6 5 go2 3 g
Output1120111
6 seconds
256 megabytes
['data structures', 'strings', 'trees', '*2600']
I. Palindrome Pairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter learning a lot about space exploration, a little girl named Ana wants to change the subject.Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has ...
Input3aabbcd
Output1
2 seconds
256 megabytes
['hashing', 'strings', '*1600']
H. Self-explorationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBeing bored of exploring the Moon over and over again Wall-B decided to explore something he is made of — binary numbers. He took a binary number and decided to count how many times different substrin...
Input1010010011
Output1
1 second
256 megabytes
['math', '*2400']
G. AI robotstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three...
Input3 23 6 17 3 1010 5 8
Output1
2 seconds
256 megabytes
['data structures', '*2200']
F. Shady Ladytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAni and Borna are playing a short game on a two-variable polynomial. It's a special kind of a polynomial: the monomials are fixed, but all of its coefficients are fill-in-the-blanks dashes, e.g. \_ xy + \_...
Input31 12 00 2
OutputAni
1 second
256 megabytes
['geometry', 'math', '*3400']
E. Ancient civilizationstime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn the surface of a newly discovered planet, which we model by a plane, explorers found remains of two different civilizations in various locations. They would like to learn more about those c...
Input50 0 11 0 00 1 01 1 13 2 0
Output31 44 23 0
0.5 seconds
256 megabytes
['constructive algorithms', 'geometry', '*3200']
D. Interstellar battletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N-1 wormholes. The wormholes are of extreme religious importanc...
Input50.50 0.29 0.49 0.95 0.832 30 33 42 134 0.661 0.690 0.36
Output1.680401.484401.61740
1 second
256 megabytes
['math', 'probabilities', 'trees', '*2200']