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 |
|---|---|---|---|---|---|
B. Unnatural Conditionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that s(a) \ge n, s(b) \ge n, s(a + b) \le m. Inp... | Input6 5 | Output6 7 | 1 second | 256 megabytes | ['constructive algorithms', 'math', '*1200'] |
A. Find Squaretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a table of size n \times m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was p... | Input5 6WWBBBWWWBBBWWWBBBWWWWWWWWWWWWW | Output2 4 | 1 second | 256 megabytes | ['implementation', '*800'] |
G. X-mouse in the Campustime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe campus has m rooms numbered from 0 to m - 1. Also the x-mouse lives in the campus. The x-mouse is not just a mouse: each second x-mouse moves from room i to the room i \cdot x \mod{m} (in ... | Input4 3 | Output3 | 1.5 seconds | 256 megabytes | ['bitmasks', 'math', 'number theory', '*2600'] |
F. Session in BSUtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp studies in Berland State University. Soon he will have to take his exam. He has to pass exactly n exams.For the each exam i there are known two days: a_i — day of the first opportunity to pass... | Input21 51 7 | Output5 | 4 seconds | 256 megabytes | ['binary search', 'dfs and similar', 'dsu', 'graph matchings', 'graphs', '*2400'] |
E. Inverse Coloringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a square board, consisting of n rows and n columns. Each tile in it should be colored either white or black.Let's call some coloring beautiful if each pair of adjacent rows are either t... | Input1 1 | Output0 | 2 seconds | 256 megabytes | ['combinatorics', 'dp', 'math', '*2100'] |
D. Mouse Hunttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMedicine faculty of Berland State University has just finished their admission campaign. As usual, about 80\% of applicants are girls and majority of them are going to live in the university dormitory for ... | Input51 2 3 2 101 3 4 3 3 | Output3 | 2 seconds | 256 megabytes | ['dfs and similar', 'graphs', '*1700'] |
C. Minimum Value Rectangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n sticks of the given lengths.Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must... | Input347 2 2 782 8 1 4 8 2 1 555 5 5 5 5 | Output2 7 7 22 2 1 15 5 5 5 | 2 seconds | 256 megabytes | ['greedy', '*1600'] |
B. Numbers on the Chessboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a chessboard of size n \times n. It is filled with numbers from 1 to n^2 in the following way: the first \lceil \frac{n^2}{2} \rceil numbers from 1 to \lceil \frac{n^2}{2} \rcei... | Input4 51 14 44 33 22 4 | Output1816134 | 1 second | 256 megabytes | ['implementation', 'math', '*1200'] |
A. Palindromic Twisttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of n lowercase Latin letters. n is even.For each position i (1 \le i \le n) in string s you are required to change the letter on this position either to the previ... | Input56abccba2cf4adfa8abaazaba2ml | OutputYESNOYESNONO | 2 seconds | 256 megabytes | ['implementation', 'strings', '*1000'] |
G. Company Acquisitionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily m... | Input3-1 -1 -1 | Output3 | 1 second | 256 megabytes | ['constructive algorithms', 'math', '*3200'] |
F. Disjoint Trianglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA point belongs to a triangle if it lies inside the triangle or on one of its sides. Two triangles are disjoint if there is no point on the plane that belongs to both triangles.You are given n poin... | Input61 12 24 64 57 25 3 | Output6 | 2 seconds | 256 megabytes | ['geometry', '*2700'] |
E. Colored Cubestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya passes all exams! Despite expectations, Vasya is not tired, moreover, he is ready for new challenges. However, he does not want to work too hard on difficult problems.Vasya remembered that he has a... | Input2 11 12 2 | Output21 1 1 21 2 2 2 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', 'matrices', '*2700'] |
D. Recovering BSTtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up th... | Input63 6 9 18 36 108 | OutputYes | 1 second | 256 megabytes | ['brute force', 'dp', 'math', 'number theory', 'trees', '*2100'] |
C. Plasticine zebratime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIs there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this a... | Inputbwwwbwwbw | Output5 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*1600'] |
B. Weakened Common Divisortime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD)... | Input317 1815 2412 15 | Output6 | 1.5 seconds | 256 megabytes | ['brute force', 'greedy', 'number theory', '*1600'] |
A. Doggo Recoloringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPanic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are deno... | Input6aabddc | OutputYes | 1 second | 256 megabytes | ['implementation', 'sortings', '*900'] |
G. Piscestime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA group of researchers are studying fish population in a natural system of lakes and rivers. The system contains n lakes connected by n - 1 rivers. Each river has integer length (in kilometers) and can be trav... | Input41 2 11 3 11 4 151 1 21 1 32 2 13 1 43 1 2 | Output2 | 5 seconds | 512 megabytes | ['data structures', 'flows', 'trees', '*3400'] |
F. Mobile Phone Networktime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are managing a mobile phone network, and want to offer competitive prices to connect a network.The network has n nodes.Your competitor has already offered some connections between some nodes,... | Input4 3 61 23 41 32 3 33 1 41 2 44 2 84 3 84 1 10 | Output14 | 3 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', 'trees', '*2600'] |
E. Down or Righttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Bob lives in a square grid of size n \times n, with rows numbered 1 through n from top to bottom, and columns numbered 1 through n from left to right. Every cell is either ... | Input4 YES NO YES YES | Output ? 1 1 4 4 ? 1 2 4 3 ? 4 1 4 4 ? 1 4 4 4 ! RDRRDD | 1 second | 256 megabytes | ['constructive algorithms', 'interactive', 'matrices', '*2100'] |
D. Array Restorationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInitially there was an array a consisting of n integers. Positions in it are numbered from 1 to n.Exactly q queries were performed on the array. During the i-th query some segment (l_i, r_i) (1 \le l... | Input4 31 0 2 3 | OutputYES1 2 2 3 | 1 second | 256 megabytes | ['constructive algorithms', 'data structures', '*1700'] |
C. Bracket Subsequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting ch... | Input6 4()(()) | Output()() | 2 seconds | 256 megabytes | ['greedy', '*1200'] |
B. Pair of Toystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTanechka is shopping in the toy shop. There are exactly n toys in the shop for sale, the cost of the i-th toy is i burles. She wants to choose two toys in such a way that their total cost is k burles. How... | Input8 5 | Output2 | 1 second | 256 megabytes | ['math', '*1000'] |
A. Single Wildcard Pattern Matchingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t. The string s consists of lowercase Latin letters and at most one wildcard character '*', the string t consists only of lowercase Latin letters. The l... | Input6 10code*scodeforces | OutputYES | 1 second | 256 megabytes | ['brute force', 'implementation', 'strings', '*1200'] |
B. Badgetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these ... | Input32 3 2 | Output2 2 3 | 1 second | 256 megabytes | ['brute force', 'dfs and similar', 'graphs', '*1000'] |
A. New Building for SIStime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is impor... | Input3 6 2 3 31 2 1 31 4 3 41 2 2 3 | Output142 | 1 second | 256 megabytes | ['math', '*1000'] |
E. Raining seasontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBy the year 3018, Summer Informatics School has greatly grown. Hotel «Berendeetronik» has been chosen as a location of the school. The camp consists of n houses with n-1 pathways between them. It is po... | Input5 101 2 0 1001 3 0 1001 4 10 801 5 20 0 | Output200 200 200 210 220 230 260 290 320 350 | 3 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'trees', '*3200'] |
D. Large Triangletime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a strange peculiarity: if you connect the cities of Rostov, Taganrog and Shakhty, peculiarly, you get a triangle«Unbelievable But True»Students from many different parts of Russia and abroad c... | Input3 70 03 00 4 | OutputNo | 3 seconds | 256 megabytes | ['binary search', 'geometry', 'sortings', '*2700'] |
C. Sergey's problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSergey just turned five years old! When he was one year old, his parents gave him a number; when he was two years old, his parents gave him an array of integers. On his third birthday he received a s... | Input5 41 22 32 42 5 | Output41 3 4 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'graphs', '*3000'] |
B. The hattime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a ci... | Input822 | Output? 4? 8! 4 | 1 second | 256 megabytes | ['binary search', 'interactive', '*2000'] |
A. Electionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.Ele... | Input1 21 100 | Output0 | 2 seconds | 256 megabytes | ['brute force', 'greedy', '*1700'] |
H. The Filmstime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn "The Man in the High Castle" world, there are m different film endings. Abendsen owns a storage and a shelf. At first, he has n ordered films on the shelf. In the i-th month he will do: Empty the storage... | Input6 4 41 2 3 4 4 41 4 01 3 21 4 21 5 2 | Output626730121504860 | 5 seconds | 512 megabytes | ['brute force', '*3300'] |
G. The Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAbendsen assigned a mission to Juliana. In this mission, Juliana has a rooted tree with n vertices. Vertex number 1 is the root of this tree. Each vertex can be either black or white. At first, all vertices ... | Input8 101 2 1 2 5 4 51 23 23 11 11 13 53 73 42 23 5 | Outputblackwhiteblackwhiteblackwhite | 3 seconds | 256 megabytes | ['data structures', '*3200'] |
F. The Neutral Zonetime limit per test5 secondsmemory limit per test16 megabytesinputstandard inputoutputstandard outputNotice: unusual memory limit!After the war, destroyed cities in the neutral zone were restored. And children went back to school.The war changed the world, as well as education. In those hard days, a ... | Input12 0 0 1 0 | Output63 | 5 seconds | 16 megabytes | ['brute force', 'math', '*2500'] |
E. The Supersonic Rockettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter the war, the supersonic rocket became the most common public transportation.Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n... | Input3 40 00 22 00 22 22 01 1 | OutputYES | 1 second | 256 megabytes | ['geometry', 'hashing', 'strings', '*2400'] |
D. The Wutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputChildan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to as... | Input2 4 540 200101101100 2000 4011 2011 4011 60 | Output24234 | 2 seconds | 256 megabytes | ['bitmasks', 'brute force', 'data structures', '*1900'] |
C. The Phone Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!The only thing Mrs. Smith remembered was that any permutation of n can be a secret phone number. Only th... | Input4 | Output3 4 1 2 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', '*1600'] |
B. The Bitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers a and b of length n. How many different ways of swapping two digits in a (... | Input50101111001 | Output4 | 2 seconds | 256 megabytes | ['implementation', 'math', '*1200'] |
A. The Ranktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of r... | Input5100 98 100 100100 100 100 100100 100 99 9990 99 90 100100 98 60 99 | Output2 | 1 second | 256 megabytes | ['implementation', '*800'] |
G. Appropriate Teamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince next season are coming, you'd like to form a team from two or three participants. There are n candidates, the i-th candidate has rank a_i. But you have weird requirements for your teammates: if... | Input12 2 21 2 3 4 5 6 7 8 9 10 11 12 | Output12 | 2 seconds | 256 megabytes | ['bitmasks', 'math', 'number theory', '*2700'] |
F. Road Projectstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in the country of Berland. Some of them are connected by bidirectional roads in such a way that there exists exactly one path, which visits each road no more than once, between every ... | Input7 21 2 182 3 223 4 244 7 242 6 43 5 121100 | Output8388 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'trees', '*2600'] |
E. Rest In The Shadestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a light source on the plane. This source is so small that it can be represented as point. The light source is moving from point (a, s_y) to the (b, s_y) (s_y < 0) with speed equal to 1 uni... | Input-3 1 622 46 753 11 36 16 47 6 | Output5.0000000000000003.0000000000000000.0000000000000001.5000000000000002.000000000000000 | 2 seconds | 256 megabytes | ['binary search', 'geometry', '*2400'] |
D. Vasya And The Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m colu... | Input2 32 95 3 13 | OutputYES3 4 56 7 8 | 2 seconds | 256 megabytes | ['constructive algorithms', 'flows', 'math', '*1800'] |
C. Vasya And The Mushroomstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows h... | Input31 2 36 5 4 | Output70 | 2 seconds | 256 megabytes | ['dp', 'implementation', '*1800'] |
B. Segment Occurrencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t, both consisting only of lowercase Latin letters.The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, \dots, s_r without cha... | Input10 3 4codeforcesfor1 33 105 65 7 | Output0101 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*1300'] |
A. Death Notetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook... | Input3 53 7 9 | Output0 2 1 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'math', '*900'] |
F. Bracket Substringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a bracket sequence s (not necessarily a regular one). A bracket sequence is a string containing only characters '(' and ')'.A regular bracket sequence is a bracket sequence that can be ... | Input5()))() | Output5 | 1 second | 256 megabytes | ['dp', 'strings', '*2300'] |
E2. Stars Drawing (Hard Edition)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a... | Input6 8....*......**.....*****....**.......*........... | Output33 4 13 5 23 5 1 | 3 seconds | 256 megabytes | ['binary search', 'dp', 'greedy', '*1900'] |
E1. Stars Drawing (Easy Edition)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a... | Input6 8....*......**.....*****....**.......*........... | Output33 4 13 5 23 5 1 | 3 seconds | 256 megabytes | ['brute force', 'dp', 'greedy', '*1700'] |
D. Walking Between Housestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n houses in a row. They are numbered from 1 to n in order from left to right. Initially you are in the house 1.You have to perform k moves to other house. In one move you go from your... | Input10 2 15 | OutputYES10 4 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', '*1600'] |
C. Songs Compressiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan has n songs on his phone. The size of the i-th song is a_i bytes. Ivan also has a flash drive which can hold at most m bytes in total. Initially, his flash drive is empty.Ivan wants to copy all ... | Input4 2110 87 43 15 4 | Output2 | 1 second | 256 megabytes | ['sortings', '*1100'] |
B. Obtaining the Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t. Both strings have length n and consist of lowercase Latin letters. The characters in the strings are numbered from 1 to n.You can successively perform the follow... | Input6abcdefabdfec | Output43 5 4 5 | 1 second | 256 megabytes | ['implementation', '*1200'] |
A. Points in Segmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of n segments on the axis Ox, each segment has integer endpoints between 1 and m inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is char... | Input3 52 21 25 5 | Output23 4 | 1 second | 256 megabytes | ['implementation', '*800'] |
B. Andtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an array with n elements a1, a2, ..., an and the number x.In one operation you can select some i (1 ≤ i ≤ n) and replace element ai with ai & x, where & denotes the bitwise and operation.You want the arra... | Input4 31 2 3 7 | Output1 | 1 second | 256 megabytes | ['greedy', '*1200'] |
A. Piles With Stonestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a beautiful garden of stones in Innopolis.Its most beautiful place is the n piles with stones numbered from 1 to n.EJOI participants have visited this place twice. When they first visited it... | Input51 2 3 4 52 1 4 3 5 | OutputYes | 1 second | 256 megabytes | ['math', '*800'] |
F. Passportstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGleb is a famous competitive programming teacher from Innopolis. He is planning a trip to N programming camps in the nearest future. Each camp will be held in a different country. For each of them, Gleb nee... | Input2 13 1 16 1 1 | OutputYES1 11 4 | 2 seconds | 512 megabytes | ['dp', 'implementation', '*3400'] |
E. Cycle sorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n positive integers a_1, a_2, \dots, a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, \dots, i_k (1 \le i_j \le n) and m... | Input5 53 2 3 1 1 | Output151 4 2 3 5 | 2 seconds | 256 megabytes | ['dsu', 'math', '*3100'] |
D. AB-Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are two strings s and t, consisting only of letters a and b. You can make the following operation several times: choose a prefix of s, a prefix of t and swap them. Prefixes can be empty, also a prefix... | Inputbabbb | Output21 01 3 | 1 second | 256 megabytes | ['constructive algorithms', 'strings', '*2800'] |
C. Hillstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputWelcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlasting city construction. From the window in your room, you see the sequence of n hills, where i-th of them has height ai... | Input51 1 1 1 1 | Output1 2 2 | 1 second | 512 megabytes | ['dp', '*1900'] |
B. Chemical tabletime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputInnopolis University scientists continue to investigate the periodic table. There are n·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be descri... | Input2 2 31 22 22 1 | Output0 | 1 second | 512 megabytes | ['constructive algorithms', 'dfs and similar', 'dsu', 'graphs', 'matrices', '*1900'] |
A. Photo of The Skytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.Strictly speaking, it m... | Input44 1 3 2 3 2 1 3 | Output1 | 1 second | 256 megabytes | ['brute force', 'implementation', 'math', 'sortings', '*1500'] |
B. Planning The Expeditiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNatasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant.The warehouse has m daily food packages. Each package has some food ty... | Input4 101 5 2 1 1 1 2 5 7 2 | Output2 | 1 second | 256 megabytes | ['binary search', 'brute force', 'implementation', '*1200'] |
A. Stagestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNatasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by ... | Input5 3xyabd | Output29 | 1 second | 256 megabytes | ['greedy', 'implementation', 'sortings', '*900'] |
F. Treetime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Main Martian Tree grows on Mars. It is a binary tree (a rooted tree, with no more than two sons at each vertex) with n vertices, where the root vertex has the number 1. Its fruits are the Main Martian Fruits... | Input3 21 21 3 | Output13 | 7 seconds | 256 megabytes | ['fft', 'graphs', 'trees', '*3400'] |
E. Storetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNatasha was already going to fly back to Earth when she remembered that she needs to go to the Martian store to buy Martian souvenirs for her friends.It is known, that the Martian year lasts x_{max} months, mon... | Input10 10 10 3 1 32 6 24 2 46 4 69 9 93 3 310 10 108 8 8 | OutputCORRECTOPENCLOSEDUNKNOWN | 2 seconds | 256 megabytes | ['data structures', '*2700'] |
D. Mars rovertime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNatasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex 1, in ... | Input10AND 9 4IN 1IN 1XOR 6 5AND 3 7IN 0NOT 10IN 1IN 1AND 2 8 | Output10110 | 5 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'implementation', 'trees', '*2000'] |
C. Bordertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAstronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. N... | Input2 812 20 | Output20 4 | 1 second | 256 megabytes | ['number theory', '*1800'] |
B. Rockettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to ... | Input5 21-1-110 | Output12453 | 1 second | 256 megabytes | ['binary search', 'interactive', '*1800'] |
A. Flytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNatasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natas... | Input21211 87 5 | Output10.0000000000 | 1 second | 256 megabytes | ['binary search', 'math', '*1500'] |
G. Allowed Letterstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the comp... | Inputbedefead52 e1 dc5 b7 ef6 ef | Outputdeadbeef | 2 seconds | 256 megabytes | ['bitmasks', 'flows', 'graph matchings', 'graphs', 'greedy', '*2400'] |
F. Dominant Indicestime limit per test4.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a rooted undirected tree consisting of n vertices. Vertex 1 is the root.Let's denote a depth array of vertex x as an infinite sequence [d_{x, 0}, d_{x, 1}, d_{x, 2}, \dots], where d_{... | Input41 22 33 4 | Output0000 | 4.5 seconds | 512 megabytes | ['data structures', 'dsu', 'trees', '*2300'] |
E. Intercity Travellingtime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLeha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.The path from Moscow to Saratov can be represented as a straight l... | Input21 2 | Output5 | 1.5 seconds | 256 megabytes | ['combinatorics', 'math', 'probabilities', '*2000'] |
D. Relatively Prime Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) \in E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between so... | Input5 6 | OutputPossible2 53 25 13 44 15 4 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'graphs', 'greedy', 'math', '*1700'] |
C. Annoying Presenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice got an array of length n as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided ... | Input2 3-1 30 0-1 -4 | Output-2.500000000000000 | 2 seconds | 256 megabytes | ['greedy', 'math', '*1700'] |
B. Minimum Ternary Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a ternary string (it is a string which consists only of characters '0', '1' and '2').You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10"... | Input100210 | Output001120 | 1 second | 256 megabytes | ['greedy', 'implementation', '*1400'] |
A. Game Shoppingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaxim wants to buy some games at the local game shop. There are n games in the shop, the i-th game costs c_i.Maxim has a wallet which can be represented as an array of integers. His wallet contains m bil... | Input5 42 4 5 2 45 3 4 6 | Output3 | 1 second | 256 megabytes | ['implementation', '*800'] |
B. Turn the Rectanglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that... | Input33 44 63 5 | OutputYES | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*1000'] |
A. Romajitime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.In Berlanese, there has to be ... | Inputsumimasen | OutputYES | 2 seconds | 256 megabytes | ['implementation', 'strings', '*900'] |
E. Mini Metrotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a simplified version of a "Mini Metro" game, there is only one subway line, and all the trains go in the same direction. There are n stations on the line, a_i people are waiting for the train at the i-t... | Input3 3 102 4 103 3 94 2 8 | Output2 | 2 seconds | 256 megabytes | ['dp', '*3400'] |
D. Antstime limit per test3 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputThere is a tree with n vertices. There are also m ants living on it. Each ant has its own color. The i-th ant has two favorite pairs of vertices: (a_i, b_i) and (c_i, d_i). You need to tell if it is possible to ... | Input61 23 14 15 26 232 6 3 41 6 6 51 4 5 2 | OutputYES212 | 3 seconds | 768 megabytes | ['2-sat', 'data structures', 'trees', '*3200'] |
C. Guess two numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Vasya and Vitya play a game. Vasya thought of two integers a and b from 1 to n and Vitya tries to guess them. Each round he tells Vasya two numbers x and y from 1 to n... | Input533210 | Output4 33 43 31 52 4 | 2 seconds | 256 megabytes | ['binary search', 'interactive', '*3000'] |
B. Pave the Parallelepipedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rectangular parallelepiped with sides of positive integer lengths A, B and C. Find the number of different groups of three integers (a, b, c) such that 1\leq a\leq b\leq c and ... | Input41 1 11 6 12 2 2100 100 100 | Output144165 | 2 seconds | 256 megabytes | ['bitmasks', 'brute force', 'combinatorics', 'math', 'number theory', '*2400'] |
A. Reorder the Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand... | Input710 1 1 1 5 5 3 | Output4 | 2 seconds | 256 megabytes | ['combinatorics', 'data structures', 'math', 'sortings', 'two pointers', '*1300'] |
F. Xor-Pathstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a rectangular grid of size n \times m. Each cell has a number written on it; the number on the cell (i, j) is a_{i, j}. Your task is to calculate the number of paths from the upper-left cell (1, 1)... | Input3 3 112 1 57 10 012 6 4 | Output3 | 3 seconds | 256 megabytes | ['bitmasks', 'brute force', 'dp', 'meet-in-the-middle', '*2100'] |
E. Military Problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem you will have to help Berland army with organizing their command delivery system.There are n officers in Berland army. The first officer is the commander of the army, and he does not ... | Input9 61 1 1 3 5 3 5 73 11 53 47 31 81 9 | Output368-194 | 3 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'trees', '*1600'] |
D. Two Strings Swapstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings a and b consisting of lowercase English letters, both of length n. The characters of both strings have indices from 1 to n, inclusive. You are allowed to do the following c... | Input7abacababacabaa | Output4 | 2 seconds | 256 megabytes | ['implementation', '*1700'] |
C. Three Parts of the Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array d_1, d_2, \dots, d_n consisting of n integer numbers.Your task is to split this array into three parts (some of which may be empty) in such a way that each element of th... | Input51 3 1 1 4 | Output5 | 1 second | 256 megabytes | ['binary search', 'data structures', 'two pointers', '*1200'] |
B. Polycarp's Practicetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is practicing his problem solving skill. He has a list of n problems with difficulties a_1, a_2, \dots, a_n, respectively. His plan is to practice for exactly k days. Each day he has to s... | Input8 35 4 2 6 5 1 9 2 | Output203 2 3 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', '*1200'] |
A. Adjacent Replacementstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka got an integer array a of length n as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mis... | Input51 2 4 5 10 | Output1 1 3 5 9 | 1 second | 256 megabytes | ['implementation', '*800'] |
F. Berland and the Shortest Pathstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Berland. Some pairs of cities are connected by roads. All roads are bidirectional. Each road connects two different cities. There is at most one road between a pai... | Input4 4 31 22 31 44 3 | Output211101011 | 5 seconds | 256 megabytes | ['brute force', 'dfs and similar', 'graphs', 'shortest paths', '*2100'] |
E2. Median on Segments (General Case Edition)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer sequence a_1, a_2, \dots, a_n.Find the number of pairs of indices (l, r) (1 \le l \le r \le n) such that the value of median of a_l, a_{l+1}, \dots,... | Input5 41 4 5 60 4 | Output8 | 3 seconds | 256 megabytes | ['sortings', '*2400'] |
E1. Median on Segments (Permutations Edition)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p_1, p_2, \dots, p_n. A permutation of length n is a sequence such that each integer between 1 and n occurs exactly once in the sequence.Find the... | Input5 42 4 5 3 1 | Output4 | 3 seconds | 256 megabytes | ['sortings', '*1800'] |
D. Polycarp and Div 3time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp likes numbers that are divisible by 3.He has a huge number s. Polycarp wants to cut from it the maximum number of numbers that are divisible by 3. To do this, he makes an arbitrary number ... | Input3121 | Output2 | 3 seconds | 256 megabytes | ['dp', 'greedy', 'number theory', '*1500'] |
C. Summarize to the Power of Twotime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence a_1, a_2, \dots, a_n is called good if, for each element a_i, there exists an element a_j (i \ne j) such that a_i+a_j is a power of two (that is, 2^d for some non-negative int... | Input64 7 1 5 4 9 | Output1 | 3 seconds | 256 megabytes | ['brute force', 'greedy', 'implementation', '*1300'] |
B. Delete from the Lefttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by 1... | Inputtestwest | Output2 | 1 second | 256 megabytes | ['brute force', 'implementation', 'strings', '*900'] |
A. Tanya and Stairwaystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every nu... | Input71 2 3 1 2 3 4 | Output23 4 | 1 second | 256 megabytes | ['implementation', '*800'] |
F. Sonya and Bitwise ORtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSonya has an array a_1, a_2, \ldots, a_n consisting of n integers and also one non-negative integer x. She has to perform m queries of two types: 1 i y: replace i-th element by value y, i.e. to ... | Input4 8 70 3 6 12 1 42 3 41 1 72 1 42 1 32 1 11 3 02 1 4 | Output517414 | 4 seconds | 512 megabytes | ['bitmasks', 'data structures', 'divide and conquer', '*2600'] |
E. Sonya and Ice Creamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSonya likes ice cream very much. She eats it even during programming competitions. That is why the girl decided that she wants to open her own ice cream shops.Sonya lives in a city with n junction... | Input6 21 2 32 3 44 5 24 6 32 4 6 | Output4 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'dp', 'greedy', 'shortest paths', 'trees', '*2400'] |
D. Sonya and Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince Sonya has just learned the basics of matrices, she decided to play with them a little bit.Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one... | Input201 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4 | Output4 52 2 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'implementation', '*2300'] |
C. Sonya and Robotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has pu... | Input51 5 4 1 3 | Output9 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*1400'] |
B. Sonya and Exhibitiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.There are n flowers in... | Input5 31 32 42 5 | Output01100 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', 'math', '*1300'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.