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
B. String Modificationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a string s of length n. He decides to make the following modification to the string: Pick an integer k, (1 \leq k \leq n). For i from 1 to n-k+1, reverse the substring s[i:i+k-1] of s....
6 4 abab 6 qwerty 5 aaaaa 6 alaska 9 lfpbavjsm 1 p
abab 1 ertyqw 3 aaaaa 1 aksala 6 avjsmbpfl 5 p 1
1 second
256 megabytes
['brute force', 'constructive algorithms', 'implementation', 'sortings', 'strings', '*1400']
A. Grade Allocationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputn students are taking an exam. The highest possible score at this exam is m. Let a_{i} be the score of the i-th student. You have access to the school database which stores the results of all students...
2 4 10 1 2 3 4 4 5 1 2 3 4
10 5
1 second
256 megabytes
['implementation', '*800']
C. Restoring Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence b_1, b_2, \ldots, b_n. Find the lexicographically minimal permutation a_1, a_2, \ldots, a_{2n} such that b_i = \min(a_{2i-1}, a_{2i}), or determine that it is impossible....
5 1 1 2 4 1 3 4 1 3 4 2 3 4 5 5 1 5 7 2 8
1 2 -1 4 5 1 2 3 6 -1 1 3 5 6 7 9 2 4 8 10
1 second
256 megabytes
['greedy', '*1200']
B. Homecomingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tra...
5 2 2 1 BB 1 1 1 AB 3 2 8 AABBBBAABB 5 3 4 BBBBB 2 1 1 ABABAB
2 1 3 1 6
1 second
256 megabytes
['binary search', 'dp', 'greedy', 'strings', '*1300']
A. Dead Pixeltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputScreen resolution of Polycarp's monitor is a \times b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 \le x < a, 0 \le y < b). You can consider columns of pixels t...
6 8 8 0 0 1 10 0 3 17 31 10 4 2 1 0 0 5 10 3 9 10 10 4 8
56 6 442 1 45 80
1 second
256 megabytes
['implementation', '*800']
E. Concatenation with intersectiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya had three strings a, b and s, which consist of lowercase English letters. The lengths of strings a and b are equal to n, the length of the string s is equal to m. Vasya decided t...
Input6 5aabbaabaaaabaaaaa
Output4
2 seconds
512 megabytes
['data structures', 'hashing', 'strings', 'two pointers', '*2700']
D. Happy New Yeartime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBeing Santa Claus is very difficult. Sometimes you have to deal with difficult situations.Today Santa Claus came to the holiday and there were m children lined up in front of him. Let's number them fro...
Input3 5 31 32 43 5
Output4
2 seconds
512 megabytes
['bitmasks', 'dp', 'implementation', '*2500']
C2. Skyscrapers (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. In this version n \le 500\,000The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construct...
Input51 2 3 2 1
Output1 2 3 2 1
3 seconds
512 megabytes
['data structures', 'dp', 'greedy', '*1900']
C1. Skyscrapers (easy version)time limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is an easier version of the problem. In this version n \le 1000The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction ...
Input51 2 3 2 1
Output1 2 3 2 1
1 second
512 megabytes
['brute force', 'data structures', 'dp', 'greedy', '*1500']
B. Different Rulestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good ol...
Input15 1 3
Output1 3
1 second
256 megabytes
['constructive algorithms', 'greedy', 'implementation', 'math', '*1700']
A. Fast Food Restauranttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTired of boring office work, Denis decided to open a fast food restaurant.On the first day he made a portions of dumplings, b portions of cranberry juice and c pancakes with condensed milk.The pec...
Input71 2 10 0 09 1 72 2 32 3 23 2 24 4 4
Output3045557
1 second
256 megabytes
['brute force', 'greedy', 'implementation', '*900']
G. Autocompletiontime limit per test7 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a set of strings S. Each string consists of lowercase Latin letters.For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type ...
10 0 i 1 q 2 g 0 k 1 e 5 r 4 m 5 h 3 p 3 e 5 8 9 1 10 6
2 4 1 3 3
7 seconds
512 megabytes
['data structures', 'dfs and similar', 'dp', '*2600']
F. Attack on Red Kingdomtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe Red Kingdom is attacked by the White King and the Black King!The Kingdom is guarded by n castles, the i-th castle is defended by a_i soldiers. To conquer the Red Kingdom, the Kings have to e...
3 2 1 3 4 7 6 1 1 2 3 1 1 1 2 2 3
2 3 0
3 seconds
512 megabytes
['games', 'two pointers', '*2500']
E. Array Shrinkingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots, a_n. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements a_i = a_{i + 1} (if there is at least one suc...
5 4 3 2 2 3
2
2 seconds
256 megabytes
['dp', 'greedy', '*2100']
D. Count the Arraystime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYour task is to calculate the number of arrays such that: each array contains n elements; each element is an integer from 1 to m; for each array, there is exactly one pair of equal elements; for ...
3 4
6
2 seconds
512 megabytes
['combinatorics', 'math', '*1700']
C. Adding Powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you are performing the following algorithm. There is an array v_1, v_2, \dots, v_n filled with zeroes at start. The following operation is applied to the array several times — at i-th step (0-in...
5 4 100 0 0 0 0 1 2 1 3 4 1 4 1 3 2 0 1 3 3 9 0 59049 810
YES YES NO NO YES
2 seconds
256 megabytes
['bitmasks', 'greedy', 'implementation', 'math', 'number theory', 'ternary search', '*1400']
B. Bogosorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots , a_n. Array is good if for each pair of indexes i < j the condition j - a_j \ne i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array ...
3 1 7 4 1 1 3 5 6 3 2 1 5 6 4
7 1 5 1 3 2 4 6 1 3 5
2 seconds
256 megabytes
['constructive algorithms', 'sortings', '*1000']
A. Two Regular Polygonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and m (m < n). Consider a convex regular polygon of n vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and eq...
2 6 3 7 3
YES NO
1 second
256 megabytes
['geometry', 'greedy', 'math', 'number theory', '*800']
F. Moving Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with...
3 1 3 2 -100 2 3
3
2 seconds
256 megabytes
['data structures', 'divide and conquer', 'implementation', 'sortings', '*1900']
E. Construct the Binary Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d.A tree i...
3 5 7 10 19 10 18
YES 1 2 1 3 YES 1 2 3 3 9 9 2 1 6 NO
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'trees', '*2200']
D. Three Integerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three integers a \le b \le c.In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) ...
8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46
1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
2 seconds
256 megabytes
['brute force', 'math', '*2000']
C. Perform the Combotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in...
3 4 2 abca 1 3 10 5 codeforces 2 8 3 2 9 26 10 qwertyuioplkjhgfdsazxcvbnm 20 10 1 2 3 5 10 5 9 4
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0 2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2
2 seconds
256 megabytes
['brute force', '*1300']
B. WeirdSorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n.You are also given a set of distinct positions p_1, p_2, \dots, p_m, where 1 \le p_i < n. The position p_i means that you can swap elements a[p_i] and a[p_i + 1]. You ca...
6 3 2 3 2 1 1 2 4 2 4 1 2 3 3 2 5 1 1 2 3 4 5 1 4 2 2 1 4 3 1 3 4 2 4 3 2 1 1 3 5 2 2 1 2 3 3 1 4
YES NO YES YES NO YES
2 seconds
256 megabytes
['dfs and similar', 'sortings', '*1200']
A. Add Odd or Subtract Eventime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integers a and b.In one move, you can change a in the following way: Choose any positive odd integer x (x > 0) and replace a with a+x; choose any positive even in...
5 2 3 10 10 2 4 7 4 9 3
1 0 2 2 1
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*800']
F. Bad Cryptographytime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn modern cryptography much is tied to the algorithmic complexity of solving several problems. One of such problems is a discrete logarithm problem. It is formulated as follows: Let's fix a finite f...
7 2 2 1 1 2 3 8 10 8 2 321321321321 2 123214213213 4356903202345442785
1 1 2 4 -1 6148914691236517205 68943624821423112
3 seconds
512 megabytes
['math', 'number theory', '*3400']
E. Strange Functiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's define the function f of multiset a as the multiset of number of occurences of every number, that is present in a.E.g., f(\{5, 5, 1, 2, 5, 2, 3, 3, 9, 5\}) = \{1, 1, 2, 2, 4\}.Let's define f^k(...
3 1
6
2 seconds
512 megabytes
['dp', '*2900']
D. Tourismtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha lives in a country with n cities numbered from 1 to n. She lives in the city number 1. There is a direct train route between each pair of distinct cities i and j, where i \neq j. In total there are n(n-...
5 8 0 1 2 2 0 0 0 1 1 2 0 1 0 0 0 2 1 1 0 0 2 0 1 2 0
2
3 seconds
256 megabytes
['dp', 'graphs', 'probabilities', '*2300']
C. Au Pont Rougetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVK just opened its second HQ in St. Petersburg! Side of its office building has a huge string s written on its side. This part of the office is supposed to be split into m meeting rooms in such way that...
4 2 1 abac
aba
2 seconds
512 megabytes
['binary search', 'dp', 'strings', '*2800']
B. Double Eliminationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. 2^n teams will compete in a double-elimination format (please, carefully read problem state...
3 1 6
6
2 seconds
512 megabytes
['dp', 'implementation', '*2500']
A. Recommendationstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorith...
5 3 7 9 7 8 5 2 5 7 5
6
2 seconds
512 megabytes
['data structures', 'greedy', 'sortings', '*1700']
G. Cow and Exercisetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFarmer John is obsessed with making Bessie exercise more!Bessie is out grazing on the farm, which consists of n fields connected by m directed roads. Each road takes some time w_i to cross. She is cur...
3 3 1 2 2 2 3 2 1 3 3 5 0 1 2 3 4
3.0000000000 4.0000000000 4.5000000000 5.0000000000 5.5000000000
1 second
256 megabytes
['flows', 'graphs', 'shortest paths', '*3100']
F. Cow and Vacationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie is planning a vacation! In Cow-lifornia, there are n cities, with n-1 bidirectional roads connecting them. It is guaranteed that one can reach any city from any other city. Bessie is consideri...
6 2 1 1 2 2 3 2 4 4 5 5 6 2 3 1 3 3 5 3 6
YES YES NO
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'trees', '*3300']
E. Cow and Treatstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass!On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer J...
5 2 1 1 1 1 1 1 2 1 3
2 2
1 second
256 megabytes
['binary search', 'combinatorics', 'dp', 'greedy', 'implementation', 'math', '*2500']
D. Cow and Fieldstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie is out grazing on the farm, which consists of n fields connected by m bidirectional roads. She is currently at field 1, and will return to her home at field n at the end of the day.The Cowfedera...
5 5 3 1 3 5 1 2 2 3 3 4 3 5 2 4
3
2 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'graphs', 'greedy', 'shortest paths', 'sortings', '*1900']
C. Cow and Messagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.The text is a string s of lowercase Latin letters...
aaabb
6
2 seconds
256 megabytes
['brute force', 'dp', 'math', 'strings', '*1500']
B. Cow and Friendtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically, he wants to get from (0,0) to (x,0) by making mu...
42 41 33 123 4 51 552 1015 4
2 3 1 2
2 seconds
256 megabytes
['geometry', 'greedy', 'math', '*1300']
A. Cow and Haybalestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of n haybale piles on the farm. The i-th pile contains a_i haybales. However, Farmer John has just left for vacati...
3 4 5 1 0 3 2 2 2 100 1 1 8 0
3 101 0
2 seconds
256 megabytes
['greedy', 'implementation', '*800']
H. Kuroni the Private Tutortime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs a professional private tutor, Kuroni has to gather statistics of an exam. Kuroni has appointed you to complete this important task. You must not disappoint him.The exam consists of n quest...
5 4 2 4 2 3 1 1 0 1 0 0 1 4 1 7
3 2
3 seconds
256 megabytes
['binary search', 'greedy', '*3500']
G. Kuroni and Antihypetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni isn't good at economics. So he decided to found a new financial pyramid called Antihype. It has the following rules: You can join the pyramid for free and get 0 coins. If you are already ...
3 1 2 3
2
3 seconds
256 megabytes
['bitmasks', 'brute force', 'dp', 'dsu', 'graphs', '*3500']
F. Kuroni and the Punishmenttime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni is very angry at the other setters for using him as a theme! As a punishment, he forced them to solve the following problem:You have an array a consisting of n positive integers. An...
3 6 2 4
0
2.5 seconds
256 megabytes
['math', 'number theory', 'probabilities', '*2500']
E. Kuroni and the Score Distributiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni is the coordinator of the next Mathforces round written by the "Proof by AC" team. All the preparation has been done, and he is discussing with the team about the score distrib...
5 3
4 5 9 13 18
1 second
256 megabytes
['constructive algorithms', 'greedy', 'implementation', 'math', '*2200']
D. Kuroni and the Celebrationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem, Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortun...
6 1 4 4 2 5 3 6 3 2 3 3 4 4
? 5 6 ? 3 1 ? 1 2 ! 4
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'interactive', 'trees', '*1900']
C. Kuroni and Impossible Calculationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo become the king of Codeforces, Kuroni has to solve the following problem.He is given n numbers a_1, a_2, \dots, a_n. Help Kuroni to calculate \prod_{1\le i<j\le n} |a_i - a_j|. As ...
2 10 8 5
3
1 second
256 megabytes
['brute force', 'combinatorics', 'math', 'number theory', '*1600']
B. Kuroni and Simple Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifical...
(()((
1 2 1 3
1 second
256 megabytes
['constructive algorithms', 'greedy', 'strings', 'two pointers', '*1200']
A. Kuroni and the Giftstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni has n daughters. As gifts for them, he bought n necklaces and n bracelets: the i-th necklace has a brightness a_i, where all the a_i are pairwise distinct (i.e. all a_i are different), th...
2 3 1 8 5 8 4 5 3 1 7 5 6 1 2
1 8 5 8 4 5 5 1 7 6 2 1
1 second
256 megabytes
['brute force', 'constructive algorithms', 'greedy', 'sortings', '*800']
F2. Animal Observation (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraint on k.Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The c...
4 5 2 0 2 1 1 0 0 0 3 1 2 1 0 4 3 1 3 3 0 0 4
25
3 seconds
512 megabytes
['data structures', 'dp', 'greedy', '*2400']
F1. Animal Observation (easy version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraint on k.Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The c...
4 5 2 0 2 1 1 0 0 0 3 1 2 1 0 4 3 1 3 3 0 0 4
25
3 seconds
512 megabytes
['data structures', 'dp', '*2300']
E. 1-Trees and Queriestime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree?Then...
5 1 2 2 3 3 4 4 5 5 1 3 1 2 2 1 4 1 3 2 1 4 1 3 3 4 2 3 3 9 5 2 3 3 9
YES YES NO YES NO
4 seconds
512 megabytes
['data structures', 'dfs and similar', 'shortest paths', 'trees', '*2000']
D. Shortest and Longest LIStime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong recently learned how to find the longest increasing subsequence (LIS) in O(n\log{n}) time for a sequence of length n. He wants to test himself if he can implement it correctly, but he...
3 3 << 7 >><>>< 5 >>><
1 2 3 1 2 3 5 4 3 7 2 1 6 4 3 1 7 5 2 6 4 3 2 1 5 5 4 2 1 3
3 seconds
256 megabytes
['constructive algorithms', 'graphs', 'greedy', 'two pointers', '*1800']
C. Air Conditionertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.Gildong tries so hard to satisfy the customers that he even memor...
4 3 0 5 1 2 7 3 5 10 -1 0 2 12 5 7 10 10 16 20 3 -100 100 0 0 100 -50 50 200 100 100 1 100 99 -100 0
YES NO YES NO
1 second
256 megabytes
['dp', 'greedy', 'implementation', 'sortings', 'two pointers', '*1500']
B. Longest Palindrometime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputReturning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "...
3 3 tab one bat
6 tabbat
1 second
256 megabytes
['brute force', 'constructive algorithms', 'greedy', 'implementation', 'strings', '*1100']
A. Two Rabbitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBeing tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller ...
5 0 10 2 3 0 10 3 3 900000000 1000000000 1 9999999 1 2 1 1 1 3 1 1
2 -1 10 -1 1
1 second
256 megabytes
['math', '*800']
G. Sum of Prefix Sumstime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWe define the sum of prefix sums of an array [s_1, s_2, \dots, s_k] as s_1 + (s_1 + s_2) + (s_1 + s_2 + s_3) + \dots + (s_1 + s_2 + \dots + s_k).You are given a tree consisting of n vertices. Each ...
4 4 2 3 2 4 1 1 3 3 7
36
6 seconds
512 megabytes
['data structures', 'divide and conquer', 'geometry', 'trees', '*2700']
F. Number of Componentstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix n \times m, initially filled with zeroes. We define a_{i, j} as the element in the i-th row and the j-th column of the matrix.Two cells of the matrix are connected if they ...
3 2 10 2 1 1 1 2 1 2 2 1 1 1 2 3 1 2 1 2 2 2 2 2 2 1 2 3 2 4 2 1 5
2 4 3 3 4 4 4 2 2 4
4 seconds
256 megabytes
['dsu', 'implementation', '*2800']
E. Erase Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s. You can build new string p from s using the following operation no more than two times: choose any subsequence s_{i_1}, s_{i_2}, \dots, s_{i_k} where 1 \le i_1 < i_2 < \...
4 ababcd abcba a b defi fed xyz x
YES NO NO YES
2 seconds
256 megabytes
['dp', 'strings', '*2200']
D. Fill The Bagtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a bag of size n. Also you have m boxes. The size of i-th box is a_i, where each a_i is an integer non-negative power of two.You can divide boxes into two parts of equal size. Your goal is to fil...
3 10 3 1 32 1 23 4 16 1 4 1 20 5 2 1 16 1 8
2 -1 0
2 seconds
256 megabytes
['bitmasks', 'greedy', '*1900']
C. Perfect Keyboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 26 lowercase Latin letters will be arranged ...
5 ababa codedoca abcda zxzytyz abcdefghijklmnopqrstuvwxyza
YES bacdefghijklmnopqrstuvwxyz YES edocabfghijklmnpqrstuvwxyz NO YES xzytabcdefghijklmnopqrsuvw NO
2 seconds
256 megabytes
['dfs and similar', 'greedy', 'implementation', '*1600']
B. National Projecttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour company was appointed to lay new asphalt on the highway of length n. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip ...
3 5 1 1 8 10 10 1000000 1 1000000
5 8 499999500000
2 seconds
256 megabytes
['math', '*1400']
A. Erasing Zeroestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a conti...
3 010011 0 1111000
2 0 0
1 second
256 megabytes
['implementation', 'strings', '*800']
F. Keep talking and nobody explodes – easytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an unusual problem in an unusual contest, here is the announcement: http://codeforces.com/blog/entry/73543You have the safe lock which consists of 5 decimal digits. If ...
00000
61376
2 seconds
256 megabytes
['bitmasks', 'brute force', 'expression parsing']
C. Segment tree or Fenwick?time limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an unusual problem in an unusual contest, here is the announcement: http://codeforces.com/blog/entry/73543You are given an array A of length n, initially filled with zeros. You need...
2 6 5 2 1 6 1 3 2 2 2 4 1 6 3 2 1 6 5 3 1 3 7 1 1 4 2 1 5
0 2 5 11
2.5 seconds
256 megabytes
['data structures']
B. DAGtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an unusual problem in an unusual contest, here is the announcement: http://codeforces.com/blog/entry/73543You are given a directed acyclic graph G with n vertices and m edges. Denote by R(v) the set of al...
5 4 1 2 2 3 3 4 4 5
55
3 seconds
256 megabytes
['constructive algorithms']
F. Super Jabertime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJaber is a superhero in a large country that can be described as a grid with n rows and m columns, where every cell in that grid contains a different city.Jaber gave every city in that country a specific ...
3 4 5 1 2 1 3 4 4 5 5 1 2 1 3 2 1 1 3 4 2 2 2 2
2 0
5 seconds
256 megabytes
['dfs and similar', 'graphs', 'implementation', 'shortest paths', '*2600']
E. Nanosofttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWarawreh created a great company called Nanosoft. The only thing that Warawreh still has to do is to place a large picture containing its logo on top of the company's building.The logo of Nanosoft can be des...
5 5 5 RRGGB RRGGY YYBBG YYBBR RBBRG 1 1 5 5 2 2 5 5 2 2 3 3 1 1 3 5 4 4 5 5
16 4 4 4 0
2 seconds
512 megabytes
['binary search', 'data structures', 'dp', 'implementation', '*2500']
D. Time to Runtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBashar was practicing for the national programming contest. Because of sitting too much in front of the computer without doing physical movements and eating a lot Bashar became much fatter. Bashar is going...
3 3 4
YES 2 2 R 2 L
1 second
256 megabytes
['constructive algorithms', 'graphs', 'implementation', '*2000']
C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols "0" and "1"). The function f(s) is equal to the number of s...
5 3 1 3 2 3 3 4 0 5 2
4 5 6 0 12
1 second
256 megabytes
['binary search', 'combinatorics', 'greedy', 'math', 'strings', '*1700']
B. Motarack's Birthdaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.Dark created that array 1000 years ago, so some ele...
7 5 -1 10 -1 12 -1 5 -1 40 35 -1 35 6 -1 -1 9 -1 3 -1 2 -1 -1 2 0 -1 4 1 -1 3 -1 7 1 -1 7 5 2 -1 5
1 11 5 35 3 6 0 42 0 0 1 2 3 4
2 seconds
256 megabytes
['binary search', 'greedy', 'ternary search', '*1500']
A. Three Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three strings a, b and c of the same length n. The strings consist of lowercase English letters only. The i-th letter of a is a_i, the i-th letter of b is b_i, the i-th letter of c is c_i.F...
4 aaa bbb ccc abc bca bca aabb bbaa baba imi mii iim
NO YES YES NO
1 second
256 megabytes
['implementation', 'strings', '*800']
B. Assigning to Classestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputReminder: the median of the array [a_1, a_2, \dots, a_{2k+1}] of odd number of elements is defined as follows: let [b_1, b_2, \dots, b_{2k+1}] be the elements of the array in the sorted order. Th...
3 1 1 1 3 6 5 4 1 2 3 5 13 4 20 13 2 5 8 3 17 16
0 1 5
2 seconds
256 megabytes
['greedy', 'implementation', 'sortings', '*1000']
A. Non-zerotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGuy-Manuel and Thomas have an array a of n integers [a_1, a_2, \dots, a_n]. In one step they can add 1 to any element of the array. Formally, in one step they can choose any integer index i (1 \le i \le n) an...
4 3 2 -1 -1 4 -1 0 0 1 2 -1 2 3 0 -2 1
1 2 0 2
1 second
256 megabytes
['implementation', 'math', '*800']
E. So Meantime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is interactive.We have hidden a permutation p_1, p_2, \dots, p_n of numbers from 1 to n from you, where n is even. You can try to guess it using the following queries:? k a_1 a_2 \dots a_k.In res...
2 1 2
? 1 2 ? 1 1 ! 1 2
4 seconds
256 megabytes
['interactive', 'math', '*3400']
D. Around the Worldtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGuy-Manuel and Thomas are planning 144 trips around the world.You are given a simple weighted undirected connected graph with n vertexes and m edges with the following restriction: there isn't any si...
6 8 1 2 0 2 3 1 2 4 3 2 6 2 3 4 8 3 5 4 5 4 5 5 6 6
2
2 seconds
512 megabytes
['bitmasks', 'combinatorics', 'dfs and similar', 'dp', 'graphs', 'graphs', 'math', 'trees', '*3000']
C. Water Balancetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n water tanks in a row, i-th of them contains a_i liters of water. The tanks are numbered from 1 to n from left to right.You can perform the following operation: choose some subsegment [l, r] ...
4 7 5 5 7
5.666666667 5.666666667 5.666666667 7.000000000
3 seconds
256 megabytes
['data structures', 'geometry', 'greedy', '*2100']
B. Aerodynamictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGuy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) a...
4 1 0 4 1 3 4 0 3
YES
1 second
256 megabytes
['geometry', '*1800']
A. Anu Has a Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnu has created her own function f: f(x, y) = (x | y) - y where | denotes the bitwise OR operation. For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers...
4 4 0 11 6
11 6 4 0
1 second
256 megabytes
['brute force', 'greedy', 'math', '*1500']
I. Falling Blockstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRecently, Polycarp has invented a new mobile game with falling blocks.In the game, n blocks are falling down, one at a time, towards a flat surface with length d units. Each block can be represented as...
3 3 1 2 2 3 1 3
1 2 1
3 seconds
512 megabytes
['*special problem', 'data structures']
H. Paint the Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s of lowercase Latin letters. It is required to paint each letter of the string in one of two colors (red or blue) so that if you write all the red letters from left to right an...
5 kotlin codeforces abacaba ffccgc yz
RRRRBB RRRRRRRBBB RRRRBBB RBBBBR RR
1 second
256 megabytes
['*special problem', 'dp', 'strings']
G. M-numberstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor a given positive integer m, a positive number is called a m-number if the product of its digits is m. For example, the beginning of a series of 24-numbers are as follows: 38, 46, 64, 83, 138, 146, 164, ...
24 9
226
3 seconds
256 megabytes
['*special problem', 'dp', 'math']
F. Movie Fantime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Polycarp has been a fan of cinema novelties and is trying not to miss them!In the near future, n new movies will be released: the i-th of them will be airing from the day a_i and to the day b_i. T...
3 7 2 1 2 1 3 2 2 2 3 1 1 2 3 1 2 5 3 1 1 1 1 1 1 1 1 1 1 6 1 13 13 31 31 25 25 12 12 14 14 10 10
1 1 3 2 3 1 4 2 1 1 1 1 2 2 0 13 31 25 12 14 10
3 seconds
256 megabytes
['*special problem', 'data structures', 'greedy', 'implementation', 'sortings']
E. Modernization of Treelandtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTreeland consists of n cities and n-1 two-way roads connecting pairs of cities. From every city, you can reach every other city moving only by the roads. You are right, the system of cities ...
4 10 4 4 5 5 2 2 1 1 3 1 9 9 10 2 7 7 8 5 6 4 3 1 2 2 3 3 4 5 3 1 2 1 3 1 4 1 5 4 1 1 2 2 4 2 3
Yes 9 1 2 4 5 6 7 8 9 10 No Yes 4 1 3 4 5 Yes 1 4
5 seconds
256 megabytes
['*special problem', 'dfs and similar', 'trees']
D. Bonus Distribution time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor the first time, Polycarp's startup ended the year with a profit! Now he is about to distribute k burles as a bonus among n employees.It is known that the current salary of the i-th employee is...
5 4 1 3 1 4 2 2 3 10 2 4 1000000000 987654321 1000000000 999999999 500000000 8 9 5 6 1 8 3 4 2 7 6 1 6 3 1 8 5 9
0 0 1 0 0 3 134259259 121913582 121913582 621913577 2 2 0 2 0 1 0 2 1 0 0 0 0 0
3 seconds
256 megabytes
['*special problem', 'binary search', 'greedy', 'sortings']
C. Dream Teamtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is the project manager in the IT-company. Right now, he needs to choose developers for his team to start a new project. The company has n developers "on the bench" (i.e not involved in other proje...
5 5 1 -1 1 -1 1 2 11 1 3 5 -3 4 3 5 3 -4 5 -1 0 3 -3 0
2 11101 11 10 6 111 5 100 2 10100
3 seconds
256 megabytes
['*special problem', 'greedy']
B. Cartoonstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTanya likes cartoons. She knows that n new cartoons will be released in his favorite cinema: the i-th of them will be airing from the day a_i to the day b_i (1 \le a_i \le b_i \le 10^9).The cinema has a spec...
5 1 1 1 3 2 1000000000 2 500000000 500000002 1000000000 3 1 2 3 4 1 4 2 4 11 4 9 3 1 5 10 10 1 5
1 500000001 -1 10 10
3 seconds
256 megabytes
['*special problem', 'implementation', 'sortings']
A. Likes Displaytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is working on the implementation of displaying likes on the Codehorses social network. The number of likes should be displayed in a format that will be easy to read by users. It was decided tha...
9 999 123 0 1782 31415926 1500 999999 35499710 2000000000
999 123 0 2K 31M 2K 1M 35M 2000M
3 seconds
256 megabytes
['*special problem', 'implementation']
F. Berland Beautytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.You have a map of that...
4 1 2 3 2 3 4 2 1 2 5 1 3 3
5 3 5
3 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'greedy', 'sortings', 'trees', '*2100']
E2. String Coloring (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a hard version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format a...
9 abacbecfd
2 1 1 2 1 2 1 2 1 2
1 second
256 megabytes
['data structures', 'dp', '*2000']
E1. String Coloring (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format ...
9 abacbecfd
YES 001010101
1 second
256 megabytes
['constructive algorithms', 'dp', 'graphs', 'greedy', 'sortings', '*1800']
D. Fight with Monsterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n monsters standing in a row numbered from 1 to n. The i-th monster has h_i health points (hp). You have your attack power equal to a hp and your opponent has his attack power equal to b ...
6 2 3 3 7 10 50 12 1 8
5
1 second
256 megabytes
['greedy', 'sortings', '*1500']
C. Yet Another Walking Robottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a robot on a coordinate plane. Initially, the robot is located at the point (0, 0). Its path is described as a string s of length n consisting of characters 'L', 'R', 'U', 'D'.Each o...
4 4 LRUD 4 LURD 5 RRUDU 5 LLDDR
1 2 1 4 3 4 -1
1 second
256 megabytes
['data structures', 'implementation', '*1500']
B. Food Buyingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka wants to buy some food in the nearby shop. Initially, he has s burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer numbe...
6 1 10 19 9876 12345 1000000000
1 11 21 10973 13716 1111111111
1 second
256 megabytes
['math', '*900']
A. Array with Odd Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers.In one move, you can choose two indices 1 \le i, j \le n such that i \ne j and set a_i := a_j. You can perform such moves any number of times (possi...
5 2 2 3 4 2 2 8 8 3 3 3 3 4 5 5 5 5 4 1 1 1 1
YES NO YES NO NO
1 second
256 megabytes
['math', '*800']
F. Good Contesttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared n problems; and since the platform is very popular, 998244351 coder from all over t...
3 1 2 1 2 1 2
499122177
3 seconds
256 megabytes
['combinatorics', 'dp', 'probabilities', '*2700']
E. Permutation Separationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p_1, p_2, \dots , p_n (an array where each integer from 1 to n appears exactly once). The weight of the i-th element of this permutation is a_i.At first, you separat...
3 3 1 2 7 1 4
4
2 seconds
256 megabytes
['data structures', 'divide and conquer', '*2200']
D. Same GCDstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers a and m. Calculate the number of integers x such that 0 \le x < m and \gcd(a, m) = \gcd(a + x, m).Note: \gcd(a, b) is the greatest common divisor of a and b.InputThe first line co...
3 4 9 5 10 42 9999999967
6 1 9999999966
2 seconds
256 megabytes
['math', 'number theory', '*1800']
C. Obtain The Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t consisting of lowercase Latin letters. Also you have a string z which is initially empty. You want string z to be equal to string t. You can perform the following op...
3 aabce ace abacaba aax ty yyt
1 -1 3
1 second
256 megabytes
['dp', 'greedy', 'strings', '*1600']
B. Infinite Prefixestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given string s of length n consisting of 0-s and 1-s. You build an infinite string t as a concatenation of an infinite number of strings s, or t = ssss \dots For example, if s = 10010, then ...
4 6 10 010010 5 3 10101 1 0 0 2 0 01
3 0 1 -1
2 seconds
256 megabytes
['math', 'strings', '*1700']
A. Display The Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a large electronic screen which can display up to 998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists...
2 3 4
7 11
1 second
256 megabytes
['greedy', '*900']
F. Three Paths on a Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles.Your task is to choose three distinct vertices a, b, c on this tree such that ...
8 1 2 2 3 3 4 4 5 4 6 3 7 3 8
5 1 8 6
2 seconds
256 megabytes
['dfs and similar', 'dp', 'greedy', 'trees', '*2000']
E. Obtain a Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rectangular matrix of size n \times m consisting of integers from 1 to 2 \cdot 10^5.In one move, you can: choose any element of the matrix and change its value to any integer bet...
3 3 3 2 1 1 2 3 4 5 6
6
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*1900']
D. MEX maximizingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: for the array [0, 0, 1, 0, 2] MEX equals to 3 because numbers 0, 1 and 2 are presented in the...
7 3 0 1 2 2 0 0 10
1 2 3 3 4 4 7
3 seconds
256 megabytes
['data structures', 'greedy', 'implementation', 'math', '*1600']