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
A1. Death Stars (easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and ...
Input4XOOOXXOOOOOOXXXXXOOOXOOOXOXOXOXX
OutputYes
1 second
256 megabytes
['implementation', '*1400']
A. Tritonic Iridescencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOverlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and ye...
Input5CY??Y
OutputYes
1 second
256 megabytes
['implementation', '*1300']
F. Heapstime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou're given a tree with n vertices rooted at 1.We say that there's a k-ary heap of depth m located at u if the following holds: For m = 1 u itself is a k-ary heap of depth 1. For m > 1 vertex u is a k-ary ...
Input41 32 34 3
Output21
2.5 seconds
512 megabytes
['dp', 'trees', '*2600']
E. Iciclestime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrew's favourite Krakozyabra has recenly fled away and now he's eager to bring it back!At the moment the refugee is inside an icy cave with n icicles dangling from the ceiling located in integer coordinat...
Input51 4 3 5 1
Output3
2.5 seconds
256 megabytes
['*2900']
D. Scissorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJenya has recently acquired quite a useful tool — k-scissors for cutting strings. They are generally used for cutting out two non-intersecting substrings of length k from an arbitrary string s (its length sho...
Input7 4 3baabaabaaaa
OutputYes1 5
1 second
256 megabytes
['brute force', 'strings', '*2600']
C. Sad powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given Q queries of the form (L, R). For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.InputThe first line contains the...
Input61 49 95 712 29137 5911 1000000
Output2103171111
2 seconds
256 megabytes
['binary search', 'math', 'number theory', '*2100']
B. Not simply beatiful stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols)....
Inputababa
OutputYes
1 second
256 megabytes
['implementation', '*1400']
A. Feed the cattime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute...
Input19 00255 1 100 1
Output25200.0000
1 second
256 megabytes
['greedy', 'math', '*1100']
I. Yet Another String Matching Problemtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you have two strings s and t, and their length is equal. You may perform the following operation any number of times: choose two different characters c1 and c2, and replace...
Inputabcdefaddcb
Output2 3 3 3
4 seconds
256 megabytes
['fft', 'math', '*2200']
H. Path Countingtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree. Let's denote d(x) as depth of node x: depth of the root is 1, depth of any other node x is d(y) + 1, where y is a parent of x.The tree has the following property: every node...
Input42 2 2
Output14 19 20 20 16 16
5 seconds
256 megabytes
['combinatorics', 'dp', '*2500']
G. Castle Defensetime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining ...
Input5 0 65 4 3 4 9
Output5
1.5 seconds
256 megabytes
['binary search', 'data structures', 'greedy', 'two pointers', '*2000']
F. Runner's Problemtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.You start in (2, 1) and h...
Input2 51 3 42 2 3
Output2
4 seconds
256 megabytes
['dp', 'matrices', 'sortings', '*2100']
E. Water Tapstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The ...
Input2 1003 1050 150
Output6.000000000000000
2 seconds
256 megabytes
['binary search', 'greedy', 'sortings', '*2000']
D. Fight Against Traffictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get fr...
Input5 4 1 51 22 33 44 5
Output0
1 second
256 megabytes
['dfs and similar', 'graphs', 'shortest paths', '*1600']
C. Matrix Walktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a matrix A of size x × y filled with integers. For every , Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this mat...
Input81 2 3 6 9 8 5 2
OutputYES3 3
1 second
256 megabytes
['implementation', '*1700']
B. String Typingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.Initially, you have an empty string. Until you type the whole string, you may perform th...
Input7abcabca
Output5
1 second
256 megabytes
['implementation', 'strings', '*1400']
A. Diagonal Walkingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.In the giv...
Input5RUURU
Output3
1 second
256 megabytes
['implementation', '*800']
G. Puzzling Languagetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem you will write a simple code generator for a 2D programming language derived from Brainfuck.The code in this language is a rectangular grid of characters '.' and 'X'. The code is conv...
Input$$$
Output.......X.............XXX...........XXXXX.........XXXXXXX.......XXXXXXXXX.....XXXXXXXXXXX...XXXXXXXXXXXXX................X.............XX..............X..............X..............
1 second
256 megabytes
['constructive algorithms', '*2200']
F. 2 + 2 != 4time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. Howe...
Input8-7+6-5+4-3+2-1-0
Output4
1 second
256 megabytes
['*2400']
E. Cheese Boardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNot to be confused with chessboard. InputThe first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have.The next N lines describe the cheeses you have. Each line conta...
Input9brie softcamembert softfeta softgoat softmuenster softasiago hardcheddar hardgouda hardswiss hard
Output3
1 second
256 megabytes
['*2000']
C. Ravioli Sorttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows of spaghetti sort. You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravi...
Input31 2 3
OutputYES
1 second
256 megabytes
['implementation', '*1600']
A. Quirky Quantifierstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputInputThe input contains a single integer a (10 ≤ a ≤ 999).OutputOutput 0 or 1.ExamplesInput13Output1Input927Output1Input48Output0
Input13
Output1
2 seconds
64 megabytes
['math', '*800']
B. Intercepted Messagetime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputHacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.Zhorik knows that...
Input7 62 5 3 1 11 4 47 8 2 4 1 8
Output3
1 second
512 megabytes
['greedy', 'implementation', '*1100']
A. Left-handers, Right-handers and Ambidexterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or...
Input1 4 2
Output6
1 second
256 megabytes
['implementation', 'math', '*800']
E. Binary Cardstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt is never too late to play the fancy "Binary Cards" game!There is an infinite amount of cards of positive and negative ranks that are used in the game. The absolute value of any card rank is a power of ...
Input19
Output21 8
1 second
512 megabytes
['brute force', '*2700']
D. Curfewtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputInstructors of Some Informatics School make students go to bed.The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students ...
Input5 1 11 0 0 0 4
Output1
2 seconds
512 megabytes
['binary search', 'brute force', 'greedy', 'sortings', '*2300']
C. Data Center Maintenancetime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputBigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client...
Input3 3 54 4 01 33 23 1
Output13
1 second
512 megabytes
['dfs and similar', 'graphs', '*1900']
B. A Leapfrog in the Arraytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has bee...
Input4 3234
Output324
2 seconds
512 megabytes
['constructive algorithms', 'math', '*1700']
A. Zebrastime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputOleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and ...
Input0010100
Output33 1 3 43 2 5 61 7
1 second
512 megabytes
['greedy', '*1600']
A. Protect Sheeptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected...
Input6 6..S.....S.W..S......W......W........
OutputYes..SD....SDW..SD....DW...DD.W........
1 second
256 megabytes
['brute force', 'dfs and similar', 'graphs', 'implementation', '*900']
G. Almost Increasing Arraytime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWe call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every elemen...
Input55 4 3 2 1
Output3
3 seconds
512 megabytes
['data structures', 'dp', '*2500']
F. Fibonacci String Subsequencestime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary string s (each character of this string is either 0 or 1).Let's denote the cost of string t as the number of occurences of s in t. For example, if s is 11 and t ...
Input2 411
Output14
3.5 seconds
256 megabytes
['combinatorics', 'dp', 'matrices', '*2400']
E. Largest Beautiful Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYes, that's another problem with definition of "beautiful" numbers.Let's call a positive integer x beautiful if its decimal representation without leading zeroes contains even number of digits...
Input48988100028923845
Output88779928923839
1 second
256 megabytes
['greedy', 'implementation', '*2200']
D. Timetabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.There are m working hours during each Berland day...
Input2 5 10100110110
Output5
2 seconds
256 megabytes
['dp', '*1800']
C. String Transformationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of |s| small english letters.In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s...
Inputaacceeggiikkmmooqqssuuwwyy
Outputabcdefghijklmnopqrstuvwxyz
1 second
256 megabytes
['greedy', 'strings', '*1300']
B. Weird Subtraction Processtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set th...
Input12 5
Output0 1
1 second
256 megabytes
['math', 'number theory', '*1100']
A. Partitiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of...
Input31 -2 0
Output3
1 second
256 megabytes
['greedy', '*800']
F. Machine Learningtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou come home and fell some unpleasant smell. Where is it coming from?You are given an array a. You have to answer the following queries: You are given two integers l and r. Let ci be the number of...
Input10 41 2 3 1 1 2 2 2 9 91 1 11 2 82 7 11 2 8
Output232
4 seconds
512 megabytes
['brute force', 'data structures', '*2600']
E. Cashbacktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount.You are given an array a of length n and an integer c. The value of some array b of length k is...
Input3 51 2 3
Output6
2 seconds
256 megabytes
['data structures', 'dp', 'greedy', 'math', '*2000']
D. Alena And The Heatertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme.""Little Alena got an array as a birthday present..."The array b of length...
Input51 2 3 4 500001
Output6 15
2 seconds
256 megabytes
['binary search', 'implementation', '*1600']
C. Phone Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnd where the are the phone numbers?You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of lett...
Input3 3abc
Outputaca
2 seconds
256 megabytes
['constructive algorithms', 'implementation', 'strings', '*1500']
B. Our Tanya is Crying Out Loudtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRight now she actually isn't. But she will be, if you don't solve this problem.You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to ...
Input9231
Output6
1 second
256 megabytes
['dp', 'greedy', '*1400']
A. Points on the linetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is t...
Input3 12 1 4
Output1
1 second
256 megabytes
['brute force', 'greedy', 'sortings', '*1200']
F. Cutlettime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2n seconds, in particular, it should be fried ...
Input10 23 511 13
OutputFull2
4 seconds
256 megabytes
['data structures', 'dp', '*2400']
E. Maximize!time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a positive integer to S, the newly added integer is not less than any number in it. Find a...
Input61 321 421 82
Output0.00000000000.50000000003.0000000000
3 seconds
256 megabytes
['binary search', 'greedy', 'ternary search', 'two pointers', '*1800']
D. Love Rescuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. N...
Input3abbdad
Output2a db a
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'graphs', 'greedy', 'strings', '*1600']
C. Convenient For Everybodytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to...
Input31 2 31 3
Output3
2 seconds
256 megabytes
['binary search', 'two pointers', '*1600']
B. Hamster Farmtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby.Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are b...
Input19 35 4 10
Output2 4
2 seconds
256 megabytes
['implementation', '*1000']
A. Love Triangletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the...
Input52 4 5 1 3
OutputYES
1 second
256 megabytes
['graphs', '*800']
G. Shortest Path Queriestime limit per test3.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an undirected connected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is...
Input5 51 2 32 3 43 4 54 5 61 5 153 1 51 1 3 13 1 52 1 53 1 5
Output112
3.5 seconds
512 megabytes
['bitmasks', 'data structures', 'dsu', 'graphs', '*2900']
F. Erasing Substringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s, initially consisting of n lowercase Latin letters. After that, you perform k operations with it, where . During i-th operation you must erase some substring of length exact...
Inputadcbca
Outputaba
1 second
256 megabytes
['bitmasks', 'dp', 'greedy', '*2700']
E. Max Historytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n. We define fa the following way: Initially fa = 0, M = 1; for every 2 ≤ i ≤ n if aM < ai then we set fa = fa + aM and then set M = i. Calculate the sum of fa over al...
Input21 3
Output1
3 seconds
256 megabytes
['combinatorics', 'math', '*2300']
D. Buy a Tickettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMusicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.There are n cities in Berland. People can travel...
Input4 21 2 42 3 76 20 1 25
Output6 14 1 25
2 seconds
256 megabytes
['data structures', 'graphs', 'shortest paths', '*2000']
C. Constructing Teststime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero. Consider the follo...
Input32101
Output5 21 1-1
1 second
256 megabytes
['binary search', 'brute force', 'constructive algorithms', '*1700']
B. Run For Your Prizetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou and your friend are participating in a TV show "Run For Your Prize".At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prize...
Input32 3 9
Output8
1 second
256 megabytes
['brute force', 'greedy', '*1100']
A. Word Correctiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVictor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.Victor thinks that if a word contains two consecutive vowels, then it'...
Input5weird
Outputwerd
1 second
256 megabytes
['implementation', '*800']
B. Vile Grasshopperstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and numbered from 2 to y. Som...
Input3 6
Output5
1 second
256 megabytes
['brute force', 'math', 'number theory', '*1400']
A. Olympiadtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.As the head of the programming committee, you are to determine the set of participants to be...
Input41 3 3 2
Output3
1 second
256 megabytes
['implementation', 'sortings', '*800']
D. World of Tanktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVitya loves programming and problem solving, but sometimes, to distract himself a little, he plays computer games. Once he found a new interesting game about tanks, and he liked it so much that he went ...
Input6 2 3 22 63 5 6
OutputYes20 3 22 24 1
2 seconds
256 megabytes
['dp', 'greedy', '*3000']
C. Lock Puzzletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWelcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find th...
Input6abacbbbabcba
Output46 3 2 3
2 seconds
256 megabytes
['constructive algorithms', 'implementation', 'strings', '*2300']
B. Sleepy Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is locate...
Input5 62 2 32 4 51 41 501
OutputWin1 2 4 5
2 seconds
256 megabytes
['dfs and similar', 'dp', 'games', 'graphs', '*2100']
A. Save Energy!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJulia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.During cooking, Julia goes to the kitche...
Input3 2 6
Output6.5
1 second
256 megabytes
['binary search', 'implementation', 'math', '*1700']
F. Fafa and Arraytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFafa has an array A of n positive integers, the function f(A) is defined as . He wants to do q queries of two types: 1 l r x — find the maximum possible value of f(A), if x is to be added to one eleme...
Input51 1 1 1 151 2 4 12 2 3 12 4 4 22 3 4 11 3 3 2
Output28
3 seconds
256 megabytes
['data structures', 'greedy', '*2600']
E. Fafa and Ancient Mathematicstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAncient Egyptians are known to have understood difficult concepts in mathematics. The ancient Egyptian mathematician Ahmes liked to write a kind of arithmetic expressions on papyrus paper...
Input(1?1)1 0
Output2
2 seconds
256 megabytes
['dfs and similar', 'dp', 'trees', '*2300']
D. Fafa and Ancient Alphabettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAncient Egyptians are known to have used a large set of symbols to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1 and S2 of equ...
Input1 201
Output500000004
2 seconds
256 megabytes
['math', 'probabilities', '*1900']
C. Fifa and Fafatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet thro...
Input5 3 3 1 1
Output3.7677669529663684 3.7677669529663684 3.914213562373095
1 second
256 megabytes
['geometry', '*1600']
B. Fafa and the Gatestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one ...
Input1U
Output0
2 seconds
256 megabytes
['implementation', '*900']
A. Fafa and his Companytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project a...
Input2
Output1
1 second
256 megabytes
['brute force', 'implementation', '*800']
B. A Prosperous Lottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputApart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that w...
Input2
Output462
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1200']
A. A Compatible Pairtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red col...
Input2 220 182 14
Output252
1 second
256 megabytes
['brute force', 'games', '*1400']
E. A Preponderant Reuniontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEast or west, home is best. That's why family reunion, the indispensable necessity of Lunar New Year celebration, is put in such a position.After the reunion dinner, Little Tommy plays a game w...
Input42 1 3 1
Output213
2 seconds
256 megabytes
['constructive algorithms', 'dp', '*3200']
D. A Creative Cutouttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverything red frightens Nian the monster. So do red paper and... you, red on Codeforces, potential or real.Big Banban has got a piece of paper with endless lattice points, where lattice points form...
Input5
Output387
2 seconds
256 megabytes
['brute force', 'combinatorics', 'math', '*2900']
C. A Colourful Prospecttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFirecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement.Little Tommy is watching a firework show. As circular shapes spread across the sky, a spl...
Input30 0 12 0 14 0 1
Output4
1 second
256 megabytes
['geometry', 'graphs', '*2700']
B. A Determined Cleanuptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now...
Input46 2
Output70 1 0 0 1 1 1
1 second
256 megabytes
['math', '*2000']
A. A Twisty Movementtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying ...
Input41 2 1 2
Output4
1 second
256 megabytes
['dp', '*1800']
G. Palindrome Partitiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a string s, find the number of ways to split s to substrings such that if there are k substrings (p1, p2, p3, ..., pk) in partition, then pi = pk - i + 1 for all i (1 ≤ i ≤ k) and k is even...
Inputabcdcdab
Output1
3 seconds
256 megabytes
['dp', 'string suffix structures', 'strings', '*2900']
F. Escape Through Leaftime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree with n nodes (numbered from 1 to n) rooted at node 1. Also, each node has two values associated with it. The values for i-th node are ai and bi.You can jump from a node to any...
Input32 10 -17 -7 52 32 1
Output10 50 0
3 seconds
256 megabytes
['data structures', 'dp', 'geometry', '*2700']
E. Team Worktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people for the task is xk. Output the sum of costs over all non-empty subsets of people....
Input1 1
Output1
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*2400']
D. Treetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a node of the tree with index 1 and with weight 0. Let cnt be the number of nodes in the tree at any instant (initially, cnt is set to 1). Support Q queries of following two types: Add a new node...
Input61 1 12 2 02 2 11 3 02 2 02 2 2
Output0112
2 seconds
512 megabytes
['binary search', 'dp', 'trees', '*2200']
C. Permutation Cycletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor a permutation P[1... N] of integers from 1 to N, function f is defined as follows: Let g(i) be the minimum positive integer j such that f(i, j) = i. We can show such j always exists.For given N...
Input9 2 5
Output6 5 8 3 4 1 9 2 7
2 seconds
256 megabytes
['brute force', 'constructive algorithms', '*1600']
B. Recursive Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet us define two functions f and g on positive integer numbers. You need to process Q queries. In each query, you will be given three integers l, r and k. You need to print the number of integers...
Input422 73 945 64 647 55 72 62 4
Output1408
2 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', '*1300']
A. Palindromic Supersequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.A subsequence of a string is a string that can be derived from it by deleting some (not necessa...
Inputaba
Outputaba
2 seconds
256 megabytes
['constructive algorithms', '*800']
C. Laboratory Worktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.Kirill has already made his measu...
Input6-1 1 1 0 0 -1
Output20 0 0 0 0 0
1 second
256 megabytes
['implementation', 'math', '*1700']
B. World Cuptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe last stage of Football World Cup is played using the play-off system.There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are ...
Input4 1 2
Output1
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1200']
A. Friends Meetingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line ...
Input34
Output1
1 second
256 megabytes
['brute force', 'greedy', 'implementation', 'math', '*800']
E. Coins Exhibitiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady and Kirill visited an exhibition of rare coins. The coins were located in a row and enumerated from left to right from 1 to k, each coin either was laid with its obverse (front) side up, or wi...
Input5 2 21 33 52 24 5
Output8
2 seconds
256 megabytes
['data structures', 'dp', 'math', '*2900']
D. Game with Tokenstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates x and y.The players take tur...
Input4-2 -10 10 -32 -1
Output4
2 seconds
256 megabytes
['data structures', 'games', 'implementation', '*2500']
C. Teodor is not a liar!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYoung Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feat...
Input2 41 23 4
Output4
1 second
256 megabytes
['data structures', 'dp', '*1900']
B. Game with Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a seg...
Inputtechnocup
Output1.000000000000000
2 seconds
256 megabytes
['implementation', 'probabilities', 'strings', '*1600']
A. Peculiar apple-treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescenc...
Input31 1
Output1
1 second
256 megabytes
['dfs and similar', 'graphs', 'trees', '*1500']
D. Пограничные вратаограничение по времени на тест1 секундаограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводГерой Аркадий находится на узкой полоске земли, разделенной на n зон, пронумерованных от 1 до n. Из i-й зоны можно пройти лишь в (i - 1)-ю зону и в (i + 1)-ю зону, если они сущес...
Входные данные5 4 13 1 1 27 1 2 1 3
Выходные данные7
ограничение по времени на тест1 секунда
ограничение по памяти на тест256 мегабайт
['*2400']
C. Красивая командаограничение по времени на тест1 секундаограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводЗавтра у хоккейной команды, которой руководит Евгений, важный матч. Евгению нужно выбрать шесть игроков, которые выйдут на лед в стартовом составе: один вратарь, два защитника и т...
Входные данные1 2 31510 1920 11 13
Выходные данные1
ограничение по времени на тест1 секунда
ограничение по памяти на тест256 мегабайт
['*special problem', 'combinatorics', 'math', '*1700']
B. Места в самолётеограничение по времени на тест1 секундаограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводВ самолёте есть n рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между ...
Входные данные1 2SP.-SS.S-S.S
Выходные данные5SPx-SSxS-S.S
ограничение по времени на тест1 секунда
ограничение по памяти на тест256 мегабайт
['*special problem', 'implementation', '*1300']
A. Прокат велосипедовограничение по времени на тест1 секундаограничение по памяти на тест256 мегабайтвводстандартный вводвыводстандартный выводКак известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя город...
Входные данные4 43 6 8 10
Выходные данные2
ограничение по времени на тест1 секунда
ограничение по памяти на тест256 мегабайт
['*special problem', 'greedy', 'implementation', '*1400']
D. Autocompletiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor.Arcady types words, punctuation signs and spaces one after another. Each letter and e...
Inputsnow affects sports such as skiing, snowboarding, and snowmachine travel.snowboarding is a recreational activity and olympic and paralympic sport.
Output141
1 second
256 megabytes
['*special problem', 'strings', 'trees', '*1900']
C. Dependency managementtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated ...
Input4a 32b 1c 1 b 20 b 11b 2 c 11b 2
Output2b 1c 1
4 seconds
256 megabytes
['*special problem', 'graphs', 'implementation', '*1900']
B. Chattime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 yea...
Input6 00 1 1 2 3 2
Output1 2 2 3 3 3
1 second
256 megabytes
['*special problem', 'dp', '*1400']
A. Login Verificationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.Login is an arbitrary sequence of lo...
Input1_wat22_watwat_1
OutputYes
1 second
256 megabytes
['*special problem', 'strings', '*1200']
J. Segmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a straight line colored in white. n black segments are added on it one by one.After each segment is added, determine the number of connected components of black segments (i. e. the number of black se...
Input31 34 52 4
Output1 2 1
1 second
256 megabytes
['data structures', '*2100']
I. A Vital Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute.Determine the longest time segment when Polycarp can...
Input105:43
Output23:59
1 second
256 megabytes
['*1700']