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. Tree and Queriestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to n. Then we represent the color of vert...
Input8 51 2 2 3 3 2 3 31 21 52 32 45 65 75 81 21 31 42 35 3
Output22101
1 second
256 megabytes
['data structures', 'dfs and similar', 'trees', '*2400']
C. Circling Round Treasurestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a map as a rectangle table. Each cell of the table is either an obstacle, or a treasure with a certain price, or a bomb, or an empty cell. Your initial position is also given to you.Y...
Input4 4.....S1.........10
Output2
1 second
256 megabytes
['bitmasks', 'shortest paths', '*2600']
B. Maximum Submatrix 2time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be ...
Input1 11
Output1
2 seconds
512 megabytes
['data structures', 'dp', 'implementation', 'sortings', '*1600']
A. Divisible by Seventime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.Numbe...
Input1689
Output1869
1 second
256 megabytes
['math', 'number theory', '*1600']
E. Inna and Babiestime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna, Dima and Sereja are in one room together. It's cold outside, so Sereja suggested to play a board game called "Babies". The babies playing board is an infinite plane containing n blue babies and ...
Input2 22 25 53 75 1
Output3
6 seconds
256 megabytes
['binary search', 'data structures', 'dsu', 'geometry', 'implementation', '*2600']
D. Inna and Sequence time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima's spent much time thinking what present to give to Inna and gave her an empty sequence w. Now they want to fill sequence w with numbers zero and one. For that, they decided to play an amusing ...
Input10 31 3 6-11100-101-11
Output011
2 seconds
256 megabytes
['binary search', 'data structures', 'dp', 'trees', '*2000']
C. Inna and Dimatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".Inna loves Dima, so she wants to go through his name as many times as possible ...
Input1 2DI
OutputPoor Dima!
1 second
256 megabytes
['dfs and similar', 'dp', 'graphs', 'implementation', '*1900']
B. Inna and Ninetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 t...
Input369727
Output2
1 second
256 megabytes
['combinatorics', 'greedy', '*1500']
A. Inna and Pink Ponytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbe...
Input5 7 1 3 2 2
Output2
1 second
256 megabytes
['greedy', 'implementation', '*2000']
B. Making Sequences is Funtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6.You want to make a consecutive integer sequence st...
Input9 1 1
Output9
2 seconds
256 megabytes
['binary search', 'implementation', 'math', '*1600']
A. Collecting Beats is Funtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCucumber boy is fan of Kyubeat, a famous music game.Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel.Each panel has a timing to pres...
Input1.135124734685789
OutputYES
1 second
256 megabytes
['implementation', '*900']
E. Drawing Circles is Funtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are a set of points S on the plane. This set doesn't contain the origin O(0, 0), and for each two distinct points in the set A and B, the triangle OAB has strictly positive area.Consider ...
Input10-46 46 0 360 20 -24 48-50 50 -49 49-20 50 8 40-15 30 14 284 10 -4 56 15 8 10-20 50 -3 154 34 -16 3416 34 2 17
Output2
3 seconds
256 megabytes
['combinatorics', 'geometry', '*3000']
D. Choosing Subtree is Funtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a tree consisting of n vertices. The vertices are numbered from 1 to n.Let's define the length of an interval [l, r] as the value r - l + 1. The score of a subtree of this tree is the...
Input10 64 1010 62 99 68 57 14 77 31 8
Output3
5 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'trees', 'two pointers', '*2600']
C. Watching Fireworks is Funtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent section...
Input50 3 149 1 126 1 46 1 10
Output-31
4 seconds
256 megabytes
['data structures', 'dp', 'math', '*2100']
B. Counting Rectangles is Funtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an n × m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the i-th row and the j-th column as (i, j).Let's define a "rectangle...
Input5 5 500101000000000101000000011 2 2 44 5 4 51 2 5 22 2 4 54 2 5 3
Output1017345
4 seconds
256 megabytes
['brute force', 'divide and conquer', 'dp', '*1900']
A. Counting Kangaroos is Funtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at...
Input825769842
Output5
1 second
256 megabytes
['binary search', 'greedy', 'sortings', 'two pointers', '*1600']
E. Subway Innovationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland is going through tough times β€” the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!The President of Berland wa...
Input31 100 1012
Output2 3
2 seconds
256 megabytes
['greedy', 'math', 'two pointers', '*2000']
D. Vesselstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a system of n vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to n, in the order from the highest to the lowest, the volume of the i-th ...
Input25 1061 1 42 11 2 51 1 42 12 2
Output458
2 seconds
256 megabytes
['data structures', 'dsu', 'implementation', 'trees', '*1800']
C. Hamburgerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausa...
InputBBBSSC6 4 11 2 34
Output2
1 second
256 megabytes
['binary search', 'brute force', '*1600']
B. Fox Dividing Cheesetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's whe...
Input15 20
Output3
1 second
256 megabytes
['math', 'number theory', '*1300']
A. K-Periodic Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.Array a is k-period if its length is divisible by k and there is such array b of length k, that a is repre...
Input6 22 1 2 2 2 1
Output1
1 second
256 megabytes
['greedy', 'implementation', 'math', '*1000']
E. Summer Readingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt school Vasya got an impressive list of summer reading books. Unlike other modern schoolchildren, Vasya loves reading, so he read some book each day of the summer.As Vasya was reading books, he was ma...
Input70 1 0 0 0 3 0
Output31 1 2 2 3 3 3
1 second
256 megabytes
['dp', 'greedy', '*2500']
D. Broken Monitortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInnocentius has a problem β€” his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is re...
Input4 8..w..w....................w..w..
Output..w++w....+..+....+..+....w++w..
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'greedy', 'implementation', '*2100']
C. Mittenstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA Christmas party in city S. had n children. All children came in mittens. The mittens can be of different colors, but each child had the left and the right mitten of the same color. Let's say that the colors ...
Input6 31 3 2 2 1 1
Output62 11 22 11 31 23 1
1 second
256 megabytes
['constructive algorithms', 'greedy', 'sortings', '*1800']
B. Berland Bingotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distin...
Input31 13 2 4 12 10 11
OutputYESNOYES
1 second
256 megabytes
['implementation', '*1300']
A. Rook, Bishop and Kingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organi...
Input4 3 1 6
Output2 1 3
1 second
256 megabytes
['graphs', 'math', 'shortest paths', '*1100']
E. Valera and Queriestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputValera loves segments. He has recently come up with one interesting problem.The Ox axis of coordinates has n segments, the i-th segment starts in position li and ends in position ri (we will mark i...
Input3 31 34 56 73 1 4 72 4 51 8
Output310
2 seconds
512 megabytes
['binary search', 'data structures', '*2200']
D. Valera and Foolstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne fine morning, n fools lined up in a row. After that, they numbered each other with numbers from 1 to n, inclusive. Each fool got a unique number. The fools decided not to change their numbers befo...
Input3 350 50 50
Output7
1 second
256 megabytes
['dfs and similar', 'dp', 'graphs', 'shortest paths', '*2200']
C. Valera and Electionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe city Valera lives in is going to hold elections to the city Parliament.The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to...
Input51 2 22 3 23 4 24 5 2
Output15
1 second
256 megabytes
['dfs and similar', 'graphs', 'trees', '*1600']
B. Valera and Contesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was...
Input5 3 1 3 13 9
Output2 3 2 3 3
1 second
256 megabytes
['constructive algorithms', 'implementation', 'math', '*1400']
A. Valera and Platestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to ea...
Input3 1 11 2 1
Output1
1 second
256 megabytes
['greedy', 'implementation', '*900']
B. Sereja and Suffixestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., ...
Input10 101 2 3 4 1 2 3 4 100000 9999912345678910
Output6666654321
1 second
256 megabytes
['data structures', 'dp', '*1100']
A. Sereja and Coat Racktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only...
Input2 12 12
Output3
1 second
256 megabytes
['implementation', '*1000']
E. Sereja and Intervalstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. An interval of numbers is a pair of integers [l, r] (1 ≀ l ≀ r ≀ m). Interval [l1, r1] belongs t...
Input1 1 1
Output1
1 second
256 megabytes
['combinatorics', 'dp', '*2700']
D. Sereja and Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja has m non-empty sets of integers A1, A2, ..., Am. What a lucky coincidence! The given sets are a partition of the set of all integers from 1 to n. In other words, for any integer v (1 ≀ v ≀ n) t...
Input3 2 21 22 1 3
Output1
1 second
256 megabytes
['bitmasks', 'dfs and similar', '*2400']
C. Sereja and the Arrangement of Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x oc...
Input5 21 22 3
Output5
1 second
256 megabytes
['graphs', 'greedy', 'sortings', '*2000']
B. Sereja ans Anagramstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequence...
Input5 3 11 2 3 2 11 2 3
Output21 3
1 second
256 megabytes
['binary search', 'data structures', '*1900']
A. Sereja and Algorithm time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q1q2... qk. The a...
Inputzyxxxxxxyyz55 51 31 111 43 6
OutputYESYESNOYESNO
1 second
256 megabytes
['data structures', 'implementation', '*1500']
E. Dima and Magic Guitartime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hol...
Input4 6 5 73 1 2 2 3 13 2 2 2 5 54 2 2 2 5 33 2 2 1 4 32 3 1 4 1 5 1
Output8
3 seconds
256 megabytes
['brute force', 'implementation', 'math', '*2200']
D. Dima and Trap Graphtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get cri...
Input4 41 2 1 102 4 3 51 3 1 52 4 2 7
Output6
3 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'dsu', 'shortest paths', 'two pointers', '*2000']
C. Dima and Saladtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits i...
Input3 210 8 12 7 1
Output18
1 second
256 megabytes
['dp', '*1900']
B. Dima and To-do Listtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.Inna and Dima are now in one room. Inna tells Dima off ...
Input6 23 2 1 6 5 4
Output1
1 second
256 megabytes
['brute force', 'implementation', '*1200']
A. Dima and Guardstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...There ar...
Input105 6 5 66 6 7 75 8 6 69 9 9 9
Output1 5 5
1 second
256 megabytes
['implementation', '*1100']
B. The Fibonacci Segmenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have array a1, a2, ..., an. Segment [l, r] (1 ≀ l ≀ r ≀ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 ≀ i ≀ r).Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the se...
Input101 2 3 5 8 13 21 34 55 89
Output10
1 second
256 megabytes
['implementation', '*1100']
A. Good Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number eve...
Input10 61234560123456012345601234560123456012345601234560123456012345601234560
Output10
1 second
256 megabytes
['implementation', '*1100']
E. Empty Rectanglestime limit per test12 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou've got an n × m table (n rows and m columns), each cell of the table contains a "0" or a "1".Your task is to calculate the number of rectangles with the sides that are parallel to the sides of t...
Input3 3 2101000101
Output8
12 seconds
512 megabytes
['divide and conquer', 'two pointers', '*3000']
D. Ghdtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe offered his sister Jane Doe find the gcd of some set of numbers a.Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbe...
Input66 2 3 4 5 6
Output3
4 seconds
256 megabytes
['brute force', 'math', 'probabilities', '*2900']
C. Beautiful Settime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe'll call a set of positive integers a beautiful if the following condition fulfills: for any prime p, if , then . In other words, if one number from the set is divisible by prime p, then at least half ...
Input10
Output16 18 24 27 36 48 54 72 108 144
1 second
256 megabytes
['brute force', 'number theory', '*2300']
B. Free Markettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each it...
Input3 21 3 10
Output4 3
1 second
256 megabytes
['dp', 'greedy', '*2200']
A. Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rect...
Input1012345
Output6
1 second
256 megabytes
['combinatorics', 'data structures', 'implementation', '*1600']
E. Two Circlestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's assume that we are given an n × m table filled by integers. We'll mark a cell in the i-th row and j-th column as (i, j). Thus, (1, 1) is the upper left cell of the table and (n, m) is the lower righ...
Input2 2 01 22 4
Output6 2
4 seconds
256 megabytes
['brute force', 'data structures', 'implementation', '*2500']
D. Renting Bikestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them.The renting site offered them m bikes. The renting price is different for different bikes, renting ...
Input2 2 105 57 6
Output2 3
1 second
256 megabytes
['binary search', 'greedy', '*1800']
C. Fixing Typostime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMany modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.In this problem your task to implement a small functionality to correct two typ...
Inputhelloo
Outputhello
1 second
256 megabytes
['greedy', 'implementation', '*1400']
B. Fencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have...
Input7 31 2 6 1 1 7 1
Output3
1 second
256 megabytes
['brute force', 'dp', '*1100']
A. Sorobantime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban β€”...
Input2
OutputO-|OO-OO
1 second
256 megabytes
['implementation', '*800']
E. Petya and Pipestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA little boy Petya dreams of growing up and becoming the Head Berland Plumber. He is thinking of the problems he will have to solve in the future. Unfortunately, Petya is too inexperienced, so you are ...
Input5 70 1 0 2 00 0 4 10 00 0 0 0 50 0 0 0 100 0 0 0 0
Output10
1 second
256 megabytes
['flows', 'graphs', 'shortest paths', '*2300']
D. Fools and Foolproof Roadstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country cons...
Input9 6 2 21 2 23 2 14 6 201 3 87 8 35 7 2
OutputYES9 51 9
1 second
256 megabytes
['data structures', 'dfs and similar', 'dsu', 'graphs', 'greedy', '*2100']
C. Insertion Sorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already writ...
Input54 0 3 1 2
Output3 2
2 seconds
256 megabytes
['data structures', 'dp', 'implementation', 'math', '*1900']
B. Petya and Staircasestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the ...
Input10 52 4 8 3 6
OutputNO
1 second
256 megabytes
['implementation', 'sortings', '*1100']
A. Two Semiknights Meettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the righ...
Input2......................#.K..##..#.......#...##..#......#.K.........................#.......#..#....####.....##...............K#K#
OutputYESNO
1 second
256 megabytes
['greedy', 'math', '*1500']
B. Levko and Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevko loves permutations very much. A permutation of length n is a sequence of distinct positive integers, each is at most n.Let’s assume that value gcd(a, b) shows the greatest common divisor of...
Input4 2
Output2 4 3 1
1 second
256 megabytes
['constructive algorithms', 'math', 'number theory', '*1200']
A. Levko and Tabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals ...
Input2 4
Output1 33 1
1 second
256 megabytes
['constructive algorithms', 'implementation', '*800']
E. Levko and Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevko loves sports pathfinding competitions in his city very much. In order to boost his performance, Levko spends his spare time practicing. The practice is a game.The city consists of n intersections...
Input4 1 31 3 43 2 21 2 1 32 4 1 33 4 1 3
OutputWIN1 1 3
2 seconds
256 megabytes
['graphs', 'greedy', 'shortest paths', '*2800']
D. Levko and Setstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevko loves all sorts of sets very much.Levko has two arrays of integers a1, a2, ... , an and b1, b2, ... , bm and a prime number p. Today he generates n sets. Let's describe the generation process for...
Input1 1 725
Output3
3 seconds
256 megabytes
['number theory', '*2600']
C. Levko and Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevko loves strings of length n, consisting of lowercase English letters, very much. He has one such string s. For each string t of length n, Levko defines its beauty relative to s as the number of p...
Input2 2yz
Output26
1 second
256 megabytes
['combinatorics', 'dp', '*2500']
B. Levko and Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all.Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculate...
Input5 24 7 4 7 4
Output0
2 seconds
256 megabytes
['binary search', 'dp', '*2000']
A. Levko and Array Recoverytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is o...
Input4 51 2 3 12 1 2 82 3 4 71 1 3 32 3 4 8
OutputYES4 7 4 7
1 second
256 megabytes
['greedy', 'implementation', '*1700']
E. Neatnesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSimon loves neatness. So before he goes to bed, Simon wants to complete all chores in the house.Simon's house looks like a rectangular table consisting of n rows and n columns from above. All rows of the tab...
Input3 1 11 0 00 1 01 0 0
OutputYESD1R2L2D2UU2
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', '*2400']
D. Pair of Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSimon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≀ l ≀ r ≀ n), such that the following conditions hold: there is integer...
Input54 6 9 3 6
Output1 32
2 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'math', 'two pointers', '*2000']
C. Prime Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSimon has a prime number x and an array of non-negative integers a1, a2, ..., an.Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common ...
Input2 22 2
Output8
1 second
256 megabytes
['math', 'number theory', '*1900']
B. Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,...
Input1 0
Output1 2
1 second
256 megabytes
['constructive algorithms', 'dp', 'math', '*1400']
A. Tabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSimon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns β€” from left to right starting from one. We'll represent...
Input3 30 0 00 1 00 0 0
Output4
1 second
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*1000']
E. Dima and Kickstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima is a good person. In fact, he's great. But all good things come to an end...Seryozha is going to kick Dima just few times.. For this reason he divides the room into unit squares. Now the room is a...
Input5 51 1 1 1 11 0 0 0 11 0 0 0 11 0 0 0 11 1 1 1 1
Output2 4
2 seconds
256 megabytes
['brute force', 'dsu', 'graphs', 'implementation', '*2300']
D. Dima and Harestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very...
Input41 2 3 44 3 2 10 1 1 0
Output13
2 seconds
256 megabytes
['dp', 'greedy', '*1800']
C. Dima and Containerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is...
Input100101201230
Output0pushStack1 popStackpushStackpushQueue2 popStack popQueuepushStackpushQueuepushFront3 popStack popQueue popFront
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*2000']
B. Dima and Text Messagestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSeryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to c...
Input3iloveyou<3i<3love<23you<3
Outputyes
2 seconds
256 megabytes
['brute force', 'strings', '*1500']
A. Dima and Continuous Linetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homew...
Input40 10 5 15
Outputyes
2 seconds
256 megabytes
['brute force', 'implementation', '*1400']
B. Flag Daytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland, there is the national holiday coming β€” the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several ...
Input7 31 2 31 4 54 6 7
Output1 2 3 3 2 2 1
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1400']
A. Group of Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into ...
Input53 4 3 2 16 8
Output3
1 second
256 megabytes
['brute force', 'greedy', 'implementation', '*1000']
E. Xenia and String Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia the coder went to The Olympiad of Informatics and got a string problem. Unfortunately, Xenia isn't fabulous in string algorithms. Help her solve the problem.String s is a sequence of cha...
Inputzzz
Output12
1 second
256 megabytes
['dp', 'hashing', 'implementation', 'string suffix structures', 'strings', '*3000']
D. Bags and Coinstime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen you were a child you must have been told a puzzle of bags and coins. Anyway, here's one of its versions: A horse has three bags. The first bag has one coin, the second bag has one coin and the t...
Input3 31 3 1
Output1 01 2 3 11 0
2.5 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'dp', 'greedy', '*2700']
C. Compartmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (...
Input51 2 2 4 3
Output2
1 second
256 megabytes
['combinatorics', 'constructive algorithms', 'greedy', 'implementation', '*2100']
B. Xenia and Hammingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia is an amateur programmer. Today on the IT lesson she learned about the Hamming distance.The Hamming distance between two strings s = s1s2... sn and t = t1t2... tn of equal length n is value . R...
Input100 10aaaaaaaaaaa
Output0
1 second
256 megabytes
['implementation', 'math', '*1900']
A. Knight Tournamenttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.As ...
Input4 31 2 11 3 31 4 4
Output3 1 4 0
3 seconds
256 megabytes
['data structures', 'dsu', '*1500']
B. Vasya and Public Transporttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the tro...
Input1 3 7 192 32 54 4 4
Output12
1 second
256 megabytes
['greedy', 'implementation', '*1100']
A. Vasya and Digital Roottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 +...
Input4 4
Output5881
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1100']
E. Lucky Number Representationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe know that lucky digits are digits 4 and 7, however Vasya's got another favorite digit 0 and he assumes it also is lucky! Lucky numbers are such non-negative integers whose decimal recor...
Input54217444751
Output7 7 7 7 7 7-1400 0 40 0 4 07 0 0 0 0 047 4 0 0 0 0
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'dp', '*2200']
D. Transferring Pyramidtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya and Petya are using an interesting data storing structure: a pyramid.The pyramid consists of n rows, the i-th row contains i cells. Each row is shifted half a cell to the left relative to t...
Input4 53 13 34 14 34 4
Output10
3 seconds
256 megabytes
['dp', '*2900']
C. Vasya and Beautiful Arraystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n.Vasya thinks that an array's beauty is the greatest common divisor of all its ele...
Input6 13 6 10 12 13 16
Output3
1 second
256 megabytes
['brute force', 'dp', 'number theory', '*2100']
B. Game with Stringstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputGiven an n × n table T consisting of lowercase English letters. We'll consider some string s good if the table contains a correct path corresponding to the given string. In other words, good strings ...
Input2abcd
OutputDRAW
1 second
512 megabytes
['bitmasks', 'dp', 'games', '*2400']
A. Vasya and Robottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight...
Input3 4 4 19 142 3 99
Output576
1 second
256 megabytes
['brute force', 'greedy', 'math', '*1500']
E. Antichaintime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1)Β modΒ n, and ...
Input001
Output1
1 second
256 megabytes
['dp', 'graph matchings', 'greedy', '*2200']
D. Queuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.Each second all boys that stand right in fr...
InputMFM
Output1
1 second
256 megabytes
['constructive algorithms', 'dp', '*2000']
C. Find Maximumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera has array a, consisting of n integers a0, a1, ..., an - 1, and function f(x), taking an integer from 0 to 2n - 1 as its single argument. Value f(x) is calculated by formula , where value bit(i) equ...
Input23 810
Output3
1 second
256 megabytes
['implementation', 'math', 'number theory', '*1600']
B. Two Heapstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera has 2Β·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes....
Input110 99
Output12 1
1 second
256 megabytes
['combinatorics', 'constructive algorithms', 'greedy', 'implementation', 'math', 'sortings', '*1900']
A. Dominotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera has got n domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants ...
Input24 26 4
Output0
1 second
256 megabytes
['implementation', 'math', '*1200']
B. Jeff and Periodstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions ho...
Input12
Output12 0
1 second
256 megabytes
['implementation', 'sortings', '*1300']
A. Jeff and Digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 ...
Input45 0 5 0
Output0
1 second
256 megabytes
['brute force', 'implementation', 'math', '*1000']
E. Jeff and Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday.Jeff hates inversions in sequences. An inve...
Input22 1
Output0
2 seconds
256 megabytes
['greedy', '*2200']
D. Jeff and Removing Periodstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCosider a sequence, consisting of n integers: a1, a2, ..., an. Jeff can perform the following operation on sequence a: take three integers v, t, k (1 ≀ v, t ≀ n;Β 0 ≀ k;Β v + tk ≀ n), such th...
Input52 2 1 1 251 51 12 21 32 3
Output21122
3 seconds
256 megabytes
['data structures', '*2700']