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. Minimum Differencetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer array a of size n.You have to perform m queries. Each query has one of two types: "1 l r k" — calculate the minimum value dif such that there are exist k distinct integer...
12 11 2 1 1 2 1 1 3 2 1 1 3 3 1 2 10 3 1 2 11 3 2 7 2 1 3 9 2 1 1 12 1 1 1 12 4 2 12 4 1 1 12 4 2 1 5 1 3 12 2 1 1 4 3
5 4 1 0 -1 5 0 1
5 seconds
256 megabytes
['data structures', 'hashing', 'sortings', 'two pointers', '*3100']
F. Lanternstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n lanterns in a row. The lantern i is placed in position i and has power equal to p_i.Each lantern can be directed to illuminate either some lanterns to the left or some lanterns to the right. If t...
4 8 0 0 3 1 1 1 1 2 2 1 1 2 2 2 2 0 1
YES RRLLLLRL YES RL YES RL NO
2 seconds
256 megabytes
['binary search', 'data structures', 'dp', '*3000']
E. Pattern Matchingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n patterns p_1, p_2, \dots, p_n and m strings s_1, s_2, \dots, s_m. Each pattern p_i consists of k characters that are either lowercase Latin letters or wildcard characters (denoted by ...
5 3 4 _b_d __b_ aaaa ab__ _bcd abcd 4 abba 2 dbcd 5
YES 3 2 4 5 1
2 seconds
256 megabytes
['bitmasks', 'data structures', 'dfs and similar', 'graphs', 'hashing', 'sortings', 'strings', '*2300']
D. Journeytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n + 1 cities, numbered from 0 to n. n roads connect these cities, the i-th road connects cities i - 1 and i (i \in [1, n]).Each road has a direction. The directions are given by a string of n charac...
2 6 LRRRLL 3 LRL
1 3 2 3 1 3 2 1 4 1 4
2 seconds
512 megabytes
['dfs and similar', 'dp', 'dsu', 'implementation', '*1700']
C. Longest Simple Cycletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n chains, the i-th chain consists of c_i vertices. Vertices in each chain are numbered independently from 1 to c_i along the chain. In other words, the i-th chain is the undirected graph...
3 4 3 4 3 3 -1 1 2 2 -1 2 2 3 2 5 6 -1 5 -1 1 3 3 5 2 -1 1 1 -1 3 5
7 11 8
2 seconds
256 megabytes
['dp', 'graphs', 'greedy', '*1600']
B. Inflationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a statistic of price changes for one product represented as an array of n positive integers p_0, p_1, \dots, p_{n - 1}, where p_0 is the initial price of the product and p_i is how the price was in...
2 4 1 20100 1 202 202 3 100 1 1 1
99 0
2 seconds
256 megabytes
['binary search', 'brute force', 'greedy', 'math', '*1300']
A. K-divisible Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and k.You should create an array of n positive integers a_1, a_2, \dots, a_n such that the sum (a_1 + a_2 + \dots + a_n) is divisible by k and maximum element in a is minim...
4 1 5 4 3 8 8 8 17
5 2 1 3
1 second
256 megabytes
['binary search', 'constructive algorithms', 'greedy', 'math', '*1000']
G. Strange Beautytime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp found on the street an array a of n elements.Polycarp invented his criterion for the beauty of an array. He calls an array a beautiful if at least one of the following conditions must be met f...
4 5 7 9 3 14 63 3 2 14 42 4 45 9 3 18 3 2 2 8
2 0 1 0
5 seconds
256 megabytes
['dp', 'math', 'number theory', 'sortings', '*1900']
F. Unusual Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two binary square matrices a and b of size n \times n. A matrix is called binary if each of its elements is equal to 0 or 1. You can do the following operations on the matrix a arbitrary ...
3 3 110 001 110 000 000 000 3 101 010 101 010 101 010 2 01 11 10 10
YES YES NO
2 seconds
256 megabytes
['2-sat', 'brute force', 'constructive algorithms', '*1900']
E. Advertising Agencytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of n different bloggers. Blogger numbere...
3 4 3 1 3 1 2 4 2 1 1 1 1 2 1 1 2
2 6 1
2 seconds
256 megabytes
['combinatorics', 'math', 'sortings', '*1600']
D. Cleaning the Phonetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp often uses his smartphone. He has already installed n applications on it. Application with number i takes up a_i units of memory.Polycarp wants to free at least m units of memory (by removi...
5 5 7 5 3 2 1 4 2 1 1 2 1 1 3 2 1 5 10 2 3 2 3 2 1 2 1 2 1 4 10 5 1 3 4 1 2 1 2 4 5 3 2 1 2 2 1 2 1
2 -1 6 4 3
1 second
256 megabytes
['binary search', 'dp', 'sortings', 'two pointers', '*1800']
C. Ball in Berlandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a ball, which will be attended by pairs of boys and girls.Each class mu...
3 3 4 4 1 1 2 3 2 3 2 4 1 1 1 1 1 2 2 4 1 1 2 2 1 2 1 2
4 0 2
2 seconds
256 megabytes
['combinatorics', 'graphs', 'math', '*1400']
B. New Year's Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp remembered the 2020-th year, and he is happy with the arrival of the new 2021-th year. To remember such a wonderful moment, Polycarp wants to represent the number n as the sum of a certain ...
5 1 4041 4042 8081 8079
NO YES YES YES NO
2 seconds
256 megabytes
['brute force', 'dp', 'math', '*900']
A. Odd Divisortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer n. Check if n has an odd divisor, greater than one (does there exist such a number x (x > 1) that n is divisible by x and x is odd).For example, if n=6, then there is x=3. If n=4,...
6 2 3 4 5 998244353 1099511627776
NO YES NO YES YES NO
2 seconds
256 megabytes
['math', 'number theory', '*900']
F. 1 2 3 4 ...time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor had a sequence d_1, d_2, \dots, d_n of integers. When Igor entered the classroom there was an integer x written on the blackboard.Igor generated sequence p using the following algorithm: initially,...
3 3 1 -1 2
3 3
5 seconds
256 megabytes
['dp', 'math', 'matrices', '*3000']
E. What Is It?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity per...
3 2 3 3
1 2 1 1 2 1 5 2 3 1 2 1 3 3 2 5 2 3 1 2 1 3 2 3
1 second
256 megabytes
['constructive algorithms', 'greedy', '*2500']
D. Cleaningtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring cleaning the coast, Alice found n piles of stones. The i-th pile has a_i stones.Piles i and i + 1 are neighbouring for all 1 \leq i \leq n - 1. If pile i becomes empty, piles i - 1 and i + 1 doesn't b...
5 3 1 2 1 3 1 1 2 5 2 2 2 1 3 5 2100 1900 1600 3000 1600 2 2443 2445
YES YES YES YES NO
2 seconds
256 megabytes
['data structures', 'dp', 'greedy', 'math', '*2200']
C. Array Destructiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou found a useless array a of 2n positive integers. You have realized that you actually don't need this array, so you decided to throw out all elements of a.It could have been an easy task, but it t...
4 2 3 5 1 2 3 1 1 8 8 64 64 2 1 1 2 4 5 1 2 3 4 5 6 7 14 3 11
YES 6 1 5 2 3 NO NO YES 21 14 7 3 11 5 6 2 4 3 1
1 second
256 megabytes
['brute force', 'constructive algorithms', 'data structures', 'greedy', 'implementation', 'sortings', '*1700']
B. Different Divisorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPositive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8.We gave you an integer d and asked yo...
2 1 2
6 15
1 second
256 megabytes
['binary search', 'constructive algorithms', 'greedy', 'math', 'number theory', '*1000']
A. Puzzle From the Futuretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the 2022 year, Mike found two binary integers a and b of length n (both of them are written only by digits 0 and 1) that can have leading zeroes. In order not to forget them, he wanted to con...
5 1 0 3 011 3 110 6 111000 6 001011
1 110 100 101101 101110
1 second
256 megabytes
['greedy', '*800']
G. Tilestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture ...
2 4 2 2 3
850
4 seconds
256 megabytes
['combinatorics', 'dp', 'fft', 'math', '*2800']
F. Strange Settime limit per test4 secondsmemory limit per test32 megabytesinputstandard inputoutputstandard outputNote that the memory limit is unusual.You are given an integer n and two sequences a_1, a_2, \dots, a_n and b_1, b_2, \dots, b_n.Let's call a set of integers S such that S \subseteq \{1, 2, 3, \dots, n\} s...
9 4 7 3 4 5 6 7 8 13 -2 3 -19 5 -6 7 -8 9 1
16
4 seconds
32 megabytes
['flows', 'math', '*2700']
E. Minimum Pathtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a weighted undirected connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Let's define the weight of the...
5 4 5 3 4 2 1 1 3 2 2 2 4 2
1 2 2 4
3 seconds
256 megabytes
['graphs', 'shortest paths', '*2400']
D. Programtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types: increase x by 1; decrease x by 1. You are given m que...
2 8 4 -+--+--+ 1 8 2 8 2 5 1 1 4 10 +-++ 1 1 1 2 2 2 1 3 2 3 3 3 1 4 2 4 3 4 4 4
1 2 4 4 3 3 4 2 3 2 1 2 2 2
2 seconds
256 megabytes
['data structures', 'dp', 'implementation', 'strings', '*1700']
C. No More Inversionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a sequence a with n elements 1, 2, 3, \dots, k - 1, k, k - 1, k - 2, \dots, k - (n - k) (k \le n < 2k).Let's call as inversion in a a pair of indices i < j such that a[i] > a[j].Suppose, y...
4 1 1 2 2 3 2 4 3
1 1 2 2 1 1 3 2
2 seconds
256 megabytes
['constructive algorithms', 'math', '*1500']
B. String LCMtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a multiplication operation between a string a and a positive integer x: a \cdot x is the string that is a result of writing x copies of a one after another. For example, "abc" \cdot~2~= "abcab...
3 baba ba aa aaa aba ab
baba aaaaaa -1
2 seconds
256 megabytes
['brute force', 'math', 'number theory', 'strings', '*1000']
A. Replacing Elementstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a_1, a_2, \dots, a_n. All a_i are positive integers.In one step you can choose three distinct indices i, j, and k (i \neq j; i \neq k; j \neq k) and assign the sum of a_j and a_k ...
3 5 3 2 3 2 5 4 3 4 2 4 4 5 4 2 1 5 3 6
NO YES YES
2 seconds
256 megabytes
['greedy', 'implementation', 'math', 'sortings', '*800']
G. Moving to the Capitaltime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Berland. The city numbered 1 is the capital. Some pairs of cities are connected by a one-way road of length 1.Before the trip, Polycarp for each city found out the value of...
3 6 7 1 2 1 3 2 5 2 4 5 1 3 6 6 2 2 2 1 2 2 1 6 8 1 2 1 5 2 6 6 1 2 3 3 4 4 2 5 4
0 0 1 2 0 1 0 0 0 0 2 1 1 0
4 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'shortest paths', '*2100']
F. New Year's Puzzletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery year Santa Claus gives gifts to all children. However, each country has its own traditions, and this process takes place in different ways. For example, in Berland you need to solve the New Ye...
3 5 2 2 2 1 4 3 2 2 1 2 3 6 4 2 1 2 3 2 4 2 6
YES NO NO
2 seconds
256 megabytes
['brute force', 'dp', 'graph matchings', 'greedy', 'sortings', '*2100']
E. Correct Placementtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has invited n friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side.Each friend is charact...
4 3 3 4 5 4 3 3 3 1 3 2 2 3 1 4 2 2 3 1 6 3 5 4 4 2 2 2 3 1 1 4 4
-1 3 -1 -1 -1 -1 -1 -1 2 2 3 3 -1 3
4 seconds
256 megabytes
['binary search', 'data structures', 'dp', 'sortings', 'two pointers', '*1700']
D. Even-Odd Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring their New Year holidays, Alice and Bob play the following game using an array a of n integers: Players take turns, Alice moves first. Each turn a player chooses any element and removes it from...
4 4 5 2 7 3 3 3 2 1 4 2 2 2 2 2 7 8
Bob Tie Alice Alice
2 seconds
256 megabytes
['dp', 'games', 'greedy', 'sortings', '*1200']
C. Long Jumpstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp found under the Christmas tree an array a of n elements and instructions for playing with it: At first, choose index i (1 \leq i \leq n) — starting position in the array. Put the chip at the ind...
4 5 7 3 1 2 3 3 2 1 4 6 2 1000 2 3 995 1 5 1 1 1 1 1
7 6 1000 5
2 seconds
256 megabytes
['dp', 'graphs', '*1100']
B. Fair Divisiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob received n candies from their parents. Each candy weighs either 1 gram or 2 grams. Now they want to divide all candies among themselves fairly so that the total weight of Alice's candies i...
5 2 1 1 2 1 2 4 1 2 1 2 3 2 2 2 3 2 1 2
YES NO YES NO NO
2 seconds
256 megabytes
['dp', 'greedy', 'math', '*800']
A. Cards for Friendstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor the New Year, Polycarp decided to send postcards to all his n friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size w \times h, which can be cu...
5 2 2 3 3 3 2 5 10 2 11 13 1 1 4 4
YES NO YES YES YES
1 second
256 megabytes
['greedy', 'math', '*800']
B. Strange Listtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have given an array a of length n and an integer x to a brand new robot. What the robot does is the following: it iterates over the elements of the array, let the current element be q. If q is divisib...
2 1 2 12 4 2 4 6 8 2
36 44
1 second
256 megabytes
['brute force', 'greedy', 'implementation', 'math', '*1100']
A. Strange Partitiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n, and an integer x. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their su...
2 3 3 3 6 9 3 3 6 4 11
6 6 7 8
1 second
256 megabytes
['greedy', 'math', 'number theory', '*900']
F. Strange Coveringtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n points on a plane. Please find the minimum sum of areas of two axis-aligned rectangles, such that each point is contained in at least one of these rectangles.Note that the chosen rect...
3 2 9 1 1 6 2 8 10 0 7 4 0 0 1 1 9 9 10 10
0 0 2
6 seconds
256 megabytes
['divide and conquer', '*3500']
E. Strange Permutationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice had a permutation p_1, p_2, \ldots, p_n. Unfortunately, the permutation looked very boring, so she decided to change it and choose some non-overlapping subranges of this permutation and reve...
2 3 1 9 1 2 3 1 1 2 1 3 1 1 2 2 2 3 2 1 3 2 3 3 3 6 4 4 6 5 4 3 1 2 1 1 3 14 1 59 2 6
1 2 3 1 3 2 2 1 3 1 4 -1 5
3 seconds
256 megabytes
['binary search', 'combinatorics', 'data structures', 'dp', 'graphs', 'implementation', 'two pointers', '*3200']
D. Strange Housingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudents of Winter Informatics School are going to live in a set of houses connected by underground passages. Teachers are also going to live in some of these houses, but they can not be accommodated r...
2 3 2 3 2 2 1 4 2 1 4 2 3
YES 2 1 3 NO
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'graph matchings', 'graphs', 'greedy', '*2200']
C. Strange Shuffletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.n people sitting in a circle are trying to shuffle a deck of cards. The players are numbered from 1 to n, so that players i and i+1 are neighbours (as well as players 1 a...
4 2 2 1 2 3 2
? 1 ? 1 ? 2 ? 3 ? 4 ! 2
1 second
256 megabytes
['binary search', 'brute force', 'constructive algorithms', 'interactive', '*2500']
B. Strange Definitiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet us call two integers x and y adjacent if \frac{lcm(x, y)}{gcd(x, y)} is a perfect square. For example, 3 and 12 are adjacent, but 6 and 9 are not.Here gcd(x, y) denotes the greatest common divi...
2 4 6 8 4 2 1 0 6 12 3 20 5 80 1 1 1
2 3
2 seconds
256 megabytes
['bitmasks', 'graphs', 'hashing', 'math', 'number theory', '*1900']
A. Strange Birthday Partytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya organized a strange birthday party. He invited n friends and assigned an integer k_i to the i-th of them. Now Petya would like to give a present to each of them. In the nearby shop there a...
2 5 4 2 3 4 3 2 3 5 12 20 5 5 5 4 3 2 1 10 40 90 160 250
30 190
1 second
256 megabytes
['binary search', 'dp', 'greedy', 'sortings', 'two pointers', '*1300']
F. Power Socketstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output// We decided to drop the legend about the power sockets but feel free to come up with your own :^)Define a chain: a chain of length 1 is a single vertex; a chain of length x is a chain of length x-1...
1 2 3
2
4 seconds
256 megabytes
['binary search', 'data structures', 'greedy', '*2600']
E. A Bit Similartime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputLet's call two strings a and b (both of length k) a bit similar if they have the same character in some position, i. e. there exists at least one i \in [1, k] such that a_i = b_i.You are given a binary...
7 4 2 0110 4 2 1001 9 3 010001110 9 3 101110001 10 3 0101110001 10 10 1111111111 11 10 11111111110
YES 11 YES 00 YES 010 YES 101 NO YES 0000000001 YES 0000000010
2 seconds
1024 megabytes
['bitmasks', 'brute force', 'hashing', 'string suffix structures', 'strings', 'two pointers', '*2400']
D. Ceil Divisionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a_1, a_2, \dots, a_n where a_i = i.In one step, you can choose two indices x and y (x \neq y) and set a_x = \left\lceil \frac{a_x}{a_y} \right\rceil (ceiling function).Your goal is to...
2 3 4
2 3 2 3 2 3 3 4 4 2 4 2
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'math', 'number theory', '*1700']
C. Building a Fencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou want to build a fence that will consist of n equal sections. All sections have a width equal to 1 and height equal to k. You will place all sections in one line side by side.Unfortunately, the gr...
3 6 3 0 0 2 5 1 1 2 3 0 2 3 2 3 0 2
YES YES NO
2 seconds
256 megabytes
['dp', 'greedy', 'implementation', 'two pointers', '*1600']
B. Red and Bluetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMonocarp had a sequence a consisting of n + m integers a_1, a_2, \dots, a_{n + m}. He painted the elements into two colors, red and blue; n elements were painted red, all other m elements were painted bl...
4 4 6 -5 7 -3 3 2 3 -4 2 1 1 4 10 -3 2 2 5 -1 -2 -3 -4 -5 5 -1 -2 -3 -4 -5 1 0 1 0
13 13 0 0
2 seconds
512 megabytes
['dp', 'greedy', '*1000']
A. Regular Bracket Sequencetime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputA bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters + and 1 into this sequence. For example, sequences (())(), () and (()(())...
5 () (?) (??) ??() )?(?
YES NO YES YES NO
1 second
512 megabytes
['constructive algorithms', 'greedy', '*1000']
N. Waste Sortingtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe progress is not standing still in Berland. Recently all garbage containers in Bertown, the capital of Berland, were replaced by differentiated recycling bins, each accepting some category of waste. ...
7 1 2 3 1 2 3 0 0 2 2 3 1 2 3 1 0 2 2 3 1 2 3 0 1 1 2 5 1 2 3 1 1 0 0 0 0 0 0 0 0 0 0 4 1 0 0 0 0 13 37 42 0 0 0 40 47
YES YES NO YES YES NO YES
2 seconds
512 megabytes
['greedy', 'implementation', '*900']
M. Similar Setstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given n sets of integers. The i-th set contains k_i integers.Two sets are called similar if they share at least two common elements, i. e. there exist two integers x and y such that x \ne y, and t...
342 1 103 1 3 55 5 4 3 2 13 10 20 3034 1 2 3 44 2 3 4 54 3 4 5 623 1 3 53 4 3 2
2 3 1 2 -1
1 second
512 megabytes
['data structures', 'graphs', 'implementation', '*2300']
L. Prime Divisors Selectiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSuppose you have a sequence of k integers A = [a_1, a_2, \dots , a_k] where each a_i \geq 2. A sequence of prime integers P = [p_1, p_2, \dots, p_k] is called suitable for the sequence A if a...
Input3 32 4 6
Output0
2 seconds
512 megabytes
['binary search', 'greedy', 'math', 'number theory', '*2700']
K. The Robottime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates (0, 0). He will execute commands which are described by a string of capi...
4LRUUDLLLUUDDDUUUUU
-1 0 1 2 0 0 0 1
2 seconds
512 megabytes
['brute force', 'implementation', '*1600']
J. Road Reformtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city...
44 5 74 1 31 2 52 3 82 4 13 4 44 6 51 2 11 3 11 4 22 4 14 3 13 2 13 2 101 2 81 3 105 5 151 2 173 1 152 3 101 4 142 5 8
1 3 0 0
2 seconds
512 megabytes
['dsu', 'graphs', 'greedy', '*1800']
I. Plane Tilingtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given five integers n, dx_1, dy_1, dx_2 and dy_2. You have to select n distinct pairs of integers (x_i, y_i) in such a way that, for every possible pair of integers (x, y), there exists exactly on...
4 2 0 0 2
YES 0 0 0 1 1 0 1 1
1 second
512 megabytes
['geometry', 'implementation', 'math', '*2500']
H. K and Medianstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence ...
43 3 117 3 31 5 710 5 34 5 613 7 71 3 5 7 9 11 12
NO YES NO YES
2 seconds
512 megabytes
['constructive algorithms', 'greedy', 'math', '*2200']
G. Hobbitstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe hobbits Frodo and Sam are carrying the One Ring to Mordor. In order not to be spotted by orcs, they decided to go through the mountains.The mountain relief can be represented as a polyline with n points (x...
6 10 10 40 20 10 25 30 30 15 50 15 65 30
70.4034587602
1 second
512 megabytes
['binary search', 'geometry', '*2500']
F. Full Turntime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i).At the same moment of time, all persons will start to rotate clockwise ...
320 0 0 11 0 2 030 0 1 11 1 0 01 0 2 060 0 0 11 0 1 22 0 2 33 0 3 -54 0 4 -55 0 5 -5
0 1 9
2 seconds
512 megabytes
['geometry', 'hashing', 'number theory', '*1700']
E. Four Segmentstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMonocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 \le i \le 4). These segments can intersect with each other, and each segment s...
4 1 2 3 4 5 5 5 5 3 1 4 1 100 20 20 100
3 25 3 2000
2 seconds
512 megabytes
['greedy', '*800']
D. Firecrackerstime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider a long corridor which can be divided into n square cells of size 1 \times 1. These cells are numbered from 1 to n from left to right.There are two people in this corridor, a hooligan and a secur...
37 2 3 61 47 2 3 65 17 2 3 64 4
2 1 1
4 seconds
512 megabytes
['binary search', 'sortings', '*1700']
C. Berpizzatime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMonocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first dif...
8 1 8 1 10 1 6 3 2 1 9 2 3
2 1 3 4
5 seconds
512 megabytes
['data structures', 'implementation', '*1400']
B. Bakerytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMonocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops.Monocarp plans that the bakery will work for n days. On the i-th day, a_i loa...
5 4 5 2 1 3 7 1 3 4 10
4 2 1 0
2 seconds
512 megabytes
['data structures', 'dsu', '*2900']
A. LaIStime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's call a sequence b_1, b_2, b_3 \dots, b_{k - 1}, b_k almost increasing if \min(b_1, b_2) \le \min(b_2, b_3) \le \dots \le \min(b_{k - 1}, b_k). In particular, any sequence with no more than two elements is ...
381 2 7 3 2 1 2 322 174 1 5 2 6 3 7
6 2 7
3 seconds
512 megabytes
['data structures', 'dp', 'greedy', '*2200']
E. Distinctive Roots in a Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree with n vertices. Each vertex i has a value a_i associated with it.Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following hol...
5 2 5 1 1 4 1 2 1 3 2 4 2 5
3
3 seconds
256 megabytes
['data structures', 'dfs and similar', 'dp', 'trees', '*2500']
D. Sum of Pathstime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputThere are n cells, numbered 1,2,\dots, n from left to right. You have to place a robot at any cell initially. The robot must make exactly k moves.In one move, the robot must move one cell to the left or...
5 1 5 3 5 1 4 2 1 9 2 4 3 6 4 6 5 2
62 58 78 86 86
3 seconds
1024 megabytes
['combinatorics', 'dp', 'math', '*2200']
C. Three Bagstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three bags. Each bag contains a non-empty multiset of numbers. You can perform a number of operations on these bags. In one operation, you can choose any two non-empty bags, and choose one num...
2 4 1 1 2 6 3 4 5 5
20
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1900']
B. Hills And Valleystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of n integers a_1, a_2, ..., a_n. Let us call an index j (2 \le j \le {{n-1}}) a hill if a_j > a_{{j+1}} and a_j > a_{{j-1}}; and let us call it a valley if a_j < a_{{j+1}} a...
4 3 1 5 3 5 2 2 2 2 2 6 1 6 2 5 2 10 5 1 6 2 5 1
0 0 1 0
1 second
256 megabytes
['brute force', 'implementation', '*1700']
A. Wizard of Orztime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0.Every second, the digit shown by each panel increases by 1. In other words, a...
2 1 2
9 98
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', '*900']
I. The Riddle of the Sphinxtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhat walks on four feet in the morning, two in the afternoon, and three at night?This is an interactive problem. This problem doesn't support hacks.Sphinx's duty is to guard the city of Thebes...
5 3 yes no no no no yes
5 101 5 110 4 100 3 101 2 001 1 000 0 110
1 second
256 megabytes
['binary search', 'data structures', 'data structures', 'interactive', '*3400']
H. Finding satisfactory solutionstime limit per test5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputGetting so far in this contest is not an easy feat. By solving all the previous problems, you have impressed the gods greatly. Thus, they decided to spare you the story for this proble...
2 2 1
1
5 seconds
1024 megabytes
['combinatorics', 'dp', 'graphs', 'greedy', 'math', '*3300']
G. Song of the Sirenstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Whoso in ignorance draws near to them and hears the Sirens' voice, he nevermore returns.Homer, OdysseyIn the times of Jason and the Argonauts, it was well known that sirens use the sound of their ...
3 3 aa bcd 2 aba 3 ca 3 aa
2 2 8
2 seconds
256 megabytes
['combinatorics', 'divide and conquer', 'hashing', 'math', 'string suffix structures', 'strings', '*2600']
F. Euclid's nightmaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare. In his bad dream E...
3 2 1 1 1 2 2 2 1
4 2 1 2
2 seconds
256 megabytes
['bitmasks', 'dfs and similar', 'dsu', 'graphs', 'greedy', 'math', 'sortings', '*2100']
E. Apollo versus Pantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnly a few know that Pan and Apollo weren't only battling for the title of the GOAT musician. A few millenniums later, they also challenged each other in math (or rather in fast calculations). The t...
8 2 1 7 3 1 2 4 4 5 5 5 5 5 6 2 2 1 0 1 0 1 1 6 1 12 123 1234 12345 123456 5 536870912 536870911 1152921504606846975 1152921504606846974 1152921504606846973
128 91 1600 505 0 1 502811676 264880351
2 seconds
256 megabytes
['bitmasks', 'brute force', 'math', '*1800']
D. 13th Labour of Heraclestime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on...
4 4 3 5 4 6 2 1 3 1 4 3 2 21 32 2 1 6 20 13 17 13 13 11 2 1 3 1 4 1 5 1 6 1 4 10 6 6 6 1 2 2 3 4 1
18 22 25 53 87 107 127 147 167 28 38 44
2.5 seconds
256 megabytes
['data structures', 'greedy', 'sortings', 'trees', '*1500']
C. Canine poetrytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of...
7 babba abaac codeforces zeroorez abcdcba bbbbbbb a
1 1 0 1 1 4 0
2 seconds
256 megabytes
['dp', 'greedy', 'strings', '*1300']
B. Last minute enhancementstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAthenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be me...
5 6 1 2 2 2 5 6 2 4 4 6 1 1 3 4 4 5 1 1 6 1 1 1 2 2 2
5 2 6 1 3
1 second
256 megabytes
['dp', 'greedy', '*800']
A. Bovine Dilemmatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArgus was charged with guarding Io, which is not an ordinary cow. Io is quite an explorer, and she wanders off rather frequently, making Argus' life stressful. So the cowherd decided to construct an enc...
8 4 1 2 4 5 3 1 3 5 3 2 6 8 2 1 2 1 50 5 3 4 5 6 8 3 1 25 26 6 1 2 4 8 16 32
4 2 3 1 0 5 3 15
1 second
256 megabytes
['brute force', 'geometry', 'math', '*800']
F. My Beautiful Madnesstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a tree. We will consider simple paths on it. Let's denote path between vertices a and b as (a, b). Let d-neighborhood of a path be a set of vertices of the tree located at a distanc...
1 4 1 1 1 1 1 1 2 1 1 3 0
Yes
2 seconds
512 megabytes
['data structures', 'trees', '*3500']
F. Max Correct Settime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call the set of positive integers S correct if the following two conditions are met: S \subseteq \{1, 2, \dots, n\}; if a \in S and b \in S, then |a-b| \neq x and |a-b| \neq y. For the given ...
10 2 5
5
4 seconds
256 megabytes
['bitmasks', 'dp', 'math', '*3100']
E. Plan of Lecturestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIvan is a programming teacher. During the academic year, he plans to give n lectures on n different topics. Each topic should be used in exactly one lecture. Ivan wants to choose which topic will he ...
5 2 2 3 0 5 3 1 5 5 4
3 2 1 5 4
2 seconds
512 megabytes
['constructive algorithms', 'dfs and similar', 'dsu', 'graphs', 'implementation', 'sortings', 'trees', '*2400']
D. Pairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have 2n integers 1, 2, \dots, 2n. You have to redistribute these 2n elements into n pairs. After that, you choose x pairs and take minimum elements from them, and from the other n - x pairs, you take maximu...
3 1 1 5 1 4 5 9 10 2 3 4
1 3 1
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'greedy', 'two pointers', '*1900']
C. Busy Robottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a robot that can move along a number line. At time moment 0 it stands at point 0.You give n commands to the robot: at time t_i seconds you command the robot to go to point x_i. Whenever the robot ...
8 3 1 5 3 0 6 4 3 1 5 2 4 10 -5 5 2 -5 3 1 4 1 5 1 6 1 4 3 3 5 -3 9 2 12 0 8 1 1 2 -6 7 2 8 3 12 -9 14 2 18 -1 23 9 5 1 -4 4 -7 6 -1 7 -3 8 -7 2 1 2 2 -2 6 3 10 5 5 8 0 12 -4 14 -7 19 -5
1 2 0 2 1 1 0 2
2 seconds
256 megabytes
['implementation', '*1800']
B. Find The Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array [a_1, a_2, \dots, a_n] such that 1 \le a_i \le 10^9. Let S be the sum of all elements of the array a.Let's call an array b of n integers beautiful if: 1 \le b_i \le 10^9 for eac...
4 5 1 2 3 4 5 2 4 6 2 1 1000000000 6 3 4 8 1 2 3
3 3 3 3 3 3 6 1 1000000000 4 4 8 1 3 3
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'greedy', '*1400']
A. Dungeontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a new computer game in which you have to fight monsters. In a dungeon you are trying to clear, you met three monsters; the first of them has a health points, the second has b health points, an...
3 3 2 4 1 1 1 10 1 7
YES NO NO
2 seconds
256 megabytes
['binary search', 'math', '*1100']
F. The Treasure of The Segmentstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp found n segments on the street. A segment with the index i is described by two integers l_i and r_i — coordinates of the beginning and end of the segment, respectively. Polycarp ...
4 3 1 4 2 3 3 6 4 1 2 2 3 3 5 4 5 5 1 2 3 8 4 5 6 7 9 10 5 1 5 2 4 3 5 3 8 4 8
0 1 2 0
3 seconds
256 megabytes
['binary search', 'data structures', 'greedy', '*1800']
E2. Close Tuples (hard version)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of this problem. The only difference between the easy and hard versions is the constraints on k and m. In this version of the problem, you need to output the answ...
4 4 3 2 1 2 4 3 4 2 1 1 1 1 1 1 1 1 1 10 4 3 5 6 1 3 2 9 8 1 2 4
2 6 1 20
4 seconds
256 megabytes
['binary search', 'combinatorics', 'implementation', 'math', 'sortings', 'two pointers', '*1700']
E1. Close Tuples (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of this problem. The only difference between easy and hard versions is the constraints on k and m (in this version k=2 and m=3). Also, in this version of the prob...
4 4 1 2 4 3 4 1 1 1 1 1 1 10 5 6 1 3 2 9 8 1 2 4
2 4 0 15
2 seconds
256 megabytes
['binary search', 'combinatorics', 'math', 'sortings', 'two pointers', '*1500']
D. Add to Neighbour and Removetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp was given an array of a[1 \dots n] of n integers. He can perform the following operation with the array a no more than n times: Polycarp selects the index i and adds the value a_...
4 5 3 1 6 6 2 4 1 2 2 1 3 2 2 2 4 6 3 2 1
4 2 0 2
3 seconds
256 megabytes
['greedy', 'math', 'number theory', '*1400']
C. Unique Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive number x. Find the smallest positive integer number that has the sum of digits equal to x and all digits are distinct (unique).InputThe first line contains a single positive int...
4 1 5 15 50
1 5 69 -1
2 seconds
256 megabytes
['brute force', 'greedy', 'math', '*900']
B. Last Year's Substringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has a string s[1 \dots n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 t...
6 8 20192020 8 22019020 4 2020 5 20002 6 729040 6 200200
YES YES YES NO NO NO
2 seconds
256 megabytes
['dp', 'implementation', 'strings', '*800']
A. Favorite Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has a favorite sequence a[1 \dots n] consisting of n integers. He wrote it out on the whiteboard as follows: he wrote the number a_1 to the left side (at the beginning of the whiteboard); ...
6 7 3 4 5 2 9 1 1 4 9 2 7 1 11 8 4 3 1 2 7 8 7 9 4 2 1 42 2 11 7 8 1 1 1 1 1 1 1 1
3 1 4 1 5 9 2 9 1 2 7 8 2 4 4 3 9 1 7 2 8 7 42 11 7 1 1 1 1 1 1 1 1
2 seconds
256 megabytes
['implementation', 'two pointers', '*800']
F. Mathematical Expressiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBarbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, \ldots, a_n...
3 2 2 0 +-*
2*2-0
1 second
256 megabytes
['constructive algorithms', 'dp', 'greedy', '*2700']
E. Water Leveltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distrac...
8 1 10 2 6 4
No
1 second
256 megabytes
['brute force', 'graphs', 'greedy', 'implementation', 'math', '*2200']
D. Divide and Summarizetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike received an array a of length n as a birthday present and decided to test how pretty it is.An array would pass the i-th prettiness test if there is a way to get an array with a sum of elemen...
2 5 5 1 2 3 4 5 1 8 9 12 6 5 5 3 1 3 1 3 1 2 3 9 11
Yes No Yes No Yes No Yes No Yes Yes
2 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'divide and conquer', 'implementation', 'sortings', '*1600']
C. Random Eventstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRon is a happy owner of a permutation a of length n.A permutation of length n 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, but...
4 4 3 4 3 2 1 1 0.3 3 1 4 0.6 5 3 4 2 1 3 5 3 0.8 4 0.6 5 0.3 6 5 1 3 2 4 5 6 4 0.9 5 0.3 2 0.4 6 0.7 3 0.5 4 2 1 2 3 4 2 0.5 4 0.1
0.600000 0.720000 0.989500 1.000000
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*1500']
B. Find the Sprucetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHolidays are coming up really soon. Rick realized that it's time to think about buying a traditional spruce tree. But Rick doesn't want real trees to get hurt so he decided to find some in an n \times ...
4 2 3 .*. *** 2 3 .*. **. 4 5 .***. ***** ***** *.*.* 5 7 ..*.*.. .*****. ******* .*****. ..*.*..
5 3 23 34
1 second
256 megabytes
['brute force', 'dp', 'implementation', '*1400']
A. String Generationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne fall day Joe got bored because he couldn't find himself something interesting to do. Marty suggested Joe to generate a string of length n to entertain him somehow. It didn't seem particularly dif...
2 3 2 4 1
aab acba
1 second
256 megabytes
['constructive algorithms', 'greedy', '*800']
B. Move and Turntime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly 1 meter in one of the four cardinal directions: north, south, west, and east. For the first s...
1
4
2 seconds
512 megabytes
['dp', 'math', '*1300']
A. Red-Blue Shuffletime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n cards numbered 1, \ldots, n. The card i has a red digit r_i and a blue digit b_i written on it.We arrange all n cards in random order from left to right, with all permutations of 1, \ldot...
3 3 777 111 3 314 159 5 09281 09281
RED BLUE EQUAL
2 seconds
512 megabytes
['math', 'probabilities', '*800']
F. Range Diameter Sumtime limit per test7 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a tree with n vertices numbered 1, \ldots, n. A tree is a connected simple graph without cycles.Let \mathrm{dist}(u, v) be the number of edges in the unique simple path connecting ver...
4 1 2 2 4 3 2
10
7 seconds
512 megabytes
['data structures', 'trees', '*3500']
E. Nim Shortcutstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAfter your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap! In the game, there ar...
3 5 3 0 0 1 2 2 0 0 1 1 2 2 3 3 5 4
LOSE WIN LOSE WIN LOSE
2 seconds
512 megabytes
['data structures', 'games', '*3100']