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. Delivery Oligopolytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe whole delivery market of Berland is controlled by two rival companies: BerEx and BerPS. They both provide fast and reliable delivery services across all the cities of Berland.The map of Berland...
3 3 1 2 2 3 3 1
3 1 3 3 2 1 2
2 seconds
256 megabytes
['brute force', 'dp', 'graphs', '*2800']
E. Guess the Roottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJury picked a polynomial f(x) = a_0 + a_1 \cdot x + a_2 \cdot x^2 + \dots + a_k \cdot x^k. k \le 10 and all a_i are integer numbers and 0 \le a_i < 10^6 + 3. It's guaranteed that there is at least one ...
1000002 0
? 0 ? 1 ! 1
2 seconds
256 megabytes
['brute force', 'interactive', 'math', '*2200']
D. Beautiful Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10,...
5 -2 -3 8 -2 1 -6
22
2 seconds
256 megabytes
['brute force', 'data structures', 'divide and conquer', 'dp', 'greedy', '*1900']
C. Alarm Clocks Everywheretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the i-th of them will start during the x_i-th minute. Ivan doesn't want to skip any o...
3 5 3 12 18 2 6 5 3 3
YES 3 4
3 seconds
256 megabytes
['math', 'number theory', '*1300']
B. Game with Telephone Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA telephone number is a sequence of exactly 11 digits such that its first digit is 8.Vasya and Petya are playing a game. Initially they have a string s of length n (n is odd) consisting of ...
13 8380011223344
YES
1 second
256 megabytes
['games', 'greedy', 'implementation', '*1200']
A. Reverse a Substringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of n lowercase Latin letters.Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in posi...
7 abacaba
YES 2 5
2 seconds
256 megabytes
['implementation', 'sortings', 'strings', '*1000']
G. Minimum Possible LCMtime limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers a_1, a_2, \dots, a_n.Your problem is to find such pair of indices i, j (1 \le i < j \le n) that lcm(a_i, a_j) is minimum possible.lcm(x, y) is t...
5 2 4 8 3 6
1 2
4 seconds
1024 megabytes
['brute force', 'greedy', 'math', 'number theory', '*2200']
F. Shovels Shoptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n shovels in the nearby shop. The i-th shovel costs a_i bourles.Misha has to buy exactly k shovels. Each shovel can be bought no more than once.Misha can buy shovels by several purchases. Durin...
7 4 5 2 5 4 2 6 3 1 2 1 6 5 2 1 3 1
7
2 seconds
256 megabytes
['dp', 'greedy', 'sortings', '*2100']
E. Two Teamstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.The i-th student has integer programming skill...
5 2 2 4 5 3 1
11111
2 seconds
256 megabytes
['data structures', 'implementation', 'sortings', '*1800']
D. Walking Robottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a robot staying at X=0 on the Ox axis. He has to walk to X=n. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.The i-th ...
5 2 1 0 1 0 1 0
5
2 seconds
256 megabytes
['greedy', '*1500']
C. Gourmet Cattime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: on Mondays, Thursdays and Sundays he eats fish food; on Tuesdays and Saturdays he eats rabbi...
2 1 1
4
1 second
256 megabytes
['implementation', 'math', '*1400']
B. Make Them Equaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a_1, a_2, \dots, a_n consisting of n integers.You can choose any non-negative integer D (i.e. D \ge 0), and for each a_i you can: add D (only once), i. e. perform a_i := a_i ...
6 1 4 4 7 4 1
3
2 seconds
256 megabytes
['math', '*1200']
A. Restoring Three Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) an...
3 6 5 4
2 1 3
1 second
256 megabytes
['math', '*800']
F. Serval and Bonus Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGetting closer and closer to a mathematician, Serval becomes a university student on math major in Japari University. On the Calculus class, his teacher taught him how to calculate the expecte...
1 1 1
332748118
1 second
256 megabytes
['combinatorics', 'dp', 'math', 'probabilities', '*2600']
E. Serval and Snaketime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Now Serval is a senior high school student in Japari Middle School. However, on the way to the school, he must go across a pond, in which there is a dangerous snake. The...
2 1 0 0
? 1 1 1 1 ? 1 2 1 2 ? 2 2 2 2 ! 1 1 2 1
1 second
256 megabytes
['binary search', 'brute force', 'interactive', '*2200']
D. Serval and Rooted Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before. As a talented boy in mathematics, he likes to play with numbers. This time, he wa...
6 1 0 1 1 0 1 1 2 2 2 2
1
2 seconds
256 megabytes
['binary search', 'dfs and similar', 'dp', 'greedy', 'trees', '*1900']
C. Serval and Parenthesis Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputServal soon said goodbye to Japari kindergarten, and began his life in Japari Primary School.In his favorite math class, the teacher taught him the following interesting definitions.A p...
6 (?????
(()())
1 second
256 megabytes
['greedy', 'strings', '*1700']
B. Serval and Toy Brickstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLuckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.He has a special interest to create difficult pro...
3 7 3 2 3 0 0 2 0 1 2 1 3 1 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0
1 0 0 0 2 0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1200']
A. Serval and Bustime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive hi...
2 2 6 4 9 5
1
1 second
256 megabytes
['brute force', 'math', '*1000']
F2. Neko Rules the Catniverse (Large Version)time limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is same as the previous one, but has larger constraints.Aki is playing a new video game. In the video game, he will control Neko, the giant cat, to fly between ...
3 3 1
4
7 seconds
256 megabytes
['bitmasks', 'dp', 'matrices', '*3000']
F1. Neko Rules the Catniverse (Small Version)time limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is same as the next one, but has smaller constraints.Aki is playing a new video game. In the video game, he will control Neko, the giant cat, to fly between pla...
3 3 1
4
7 seconds
256 megabytes
['bitmasks', 'dp', 'matrices', '*2800']
E. Neko and Flashbacktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation of length k is a sequence of k integers from 1 to k containing each integer exactly once. For example, the sequence [3, 1, 2] is a permutation of length 3.When Neko was five, he thoug...
5 4 5 3 5 6 7 4 6
3 4 6 5 7
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', '*2400']
D. Neko and Aki's Pranktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNeko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire ba...
1
1
1 second
256 megabytes
['dp', 'greedy', 'trees', '*2100']
C. Neko does Mathstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNeko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.Neko has two integers a and b. His goal is to find a non-negative integer k such that t...
6 10
2
1 second
256 megabytes
['brute force', 'math', 'number theory', '*1800']
B. Neko Performs Cat Furrier Transformtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to cre...
39
4 5 3
1 second
256 megabytes
['bitmasks', 'constructive algorithms', 'dfs and similar', 'math', '*1300']
A. Neko Finds Grapestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful myst...
5 4 9 14 6 2 11 8 4 7 20
3
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*800']
F. Sonya and Informaticstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.Given an array a of length ...
3 2 0 1 0
333333336
1 second
256 megabytes
['combinatorics', 'dp', 'matrices', 'probabilities', '*2300']
E. Number of Componentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formal...
3 2 1 3
7
1 second
256 megabytes
['combinatorics', 'data structures', 'dp', 'math', '*2100']
D. Stas and the Queue at the Buffettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of n high school students numbered from 1 to n. Initially, each student i is ...
3 4 2 2 3 6 1
12
1 second
256 megabytes
['greedy', 'math', 'sortings', '*1600']
C. Problem for Nazartime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task.Consider two infinite se...
1 3
7
1 second
256 megabytes
['constructive algorithms', 'math', '*1800']
B. Dima and a Bad XORtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudent Dima from Kremland has a matrix a of size n \times m filled with non-negative integers.He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of ...
3 2 0 0 0 0 0 0
NIE
1 second
256 megabytes
['bitmasks', 'brute force', 'constructive algorithms', 'dp', '*1600']
A. Maxim and Biologytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".Maxim was very boring to sit in...
4 ZCTH
2
1 second
256 megabytes
['brute force', 'strings', '*1000']
B. Tiling Challengetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth c...
3 #.# ... #.#
YES
2 seconds
256 megabytes
['greedy', 'implementation', '*900']
A. Stock Arbitragingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWelcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!In the morning, ...
3 4 11 4 2 5 4 4 5 4
26
1 second
256 megabytes
['greedy', 'implementation', '*800']
E. Election Promisestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citize...
4 2 2 1 1 5 1 2 3 4
WIN 1 5 1 5
2 seconds
256 megabytes
['games', 'graphs', '*3200']
D. Abandoning Roadstime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputCodefortia is a small island country located somewhere in the West Pacific. It consists of n settlements connected by m bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants re...
5 5 20 25 1 2 25 2 3 25 3 4 20 4 5 20 5 1 20
0 25 60 40 20
5 seconds
512 megabytes
['brute force', 'dp', 'graphs', 'greedy', '*3000']
C. Tree Generator™time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOwl Pacino has always been into trees — unweighted rooted trees in particular. He loves determining the diameter of every tree he sees — that is, the maximum length of any simple path in the tree.Owl ...
5 5 (((()))) 4 5 3 4 5 6 3 6 2 5
4 3 3 2 4 4
2 seconds
256 megabytes
['data structures', 'implementation', 'trees', '*2700']
B. Three Religionstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution...
6 8 abdabc + 1 a + 1 d + 2 b + 2 c + 3 a + 3 b + 1 c - 2
YES YES YES YES YES YES NO YES
3 seconds
256 megabytes
['dp', 'implementation', 'strings', '*2200']
A. Prefix Sum Primestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.However, there is one condit...
5 1 2 1 2 1
1 1 1 2 2
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', 'number theory', '*1200']
H. Holy Diver time limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given an array which is initially empty. You need to perform n operations of the given format: "a l r k": append a to the end of the array. After that count the number of integer pairs x, y suc...
5 0 0 0 1 0 1 0 5 5 2 1 0 5 2 1 0 2 4 3 3
1 1 2 6 3
3 seconds
1024 megabytes
['data structures', '*3500']
G. Gold Experiencetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputConsider an undirected graph G with n vertices. There is a value a_i in each vertex.Two vertices i and j are connected with an edge if and only if gcd(a_i, a_j) > 1, where gcd(x, y) denotes the great...
6 3 6 15 10 8 14 12
1 3 6
2 seconds
1024 megabytes
['constructive algorithms', 'graphs', 'math', 'number theory', 'probabilities', '*3300']
F. Foo Fighterstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n objects. Each object has two integer properties: val_i — its price — and mask_i. It is guaranteed that the sum of all prices is initially non-zero.You want to select a positive integer s....
5 17 206 -6 117 -2 151 9 93 6 117
64
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', '*2700']
E. Earth Wind and Firetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n stones arranged on an axis. Initially the i-th stone is located at the coordinate s_i. There may be more than one stone in a single place.You can perform zero or more operations of the...
5 2 2 7 4 9 5 4 5 5 5
YES 4 4 3 1 2 3 1 2 5 2 1 5 2
4 seconds
256 megabytes
['constructive algorithms', 'greedy', 'math', 'sortings', 'two pointers', '*2300']
D. Dirty Deeds Done Dirt Cheaptime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n pairs of integers (a_1, b_1), (a_2, b_2), \ldots, (a_n, b_n). All of the integers in the pairs are distinct and are in the range from 1 to 2 \cdot n inclusive.Let's call a ...
5 1 7 6 4 2 10 9 8 3 5
3 1 5 3
3 seconds
256 megabytes
['greedy', 'sortings', '*1800']
C. Crazy Diamondtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p of integers from 1 to n, where n is an even number. Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type: take tw...
2 2 1
1 1 2
3 seconds
256 megabytes
['constructive algorithms', 'sortings', '*1700']
B. Born This Waytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C.There are n flights from A to B, they...
4 5 1 1 2 1 3 5 7 1 2 3 9 10
11
1 second
256 megabytes
['binary search', 'brute force', 'two pointers', '*1600']
A. Another One Bites The Dusttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a string good if and only if it consists of only two types of letters — 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings a...
1 1 1
4
1 second
256 megabytes
['greedy', '*800']
F. Zigzag Gametime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a complete bipartite graph with 2n nodes, with n nodes on each side of the bipartition. Nodes 1 through n are on one side of the bipartition, and nodes n+1 to 2n are on the other side. You a...
2 3 3 1 9 2 5 7 6 4 8 6 -1 1 1 I 1 -1
A D 3 2 B 2
5 seconds
256 megabytes
['games', 'interactive', '*3500']
E. Rainbow Coinstime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCarl has n coins of various colors, and he would like to sort them into piles. The coins are labeled 1,2,\ldots,n, and each coin is exactly one of red, green, or blue. He would like to sort the coins in...
3 3 1 1 1 3 1 0 0 6 000 010 100 001 000
Q 1 1 2 Q 1 2 3 Q 1 1 3 A 3 0 0 1 2 3 Q 1 1 3 Q 1 2 3 Q 1 1 2 A 2 0 1 1 3 2 Q 3 1 2 3 4 5 6 Q 3 1 3 2 5 4 6 Q 3 1 4 2 6 3 5 Q 3 1 5 2 4 3 6 Q 3 1 6 2 3 4 5 A 2 2 2 1 4 2 5 3 6
6 seconds
256 megabytes
['interactive', '*3000']
D. Palindrome XORtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of characters "1", "0", and "?". The first character of s is guaranteed to be "1". Let m be the number of characters in s.Count the number of ways we can choose a pai...
10110
3
1 second
256 megabytes
['dfs and similar', 'graphs', '*2400']
C. Thanos Nimtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob are playing a game with n piles of stones. It is guaranteed that n is an even number. The i-th pile has a_i stones.Alice and Bob will play a game alternating turns with Alice going first.On a ...
2 8 8
Bob
1 second
256 megabytes
['games', '*2000']
B. Chladni Figuretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 \leq i < n) are adjacent, and s...
12 6 1 3 3 7 5 7 7 11 9 11 11 3
Yes
3 seconds
256 megabytes
['brute force', 'strings', '*1900']
A. Hide and Seektime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent.Alice initially has a token on some cell on the...
5 3 5 1 4
9
1 second
256 megabytes
['graphs', '*1500']
H. Satanic Panictime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of n points in a 2D plane. No three points are collinear.A pentagram is a set of 5 points A,B,C,D,E that can be arranged as follows. Note the length of the line segments don't matte...
5 0 0 0 2 2 0 2 2 1 3
1
4 seconds
256 megabytes
['dp', 'geometry', '*2900']
G. Zoning Restrictionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can ...
3 3 3 1 1 1 1000 2 2 3 1000 3 3 2 1000
14
1 second
256 megabytes
['dp', 'flows', 'graphs', '*2700']
F. Leaf Partitiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree with n nodes, labeled from 1 to n. The tree is rooted at node 1. The parent of the i-th node is p_i. A leaf is node with no children. For a given set of leaves L, let f(L) de...
5 1 1 1 1
12
1 second
256 megabytes
['dp', 'trees', '*2500']
E. Hot is Coldtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n integers a_1, a_2, \ldots, a_n.You will perform q operations. In the i-th operation, you have a symbol s_i which is either "<" or ">" and a number x_i.You make a new array b suc...
11 3 -5 -4 -3 -2 -1 0 1 2 3 4 5 > 2 > -4 < 5
5 4 -3 -2 -1 0 1 2 -3 4 5
1 second
256 megabytes
['bitmasks', 'data structures', 'divide and conquer', 'implementation', '*2400']
D. Frog Jumpingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.Let f(x) be the number of distinct integers ...
7 5 3
19
2 seconds
256 megabytes
['dfs and similar', 'math', 'number theory', '*2100']
C. Tree Diametertime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a weighted tree with n nodes and n-1 edges. The nodes are conveniently labeled from 1 to n. The weights are positive integers at most 100. Define the distance between two nodes to be the sum of...
2 5 9 6 10 9 10 2 99
1 4 1 2 3 4 5 1 4 2 3 4 5 1 1 4 3 4 5 1 2 1 4 4 5 1 2 3 1 4 5 1 2 3 4 -1 10 1 1 1 2 -1 99
4 seconds
256 megabytes
['bitmasks', 'graphs', 'interactive', '*1700']
B. Hate "A"time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob has a string s consisting of lowercase English letters. He defines s' to be the string after removing all "a" characters from s (keeping all other characters in the same order). He then generates a new st...
aaaaa
aaaaa
1 second
256 megabytes
['implementation', 'strings', '*1100']
A. Love "A"time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice has a string s. She really likes the letter "a". She calls a string good if strictly more than half of the characters in that string are "a"s. For example "aaabb", "axaa" are good strings, and "baca", "...
xaxxxxa
3
1 second
256 megabytes
['implementation', 'strings', '*800']
D. Pigeon d'Ortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFrom "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons? The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush,...
5 1 2 3 4 5
4
1 second
256 megabytes
['implementation']
C. Mystery Circuittime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output InputThe input contains a single integer a (0 \le a \le 15).OutputOutput a single integer.ExampleInput 3 Output 13
3
13
1 second
256 megabytes
['bitmasks', 'brute force']
B. Kanban Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInputThe input contains a single integer a (1 \le a \le 99).OutputOutput "YES" or "NO".ExamplesInput 5 Output YES Input 13 Output NO Input 24 Output NO Input 46 Output YES
5
YES
1 second
256 megabytes
['brute force']
A. Thanos Sorttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThanos sort is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process.Given an ...
4 1 2 2 4
4
1 second
256 megabytes
['implementation']
G. Two Merged Sequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing.Strictly increasing sequence is a sequence of integers [x_1 < x_2 < \dots < x_k...
9 5 1 3 6 8 2 9 0 10
YES 1 0 0 0 0 1 0 1 0
2 seconds
256 megabytes
['dp', 'greedy', '*2400']
F. Graph Without Long Directed Pathstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph.You have to direct its edges in such a w...
6 5 1 5 2 1 1 4 3 1 6 1
YES 10100
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*1700']
E. Median Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t, both consisting of exactly k lowercase Latin letters, s is lexicographically less than t.Let's consider list of all strings consisting of exactly k lowercase Latin let...
2 az bf
bc
2 seconds
256 megabytes
['bitmasks', 'math', 'number theory', 'strings', '*1900']
D. Equalize Them Alltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices (i, j) such that |i-j|=1 (indices i ...
5 2 4 6 6 6
2 1 2 3 1 1 2
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1400']
C. Two Shuffled Sequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing.Strictly increasing sequence is a sequence of integers [x_1 < x_2 < \dots ...
7 7 2 7 3 3 1 4
YES 2 3 7 5 7 4 3 2 1
2 seconds
256 megabytes
['constructive algorithms', 'sortings', '*1000']
B. Parity Alternated Deletionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has an array a consisting of n integers.He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after...
5 1 5 7 8 2
0
2 seconds
256 megabytes
['greedy', 'implementation', 'sortings', '*900']
A. Diverse Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" an...
8 fced xyz r dabcef az aa bad babc
Yes Yes Yes Yes No No No No
1 second
256 megabytes
['implementation', 'strings', '*800']
C. Queentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree with vertices numerated from 1 to n. A tree is a connected graph without cycles. A rooted tree has a special vertex named root.Ancestors of the vertex i are all vertices on the path f...
5 3 1 1 1 -1 0 2 1 3 0
1 2 4
1 second
256 megabytes
['dfs and similar', 'trees', '*1400']
B. Nirvanatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.Help Kurt find the maximum possible product of digits among all ...
390
216
1 second
256 megabytes
['brute force', 'math', 'number theory', '*1200']
A. The Doorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThree years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he...
5 0 0 1 0 0
3
1 second
256 megabytes
['implementation', '*800']
E. Pink Floydtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive task.Scientists are about to invent a new optimization for the Floyd-Warshall algorithm, which will allow it to work in linear time. There is only one part of the optimization still ...
4 2 1 2 3 4 0 1 1
? 1 3 ? 4 2 ? 3 2 ! 3
4 seconds
256 megabytes
['graphs', 'interactive', '*3200']
D. Foreignertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTraveling around the world you noticed that many shop owners raise prices to inadequate values if the see you are a foreigner.You define inadequate numbers as follows: all integers from 1 to 9 are inadequa...
4021
6
1 second
256 megabytes
['dp', '*2800']
C. U2time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Vasya learned that, given two points with different x coordinates, you can draw through them exactly one parabola with equation of type y = x^2 + bx + c, where b and c are reals. Let's call such a parabola...
3 -1 0 0 2 1 0
2
1 second
256 megabytes
['geometry', '*2400']
B. Lynyrd Skynyrdtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n. Lynyrd and Skynyrd became bore...
Input3 6 32 1 31 2 3 1 2 31 52 63 5
Output110
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'dp', 'math', 'trees', '*2000']
A. The Beatlestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through n \cdot k cities. The cities are numerated from 1 to n \cdot k, the distance between the neighboring cities ...
2 3 1 1
1 6
1 second
256 megabytes
['brute force', 'math', '*1700']
G. Privatization of Roads in Treelandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTreeland consists of n cities and n-1 roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are right — ...
6 2 1 4 4 3 3 5 3 6 5 2
2 1 2 1 1 2
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'dfs and similar', 'graphs', 'greedy', 'trees', '*1900']
F2. Same Sum Blocks (Hard)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is given in two editions, which differ exclusively in the constraints on the number n.You are given an array of integers a[1], a[2], \dots, a[n]. A block is a sequence of contiguo...
7 4 1 2 2 1 5 3
3 7 7 2 3 4 5
3 seconds
256 megabytes
['data structures', 'greedy', '*1900']
F1. Same Sum Blocks (Easy)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is given in two editions, which differ exclusively in the constraints on the number n.You are given an array of integers a[1], a[2], \dots, a[n]. A block is a sequence of contiguo...
7 4 1 2 2 1 5 3
3 7 7 2 3 4 5
2 seconds
256 megabytes
['greedy', '*1900']
E. Superhero Battletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again.Ea...
1000 6 -100 -200 -300 125 77 -4
9
2 seconds
256 megabytes
['math', '*1700']
D. Colored Bootstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n left boots and n right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings l and r, both of length n. The char...
10 codeforces dodivthree
5 7 8 4 9 2 2 9 10 3 1
2 seconds
256 megabytes
['greedy', 'implementation', '*1500']
C. Polycarp Restores Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array of integers p_1, p_2, \dots, p_n is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3, 1, 2], [1],...
3 -2 1
3 1 2
2 seconds
256 megabytes
['math', '*1500']
B. Maximal Continuous Resttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a_1, a_2, \dots, a_n (each a_i is either 0 or 1), wh...
5 1 0 1 0 1
2
2 seconds
256 megabytes
['implementation', '*900']
A. Game 23time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves.Print the number of moves ...
120 51840
7
1 second
256 megabytes
['implementation', 'math', '*1000']
G. Double Treetime limit per test10 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given a special undirected graph. It consists of 2n vertices numbered from 1 to 2n. The following properties hold for the graph: there are exactly 3n-2 edges in the graph: n edges connect vertic...
5 3 6 15 4 8 1 2 5 4 2 3 5 7 1 4 1 5 1 5 2 1 3 1 2 5 6 1 10
3 15 4
10 seconds
1024 megabytes
['data structures', 'divide and conquer', 'shortest paths', 'trees', '*2700']
F. Extending Set of Pointstime limit per test3.5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputFor a given set of two-dimensional points S, let's denote its extension E(S) as the result of the following algorithm:Create another set of two-dimensional points R, which is initially equa...
7 1 1 1 2 2 1 2 2 1 2 1 3 2 1
1 2 4 4 4 6 3
3.5 seconds
1024 megabytes
['data structures', 'divide and conquer', 'dsu', '*2600']
E. Palindrome-less Arraystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote that some array b is bad if it contains a subarray b_l, b_{l+1}, \dots, b_{r} of odd length more than 1 (l < r and r - l + 1 is odd) such that \forall i \in \{0, 1, \dots, r - l\} ...
2 3 -1 -1
9
2 seconds
256 megabytes
['combinatorics', 'divide and conquer', 'dp', '*2200']
D. Minimum Triangulationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a regular polygon with n vertices labeled from 1 to n in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle ...
3
6
2 seconds
256 megabytes
['dp', 'greedy', 'math', '*1200']
C. Playlisttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total leng...
4 3 4 7 15 1 3 6 6 8
78
2 seconds
256 megabytes
['brute force', 'data structures', 'sortings', '*1600']
B. Good Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If...
3 2 <> 3 ><< 1 >
1 0 0
1 second
256 megabytes
['implementation', 'strings', '*1200']
A. Detective Booktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that ...
9 1 3 3 6 7 6 8 8 9
4
2 seconds
256 megabytes
['implementation', '*1000']
F. Dish Shoppingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are m people living in a city. There are n dishes sold in the city. Each dish i has a price p_i, a standard s_i and a beauty b_i. Each person j has an income of inc_j and a preferred beauty pref_j...
3 3 2 1 3 2 4 4 2 1 1 2 2 3 1 2 4
1 2 0
2 seconds
256 megabytes
['data structures', 'divide and conquer', '*2500']
E. Maximize Mextime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exac...
5 3 0 1 2 2 0 1 2 2 3 2 5 3 2 4 5 1
3 1 1 1 0
2 seconds
256 megabytes
['flows', 'graph matchings', 'graphs', '*2400']
D. Steps to Onetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVivek initially has an empty array a and some integer constant m.He performs the following algorithm: Select a random integer x uniformly in range from 1 to m and append it to the end of a. Compute the...
1
1
2 seconds
256 megabytes
['dp', 'math', 'number theory', 'probabilities', '*2300']
C. Edgy Treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red.You are also given an integer k. Consider sequences o...
4 4 1 2 1 2 3 1 3 4 1
252
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'graphs', 'math', 'trees', '*1500']
B. Chocolatestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou went to the store, selling n types of chocolates. There are a_i chocolates of type i in stock.You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocola...
5 1 2 1 3 6
10
2 seconds
256 megabytes
['greedy', 'implementation', '*1000']