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
D. The tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHarry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign o...
Input4 1-1-1-1-1
Output4 1 2 3 4 0
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2100']
C. Anniversarytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations.Dima is sure that...
Input10 1 8 2
Output3
2 seconds
256 megabytes
['data structures', 'implementation', 'math', 'matrices', 'number theory', '*2400']
B. Naughty Stone Pilestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile...
Input52 3 4 1 122 3
Output9 8
2 seconds
256 megabytes
['greedy', '*1900']
A. Flying Saucer Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).The flying saucer, on which the brave pi...
Input1 10
Output2
2 seconds
256 megabytes
['math', '*1400']
E. Unsolvabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the following equation: where sign [a] represents the integer part of number a.Let's find all integer z (z > 0), for which this equation is unsolvable in positive integers. The phrase "unsolvable...
Input1
Output1
2 seconds
256 megabytes
['math', 'number theory', '*2100']
D. Snaketime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet us remind you the rules of a very popular game called "Snake" (or sometimes "Boa", "Python" or "Worm").The game field is represented by an n × m rectangular table. Some squares of the field are considered i...
Input4 5##.....1#@432#....#.
Output4
4 seconds
256 megabytes
['bitmasks', 'dfs and similar', 'graphs', 'implementation', '*2200']
C. Barcodetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.A picture is a barcode if the following conditio...
Input6 5 1 2##.#..###.###..#...#.##.####..
Output11
2 seconds
256 megabytes
['dp', 'matrices', '*1700']
B. Well-known Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNumbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: F(k, n) = 0, for integer n, 1 ≀ n < k; F(k, k) = 1; F(k, n) = F(k, n - 1) + F(k, ...
Input5 2
Output30 2 3
2 seconds
256 megabytes
['binary search', 'greedy', 'number theory', '*1600']
A. Dice Towertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are m...
Input363 25 42 4
OutputYES
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1100']
B. Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≀ l ≀ r ≀ n) such, that among numbers al,  al + 1,  ...,  ar there are exactly k d...
Input4 21 2 2 3
Output1 2
2 seconds
256 megabytes
['bitmasks', 'implementation', 'two pointers', '*1500']
A. Parallelepipedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this paral...
Input1 1 1
Output12
2 seconds
256 megabytes
['brute force', 'geometry', 'math', '*1100']
E. Planar Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA graph is called planar, if it can be drawn in such a way that its edges intersect only at their vertexes.An articulation point is such a vertex of an undirected graph, that when removed increases the nu...
Input3 31 22 33 10 01 00 113 1 2 3
Output3
1 second
256 megabytes
['flows', 'geometry', 'graphs', '*3000']
D. Spidertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA plane contains a not necessarily convex polygon without self-intersections, consisting of n vertexes, numbered from 1 to n. There is a spider sitting on the border of the polygon, the spider can move like th...
Input40 01 01 10 11 4
Output1.000000000000000000e+000
3 seconds
256 megabytes
['geometry', 'graphs', '*3000']
C. Partial Sumstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: First we build by the array a an array s of partial sums, con...
Input3 11 2 3
Output1 3 6
4 seconds
256 megabytes
['combinatorics', 'math', 'number theory', '*1900']
B. Two Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≀ k1 < k2 < ... < k|x| ≀ |s|).You've got two stringsΒ β€” s and t. Let's consid...
Inputababab
OutputYes
2 seconds
256 megabytes
['data structures', 'dp', 'strings', '*1900']
A. Bracket Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA bracket sequence is a string, containing only characters "(", ")", "[" and "]".A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inser...
Input([])
Output1([])
2 seconds
256 megabytes
['data structures', 'expression parsing', 'implementation', '*1700']
E. Decoding Genometime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different n...
Input3 3 2abba
Output17
2 seconds
256 megabytes
['dp', 'matrices', '*1900']
D. Olympiadtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the...
Input5 21 1 1 1 11 1 1 1 1
Output1 5
1 second
256 megabytes
['binary search', 'greedy', 'sortings', 'two pointers', '*1900']
C. Reducing Fractionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the f...
Input3 2100 5 250 10
Output2 32 11 1 1
2 seconds
256 megabytes
['implementation', 'math', 'number theory', 'sortings', '*1800']
B. Cosmic Tablestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDH...
Input3 3 51 2 34 5 67 8 9g 3 2r 3 2c 2 3g 2 2g 3 2
Output896
3 seconds
256 megabytes
['data structures', 'implementation', '*1300']
A. Shooshuns and Sequence time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day shooshuns found a sequence of n integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: Find the number that goes k-th...
Input3 23 1 1
Output1
2 seconds
256 megabytes
['brute force', 'implementation', '*1200']
B. Little Elephant and Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves numbers. He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at le...
Input1
Output1
2 seconds
256 megabytes
['implementation', '*1300']
A. Little Elephant and Functiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of t...
Input1
Output1
2 seconds
256 megabytes
['implementation', 'math', '*1000']
E. Little Elephant and Inversionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.The Little Elephant wants to count, how many pairs of...
Input3 11 3 2
Output3
2 seconds
256 megabytes
['data structures', 'two pointers', '*2400']
D. Little Elephant and Triangletime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant is playing with the Cartesian coordinates' system. Most of all he likes playing with integer points. The Little Elephant defines an integer point as a pair of integers...
Input2 1
Output36
3 seconds
256 megabytes
['geometry', 'math', '*2500']
C. Little Elephant and Shiftstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≀ i ≀ n) element of the permutation a as ai, the j-th (1...
Input21 22 1
Output10
2 seconds
256 megabytes
['data structures', '*2100']
B. Little Elephant and Arraytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Ele...
Input7 23 1 2 2 3 3 71 73 4
Output31
4 seconds
256 megabytes
['constructive algorithms', 'data structures', '*1800']
A. Little Elephant and Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant has got a problem β€” somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.The Little Elephant does...
Input21 2
OutputYES
2 seconds
256 megabytes
['implementation', 'sortings', '*1300']
E. Parking Lottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA parking lot in the City consists of n parking spaces, standing in a line. The parking spaces are numbered from 1 to n from left to right. When a car arrives at the lot, the operator determines an empty ...
Input7 111 151 1231231 31 52 1231232 151 212 31 61 71 8
Output17427413
2 seconds
256 megabytes
['data structures', '*2200']
D. Choosing Capital for Treelandtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the dir...
Input32 12 3
Output02
3 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'trees', '*1700']
C. Color Stripetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of th...
Input6 3ABBACC
Output2ABCACA
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', '*1600']
B. Special Offer! Super Price 999 Bourles!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to sta...
Input1029 102
Output999
1 second
256 megabytes
['implementation', '*1400']
A. k-Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not...
Input2aazz
Outputazaz
2 seconds
256 megabytes
['implementation', 'strings', '*1000']
B. Airporttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: it is up to a passenger to choose a plane to fly on; if...
Input4 32 1 1
Output5 5
2 seconds
256 megabytes
['implementation', '*1100']
A. Mountain Scenerytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points wi...
Input3 20 5 3 5 1 5 2
Output0 5 3 4 1 4 2
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', '*1100']
E. Alien DNAtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor Bajtocy is conducting experiments on alien DNA. He has discovered that it is subject to repetitive mutations β€” each mutation happens in the same way: some continuous subsequence of the alien DNA b...
InputGAGA40
OutputGAGA
2 seconds
256 megabytes
['data structures', 'dsu', 'trees', '*2800']
D. Bitonix' Patroltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputByteland is trying to send a space mission onto the Bit-X planet. Their task is complicated by the fact that the orbit of the planet is regularly patrolled by Captain Bitonix, the leader of the space ...
Input7 6 55 4 12 6 5
Output6
2 seconds
256 megabytes
['bitmasks', 'brute force', 'combinatorics', 'dfs and similar', 'math', '*2900']
C. Formurosatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Bytelandian Institute for Biological Research (BIBR) is investigating the properties of two species of bacteria, named simply 0 and 1. Even under a microscope, bacteria of those two species are very diff...
Input2(?^?)
OutputNO
1 second
256 megabytes
['divide and conquer', 'dp', 'expression parsing', '*2600']
B. Blackboard Fibonaccitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFibonacci numbers are the sequence of integers: f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, ..., fn = fn - 2 + fn - 1. So every next number is the sum of the previous two.Bajtek has developed ...
Input6 10
Output2TBBTTB
1 second
256 megabytes
['brute force', 'math', '*2100']
A. Ice Skatingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift....
Input22 11 2
Output1
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'dsu', 'graphs', '*1200']
E. Martian Lucktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou know that the Martians use a number system with base k. Digit b (0 ≀ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology...
Input10 5 63 2 0 5 6 1
Output5
2 seconds
256 megabytes
['math', 'number theory', '*2000']
D. Spider's Webtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPaw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web. There are n main threads going from the center of the we...
Input73 1 6 74 3 5 2 92 8 14 3 7 6 43 2 5 93 6 3 83 4 2 9
Output6
2 seconds
256 megabytes
['binary search', 'sortings', 'two pointers', '*1700']
C. Hiring Stafftime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff.The store will work seven days a week, but not around the clock. Every day at ...
Input4 3 2
Output41 1 4 5
2 seconds
256 megabytes
['greedy', '*1800']
B. Forming Teamstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archen...
Input5 41 22 45 31 4
Output1
2 seconds
256 megabytes
['dfs and similar', 'implementation', '*1700']
A. Tiling with Hexagonstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSeveral ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The fl...
Input2 3 4
Output18
2 seconds
256 megabytes
['implementation', 'math', '*1200']
E. Periodical Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA non-empty string s is called binary, if it consists only of characters "0" and "1". Let's number the characters of binary string s from 1 to the string's length and let's denote the i-th characte...
Input1 10
Output3
2 seconds
256 megabytes
['combinatorics', 'dp', 'number theory', '*2100']
D. Hot Daystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1 ≀ i ≀ n) region has a stable temperature of...
Input2 1030 35 1 10020 35 10 10
Output120
2 seconds
256 megabytes
['greedy', '*1900']
C. Crossestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell th...
Input2 2 1
Output4
2 seconds
256 megabytes
['brute force', 'implementation', '*2100']
B. Olympic Medaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/c...
Input3 1 2 31 23 3 2 11 2
Output2.683281573000
2 seconds
256 megabytes
['greedy', 'math', '*1300']
A. Bicycle Chaintime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal...
Input24 5312 13 15
Output2
2 seconds
256 megabytes
['brute force', 'implementation', '*900']
B. Hometasktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the tas...
Input10
Output0
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'greedy', 'math', '*1600']
A. System of Equationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik sol...
Input9 3
Output1
2 seconds
256 megabytes
['brute force', '*800']
E. Two Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRubik is very keen on number permutations. A permutation a with length n is a sequence, consisting of n different numbers from 1 to n. Element number i (1 ≀ i ≀ n) of this permutation will be denoted...
Input1 111
Output1
2 seconds
256 megabytes
['data structures', 'hashing', 'strings', '*2700']
D. Starstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurik loves painting stars. A star is a shape that results if we take a regular pentagon and paint all diagonals in it. Recently he decided to teach Rubik to paint stars. After many years of training Rubik co...
Input1
Output53.830127018922193 3.366025403784439-3.601321235851749 10.0573314673730210.466045194906253 19.19278604379903010.411264148588986 18.14750141112249512.490381056766580 8.3660254037844391 2 3 4 51 3 5 2 4 1
2 seconds
256 megabytes
['constructive algorithms', 'geometry', '*2300']
C. Relay Racetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n × n cells (represented as unit squares), each cell has some ...
Input15
Output5
4 seconds
256 megabytes
['dp', '*2000']
B. Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.There is integer n and array...
Input10 0 0 0 0 0 0 0 0 1
Output1
2 seconds
256 megabytes
['combinatorics', 'dp', '*1900']
A. Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some o...
Input110
Output1
1 second
256 megabytes
['dfs and similar', 'greedy', '*1700']
E. IT Restaurantstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputΠ‘ity N. has a huge problem with roads, food and IT-infrastructure. In total the city has n junctions, some pairs of them are connected by bidirectional roads. The road network consists of n - 1 roads...
Input51 22 33 44 5
Output31 32 23 1
1.5 seconds
256 megabytes
['dfs and similar', 'dp', 'trees', '*1500']
D. Cutting a Fencetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya the carpenter has an estate that is separated from the wood by a fence. The fence consists of n planks put in a line. The fence is not closed in a circle. The planks are numbered from left to ri...
Input33 2 131 2 3
Output2.0000000000000001.5000000000000001.000000000000000
5 seconds
256 megabytes
['binary search', 'data structures', 'dsu', '*2500']
C. Cowboystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA very tense moment: n cowboys stand in a circle and each one points his colt at a neighbor. Each cowboy can point the colt to the person who follows or precedes him in clockwise direction. Human life is wort...
InputBABBBABBA
Output2
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*2100']
B. Polycarpus is Looking for Good Substringstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe'll call string s[a, b] = sasa + 1... sb (1 ≀ a ≀ b ≀ |s|) a substring of string s = s1s2... s|s|, where |s| is the length of string s.The trace of a non-empty string t is ...
Inputaaaaa2aa
Output11
4 seconds
256 megabytes
['bitmasks', 'hashing', 'implementation', '*2300']
A. Privatizationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a developed network of flights between Berland and Beerland. All of them belong to the Berland state company BerAvia. Each flight connects some Berland city with some Beerland city. For each fl...
Input3 5 8 21 41 33 31 21 12 11 52 2
Output42 1 2 1 2 1 2 2
2 seconds
256 megabytes
['flows', 'graphs', '*3000']
C. Trails and Gladestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya went for a walk in the park. The park has n glades, numbered from 1 to n. There are m trails between the glades. The trails are numbered from 1 to m, where the i-th trail connects glades xi an...
Input3 31 22 33 1
Output0
4 seconds
256 megabytes
['constructive algorithms', 'dsu', 'graphs', 'greedy', '*2400']
B. Pixelstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFlatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of p...
Input1 1 1
Output1
2 seconds
256 megabytes
['constructive algorithms', 'math', '*2100']
A. Multicolored Marblestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.A non-empty sequence of red and blue marbles is a ze...
Input3
Output6
2 seconds
256 megabytes
['dp', 'math', '*1600']
E. Blood Cousinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus got hold of a family relationship tree. The tree describes family relationships of n people, numbered 1 through n. Each person in the tree has no more than one parent.Let's call person a a 1-...
Input60 1 1 0 4 471 11 22 12 24 15 16 1
Output0 0 1 0 0 1 1
2 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'trees', '*2100']
D. Prizes, Prizes, more Prizestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules,...
Input33 10 42 4 10 15 20
Output1 1 1 0 0 1
2 seconds
256 megabytes
['implementation', '*1200']
C. Police Stationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital β€” number 1. The road n...
Input4 41 22 41 33 4
Output1.000000000000
2 seconds
256 megabytes
['dp', 'graphs', 'shortest paths', '*1900']
B. Solitairetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA boy named Vasya wants to play an old Russian solitaire called "Accordion". In this solitaire, the player must observe the following rules: A deck of n cards is carefully shuffled, then all n cards are pu...
Input42S 2S 2C 2C
OutputYES
2 seconds
256 megabytes
['dfs and similar', 'dp', '*1900']
A. Dubsteptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.Let's assume th...
InputWUBWUBABCWUB
OutputABC
2 seconds
256 megabytes
['strings', '*900']
C3. Game with Two Treestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY has come up with a new developing game for children. The Beaver thinks that this game will help children to understand programming better.The main object of the game is...
Input51 1 a2 1 a1 2 b2 1 b2 3 a
Output13347
1 second
256 megabytes
['data structures', '*2700']
C2. Game with Two Treestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY has come up with a new developing game for children. The Beaver thinks that this game will help children to understand programming better.The main object of the game is...
Input51 1 a2 1 a1 2 b2 1 b2 3 a
Output13347
1 second
256 megabytes
['*2200']
C1. Game with Two Treestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY has come up with a new developing game for children. The Beaver thinks that this game will help children to understand programming better.The main object of the game is...
Input51 1 a2 1 a1 2 b2 1 b2 3 a
Output13347
1 second
256 megabytes
['*2100']
B3. Military Trainingstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY started cooperating with the Ministry of Defence. Now they train soldiers to move armoured columns. The training involves testing a new type of tanks that can transmit ...
Input3211
Output5
3 seconds
256 megabytes
['*1700']
B2. Military Trainingstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY started cooperating with the Ministry of Defence. Now they train soldiers to move armoured columns. The training involves testing a new type of tanks that can transmit ...
Input3211
Output5
3 seconds
256 megabytes
['*1900']
B1. Military Trainingstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY started cooperating with the Ministry of Defence. Now they train soldiers to move armoured columns. The training involves testing a new type of tanks that can transmit ...
Input3211
Output5
3 seconds
256 megabytes
['*1600']
A3. Beaver's Calculator 1.0time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be ...
Input22 1 1 1 102 3 1 1 10
Output01 12 13 24 2
3 seconds
256 megabytes
['greedy', '*2000']
A2. Beaver's Calculator 1.0time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be ...
Input22 1 1 1 102 3 1 1 10
Output01 12 13 24 2
3 seconds
256 megabytes
['greedy', '*1800']
A1. Beaver's Calculator 1.0time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be ...
Input22 1 1 1 102 3 1 1 10
Output01 12 13 24 2
3 seconds
256 megabytes
['greedy', '*1600']
B. Little Elephant and Sortingtime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves sortings.He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elepha...
Input31 2 3
Output0
0.5 seconds
256 megabytes
['brute force', 'greedy', '*1400']
A. Little Elephant and Rozdiltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. ...
Input27 4
Output2
2 seconds
256 megabytes
['brute force', 'implementation', '*900']
E. Little Elephant and Stringstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves strings very much. He has an array a from n strings, consisting of lowercase English letters. Let's number the elements of the array from 1 to n, then let's denot...
Input3 1abcaab
Output6 1 3
3 seconds
256 megabytes
['data structures', 'implementation', 'string suffix structures', 'two pointers', '*2800']
D. Little Elephant and Retro Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant has found a ragged old black-and-white string s on the attic.The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the le...
Input3 2XXX
Output0
2 seconds
256 megabytes
['dp', '*2400']
C. Little Elephant and Furik and Rubiktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Elephant loves Furik and Rubik, who he met in a small city Kremenchug.The Little Elephant has two strings of equal length a and b, consisting only of uppercase English lette...
Input2ABBA
Output0.400000000
2 seconds
256 megabytes
['math', 'probabilities', '*2000']
B. Little Elephant and Cardstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves to play with color cards.He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on t...
Input34 74 77 4
Output0
2 seconds
256 megabytes
['binary search', 'data structures', '*1500']
A. Little Elephant and Intervaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant very much loves sums on intervals.This time he has a pair of integers l and r (l ≀ r). The Little Elephant has to find the number of such integers x (l ≀ x ≀ r), that ...
Input2 47
Output12
2 seconds
256 megabytes
['binary search', 'combinatorics', 'dp', '*1500']
E. Transportationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera came to Japan and bought many robots for his research. He's already at the airport, the plane will fly very soon and Valera urgently needs to bring all robots to the luggage compartment.The robo...
Input3 10 100 12 101 6 100 1 1
Output2 6
2 seconds
256 megabytes
['greedy', 'sortings', 'two pointers', '*2300']
D. Hit Balltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his...
Input7 2 113 -11 2
Output6.5000000000 2.0000000000
2 seconds
256 megabytes
['geometry', 'implementation', 'math', '*1700']
C. Photographertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maxi...
Input3 102 31 42 11 0
Output23 2
2 seconds
256 megabytes
['greedy', 'sortings', '*1400']
B. Game on Papertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.He took a checkered white square piece of paper, consisting of n × n cells. After...
Input4 111 11 21 32 22 31 42 43 43 23 34 1
Output10
2 seconds
256 megabytes
['brute force', 'implementation', '*1300']
A. Two Problemstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not ...
Input30 5 20 20 3 5
OutputYES
2 seconds
256 megabytes
['brute force', 'implementation', '*1200']
B. Brand New Easy Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Mat...
Input4find the next palindrome110 find the previous palindrome or print better luck next time
Output1[:||||||:]
2 seconds
256 megabytes
['brute force', '*1700']
A. LLPStime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.You are given string s consisting of lowercase English letters only. Find its lexicograph...
Inputradar
Outputrr
2 seconds
256 megabytes
['binary search', 'bitmasks', 'brute force', 'greedy', 'implementation', 'strings', '*800']
E. Thoroughly Bureaucratic Organizationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce n people simultaneously signed in to the reception at the recently opened, but already thoroughly bureaucratic organization (abbreviated TBO). As the organization is thorough...
Input54 14 27 31 142 7
Output323011
2 seconds
256 megabytes
['binary search', 'combinatorics', '*2600']
D. Brand New Problemtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (S...
Input4find the next palindrome110 find the previous palindrome or print better luck next time
Output1[:||||||:]
5 seconds
256 megabytes
['bitmasks', 'brute force', 'dp', '*2600']
C. Fragile Bridgestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave ...
Input52 1 2 1
Output5
2 seconds
256 megabytes
['dp', '*2000']
B. Guess That Car!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called "Guess That Car!".The g...
Input2 33 4 53 9 1
Output3921 1
2 seconds
256 megabytes
['math', 'ternary search', '*1800']
A. Clear Symmetrytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We...
Input4
Output3
2 seconds
256 megabytes
['constructive algorithms', 'dp', 'math', '*1700']
E. Tractor Collegetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile most students still sit their exams, the tractor college has completed the summer exam session. In fact, students study only one subject at this college β€” the Art of Operating a Tractor. Therefo...
Input5 113 4 3 5 5
Output1 3 3
4 seconds
256 megabytes
['implementation', 'math', 'number theory', 'ternary search', '*2400']
D. Programming Languagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools o...
Input4void f(int,T)void f(T, T) void foo123 ( int, double, string,string ) void p(T,double)3int a string sdouble x123 5f(a, a) f(s,a )foo (a,s,s) f ( s ,x123)proc(a)
Output21010
2 seconds
256 megabytes
['binary search', 'brute force', 'expression parsing', 'implementation', '*1800']