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. Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be of them.You want to draw these s...
Input2
Output2
2 seconds
256 megabytes
['constructive algorithms', 'math', '*1300']
A. Generate Logintime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the pre...
Inputharry potter
Outputhap
2 seconds
256 megabytes
['brute force', 'greedy', 'sortings', '*1000']
H. New Year and Boolean Bridgestime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYour friend has a hidden directed graph with n nodes.Let f(u, v) be true if there is a directed path from node u to node v, and false otherwise. For each pair of distinct nodes, u, v, you...
Input4-AAAA-AAAA-AAAA-
Output4
5 seconds
512 megabytes
['*3100']
G. New Year and Original Ordertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, S(50394) = 3459, S(353535) = 333555.Given a number X, compute modulo 109 + 7.I...
Input21
Output195
2 seconds
256 megabytes
['dp', 'math', '*2800']
F. New Year and Rainbow Roadstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoy and Biv have a set of n points on the infinite number line.Each point has one of 3 colors: red, green, or blue.Roy and Biv would like to connect all the points with some edges. Edges ca...
Input41 G5 R10 B15 G
Output23
2 seconds
256 megabytes
['graphs', 'greedy', 'implementation', '*2400']
E. New Year and Entity Enumerationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer m.Let M = 2m - 1.You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m.A set of ...
Input5 3110100010111000
Output4
2 seconds
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'math', '*2500']
D. New Year and Arbitrary Arrangementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three integers k, pa and pb.You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. Wi...
Input1 1 1
Output2
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*2200']
C. New Year and Curlingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCarol is currently curling.She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100.She then will slide the disks towards the line y = 0 one ...
Input6 25 5 6 8 3 12
Output2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613
2 seconds
256 megabytes
['brute force', 'geometry', 'implementation', 'math', '*1500']
B. New Year and Buggy Bottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob programmed a robot to navigate through a 2d maze.The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.There is a single robot in the ...
Input5 6.....#S....#.#.....#.......E..333300012
Output1
1 second
256 megabytes
['brute force', 'implementation', '*1200']
A. New Year and Counting Cardstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour friend has n cards.You know that each card has a lowercase English letter on one side and a digit on the other.Currently, your friend has laid out the cards on a table so only one side...
Inputee
Output2
1 second
256 megabytes
['brute force', 'implementation', '*800']
B. Tic-Tac-Toetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.The game is played on the following...
Input... ... ...... ... ...... ... ...... ... ...... ... ...... x.. ...... ... ...... ... ...... ... ...6 4
Output... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ...
2 seconds
256 megabytes
['implementation', '*1400']
A. Masha and Bearstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes ...
Input50 30 10 10
Output503010
2 seconds
256 megabytes
['brute force', 'implementation', '*1300']
E. Reversestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHurricane came to Berland and to suburbs Stringsvill. You are going to it to check if it's all right with you favorite string. Hurrinace broke it a bit by reversing some of its non-intersecting substrings. Y...
Inputabcxxxdefcbaxxxfed
Output27 91 3
2 seconds
256 megabytes
['dp', 'string suffix structures', 'strings', '*3300']
D. Power Towertime limit per test4.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPriests of the Quetzalcoatl cult want to build a tower to represent a power of their god. Tower is usually made of power-charged rocks. It is built with the help of rare magic by levitating the current ...
Input6 10000000001 2 2 3 3 381 11 62 22 32 44 44 54 6
Output1124256327597484987
4.5 seconds
256 megabytes
['chinese remainder theorem', 'math', 'number theory', '*2700']
C. Partytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guest...
Input5 61 21 32 32 53 44 5
Output22 3
1 second
256 megabytes
['bitmasks', 'brute force', 'dp', 'graphs', '*2400']
B. Seating of Studentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudents went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that stude...
Input2 4
OutputYES5 4 7 2 3 6 1 8
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'math', '*2200']
A. Shockerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that conta...
Input5! abc. ad. b! cd? c
Output1
2 seconds
256 megabytes
['implementation', 'strings', '*1600']
G. Yet Another Maxflow Problemtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem you will have to deal with a very special network.The network consists of two parts: part A and part B. Each part consists of n vertices; i-th vertex of part A is denoted a...
Input4 3 21 23 45 62 2 71 4 84 3 91 1002 100
Output91414
4 seconds
256 megabytes
['data structures', 'flows', 'graphs', '*2700']
F. Clear The Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix f with 4 rows and n columns. Each element of the matrix is either an asterisk (*) or a dot (.).You may perform the following operation arbitrary number of times: choose a square...
Input41 10 8 20***.***.***....*
Output9
1 second
256 megabytes
['bitmasks', 'dp', '*2200']
E. Swapping Characterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exact...
Input3 4abaccaabacba
Outputacab
1 second
256 megabytes
['brute force', 'hashing', 'implementation', 'strings', '*2200']
D. Almost Differencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote a function You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.InputThe first line contains one i...
Input51 2 3 1 3
Output4
2 seconds
256 megabytes
['data structures', 'math', '*2200']
C. Boxes Packingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.Mishka can put a box i into another box j if the following conditions are met: i-th box is not put into anot...
Input31 2 3
Output1
1 second
256 megabytes
['greedy', '*1200']
B. The Modcrabtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.After two hours of playing the game Vova has tracked the mon...
Input10 6 10017 5
Output4STRIKEHEALSTRIKESTRIKE
1 second
256 megabytes
['greedy', 'implementation', '*1200']
A. Hungry Student Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.CFK sells chicken chunks in small and large portions. A small portion...
Input265
OutputYESNO
1 second
256 megabytes
['greedy', 'implementation', '*900']
B. Coloring a Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.Each vertex has a color, let's denote the color of vertex v by cv. Initially cv = 0.Y...
Input61 2 2 1 52 1 1 1 1 1
Output3
1 second
256 megabytes
['dfs and similar', 'dsu', 'greedy', '*1200']
A. Visiting a Friendtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPig is visiting a friend.Pig's house is located at point 0, and his friend's house is located at point m on an axis.Pig can use teleports to move along the axis.To use a teleport, Pig should come to ...
Input3 50 22 43 5
OutputYES
1 second
256 megabytes
['greedy', 'implementation', '*1100']
E. Cyclic Ciphertime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Senor Vorpal Kickass'o invented an innovative method to encrypt integer sequences of length n. To encrypt a sequence, one has to choose a secret sequence , that acts as a key.Vorpal is very selective,...
Input110
Output11
5 seconds
256 megabytes
['fft', 'math', '*3300']
D. Weighting a Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a connected undirected graph with n vertices and m edges. The vertices are enumerated from 1 to n. You are given n integers c1, c2, ..., cn, each of them is between  - n and n, inclusiv...
Input3 32 2 21 22 31 3
OutputYES111
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', '*2700']
C. Bipartite Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph with n vertices. There are no edge-simple cycles with the even length in it. In other words, there are no cycles of even length that pass each edge at most once. L...
Input6 61 22 33 14 55 66 431 34 61 6
Output5514
2 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'dsu', 'graphs', 'two pointers', '*2300']
B. GCD of Polynomialstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you have two polynomials and . Then polynomial can be uniquely represented in the following way:This can be done using long division. Here, denotes the degree of polynomial P(x). is cal...
Input1
Output10 101
2 seconds
256 megabytes
['constructive algorithms', 'math', '*2200']
A. Hashing Treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced p...
Input21 1 1
Outputperfect
2 seconds
256 megabytes
['constructive algorithms', 'trees', '*1500']
E. Maximum Questionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' ...
Input5bb?a?1
Output2
2 seconds
256 megabytes
['data structures', 'dp', 'strings', '*2100']
D. Unusual Sequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCount the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such that gcd(a1, a2, ..., an) = x and . As this number could be large, print the answer modulo 109 + 7...
Input3 9
Output3
1 second
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'math', 'number theory', '*2000']
C. Remove Extra Onetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.We remind that in a sequence of numbers a1, a2, ..., ak the element a...
Input11
Output1
2 seconds
256 megabytes
['brute force', 'data structures', 'math', '*1700']
B. Position in Fractiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.InputThe first contains three single positive integers a, b, c (1 ≤...
Input1 2 0
Output2
1 second
256 megabytes
['math', 'number theory', '*1300']
A. Find Extra Onetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.InputThe first line con...
Input31 1-1 -12 -1
OutputYes
1 second
256 megabytes
['geometry', 'implementation', '*800']
F. Letters Removingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has a string of length n consisting of small and large English letters and digits.He performs m operations. Each operation is described with two integers l and r and a character c: Petya remove...
Input4 2abac1 3 a2 2 c
Outputb
2 seconds
256 megabytes
['data structures', 'strings', '*2100']
E. Segments Removaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has an array of integers of length n.Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are se...
Input42 5 5 2
Output2
2 seconds
256 megabytes
['data structures', 'dsu', 'flows', 'implementation', 'two pointers', '*2000']
D. Shovel Saletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps want...
Input7
Output3
1 second
256 megabytes
['constructive algorithms', 'math', '*1800']
C. Dividing the numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible...
Input4
Output02 1 4
1 second
256 megabytes
['constructive algorithms', 'graphs', 'math', '*1300']
B. Months and Yearstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April...
Input431 31 30 31
OutputYes
1 second
256 megabytes
['implementation', '*1200']
A. Splitting in Teamstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the sa...
Input41 1 2 1
Output1
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', '*800']
F. Restoring the Expressiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restor...
Input12345168
Output123+45=168
2 seconds
256 megabytes
['brute force', 'hashing', 'math', '*2300']
E. Squares and not squarestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnn and Borya have n piles with candies and n is even number. There are ai candies in pile with number i.Ann likes numbers which are square of some integer and Borya doesn't like numbers which...
Input412 14 30 4
Output2
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1600']
D. Alarm Clocktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings....
Input3 3 23 5 1
Output1
2 seconds
256 megabytes
['greedy', '*1600']
C. Phone Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.Vasya decided to organize information about the phone ...
Input2ivan 1 00123masha 1 00123
Output2masha 1 00123 ivan 1 00123
2 seconds
256 megabytes
['implementation', 'strings', '*1400']
B. Proper Nutritiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars...
Input723
OutputYES2 1
1 second
256 megabytes
['brute force', 'implementation', 'number theory', '*1100']
A. Roundingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.For example, if n = 4722 answer is 4720. If n...
Input5
Output0
1 second
256 megabytes
['implementation', 'math', '*800']
B. Chtholly's requesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output — Thanks a lot for today.— I experienced so many great things.— You gave me memories like dreams... But I have to leave now...— One last request, can you...— Help me solve a Codeforces problem?— ....
Input2 100
Output33
2 seconds
256 megabytes
['brute force', '*1300']
A. Scarborough Fairtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAre you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No...
Input3 1ioi1 1 i n
Outputnoi
2 seconds
256 megabytes
['implementation', '*800']
E. Welcome home, Chthollytime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output— I... I survived.— Welcome home, Chtholly.— I kept my promise...— I made it... I really made it!After several days of fighting, Chtholly Nota Seniorious miraculously returned from the fierce b...
Input5 61 5 5 5 82 2 5 51 2 4 32 2 5 22 2 5 51 3 5 12 1 5 1
Output3303
3 seconds
512 megabytes
['data structures', 'dsu', '*3100']
D. Nephren Runs a Cinematime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema.However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently),...
Input4 97 2 3
Output13
2.5 seconds
256 megabytes
['chinese remainder theorem', 'combinatorics', 'math', 'number theory', '*2900']
C. Willem, Chtholly and Seniorioustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output— Willem...— What's the matter?— It seems that there's something wrong with Seniorious...— I'll have a look...Seniorious is made by linking special talismans in particular order.After ...
Input10 10 7 9
Output2103
2 seconds
256 megabytes
['data structures', 'probabilities', '*2600']
B. Ithea Plays With Chthollytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. Refer to the Interaction section below for better understanding.Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.In...
Input2 4 4213
Output122
1 second
256 megabytes
['binary search', 'constructive algorithms', 'games', 'greedy', 'interactive', '*2000']
A. Nephren gives a riddletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhat are you doing at the end of the world? Are you busy? Will you save us?Nephren is playing a game with little leprechauns.She gives them an infinite array of strings, f0... ∞.f0 is "What are...
Input31 11 21 111111111111
OutputWh.
2 seconds
256 megabytes
['binary search', 'dfs and similar', '*1700']
E. Eyes Closedtime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya and Petya were tired of studying so they decided to play a game. Before the game begins Vasya looks at array a consisting of n integers. As soon as he remembers all elements of a the game begins. ...
Input4 41 1 2 21 2 2 3 32 1 21 1 2 3 42 1 2
Output3.00000003.0000000
2.5 seconds
256 megabytes
['data structures', 'probabilities', '*2300']
D. String Marktime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexicographically smaller than x.Recently at the BSU was an important test work on ...
Inputabcddd
Output5
4 seconds
256 megabytes
['combinatorics', 'math', 'strings', '*2100']
C. Square Subsetstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way ...
Input41 1 1 1
Output15
4 seconds
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'math', '*2000']
B. XK Segmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer...
Input4 2 11 3 5 7
Output3
1 second
256 megabytes
['binary search', 'math', 'sortings', 'two pointers', '*1700']
A. Pizza Separationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudents Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delive...
Input490 90 90 90
Output0
1 second
256 megabytes
['brute force', 'implementation', '*1200']
E. Ralph and Mushroomstime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRalph is going to collect mushrooms in the Mushroom Forest. There are m directed paths connecting n trees in the Mushroom Forest. On each path grow some mushrooms. When Ralph passes a path, he c...
Input2 21 2 42 1 41
Output16
2.5 seconds
512 megabytes
['dp', 'graphs', '*2100']
D. Ralph And His Tour in Binary Countrytime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRalph is in the Binary Country. The Binary Country consists of n cities and (n - 1) bidirectional roads connecting the cities. The roads are numbered from 1 to (n - 1), the i-th...
Input2 251 82 4
Output114
2.5 seconds
512 megabytes
['brute force', 'data structures', 'trees', '*2200']
C. Marco and GCD Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.When he woke up, he only remembered that the ...
Input42 4 6 12
Output34 6 12
1 second
256 megabytes
['constructive algorithms', 'math', '*1900']
B. Ralph And His Magic Fieldtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRalph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn...
Input1 1 -1
Output1
1 second
256 megabytes
['combinatorics', 'constructive algorithms', 'math', 'number theory', '*1800']
A. QAQtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great n...
InputQAQAQYSYIOIWIN
Output4
1 second
256 megabytes
['brute force', 'dp', '*800']
F. Subtree Minimum Querytime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree consisting of n vertices. Each vertex has a number written on it; number ai is written on vertex i.Let's denote d(i, j) as the distance between vertices i and j in th...
Input5 21 3 2 3 52 35 13 44 121 22 3
Output25
6 seconds
512 megabytes
['data structures', 'trees', '*2300']
E. Counting Arraystime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integer numbers x and y. An array F is called an y-factorization of x iff the following conditions are met: There are y elements in F, and all of them are integer numbers; ...
Input26 34 2
Output366
3 seconds
256 megabytes
['combinatorics', 'dp', 'math', 'number theory', '*2000']
D. Credit Cardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.She starts with 0 money on her account.In the evening of i-th day a transaction ai occurs. If ai...
Input5 10-1 5 0 -5 3
Output0
2 seconds
256 megabytes
['data structures', 'dp', 'greedy', 'implementation', '*1900']
C. Rumortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of ...
Input5 22 5 3 4 81 44 5
Output10
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'greedy', '*1300']
B. Beautiful Divisorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k c...
Input3
Output1
2 seconds
256 megabytes
['brute force', 'implementation', '*1000']
A. Chess For Threetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for t...
Input3112
OutputYES
1 second
256 megabytes
['implementation', '*900']
B. Wrathtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHands that shed innocent blood!There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at ...
Input40 1 0 10
Output1
2 seconds
256 megabytes
['greedy', 'implementation', 'two pointers', '*1200']
A. Greedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai  ≤  bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can ...
Input23 53 6
OutputYES
2 seconds
256 megabytes
['greedy', 'implementation', '*900']
E. Lusttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA false witness that speaketh lies!You are given a sequence containing n integers. There is a variable res that is equal to 0 initially. The following process repeats k times.Choose an index from 1 to n uniforml...
Input2 15 5
Output5
2 seconds
256 megabytes
['combinatorics', 'math', 'matrices', '*3000']
D. Slothtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSloth is bad, mkay? So we decided to prepare a problem to punish lazy guys.You are given a tree, you should count the number of ways to remove an edge from it and then add an edge to it such that the final grap...
Input41 22 33 4
Output8
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graph matchings', 'trees', '*3100']
C. Envytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of its edges is minimum possible.You are given a graph G. If you ...
Input5 71 2 21 3 22 3 12 4 13 4 13 5 24 5 242 3 43 3 4 52 1 72 1 2
OutputYESNOYESNO
2 seconds
256 megabytes
['data structures', 'dsu', 'graphs', '*2300']
B. Gluttonytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x1, x2, ..., xk} (1 ≤ xi ≤ n, 0 < k < n) the sums of elements on th...
Input21 2
Output2 1
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2000']
A. Pridetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the greate...
Input52 2 3 4 6
Output5
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'math', 'number theory', '*1500']
E. Mod Mod Modtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of integers a1, a2, ..., an. Let , and for 1 ≤ i < n. Here, denotes the modulus operation. Find the maximum value of f(x, 1) over all nonnegative integers x. InputThe first line...
Input210 5
Output13
2 seconds
256 megabytes
['binary search', 'dp', 'math', '*3000']
G. Xor-MSTtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a complete undirected graph with n vertices. A number ai is assigned to each vertex, and the weight of an edge between vertices i and j is equal to ai xor aj.Calculate the weight of the minimum ...
Input51 2 3 4 5
Output8
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'data structures', '*2300']
F. Connecting Verticestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). Y...
Input30 0 10 0 11 1 0
Output1
4 seconds
256 megabytes
['dp', 'graphs', '*2500']
E. Maximum Subsequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the val...
Input4 45 2 4 1
Output3
1 second
256 megabytes
['bitmasks', 'divide and conquer', 'meet-in-the-middle', '*1800']
D. Almost Identity Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.Let's call a permutation an almost identity permutation iff there exist at leas...
Input4 1
Output1
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*1600']
C. K-Dominant Charactertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.You have to find minimum ...
Inputabacaba
Output2
2 seconds
256 megabytes
['binary search', 'implementation', 'two pointers', '*1400']
B. Buggy Robottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform: U — m...
Input4LDUR
Output4
2 seconds
256 megabytes
['greedy', '*1000']
A. Local Extrematime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local...
Input31 2 3
Output0
1 second
256 megabytes
['brute force', 'implementation', '*800']
F. Row of Modelstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDuring the final part of fashion show all models come to the stage and stay in one row and fashion designer stays to right to model on the right. During the rehearsal, Izabella noticed, that row isn't n...
Input5 42 3 5 2 5
OutputNO
2 seconds
512 megabytes
['greedy', 'sortings', '*2500']
E. Little Brothertime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMasha's little brother draw two points on a sheet of paper. After that, he draws some circles and gave the sheet to his sister. Masha has just returned from geometry lesson so she instantly noticed som...
Input2 4 7 1333 0 112 4 2-4 14 2
Output5.1478150705
3 seconds
512 megabytes
['binary search', 'geometry', 'sortings', '*2800']
D. Ratings and Reality Showstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each phot...
Input5 1 1 1 4 0 51 12 13 14 05 0
Output6
2 seconds
256 megabytes
['data structures', 'two pointers', '*2400']
C. Solution for Cubetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.It's too hard to learn to solve Rubik'...
Input2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
OutputNO
2 seconds
256 megabytes
['brute force', 'implementation', '*1500']
B. Cubes for Mashatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAbsent-minded Masha got set of n cubes for her birthday.At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make ...
Input30 1 2 3 4 56 7 8 9 0 12 3 4 5 6 7
Output87
1 second
256 megabytes
['brute force', 'implementation', '*1300']
A. Div. 64time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTop-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to...
Input100010001
Outputyes
1 second
256 megabytes
['implementation', '*1000']
F. Symmetric Projectionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number...
Input31 22 13 3
Output3
2 seconds
256 megabytes
['geometry', '*2900']
E. Maximum Elementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his ...
Input5 2
Output22
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*2400']
D. Restoration of stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.You are given a set of strings. A string (n...
Input4mailailrucf
Outputcfmailru
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'implementation', '*2000']
C. Petya and Catacombstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.Catacombs consist of several rooms ...
Input20 0
Output2
1 second
256 megabytes
['dsu', 'greedy', 'implementation', 'trees', '*1300']
B. Vlad and Cafestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had...
Input51 3 2 1 2
Output3
2 seconds
256 megabytes
['*1000']
A. ACM ICPCtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the dec...
Input1 3 2 1 2 1
OutputYES
2 seconds
256 megabytes
['brute force', '*1000']
F. Anti-Palindromizetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) ai ≠ am - i + 1.Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form so...
Input8abacabac1 1 1 1 1 1 1 1
Output8
2 seconds
256 megabytes
['flows', 'graphs', 'greedy', '*2500']
E. Binary Matrixtime limit per test3 secondsmemory limit per test16 megabytesinputstandard inputoutputstandard outputYou are given a matrix of size n × m. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if th...
Input3 41A8
Output3
3 seconds
16 megabytes
['dsu', '*2500']