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
A. Case of Matryoshkastime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.The main exhibit is a construction of n matryoshka dolls that...
Input3 22 1 21 3
Output1
2 seconds
256 megabytes
['implementation', '*1500']
B. Ohana Cleans Uptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOhana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her br...
Input40101100011110101
Output2
2 seconds
256 megabytes
['brute force', 'greedy', 'strings', '*1200']
A. Kyoya and Photobookstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly...
Inputa
Output51
2 seconds
256 megabytes
['brute force', 'math', 'strings', '*900']
E. Kyoya and Traintime limit per test8 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKyoya Ootori wants to take the train to get to school. There are n train stations and m one-way train lines going between various stations. Kyoya is currently at train station 1, and the school is at ...
Input4 4 5 11 2 050000 0 50000 0 02 3 010000 0 0 0 900003 4 0100000 0 0 0 02 4 00 0 0 50000 50000
Output0.7000000000
8 seconds
512 megabytes
['dp', 'fft', 'graphs', 'math', 'probabilities', '*3200']
D. Nudist Beachtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNudist Beach is planning a military operation to attack the Life Fibers. In this operation, they will attack and capture several cities which are currently under the control of the Life Fibers.There are ...
Input9 8 43 9 6 81 21 31 41 52 62 72 82 9
Output31 4 5
2 seconds
256 megabytes
['binary search', 'graphs', 'greedy', '*2300']
C. Love Trianglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are...
Input3 0
Output4
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'graphs', '*2200']
B. Kyoya and Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, ...
Input4 3
Output1 3 2 4
2 seconds
256 megabytes
['binary search', 'combinatorics', 'constructive algorithms', 'greedy', 'implementation', 'math', '*1900']
A. Kyoya and Colored Ballstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the...
Input3221
Output3
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*1500']
E. Vanya and Bracketstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya is doing his maths homework. He has an expression of form , where x1, x2, ..., xn are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to ...
Input3+5*7+8*4
Output303
1 second
256 megabytes
['brute force', 'dp', 'expression parsing', 'greedy', 'implementation', 'strings', '*2100']
D. Vanya and Trianglestime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted poin...
Input40 01 12 02 2
Output3
4 seconds
512 megabytes
['brute force', 'combinatorics', 'data structures', 'geometry', 'math', 'sortings', '*1900']
C. Vanya and Scalestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can...
Input3 7
OutputYES
1 second
256 megabytes
['brute force', 'dp', 'greedy', 'math', 'meet-in-the-middle', 'number theory', '*1900']
B. Vanya and Bookstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya got an important task β€” he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books s...
Input13
Output17
1 second
256 megabytes
['implementation', 'math', '*1200']
A. Vanya and Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In...
Input21 1 2 32 2 3 3
Output10
2 seconds
256 megabytes
['implementation', 'math', '*1000']
E. GukiZ and GukiZianatime limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a,...
Input4 31 2 3 41 1 2 11 1 1 12 3
Output2
10 seconds
256 megabytes
['binary search', 'data structures', 'implementation', '*2500']
D. GukiZ and Binary Operationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following co...
Input2 1 2 10
Output3
1 second
256 megabytes
['combinatorics', 'implementation', 'math', 'matrices', 'number theory', '*2100']
C. GukiZ hates Boxestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are n piles of boxes, arranged in a line, from left to right, i-th pi...
Input2 11 1
Output4
2 seconds
256 megabytes
['binary search', 'greedy', '*2200']
B. ZgukistringZtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so...
Inputaaaab
Outputaaa
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', 'strings', '*1800']
A. GukiZ and Contesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, n students will attend, and ...
Input31 3 3
Output3 1 1
2 seconds
256 megabytes
['brute force', 'implementation', 'sortings', '*800']
E. Brackets in Implicationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImplication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is wri...
Input40 1 1 0
OutputYES(((0)->1)->(1->0))
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'implementation', 'math', '*2200']
D. Regular Bridgetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connecte...
Input1
OutputYES2 11 2
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'implementation', '*1900']
C. Divisibility by Eighttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.Your task is to determine if it is possible in this case to r...
Input3454
OutputYES344
2 seconds
256 megabytes
['brute force', 'dp', 'math', '*1500']
B. Preparing Olympiadtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the...
Input3 5 6 11 2 3
Output2
2 seconds
256 megabytes
['bitmasks', 'brute force', '*1400']
A. Two Substringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).InputThe only line of input contains a...
InputABA
OutputNO
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'implementation', 'strings', '*1500']
H. Degenerate Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe determinant of a matrix 2 × 2 is defined as follows:A matrix is called degenerate if its determinant is equal to zero. The norm ||A|| of a matrix A is defined as a maximum of absolute values of i...
Input1 23 4
Output0.2000000000
1 second
256 megabytes
['binary search', 'math', '*2100']
G. Happy Linetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDo you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We kno...
Input211 8
Output9 10
1 second
256 megabytes
['constructive algorithms', 'greedy', 'sortings', '*2200']
F. Yura and Developerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYura has a team of k developers and a list of n tasks numbered from 1 to n. Yura is going to choose some tasks to be done this week. Due to strange Looksery habits the numbers of chosen tasks shoul...
Input4 31 2 3 4
Output3
1 second
256 megabytes
['data structures', 'divide and conquer', '*2800']
E. Sasha Circletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerlanders like to eat cones after a hard day. Misha Square and Sasha Circle are local authorities of Berland. Each of them controls its points of cone trade. Misha has n points, Sasha β€” m. Since their s...
Input2 2-1 01 00 -10 1
OutputNO
2 seconds
256 megabytes
['geometry', 'math', '*2700']
D. Haar Featurestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As par...
Input6 8BBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWW
Output2
1 second
256 megabytes
['greedy', 'implementation', '*1900']
C. The Game Of Paritytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground....
Input3 11 2 1
OutputStannis
1 second
256 megabytes
['games', '*2200']
B. Looksery Partytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Looksery company, consisting of n staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the ...
Input31010100010 1 2
Output11
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'greedy', '*2300']
A. Face Detectiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. I...
Input4 4xxxxxfaxxcexxxxx
Output1
1 second
256 megabytes
['implementation', 'strings', '*900']
B. Mike and Funtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column n...
Input5 4 50 1 1 01 0 0 10 1 1 01 0 0 10 0 0 01 11 41 14 24 3
Output34334
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'implementation', '*1400']
A. Mike and Faxtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. ...
Inputsaba2
OutputNO
1 second
256 megabytes
['brute force', 'implementation', 'strings', '*1100']
E. Mike and Friendstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhat-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercase English letters. What is double strange that a phone number can be associated with several bears!...
Input5 5aababababababb1 5 13 5 11 5 21 5 31 4 5
Output75636
3 seconds
256 megabytes
['data structures', 'string suffix structures', 'strings', 'trees', '*2800']
D. Mike and Fishtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. He has marked n distinct points ...
Input41 11 22 12 2
Outputbrrb
3 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', '*2600']
C. Mike and Foamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1 to n. i-th kind of beer has ai milliliters of foam on it. Max...
Input5 61 2 3 4 6123451
Output013562
2 seconds
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'math', 'number theory', '*2300']
B. Mike and Feettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th ...
Input101 2 3 4 5 4 3 2 1 6
Output6 4 4 3 3 2 2 1 1 1
1 second
256 megabytes
['binary search', 'data structures', 'dp', 'dsu', '*1900']
A. Mike and Frogtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar. So, ...
Input54 21 10 12 3
Output3
1 second
256 megabytes
['brute force', 'greedy', 'implementation', 'math', '*2200']
E. Soldier and Travelingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has t...
Input4 41 2 6 33 5 3 11 22 33 44 2
OutputYES1 0 0 0 2 0 0 0 0 5 1 0 0 0 2 1
1 second
256 megabytes
['flows', 'graphs', 'math', '*2100']
D. Soldier and Number Gametime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of ro...
Input23 16 3
Output25
3 seconds
256 megabytes
['constructive algorithms', 'dp', 'math', 'number theory', '*1700']
C. Soldier and Cardstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible tha...
Input42 1 32 4 2
Output6 2
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'games', '*1400']
B. Soldier and Badgestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputColonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for t...
Input41 3 1 4
Output1
3 seconds
256 megabytes
['brute force', 'greedy', 'implementation', 'sortings', '*1200']
A. Soldier and Bananastime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay iΒ·k dollars for the i-th banana). ...
Input3 17 4
Output13
1 second
256 megabytes
['brute force', 'implementation', 'math', '*800']
E. Paths and Treestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know it...
Input3 31 2 12 3 11 3 23
Output21 2
3 seconds
256 megabytes
['graphs', 'greedy', 'shortest paths', '*2000']
D. Queuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed i...
Input515 2 1 5 3
Output4
1 second
256 megabytes
['greedy', 'implementation', 'sortings', '*1300']
C. Woodcutterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation t...
Input51 22 15 1010 919 1
Output3
1 second
256 megabytes
['dp', 'greedy', '*1500']
B. Equidistant Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance...
Input00011011
Output0011
1 second
256 megabytes
['greedy', '*1100']
A. Toy Carstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. ...
Input3-1 0 00 -1 10 2 -1
Output21 3
1 second
256 megabytes
['implementation', '*900']
B. Sea and Islandstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islan...
Input5 2
OutputYESSSSSSLLLLLSSSSSLLLLLSSSSS
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1400']
A. Set of Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the first characters of th...
Input1abca
OutputYESabca
1 second
256 megabytes
['implementation', 'strings', '*1100']
E. Listening to Musictime limit per test7 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPlease note that the memory limit differs from the standard.You really love to listen to music. During the each of next s days you will listen to exactly m songs from the playlist that consists of e...
Input5 31 2 1 2 351 1 21 3 21 3 31 3 51 3 1
Output20231
7 seconds
64 megabytes
['constructive algorithms', 'data structures', '*3200']
D. Road Improvementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n incl...
Input31 1
Output4 3 3
2 seconds
256 megabytes
['dp', 'trees', '*2300']
C. Remembering Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some...
Input4 5abcdeabcdeabcdeabcde1 1 1 1 11 1 1 1 11 1 1 1 11 1 1 1 1
Output3
2 seconds
256 megabytes
['bitmasks', 'dp', '*2500']
B. Destroying Roadstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour y...
Input5 41 22 33 44 51 3 23 5 2
Output0
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'shortest paths', '*2100']
A. Writing Codetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProgrammers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of co...
Input3 3 3 1001 1 1
Output10
3 seconds
256 megabytes
['dp', '*1800']
F. Questtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer qi, and the time ti in minutes needed to complete the task. An interes...
Input5 51 11 12 23 34 4
Output11
1 second
256 megabytes
['dp', 'greedy', '*2100']
E. Playing on Graphtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.Vova has a non-directed graph consisting of n vertices and m edges without loops and mul...
Input5 41 22 33 43 5
Output3
3 seconds
256 megabytes
['graphs', 'shortest paths', '*2600']
D. Superhero's Jobtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's tough to be a superhero. And it's twice as tough to resist the supervillain who is cool at math. Suppose that you're an ordinary Batman in an ordinary city of Gotham. Your enemy Joker mined the b...
Input3
Output1
2 seconds
256 megabytes
['dfs and similar', 'dp', 'hashing', 'math', 'number theory', '*2600']
C. Idempotent functionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function , that for any the formula g(g(x)) = g(x) holds.Let's denote as f(...
Input41 2 2 4
Output1
1 second
256 megabytes
['constructive algorithms', 'graphs', 'math', '*2000']
B. Duck Hunttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA duck hunter is doing his favorite thing, hunting. He lives in a two dimensional world and is located at point (0, 0). As he doesn't like walking for his prey, he prefers to shoot only vertically up (becau...
Input3 3-3 01 3-1 2
Output3
3 seconds
256 megabytes
['data structures', '*3100']
A. Place Your Ad Heretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan Anatolyevich's agency is starting to become famous in the town. They have already ordered and made n TV commercial videos. Each video is made in a special way: the colors and the soundtrack ar...
Input2 37 91 42 8 20 4 18 9 3
Output42 1
2 seconds
256 megabytes
['data structures', 'sortings', '*2400']
E. Infinite Inversionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of sw...
Input24 21 4
Output4
2 seconds
256 megabytes
['binary search', 'data structures', 'implementation', 'sortings', 'trees', '*2100']
D. Bad Luck Islandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and ...
Input2 2 2
Output0.333333333333 0.333333333333 0.333333333333
2 seconds
256 megabytes
['dp', 'probabilities', '*1900']
C. Ice Cavetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice...
Input4 6X...XX...XX..X..X.......1 62 2
OutputYES
2 seconds
256 megabytes
['dfs and similar', '*2000']
B. School Markstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write eve...
Input5 3 5 18 43 5 4
Output4 1
2 seconds
256 megabytes
['greedy', 'implementation', '*1700']
A. Combination Locktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputScrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The c...
Input58219564723
Output13
2 seconds
256 megabytes
['implementation', '*800']
H. Summer Dichotomytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputT students applied into the ZPP class of Summer Irrelevant School. The organizing committee of the school may enroll any number of them, but at least t students must be enrolled. The enrolled student...
Input10 203 03 64 916 25
OutputPOSSIBLE4 16112
2 seconds
256 megabytes
['2-sat', 'data structures', 'dfs and similar', 'greedy', '*3200']
G. Berserk Robot time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHelp! A robot escaped our lab and we need help finding it. The lab is at the point (0, 0) of the coordinate plane, at time 0 the robot was there. The robot's movements are defined by a programΒ β€” a stri...
Input3 31 1 02 1 -13 0 -1
OutputRDL
2 seconds
256 megabytes
['constructive algorithms', 'math', 'sortings', '*3100']
F. A Heap of Heapstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAndrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment.The teacher...
Input51 5 4 3 2
Output3 2 1 0
3 seconds
512 megabytes
['brute force', 'data structures', 'math', 'sortings', '*2200']
E. Demiurges Play Againtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDemiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.There is a rooted tree on n nodes, m of which are leaves (a ...
Input51 21 32 42 5
Output3 2
2 seconds
256 megabytes
['dfs and similar', 'dp', 'math', 'trees', '*2200']
D. Weird Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.Igor's chessboard is a square of size n...
Input5oxxxxx...xx...xx...xxxxxo
OutputYES....x........x........x........x....xxxxoxxxx....x........x........x........x....
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', '*1800']
C. Tourist's Notestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pic...
Input8 22 07 0
Output2
2 seconds
256 megabytes
['binary search', 'brute force', 'greedy', 'implementation', 'math', '*1600']
B. Quasi Binarytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011Β β€” are quasibinary and numbers 2, 12, 900 are not.You are given a positive ...
Input9
Output91 1 1 1 1 1 1 1 1
2 seconds
256 megabytes
['constructive algorithms', 'dp', 'greedy', 'implementation', '*1400']
A. Cutting Bannertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and ...
InputCODEWAITFORITFORCES
OutputYES
2 seconds
256 megabytes
['brute force', 'implementation', '*1400']
E. Tavas on the Pathtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTavas lives in Tavaspolis. Tavaspolis has n cities numbered from 1 to n connected by n - 1 bidirectional roads. There exists a path between any two cities. Also each road has a length. Tavas' favor...
Input2 3101 2 31 2 21 2 31 2 4
Output10100
3 seconds
256 megabytes
['data structures', 'divide and conquer', 'trees', '*3100']
D. Tavas in Kansastime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputTavas lives in Kansas. Kansas has n cities numbered from 1 to n connected with m bidirectional roads. We can travel from any city to any other city via these roads. Kansas is as strange as Tavas. So t...
Input4 41 23 2 5 -111 4 23 4 23 1 53 2 1
OutputCry
2 seconds
512 megabytes
['dp', 'games', '*2900']
E. Tavas and Pashmakstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTavas is a cheerleader in the new sports competition named "Pashmaks". This competition consists of two part: swimming and then running. People will immediately start running R meters after they fi...
Input31 32 23 1
Output1 2 3
1 second
256 megabytes
['geometry', 'math', '*2600']
D. Tavas and Malekastime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. Today Tavas fell asleep in Malekas' place. While...
Input6 2ioi1 3
Output26
2 seconds
256 megabytes
['greedy', 'hashing', 'string suffix structures', 'strings', '*1900']
C. Tavas and Karafstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKarafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has ...
Input2 1 41 5 33 3 107 10 26 4 8
Output4-18-1
2 seconds
256 megabytes
['binary search', 'greedy', 'math', '*1900']
B. Tavas and SaDDastime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas too...
Input4
Output1
1 second
256 megabytes
['bitmasks', 'brute force', 'combinatorics', 'implementation', '*1100']
A. Tavas and Nafastime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to sha...
Input6
Outputsix
1 second
256 megabytes
['brute force', 'implementation', '*1000']
F. Simplified Nonogramtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this task you have to write a program dealing with nonograms on fields no larger than 5 × 20.Simplified nonogram is a task where you have to build such field (each cell is either white or black...
Input3 52 3 21 0 1 2 1
Output*.**.*.*.**..**
2 seconds
256 megabytes
['bitmasks', 'dp', 'hashing', 'meet-in-the-middle', '*2400']
E. Berland Local Positioning Systemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland a bus travels along the main street of the capital. The street begins from the main square and looks like a very long segment. There are n bus stops located along the stree...
Input62 3 5 7 11 1353 4 5 5 6
Output10
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'hashing', 'implementation', '*2400']
D. Handshakestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting do...
Input52 1 3 0 1
OutputPossible4 5 1 3 2
1 second
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'greedy', '*1900']
C. Polycarpus' Dicetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number,...
Input2 84 4
Output3 3
1 second
256 megabytes
['math', '*1600']
B. Covered Pathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this s...
Input5 64 2
Output26
1 second
256 megabytes
['dp', 'greedy', 'math', '*1400']
A. Examtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by si...
Input6
Output61 5 3 6 2 4
1 second
256 megabytes
['constructive algorithms', 'implementation', 'math', '*1100']
F. Encodingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp invented a new way to encode strings. Let's assume that we have string T, consisting of lowercase English letters. Let's choose several pairs of letters of the English alphabet in such a way that ea...
Input11 5abacabadabaacaba
Output31 3 7
3 seconds
256 megabytes
['hashing', 'string suffix structures', 'strings', '*2400']
E. Correcting Mistakestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnalyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query,...
Input7readingtrading
Output1
2 seconds
256 megabytes
['constructive algorithms', 'dp', 'greedy', 'hashing', 'strings', 'two pointers', '*1800']
D. Landmarkstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe have an old building with n + 2 columns in a row. These columns support the ceiling. These columns are located in points with coordinates 0 = x0 < x1 < ... < xn < xn + 1. The leftmost and the rightmost c...
Input20 20 40 10015 40
Output10
2 seconds
256 megabytes
['data structures', 'dp', '*3000']
C. Board Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can m...
Input2 1 2 2
OutputPolycarp
1 second
256 megabytes
['games', 'greedy', 'implementation', 'math', '*1700']
B. Work Grouptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of cour...
Input7-1 31 21 11 44 54 35 2
Output17
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'strings', 'trees', '*2000']
A. Berland Minerstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe biggest gold mine in Berland consists of n caves, connected by n - 1 transitions. The entrance to the mine leads to the cave number 1, it is possible to go from it to any remaining cave of the mine...
Input65 8 4 6 3 121 21 34 22 56 367 4 2 5 3 11
Output6
3 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'greedy', 'trees', '*3000']
I. Different variablestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputN variables X1, ..., XN can have positive integer values. You are given K constraints for these value that look like "the values of variables Xi1, Xi2, ..., XiM are different". Among all possible ...
Input2 12 1 2
Output1 2
2 seconds
256 megabytes
['*special problem', '*2500']
H. Points in triangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of points on a plane with positive integer coordinates. Find a triangle of minimum area with vertices in points (0, 0), (A, 0) and (0, B) (A and B are unknown positive integers)...
Input21 11 3
Output6.0
2 seconds
256 megabytes
['*special problem', 'geometry', '*2100']
G. Levenshtein distancetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevenshtein distance between two strings of letters is calculated as the minimal total cost of a sequence of edit actions that converts one of the strings into the other one. The allowed edit act...
Inputarcbug
Output8
2 seconds
256 megabytes
['*special problem', '*2100']
F. Jumping frogstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA rectangular swamp is inhabited by 10 species of frogs. Frogs of species i can jump from hillocks to hillock exactly i units along X-axis or Y-axis. Initially frogs of all types sit at the hillock at c...
Input30 10 -20 3
Output3
2 seconds
256 megabytes
['*special problem', '*2100']
E. Sum and producttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given integers N and D. Find N positive integers x1...xN such that the difference of their product and their sum equals D.InputThe only line of input contains integers N (2 ≀ N ≀ 1000) and D (...
Input2 1
Output2 3
2 seconds
256 megabytes
['*special problem', '*1700']
D. Set subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a starting set consisting of all integers from 1 to 1000, inclusive. You are also given several sets which need to be subtracted from the starting set (i.e., each number which is in at l...
Input21 900902 999
Output2 901 1000
2 seconds
256 megabytes
['*special problem', '*1600']
C. Diophantine equationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an equation A * X + B * Y = C, A, B, C are positive integer coefficients, X and Y are variables which can have positive integer values only. Output the number of solutions of this e...
Input3 5 35
Output25 410 1
2 seconds
256 megabytes
['*special problem', '*1500']