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
D. Airplane Arrangementstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an airplane which has n rows from front to back. There will be m people boarding this airplane.This airplane has an entrance at the very front and very back of the plane.Each person has...
Input3 3
Output128
2 seconds
256 megabytes
['math', 'number theory', '*2700']
C. Future Failuretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob are playing a game with a string of characters, with Alice going first. The string consists n characters, each of which is one of the first k letters of the alphabet. On a player’s turn, ...
Input4 2 100000007
Output14
3 seconds
256 megabytes
['dp', 'games', '*2800']
B. Diverging Directionstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed weighted graph with n nodes and 2n - 2 edges. The nodes are labeled from 1 to n, while the edges are labeled from 1 to 2n - 2. The graph's edges can be split into two par...
Input5 91 3 13 2 21 4 33 5 45 1 53 1 62 1 74 1 82 1 12 1 32 3 52 5 21 1 1002 1 31 8 302 4 22 2 4
Output014810013210
3 seconds
256 megabytes
['data structures', 'dfs and similar', 'trees', '*2100']
A. Binary Blockstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compr...
Input3 5001001011011001
Output5
2 seconds
256 megabytes
['brute force', '*1400']
G. Functions On The Segmentstime limit per test5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou have an array f of n functions.The function fi(x) (1 ≤ i ≤ n) is characterized by parameters: x1, x2, y1, a, b, y2 and take values: y1, if x ≤ x1. a·x + b, if x1 < x ≤ x2. y2, if x ...
Input11 2 1 4 5 1011 1 2
Output13
5 seconds
1024 megabytes
['data structures', '*2500']
F. Prefix Sumstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that yi is equal to the sum of first i elements of array x (0 ≤ i ≤ m).You have an ...
Input2 21 1
Output1
1 second
256 megabytes
['binary search', 'brute force', 'combinatorics', 'math', 'matrices', '*2400']
E. Vasya's Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two...
Input3 5
Output3
1 second
256 megabytes
['binary search', 'implementation', 'math', '*2100']
D. Round Subsettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call the roundness of the number the number of zeros to which it ends.You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the se...
Input3 250 4 20
Output3
2 seconds
256 megabytes
['dp', 'math', '*2100']
C. Two Sealstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne very important person has a piece of paper in the form of a rectangle a × b.Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impressi...
Input2 2 21 22 1
Output4
1 second
256 megabytes
['brute force', 'implementation', '*1500']
B. Flag of Berlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in wi...
Input6 5RRRRRRRRRRBBBBBBBBBBGGGGGGGGGG
OutputYES
1 second
256 megabytes
['brute force', 'implementation', '*1600']
A. Text Volumetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a text of single-space separated words, consisting of small and capital Latin letters.Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all ...
Input7NonZERO
Output5
1 second
256 megabytes
['implementation', '*800']
F. Roads in the Kingdomtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the Kingdom K., there are n towns numbered with integers from 1 to n. The towns are connected by n bi-directional roads numbered with integers from 1 to n. The i-th road connects the towns ui ...
Input31 2 42 3 51 3 1
Output5
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'trees', '*2500']
E. The penguin's gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPay attention: this problem is interactive.Penguin Xoriy came up with a new game recently. He has n icicles numbered from 1 to n. Each icicle has a temperature — an integer from 1 to 109. Exactly tw...
Input4 2 1211
Output? 3 1 2 3? 1 1? 1 3! 1 3
1 second
256 megabytes
['binary search', 'constructive algorithms', 'interactive', '*2400']
D. Palindromic characteristicstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPalindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.A string i...
Inputabba
Output6 1 0 0
3 seconds
256 megabytes
['brute force', 'dp', 'hashing', 'strings', '*1900']
C. Star skytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c).Over ti...
Input2 3 31 1 13 2 02 1 1 2 20 2 1 4 55 1 1 5 5
Output303
2 seconds
256 megabytes
['dp', 'implementation', '*1600']
B. The number on the boardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It'...
Input311
Output1
2 seconds
256 megabytes
['greedy', '*1100']
A. Key racestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds a...
Input5 1 2 1 2
OutputFirst
1 second
256 megabytes
['math', '*800']
B. The Festive Eveningtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the t...
Input5 1AABBB
OutputNO
1 second
256 megabytes
['data structures', 'implementation', '*1100']
A. The Useless Toytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she h...
Input^ >1
Outputcw
1 second
256 megabytes
['implementation', '*900']
E. Caramel Cloudstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output It is well-known that the best decoration for a flower bed in Sweetland are vanilla muffins. Seedlings of this plant need sun to grow up. Slastyona has m seedlings, and the j-th seedling needs at lea...
Input3 51 7 11 6 21 7 13725
Output12710
3 seconds
256 megabytes
['data structures', 'dp', 'sortings', '*3400']
D. Red-Black Cobwebtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Slastyona likes to watch life of nearby grove's dwellers. This time she watches a strange red-black spider sitting at the center of a huge cobweb.The cobweb is a set of n nodes connected by threads...
Input51 2 9 02 3 5 12 4 5 02 5 5 1
Output1265625
6 seconds
256 megabytes
['data structures', 'divide and conquer', 'implementation', 'trees', '*2800']
C. Ever-Hungry Krakozyabratime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output Recently, a wild Krakozyabra appeared at Jelly Castle. It is, truth to be said, always eager to have something for dinner.Its favorite meal is natural numbers (typically served with honey sau...
Input1 10
Output9
1 second
256 megabytes
['brute force', 'combinatorics', 'greedy', 'math', '*2700']
B. The Bakerytime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.Soon the expenses st...
Input4 11 2 2 1
Output2
2.5 seconds
256 megabytes
['binary search', 'data structures', 'divide and conquer', 'dp', 'two pointers', '*2200']
A. The Meaningless Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number...
Input62 475 458 816 16247 9941000000000 1000000
OutputYesYesYesNoNoYes
1 second
256 megabytes
['math', 'number theory', '*1700']
E. Vasya and Shiftstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a set of 4n strings of equal length, consisting of lowercase English letters "a", "b", "c", "d" and "e". Moreover, the set is split into n groups of 4 equal strings each. Vasya also has one...
Input1 1b2ae
Output11
2 seconds
256 megabytes
['matrices', '*2600']
D. Misha, Grisha and Undergroundtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMisha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possi...
Input3 21 11 2 32 3 3
Output23
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'trees', '*1900']
C. Strange Radiationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximu...
Input2 999400000 1 2500000 1 1
Output500000.000000000000000000000000000000
3 seconds
256 megabytes
['binary search', 'implementation', 'math', '*2500']
B. Petya and Examtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..There is a...
Inputaba?a2aaaaab
OutputYESNO
2 seconds
256 megabytes
['implementation', 'strings', '*1600']
A. Sasha and Stickstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.Today he invented one simple game to play...
Input1 1
OutputYES
2 seconds
256 megabytes
['games', 'math', '*800']
C. Jury Markstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some sco...
Input4 1-5 5 0 2010
Output3
2 seconds
256 megabytes
['brute force', 'constructive algorithms', '*1700']
B. Keyboard Layoutstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alp...
InputqwertyuiopasdfghjklzxcvbnmveamhjsgqocnrbfxdtwkylupziTwccpQZAvb2017
OutputHelloVKCup2017
1 second
256 megabytes
['implementation', 'strings', '*800']
A. Unimodal Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArray of integers is unimodal, if: it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing. The first block (increasing) and the last block (decrea...
Input61 5 5 5 4 2
OutputYES
1 second
256 megabytes
['implementation', '*1000']
E. Perpetual Motion Machinetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDeveloper Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way.Each element has one controller that can be set to any non...
Input4 4 41 22 33 44 2 3 22 33 1 4 61 23 44 21 41 33 2 10 92 13 25 26 22 72 82 92 104 2
OutputYES1 2 2 1NOYES1 1 1 1YES1 5 1 1 1 1 1 1 1 1
2 seconds
512 megabytes
['constructive algorithms', 'dp', 'graphs', 'implementation', 'math', 'trees', '*3100']
D. Singer Housetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt is known that passages in Singer house are complex and intertwined. Let's define a Singer k-house as a graph built by the following process: take complete binary tree of height k and add edges from ea...
Input2
Output9
2 seconds
512 megabytes
['combinatorics', 'dp', 'graphs', 'trees', '*2800']
C. Bamboo Partitiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are ...
Input3 41 3 5
Output3
2 seconds
512 megabytes
['brute force', 'data structures', 'implementation', 'math', 'number theory', 'sortings', 'two pointers', '*2300']
B. Cards Sortingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them...
Input46 3 1 2
Output7
1 second
256 megabytes
['data structures', 'implementation', 'sortings', '*1600']
A. Office Keystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then g...
Input2 4 5020 10060 10 40 80
Output50
2 seconds
256 megabytes
['binary search', 'brute force', 'dp', 'greedy', 'sortings', '*1800']
B. Black Squaretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible...
Input5 4WWWWWWWBWWWBWWBBWWWW
Output5
1 second
256 megabytes
['implementation', '*1300']
A. Restaurant Tablestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one p...
Input4 1 21 2 1 1
Output0
1 second
256 megabytes
['implementation', '*1200']
F. Dirty Arkady's Kitchentime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputArkady likes to walk around his kitchen. His labyrinthine kitchen consists of several important places connected with passages. Unfortunately it happens that these passages are flooded with mil...
Input5 61 2 0 12 5 2 32 5 0 11 3 0 13 4 1 24 5 2 3
Output3
6 seconds
512 megabytes
['data structures', 'dp', 'graphs', 'shortest paths', '*3200']
E. Rusty Stringtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGrigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossibl...
Input3 5V??VK 6?????? 4?VK?
Output23 561 2 3 4 5 632 3 4
3 seconds
512 megabytes
['fft', 'math', 'strings', '*2700']
D. Best Edge Weighttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a connected weighted graph with n vertices and m edges. The graph doesn't contain loops nor multiple edges. Consider some edge with id i. Let's determine for this edge the maximum integ...
Input4 41 2 22 3 23 4 24 1 3
Output2 2 2 1
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'graphs', 'trees', '*2700']
C. DNA Evolutiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputEveryone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rar...
InputATGCATGC42 1 8 ATGC2 2 6 TTT1 4 T2 2 6 TA
Output824
2 seconds
512 megabytes
['data structures', 'strings', '*2100']
B. High Loadtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputArkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire ...
Input3 2
Output21 22 3
2 seconds
512 megabytes
['constructive algorithms', 'greedy', 'implementation', 'trees', '*1800']
A. String Reconstructiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan ...
Input3a 4 1 3 5 7ab 2 1 5ca 1 4
Outputabacaba
2 seconds
256 megabytes
['data structures', 'greedy', 'sortings', 'strings', '*1700']
G. Tree Queriestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of n vertices (numbered from 1 to n). Initially all vertices are white. You have to process q queries of two different types: 1 x — change the color of vertex x to black....
Input4 61 22 33 41 21 22 21 32 22 2
Output321
3 seconds
256 megabytes
['dfs and similar', 'graphs', 'trees', '*2500']
F. String Compressiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIvan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters.Unfortunately, when Ivan started writing the letter, he realised that it is very long and ...
Inputaaaaaaaaaa
Output3
2 seconds
512 megabytes
['dp', 'hashing', 'string suffix structures', 'strings', '*2400']
E. Minimal Labelstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.You should assign labels to all vert...
Input3 31 21 33 2
Output1 3 2
1 second
256 megabytes
['data structures', 'dfs and similar', 'graphs', 'greedy', '*2300']
D. Suitable Replacementtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric:Any two letters can be swap...
Input?aa?ab
Outputbaab
1 second
256 megabytes
['binary search', 'greedy', 'implementation', '*1500']
C. Multi-judge Solvingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMakes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all t...
Input3 32 1 9
Output1
1 second
256 megabytes
['greedy', 'implementation', '*1600']
B. Five-In-a-Rowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.In current match they ha...
InputXX.XX..........OOOO.................................................................................
OutputYES
1 second
256 megabytes
['brute force', 'implementation', '*1600']
A. Binary Protocoltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: Each digit is represented with number...
Input3111
Output3
1 second
256 megabytes
['implementation', '*1100']
F. Madnesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe second semester starts at the University of Pavlopolis. After vacation in Vičkopolis Noora needs to return to Pavlopolis and continue her study.Sometimes (or quite often) there are teachers who do not lik...
Input31 22 3
Output21 1 1 2 0.66666666661 2 2 3 0.6666666666
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'trees', '*2500']
E. Liartime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe first semester ended. You know, after the end of the first semester the holidays begin. On holidays Noora decided to return to Vičkopolis. As a modest souvenir for Leha, she brought a sausage of length m fro...
Input9hloyaygrt6loyyrt3
OutputYES
4 seconds
256 megabytes
['binary search', 'dp', 'hashing', 'string suffix structures', '*2400']
D. My pretty girl Nooratime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university...
Input2 2 4
Output19
1.5 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'math', 'number theory', '*1800']
C. Hacker, pack your bags!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.So the hacker began to work hard in order to get rid of boredom. It me...
Input4 51 3 41 2 55 6 11 2 4
Output5
2 seconds
256 megabytes
['binary search', 'greedy', 'implementation', 'sortings', '*1600']
B. Crossword solvingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputErelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though ...
Input3 5abcxaybz
Output22 3
1 second
256 megabytes
['brute force', 'implementation', 'strings', '*1000']
A. I'm bored with lifetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHolidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide s...
Input4 3
Output6
1 second
256 megabytes
['implementation', 'math', 'number theory', '*800']
E. Okabe and El Psy Kongrootime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOkabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can b...
Input1 30 3 3
Output4
2 seconds
256 megabytes
['dp', 'matrices', '*2100']
D. Okabe and Citytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOkabe likes to be able to walk through his city on a path lit by street lamps. That way, he doesn't get beaten up by schoolchildren.Okabe's city is represented by a 2D grid of cells. Rows are numbered ...
Input4 4 51 12 12 33 34 3
Output2
4 seconds
256 megabytes
['dfs and similar', 'graphs', 'shortest paths', '*2200']
C. Okabe and Boxestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOkabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n o...
Input3add 1removeadd 2add 3removeremove
Output1
3 seconds
256 megabytes
['data structures', 'greedy', 'trees', '*1500']
B. Okabe and Banana Treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOkabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.Consider the point (x, y) in the 2D plane such that x and y are in...
Input1 5
Output30
2 seconds
256 megabytes
['brute force', 'math', '*1300']
A. Okabe and Future Gadget Laboratorytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOkabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined ...
Input31 1 22 3 16 4 1
OutputYes
2 seconds
256 megabytes
['implementation', '*800']
B. Mister B and Angle in Polygontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is...
Input3 15
Output1 2 3
2 seconds
256 megabytes
['constructive algorithms', 'geometry', 'math', '*1300']
A. Mister B and Book Readingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.At first day Mister B read v0 pages, but after that he started to speed up...
Input5 5 10 5 4
Output1
2 seconds
256 megabytes
['implementation', '*900']
E. Mister B and Flight to the Moontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn order to fly to the Moon Mister B just needs to solve the following problem.There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of ...
Input3
Output23 1 2 33 1 2 3
2 seconds
256 megabytes
['constructive algorithms', 'graphs', '*2800']
D. Mister B and Astronomerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter studying the beacons Mister B decided to visit alien's planet, because he learned that they live in a system of flickering star Moon. Moreover, Mister B learned that the star shines onc...
Input4 22 3
Output3 1
2 seconds
256 megabytes
['number theory', '*2900']
C. Mister B and Beacons on Fieldtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMister B has a house in the middle of a giant plain field, which attracted aliens life. For convenience, aliens specified the Cartesian coordinate system on the field in such a way that ...
Input32 1 12 1 11 1 31 5 12 2 11 1 210 6 182 103 213 1 13
Output47171
5 seconds
256 megabytes
['number theory', '*2900']
B. Mister B and PR Shiftstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome time ago Mister B detected a strange signal from the space, which he started to study.After some transformation the signal turned out to be a permutation p of length n or its cyclic shift....
Input31 2 3
Output0 0
2 seconds
256 megabytes
['data structures', 'implementation', 'math', '*1900']
A. Mister B and Boring Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens.All characters in this game are lowercas...
Input1 1 1 8
Output2
2 seconds
256 megabytes
['games', 'greedy', '*2200']
G. Four Melodiestime limit per test5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputAuthor note: I think some of you might remember the problem "Two Melodies" from Eductational Codeforces Round 22. Now it's time to make it a bit more difficult!Alice is a composer, and recently she had...
Input51 3 5 7 9
Output4
5 seconds
1024 megabytes
['flows', 'graphs', '*2600']
F. Level Generationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.Ivan decided that...
Input3346
Output236
1 second
256 megabytes
['binary search', 'math', 'ternary search', '*2100']
E. Card Game Againtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova again tries to play some computer card game.The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck ...
Input3 46 2 8
Output4
2 seconds
256 megabytes
['binary search', 'data structures', 'number theory', 'two pointers', '*1900']
D. Multicolored Carstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.The game...
Input4 12 1 4 2
Output2
2 seconds
256 megabytes
['data structures', 'implementation', '*1700']
C. Sofa Thieftime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?Fortunately, the thief had l...
Input23 23 1 3 21 2 2 21 0 0 1
Output1
1 second
256 megabytes
['brute force', 'implementation', '*2000']
B. Permutation Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputn children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to...
Input4 52 3 1 4 4
Output3 1 2 4
1 second
256 megabytes
['implementation', '*1600']
A. Diplomas and Certificatestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything....
Input18 2
Output3 6 9
1 second
256 megabytes
['implementation', 'math', '*800']
F. MEX Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of integer numbers, initially it is empty. You should perform n queries.There are three different types of queries: 1 l r — Add all missing numbers from the interval [l, r] 2 l r — ...
Input31 3 43 1 62 1 3
Output131
2 seconds
256 megabytes
['binary search', 'data structures', 'trees', '*2300']
E. Choosing The Commandertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.Vova managed to build a large army, but forgot about the main person in the ar...
Input51 31 43 6 32 43 6 3
Output10
2 seconds
256 megabytes
['bitmasks', 'data structures', 'trees', '*2000']
D. Imbalanced Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance valu...
Input31 4 1
Output9
2 seconds
256 megabytes
['data structures', 'divide and conquer', 'dsu', 'sortings', '*1900']
C. Really Big Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and ...
Input12 1
Output3
1 second
256 megabytes
['binary search', 'brute force', 'dp', 'math', '*1600']
B. Makes And The Producttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a pa...
Input41 1 1 1
Output4
2 seconds
256 megabytes
['combinatorics', 'implementation', 'math', 'sortings', '*1500']
A. Treasure Hunttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCaptain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treas...
Input0 0 0 62 3
OutputYES
1 second
256 megabytes
['implementation', 'math', 'number theory', '*1200']
B. Karen and Coffeetime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputTo stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent s...
Input3 2 491 9492 9797 9992 9493 9795 9690 100
Output3304
2.5 seconds
512 megabytes
['binary search', 'data structures', 'implementation', '*1400']
A. Karen and Morningtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKaren is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time i...
Input05:39
Output11
2 seconds
512 megabytes
['brute force', 'implementation', '*1000']
E. Karen and Neighborhoodtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood. The neighborhood consists of n houses i...
Input6 4
Output2
2 seconds
512 megabytes
['binary search', 'constructive algorithms', 'implementation', '*2900']
D. Karen and Cardstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKaren just got home from the supermarket, and is getting ready to go to sleep. After taking a shower and changing into her pajamas, she looked at her shelf and saw an album. Curious, she opened it an...
Input3 4 4 52 2 51 3 44 1 1
Output10
2 seconds
512 megabytes
['binary search', 'combinatorics', 'data structures', 'geometry', '*2800']
C. Karen and Supermarkettime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputOn the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can ...
Input6 1610 910 5 112 2 120 18 310 2 32 1 5
Output4
2 seconds
512 megabytes
['brute force', 'dp', 'trees', '*2400']
B. Karen and Testtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKaren has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and ha...
Input53 6 9 12 15
Output36
2 seconds
512 megabytes
['brute force', 'combinatorics', 'constructive algorithms', 'math', '*2200']
A. Karen and Gametime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputOn the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the n...
Input3 52 2 2 3 20 0 0 1 01 1 1 2 1
Output4row 1row 1col 4row 3
2 seconds
512 megabytes
['brute force', 'greedy', 'implementation', '*1700']
E. An unavoidable detour for hometime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThose unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there'...
Input43 2 3 2
Output1
3 seconds
256 megabytes
['combinatorics', 'dp', 'graphs', 'shortest paths', '*2600']
D. An overnight dance in discothequetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it?The discotheque can be seen as an infinite xy-plane, ...
Input52 1 60 4 12 -1 31 -2 14 -1 1
Output138.23007676
2 seconds
256 megabytes
['dfs and similar', 'dp', 'geometry', 'greedy', 'trees', '*2000']
C. An impassioned circulation of affectiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Ko...
Input6koyomi31 o4 o4 m
Output365
2 seconds
256 megabytes
['brute force', 'dp', 'strings', 'two pointers', '*1600']
B. An express train to reveriestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the ill...
Input51 2 3 4 31 2 5 4 5
Output1 2 5 4 3
1 second
256 megabytes
['constructive algorithms', '*1300']
A. An abandoned sentiment from pasttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed...
Input4 211 0 0 145 4
OutputYes
1 second
256 megabytes
['constructive algorithms', 'greedy', 'implementation', 'sortings', '*900']
F. Bipartite Checkingtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or remov...
Input3 52 31 31 21 21 2
OutputYESYESNOYESNO
6 seconds
256 megabytes
['data structures', 'dsu', 'graphs', '*2500']
E. Army Creationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.In the game Vova can hire n different warriors; ith warrior h...
Input6 21 1 1 2 2 251 64 31 12 62 6
Output24132
2 seconds
256 megabytes
['binary search', 'data structures', '*2200']
D. Two Melodiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with n notes written on it. She wants to take two ...
Input41 2 4 5
Output4
2 seconds
256 megabytes
['dp', 'flows', '*2600']
C. The Tag Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of...
Input4 31 22 32 4
Output4
1 second
256 megabytes
['dfs and similar', 'graphs', '*1700']
B. The Golden Agetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUnlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are un...
Input2 3 1 10
Output1
1 second
256 megabytes
['brute force', 'math', '*1800']