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. Robot and Candiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has a rectangular field of n \times m cells (the size of the n \cdot m field does not exceed 10^6 cells, m \ge 2), in each cell of which there can be candy. There are n rows and m columns i...
4 2 2 00 00 3 3 100 000 101 4 5 01000 00001 00010 10000 3 3 111 111 111
0 2 2 4
2 seconds
256 megabytes
['data structures', 'graph matchings', 'greedy', '*2500']
F. ATM and Studentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains s rubles.A queue of n students lined up to him. Each student wants to either withdraw a certain amou...
3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543
2 4 -1 1 2
2 seconds
256 megabytes
['binary search', 'data structures', 'two pointers', '*1800']
E2. Escape The Maze (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference with E1 is the question of the problem.Vlad built a maze out of n rooms and n-1 bidirectional corridors. From any room u any other room v can be reached through a s...
4 8 2 5 3 4 7 2 5 1 6 3 6 7 2 1 7 6 8 8 4 6 5 7 3 4 7 2 5 1 6 3 6 7 2 1 7 6 8 3 1 2 1 2 2 3 3 2 2 3 3 1 1 2
-1 2 1 2
2 seconds
256 megabytes
['dfs and similar', 'dp', 'greedy', 'shortest paths', 'trees', '*1900']
E1. Escape The Maze (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference with E2 is the question of the problem..Vlad built a maze out of n rooms and n-1 bidirectional corridors. From any room u any other room v can be reached through a ...
4 8 2 5 3 4 7 2 5 1 6 3 6 7 2 1 7 6 8 3 1 2 1 2 2 3 3 1 2 1 2 1 3 3 2 2 3 3 1 1 2
YES NO YES NO
2 seconds
256 megabytes
['dfs and similar', 'greedy', 'shortest paths', 'trees', 'two pointers', '*1700']
D. Weights Assignment For Tree Edgestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree consisting of n vertices. Vertices are numbered from 1 to n. Any vertex can be the root of a tree.A tree is a connected undirected graph without cycles. A...
4 5 3 1 3 3 1 3 1 2 5 4 3 1 1 2 3 1 2 7 1 1 2 3 4 5 6 1 2 3 4 5 6 7 6 4 4 4 4 1 1 4 2 1 5 6 3
1 10 0 102 100 -1 0 3 100 1 1 2 4 6 5 10 0 2 3
2 seconds
256 megabytes
['constructive algorithms', 'trees', '*1500']
C. Polycarp Recovers the Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp wrote on a whiteboard an array p of length n, which is a permutation of numbers from 1 to n. In other words, in p each number from 1 to n occurs exactly once.He also prepare...
4 4 1 3 2 4 1 1 5 1 3 5 4 2 3 3 2 1
3 1 4 2 1 -1 2 3 1
2 seconds
256 megabytes
['constructive algorithms', '*1000']
B. Team Composition: Programmers and Mathematicianstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate.There are a programmers and b mathematicians at ...
6 5 5 10 1 2 3 0 0 17 2 1000000000 1000000000
2 1 1 0 2 500000000
1 second
256 megabytes
['binary search', 'constructive algorithms', 'math', '*800']
A. Make Eventime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has an integer n that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times: Reverse the prefix of length l (in other words, l leftmost digits)...
4 3876 387 4489 3
0 2 1 -1
1 second
256 megabytes
['constructive algorithms', 'math', '*800']
I. Mashtali vs AtCodertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter many unsuccessful tries, Mashtali decided to copy modify an AtCoder problem. So here is his copied new problem:There is a tree with n vertices and some non-empty set of the vertices are pinne...
5 1 2 2 3 2 4 4 5
11122
1 second
256 megabytes
['games', 'trees', '*3100']
H. Squid Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter watching the new over-rated series Squid Game, Mashtali and Soroush decided to hold their own Squid Games! Soroush agreed to be the host and will provide money for the winner's prize, and Mashtali be...
6 3 1 1 1 4 4 1 5 3 4 2 6
2
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'greedy', 'trees', '*3100']
G. AmShZ Wins a Bettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRight before the UEFA Euro 2020, AmShZ and Safar placed bets on who'd be the champion, AmShZ betting on Italy, and Safar betting on France.Of course, AmShZ won. Hence, Safar gave him a bracket sequenc...
)(()(())))
)((())))
1 second
256 megabytes
['data structures', 'greedy', 'hashing', '*3300']
F. Mashtali: a Space Oddyseytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLee was planning to get closer to Mashtali's heart to proceed with his evil plan(which we're not aware of, yet), so he decided to beautify Mashtali's graph. But he made several rules for hims...
6 7 1 2 1 1 3 2 2 3 2 1 4 1 4 5 1 2 5 2 2 6 2
2 1212212
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', '*3000']
E. AmShZ and G.O.A.T.time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an array of k integers c_1, c_2, \ldots, c_k terrible, if the following condition holds:Let AVG be the \frac{c_1 + c_2 + \ldots + c_k}{k}(the average of all the elements of the array, it ...
4 3 1 2 3 5 1 4 4 5 6 6 7 8 197860736 212611869 360417095 837913434 8 6 10 56026534 405137099 550504063 784959015 802926648 967281024
0 1 2 3
1 second
256 megabytes
['binary search', 'brute force', 'greedy', 'implementation', 'math', '*2300']
D. Not Quite Leetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLee couldn't sleep lately, because he had nightmares. In one of his nightmares (which was about an unbalanced global round), he decided to fight back and propose a problem below (which you should solve) ...
4 2 2 4 7
10
1 second
256 megabytes
['combinatorics', 'dp', 'math', 'number theory', '*2000']
C. Keshi Is Throwing a Partytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKeshi is throwing a party and he wants everybody in the party to be happy.He has n friends. His i-th friend has i dollars. If you invite the i-th friend to the party, he will be happy only if...
3 3 1 2 2 1 1 1 2 0 0 0 1 2 1 0 0 1
2 1 2
1 second
256 megabytes
['binary search', 'greedy', '*1600']
B. Kalindrome Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array [b_1, b_2, \ldots, b_m] is a palindrome, if b_i = b_{m+1-i} for each i from 1 to m. Empty array is also a palindrome.An array is called kalindrome, if the following condition holds: It's poss...
4 1 1 2 1 2 3 1 2 3 5 1 4 4 1 4
YES YES NO YES
1 second
256 megabytes
['greedy', 'two pointers', '*1100']
A. Anti Light's Cell Guessingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a game on a n \times m grid, in which the computer has selected some cell (x, y) of the grid, and you have to determine which one. To do so, you will choose some k and some k...
2 2 3 3 1
2 1
1 second
256 megabytes
['math', '*900']
H. Pushing Robotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output There're n robots placed on a number line. Initially, i-th of them occupies unit segment [x_i, x_i + 1]. Each robot has a program, consisting of k instructions numbered from 1 to k. The robot performs...
2 1 0 4 1 -1 8 1 0 2 0 1 1 2 1 1 2 2 2 1 3 2 3
0 4 1 3 1 2 1 2
1 second
256 megabytes
['*3500']
G. A Stroll Around the Matrixtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output William has two arrays of numbers a_1, a_2, \dots, a_n and b_1, b_2, \dots, b_m. The arrays satisfy the conditions of being convex. Formally an array c of length k is considered convex if...
5 3 4 1 2 4 7 11 5 7 10 1 3 2 2 2 5 1 5 4 2 1 7
98 128 219 229
6 seconds
256 megabytes
['data structures', 'greedy', 'math', '*3000']
F. Interesting Sectionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output William has an array of non-negative numbers a_1, a_2, \dots, a_n. He wants you to find out how many segments l \le r pass the check. The check is performed in the following manner: The minim...
5 1 2 3 4 5
9
2 seconds
256 megabytes
['data structures', 'divide and conquer', 'meet-in-the-middle', 'two pointers', '*2800']
E. William The Oblivious time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Before becoming a successful trader William got a university degree. During his education an interesting situation happened, after which William started to listen to homework assignments much...
9 12 aaabccccc 4 a 4 b 2 b 5 a 1 b 6 b 5 c 2 a 1 a 5 a 6 b 7 b
0 1 2 2 1 2 1 2 2 2 2 2
3 seconds
256 megabytes
['bitmasks', 'data structures', 'dp', 'matrices', '*2400']
D. Social Networktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of c...
7 6 1 2 3 4 2 4 7 6 6 5 1 7
1 1 3 3 3 6
2 seconds
256 megabytes
['dsu', 'graphs', 'greedy', 'implementation', 'trees', '*1600']
C. Complex Market Analysistime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output While performing complex market analysis William encountered the following problem:For a given array a of size n and a natural number e, calculate the number of pairs of natural numbers (i, ...
6 7 3 10 2 1 3 1 19 3 3 2 1 13 1 9 3 2 4 2 1 1 1 1 4 2 3 1 1 1 1 4 1 1 2 1 1 2 2 1 2
2 0 4 0 5 0
2 seconds
256 megabytes
['binary search', 'dp', 'implementation', 'number theory', 'schedules', 'two pointers', '*1400']
B. William the Vigilanttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Before becoming a successful trader William got a university degree. During his education an interesting situation happened, after which William started to listen to homework assignments much m...
9 10 abcabcabc 1 a 1 b 2 c 3 a 4 b 5 c 8 a 9 b 1 c 4 a
3 2 2 2 1 2 1 1 1 0
2 seconds
256 megabytes
['implementation', 'strings', '*1100']
A. Divide and Multiplytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output William has array of n numbers a_1, a_2, \dots, a_n. He can perform the following sequence of operations any number of times: Pick any two items from array a_i and a_j, where a_i must be a mult...
5 3 6 4 2 5 1 2 3 4 5 1 10 3 2 3 4 15 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
50 46 10 26 35184372088846
1 second
256 megabytes
['greedy', 'implementation', 'math', 'number theory', '*900']
G. Alphabetic Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given m strings and a tree on n nodes. Each edge has some letter written on it.You have to answer q queries. Each query is described by 4 integers u, v, l and r. The answer to the query is the...
2 5 3 1 2 a aab abab aaa b a 2 1 1 5 1 2 1 3 2 1 3 5
8 7 4
3 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'hashing', 'string suffix structures', 'strings', 'trees', '*3500']
F. MEX countingtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor an array c of nonnegative integers, MEX(c) denotes the smallest nonnegative integer that doesn't appear in it. For example, MEX([0, 1, 3]) = 2, MEX([42]) = 0.You are given integers n, k, and an array...
4 0 0 0 0 0
256
4 seconds
256 megabytes
['combinatorics', 'dp', 'implementation', '*3200']
E. The Cells on the Papertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn an endless checkered sheet of paper, n cells are chosen and colored in three colors, where n is divisible by 3. It turns out that there are exactly \frac{n}{3} marked cells of each of three ...
9 2 3 1 4 1 2 2 1 3 3 4 1 5 3 2 4 4 3 2 4 1 5 2 2 3 5 3
6
2 seconds
256 megabytes
['binary search', 'implementation', 'sortings', '*2800']
D. Dominoestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n dominoes. Each domino has a left and a right cell. Each cell can be colored either black or white. Some cells are already colored, while some aren't yet.The coloring is said to be valid if and...
1 ?W
1
1 second
256 megabytes
['combinatorics', 'fft', 'graphs', 'math', 'number theory', '*2400']
C. Game Mastertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputn players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that ...
3 4 1 2 3 4 1 2 3 4 4 11 12 20 21 44 22 11 30 1 1000000000 1000000000
0001 1111 1
1 second
256 megabytes
['data structures', 'dfs and similar', 'dp', 'graphs', 'greedy', 'two pointers', '*1700']
B. Build the Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three integers n, a, b. Determine if there exists a permutation p_1, p_2, \ldots, p_n of integers from 1 to n, such that:There are exactly a integers i with 2 \le i \le n-1 such tha...
3 4 1 1 6 1 2 6 4 0
1 3 2 4 4 2 3 1 5 6 -1
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1200']
A. Find Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven n, find any array a_1, a_2, \ldots, a_n of integers such that all of the following conditions hold: 1 \le a_i \le 10^9 for every i from 1 to n.a_1 < a_2 < \ldots <a_nFor every i from 2 to n, a_i isn't...
3 1 2 7
1 2 3 111 1111 11111 111111 1111111 11111111 111111111
1 second
256 megabytes
['constructive algorithms', 'math', '*800']
H. Banquet Preparations 2time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe chef has cooked n dishes yet again: the i-th dish consists of a_i grams of fish and b_i grams of meat. Banquet organizers consider two dishes i and j equal if a_i=a_j and b_i=b_j at the sam...
5 3 10 10 2 9 9 0 10 9 1 2 3 4 1 5 1 2 3 7 2 5 6 5 4 5 5 6 1 13 42 50 5 5 7 12 3 1 4 7 3 7 0 0 0 4 1 5
1 1 1 0 0 1 0 2 0 1 1 1 2 3 2 0 4 1 5 1 8 42 2 5 7 3 1 4 3 0 0 4 1
3 seconds
256 megabytes
['greedy', 'sortings', 'two pointers', '*2200']
G. Banquet Preparations 1time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA known chef has prepared n dishes: the i-th dish consists of a_i grams of fish and b_i grams of meat. The banquet organizers estimate the balance of n dishes as follows. The balance is equal t...
8 1 5 3 4 1 6 3 4 2 2 1 3 4 2 2 4 1 3 1 7 3 6 1 7 1 8 1 9 3 6 1 8 1 9 30 10 3 4 3 1 3 2 4 1 5 4 0 7 6 4 0 8 4 1 5 3
0 2 3 1 3 3 0 1 1 1 1 2 1 3 0 4 3 0 6 0 6 0 6 7 1 5 1 5 6 0 0 3 1 3 1 3 1 0 0 4 2 2 0 4 3 1 1 3
2 seconds
256 megabytes
['greedy', '*2200']
F. Robot on the Board 2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe robot is located on a checkered rectangular board of size n \times m (n rows, m columns). The rows in the board are numbered from 1 to n from top to bottom, and the columns — from 1 to m from...
7 1 1 R 1 3 RRL 2 2 DL RU 2 2 UD RU 3 2 DL UL RU 4 4 RRRD RUUD URUD ULLR 4 4 DDLU RDDU UUUU RDLD
1 1 1 1 1 3 1 1 4 2 1 3 3 1 5 4 3 12 1 1 4
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'graphs', 'implementation', '*2300']
E. Robot on the Board 1time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe robot is located on a checkered rectangular board of size n \times m (n rows, m columns). The rows in the board are numbered from 1 to n from top to bottom, and the columns — from 1 to m from...
4 1 1 L 1 2 L 3 3 RRDLUU 4 3 LUURRDDLLLUU
1 1 1 2 2 1 3 2
2 seconds
256 megabytes
['implementation', '*1600']
D. Blue-Red Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of integers a of length n. The elements of the array can be either different or the same. Each element of the array is colored either blue or red. There are no unpainted ele...
8 4 1 2 5 2 BRBR 2 1 1 BB 5 3 1 4 2 5 RBRRB 5 3 1 3 1 3 RBRRB 5 5 1 5 1 5 RBRRB 4 2 2 2 2 BRBR 2 1 -2 BR 4 -2 -1 4 0 RRRR
YES NO YES YES NO YES YES YES
1 second
256 megabytes
['greedy', 'math', 'sortings', '*1300']
C. Minimum Extractiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYelisey has an array a of n integers.If a has length strictly greater than 1, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number m in the ...
8 1 10 2 0 0 3 -1 2 0 4 2 10 1 7 2 2 3 5 3 2 -4 -2 0 2 -1 1 1 -2
10 0 2 5 2 2 2 -2
1 second
256 megabytes
['brute force', 'sortings', '*1000']
B. Odd Grasshoppertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe grasshopper is located on the numeric axis at the point with coordinate x_0.Having nothing else to do he starts jumping between integer points on the axis. Making a jump from a point with coordinat...
9 0 1 0 2 10 10 10 99 177 13 10000000000 987654321 -433494437 87178291199 1 0 -1 1
-1 1 11 110 190 9012345679 -87611785637 1 0
1 second
256 megabytes
['math', '*900']
A. Linear Keyboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a keyboard that consists of 26 keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word s ...
5 abcdefghijklmnopqrstuvwxyz hello abcdefghijklmnopqrstuvwxyz i abcdefghijklmnopqrstuvwxyz codeforces qwertyuiopasdfghjklzxcvbnm qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq qwertyuiopasdfghjklzxcvbnm abacaba
13 0 68 0 74
1 second
256 megabytes
['implementation', 'strings', '*800']
F. Tree Queriestime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of n vertices. Recall that a tree is an undirected connected acyclic graph. The given tree is rooted at the vertex 1.You have to process q queries. In each query, you are ...
8 6 7 3 2 8 3 5 7 7 4 7 1 7 3 6 1 0 1 2 1 3 7 1 5 0 7 200000
5 2 1 4 0 4
6 seconds
512 megabytes
['brute force', 'dp', 'trees', '*2800']
E. Arenatime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n heroes fighting in the arena. Initially, the i-th hero has a_i health points.The fight in the arena takes place in several rounds. At the beginning of each round, each alive hero deals 1 damage to a...
2 5
5
3 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*2100']
D. Red-Blue Matrixtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix, consisting of n rows and m columns. The j-th cell of the i-th row contains an integer a_{ij}.First, you have to color each row of the matrix either red or blue in such a way th...
3 5 5 1 5 8 8 7 5 2 1 4 3 1 6 9 7 5 9 3 3 3 2 1 7 9 9 8 3 3 8 9 8 1 5 3 7 5 7 2 6 3 3 3 2 2 2 1 1 1 4 4 4
YES BRBRB 1 NO YES RB 3
4 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', 'sortings', '*2400']
C. Banknotestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland, n different types of banknotes are used. Banknotes of the i-th type have denomination 10^{a_i} burles (burles are the currency used in Berland); the denomination of banknotes of the first type i...
4 3 13 0 1 2 2 777 0 4 3 255 0 1 3 10 1000000000 0 1 2 3 4 5 6 7 8 9
59 778 148999 999999920999999999
2 seconds
256 megabytes
['greedy', 'number theory', '*1400']
B. Update Filestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland State University has received a new update for the operating system. Initially it is installed only on the 1-st computer.Update files should be copied to all n computers. The computers are not co...
4 8 3 6 6 7 1 1 1
4 3 6 0
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*1100']
A. AB Balancetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s of length n consisting of characters a and/or b.Let \operatorname{AB}(s) be the number of occurrences of string ab in s as a substring. Analogically, \operatorname{BA}(s) is the nu...
4 b aabbbabaa abbb abbaab
b aabbbabaa bbbb abbaaa
2 seconds
256 megabytes
['strings', '*900']
F. PalindORmetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn integer array a of length n is said to be a PalindORme if (a_{1} | a_{2} | \ldots | a_{i}) = (a_{{n - i + 1}} | \ldots | a_{{n - 1}} | a_{n}) for all 1 \leq i \leq n, where | denotes the bit...
1 1 998244353
2
4 seconds
256 megabytes
['combinatorics', 'dp', '*2900']
E. Array Equalizertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJeevan has two arrays a and b of size n. He is fond of performing weird operations on arrays. This time, he comes up with two types of operations: Choose any i (1 \le i \le n) and increment a_j by 1 ...
2 3 7 -1 5 3 1 4 3
2 4 2
2 seconds
256 megabytes
['binary search', 'greedy', 'implementation', 'math', 'number theory', 'sortings', 'two pointers', '*2400']
D. Treelabelingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEikooc and Sushi play a game.The game is played on a tree having n nodes numbered 1 to n. Recall that a tree having n nodes is an undirected, connected graph with n-1 edges.They take turns alternately mo...
3 1 2 1 2 3 1 2 1 3
1 2 1 1 2 3
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'dfs and similar', 'games', 'greedy', 'implementation', 'trees', '*2100']
C. Dominant Charactertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAshish has a string s of length n containing only characters 'a', 'b' and 'c'.He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substr...
3 2 aa 5 cbabb 8 cacabccc
2 -1 3
2 seconds
256 megabytes
['brute force', 'greedy', 'implementation', 'strings', '*1400']
B. Reverse Sorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAshish has a binary string s of length n that he wants to sort in non-decreasing order.He can perform the following operation: Choose a subsequence of any length such that its elements are in non-incre...
3 7 0011111 5 10100 6 001000
0 1 4 1 3 4 5 1 3 3 5 6
2 seconds
256 megabytes
['greedy', 'sortings', '*1000']
A. A.M. Deviationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA number a_2 is said to be the arithmetic mean of two numbers a_1 and a_3, if the following condition holds: a_1 + a_3 = 2\cdot a_2. We define an arithmetic mean deviation of three numbers a_1, a_2 and ...
3 3 4 5 2 2 6 1 6 5
0 1 0
1 second
256 megabytes
['math', 'number theory', '*800']
B. XOR Specia-LIS-ttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYouKn0wWho has an integer sequence a_1, a_2, \ldots a_n. Now he will split the sequence a into one or more consecutive subarrays so that each element of a belongs to exactly one subarray. Let k be the...
4 7 1 3 4 2 2 1 5 3 1 3 4 5 1 3 2 4 2 4 4 3 2 1
YES NO YES YES
1 second
256 megabytes
['*1100']
A. Eratime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputShohag has an integer sequence a_1, a_2, \ldots, a_n. He can perform the following operation any number of times (possibly, zero): Select any positive integer k (it can be different in different operations). Cho...
4 3 1 3 4 5 1 2 5 7 4 1 1 3 69 6969 696969
1 3 0 696966
1 second
256 megabytes
['greedy', '*800']
F. October 18, 2017time limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt was October 18, 2017. Shohag, a melancholic soul, made a strong determination that he will pursue Competitive Programming seriously, by heart, because he found it fascinating. Fast forward to 4 ye...
6 2 2 0 2 1 1 3 2 3 69 69 69 2017 10 18 5 7 0
6 1 15 699496932 892852568 713939942
4 seconds
512 megabytes
['combinatorics', 'dp', 'implementation', 'math', '*2700']
E. A Perfect Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence of integers b_1, b_2, \ldots, b_m is called good if max(b_1, b_2, \ldots, b_m) \cdot min(b_1, b_2, \ldots, b_m) \ge b_1 + b_2 + \ldots + b_m.A sequence of integers a_1, a_2, \ldots, a_n i...
2 998244353
4
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*3200']
D. Artistic Partitiontime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputFor two positive integers l and r (l \le r) let c(l, r) denote the number of integer pairs (i, j) such that l \le i \le j \le r and \operatorname{gcd}(i, j) \ge l. Here, \operatorname{gcd}(i, j) i...
4 6 2 4 4 3 1 10 3
8 4 6 11
3 seconds
1024 megabytes
['divide and conquer', 'dp', 'number theory', '*3000']
C. Extreme Extensiontime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor an array b of n integers, the extreme value of this array is the minimum number of times (possibly, zero) the following operation has to be performed to make b non-decreasing: Select an index ...
4 3 5 4 3 4 3 2 1 4 1 69 8 7264 40515 28226 92776 35285 21709 75124 48163
5 9 0 117
4 seconds
256 megabytes
['dp', 'greedy', 'math', 'number theory', '*2300']
B. Moderate Modular Modetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYouKn0wWho has two even integers x and y. Help him to find an integer n such that 1 \le n \le 2 \cdot 10^{18} and n \bmod x = y \bmod n. Here, a \bmod b denotes the remainder of a after division ...
4 4 8 4 2 420 420 69420 42068
4 10 420 9969128
1 second
256 megabytes
['constructive algorithms', 'math', 'number theory', '*1600']
A. Di-visible Confusiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYouKn0wWho has an integer sequence a_1, a_2, \ldots, a_n. He will perform the following operation until the sequence becomes empty: select an index i such that 1 \le i \le |a| and a_i is not divis...
5 3 1 2 3 1 2 2 7 7 10 384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328 8 6 69 696 69696 696969 6969696 69696969 696969696
YES NO YES YES NO
1 second
256 megabytes
['constructive algorithms', 'math', 'number theory', '*1300']
B. Divine Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBlack is gifted with a Divine array a consisting of n (1 \le n \le 2000) integers. Each position in a has an initial value. After shouting a curse over the array, it becomes angry and starts an unstoppab...
2 7 2 1 1 4 3 1 2 4 3 0 1 1 2 2 6 1 2 1 1 2 1 0 2 1000000000
1 2 3 3 1 2
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*1100']
A. Two Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s. You need to find two non-empty strings a and b such that the following conditions are satisfied: Strings a and b are both subsequences of s. For each index i, character s_...
3 fc aaaa thebrightboiler
c f a aaa b therightboiler
2 seconds
256 megabytes
['implementation', '*800']
F. Two Sortstime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIntegers from 1 to n (inclusive) were sorted lexicographically (considering integers as strings). As a result, array a_1, a_2, \dots, a_n was obtained.Calculate value of (\sum_{i = 1}^n ((i - a_i) \mod 9982...
3
0
4 seconds
512 megabytes
['binary search', 'dfs and similar', 'math', 'meet-in-the-middle', '*3400']
E. Phys Ed Onlinetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputStudents of one unknown college don't have PE courses. That's why q of them decided to visit a gym nearby by themselves. The gym is open for n days and has a ticket system. At the i-th day, the cost of...
7 5 2 2 15 6 3 7 5 6 1 2 3 7 5 5 7 7 3 5
2 12 7 6 9
2 seconds
512 megabytes
['data structures', 'dp', 'greedy', '*2900']
D. Difficult Mountaintime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA group of n alpinists has just reached the foot of the mountain. The initial difficulty of climbing this mountain can be described as an integer d.Each alpinist can be described by two integers s ...
3 2 2 6 3 5 5 7
2
2 seconds
512 megabytes
['data structures', 'dp', 'greedy', 'sortings', '*2700']
C. Optimal Insertiontime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given two arrays of integers a_1, a_2, \ldots, a_n and b_1, b_2, \ldots, b_m.You need to insert all elements of b into a in an arbitrary way. As a result you will get an array c_1, c_2, \ldo...
3 3 4 1 2 3 4 3 2 1 3 3 3 2 1 1 2 3 5 4 1 3 5 3 1 4 3 6 1
0 4 6
3 seconds
512 megabytes
['data structures', 'divide and conquer', 'dp', 'greedy', 'sortings', '*2300']
B. Frog Travelertime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputFrog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of n meters depth. Now Gorf is on the bottom of the well and has a long way up.The surface of the well...
3 0 2 2 1 1 0
2 1 0
2 seconds
512 megabytes
['data structures', 'dfs and similar', 'dp', 'graphs', 'shortest paths', 'two pointers', '*1900']
A. Array Eliminationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given array a_1, a_2, \ldots, a_n, consisting of non-negative integers.Let's define operation of "elimination" with integer parameter k (1 \leq k \leq n) as follows: Choose k distinct array...
5 4 4 4 4 4 4 13 7 25 19 6 3 5 3 1 7 1 1 1 5 0 0 0 0 0
1 2 4 1 2 1 1 1 2 3 4 5
2 seconds
512 megabytes
['bitmasks', 'greedy', 'math', 'number theory', '*1300']
J. Robot Factorytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at ...
4 5 9 14 11 12 13 5 15 11 6 7 5 9 14 9 14 3 2 14 3 14
9 4 4 2 1
1 second
256 megabytes
['bitmasks', 'dfs and similar', '*1400']
F. Party Organizationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn the great island of Baltia, there live N people, numbered from 1 to N. There are exactly M pairs of people that are friends with each other. The people of Baltia want to organize a successful par...
6 3 1 4 4 2 5 4
1 2 3 5 6
1 second
256 megabytes
['brute force', 'math', 'probabilities', '*2300']
E. Array Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob are playing a game. They are given an array A of length N. The array consists of integers. They are building a sequence together. In the beginning, the sequence is empty. In one turn a player ...
1 5
Alice
1 second
256 megabytes
['games', 'greedy', 'two pointers', '*1900']
J. Bob's Beautiful Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob really likes playing with arrays of numbers. That's why for his birthday, his friends bought him a really interesting machine – an array beautifier. The array beautifier takes an array A cons...
2 5 5
YES 2 3
1 second
256 megabytes
['bitmasks', 'brute force', 'greedy', '*2600']
I. Deserttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph of N nodes and M edges, E_1, E_2, \dots E_M.A connected graph is a cactus if each of it's edges belogs to at most one simple cycle. A graph is a desert if each of it's connect...
5 6 1 2 2 3 3 4 4 5 5 1 2 4
20
2 seconds
256 megabytes
['data structures', 'graphs', '*2700']
H. Hidden Fortresstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem!As part of your contribution in the Great Bubble War, you have been tasked with finding the newly built enemy fortress. The world you live in is a giant 10^9 \times 10^9 ...
1 1 2 1
? 2 2 ? 5 5 ? 4 7 ? 1 5 ! 2 3 4 5
1 second
256 megabytes
['interactive', 'math', '*2100']
G. Shortest pathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given N points on an infinite plane with the Cartesian coordinate system on it. N-1 points lay on one line, and one point isn't on that line. You are on point K at the start, and the goal is to v...
5 2 0 0 -1 1 2 -2 0 1 -2 2
7.478709
1 second
256 megabytes
['brute force', 'geometry', 'math', 'shortest paths', '*2700']
F. Marstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the year 2420 humans have finally built a colony on Mars thanks to the work of Elon Tusk. There are 10^9+7 cities arranged in a circle in this colony and none of them are connected yet. Elon Tusk wants to con...
9 8 17 0 12 6 10 8 2 4 5 2 3 12 2 3 6 2 4 6 4 6 2 2 8 2 1 2 17 1 8 2 9 9 14
Yes No Yes Yes Yes Yes No Yes
2 seconds
256 megabytes
['hashing', '*2700']
E. Two Arraystime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integer arrays of length N, A1 and A2. You are also given Q queries of 4 types: 1 k l r x: set Ak_i:=min(Ak_i, x) for each l \leq i \leq r.2 k l r x: set Ak_i:=max(Ak_i, x) for each l \le...
3 4 1 0 2 2 1 0 4 1 3 3 2 2 2 3 1 1 1 3 0 4 1 3
4 4
5 seconds
256 megabytes
['data structures', 'matrices', '*3200']
D. Bubble Poppingtime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are N bubbles in a coordinate plane. Bubbles are so tiny that it can be assumed that each bubble is a point (X_i, Y_i). Q Bubble Cup finalists plan to play with the bubbles. Each finalist would...
4 0 0 1 0 0 1 1 1 2 1 -1 3 -1 1 4
4 2
2.5 seconds
256 megabytes
['*3200']
C. Bubble Striketime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game for two players.Each game is set in...
7 1.0000
6
0.5 seconds
256 megabytes
['combinatorics', 'math', 'probabilities', 'ternary search', '*2000']
B. Restaurant Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob always had hard time choosing restaurant for the dinner. Previously they performed Eenie Meenie Miney Mo game, but eventually as their restaurant list grew, they had to create a new game....
1 4 0 1 left right
0
1 second
256 megabytes
['*3100']
A. Weightstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array A of length N weights of masses A_1, A_2...A_N. No two weights have the same mass. You can put every weight on one side of the balance (left or right). You don't have to put weights in o...
5 3 8 2 13 7 LLRLL
3 L 2 R 8 R 13 L 7 L
1 second
256 megabytes
['constructive algorithms', 'greedy', 'two pointers', '*2600']
G. The Sum of Good Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a positive integer good if there is no digit 0 in its decimal representation.For an array of a good numbers a, one found out that the sum of some two neighboring elements is equal t...
1256133 17
1 2 3 3
2 seconds
256 megabytes
['hashing', 'math', 'string suffix structures', 'strings', '*3200']
F. RBStime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence (or, shortly, an RBS) is a bracket sequence that can be transformed into a correct arithmetic expression by insert...
2 ( )
1
3 seconds
512 megabytes
['binary search', 'bitmasks', 'brute force', 'data structures', 'dp', '*2400']
E. Staircasestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix, consisting of n rows and m columns. The rows are numbered top to bottom, the columns are numbered left to right.Each cell of the matrix can be either free or locked.Let's call a pat...
2 2 8 1 1 1 1 1 1 2 2 1 1 1 2 2 1 1 1
5 10 5 2 5 3 1 0
2 seconds
256 megabytes
['brute force', 'combinatorics', 'data structures', 'dfs and similar', 'dp', 'implementation', 'math', '*2100']
D. Training Sessiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp is the coach of the Berland State University programming teams. He decided to compose a problemset for a training session for his teams.Monocarp has n problems that none of his students have...
2 4 2 4 3 4 2 1 1 3 5 1 5 2 4 3 3 4 2 5 1
3 10
2 seconds
256 megabytes
['combinatorics', 'data structures', 'geometry', 'implementation', 'math', '*1700']
C. Delete Two Elementstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp has got an array a consisting of n integers. Let's denote k as the mathematic mean of these elements (note that it's possible that k is not an integer). The mathematic mean of an array of...
4 4 8 8 8 8 3 50 20 10 5 1 4 7 3 5 7 1 2 3 4 5 6 7
6 0 2 3
2 seconds
256 megabytes
['data structures', 'dp', 'implementation', 'math', 'two pointers', '*1200']
B. Groupstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn students attended the first meeting of the Berland SU programming course (n is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the...
2 4 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 2 0 0 0 1 0 0 0 0 1 0
YES NO
4 seconds
256 megabytes
['brute force', 'implementation', '*1000']
A. Computer Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp is playing a computer game. Now he wants to complete the first level of this game.A level is a rectangular grid of 2 rows and n columns. Monocarp controls a character, which starts in cell (1, ...
4 3 000 000 4 0011 1100 4 0111 1110 6 010101 101010
YES YES NO YES
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'dp', 'implementation', '*800']
F. Ideal Farmtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTheofanis decided to visit his uncle's farm. There are s animals and n animal pens on the farm. For utility purpose, animal pens are constructed in one row.Uncle told Theofanis that a farm is lucky if you ...
4 1 1 1 1 1 2 100 50 200 56220 47258 14497
YES NO NO YES
2 seconds
256 megabytes
['constructive algorithms', 'math', '*2400']
E2. Rubik's Cube Coloring (hard version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors.Theofanis is starving, and he wants to eat his favorite ...
3 2 5 orange 2 white
1024
3 seconds
256 megabytes
['brute force', 'dp', 'implementation', 'math', 'trees', '*2300']
E1. Rubik's Cube Coloring (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors.Theofanis is starving, and he wants to eat his favori...
3
24576
2 seconds
256 megabytes
['combinatorics', 'math', '*1300']
D. The Number of Imposterstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTheofanis started playing the new online game called "Among them". However, he always plays with Cypriot players, and they all have the same name: "Andreas" (the most common name in Cyprus).In...
5 3 2 1 2 imposter 2 3 crewmate 5 4 1 3 crewmate 2 5 crewmate 2 4 imposter 3 4 imposter 2 2 1 2 imposter 2 1 crewmate 3 5 1 2 imposter 1 2 imposter 3 2 crewmate 3 2 crewmate 1 3 imposter 5 0
2 4 -1 2 5
3 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'dp', 'dsu', 'graphs', '*1700']
C. Make Them Equaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTheofanis has a string s_1 s_2 \dots s_n and a character c. He wants to make all characters of the string equal to c using the minimum number of operations.In one operation he can choose a number x (1...
3 4 a aaaa 4 a baaa 4 b bzyx
0 1 2 2 2 3
2 seconds
256 megabytes
['brute force', 'greedy', 'math', 'strings', '*1200']
B. Special Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTheofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers.Let's call a positive number special if ...
3 3 4 2 12 105 564
9 12 3595374
2 seconds
256 megabytes
['bitmasks', 'math', '*1100']
A. Consecutive Sum Riddletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTheofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).You are given an integer n. You need to find two integers l and...
7 1 2 3 6 100 25 3000000000000
0 1 -1 2 1 2 1 3 18 22 -2 7 999999999999 1000000000001
2 seconds
256 megabytes
['math', '*800']
G. Changing Bracketstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence of round and square brackets is given. You can change the sequence by performing the following operations: change the direction of a bracket from opening to closing and vice versa withou...
3 ([))[)()][]] 3 1 12 4 9 3 6 )))))) 2 2 3 1 4 [] 1 1 2
0 2 1 0 0 0
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'dp', 'greedy', '*2200']
F. Red-Black Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is given a non-negative integer x, the decimal representation of which contains n digits. You need to color each its digit in red or black, so that the number formed by the red digits is divisible ...
4 5 3 13 02165 4 2 1 1357 8 1 1 12345678 2 7 9 90
RBRBR -1 BBRRRRBB BR
1 second
256 megabytes
['dfs and similar', 'dp', 'implementation', 'math', 'meet-in-the-middle', '*2100']
E. Gardener and Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tree is an undirected connected graph in which there are no cycles. This problem is about non-rooted trees. A leaf of a tree is a vertex that is connected to at most one vertex.The gardener Vitaly...
6 14 1 1 2 2 3 2 4 4 5 4 6 2 7 7 8 8 9 8 10 3 11 3 12 1 13 13 14 2 200000 1 2 3 2 1 2 2 3 5 1 5 1 3 2 2 1 5 4 6 2 5 1 2 5 5 6 4 2 3 4 7 1 4 3 5 1 1 3 6 1 1 7 2 1
7 0 0 3 1 2
4 seconds
256 megabytes
['brute force', 'data structures', 'dfs and similar', 'greedy', 'implementation', 'trees', '*1600']
D2. Half of Sametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is a complicated version of D1, but it has significant differences, so read the whole statement.Polycarp has an array of n (n is even) integers a_1, a_2, \dots, a_n. Polycarp conceived of a ...
4 6 48 13 22 -15 16 35 8 -1 0 1 -1 0 1 -1 0 4 100 -1000 -1000 -1000 4 1 1 1 1
13 2 -1 -1
1 second
256 megabytes
['brute force', 'math', 'number theory', '*1900']
D1. All are Sametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is a simplified version of D2, but it has significant differences, so read the whole statement.Polycarp has an array of n (n is even) integers a_1, a_2, \dots, a_n. Polycarp conceived of a p...
3 6 1 5 3 1 1 5 8 -1 0 1 -1 0 1 -1 0 4 100 -1000 -1000 -1000
2 1 1100
1 second
256 megabytes
['math', 'number theory', '*1100']