problem_statement
stringlengths
147
8.53k
input
stringlengths
1
771
output
stringlengths
1
592
time_limit
stringclasses
32 values
memory_limit
stringclasses
21 values
tags
stringlengths
6
168
B. The Same Calendartime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.The calendar is ...
Input2016
Output2044
1 second
256 megabytes
['implementation', '*1600']
A. Johny Likes Numberstime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.InputThe only line contains two integers n and k (1 ≤ n, ...
Input5 3
Output6
0.5 seconds
256 megabytes
['implementation', 'math', '*800']
E. Vanya and Balloonstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVanya plays a game of balloons on the field of size n × n, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all value...
Input41233021320200303
Output108
3 seconds
512 megabytes
['binary search', 'brute force', 'dp', 'implementation', '*2300']
D. Vanya and Treasuretime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya is in the palace that can be represented as a grid n × m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest ...
Input3 4 32 1 1 11 1 1 12 1 1 3
Output5
1.5 seconds
256 megabytes
['data structures', 'dp', 'graphs', 'shortest paths', '*2300']
C. Vanya and Labeltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya ...
Inputz
Output3
1 second
256 megabytes
['bitmasks', 'combinatorics', 'implementation', 'strings', '*1500']
B. Vanya and Food Processortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each seco...
Input5 6 35 4 3 2 1
Output5
1 second
256 megabytes
['implementation', 'math', '*1400']
A. Vanya and Fencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the heigh...
Input3 74 5 14
Output4
1 second
256 megabytes
['implementation', '*800']
E. The Last Fight Between Human and AItime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight be...
Input1 2-1?
OutputYes
1 second
256 megabytes
['math', '*2400']
D. Theseus and labyrinthtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTheseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of blocks of size 1 × 1.Each block of the labyrinth ha...
Input2 2+**U1 12 2
Output-1
3 seconds
256 megabytes
['graphs', 'implementation', 'shortest paths', '*2000']
C. Vasya and Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHigh school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (con...
Input4 2abba
Output4
1 second
256 megabytes
['binary search', 'dp', 'strings', 'two pointers', '*1500']
B. Pyramid of Glassestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid...
Input3 5
Output4
1 second
256 megabytes
['implementation', 'math', 'math', '*1500']
A. Nicholas and Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.Nicholas want the minimum element (integer 1) and the maximum elemen...
Input54 5 1 3 2
Output3
1 second
256 megabytes
['constructive algorithms', 'implementation', '*800']
E. Trains and Statistictime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at...
Input44 4 4
Output6
2 seconds
256 megabytes
['data structures', 'dp', 'greedy', '*2300']
D. Tree Constructiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.You are given ...
Input31 2 3
Output1 2
2 seconds
256 megabytes
['data structures', 'trees', '*1800']
C. Money Transferstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours...
Input35 0 -5
Output1
1 second
256 megabytes
['constructive algorithms', 'data structures', 'greedy', 'sortings', '*2100']
B. Restoring Paintingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. ...
Input2 1 1 1 2
Output2
1 second
256 megabytes
['brute force', 'constructive algorithms', 'math', '*1400']
A. Infinite Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equ...
Input1 7 3
OutputYES
1 second
256 megabytes
['math', '*1100']
B. Problems for Roundtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of s...
Input5 21 45 2
Output2
2 seconds
256 megabytes
['greedy', 'implementation', '*1300']
A. Bear and Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.Each minute can be either interesting or boring. If 15 consecutive minutes ar...
Input37 20 88
Output35
2 seconds
256 megabytes
['implementation', '*800']
B. Different is Goodtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it whe...
Input2aa
Output1
2 seconds
256 megabytes
['constructive algorithms', 'implementation', 'strings', '*1000']
A. Summer Camptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.This is your first year at summer camp, and you are asked to solve the following problem. All integers...
Input3
Output3
1 second
256 megabytes
['implementation', '*800']
E. Organizing a Racetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKekoland is a country with n beautiful cities numbered from left to right and connected by n - 1 roads. The i-th road connects cities i and i + 1 and length of this road is wi kilometers. When you d...
Input4 42 2 21 1 1 1
Output4
3 seconds
256 megabytes
['data structures', 'greedy', '*3300']
D. Roads in Yuslandtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMayor of Yusland just won the lottery and decided to spent money on something good for town. For example, repair all the roads in the town.Yusland consists of n intersections connected by n - 1 bidir...
Input6 51 21 33 44 54 62 1 23 1 44 1 35 3 16 3 2
Output8
4 seconds
256 megabytes
['data structures', 'dp', 'greedy', '*2900']
C. Ultimate Weirdness of an Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYasin has an array a containing n integers. Yasin is a 5 year old, so he loves ultimate weird things.Yasin denotes weirdness of an array as maximum gcd(ai,  aj) value among all 1 ≤ i < ...
Input32 6 3
Output6
2 seconds
256 megabytes
['data structures', 'number theory', '*2800']
B. Robin Hoodtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.There are n citizens in Kekoland, each person has ci c...
Input4 11 1 4 2
Output2
1 second
256 megabytes
['binary search', 'greedy', '*2000']
A. Recycling Bottlestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.We can think Central Perk as coordi...
Input3 1 1 2 0 031 12 12 3
Output11.084259940083
2 seconds
256 megabytes
['dp', 'geometry', 'greedy', 'implementation', '*1800']
F. Restore a Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n. Magically, all the numbers were shu...
Input003512021
Output30021
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'strings', '*2300']
E. Correct Bracket Sequence Editortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get...
Input8 4 5(())()()RDLD
Output()
2 seconds
256 megabytes
['data structures', 'dsu', 'strings', '*1700']
D2. Magic Powder - 2time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe term of this problem is the same as the previous one, the only exception — increased restrictions.InputThe first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the n...
Input1 100000000011000000000
Output2000000000
1 second
256 megabytes
['binary search', 'implementation', '*1500']
D1. Magic Powder - 1time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find ...
Input3 12 1 411 3 16
Output4
1 second
256 megabytes
['binary search', 'brute force', 'implementation', '*1400']
C. Cinematime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMoscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of...
Input32 3 223 22 3
Output2
2 seconds
256 megabytes
['implementation', 'sortings', '*1300']
B. Game of Robotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Bel...
Input2 21 2
Output1
1 second
256 megabytes
['implementation', '*1000']
A. Holidaystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possib...
Input14
Output4 4
1 second
256 megabytes
['brute force', 'constructive algorithms', 'greedy', 'math', '*900']
A. Little Artem and Presentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that p...
Input1
Output1
2 seconds
256 megabytes
['math', '*800']
B. Coat of Anticubismtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous ...
Input31 2 1
Output1
1 second
256 megabytes
['constructive algorithms', 'geometry', '*1100']
A. Pouring Raintime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent ...
Input1 2 3 100
OutputNO
1 second
256 megabytes
['geometry', 'math', '*1100']
E. Forensic Examinationtime limit per test6 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputThe country of Reberland is the archenemy of Berland. Recently the authorities of Berland arrested a Reberlandian spy who tried to bring the leaflets intended for agitational propaganda to Berlan...
Inputsuffixtree3suffixtreesareawesomecartesiantreeisworsethansegmenttreenyeeheeheee21 2 1 101 3 9 10
Output1 13 4
6 seconds
768 megabytes
['data structures', 'string suffix structures', '*3100']
D. Chain Reactiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGroup of Berland scientists, with whom you have a close business relationship, makes a research in the area of peaceful nuclear energy. In particular, they found that a group of four nanobots, placed o...
Input21 11 -1-1 1-1 -11 12 24 46 6
Output01 11 -1-1 1-1 -1-1
3 seconds
256 megabytes
['brute force', 'geometry', '*3000']
C. Codewordtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe famous sculptor Cicasso is a Reberlandian spy!These is breaking news in Berlandian papers today. And now the sculptor is hiding. This time you give the shelter to the maestro. You have a protected bunker...
Input3a2 21 bc2 5
Output51162626
6 seconds
256 megabytes
['combinatorics', 'strings', '*2500']
B. World Tourtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA famous sculptor Cicasso goes to a world tour!Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exc...
Input8 91 22 33 44 14 55 66 77 88 5
Output2 1 8 7
5 seconds
512 megabytes
['graphs', 'shortest paths', '*2000']
A. Reberland Linguisticstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFirst-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to h...
Inputabacabaca
Output3acabaca
1 second
256 megabytes
['dp', 'implementation', 'strings', '*1800']
F. Four Divisorstime limit per test10 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputIf an integer a is divisible by another integer b, then b is called the divisor of a.For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12.Let’s define a function D(n) — number of inte...
Input10
Output3
10 seconds
768 megabytes
['data structures', 'dp', 'math', 'number theory', 'sortings', 'two pointers', '*2400']
E. Beautiful Subarraystime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputOne day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an.A subarray of the array a is a sequence al,  al  +  1,  ...,  ar for some integers (l,  r) such that 1  ≤  ...
Input3 11 2 3
Output5
3 seconds
512 megabytes
['data structures', 'divide and conquer', 'strings', 'trees', '*2100']
D. Simple Subsettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i,  j) (1  ≤ i  <  j ≤ k), xi  +  xj is a prime.You are given an array a with n positive integers a1...
Input22 3
Output23 2
1 second
256 megabytes
['constructive algorithms', 'greedy', 'number theory', '*1800']
C. Simple Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputzscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.zscoder is given a st...
Inputaab
Outputbab
2 seconds
256 megabytes
['dp', 'greedy', 'strings', '*1300']
B. Shoppingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the a...
Input2 2 53 4 1 2 51 53 1
Output14
1 second
256 megabytes
['brute force', '*1400']
A. Buses Between Citiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBuses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a...
Input10 3010 3505:20
Output5
1 second
256 megabytes
['implementation', '*1600']
A. Complicated GCDtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGreatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find grea...
Input1 2
Output1
1 second
256 megabytes
['math', 'number theory', '*800']
A. Rebustime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with ...
Input? + ? - ? + ? + ? = 42
OutputPossible9 + 13 - 39 + 28 + 31 = 42
1 second
256 megabytes
['constructive algorithms', 'expression parsing', 'greedy', 'math', '*1800']
E. To Hack or not to Hacktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a regular Codeforces round consisting of three problems that uses dynamic scoring.You are given an almost final scoreboard. For each participant (including yourself), the time of the ac...
Input4120 120 161 61 120-61 61 1200 0 0
Output1
1 second
256 megabytes
['brute force', 'dp', 'greedy', '*3100']
D. International Olympiadtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInternational Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last d...
Input5IAO'15IAO'2015IAO'1IAO'9IAO'0
Output201512015199119891990
1 second
256 megabytes
['constructive algorithms', 'greedy', 'implementation', 'math', '*2000']
C. Binary Tabletime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a table consisting of n rows and m columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace...
Input3 4011010100111
Output2
6 seconds
256 megabytes
['bitmasks', 'brute force', 'divide and conquer', 'dp', 'fft', 'math', '*2600']
B. Graph Coloringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edge...
Input3 31 2 B3 1 R3 2 B
Output12
1 second
256 megabytes
['dfs and similar', 'graphs', '*2200']
A. Gambling Nimtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAs you know, the game of "Nim" is played with n piles of stones, where the i-th pile initially contains ai stones. Two players alternate the turns. During a turn a player picks any non-empty pile and rem...
Input21 11 1
Output0/1
2 seconds
512 megabytes
['bitmasks', 'math', 'matrices', 'probabilities', '*2400']
H. Rotate Matrixtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a square matrix of integer numbers. Rotate it 90 degrees clockwise (see examples for clarification of rotation).InputThe input consists of n lines (1 ≤ n ≤ 10, n is not given explicitly). E...
Input1 2 34 5 67 8 9
Output7 4 18 5 29 6 3
2 seconds
64 megabytes
['*special problem', '*2400']
G. Hungarian Notationtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIn Hungarian notation, a variable name is prefixed with a letter or a group of letters which are mnemonics for the type of that variable. For the purposes of this problem we will consider only two d...
Inputcount18
OutputiCount
2 seconds
64 megabytes
['*special problem', '*2200']
F. Primes in Intervaltime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given two integers a and b (a ≤ b). How many prime numbers are there on the interval from a to b, inclusive?InputThe input contains two integers a and b (2 ≤ a ≤ b ≤ 1 000 000), separated by...
Input10 20
Output4
2 seconds
64 megabytes
['*special problem', '*1900']
E. Divisibility Checktime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given an array of integers. Check whether there exists a number in this array which is divisible by all other numbers in this array. Output 1, if such a number exists, and 0 otherwise.InputT...
Input6 12 4
Output1
2 seconds
64 megabytes
['*special problem', '*2000']
D. Maximal Differencetime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given an array of integers ai. Find the largest absolute value of difference between adjacent elements of the array max(abs(ai - ai + 1)).InputThe only line of the input contains a list of s...
Input2 10 4 8 6 12
Output8
2 seconds
64 megabytes
['*special problem', '*2100']
C. Array Sumtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given an array of integers. Calculate the sum of its elements.InputThe i-th line of the input contains an integer ai (0 ≤ a ≤ 1000) — the i-th element of the array. The size of the array is between 1...
Input2151103
Output130
2 seconds
64 megabytes
['*special problem', '*2000']
B. Seasonstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a name of a month. Output the season of the year to which it belongs (based on Northern hemisphere).InputThe input consists of a single string containing the name of one of the twelve months (Jan...
InputApril
Outputspring
2 seconds
64 megabytes
['*special problem', '*1900']
A. Lazy Caterer Sequencetime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputLazy caterer sequence is defined as the maximum number of pieces formed when slicing a convex pancake with n cuts (each cut is a straight line). The formula is Cn = n·(n + 1) / 2 + 1. You are giv...
Input2
Output4
2 seconds
64 megabytes
['*special problem', '*1300']
F. Bear and Bowling 4time limit per test2 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) num...
Input65 -1000 1 -3 7 -8
Output16
2 seconds
256 megabytes
['binary search', 'data structures', 'divide and conquer', 'geometry', 'ternary search', '*2500']
E. Different Subsets For All Tuplestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence).You are given two positive integer...
Input1 3
Output6
2 seconds
256 megabytes
['combinatorics', 'math', '*2300']
D. Number of Parallelogramstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.InputThe firs...
Input40 11 01 12 0
Output1
4 seconds
256 megabytes
['geometry', '*1900']
C. Hard Processtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a with n elements. Each element of a is either 0 or 1.Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You ca...
Input7 11 0 0 1 1 0 1
Output41 0 0 1 1 1 1
1 second
256 megabytes
['binary search', 'dp', 'two pointers', '*1600']
B. Seating On Bustime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.Consider that m...
Input2 7
Output5 1 6 2 7 3 4
1 second
256 megabytes
['implementation', '*1000']
A. Co-prime Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n elements, you must make it a co-prime array in as few moves as possible.In each move you can insert any positive integral number you want not greater than 109 in any place in...
Input32 7 28
Output12 7 9 28
1 second
256 megabytes
['greedy', 'implementation', 'math', 'number theory', '*1200']
G. Fence Divercitytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLong ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeter...
Input21 1
Output0
2 seconds
256 megabytes
['combinatorics', 'dp', 'number theory', '*2300']
F. Polycarp and Haytime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table, where n is the number of rows, and m is the number of columns in the table. Each cell of the tabl...
Input2 3 3510 4 99 9 7
OutputYES7 0 7 7 7 7
4 seconds
512 megabytes
['dfs and similar', 'dsu', 'graphs', 'greedy', 'sortings', '*2000']
E. New Reformtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city...
Input4 32 11 34 3
Output1
1 second
256 megabytes
['data structures', 'dfs and similar', 'dsu', 'graphs', 'greedy', '*1600']
D. Bicycle Racetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaria participates in a bicycle race.The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the nor...
Input60 00 11 11 22 22 00 0
Output1
1 second
256 megabytes
['geometry', 'implementation', 'math', '*1500']
C. Tanya and Toystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bou...
Input3 71 3 4
Output22 5
1 second
256 megabytes
['greedy', 'implementation', '*1200']
B. Qualifying Contesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVery soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form team...
Input5 2Ivanov 1 763Andreev 2 800Petrov 1 595Sidorov 1 790Semenov 2 503
OutputSidorov IvanovAndreev Semenov
1 second
256 megabytes
['constructive algorithms', 'sortings', '*1300']
A. Round Housetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.Today Vasya got bored and decided to take a walk in the yard. Vasy...
Input6 2 -5
Output3
1 second
256 megabytes
['implementation', 'math', '*1000']
A. Bear and Reverse Radewooshtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.There will be n pro...
Input3 250 85 25010 15 25
OutputLimak
2 seconds
256 megabytes
['implementation', '*800']
G. You're a Professionaltime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputA simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.You are given user's friends' opi...
Input3 3 2YYYNNNYNY
Output2
2 seconds
64 megabytes
['*special problem', '*1900']
F. Ace It!time limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputInputThe only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").OutputOutput a single...
InputA221033
Output21
2 seconds
64 megabytes
['*special problem', '*1900']
E. Out of Controlstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and retu...
Input30 1 11 0 41 4 0
Output2
2 seconds
64 megabytes
['*special problem', '*2000']
D. Rosetta Problemtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+ ++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>+++++++ +++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>>.<<<<<<<<<...
Input129
Output1
2 seconds
64 megabytes
['*special problem', '*2100']
C. Without Texttime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output You can preview the image in better quality by the link: http://assets.codeforces.com/files/656/without-text.pngInputThe only line of the input is a string (between 1 and 50 characters long, inclusive)....
InputCodeforces
Output-87
2 seconds
64 megabytes
['*special problem', '*2000']
B. Scrambledtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputBtoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow ar...
Input120
Output0.500000
2 seconds
64 megabytes
['*special problem', 'implementation', '*1700']
A. Da Vinci Powerstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputInputThe input contains a single integer a (0 ≤ a ≤ 35).OutputOutput a single integer.ExamplesInput3Output8Input10Output1024
Input3
Output8
2 seconds
64 megabytes
['*special problem', '*1900']
G. Move by Primetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPussycat Sonya has an array consisting of n positive integers. There are 2n possible subsequences of the array. For each subsequence she counts the minimum number of operations to make all its elements ...
Input360 60 40
Output6
5 seconds
256 megabytes
['combinatorics', 'math', 'number theory', '*3100']
F. Paper tasktime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAlex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he ...
Input10()()()()()
Output5
3 seconds
512 megabytes
['data structures', 'string suffix structures', 'strings', '*2600']
E. Bear and Forgotten Tree 2time 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. He once had a tree with n vertices but he l...
Input5 4 21 22 34 24 1
Outputpossible
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'graphs', 'trees', '*2400']
D. Delivery Bearstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNiwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.In the city, Niwel took on a job managing bears to...
Input4 4 31 2 22 4 11 3 13 4 2
Output1.5000000000
2 seconds
256 megabytes
['binary search', 'flows', 'graphs', '*2200']
C. Bear and Up-Downtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied: ti < ti + 1 for each odd i < n; ti > ti + 1 for each eve...
Input52 8 4 7 7
Output2
2 seconds
256 megabytes
['brute force', 'implementation', '*1900']
B. Bear and Compressingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English al...
Input3 5ab acc cca aee cff d
Output4
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'dp', 'strings', '*1300']
A. Bear and Three Ballstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. He has n balls, the i-th ball has size ti.Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to...
Input418 55 16 17
OutputYES
2 seconds
256 megabytes
['brute force', 'implementation', 'sortings', '*900']
F. Ants on a Circletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn ants are on a circle of length m. An ant travels one unit of distance per one unit of time. Initially, the ant number i is located at the position si and is facing in the direction di (which is eit...
Input2 4 81 R3 L
Output1 3
2 seconds
256 megabytes
['constructive algorithms', 'math', '*2800']
E. Pursuit For Artifactstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputJohnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience.In that country there are n islands and m bridg...
Input6 71 2 02 3 03 1 03 4 14 5 05 6 06 4 01 6
OutputYES
3 seconds
512 megabytes
['dfs and similar', 'dsu', 'graphs', 'trees', '*2300']
D. Nested Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.InputThe first line contains a single integer n (1 ≤ n ≤ ...
Input41 82 34 75 6
Output3010
2 seconds
256 megabytes
['data structures', 'sortings', '*1800']
C. Foe Pairstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contai...
Input4 21 3 2 43 22 4
Output5
1 second
256 megabytes
['combinatorics', 'sortings', 'two pointers', '*1800']
B. z-sorttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: ai ≥ ai - 1 for all even i, ai ≤ ai - 1 for all odd i > 1. For example the arrays ...
Input41 2 2 1
Output1 2 1 2
1 second
256 megabytes
['sortings', '*1000']
A. Gabriel and Caterpillartime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h...
Input10 302 1
Output1
1 second
256 megabytes
['implementation', 'math', '*1400']
B. Beautiful Paintingstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.We are allo...
Input520 30 10 50 40
Output4
1 second
256 megabytes
['greedy', 'sortings', '*1200']
A. Joystickstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFriends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to...
Input3 5
Output6
1 second
256 megabytes
['dp', 'greedy', 'implementation', 'math', '*1100']
E. Clockwork Bombtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMy name is James diGriz, I'm the most clever robber and treasure hunter in the whole galaxy. There are books written about my adventures and songs about my operations, though you were able to catch me ...
Input31 22 31 33 2
Output11 2 1 3
6 seconds
256 megabytes
['data structures', 'dfs and similar', 'dsu', 'greedy', 'trees', '*3200']
D. Zip-linetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the heights of all trees in the forest. He is sure that he remem...
Input4 41 2 3 41 11 44 34 5
Output4334
3 seconds
256 megabytes
['binary search', 'data structures', 'dp', 'hashing', '*2600']