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
C. Superior Periodic Subarraystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an infinite periodic array a0, a1, ..., an - 1, ... with the period of length n. Formally, . A periodic subarray (l, s) (0 ≀ l < n, 1 ≀ s < n) of array a is an infinite period...
Input47 1 2 3
Output2
1 second
256 megabytes
['number theory', '*2400']
B. Once Again...time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the give...
Input4 33 1 4 2
Output5
1 second
256 megabytes
['constructive algorithms', 'dp', 'matrices', '*1900']
A. GCD Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greates...
Input42 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output4 3 6 2
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'number theory', '*1700']
F. Zublicanes and Mumocratestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on n main squares of t...
Input81 42 43 46 57 58 54 5
Output1
3 seconds
512 megabytes
['dp', 'trees', 'two pointers', '*2400']
E. Kojiro and Furraritime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMotorist Kojiro spent 10 years saving up for his favorite car brand, Furrari. Finally Kojiro's dream came true! Kojiro now wants to get to his girlfriend Johanna to show off his car to her.Kojiro w...
Input8 4 1 12 40
Output0 4
2 seconds
256 megabytes
['dp', 'greedy', '*2800']
D. Three Logostime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThree companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only i...
Input5 1 2 5 5 2
Output5AAAAABBBBBBBBBBCCCCCCCCCC
1 second
256 megabytes
['bitmasks', 'brute force', 'constructive algorithms', 'geometry', 'implementation', 'math', '*1700']
C. Developing Skillstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 t...
Input2 47 9
Output2
1 second
256 megabytes
['implementation', 'math', 'sortings', '*1400']
B. Luxurious Housestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.Let's enumerate all the houses from left to right, ...
Input51 2 3 1 2
Output3 2 0 2 0
1 second
256 megabytes
['implementation', 'math', '*1100']
A. Vasya the Hipstertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.According to the latest fashion, hipsters should wear the socks of different c...
Input3 1
Output1 1
1 second
256 megabytes
['implementation', 'math', '*800']
E. Kefa and Watchtime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He...
Input3 1 21122 2 3 11 1 3 82 1 2 1
OutputNOYES
1.5 seconds
256 megabytes
['data structures', 'hashing', 'strings', '*2500']
D. Kefa and Dishestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order ...
Input2 2 11 12 1 1
Output3
2 seconds
256 megabytes
['bitmasks', 'dp', '*1800']
C. Kefa and Parktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contai...
Input4 11 1 0 01 21 31 4
Output2
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'trees', '*1500']
B. Kefa and Companytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is charact...
Input4 575 50 100150 2075 1
Output100
2 seconds
256 megabytes
['binary search', 'sortings', 'two pointers', '*1500']
A. Kefa and First Stepstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≀ i ≀ n) he makes ai money. Kefa loves progress, that's why he wants to know th...
Input62 2 1 3 4 1
Output3
2 seconds
256 megabytes
['brute force', 'dp', 'implementation', '*900']
B. Finding Team Membertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each ...
Input261 23 4 5
Output2 1 4 3
2 seconds
256 megabytes
['brute force', 'implementation', 'sortings', '*1300']
A. Raising Bacteriatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in th...
Input5
Output2
1 second
256 megabytes
['bitmasks', '*1000']
F. Mirror Boxtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a box full of mirrors. Box consists of grid of size n × m. Each cell of the grid contains a mirror put in the shape of '\' or ' / ' (45 degree to the horizontal or vertical line). But mirrors...
Input2 2 1000000007*//*
Output1
2 seconds
256 megabytes
['matrices', 'trees', '*3200']
E. Walking!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a sand trail in front of Alice's home.In daytime, people walk over it and leave a footprint on the trail for their every single step. Alice cannot distinguish the order of the footprints, but she can...
InputRRLRL
Output12 5 1 3 4
1 second
256 megabytes
['constructive algorithms', 'greedy', '*2700']
D. LCS Againtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string S of length n with each character being one of the first m lowercase English letters. Calculate how many different strings T of length n composed from the first m lowercase English le...
Input3 3aaa
Output6
2 seconds
256 megabytes
['dp', 'greedy', '*2700']
C. Weakness and Poornesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of n integers a1, a2, ..., an. Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.The weakness of a seq...
Input31 2 3
Output1.000000000000000
2 seconds
256 megabytes
['ternary search', '*2000']
B. "Or" Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make as large as possible, where denotes the bitwise ...
Input3 1 21 1 1
Output3
2 seconds
256 megabytes
['brute force', 'greedy', '*1700']
A. A Problem about Polylinetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find mi...
Input3 1
Output1.000000000000
1 second
256 megabytes
['geometry', 'math', '*1700']
B. Modulo Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of numbers a1, a2, ..., an, and a number m.Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.InputThe...
Input3 51 2 3
OutputYES
2 seconds
256 megabytes
['combinatorics', 'data structures', 'dp', 'two pointers', '*1900']
A. Multiplication Tabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1...
Input10 5
Output2
1 second
256 megabytes
['implementation', 'number theory', '*1000']
E. Painting Edgestime limit per test6 secondsmemory limit per test600 megabytesinputstandard inputoutputstandard outputNote the unusual memory limit for this problem.You are given an undirected graph consisting of n vertices and m edges. The vertices are numbered with integers from 1 to n, the edges are numbered with i...
Input3 3 2 51 22 31 31 12 13 23 12 2
OutputYESYESYESNOYES
6 seconds
600 megabytes
['binary search', 'data structures', '*3300']
D. Flights for Regular Customerstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the country there are exactly n cities numbered with positive integers from 1 to n. In each city there is an airport is located.Also, there is the only one airline, which makes m flig...
Input3 21 2 02 3 1
Output2
4 seconds
256 megabytes
['dp', 'matrices', '*2700']
C. Points on Planetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: (the distance calculated by su...
Input50 78 103 45 09 12
Output4 3 1 2 5
2 seconds
256 megabytes
['constructive algorithms', 'divide and conquer', 'geometry', 'greedy', 'sortings', '*2100']
B. Invariance of Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tree of size n is an undirected connected graph consisting of n vertices without cycles.Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for ...
Input44 3 2 1
OutputYES4 14 21 3
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'greedy', 'trees', '*2100']
A. Vasya and Petya's Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.Petya can ask questions like: "Is the unknown number divisible by number...
Input4
Output32 4 3
1 second
256 megabytes
['math', 'number theory', '*1500']
I. Robots protectiontime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputCompany "Robots industries" produces robots for territory protection. Robots protect triangle territories β€” right isosceles triangles with catheti parallel to North-South and East-West directions....
Input17 101 1 3 2 41 3 10 3 71 2 6 8 21 3 9 4 22 4 41 4 15 10 62 7 72 9 42 12 22 13 8
Output22201
1.5 seconds
512 megabytes
['data structures', '*2800']
H. Botstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. Th...
Input2
Output19
1.5 seconds
256 megabytes
['combinatorics', 'dp', 'math', 'number theory', '*1800']
G. Run for beertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeople in BubbleLand like to drink beer. Little do you know, beer here is so good and strong that every time you drink it your speed goes 10 times slower than before you drank it.Birko lives in city Beerg...
Input8 100 1 11 2 52 7 60 3 23 7 30 4 04 5 05 7 20 6 06 7 7
Output3230 3 7
1 second
256 megabytes
['dfs and similar', 'shortest paths', '*2200']
F. Bulbotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBananistan is a beautiful banana republic. Beautiful women in beautiful dresses. Beautiful statues of beautiful warlords. Beautiful stars in beautiful nights.In Bananistan people play this crazy game – Bulbo. Th...
Input5 42 79 168 109 171 6
Output8
1 second
256 megabytes
['dp', 'greedy', '*2100']
E. Spectator Riotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt’s riot time on football stadium Ramacana! Raging fans have entered the field and the police find themselves in a difficult situation. The field can be represented as a square in the coordinate syste...
Input31 1 11 1 11 2 1
Output2 22 11 0
1 second
256 megabytes
['geometry', '*2800']
D. Tablecitytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does...
InputΠ’ этой Π·Π°Π΄Π°Ρ‡Π΅ Π½Π΅Ρ‚ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² Π²Π²ΠΎΠ΄Π°-Π²Ρ‹Π²ΠΎΠ΄Π°.This problem doesn't have sample input and output.
OutputΠ‘ΠΌΠΎΡ‚Ρ€ΠΈΡ‚Π΅ Π·Π°ΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅ Π½ΠΈΠΆΠ΅.See the note below.
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1700']
C. Partytime limit per test2 secondsmemory limit per test4 megabytesinputstandard inputoutputstandard outputNote the unusual memory limit for the problem.People working in MDCS (Microsoft Development Center Serbia) like partying. They usually go to night clubs on Friday and Saturday.There are N people working in MDCS a...
Input41 2 3 42 3 4 13 4 1 24 1 2 35 8 7 16 9 81 355 78 1 61 1 1 1
Output167
2 seconds
4 megabytes
['bitmasks', 'brute force', 'graph matchings', '*2700']
B. Bribestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRuritania is a country with a very badly maintained road network, which is not exactly good news for lorry drivers that constantly have to do deliveries. In fact, when roads are maintained, they become one-way....
Input51 2 02 3 05 1 13 4 155 4 5 2 2
Output4
1 second
256 megabytes
['dfs and similar', 'graphs', 'trees', '*2200']
A. Fibonotcitime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFibonotci sequence is an integer recursive sequence defined by the recurrence relation Fn = sn - 1Β·Fn - 1 + sn - 2Β·Fn - 2 with F0 = 0, F1 = 1 Sequence s is an infinite and almost cyclic sequence with a c...
Input10 831 2 127 35 4
Output4
2 seconds
256 megabytes
['data structures', 'math', 'matrices', '*2700']
B. Bear and Three Musketeerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDo you know a story about the three musketeers? Anyway, you will learn about its origins now.Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. ...
Input5 61 21 32 32 43 44 5
Output2
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'graphs', 'hashing', '*1500']
A. Bear and Electionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.There are n candidates, including Limak. We know how many citizens are going...
Input55 1 11 2 8
Output4
1 second
256 megabytes
['greedy', 'implementation', '*1200']
E. Bear and Bowlingtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is an old brown bear. He often goes bowling with his friends. Today he feels really good and tries to beat his own record!For rolling a ball one gets a score β€” an integer (maybe negative) numbe...
Input5-2 -8 0 5 -3
Output13
6 seconds
256 megabytes
['data structures', 'greedy', '*3200']
D. Bear and Cavalrytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWould you want to fight against bears riding horses? Me neither.Limak is a grizzly bear. He is general of the dreadful army of Bearland. The most important part of an army is cavalry of course.Cavalr...
Input4 21 10 100 10003 7 2 52 42 4
Output57327532
3 seconds
256 megabytes
['data structures', 'divide and conquer', 'dp', '*3000']
C. Bear and Drawingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.Recall that tree is a...
Input81 21 31 66 46 76 57 8
OutputYes
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'trees', '*2300']
B. Bear and Blockstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for th...
Input62 1 4 6 2 2
Output3
1 second
256 megabytes
['binary search', 'data structures', 'dp', 'math', '*1600']
A. Bear and Pokertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of t...
Input475 150 75 50
OutputYes
2 seconds
256 megabytes
['implementation', 'math', 'number theory', '*1300']
B. Order Booktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this task you need to process a set of stock exchange orders and use them to create order book.An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i ...
Input6 2B 10 3S 50 2S 40 1S 50 6B 20 4B 25 10
OutputS 50 8S 40 1B 25 10B 20 4
2 seconds
256 megabytes
['data structures', 'greedy', 'implementation', 'sortings', '*1300']
A. Arraystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in...
Input3 32 11 2 33 4 5
OutputYES
2 seconds
256 megabytes
['sortings', '*900']
E. Geometric Progressionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeometric progression with the first element a and common ratio b is a sequence of numbers a, ab, ab2, ab3, ....You are given n integer geometric progressions. Your task is to find the smallest ...
Input22 24 1
Output4
1 second
256 megabytes
['math', '*3200']
D. Campustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOscolcovo city has a campus consisting of n student dormitories, n universities and n military offices. Initially, the i-th dormitory belongs to the i-th university and is assigned to the i-th military office....
Input2 7A 1Q 1U 1 2A 1Z 1Q 1Q 2
Output102
2 seconds
256 megabytes
['binary search', 'data structures', 'dsu', 'trees', '*3100']
C. CNF 2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/...
Input2 22 1 -22 2 -1
OutputYES11
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'greedy', '*2500']
B. Minimizationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n.You need to permute the array elements so that value became minimal possible. In particu...
Input3 21 2 4
Output1
2 seconds
256 megabytes
['dp', 'greedy', 'sortings', '*2000']
A. Lengthening Stickstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be i...
Input1 1 1 2
Output4
1 second
256 megabytes
['combinatorics', 'implementation', 'math', '*2100']
E. Pig and Palindromestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of n rows and m columns. We enumerate the rows of the rectangl...
Input3 4aaabbaaaabba
Output3
4 seconds
256 megabytes
['combinatorics', 'dp', '*2300']
D. Tree Requeststime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n - 1 remaining vertices has a parent in the tree. Vertex is...
Input6 51 1 1 3 3zacccd1 13 34 16 11 2
OutputYesNoYesYesYes
2 seconds
256 megabytes
['binary search', 'bitmasks', 'constructive algorithms', 'dfs and similar', 'graphs', 'trees', '*2200']
C. Replacementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDaniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two c...
Input10 3.b..bz....1 h3 c9 f
Output431
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'implementation', '*1600']
B. Simple Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.Then, by using a ...
Input3 1
Output2
1 second
256 megabytes
['constructive algorithms', 'games', 'greedy', 'implementation', 'math', '*1300']
A. Electionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is ...
Input3 31 2 32 3 11 2 1
Output2
1 second
256 megabytes
['implementation', '*1100']
B. Inventorytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCompanies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database b...
Input31 3 2
Output1 3 2
1 second
256 megabytes
['greedy', 'math', '*1200']
A. Musictime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.Unfortunately, internet is not...
Input5 2 2
Output2
2 seconds
256 megabytes
['implementation', 'math', '*1500']
E. Longest Increasing Subsequencetime limit per test1.5 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputNote that the memory limit in this problem is less than usual.Let's consider an array consisting of positive integers, some positions of which contain gaps.We have a collection of num...
Input31 2 3110
Output1 2 3
1.5 seconds
128 megabytes
['data structures', 'dp', '*3000']
D. Sign Poststime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne Khanate had a lot of roads and very little wood. Riding along the roads was inconvenient, because the roads did not have road signs indicating the direction to important cities.The Han decided that it'...
Input3 11 0 00 -1 07 -93 0
OutputYES11 2
2 seconds
256 megabytes
['brute force', 'geometry', 'math', '*2800']
C. New Languagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLiving in Byteland was good enough to begin with, but the good king decided to please his subjects and to introduce a national language. He gathered the best of wise men, and sent an expedition to farawa...
InputVC2 11 V 2 Caa
Outputab
2 seconds
256 megabytes
['2-sat', 'greedy', '*2600']
B. Symmetric and Transitivetime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many a...
Input1
Output1
1.5 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*1900']
A. Primes or Palindromes?time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasi...
Input1 1
Output40
3 seconds
256 megabytes
['brute force', 'implementation', 'math', 'number theory', '*1600']
F. Mausoleumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKing of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capi...
Input3 0
Output9
1 second
256 megabytes
['dp', '*2400']
E. President and Roadstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland has n cities, the capital is located in city s, and the historic home town of the President is in city t (s ≠ t). The cities are connected by one-way roads, the travel time for each of the...
Input6 7 1 61 2 21 3 102 3 72 4 83 5 34 5 25 6 1
OutputYESCAN 2CAN 1CAN 1CAN 1CAN 1YES
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'hashing', 'shortest paths', '*2200']
D. One-Dimensional Battle Shipstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).At the beginning of the game ...
Input11 3 354 8 6 1 11
Output3
1 second
256 megabytes
['binary search', 'data structures', 'greedy', 'sortings', '*1700']
C. Geometric Progressiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting o...
Input5 21 1 2 2 4
Output4
1 second
256 megabytes
['binary search', 'data structures', 'dp', '*1700']
B. Berland National Librarytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading ro...
Input6+ 12001- 12001- 1- 1200+ 1+ 7
Output3
1 second
256 megabytes
['implementation', '*1300']
A. Lineland Mailtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAll cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β€” a coordinate on the Ox axis. No two cities are located at a single point.Lineland resid...
Input4-5 -2 2 7
Output3 123 94 75 12
3 seconds
256 megabytes
['greedy', 'implementation', '*900']
G. Max and Mintime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo kittens, Max and Min, play with a pair of non-negative integers x and y. As you can guess from their names, kitten Max loves to maximize and kitten Min loves to minimize. As part of this game Min want...
Input2 242 432 33 23 1010 3
OutputMin
2 seconds
256 megabytes
['geometry', '*2500']
F. Clique in the Divisibility Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.Just in case, let us remind ...
Input83 4 6 8 10 18 21 24
Output3
1 second
256 megabytes
['dp', 'math', 'number theory', '*1500']
E. Restoring Maptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArchaeologists found some information about an ancient land of Treeland. We know for sure that the Treeland consisted of n cities connected by the n - 1 road, such that you can get from each city to any...
Input54 3 2 4 15 5 3 2 4 15 4 2 1 5 34 2 1 4 33 1 4 5
Output1 41 21 34 5
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'trees', '*3200']
D. Restructuring Companytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEven the most successful company can go through a crisis period when you have to make a hard decision β€” to restructure, discard and merge departments, fire employees and do other unpleasant stuf...
Input8 63 2 51 2 53 2 52 4 72 1 23 1 7
OutputNOYESYES
2 seconds
256 megabytes
['data structures', 'dsu', '*1900']
C. Logistical Questionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome country consists of n cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (n - 1) bid...
Input53 1 2 6 51 2 32 3 14 3 95 3 1
Output3 192.0
2 seconds
256 megabytes
['dfs and similar', 'divide and conquer', 'trees', '*3000']
B. Replicating Processestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more f...
Input21 2 21 2 21 2 21 2 22 1 12 1 12 1 12 1 1
OutputYES1 2 5 6 3 7 4 8
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2600']
A. Matching Namestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTeachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his...
Input5gennadygalyaborisbilltoshikbilbotoringendalfsmauggaladriel
Output114 12 51 35 23 4
2 seconds
256 megabytes
['dfs and similar', 'strings', 'trees', '*2300']
B. Gerald is into Arttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the ...
Input3 21 32 1
OutputYES
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*1200']
A. Currency System in Geraldiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that...
Input51 2 3 4 5
Output-1
2 seconds
256 megabytes
['implementation', 'sortings', '*1000']
E. Gerald and Pathtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The...
Input31 12 23 3
Output5
4 seconds
256 megabytes
['dp', 'sortings', '*3000']
D. Randomizertime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald got tired of playing board games with the usual six-sided die, and he bought a toy called Randomizer. It functions as follows.A Randomizer has its own coordinate plane on which a strictly convex p...
Input40 02 02 20 2
Output0.2
2.5 seconds
256 megabytes
['combinatorics', 'geometry', 'probabilities', '*2800']
C. Gerald and Giant Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like...
Input3 4 22 22 3
Output2
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', 'number theory', '*2200']
B. Equivalent Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we s...
Inputaabaabaa
OutputYES
2 seconds
256 megabytes
['divide and conquer', 'hashing', 'sortings', 'strings', '*1700']
A. Gerald's Hexagontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal ...
Input1 1 1 1 1 1
Output6
2 seconds
256 megabytes
['brute force', 'geometry', 'math', '*1600']
E. A Simple Tasktime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if ...
Input10 5abacdabcda7 10 05 8 11 4 03 6 07 10 1
Outputcbcaaaabdd
5 seconds
512 megabytes
['data structures', 'sortings', 'strings', '*2300']
D. Guess Your Way Out! IItime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing a...
Input3 13 4 6 0
Output7
2 seconds
256 megabytes
['data structures', 'implementation', 'sortings', '*2300']
C. Amr and Chemistrytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For ...
Input34 8 2
Output2
1 second
256 megabytes
['brute force', 'graphs', 'greedy', 'math', 'shortest paths', '*1900']
B. Amr and The Large Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.Amr doesn't care about anything in the array except the beauty of it. The beauty of the array...
Input51 1 2 2 1
Output1 5
1 second
256 megabytes
['implementation', '*1300']
A. Lala Land and Apple Treestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.Lala Land has exactly n apple t...
Input2-1 51 5
Output10
1 second
256 megabytes
['brute force', 'implementation', 'sortings', '*1100']
E. Ann and Half-Palindrometime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputTomorrow Ann takes the hardest exam of programming where she should get an excellent mark. On the last theoretical class the teacher introduced the notion of a half-palindrome. String t is a...
Inputabbabaab7
Outputabaa
1.5 seconds
512 megabytes
['data structures', 'dp', 'graphs', 'string suffix structures', 'strings', 'trees', '*2300']
D. Vitaly and Cycletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter Vitaly was expelled from the university, he became interested in the graph theory.Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once.Vitaly was wonderin...
Input4 41 21 34 24 3
Output1 2
1 second
256 megabytes
['combinatorics', 'dfs and similar', 'graphs', 'math', '*2000']
C. Arthur and Tabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.In total the table Arthur bought has n legs, the length of the i-th leg is l...
Input21 53 2
Output2
1 second
256 megabytes
['brute force', 'data structures', 'dp', 'greedy', 'math', 'sortings', '*1900']
B. Pasha and Teatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can h...
Input2 41 1 1 1
Output3
1 second
256 megabytes
['constructive algorithms', 'implementation', 'math', 'sortings', '*1500']
A. Ilya and Diplomastime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSoon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.At a meeting of the jury of the Olympiad it was decided that each of the n participants, dependi...
Input61 52 63 7
Output1 2 3
1 second
256 megabytes
['greedy', 'implementation', 'math', '*1100']
B. Case of Fake Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once w...
Input31 0 0
OutputYes
2 seconds
256 megabytes
['brute force', 'implementation', '*1100']
A. Case of the Zeros and Onestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.Once he thought about a string of length n consisting of zeroes ...
Input41100
Output0
1 second
256 megabytes
['greedy', '*900']
E. Case of Computer Networktime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible attack by hackers on a major computer network.In this network are n vertices, some pairs of ...
Input4 4 21 21 32 33 41 34 2
OutputYes
3 seconds
256 megabytes
['dfs and similar', 'graphs', 'trees', '*2800']
D. Case of a Top Secrettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrewid the Android is a galaxy-famous detective. Now he is busy with a top secret case, the details of which are not subject to disclosure.However, he needs help conducting one of the investiga...
Input3 20 3 52 31 8
Output32
2 seconds
256 megabytes
['binary search', 'implementation', 'math', '*2500']
C. Case of Chocolatetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom.A bar of chocolate can be presented as an n × n table, where each cell r...
Input6 53 4 U6 1 L2 5 L1 6 U4 3 U
Output43212
3 seconds
256 megabytes
['data structures', '*2200']
B. Case of Fugitivetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.The only dry land there is an archipelago of n n...
Input4 41 47 89 1012 144 5 3 8
OutputYes2 3 1
3 seconds
256 megabytes
['data structures', 'greedy', 'sortings', '*2000']