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
H. Endless Roses Most Beautifultime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady decided to buy roses for his girlfriend.A flower shop has white, orange and red roses, and the total amount of them is n. Arkady thinks that red roses are not good together with whi...
Input5 34 3 4 1 6RROWW
Output11
1 second
256 megabytes
['*2200']
G. Large Bouquetstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if...
Input52 3 4 2 7
Output2
1 second
256 megabytes
['*1500']
F. Mobile Communicationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sum of p rubles is charged from Arkady's mobile phone account every day in the morning. Among the following m days, there are n days when Arkady will top up the account: in the day di he will d...
Input3 6 72 134 207 9
Output3
1 second
256 megabytes
['*2000']
E. Merge Equal Elementstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of positive integers a1, a2, ..., an. While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair,...
Input65 2 1 1 2 2
Output25 4
1 second
256 megabytes
['constructive algorithms', 'data structures', '*1900']
D. Choose Placetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right. Some places are already occupied, and some places are...
Input..-**-....-**-....-..-....-..-....-..-....-..-..
Output..-**-....-**-....-..-....-P.-....-..-....-..-..
1 second
256 megabytes
['*1600']
C. Is This a Zebra?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can repr...
Input90 0 0 1 1 1 0 0 0
OutputYES
1 second
256 megabytes
['implementation', '*1700']
B. Add Pointstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.Determine the number m — the smallest number of points you should add on the line to...
Input3-5 10 5
Output1
1 second
256 megabytes
['*1800']
A. 2-3-numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisor...
Input1 10
Output7
1 second
256 megabytes
['implementation', 'math', '*1300']
F. Parametric Circulationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova has recently learned what a circulaton in a graph is. Recall the definition: let G = (V, E) be a directed graph. A circulation f is such a collection of non-negative real numbers f_e (e \i...
Input3 31 2 0 3 -4 72 3 -2 5 1 63 1 0 4 0 4
Output0.25
2 seconds
256 megabytes
['binary search', 'flows', '*3100']
E. May Holidaystime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's May in Flatland, and there are m days in this month. Despite the fact that May Holidays are canceled long time ago, employees of some software company still have a habit of taking short or long vaca...
Input7 84 5 1 1 5 50 0 0 1 2 0 02 6 3 7 -2 4 -3 1
Output1 1 1 2 2 2 1 0
5 seconds
256 megabytes
['data structures', 'trees', '*2900']
D. Aztec Catacombstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIndiana Jones found ancient Aztec catacombs containing a golden idol. The catacombs consists of n caves. Each pair of caves is connected with a two-way corridor that can be opened or closed. The entra...
Input4 41 22 31 33 4
Output21 3 4
2 seconds
256 megabytes
['constructive algorithms', '*2600']
C. Big Secrettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence a_1, \ldots, a_n. In order to not reveal the s...
Input31 2 3
OutputNo
2 seconds
256 megabytes
['constructive algorithms', 'math', '*2200']
B. Resource Distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server m...
Input6 8 163 5 2 9 8 7
OutputYes3 21 2 65 4
2 seconds
256 megabytes
['binary search', 'implementation', 'sortings', '*1700']
A. Stairs and Elevatorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the year of 30XX participants of some world programming championship live in a single large hotel. The hotel has n floors. Each floor has m sections with a single corridor connecting all of th...
Input5 6 1 1 32531 1 5 61 3 5 43 3 5 3
Output754
2 seconds
256 megabytes
['binary search', '*1600']
F. Minimal Subset Differencetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference b...
Input101 100 01 100 11 100 21 100 31 100 41 100 51 100 61 100 71 100 81 100 9
Output92844587080889498100
3 seconds
256 megabytes
['dp', '*3200']
E. Wardrobetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOlya wants to buy a custom wardrobe. It should have n boxes with heights a1, a2, ..., an, stacked one on another in some order. In other words, we can represent each box as a vertical segment of length ai, an...
Input5 3 63 2 5 1 21 1 0 1 0
Output2
1 second
256 megabytes
['dp', 'greedy', '*2700']
D. Contact ATCtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady the air traffic controller is now working with n planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The i-th plane, small enough to be ...
Input5 1-3 2-3 3-1 21 -33 -5
Output3
1 second
256 megabytes
['*2500']
C. Riverside Curiotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.Arkady goes to the riverside each day and makes a mark on the side of the chann...
Input60 1 0 3 0 2
Output6
1 second
256 megabytes
['data structures', 'dp', 'greedy', '*1700']
B. Three-level Lasertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of th...
Input4 41 3 5 7
Output0.5
1 second
256 megabytes
['binary search', 'greedy', 'two pointers', '*1600']
A. Mystical Mosaictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a rectangular grid of n rows of m initially-white cells each.Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a n...
Input5 8.#.#..#......#...#.#..#.#.#....#.....#..
OutputYes
1 second
256 megabytes
['greedy', 'implementation', '*1300']
F. Public Servicetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are N cities in Bob's country connected by roads. Some pairs of cities are connected by public transport. There are two competing transport companies — Boblines operating buses and Bobrail runnin...
Input41 22 33 45 66 77 8
OutputYes6 8 5 7
4 seconds
256 megabytes
['constructive algorithms', 'graphs', 'trees', '*3200']
E. Perpetual Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a number x initially written on a blackboard. You repeat the following action a fixed amount of times: take the number x currently written on a blackboard and erase it select an inte...
Input2 10 0 1
Output332748118 332748118 332748118
2 seconds
256 megabytes
['fft', 'math', 'matrices', '*3100']
D. Picking Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: A BC B AC C AB AAA empty s...
InputAABCCBAABABCB51 3 1 22 2 2 47 9 1 13 4 2 34 5 1 3
Output10011
2 seconds
256 megabytes
['constructive algorithms', 'implementation', 'strings', '*2500']
C. Perfect Securitytime limit per test3.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAlice has a very important message M consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice ge...
Input38 4 1317 2 7
Output10 3 28
3.5 seconds
512 megabytes
['data structures', 'greedy', 'strings', 'trees', '*1800']
B. Producing Snowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount ...
Input310 10 55 7 2
Output5 12 4
1 second
256 megabytes
['binary search', 'data structures', '*1600']
A. Primal Sporttime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating ...
Input14
Output6
1.5 seconds
256 megabytes
['math', 'number theory', '*1700']
F. Divisibilitytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputImp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a i...
Input3 3
OutputNo
1 second
256 megabytes
['constructive algorithms', 'dp', 'greedy', 'number theory', '*2400']
E. Birdstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputApart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp needs strong magic. There are n trees in a row on an alley in a park, there is a nest on each of the trees. In the i-th nest...
Input2 12 0 43 44 2
Output6
1 second
256 megabytes
['dp', '*2200']
D. Robot Vacuum Cleanertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPushok the dog has been chasing Imp for a few hours already. Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner. While moving, the robot generates a string t consisting of let...
Input4sshhsshhhs
Output18
1 second
256 megabytes
['greedy', 'sortings', '*1800']
C. Cave Paintingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputImp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a ...
Input4 4
OutputNo
1 second
256 megabytes
['brute force', 'number theory', '*1600']
B. Magic Foresttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputImp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is eq...
Input6
Output1
1 second
256 megabytes
['brute force', '*1300']
A. Cloning Toystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputImp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy...
Input6 3
OutputYes
1 second
256 megabytes
['implementation', '*1300']
01. Labyrinth-1time limit per test8 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou have a robot in a two-dimensional labyrinth which consists of N × M cells. Some pairs of cells adjacent by side are separated by a wall or a door. The labyrinth itself is separated from the outside w...
Input1 1 30 30 1 1 1 1 1 11 1 1 22 2 2 31 49 0
Outputfor-1111 take open-up open-left open-right open-down move-left if-ok for-11 move-left take open-up open-left open-right open-down end else move-right if-ok for-11 move-right take open-up open-left open-right open-down end else endif endif move-up if-ok ...
8 seconds
512 megabytes
['*3200']
G. List Of Integerstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest common divisor of two integer numbers), sorted in ascending order. The elements...
Input37 22 17 22 27 22 3
Output91315
5 seconds
256 megabytes
['binary search', 'bitmasks', 'brute force', 'combinatorics', 'math', 'number theory', '*2200']
F. SUM and REPLACEtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6).You are given an array a of n integer...
Input7 66 4 1 10 3 2 42 1 72 4 51 3 52 4 41 5 72 1 7
Output3013422
2 seconds
256 megabytes
['brute force', 'data structures', 'dsu', 'number theory', '*2000']
E. Connected Components?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph consisting of n vertices and edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge be...
Input5 51 23 43 24 22 5
Output21 4
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'dsu', 'graphs', '*2100']
D. Tankstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya sometimes has to water his field. To water the field, Petya needs a tank with exactly V ml of water.Petya has got N tanks, i-th of them initially containing ai ml of water. The tanks are really large, any...
Input2 3 52 3
OutputYES1 2 1
2 seconds
256 megabytes
['dp', 'greedy', 'implementation', '*2400']
C. Swap Adjacent Elementstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array.For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, ...
Input61 2 5 3 4 601110
OutputYES
1 second
256 megabytes
['dfs and similar', 'greedy', 'math', 'sortings', 'two pointers', '*1400']
B. Tea Queuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two p...
Input221 31 431 51 12 3
Output1 2 1 0 2
1 second
256 megabytes
['implementation', '*1200']
A. Water The Gardentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is winter now, and Max decided it's about time he watered the garden.The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located...
Input35 133 31 2 34 11
Output314
1 second
256 megabytes
['implementation', '*1000']
F. A Game With Numberstime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputImagine that Alice is playing a card game with her friend Bob. They both have exactly 8 cards and there is an integer on each card, ranging from 0 to 4. In each round, Alice or Bob in turns choose...
Input410 0 0 0 0 0 0 01 2 3 4 1 2 3 410 0 0 1 0 0 0 00 0 0 0 4 0 0 001 0 0 0 0 0 0 00 0 0 4 0 0 2 011 1 1 1 1 1 1 11 1 1 1 1 1 1 1
OutputAliceBobAliceDeal
4 seconds
512 megabytes
['games', 'graphs', 'shortest paths', '*2600']
E. Congruence Equationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an integer x. Your task is to find out how many positive integers n (1 \leq n \leq x) satisfy n \cdot a^n \equiv b \quad (\textrm{mod}\;p), where a, b, p are all known constants.InputThe onl...
Input2 3 5 8
Output2
3 seconds
256 megabytes
['chinese remainder theorem', 'math', 'number theory', '*2100']
D. Substringtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letter...
Input5 4abaca1 21 33 44 5
Output3
3 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', '*1700']
C. Seat Arrangementstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and ...
Input2 3 2**....
Output3
1 second
256 megabytes
['brute force', 'implementation', '*1300']
B. Perfect Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.InputA single lin...
Input1
Output19
2 seconds
256 megabytes
['binary search', 'brute force', 'dp', 'implementation', 'number theory', '*1100']
A. Supermarkettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that a yuan ...
Input3 51 23 41 3
Output1.66666667
2 seconds
256 megabytes
['brute force', 'greedy', 'implementation', '*800']
B. Radio Stationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n serv...
Input2 2main 192.168.0.2replica 192.168.0.1block 192.168.0.1;proxy 192.168.0.2;
Outputblock 192.168.0.1; #replicaproxy 192.168.0.2; #main
2 seconds
256 megabytes
['implementation', 'strings', '*900']
A. Eleventime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters. Her friend suggested that h...
Input8
OutputOOOoOooO
1 second
256 megabytes
['brute force', 'implementation', '*800']
E. Upside Downtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAs we all know, Eleven has special abilities. Thus, Hopper convinced her to close the gate to the Upside Down World with her mind. Upside down monsters like to move between the worlds, so they are going t...
Input6 4 51 6 b2 3 a1 2 b5 3 b4 5 babbbaa1 2 16 2 31 6 24 5 41 6 2
Output01101
3 seconds
512 megabytes
['data structures', 'string suffix structures', 'strings', 'trees', '*3400']
D. Stranger Treestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWill shares a psychic connection with the Upside Down Monster, so everything the monster knows, Will knows. Suddenly, he started drawing, page after page, non-stop. Joyce, his mom, and Chief Hopper put ...
Input31 21 3
Output0 2 1
1 second
256 megabytes
['dp', 'math', 'matrices', 'trees', '*2600']
C. Pollywogtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs we all know, Dart is some kind of creature from Upside Down world. For simplicity, we call their kind pollywogs. Dart and x - 1 other pollywogs are playing a game. There are n stones in a row, numbered fr...
Input2 3 10 21 2 35 -106 1000
Output6
2 seconds
256 megabytes
['combinatorics', 'dp', 'matrices', '*2900']
B. MADMAXtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a...
Input4 41 2 b1 3 a2 4 c3 4 b
OutputBAAAABAABBBABBBB
1 second
256 megabytes
['dfs and similar', 'dp', 'games', 'graphs', '*1700']
A. The Monstertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, beca...
Input((?))
Output4
1 second
256 megabytes
['dp', 'greedy', 'implementation', 'math', '*1800']
E. Jamie and Treetime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo your surprise, Jamie is the final boss! Ehehehe.Jamie has given you a tree with n vertices, numbered from 1 to n. Initially, the root of the tree is the vertex with number 1. Also, each vertex has...
Input6 71 4 2 8 5 71 23 14 34 53 63 12 4 6 33 41 62 2 4 -51 43 3
Output27195
2.5 seconds
256 megabytes
['data structures', 'trees', '*2400']
D. Jamie and To-do Listtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWhy I have to finish so many assignments???Jamie is getting very busy with his school life. He starts to forget the assignments that he has to do. He decided to write the things down on a to-do l...
Input8set chemlabreport 1set physicsexercise 2set chinesemockexam 3query physicsexercisequery chinesemockexamremove physicsexercisequery physicsexercisequery chinesemockexam
Output12-11
2 seconds
512 megabytes
['data structures', 'interactive', 'trees', '*2200']
C. Jamie and Interesting Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJamie has recently found undirected weighted graphs with the following properties very interesting: The graph is connected and contains exactly n vertices and m edges. All edge weights a...
Input4 4
Output7 71 2 32 3 23 4 22 4 4
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'shortest paths', '*1600']
B. Jamie and Binary Sequence (changed after round)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:Find k in...
Input23 5
OutputYes3 3 2 1 0
2 seconds
256 megabytes
['bitmasks', 'greedy', 'math', '*2000']
A. Jamie and Alarm Snoozetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky tim...
Input311 23
Output2
2 seconds
256 megabytes
['brute force', 'implementation', 'math', '*900']
G. Coprime Arraystime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an array a of size n coprime iff gcd(a1, a2, ..., an) = 1, where gcd is the greatest common divisor of the arguments.You are given two numbers n and k. For each i (1 ≤ i ≤ k) you have to d...
Input3 4
Output82
3.5 seconds
256 megabytes
['math', 'number theory', '*2300']
F. Imbalance Value of a Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x, y) as the difference between maximum...
Input42 2 3 11 21 31 4
Output6
4 seconds
256 megabytes
['data structures', 'dsu', 'graphs', 'trees', '*2400']
E. Physical Education Lessonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to a...
Input461 2 13 4 12 3 21 3 22 4 11 4 2
Output202314
1 second
256 megabytes
['data structures', 'implementation', 'sortings', '*2300']
D. Almost Acyclic Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it.Can yo...
Input3 41 22 33 23 1
OutputYES
1 second
256 megabytes
['dfs and similar', 'graphs', '*2200']
C. Permute Digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.It ...
Input123222
Output213
1 second
256 megabytes
['dp', 'greedy', '*1700']
B. Browsertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLuba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with in...
Input6 3 2 4
Output5
1 second
256 megabytes
['implementation', '*1300']
A. Gardentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLuba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ...
Input3 62 3 5
Output2
1 second
256 megabytes
['implementation', '*900']
H. Ember and Storm's Tree Gametime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputEmber and Storm play a game. First, Ember picks a labelled tree T of n vertices, such that the degree of every vertex is at most d. Then, Storm picks two distinct vertices u and v in this ...
Input2 1 1000000007
Output4
3 seconds
512 megabytes
['combinatorics', 'dp', 'games', 'trees', '*3400']
G. Sum the Fibonaccitime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array s of n non-negative integers.A 5-tuple of integers (a, b, c, d, e) is said to be valid if it satisfies the following conditions: 1 ≤ a, b, c, d, e ≤ n (sa | sb) & sc & (sd ...
Input21 2
Output32
4 seconds
256 megabytes
['bitmasks', 'divide and conquer', 'dp', 'fft', 'math', '*2600']
F. Substrings in a Stringtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a string s, process q queries, each having one of the following forms: 1 i c — Change the i-th character in the string to c. 2 l r y — Consider the substring of s starting at position l...
Inputababababa32 1 7 aba1 5 c2 1 7 aba
Output31
6 seconds
256 megabytes
['bitmasks', 'brute force', 'data structures', 'string suffix structures', 'strings', '*3000']
E. Palindromes in a Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t.A path in the tree is said to be ...
Input51 22 33 43 5abcbb
Output1 3 4 3 3
4 seconds
256 megabytes
['bitmasks', 'data structures', 'divide and conquer', 'trees', '*2400']
D. Bash and a Tough Math Puzzletime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBash likes playing with arrays. He has an array a1, a2, ... an of n integers. He likes to guess the greatest common divisor (gcd) of different segments of the array. Of course, sometime...
Input32 6 341 1 2 21 1 3 32 1 91 1 3 2
OutputYESYESNO
2.5 seconds
256 megabytes
['data structures', 'number theory', '*1900']
C. Travelling Salesman and Special Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positi...
Input1102
Output3
1 second
256 megabytes
['brute force', 'combinatorics', 'dp', '*1800']
B. Conan and Agasa play a Card Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEdogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai wri...
Input34 5 7
OutputConan
2 seconds
256 megabytes
['games', 'greedy', 'implementation', '*1200']
A. Perfect Squarestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2.I...
Input24 2
Output2
1 second
256 megabytes
['brute force', 'implementation', 'math', '*900']
H. Don't Exceedtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou generate real numbers s1, s2, ..., sn as follows: s0 = 0; si = si - 1 + ti, where ti is a real number chosen independently uniformly at random between 0 and 1, inclusive. You are given real number...
Input41.0023.0000004.0
Output1
4 seconds
256 megabytes
['math', 'probabilities', '*3400']
G. Power Substringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n positive integers a1, a2, ..., an.For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its...
Input282
Output31
2 seconds
256 megabytes
['math', 'number theory', '*3200']
F. Strongly Connected Tournamenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a chess tournament in All-Right-City. n players were invited to take part in the competition. The tournament is held by the following rules: Initially, each player plays one ga...
Input31 2
Output4
2 seconds
256 megabytes
['dp', 'graphs', 'math', 'probabilities', '*2800']
E. Logical Expressiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of...
Input400110011000001111111000000011111
Outputy(y|z)&x!xx|y&z
3 seconds
256 megabytes
['bitmasks', 'dp', 'shortest paths', '*2400']
D. Too Easy Problemstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore ...
Input5 3003 1004 1504 802 902 300
Output233 1 4
2 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'greedy', 'sortings', '*1800']
C. Party Lemonadetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.Your favorite store sells lemonade in ...
Input4 1220 30 70 90
Output150
1 second
256 megabytes
['bitmasks', 'dp', 'greedy', '*1600']
B. Christmas Sprucetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u i...
Input4111
OutputYes
1 second
256 megabytes
['implementation', 'trees', '*1200']
A. Modular Exponentiationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe following problem is well-known: given integers n and m, calculate , where 2n = 2·2·...·2 (n factors), and denotes the remainder of division of x by y.You are asked to solve the "reverse" p...
Input442
Output10
1 second
256 megabytes
['implementation', 'math', '*900']
E. Prime Gifttime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOpposite to Grisha's nice behavior, Oleg, though he has an entire year at his disposal, didn't manage to learn how to solve number theory problems in the past year. That's why instead of Ded Moroz he was...
Input32 3 57
Output8
3.5 seconds
256 megabytes
['binary search', 'dfs and similar', 'math', 'meet-in-the-middle', 'number theory', 'two pointers', '*2400']
D. Fishestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, ...
Input3 3 2 3
Output2.0000000000
1 second
256 megabytes
['data structures', 'graphs', 'greedy', 'probabilities', 'shortest paths', '*2100']
C. Perun, Ult!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA lot of students spend their winter holidays productively. Vlad has advanced very well in doing so! For three days already, fueled by salads and tangerines — the leftovers from New Year celebration — he h...
Input3 21000 10 5070 5 590 70 1110 20 220 2 1030 3 10
Output3000
1 second
256 megabytes
['brute force', 'greedy', 'sortings', '*2500']
B. New Year's Evetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled ...
Input4 3
Output7
1 second
256 megabytes
['bitmasks', 'constructive algorithms', 'number theory', '*1300']
A. Tricky Alchemytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.Gris...
Input4 32 1 1
Output2
1 second
256 megabytes
['implementation', '*800']
G. Mass Change Queriestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers. You have to process q queries to this array; each query is given as four numbers l, r, x and y, denoting that for every i such that l ≤ i ≤ r and...
Input51 2 3 4 533 5 3 51 5 5 11 5 1 5
Output5 2 5 4 5
3 seconds
512 megabytes
['data structures', '*2500']
F. Tree Destructiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: choose two leaves; add the length of ...
Input31 21 3
Output32 3 32 1 1
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'greedy', 'trees', '*2400']
E. Stack Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).You may perform the following operations until both a and s are empty: Take the first element of a, ...
Input5 33 2 1
Output3 2 1 5 4
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'greedy', 'implementation', '*2000']
D. Inversion Countingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a...
Input31 2 321 22 3
Outputoddeven
2 seconds
256 megabytes
['brute force', 'math', '*1800']
C. Three Garlandstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.When a garland is switched on, it periodical...
Input2 2 3
OutputYES
2 seconds
256 megabytes
['brute force', 'constructive algorithms', '*1400']
B. Two Cakestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into...
Input5 2 3
Output1
1 second
256 megabytes
['binary search', 'brute force', 'implementation', '*1200']
A. Nearest Minimumstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times...
Input23 3
Output1
2 seconds
256 megabytes
['implementation', '*1100']
C. Minimum Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j...
Input3abdeaj
Output47
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', '*1700']
B. Door Framestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous ...
Input812
Output1
1 second
256 megabytes
['greedy', 'implementation', '*1600']
A. The Way to Hometime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the poi...
Input8 410010101
Output2
1 second
256 megabytes
['dfs and similar', 'dp', 'greedy', 'implementation', '*800']
F. AND-permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an integer N, find two permutations: Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N. Permutation q of numbers from 1 to N such that qi ≠ i and q...
Input3
OutputNONO
2 seconds
256 megabytes
['constructive algorithms', '*2500']
E. Coprocessortime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other t...
Input4 30 1 0 10 11 22 3
Output2
1.5 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'greedy', '*1900']
D. Colorful Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has ...
Inputaabb
Output2
2 seconds
256 megabytes
['data structures', 'greedy', 'implementation', '*2100']
C. Python Indentationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.We will consider an extremely simplified...
Input4sffs
Output1
2 seconds
256 megabytes
['dp', '*1800']