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
F. One Node is Gonetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an integer n. Let's define following tree generation as McDic's generation: Make a complete and full binary tree of 2^{n} - 1 vertices. Complete and full binary tree means a tree that exactl...
4 1 2 1 3 2 4 2 5 3 6 3 13 3 14 4 7 4 8 5 9 5 10 6 11 6 12
1 3
1 second
256 megabytes
['constructive algorithms', 'implementation', 'trees', '*2500']
E. Another Filling the Gridtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n \times n square grid and an integer k. Put an integer in each cell while satisfying the conditions below. All numbers in the grid should be between 1 and k inclusive. Minimum numb...
2 2
7
1 second
256 megabytes
['combinatorics', 'dp', 'math', '*2300']
D. Complete Tripartitetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a simple undirected graph consisting of n vertices and m edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconne...
6 11 1 2 1 3 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6
1 2 2 3 3 3
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'graphs', 'hashing', 'implementation', '*1900']
C. Primes and Multiplicationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's introduce some definitions that will be needed later.Let prime(x) be the set of prime divisors of x. For example, prime(140) = \{ 2, 5, 7 \}, prime(169) = \{ 13 \}.Let g(x, p) be the ma...
10 2
2
1 second
256 megabytes
['math', 'number theory', '*1700']
B. Filling the Gridtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose there is a h \times w grid consisting of empty or full cells. Let's make some definitions: r_{i} is the number of consecutive full cells connected to the left side in the i-th row (1 \le i \l...
3 4 0 3 1 0 2 3 0
2
1 second
256 megabytes
['implementation', 'math', '*1400']
A. Distinct Digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have two integers l and r. Find an integer x which satisfies the conditions below: l \le x \le r. All digits of x are different. If there are multiple answers, print any of them.InputThe first li...
121 130
123
1 second
256 megabytes
['brute force', 'implementation', '*800']
G. Not Sametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer array a_1, a_2, \dots, a_n, where a_i represents the number of blocks at the i-th position. It is guaranteed that 1 \le a_i \le n. In one operation you can choose a subset of indices...
5 5 5 5 5 5
6 11111 01111 10111 11011 11101 11110
2 seconds
256 megabytes
['constructive algorithms', '*2600']
F2. Wrong Answer on test 233 (Hard Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour program fails again. This time it gets "Wrong answer on test 233".This is the harder version of the problem. In this version, 1 \le n \le 2\cdot10^5. You can hack this pro...
3 3 1 3 1
9
1 second
256 megabytes
['combinatorics', 'math', '*2400']
F1. Wrong Answer on test 233 (Easy Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour program fails again. This time it gets "Wrong answer on test 233".This is the easier version of the problem. In this version 1 \le n \le 2000. You can hack this problem on...
3 3 1 3 1
9
1 second
256 megabytes
['dp', '*2200']
E. Arson In Berland Foresttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events.A destructive fire raged through the Forest, and severa...
3 6 XXXXXX XXXXXX XXXXXX
1 ...... .X.XX. ......
2 seconds
512 megabytes
['binary search', 'graphs', 'graphs', 'shortest paths', '*2200']
D2. Optimal Subsequences (Hard Version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the harder version of the problem. In this version, 1 \le n, m \le 2\cdot10^5. You can hack this problem if you locked it. But you can hack the previous problem only if yo...
3 10 20 10 6 1 1 2 1 2 2 3 1 3 2 3 3
20 10 20 10 20 10
3 seconds
256 megabytes
['data structures', 'greedy', '*1800']
D1. Optimal Subsequences (Easy Version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easier version of the problem. In this version 1 \le n, m \le 100. You can hack this problem only if you solve and lock both problems.You are given a sequence of integ...
3 10 20 10 6 1 1 2 1 2 2 3 1 3 2 3 3
20 10 20 10 20 10
3 seconds
256 megabytes
['data structures', 'greedy', '*1600']
C. Messytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are fed up with your messy room, so you decided to clean it up.Your room is a bracket sequence s=s_{1}s_{2}\dots s_{n} of length n. Each character of this string is either an opening bracket '(' or a closing...
4 8 2 ()(())() 10 3 ))()()()(( 2 1 () 2 1 )(
4 3 4 1 1 5 8 2 2 3 4 10 1 4 6 7 0 1 1 2
1 second
256 megabytes
['constructive algorithms', '*1700']
B. Boxtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPermutation p is a sequence of integers p=[p_1, p_2, \dots, p_n], consisting of n distinct (unique) positive integers between 1 and n, inclusive. For example, the following sequences are permutations: [3, 4, 1, 2]...
4 5 1 3 4 5 5 4 1 1 3 4 2 2 2 1 1
1 3 4 5 2 -1 2 1 1
1 second
256 megabytes
['constructive algorithms', '*1200']
A. Math Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour math teacher gave you the following problem:There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], \ldots, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ...
4 3 4 5 5 9 7 7 5 11 19 4 17 16 16 3 12 14 17 1 1 10 1 1 1
2 4 0 0
2 seconds
256 megabytes
['math', '*1100']
G. To Make 1time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n positive integers written on the blackboard. Also, a positive number k \geq 2 is chosen, and none of the numbers on the blackboard are divisible by k. In one operation, you can choose any two in...
2 2 1 1
YES 1 1
2 seconds
512 megabytes
['bitmasks', 'constructive algorithms', 'dp', 'greedy', 'number theory', '*3100']
F. Tree Factorytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and important order...
5 0 0 1 1
0 2 1 4 3 2 1 3
2 seconds
512 megabytes
['constructive algorithms', 'greedy', 'trees', '*2500']
E. Rock Is Pushtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are at the top left cell (1, 1) of an n \times m labyrinth. Your goal is to get to the bottom right cell (n, m). You can only move right or down, one cell per step. Moving right from a cell (x, y) ta...
1 1 .
1
2 seconds
512 megabytes
['binary search', 'dp', '*2200']
D. Power Productstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given n positive integers a_1, \ldots, a_n, and an integer k \geq 2. Count the number of pairs i, j such that 1 \leq i < j \leq n, and there exists an integer x such that a_i \cdot a_j = x^k.In...
6 3 1 3 9 8 24 1
5
2 seconds
512 megabytes
['hashing', 'math', 'number theory', '*1800']
C. p-binarytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine t...
24 0
2
2 seconds
512 megabytes
['bitmasks', 'brute force', 'math', '*1600']
B2. TV Subscriptions (Hard Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n day...
4 5 2 2 1 2 1 2 1 9 3 3 3 3 3 2 2 2 1 1 1 4 10 4 10 8 6 4 16 9 8 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
2 1 4 5
2 seconds
256 megabytes
['implementation', 'two pointers', '*1300']
B1. TV Subscriptions (Easy Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n day...
4 5 2 2 1 2 1 2 1 9 3 3 3 3 3 2 2 2 1 1 1 4 10 4 10 8 6 4 16 9 8 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
2 1 4 5
2 seconds
256 megabytes
['implementation', '*1000']
A. Forgetting Thingstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation a + 1 = b with positive integers a and b, but Kolya forgot the numbers a and b. He does, how...
1 2
199 200
2 seconds
512 megabytes
['math', '*900']
G. Wooden Rafttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you are stuck on a desert island. The only way to save yourself is to craft a wooden raft and go to the sea. Fortunately, you have a hand-made saw and a forest nearby. Moreover, you've already cut...
1 9
4
2 seconds
256 megabytes
['binary search', 'math', 'number theory', '*3200']
F. Stack Exterminable Arraystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's look at the following process: initially you have an empty stack and an array s of the length l. You are trying to push array elements to the stack in the order s_1, s_2, s_3, \dots s_...
3 5 2 1 1 2 2 6 1 2 1 1 3 2 9 3 1 2 2 1 6 6 3 3
4 1 8
2 seconds
256 megabytes
['data structures', 'divide and conquer', 'dp', 'hashing', '*2600']
E. Paint the Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i.Let's define the k-coloring...
2 4 1 1 2 5 3 1 2 3 4 3 7 2 1 2 5 1 3 4 1 4 2 2 5 1 2 6 2 4 7 3
8 14
2 seconds
256 megabytes
['dp', 'sortings', 'trees', '*2100']
D. Sequence Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a_1, a_2, \dots, a_n, consisting of integers.You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the begi...
3 7 3 1 6 6 3 1 1 8 1 1 4 4 4 7 8 8 7 4 2 5 2 6 2 7
2 0 1
2 seconds
256 megabytes
['dp', 'greedy', 'two pointers', '*2000']
C. Save the Naturetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!You have n tickets to sell. The price of the i-th ticket is p...
4 1 100 50 1 49 1 100 8 100 200 100 200 100 200 100 100 10 2 15 3 107 3 1000000000 1000000000 1000000000 50 1 50 1 3000000000 5 200 100 100 100 100 69 5 31 2 90
-1 6 3 4
2 seconds
256 megabytes
['binary search', 'greedy', '*1600']
B. Strings Equalizationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.During each operation you choose tw...
3 xabb aabx technocup technocup a z
YES YES NO
1 second
256 megabytes
['strings', '*1000']
A. CMEtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are C...
4 2 5 8 11
2 1 0 1
1 second
256 megabytes
['math', '*800']
G. Graph And Numberstime limit per test3.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph with n vertices and m edges. You have to write a number on each vertex of this graph, each number should be either 0 or 1. After that, you write a number on each ...
6 5 1 2 2 3 3 4 4 5 5 1
20
3.5 seconds
512 megabytes
['bitmasks', 'brute force', 'combinatorics', 'dp', 'meet-in-the-middle', '*2900']
F. Choose a Squaretime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya recently found a game "Choose a Square". In this game, there are n points numbered from 1 to n on an infinite field. The i-th point has coordinates (x_i, y_i) and cost c_i.You have to choose a s...
6 0 0 2 1 0 -5 1 1 3 2 3 4 1 4 -4 3 1 -1
4 1 1 3 3
6 seconds
256 megabytes
['binary search', 'data structures', 'sortings', '*2400']
E. Game With Stringtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob play a game. Initially they have a string s_1, s_2, \dots, s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the play...
3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X
YES NO YES
3 seconds
256 megabytes
['games', '*2500']
D. Make The Fence Great Againtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards...
3 3 2 4 2 1 3 5 3 2 3 2 10 2 6 4 1 7 3 3 2 6 1000000000 2
2 9 0
2 seconds
256 megabytes
['dp', '*1800']
C. Perfect Teamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She...
6 1 1 1 3 6 0 0 0 0 0 1 1 10 1 10 4 4 1
1 3 0 0 1 3
2 seconds
256 megabytes
['binary search', 'math', '*1200']
B. Knightstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.A knight is a chess piece that can a...
3
WBW BBB WBW
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1100']
A. 2048 Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations with this mul...
6 4 1024 512 64 512 1 2048 3 64 512 2 2 4096 4 7 2048 2 2048 2048 2048 2048 2048 2 2048 4096
YES YES NO NO YES YES
1 second
256 megabytes
['brute force', 'greedy', 'math', '*1000']
G. Geolocationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are working for the Gryzzl company, headquartered in Pawnee, Indiana.The new national park has been opened near Pawnee recently and you are to implement a geolocation system, so people won't get lost....
3 0 0 0 1 1 0 1 1 1 2
1 1 1
2 seconds
256 megabytes
['geometry', '*3400']
F. Gardener Alextime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGardener Alex loves to grow trees. We remind that tree is a connected acyclic graph on n vertices. Today he decided to grow a rooted binary tree. A binary tree is a tree where any vertex has no more tha...
4 1 2 3 4
3 3
2 seconds
256 megabytes
['binary search', 'data structures', '*2700']
E. Tourismtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlex decided to go on a touristic trip over the country.For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. T...
5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2
27
2 seconds
256 megabytes
['dfs and similar', 'dp', 'dsu', 'graphs', 'greedy', 'trees', '*2200']
D. Alex and Juliantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBoy Dima gave Julian a birthday present — set B consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!Julian was almost ...
3 1 2 3
1 2
2 seconds
256 megabytes
['bitmasks', 'math', 'number theory', '*1900']
C. Substring Game in the Lessontime limit per test2 secondsmemory limit per test256 mebibytesinputstandard inputoutputstandard outputMike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string s and a number k (0 ...
abba
Mike Ann Ann Mike
2 seconds
256 mebibytes
['games', 'greedy', 'strings', '*1300']
B. Multiplication Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table M with n rows and n columns such that M_{ij}=a_i \cdot a_j where a_1, \dots, a_n is som...
5 0 4 6 2 4 4 0 6 2 4 6 6 0 3 6 2 2 3 0 2 4 4 6 2 0
2 2 3 1 2
2 seconds
256 megabytes
['math', 'number theory', '*1300']
A. Cardstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha st...
4 ezor
0
2 seconds
256 megabytes
['implementation', 'sortings', 'strings', '*800']
G. Harvestertime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is Bubble Cup finals season and farmer Johnny Bubbles must harvest his bubbles. The bubbles are in a rectangular bubblefield formed of N x M square parcels divided into N rows and M columns. The parcel...
2 2 1 2 3 4
10
0.5 seconds
256 megabytes
['implementation', '*2000']
C. Periodic integer numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice became interested in periods of integer numbers. We say positive X integer number is periodic with length L if there exists positive integer number P with L digits such that X can be writ...
3 123456
124124
1 second
256 megabytes
['implementation', 'strings', '*1700']
I. The Light Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor her birthday Alice received an interesting gift from her friends – The Light Square. The Light Square game is played on an N \times N lightbulbs square board with a magical lightbulb bar of size ...
2 11 11 00 01 11
-1
2 seconds
256 megabytes
['2-sat', 'dfs and similar', 'greedy', '*2100']
H. Function Compositiontime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe are definitely not going to bother you with another generic story when Alice finds about an array or when Alice and Bob play some stupid game. This time you'll get a simple, plain text.First...
10 2 3 1 5 6 4 2 10 7 7 5 10 1 5 7 10 6 1 1 10 8
3 0 1 1 0
0.5 seconds
256 megabytes
['dfs and similar', '*2900']
G. Alpha planetary systemtime limit per test1 secondmemory limit per test128 megabytesinputstandard inputoutputstandard outputThree planets X, Y and Z within the Alpha planetary system are inhabited with an advanced civilization. The spaceports of these planets are connected by interplanetary space shuttles. The flight...
10 15 XXXXYYYZZZ 0 4 0 5 0 6 4 1 4 8 1 7 1 9 7 2 7 5 5 3 6 2 6 9 8 2 8 3 9 3
0 4 2 0 5 2 0 6 2 4 1 1 4 8 1 1 7 2 1 9 3 7 2 2 7 5 1 5 3 1 6 2 1 6 9 1 8 2 3 8 3 1 9 3 1
1 second
128 megabytes
['constructive algorithms', 'graphs', 'shortest paths', '*3000']
F. Workout plantime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to...
5 10000 10000 30000 30000 40000 20000 20000 5 2 8 3 6
5
1 second
256 megabytes
['data structures', 'greedy', '*1500']
E. Product Tuplestime limit per test8 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputWhile roaming the mystic areas of Stonefalls, in order to drop legendary loot, an adventurer was given a quest as follows. He was given an array A = {a_1,a_2,...,a_N } of length N, and a number K.Defin...
5 2 1 2 3 4 5 3 1 6 1 1 1 6 5 2 2 6 2 3 1
85 127 63
8 seconds
128 megabytes
['divide and conquer', 'fft', '*2500']
D. Xor Spanning Treetime limit per test2 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputIn the galaxy far far away is the ancient interplanetary republic of Bubbleland, consisting of N planets. Between them, there are M bidirectional wormholes, each connecting a pair of planets. Bubble...
6 6 4 1 5 5 2 1 6 3 2 1 2 6 1 3 3 2 3 4
1 1
2 seconds
128 megabytes
['divide and conquer', 'fft', 'graphs', '*2400']
C. Jumping Transformerstime limit per test4 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputYou, the mighty Blackout, are standing in the upper-left (0,0) corner of NxM matrix. You must move either right or down each second. There are K transformers jumping around the matrix in the foll...
3 3 5 0 1 1 0 7 1 1 1 0 10 1 1 1 1 2 1 1 1 2 2 0 1 1 2 3
9
4 seconds
128 megabytes
['dp', '*2600']
B. Guarding warehousestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob Bubblestrong just got a new job as security guard. Bob is now responsible for safety of a collection of warehouses, each containing the most valuable Bubble Cup assets - the high-quality bubble...
5 4 1 1 1 3 3 3 3 1 4 4 3 6 2 6 0 4 0 6 -5 3 -4 4 -3 4 -2 3 -3 2 -4 2 3 0 -1 1 -3 -1 -3 4 1 -4 1 -6 -1 -6 -1 -4
13.333333333333
1 second
256 megabytes
['data structures', 'geometry', '*3000']
A. BubbleReactortime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are in charge of the BubbleReactor. It consists of N BubbleCores connected with N lines of electrical wiring. Each electrical wiring connects two distinct BubbleCores. There are no BubbleCores con...
10 0 1 0 3 0 4 0 9 1 2 2 3 2 7 4 5 4 6 7 8
51
1.5 seconds
256 megabytes
['dp', 'graphs', '*2800']
F. Forced Online Queries Problemtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.You are asked to perform some queries on the graph. Let last be the answer to the lat...
5 9 1 1 2 1 1 3 2 3 2 1 2 4 2 3 4 1 2 4 2 3 4 1 1 3 2 4 3
1010
5 seconds
256 megabytes
['data structures', 'divide and conquer', 'dsu', 'graphs', 'trees', '*2600']
E. Sum Queries?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at le...
4 5 300 10001 20 20 2 1 3 1 1 310 2 1 3 2 3 3 2 3 4
-1 330 -1 40
2 seconds
256 megabytes
['data structures', 'greedy', 'implementation', 'math', '*2300']
D. Coloring Edgestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed graph with n vertices and m directed edges without self-loops or multiple edges.Let's denote the k-coloring of a digraph as following: you color each edge in one of k colors. Th...
4 5 1 2 1 3 3 4 2 4 1 4
1 1 1 1 1 1
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', '*2100']
C. The Number Of Good Substringstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary string s (recall that a string is binary if each character is either 0 or 1).Let f(t) be the decimal representation of integer t written in binary form (possibly w...
4 0110 0101 00001000 0001000
4 3 4 3
4 seconds
256 megabytes
['binary search', 'bitmasks', 'brute force', '*1700']
B. Zmei Gorynichtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! Initially Zmei Gorynich has x heads. You can deal n types of blows. If you d...
3 3 10 6 3 8 2 1 4 4 10 4 1 3 2 2 6 1 100 2 15 10 11 14 100
2 3 -1
1 second
256 megabytes
['greedy', 'math', '*1600']
A. Creating a Charactertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp f...
4 5 3 4 2 1 0 3 5 5 4 10 6
3 1 2 0
1 second
256 megabytes
['binary search', 'math', '*1300']
F. Wi-Fitime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou work as a system administrator in a dormitory, which has n rooms one after another along a straight hallway. Rooms are numbered from 1 to n.You have to connect all n rooms to the Internet.You can connect ea...
5 2 00100
3
2 seconds
256 megabytes
['data structures', 'dp', 'greedy', '*2100']
E2. Numerical Sequence (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between the easy and the hard versions is the maximum value of k.You are given an infinite sequence of form "112123123412345\dots" which consist of blocks of all...
5 1 3 20 38 56
1 2 5 2 0
2 seconds
256 megabytes
['binary search', 'math', '*2200']
E1. Numerical Sequence (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between the easy and the hard versions is the maximum value of k.You are given an infinite sequence of form "112123123412345\dots" which consist of blocks of all...
5 1 3 20 38 56
1 2 5 2 0
2 seconds
256 megabytes
['binary search', 'brute force', 'math', '*1900']
D. Swordstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has...
3 3 12 6
5 3
2 seconds
256 megabytes
['math', '*1300']
C. White Sheettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left co...
2 2 4 4 1 1 3 5 3 1 5 5
NO
1 second
256 megabytes
['geometry', 'math', '*1700']
B. Shootingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya ...
3 20 10 20
43 1 3 2
1 second
256 megabytes
['greedy', 'implementation', 'sortings', '*900']
A. Prefixestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n.He wants to modify his string so that every its prefix of even lengt...
4 bbbb
2 abba
1 second
256 megabytes
['strings', '*800']
F. Radio Stationstime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn addition to complaints about lighting, a lot of complaints about insufficient radio signal covering has been received by Bertown city hall recently. n complaints were sent to the mayor, all of which...
2 4 4 2 1 3 2 3 1 4 1 2 3 4 1 4 1 2 3 4
2 3 1 3
7 seconds
256 megabytes
['2-sat', '*2700']
E. Marblestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a c...
7 3 4 2 3 4 2 2
3
4 seconds
256 megabytes
['bitmasks', 'dp', '*2200']
D. Ticket Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased....
4 0523
Bicarp
1 second
256 megabytes
['games', 'greedy', 'math', '*1700']
C. Swap Letterstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp has got two strings s and t having equal length. Both strings consist of lowercase Latin letters "a" and "b". Monocarp wants to make these two strings s and t equal to each other. He can do the ...
4 abab aabb
2 3 3 3 2
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1500']
B. The Number of Productstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a_1, a_2, \dots, a_n consisting of n non-zero integers (i.e. a_i \ne 0). You have to calculate two following values: the number of pairs of indices (l, r) (l \le r) su...
5 5 -3 3 -1 1
8 7
2 seconds
256 megabytes
['combinatorics', 'dp', 'implementation', '*1400']
A. Yellow Cardstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a_1 players in the first team and a_...
2 3 5 1 8
0 4
1 second
256 megabytes
['greedy', 'implementation', 'math', '*1000']
H. Tiles Placementtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe new pedestrian zone in Moscow city center consists of n squares connected with each other by n - 1 footpaths. We define a simple path as a sequence of squares such that no square appears in this s...
7 4 1 3 2 3 3 4 4 5 5 6 5 7
Yes 1 1 2 3 4 1 1
3 seconds
512 megabytes
['constructive algorithms', 'dfs and similar', 'trees', '*2800']
G. Feeling Goodtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRecently biologists came to a fascinating conclusion about how to find a chameleon mood. Consider chameleon body to be a rectangular table n \times m, each cell of which may be green or blue and may chan...
2 2 6 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 1 1 1
-1 1 1 2 2 -1 -1 -1 1 1 2 2
3 seconds
512 megabytes
['bitmasks', 'data structures', '*3200']
F. Employmenttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputTwo large companies "Cecsi" and "Poca Pola" are fighting against each other for a long time. In order to overcome their competitor, "Poca Pola" started a super secret project, for which it has total n vaca...
10 3 1 5 5 10 4 6
3 1 2 3
2 seconds
512 megabytes
['greedy', 'sortings', '*2700']
E. Petya and Construction Settime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give ...
3 2 2 2
1 6 2 6 3 5 3 6 4 5
1 second
512 megabytes
['constructive algorithms', 'graphs', 'math', 'sortings', 'trees', '*2000']
D. Treasure Islandtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputAll of us love treasures, right? That's why young Vasya is heading for a Treasure Island.Treasure Island may be represented as a rectangular table n \times m which is surrounded by the ocean. Let us nu...
2 2 .. ..
2
1 second
512 megabytes
['dfs and similar', 'dp', 'flows', 'hashing', '*1900']
C. Bad Sequencetime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputPetya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his drea...
2 )(
Yes
1 second
512 megabytes
['data structures', 'greedy', '*1200']
B. Badgestime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many...
5 6 3
4
1 second
512 megabytes
['brute force', 'math', '*1100']
A. Optimal Currency Exchangetime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAndrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to ex...
100 60 70
40
1.5 seconds
512 megabytes
['brute force', 'math', '*1400']
G. Path Queriestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i.You are given m queries. The ...
7 5 1 2 1 3 2 3 2 4 1 4 5 2 5 7 4 3 6 2 5 2 3 4 1
21 7 15 21 3
3 seconds
256 megabytes
['divide and conquer', 'dsu', 'graphs', 'sortings', 'trees', '*1800']
F. Unstable String Sorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAuthors have come up with the string s consisting of n lowercase Latin letters.You are given two permutations of its indices (not necessary equal) p and q (both of length n). Recall that the perm...
3 2 1 2 3 1 3 2
YES abb
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'dsu', 'graphs', 'greedy', 'implementation', 'strings', '*2100']
E. Two Small Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t both of length 2 and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings s and t: "ab", "ca", "bb".You have to find a string res consis...
2 ab bc
YES acbbac
2 seconds
256 megabytes
['brute force', 'constructive algorithms', '*1900']
D2. Equalizing by Division (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the number of elements in the array.You are given an array a consisting of n integers. In one move you can choose any a_i a...
5 3 1 2 2 4 5
1
2 seconds
256 megabytes
['brute force', 'math', 'sortings', '*1600']
D1. Equalizing by Division (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the number of elements in the array.You are given an array a consisting of n integers. In one move you can choose any a_i a...
5 3 1 2 2 4 5
1
2 seconds
256 megabytes
['brute force', 'implementation', '*1500']
C. Book Readingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is reading a book consisting of n pages numbered from 1 to n. Every time he finishes the page with the number divisible by m, he writes down the last digit of this page number. For example, if n=...
7 1 1 10 1 100 3 1024 14 998244353 1337 123 144 1234312817382646 13
1 45 153 294 3359835 0 427262129093995
1 second
256 megabytes
['math', '*1200']
B. Bad Pricestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp analyzes the prices of the new berPhone. At his disposal are the prices for n last days: a_1, a_2, \dots, a_n, where a_i is the price of berPhone on the day i.Polycarp considers the price on the da...
5 6 3 9 4 6 7 5 1 1000000 2 2 1 10 31 41 59 26 53 58 97 93 23 84 7 3 2 1 2 3 4 5
3 0 1 8 2
1 second
256 megabytes
['data structures', 'implementation', '*1100']
A. Chips Movingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.You can perform each of the two following types of moves any (possibly,...
3 1 2 3
1
1 second
256 megabytes
['math', '*900']
I. Unusual Graphtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan on his birthday was presented with array of non-negative integers a_1, a_2, \ldots, a_n. He immediately noted that all a_i satisfy the condition 0 \leq a_i \leq 15.Ivan likes graph theory very much...
4 4 1 2 2 3 3 4 4 1
0 1 0 1
5 seconds
256 megabytes
['*special problem', 'graphs', '*3000']
H. Road Repair in Treelandtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities and n-1 two-way roads in Treeland. Each road connects a pair of different cities. From any city you can drive to any other, moving only along the roads. Cities are numbered ...
3 3 1 2 2 3 6 1 2 1 3 1 4 1 5 1 6 7 3 1 1 4 4 6 5 1 2 4 1 7
1 10 20 3 1 1 1 2 2 2 11 11 12 13 12 13
3 seconds
256 megabytes
['*special problem', 'binary search', 'dp', 'trees', '*3100']
G. King's Pathtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities and n-1 two-way roads in Treeland. Each road connects a pair of different cities. From any city you can drive to any other, moving only along the roads. Cities are numbered from 1 to n....
1 7 2 3 2 7 1 1 3 7 1 2 3 1 2 3 1 7 4 1 2 6 2 3 2 4 5 4
Yes 4 1 4 2 6
5 seconds
256 megabytes
['*special problem', 'math', 'trees', '*2500']
F. kotlinkotlinkotlinkotlin...time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp really likes writing the word "kotlin". He wrote this word several times in a row without spaces. For example, he could write the string like "kotlinkotlinkotlinkotlin".Polycarp s...
2 lin kot
2 1
3 seconds
256 megabytes
['*special problem', 'graphs', 'implementation', 'strings', '*2300']
E. Double Permutation Inc.time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp recently became an employee of the company "Double Permutation Inc." Now he is a fan of permutations and is looking for them everywhere!A permutation in this problem is a sequence of ...
5 1 2 3 2 1
RBBBG
5 seconds
256 megabytes
['*special problem', 'binary search', 'greedy', '*2000']
D. Teamstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n table bowling players, the rating of the i-th player equals r_i. Compose a maximum number of teams in a such way that: each player belongs to at most one team; each team contains exactly a+b playe...
12 1 2 2 1 1 2 2 2 2 2 3 3 4 6 6
3
3 seconds
256 megabytes
['*special problem', 'binary search', 'greedy', 'math', '*2000']
C. Ice Creamtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSummer in Berland lasts n days, the price of one portion of ice cream on the i-th day is c_i. Over the summer, Tanya wants to eat exactly k portions of ice cream. At the same time, on the i-th day, she deci...
3 7 3 5 6 0 3 4 3 3 3
31
3 seconds
256 megabytes
['*special problem', 'greedy', 'sortings', '*1700']
B. Traveling Around the Golden Ring of Berlandtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Golden Ring is the special tourist route in Berland. This route consists of n cities and the cyclic railway route. Cities are numbered from 1 to n so that: the next ci...
3 1 0 0
1
3 seconds
256 megabytes
['*special problem', 'implementation', '*1500']
A. Three Problemstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is choosing three problems for creating a programming test. Totally he has n problems in his list. The complexity of the i-th problem equals r_i. All problems are numerated from 1 to n.Help Po...
6 3 1 4 1 5 9
4 1 3
3 seconds
256 megabytes
['*special problem', 'implementation', '*1000']
G. Mateusz and Escape Roomtime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMateusz likes to travel! However, on his 42nd visit to Saint Computersburg there is not much left to sightsee. That's why he decided to go to an escape room with his friends!The team has solve...
5 0 2 3 1 2 3 4 3 3 4 3 3 4 3 3
4
7 seconds
256 megabytes
['dp', '*3500']