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. Table Compressiontime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression alg...
Input2 21 23 4
Output1 22 3
4 seconds
256 megabytes
['dfs and similar', 'dp', 'dsu', 'graphs', 'greedy', '*2200']
B. Image Previewtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from ...
Input4 2 3 10wwhw
Output2
1 second
256 megabytes
['binary search', 'brute force', 'dp', 'two pointers', '*1900']
A. Watchmentime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWatchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).Th...
Input31 17 51 5
Output2
3 seconds
256 megabytes
['data structures', 'geometry', 'math', '*1400']
E. Автобусограничение по времени на тест8 секундограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводВдоль дороги стоят n путешественников. Дорога представляет собой прямую, размерами путешественников можно пренебречь, считая их точками.Водитель автобуса Василий, благодаря мобильному прило...
Входные данные3 28 93 51 3
Выходные данные11 3
ограничение по времени на тест8 секунд
ограничение по памяти на тест256 мегабайт
['binary search', 'data structures', 'greedy', 'sortings', '*2100']
D. Дефрагментация памятиограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводПамять компьютера состоит из n ячеек, которые выстроены в ряд. Пронумеруем ячейки от 1 до n слева направо. Про каждую ячейку известно, свободна она или принадлежит какому-либ...
Входные данные40 2 2 1
Выходные данные2
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['constructive algorithms', 'greedy', 'implementation', '*1600']
C. Печать условийограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводНа тренировку по подготовке к соревнованиям по программированию пришли n команд. Тренер для каждой команды подобрал тренировку, комплект задач для i-й команды занимает ai страниц. В...
Входные данные2 3 54 6
Выходные данные2
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['constructive algorithms', 'greedy', 'sortings', '*1500']
B. Этажиограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводЕсть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от...
Входные данные4 10 5200 6
Выходные данные39
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['constructive algorithms', '*1400']
A. Любимые числа Поликарпаограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводПоликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2. По заданной последо...
Входные данные580 7 16 4 48
Выходные данные16 3
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['constructive algorithms', 'implementation', '*1000']
E. Собери числоограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводДано целое неотрицательное число k и n неотрицательных целых чисел a1, a2, ..., an. Записывая некоторые из этих чисел друг за другом в произвольном порядке и, возможно, используя каки...
Входные данные2 3123 1
Выходные данныеYES123
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['graphs', 'shortest paths', '*2300']
D. Собачки и мискиограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводНа координатной прямой сидит n собачек, i-я собачка находится в точке xi. Кроме того, на прямой есть m мисок с едой, для каждой известна её координата на прямой uj и время tj, чере...
Входные данные5 4-2 0 4 8 13-1 14 36 311 2
Выходные данные4
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['data structures', 'greedy', 'sortings', '*1900']
C. Путь Роботаограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводВам задано прямоугольное клетчатое поле, состоящее из n строк и m столбцов. Поле содержит цикл из символов «*», такой что: цикл можно обойти, посетив каждую его клетку ровно один раз,...
Входные данные3 3****.**S*
Выходные данныеLUURRDDL
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['constructive algorithms', 'dfs and similar', 'graphs', '*1100']
B. Собери столограничение по времени на тест2 секундыограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводВася купил стол, у которого n ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется,...
Входные данные31 3 2 4 5 3
Выходные данные1 52 43 3
ограничение по времени на тест2 секунды
ограничение по памяти на тест256 мегабайт
['constructive algorithms', 'sortings', '*800']
A. Наибольший подъемограничение по времени на тест1 секундаограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводПрофиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёзд...
Входные данные6 11....................*..*.......*.**.......*.**..*...**.***********
Выходные данные3 4
ограничение по времени на тест1 секунда
ограничение по памяти на тест256 мегабайт
['constructive algorithms', 'implementation', '*900']
G. Armistice Area Apportionmenttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a drawn-out mooclear arms race, Farmer John and the Mischievous Mess Makers have finally agreed to establish peace. They plan to divide the territory of Bovinia with a line passing ...
Input2 51 02 1
Output7.2111025509
3 seconds
256 megabytes
['binary search', 'geometry', '*3200']
F. Cowslip Collectionstime limit per test8 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good hortic...
Input3 3 246986
Output516
8 seconds
512 megabytes
['combinatorics', 'math', 'number theory', '*2500']
E. Intellectual Inquirytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter getting kicked out of her reporting job for not knowing the alphabet, Bessie has decided to attend school at the Fillet and Eggs Eater Academy. She has been making good progress with her st...
Input1 3ac
Output8
2 seconds
256 megabytes
['dp', 'greedy', 'strings', '*2200']
D. Robot Rapping Results Reporttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming c...
Input4 52 11 32 34 24 3
Output4
2 seconds
256 megabytes
['binary search', 'dp', 'graphs', '*1800']
C. Enduring Exodustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to sta...
Input7 20100100
Output2
2 seconds
256 megabytes
['binary search', 'two pointers', '*1600']
B. Mischievous Mess Makerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th ...
Input5 2
Output10
1 second
256 megabytes
['greedy', 'math', '*1200']
A. Amity Assessmenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the g...
InputABXCXBAC
OutputYES
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', '*1200']
C. Hostname Aliasestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are giv...
Input10http://abacaba.ru/testhttp://abacaba.ru/http://abacaba.comhttp://abacaba.com/testhttp://abacaba.de/http://abacaba.ru/testhttp://abacaba.de/testhttp://abacaba.com/http://abacaba.com/thttp://abacaba.com/test
Output1http://abacaba.de http://abacaba.ru
5 seconds
256 megabytes
['*special problem', 'binary search', 'data structures', 'implementation', 'sortings', 'strings', '*2100']
B. Processing Queriestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment ti and needs to be processed for di units of time. All ti...
Input5 12 94 810 915 219 1
Output11 19 -1 21 22
5 seconds
256 megabytes
['*special problem', 'constructive algorithms', 'data structures', 'two pointers', '*1700']
A. Parliament of Berlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indic...
Input3 2 2
Output0 31 2
1 second
256 megabytes
['*special problem', 'constructive algorithms', '*1000']
G. Choosing Adstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputOne social network developer recently suggested a new algorithm of choosing ads for users.There are n slots which advertisers can buy. It is possible to buy a segment of consecutive slots at once. The mo...
Input5 9 331 2 1 3 32 1 52 1 52 1 32 3 31 2 4 52 1 52 3 51 4 5 12 1 5
Output3 1 2 32 1 32 2 13 1 1000 10001 52 5 32 1 5
3 seconds
512 megabytes
['data structures', '*3200']
F. Bears and Juicetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n bears in the inn and p places to sleep. Bears will party together for some number of nights (and days).Bears love drinking juice. They don't like wine but they can't distinguish it from ju...
Input5 1 3
Output32
5 seconds
256 megabytes
['dp', 'math', 'meet-in-the-middle', '*2900']
E. Bear and Destroying Subtreestime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLimak is a little grizzly bear. He will once attack Deerland but now he can only destroy trees in role-playing games. Limak starts with a tree with one vertex. The only vertex has index 1...
Input71 11 12 11 21 32 22 1
Output0.75000000000.50000000001.1875000000
5 seconds
512 megabytes
['dp', 'math', 'probabilities', 'trees', '*2700']
D. Bearish Fanpagestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a social website with n fanpages, numbered 1 through n. There are also n companies, and the i-th company owns the i-th fanpage.Recently, the website created a feature called following. Each ...
Input5 1210 20 30 40 502 3 4 5 22 12 22 32 42 51 4 22 12 22 32 42 53
Output10362840369572728299 57
5 seconds
256 megabytes
['*2900']
C. Levels and Regionstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRadewoosh is playing a computer game. There are n levels, numbered 1 through n. Levels are divided into k regions (groups). Each region contains some positive number of consecutive levels.The game ...
Input4 2100 3 5 7
Output5.7428571429
3 seconds
256 megabytes
['dp', '*2400']
B. Bear and Two Pathstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.Bear Limak was once i...
Input7 112 4 7 3
Output2 7 1 3 6 5 47 1 5 4 6 2 3
2 seconds
256 megabytes
['constructive algorithms', 'graphs', '*1600']
A. Bear and Colorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.For a f...
Input41 2 1 2
Output7 3 0 0
2 seconds
256 megabytes
['implementation', '*1500']
G. Little Artem and Graphtime limit per test12 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artem is given a graph, constructed as follows: start with some k-clique, then add new vertices one by one, connecting them to k already existing vertices that form a k-clique.Artem wan...
Input3 21 2
Output3
12 seconds
256 megabytes
['*2300']
F. Little Artem and 2-SATtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artem is a very smart programmer. He knows many different difficult algorithms. Recently he has mastered in 2-SAT one.In computer science, 2-satisfiability (abbreviated as 2-SAT) is the ...
Input2 1 11 21 2
OutputSIMILAR
3 seconds
256 megabytes
['*3000']
E. Little Artem and Time Machinetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data...
Input61 1 53 5 51 2 53 6 52 3 53 7 5
Output121
2 seconds
256 megabytes
['data structures', '*2000']
D. Little Artem and Random Variabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.Consider two dices. When thrown each dic...
Input20.25 0.750.75 0.25
Output0.5 0.5 0.5 0.5
2 seconds
256 megabytes
['dp', 'implementation', 'math', 'probabilities', '*2400']
C. Little Artem and Dancetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.More detailed, there are n pa...
Input6 31 221 2
Output4 3 6 5 2 1
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', '*1800']
B. Little Artem and Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the stor...
Input2 2 62 12 23 1 1 13 2 2 23 1 2 83 2 1 8
Output8 2 1 8
2 seconds
256 megabytes
['implementation', '*1400']
A. Little Artem and Grasshoppertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.The area looks like a strip of cells 1 × n. Each cell contains the direction for the ne...
Input2><1 2
OutputFINITE
2 seconds
256 megabytes
['implementation', '*1000']
F. Bear and Chemistrytime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a smart brown bear who loves chemistry, reactions and transforming elements.In Bearland (Limak's home) there are n elements, numbered 1 through n. There are also special machines, that can...
Input6 5 41 22 33 42 45 62 04 22 16 23 43 26 3 42 54 62 11 21 2
OutputYESNOYESYES
6 seconds
256 megabytes
['data structures', 'dfs and similar', 'graphs', 'trees', '*3300']
E. Bear and Paradoxtime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a big polar bear. He prepared n problems for an algorithmic contest. The i-th problem has initial score pi. Also, testers said that it takes ti minutes to solve the i-th problem. Problems ...
Input34 3 101 1 8
Output0.62500000000
3.5 seconds
256 megabytes
['binary search', 'greedy', 'math', 'sortings', '*2800']
D. Bear and Contributiontime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCodeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. ...
Input4 3 100 3012 2 6 1
Output220
4 seconds
256 megabytes
['data structures', 'greedy', 'sortings', 'two pointers', '*2400']
C. Bear and Polynomialstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding...
Input3 100000000010 -9 -3 5
Output3
2 seconds
256 megabytes
['hashing', 'implementation', 'math', '*2200']
B. Bear and Forgotten Tree 3time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through n.Limak is a little polar bear and Radewoosh is his evil enemy. Limak once ...
Input5 3 2
Output1 21 33 43 5
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'trees', '*1600']
A. Bear and Displayed Friendstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigg...
Input4 2 8300 950 500 2001 32 42 31 11 22 12 22 3
OutputNOYESNOYESYES
2 seconds
256 megabytes
['implementation', '*1200']
D. Three-dimensional Turtle Super Computer time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1...
Input2 2 3000000111111
Output2
3 seconds
256 megabytes
['brute force', 'dfs and similar', 'graphs', '*1800']
C. Road Improvementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads.In each city there is exactl...
Input41 23 43 2
Output22 2 11 3
2 seconds
256 megabytes
['*special problem', 'dfs and similar', 'graphs', 'greedy', 'trees', '*1800']
B. Making Genome in Berlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we'...
Input3bcdabcdef
Outputabcdef
1 second
256 megabytes
['*special problem', 'dfs and similar', 'strings', '*1500']
A. Home Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the str...
Input4 2
Output2
1 second
256 megabytes
['*special problem', 'constructive algorithms', 'math', '*1100']
D. Running with Obstaclestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not ...
Input3 10 1 33 4 7
OutputRUN 2JUMP 3RUN 1JUMP 2RUN 2
2 seconds
256 megabytes
['*special problem', 'data structures', 'dp', 'greedy', '*1600']
C. Promocodes with Mistakestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". O...
Input2000000999999
Output2
1 second
256 megabytes
['*special problem', 'brute force', 'constructive algorithms', 'implementation', '*1400']
B. Chat Ordertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of...
Input4alexivanromanivan
Outputivanromanalex
3 seconds
256 megabytes
['*special problem', 'binary search', 'constructive algorithms', 'data structures', 'sortings', '*1200']
A. Voting for Photostime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and ...
Input51 3 2 2 1
Output2
1 second
256 megabytes
['*special problem', 'constructive algorithms', 'implementation', '*1000']
A. Orchestratime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPaul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a pic...
Input2 2 1 11 2
Output4
2 seconds
256 megabytes
['brute force', 'implementation', '*1100']
A. Island Puzzletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and addit...
Input31 0 22 0 1
OutputYES
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*1300']
H. Fibonacci-ish IItime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYash is finally tired of computing the length of the longest Fibonacci-ish sequence. He now plays around with more complex things such as Fibonacci-ish potentials. Fibonacci-ish potential of an array...
Input5 102 1 2 1 222 44 5
Output33
5 seconds
512 megabytes
['data structures', 'implementation', '*3100']
G. Yash And Treestime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYash loves playing with trees and gets especially excited when they have something to do with prime numbers. On his 20th birthday he was granted with a rooted tree of n nodes to answer queries on. Hear...
Input8 203 7 9 8 4 11 7 31 21 33 44 54 64 75 842 11 1 12 52 4
Output311
4 seconds
512 megabytes
['bitmasks', 'data structures', 'dfs and similar', 'math', 'number theory', '*2800']
F. The Chocolate Spreetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob have a tree (undirected acyclic connected graph). There are ai chocolates waiting to be picked up in the i-th vertex of the tree. First, they choose two different vertices as their s...
Input91 2 3 4 5 6 7 8 91 21 31 41 51 61 71 81 9
Output25
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'trees', '*2600']
E. Startup Fundingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn e-commerce startup pitches to the investors to get funding. They have been functional for n weeks now and also have a website!For each week they know the number of unique visitors during this week ...
Input3 23 2 1300 200 300
Output133.3333333
3 seconds
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'probabilities', 'two pointers', '*2400']
D. Fibonacci-ishtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements f0 and f1 are arbitrary fn + 2...
Input31 2 -1
Output3
3 seconds
512 megabytes
['brute force', 'dp', 'hashing', 'implementation', 'math', '*2000']
C. Spy Syndrome 2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many...
Input30ariksihsidlihcdnaehsetahgnisol10KirahatesishelosingdeathchildishLandNote
OutputKira is childish and he hates losing
2 seconds
256 megabytes
['data structures', 'dp', 'hashing', 'implementation', 'sortings', 'string suffix structures', 'strings', '*1900']
B. A Trivial Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with ex...
Input1
Output55 6 7 8 9
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'math', 'number theory', '*1300']
A. Ebony and Ivorytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative ...
Input4 6 15
OutputNo
2 seconds
256 megabytes
['brute force', 'math', 'number theory', '*1100']
F. Magic Matrixtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou're given a matrix A of size n × n.Let's call the matrix with nonnegative elements magic if it is symmetric (so aij = aji), aii = 0 and aij ≤ max(aik, ajk) for all triples i, j, k. Note that i, j, k d...
Input30 1 21 0 22 2 0
OutputMAGIC
5 seconds
512 megabytes
['brute force', 'divide and conquer', 'graphs', 'matrices', 'trees', '*2400']
E. Thief in a Shoptime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA thief made his way to a shop.As usual he has his lucky knapsack with him. The knapsack can contain k objects. There are n kinds of products in the shop and an infinite number of products of each kin...
Input3 21 2 3
Output2 3 4 5 6
5 seconds
512 megabytes
['divide and conquer', 'dp', 'fft', 'math', '*2400']
D. Longest Subsequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM as l. Find any longest subsequence o...
Input7 86 2 9 2 7 2 3
Output6 51 2 4 6 7
2 seconds
256 megabytes
['brute force', 'math', 'number theory', '*2100']
C. The Smallest String Concatenationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.Given the l...
Input4abbaabacababcder
Outputabacabaabbabcder
3 seconds
256 megabytes
['sortings', 'strings', '*1700']
B. Alice, Bob, Two Teamstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi.The way to split up game pieces is split i...
Input51 2 3 4 5ABABA
Output11
1.5 seconds
256 megabytes
['brute force', 'constructive algorithms', '*1400']
A. Grandma Laura and Applestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGrandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.She precis...
Input2 10halfhalfplus
Output15
1 second
256 megabytes
['*1200']
E. Product Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBlake is the boss of Kris, however, this doesn't spoil their friendship. They often gather at the bar to talk about intriguing problems about maximising some values. This time the problem is really special...
Input44 3 2 5
Output39
1 second
256 megabytes
['data structures', 'dp', 'geometry', '*2600']
D. Messengertime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputEach employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example...
Input5 33-a 2-b 4-c 3-a 2-c2-a 2-b 1-c
Output1
2 seconds
512 megabytes
['data structures', 'hashing', 'implementation', 'string suffix structures', 'strings', '*2100']
C. Reporttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the f...
Input3 11 2 32 2
Output2 1 3
2 seconds
256 megabytes
['data structures', 'sortings', '*1700']
B. Print Checktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype ...
Input3 3 31 1 32 2 11 2 2
Output3 1 3 2 2 2 0 1 0
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1200']
A. Interviewtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBlake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the intervie...
Input51 2 4 3 22 3 3 12 1
Output22
1 second
256 megabytes
['brute force', 'implementation', '*900']
R. Gametime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThere is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.The g...
Input1
Output1
0.5 seconds
64 megabytes
['games', 'math', '*1200']
Q. Pyramidstime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of th...
Input2 5 3
Output38.546168065709
0.5 seconds
64 megabytes
['geometry', 'math', '*1700']
P. Area of a Startime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIt was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that ...
Input7 10
Output108.395919545675
0.5 seconds
64 megabytes
['geometry', '*2100']
O. Arrowtime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPetya has recently started working as a programmer in the IT city company that develops computer games.Besides game mechanics implementation to create a game it is necessary to create tool programs that can be...
Input8 8 0 2 8 3 4 5
Output8.000000000000 11.0000000000004.000000000000 8.0000000000006.000000000000 8.0000000000006.000000000000 3.00000000000010.000000000000 3.00000000000010.000000000000 8.00000000000012.000000000000 8.000000000000
0.5 seconds
64 megabytes
['geometry', '*2000']
N. Forecasttime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe Department of economic development of IT City created a model of city development till year 2100.To prepare report about growth perspectives it is required to get growth estimates from the model.To get ...
Input1 30 200
Output-10.000000000000000-20.000000000000000
0.5 seconds
64 megabytes
['math', '*1300']
M. Turntime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputVasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face.One of the project's know-how is a camera rotating around its ...
Input60
Output1
0.5 seconds
64 megabytes
['geometry', 'math', '*1800']
L. Cracking the Codetime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a p...
Input12345
Output71232
0.5 seconds
64 megabytes
['implementation', 'math', '*1400']
K. Indivisibilitytime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company t...
Input12
Output2
0.5 seconds
64 megabytes
['math', 'number theory', '*1500']
J. Divisibilitytime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision t...
Input3000
Output1
0.5 seconds
64 megabytes
['math', 'number theory', '*1100']
I. Parking Lottime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputTo quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.The pa...
Input3
Output24
0.5 seconds
64 megabytes
['combinatorics', 'math', '*1700']
H. Benchestime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.The city funded purchase of five benc...
Input5
Output120
0.5 seconds
64 megabytes
['combinatorics', 'math', '*1400']
G. Challenge Pennantstime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputBecause of budget cuts one IT company established new non-financial reward system instead of bonuses.Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features...
Input2
Output24
0.5 seconds
64 megabytes
['combinatorics', 'math', '*1600']
F. Selection of Personneltime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputOne company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n re...
Input7
Output29
0.5 seconds
64 megabytes
['combinatorics', 'math', '*1300']
E. A rectangletime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputDeveloping tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.A field map consists of hexagonal cells. Since locations sizes are going to be big, ...
Input1 1 5 5
Output13
0.5 seconds
64 megabytes
['math', '*1900']
D. Hexagons!time limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputAfter a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Mig...
Input2
Output19
0.5 seconds
64 megabytes
['math', '*1100']
C. Lucky Numberstime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in ...
Input2
Output6
0.5 seconds
64 megabytes
['combinatorics', 'math', '*1100']
B. Moore's Lawtime limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.M...
Input1000 1000000
Output1011.060722383550382782399454922040
0.5 seconds
64 megabytes
['math', '*1200']
A. Again Twenty Five!time limit per test0.5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the...
Input2
Output25
0.5 seconds
64 megabytes
['number theory', '*800']
E. Famil Door and Roadstime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputFamil Door’s City map looks like a tree (undirected connected acyclic graph) so other people call it Treeland. There are n intersections in the city connected by n - 1 bidirectional roads.There a...
Input4 32 44 13 23 12 34 1
Output4.000000003.000000003.00000000
5 seconds
512 megabytes
['combinatorics', 'data structures', 'dfs and similar', 'dp', 'probabilities', 'trees', '*2300']
D. Babaei and Birthday Caketime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.Simple cake is a cylinder of some radius and height. The volume of t...
Input2100 3040 10
Output942477.796077000
2 seconds
256 megabytes
['data structures', 'dp', '*2000']
C. Famil Door and Bracketstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves s...
Input4 1(
Output4
2 seconds
256 megabytes
['dp', 'strings', '*2000']
B. Far Relative’s Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFamil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of ...
Input4M 151 307F 343 352F 117 145M 24 128
Output2
2 seconds
256 megabytes
['brute force', '*1100']
A. Far Relative’s Birthday Caketime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDoor's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!The cake is a n × n square consisting of equal squa...
Input3.CCC..C.C
Output4
1 second
256 megabytes
['brute force', 'combinatorics', 'constructive algorithms', 'implementation', '*800']
F. Bear and Fair Settime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's very unfortunate for you. He will eat all your cookies unless you can demonstrate you...
Input10 20 110 10
Outputfair
2 seconds
256 megabytes
['flows', 'graphs', '*2500']
E. Zbazi in Zeydabadtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA tourist wants to visit country Zeydabad for Zbazi (a local game in Zeydabad).The country Zeydabad is a rectangular table consisting of n rows and m columns. Each cell on the country is either 'z' ...
Input4 4zzzzzzz..z..zzzz
Output16
5 seconds
512 megabytes
['data structures', 'implementation', '*2300']
D. Magic Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.For example, the numbers 1727374,...
Input2 61099
Output8
2 seconds
256 megabytes
['dp', '*2200']
C. Bear and String Distancetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.The distance between two letters is defined as the difference between th...
Input4 26bear
Outputroar
1 second
256 megabytes
['greedy', 'strings', '*1300']
B. New Skateboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMax wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile ...
Input124
Output4
1 second
256 megabytes
['dp', '*1300']