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
C. Yet Another Broken Keyboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Norge found a string s = s_1 s_2 \ldots s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s...
7 2 abacaba a b
12
2 seconds
256 megabytes
['combinatorics', 'dp', 'implementation', '*1200']
B. Snow Walking Robottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently you have bought a snow walking robot and brought it home. Suppose your home is a cell (0, 0) on an infinite grid.You also have the sequence of instructions of this robot. It is written as ...
6 LRU DURLDRUDRULRDURDDL LRUDDLRUDRUL LLLLRRRR URDUR LLL
2 LR 14 RUURDDDDLLLUUR 12 ULDDDRRRUULL 2 LR 2 UD 0
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*1200']
A. Three Friendstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThree friends are going to meet each other. Initially, the first friend stays at the position x = a, the second friend stays at the position x = b and the third friend stays at the position x = c on the ...
8 3 3 4 10 20 30 5 5 5 2 4 3 1 1000000000 1000000000 1 1000000000 999999999 3 2 5 3 2 6
0 36 0 0 1999999994 1999999994 2 4
1 second
256 megabytes
['brute force', 'greedy', 'math', 'sortings', '*900']
F. Divide The Studentstime limit per test8 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRecently a lot of students were enrolled in Berland State University. All students were divided into groups according to their education program. Some groups turned out to be too large to attend l...
3 9 4 13 1 10 3 1 2 3 4 5 6 7 9 4 13 1 10 3 2 1 3 4 5 6 7 1 2 3 4 5 6 0 0 0 0 0 0 0
1 1 3 4 2 0 7 -1 0 0 0 0 0 0 0
8 seconds
512 megabytes
['brute force', '*2700']
E. Common Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt first, let's define function f(x) as follows: \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matri...
11 3
5
2 seconds
256 megabytes
['binary search', 'combinatorics', 'dp', 'math', '*2100']
D. Portalstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer n castles of your opponent.Let's describe the game process in det...
4 3 7 7 4 17 3 0 8 11 2 0 13 3 5 3 1 2 1 4 3
5
2 seconds
256 megabytes
['data structures', 'dp', 'greedy', 'implementation', 'sortings', '*2100']
C. Shawarma Tenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbou...
4 3 2 1 3 4 2 5 1 4 1
3 4 2
1 second
256 megabytes
['brute force', 'geometry', 'greedy', 'implementation', '*1300']
B. Blockstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blo...
8 BWWWWWWB
3 6 2 4
2 seconds
256 megabytes
['greedy', 'math', '*1300']
A. Suitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.The store does not sell single clothing items — instead, it sells suits of t...
4 5 6 3 1 2
6
1 second
256 megabytes
['brute force', 'greedy', 'math', '*800']
I. Xor on Figurestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is given an integer k and a grid 2^k \times 2^k with some numbers written in its cells, cell (i, j) initially contains number a_{ij}. Grid is considered to be a torus, that is, the cell to the ri...
2 5 5 5 5 2 6 2 3 0 0 2 0 0 0 0 0 5 1 1 1 2 1 3 1 4 2 4
3
5 seconds
256 megabytes
['constructive algorithms', 'fft', 'math', '*3500']
H. Number of Componentstime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose that we have an array of n distinct numbers a_1, a_2, \dots, a_n. Let's build a graph on n vertices as follows: for every pair of vertices i < j let's connect i and j with an edge, if a_i...
5 3 50 40 30 20 10 1 25 3 45 1 48
3 3 4
8 seconds
256 megabytes
['data structures', '*3300']
G. Subset with Zero Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n integers a_1, a_2, \dots, a_n, such that for each 1\le i \le n holds i-n\le a_i\le i-1.Find some nonempty subset of these integers, whose sum is equal to 0. It can be shown that s...
2 5 0 1 2 3 4 4 -3 1 1 1
1 1 4 1 4 3 2
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'math', '*2700']
F. Awesome Substringstime limit per test8 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's call a binary string s awesome, if it has at least 1 symbol 1 and length of the string is divisible by the number of 1 in it. In particular, 1, 1010, 111 are awesome, but 0, 110, 01010 aren't...
111
6
8 seconds
512 megabytes
['math', 'strings', '*2600']
E. Divide Pointstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of n\ge 2 pairwise different points with integer coordinates. Your task is to partition these points into two nonempty groups A and B, such that the following condition holds:For ever...
3 0 0 0 1 1 0
1 1
1 second
256 megabytes
['constructive algorithms', 'geometry', 'math', '*2300']
D. Strange Devicetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is interactive.We have hidden an array a of n pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you jus...
4 3 4 9 4 9 4 9 1 2
? 2 3 4 ? 1 3 4 ? 1 2 4 ? 1 2 3 ! 3
1 second
256 megabytes
['constructive algorithms', 'interactive', 'math', 'sortings', '*1900']
C. Make Goodtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an array a_1, a_2, \dots, a_m of nonnegative integer numbers good if a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m), where \oplus denotes the bitwise XOR operation.For e...
3 4 1 2 3 6 1 8 2 1 1
0 2 4 4 3 2 6 2
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'math', '*1400']
B. Interesting Subarraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor an array a of integers let's denote its maximal element as \max(a), and minimal as \min(a). We will call an array a of k integers interesting if \max(a) - \min(a) \ge k. For example, array [1...
3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020
NO YES 1 4 NO
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'math', '*1200']
A. Card Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo players decided to play one interesting card game.There is a deck of n cards, with values from 1 to n. The values of cards are pairwise different (this means that no two different cards have equal values...
2 2 1 1 2 1 5 2 3 2 3 1 4 5
YES NO
1 second
256 megabytes
['games', 'greedy', 'math', '*800']
B. Modulo Equalitytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive integer m and two integer sequence: a=[a_1, a_2, \ldots, a_n] and b=[b_1, b_2, \ldots, b_n]. Both of these sequence have a length n.Permutation is a sequence of n different po...
4 3 0 0 2 1 2 0 1 1
1
3 seconds
256 megabytes
['brute force', 'sortings', '*1500']
A. Equationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a positive integer composite if it has at least one divisor other than 1 and itself. For example: the following numbers are composite: 1024, 4, 6, 9; the following numbers are not composite: 13,...
1
9 8
3 seconds
256 megabytes
['brute force', 'math', '*800']
E. Happy Cactustime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a cactus graph, in this graph each edge lies on at most one simple cycle.It is given as m edges a_i, b_i, weight of i-th edge is i.Let's call a path in cactus increasing if the weights of e...
3 3 1 2 2 3 3 1
2 2 2
3 seconds
256 megabytes
['dp', '*3400']
D. Invertation in Tournamenttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tournament — complete directed graph.In one operation you can pick any vertex v and change the direction of all edges with v on one of the ends (i.e all edges u \to v change ...
3 010 001 100
0 1
3 seconds
256 megabytes
['brute force', 'divide and conquer', 'graphs', 'math', '*3200']
C. K Integerstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p_1, p_2, \ldots, p_n.In one move you can swap two adjacent values.You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,\ldots, ...
5 5 4 3 2 1
0 1 3 6 10
3 seconds
256 megabytes
['binary search', 'data structures', '*2300']
B. Domino for Youngtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, \ldots, a_n (a_1 \geq a_2 \geq \ldots \geq a_n \geq 1). Young diagram for a=[3,2,2,2,1]. Your goal is ...
5 3 2 2 2 1
4
3 seconds
256 megabytes
['dp', 'greedy', 'math', '*2000']
A. Long Beautiful Integertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer x of n digits a_1, a_2, \ldots, a_n, which make up its decimal notation in order from left to right.Also, you are given a positive integer k < n.Let's call integer b_1,...
3 2 353
3 353
3 seconds
256 megabytes
['constructive algorithms', 'greedy', 'implementation', 'strings', '*1700']
L. Lexicographytime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLucy likes letters. She studied the definition of the lexicographical order at school and plays with it.At first, she tried to construct the lexicographically smallest word out of given letters. It was s...
3 2 2 abcdef
af bc ed
3 seconds
512 megabytes
['constructive algorithms', 'strings', '*1800']
K. Key Storagetime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKarl is developing a key storage service. Each user has a positive integer key.Karl knows that storing keys in plain text is bad practice. So, instead of storing a key, he decided to store a fingerprint o...
3 1 11 123456
0 1 127
3 seconds
512 megabytes
['combinatorics', 'math', '*2100']
J. Just Arrange the Iconstime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBerPhone X is almost ready for release with n applications being preinstalled on the phone. A category of an application characterizes a genre or a theme of this application (like "game", "busi...
3 11 1 5 1 5 1 5 1 1 1 1 5 6 1 2 2 2 2 1 5 4 3 3 1 2
3 3 4
5 seconds
512 megabytes
['greedy', 'implementation', 'math', '*1800']
I. Intriguing Selectiontime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.You are the head coach of a chess club. The club has 2n players, each player has some strength which can be represented by a number, and all those numbers are disti...
2 3 > < > < > > 3 < < < > >
? 1 3 ? 4 2 ? 4 5 ? 6 5 ? 3 4 ? 5 6 ! ? 3 4 ? 4 2 ? 5 3 ? 6 4 ? 3 1 !
5 seconds
512 megabytes
['brute force', 'constructive algorithms', 'implementation', 'interactive', 'sortings', '*2600']
H. Help BerLinetime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVery soon, the new cell phone services provider "BerLine" will begin its work in Berland!The start of customer service is planned along the main street of the capital. There are n base stations that are ...
5 3 1 3 2 3 1 2 3 1 1 10 6 10 4 2 7 9 5 8 3 1 10 2 4 6 9 1 8 10 5 3 7
1 3 2 10 20 10 1 2 3 4 5 3 1 3 5 4 2 1 2 3 4 5 6 7 8 9 10
5 seconds
512 megabytes
['constructive algorithms', '*3200']
G. Game Relicstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputEsports is a form of competitive sports using video games. Dota 2 is one of the most popular competitive video games in Esports. Recently, a new video game Dota 3 was released. In Dota 3 a player can buy ...
2 20 25 100
47.50000000000000000
3 seconds
512 megabytes
['math', 'probabilities', '*3000']
E. Electionstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputByteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one oppo...
5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9
2 3 1
3 seconds
512 megabytes
['greedy', '*1700']
D. DevOps Best Practicestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDaisy is a senior software engineer at RainyDay, LLC. She has just implemented three new features in their product: the first feature makes their product work, the second one makes their product...
3 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 0 1
Possible 1 1 1 2 3 2 1 3
3 seconds
512 megabytes
['constructive algorithms', '*2800']
B. Balls of Bumatime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBalph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left o...
BBWWBB
3
3 seconds
512 megabytes
['*900']
H. Red-Blue Graphtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a directed graph on n vertices numbered 1 through n where each vertex (except n) has two outgoing arcs, red and blue. At any point in time, exactly one of the arcs is active for each vertex. I...
6 2 1 5 5 2 1 6 3 4 3 21 1 BBBBB 1 RBBBB 2 BBBBB 5 BRBBB 3 BRBBR 1 BRRBR 1 RRRBR 2 BRRBR 5 BBRBR 4 BBRBB 3 BBRRB 2 BBBRB 5 BRBRB 3 BRBRR 1 BRRRR 1 RRRRR 2 BRRRR 5 BBRRR 4 BBRRB 2 BRBBB 4 BRBBR
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 -1 -1
4 seconds
512 megabytes
['dp', 'graphs', 'math', 'matrices', 'meet-in-the-middle', '*3400']
G. Permutation Concatenationtime limit per test1 secondmemory 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, 1, 3, 2, 2, 1...
2
8
1 second
256 megabytes
['string suffix structures', '*3300']
F. Almost Same Distancetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v \in W the distance between u and v is either k or k+1.You ar...
5 1 2 1 3 1 4 4 5
4 3 2 1 1
5 seconds
256 megabytes
['dfs and similar', 'graphs', '*2900']
E. Spaceship Solitairetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n typ...
2 2 3 5 2 1 1 2 2 1 1 1 1 2 1 2 2 2 0
4 3 3 2 3
1 second
256 megabytes
['data structures', 'greedy', 'implementation', '*2100']
D. Decreasing Debtstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n people in this world, conveniently numbered 1 through n. They are using burles to buy goods and services. Occasionally, a person might not have enough currency to buy what he wants or nee...
Input3 21 2 102 3 5
Output21 2 51 3 5
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'graphs', 'greedy', 'implementation', 'math', 'two pointers', '*2000']
C. Diverse Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet a be a matrix of size r \times c containing positive integers, not necessarily distinct. Rows of the matrix are numbered from 1 to r, columns are numbered from 1 to c. We can construct an array b co...
2 2
4 12 2 9
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', 'number theory', '*1400']
B. Dice Towertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is playing with 6-sided dice. A net of such standard cube is shown below.He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosin...
4 29 34 19 38
YES YES YES NO
1 second
256 megabytes
['constructive algorithms', 'math', '*1000']
A. Competitive Programmertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they ne...
6 603 006 205 228 1053 0000000000000000000000000000000000000000000000
red red cyan cyan cyan red
1 second
256 megabytes
['chinese remainder theorem', 'math', '*1000']
E. Beautiful Mirrorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCreatnx 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 \frac{p_i}{100} for...
1 50
2
2 seconds
256 megabytes
['data structures', 'dp', 'math', 'probabilities', '*2100']
B. Beautiful Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p=[p_1, p_2, \ldots, p_n] of integers from 1 to n. Let's call the number m (1 \le m \le n) beautiful, if there exists two indices l, r (1 \le l \le r \le n), such that the...
3 6 4 5 1 3 2 6 5 5 3 1 2 4 4 1 4 3 2
101011 11111 1001
1 second
256 megabytes
['data structures', 'implementation', 'math', 'two pointers', '*1300']
A. Beautiful Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.Ahcl wants to construct a ...
3 a???cb a??bbc a?b?c
ababcb -1 acbac
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1000']
F. Beautiful Fibonacci Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe well-known Fibonacci sequence F_0, F_1, F_2,\ldots is defined as follows: F_0 = 0, F_1 = 1. For each i \geq 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence o...
3 1 1
2 1
1 second
256 megabytes
['constructive algorithms', 'number theory', '*3500']
E. Beautiful Leaguetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA football league has recently begun in Beautiful land. There are n teams participating in the league. Let's enumerate them with integers from 1 to n.There will be played exactly \frac{n(n-1)}{2} matc...
3 1 1 2
010 001 100
1 second
256 megabytes
['constructive algorithms', 'flows', 'graph matchings', '*2700']
D2. Beautiful Bracket Sequence (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 \leq n \leq 10^6.Let's define a correct ...
??
1
2 seconds
256 megabytes
['combinatorics', 'probabilities', '*2900']
D1. Beautiful Bracket Sequence (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 \leq n \leq 2000. The hard version of th...
??
1
2 seconds
256 megabytes
['combinatorics', 'dp', 'probabilities', '*2600']
C. Beautiful Mirrors with queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCreatnx 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 \frac{...
2 2 50 50 2 2
4 6
2 seconds
256 megabytes
['data structures', 'probabilities', '*2400']
B. Beautiful Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, \ldots, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for...
2 2 2 1
YES 0 1 0 1 2 3 2
1 second
256 megabytes
['brute force', 'constructive algorithms', 'greedy', '*1900']
A. Beautiful Regional Contesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSo the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problem...
5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11
1 2 3 0 0 0 0 0 0 2 5 3 2 6 6
2 seconds
256 megabytes
['greedy', 'implementation', '*1500']
F. Economic Difficultiestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn electrical grid in Berland palaces consists of 2 grids: main and reserve. Wires in palaces are made of expensive material, so selling some of them would be a good idea!Each grid (main and res...
3 6 4 1 1 4 2 6 5 3 4 1 1 1 3 4 2
5
3 seconds
256 megabytes
['data structures', 'dfs and similar', 'dp', 'flows', 'graphs', 'trees', '*2400']
E. Editortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text.Your editor consists of a line with infinite length and cursor, which points to the curren...
11 (RaRbR)L)L(
-1 -1 -1 -1 -1 -1 1 1 -1 -1 2
1 second
256 megabytes
['data structures', 'implementation', '*2100']
D. Secret Passwordstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and stole a piece of...
4 a b ab d
2
1 second
256 megabytes
['dfs and similar', 'dsu', 'graphs', '*1500']
C. Everyone is a Winner!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn the well-known testing system MathForces, a draw of n rating units is arranged. The rating will be distributed according to the following algorithm: if k participants take part in this event, ...
4 5 11 1 3
4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
1 second
256 megabytes
['binary search', 'math', 'meet-in-the-middle', 'number theory', '*1400']
B. PIN Codestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA PIN code is a string that consists of exactly 4 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.Polycarp has n (2 \le n \le ...
3 2 1234 0600 2 1337 1337 4 3139 3139 3139 3139
0 1234 0600 1 1337 1237 3 3139 3138 3939 6139
1 second
256 megabytes
['greedy', 'implementation', '*1400']
A. Sweet Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are r candies in it, the second pile contains only green candies and there are g candies...
6 1 1 1 1 2 1 4 1 1 7 4 10 8 1 4 8 2 8
1 2 2 10 5 9
1 second
256 megabytes
['math', '*1100']
F. Xor-Settime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two sets of integers: A and B. You need to output the sum of elements in the set C = \{x | x = a \oplus b, a \in A, b \in B\} modulo 998244353, where \oplus denotes the bitwise XOR operation. Ea...
2 3 5 5 8 3 1 2 1 9 2 9
112
2 seconds
256 megabytes
['bitmasks', 'divide and conquer', 'math', '*3100']
F. Colored Treetime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given a tree with n vertices. The color of the i-th vertex is h_{i}.The value of the tree is defined as \sum\limits_{h_{i} = h_{j}, 1 \le i < j \le n}{dis(i,j)}, where dis(i,j) is the number of ...
4 1 1 1 2 1 1 1 2 1 2 1 3 3 4
22
2.5 seconds
256 megabytes
['data structures', 'trees', '*2700']
E. Tournamenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are organizing a boxing tournament, where n boxers will participate (n is a power of 2), and your friend is one of them. All boxers have different strength from 1 to n, and boxer i wins in the match ag...
4 3 9 1 -1
0
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', '*2400']
D. A Game with Trapstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a computer game, where you lead a party of m soldiers. Each soldier is characterised by his agility a_i.The level you are trying to get through can be represented as a straight line ...
5 6 4 14 1 2 3 4 5 1 5 2 1 2 5 2 3 5 3 5 3
3
3 seconds
256 megabytes
['binary search', 'dp', 'greedy', 'sortings', '*1900']
C. Infinite Fencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.You must ...
4 1 1 2 2 10 4 5 2 3 3 2 2
OBEY REBEL OBEY OBEY
2 seconds
256 megabytes
['greedy', 'math', 'number theory', '*1700']
B. Obtain Two Zeroestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers a and b. You may perform any number of operations on them (possibly zero).During each operation you should choose any positive integer x and set a := a - x, b := b - 2x or ...
3 6 9 1 1 1 2
YES NO YES
1 second
256 megabytes
['binary search', 'math', '*1300']
A. Heatingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSeveral days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has n rooms. ...
4 1 10000 10000 1 2 6 4 6
100000000 1 18 10
1 second
256 megabytes
['math', '*1000']
G. Divisor Settime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an integer x represented as a product of n its prime divisors p_1 \cdot p_2, \cdot \ldots \cdot p_n. Let S be the set of all positive integer divisors of x (including 1 and x itself).We call...
3 2999999 43 2999957
3
5 seconds
512 megabytes
['divide and conquer', 'fft', 'greedy', 'math', 'number theory', '*2600']
F. Make Them Similartime limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputLet's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example: 2 and 4 are similar (binary representations are 10 and 100); 1337 and 421...
2 7 2
1
4 seconds
1024 megabytes
['bitmasks', 'brute force', 'hashing', 'meet-in-the-middle', '*2400']
E. The Contesttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA team of three programmers is going to play a contest. The contest consists of n problems, numbered from 1 to n. Each problem is printed on a separate sheet of paper. The participants have decided to div...
2 1 2 3 1 4 2 5
1
2 seconds
512 megabytes
['data structures', 'dp', 'greedy', '*2000']
D. Yet Another Monster Killing Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is ...
2 6 2 3 11 14 1 8 2 3 2 100 1 5 3 5 100 2 3 2 30 5 90 1
5 -1
2 seconds
256 megabytes
['binary search', 'data structures', 'dp', 'greedy', 'sortings', 'two pointers', '*1700']
C. Dominated Subarraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an array t dominated by value v in the next situation.At first, array t should have at least 2 elements. Now, let's calculate number of occurrences of each number num in t and define it ...
4 1 1 6 1 2 3 4 5 1 9 4 1 2 4 5 4 3 2 1 4 3 3 3 3
-1 6 3 2
2 seconds
256 megabytes
['greedy', 'implementation', 'sortings', 'strings', 'two pointers', '*1200']
B. Magic Sticktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applie...
7 2 3 1 1 3 6 6 8 1 2 4 1 31235 6578234
YES YES NO YES NO YES YES
1 second
256 megabytes
['math', '*1000']
A. Two Rival Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are the gym teacher in the school.There are n students in the row. And there are two rivalling students among them. The first one is in position a, the second in position b. Positions are number...
3 5 1 3 2 100 33 100 1 6 0 2 3
2 99 1
1 second
256 megabytes
['greedy', 'math', '*800']
F. Equalizing Two Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t both of length n and both consisting of lowercase Latin letters.In one move, you can choose any length len from 1 to n and perform the following operation: Ch...
4 4 abcd abdc 5 ababa baaba 4 asdf asdg 4 abcd badc
NO YES NO YES
1 second
256 megabytes
['constructive algorithms', 'sortings', 'strings', '*2000']
E. Yet Another Division Into Teamstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students at your university. The programming skill of the i-th student is a_i. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. ...
5 1 1 3 4 2
3 1 1 1 1 1 1
2 seconds
256 megabytes
['dp', 'greedy', 'sortings', '*2000']
D. Binary String Minimizingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary string of length n (i. e. a string consisting of n characters '0' and '1').In one move you can swap two adjacent characters of the string. What is the lexicographically ...
3 8 5 11011010 7 9 1111100 7 11 1111100
01011110 0101111 0011111
1 second
256 megabytes
['greedy', '*1500']
C. Platforms Jumpingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1)....
7 3 2 1 2 1
YES 0 1 0 2 2 0 3
1 second
256 megabytes
['greedy', '*1700']
B. Minimize the Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation of length n. Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation...
4 5 5 4 1 3 2 4 1 2 4 3 1 1 4 4 3 2 1
1 5 2 4 3 1 2 3 4 1 1 4 3 2
1 second
256 megabytes
['greedy', '*1400']
A. Payment Without Changetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 \le x \le a) coins of value n and y (0 \...
4 1 2 3 4 1 2 3 6 5 2 6 27 3 3 5 18
YES NO NO YES
1 second
256 megabytes
['math', '*1000']
C. League of Leesinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end! The tournament consisted of n (n \ge 5) teams around th...
5 4 3 2 2 3 5 4 1 2
1 4 2 3 5
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*1600']
B. Fridge Lockerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHanh lives in a shared apartment. There are n people (including Hanh) living there, each has a private fridge. n fridges are secured by several steel chains. Each steel chain connects two different frid...
3 4 4 1 1 1 1 3 1 1 2 3 3 3 1 2 3
8 1 2 4 3 3 2 4 1 -1 12 3 2 1 2 3 1
1 second
256 megabytes
['graphs', 'implementation', '*1100']
A. Changing Volumetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob watches TV every day. He always sets the volume of his TV to b. However, today he is angry to find out someone has changed the volume to a. Of course, Bob has a remote control that can change the v...
3 4 0 5 14 3 9
2 3 2
1 second
256 megabytes
['math', '*800']
E. Send Tree to Charlietime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputChristmas was knocking on the door, and our protagonist, Bob, was preparing a spectacular present for his long-time second best friend Charlie. As chocolate boxes are lame, he decided to decorate...
4 3 4 2 4 4 1 0 4 0 0
2
4 seconds
512 megabytes
['combinatorics', 'dfs and similar', 'dsu', 'trees', '*3300']
D. Tree Queriestime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputHanh is a famous biologist. He loves growing trees and doing experiments on his own garden.One day, he got a tree consisting of n vertices. Vertices are numbered from 1 to n. A tree with n vertices is an...
5 12 1 2 1 3 2 4 2 5 1 1 1 2 1 2 2 2 3 2 4 2 5 1 2 2 2 1 2 2 2 3 2 4 2 5
1 199648871 399297742 199648871 199648871 598946614 199648873 2 2 2
5 seconds
512 megabytes
['data structures', 'probabilities', 'trees', '*2700']
C. Point Orderingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Khanh has n points on the Cartesian plane, denoted by a_1, a_2, \ldots, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are co...
6 15 -1 1
1 1 4 6 2 1 5 6 2 2 1 4 0 1 3 4 2 6 5
1 second
256 megabytes
['constructive algorithms', 'geometry', 'interactive', 'math', '*2300']
B2. Send Boxes to Alice (Hard Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the harder version of the problem. In this version, 1 \le n \le 10^6 and 0 \leq a_i \leq 10^6. You can hack this problem if you locked it. But you can hack the previous prob...
3 4 8 5
9
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', 'number theory', 'ternary search', 'two pointers', '*2100']
B1. Send Boxes to Alice (Easy Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easier version of the problem. In this version, 1 \le n \le 10^5 and 0 \le a_i \le 1. You can hack this problem only if you solve and lock both problems.Christmas is com...
3 1 0 1
2
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', 'number theory', 'ternary search', 'two pointers', '*1800']
A. Feeding Chickentime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLong is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.His farm is presented by a rectangle grid with r rows and...
4 3 5 3 ..R.. ...R. ....R 6 4 6 R..R R..R RRRR RRRR R..R R..R 5 5 4 RRR.. R.R.. RRR.. R..R. R...R 2 31 62 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
11122 22223 33333 aacc aBBc aBBc CbbA CbbA CCAA 11114 22244 32444 33344 33334 abcdefghijklmnopqrstuvwxyzABCDE FGHIJKLMNOPQRSTUVWXYZ0123456789
1.5 seconds
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*1700']
F. Cheap Robottime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou're given a simple, undirected, connected, weighted graph with n nodes and m edges.Nodes are numbered from 1 to n. There are exactly k centrals (recharge points), which are nodes 1, 2, \ldots, k.We con...
10 9 3 1 10 9 11 9 2 37 2 4 4 4 1 8 1 5 2 5 7 3 7 3 2 3 8 4 8 6 13 2 3
12
3 seconds
512 megabytes
['binary search', 'dsu', 'graphs', 'shortest paths', 'trees', '*2500']
E. Antenna Coveragetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe mayor of the Central Town wants to modernize Central Street, represented in this problem by the (Ox) axis.On this street, there are n antennas, numbered from 1 to n. The i-th antenna lies on the ...
3 595 43 2 300 4 554 10
281
3 seconds
256 megabytes
['data structures', 'dp', 'greedy', 'sortings', '*2200']
D. Harmonious Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n.The graph is considered harmonious if and only if the following property holds: For every triple of integers ...
14 8 1 2 2 7 3 4 6 3 5 7 3 8 6 8 11 12
1
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'dsu', 'graphs', 'greedy', 'sortings', '*1700']
C. Sweets Eatingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer a_i.Yui loves sweets, but she can eat at ...
9 2 6 19 3 4 4 2 6 7 8
2 5 11 18 30 43 62 83 121
1 second
256 megabytes
['dp', 'greedy', 'math', 'sortings', '*1500']
B. Silly Mistaketime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Central Company has an office with a sophisticated security system. There are 10^6 employees, numbered from 1 to 10^6.The security system logs entrances and departures. The entrance of the i-th emplo...
6 1 7 -7 3 -1 -3
1 6
1 second
256 megabytes
['greedy', 'implementation', '*1400']
A. Single Pushtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given two arrays a[1 \dots n] and b[1 \dots n], both of the same length n.In order to perform a push operation, you have to choose three integers l, r, k satisfying 1 \le l \le r \le n and k > 0. Th...
4 6 3 7 1 4 1 2 3 7 3 6 3 2 5 1 1 1 1 1 1 2 1 3 1 2 42 42 42 42 1 7 6
YES NO YES NO
1 second
256 megabytes
['implementation', '*1000']
L. Road Constructiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are N cities in the country of Numbata, numbered from 1 to N. Currently, there is no road connecting them. Therefore, each of these N cities proposes a road candidate to be constructed.City i ...
4 5 2 2 1 2 3 2 2 3 4 2 3 4 2 2 4 5 1 2 3 4 5
1 2 2 3 3 4 0 0 4 2
2 seconds
256 megabytes
['flows', 'graphs', '*2300']
K. Addition Robottime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAdding two numbers several times is a time-consuming task, so you want to build a robot. The robot should have a string S = S_1 S_2 \dots S_N of N characters on its memory that represents addition inst...
5 3 ABAAA 2 1 5 1 1 1 3 5 2 2 5 0 1000000000
11 3 0 1000000000
3 seconds
256 megabytes
['data structures', 'math', 'matrices', '*2100']
J. Tiling Terracetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTalia has just bought an abandoned house in the outskirt of Jakarta. The house has a nice and long yard which can be represented as a one-dimensional grid containing 1 \times N cells. To beautify the ho...
6 4 10 25 40 ..#...
75
1 second
256 megabytes
['brute force', 'dp', '*2300']
I. Mission Possibletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAllen, a government secret service, has been assigned to infiltrate a mafia secret base to uncover crucial information regarding the mafia's operations.The secret base is a rectangular bounded by (x_L...
3 2 2 50 26 4 14 48 14 15 13 7 36 16 6 46 18 3
2 13.25 23.1234567 36.591003 7.1
1 second
256 megabytes
['*3000']
H. Twin Buildingstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of ...
2 5 5 3 4
12.5
1 second
256 megabytes
['greedy', 'implementation', '*1800']
G. Performance Reviewtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRandall is a software engineer at a company with N employees. Every year, the company re-evaluates its employees. At the end of every year, the company replaces its several worst-performing employe...
5 3 3 50 40 30 20 10 4 1 2 3 100 1 4 2 6 7 1 3 300 2 1 400 2 1 5
1 0 1
2 seconds
256 megabytes
['data structures', '*2100']
F. Regular Forestationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA forestation is an act of planting a bunch of trees to grow a forest, usually to replace a forest that had been cut down. Strangely enough, graph theorists have another idea on how to make a fores...
13 1 5 1 7 2 4 2 8 2 11 3 12 4 7 4 12 6 11 7 13 9 10 9 12
3
1 second
256 megabytes
['hashing', 'trees', '*2400']