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. The Contesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!This contest consists of n problems, and Pasha solves it... | Input23 421 47 9 | Output7 | 2 seconds | 256 megabytes | ['implementation', '*1100'] |
E. Sagheer and Apple Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: ... | Input32 2 31 1 | Output1 | 2 seconds | 256 megabytes | ['games', 'trees', '*2300'] |
D. Sagheer and Kindergartentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSagheer is working at a kindergarten. There are n children and m different toys. These children use well-defined protocols for playing with the toys: Each child has a lovely set of toys that ... | Input3 3 5 11 12 23 31 22 33 1 | Output3 | 1 second | 256 megabytes | ['dfs and similar', 'graphs', 'implementation', 'trees', '*2700'] |
C. Sagheer and Nubian Markettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered... | Input3 112 3 5 | Output2 11 | 2 seconds | 256 megabytes | ['binary search', 'sortings', '*1500'] |
B. Sagheer, the Hausmeistertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university ... | Input2 200100100 | Output5 | 1 second | 256 megabytes | ['bitmasks', 'brute force', 'dp', '*1600'] |
A. Sagheer and Crossroadstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each ... | Input1 0 0 10 1 0 00 0 1 00 0 0 1 | OutputYES | 1 second | 256 megabytes | ['implementation', '*1200'] |
E. Vladik and Entertaining Flagstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn his spare time Vladik estimates beauty of the flags.Every flag could be represented as the matrix n × m which consists of positive integers.Let's define the beauty of the flag as numb... | Input4 5 41 1 1 1 11 2 2 3 31 1 1 2 54 4 5 5 51 52 51 24 5 | Output6734 | 2 seconds | 256 megabytes | ['data structures', 'dsu', 'graphs', '*2600'] |
D. Vladik and Favorite Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Vladik has favorite game, in which he plays all his free time.Game field could be represented as n × m matrix which consists of cells of three types: «.» — no... | Input4 3...**.F*....1 11 21 31 32 33 34 34 24 13 1 | OutputRLLDUUURRD | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'graphs', 'interactive', '*2100'] |
C. Vladik and Memorable Triptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:Vladik is at initial train station, and now n people (in... | Input64 4 2 5 2 3 | Output14 | 2 seconds | 256 megabytes | ['dp', 'implementation', '*1900'] |
B. Vladik and Complicated Booktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by... | Input5 55 4 3 2 11 5 31 3 12 4 34 4 42 5 3 | OutputYesNoYesYesNo | 2 seconds | 256 megabytes | ['implementation', 'sortings', '*1200'] |
A. Vladik and Courtesytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was les... | Input1 1 | OutputValera | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*800'] |
B. Summer sell-offtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSummer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job i... | Input4 22 13 52 31 5 | Output10 | 1 second | 256 megabytes | ['greedy', 'sortings', '*1300'] |
A. Straight «A»time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNoora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a pr... | Input2 108 9 | Output4 | 1 second | 256 megabytes | ['implementation', 'math', '*900'] |
E. Surprise me!time limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTired of boring dates, Leha and Noora decided to play a game.Leha found a tree with n vertices numbered from 1 to n. We remind you that tree is an undirected graph without cycles. Each vertex v of a tree... | Input31 2 31 22 3 | Output333333338 | 8 seconds | 256 megabytes | ['divide and conquer', 'math', 'number theory', 'trees', '*3100'] |
D. Hitchhiking in the Baltic Statestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLeha and Noora decided to go on a trip in the Baltic States. As you know from the previous problem, Leha has lost his car on the parking of the restaurant. Unfortunately, requests to ... | Input56 61 23 42 21 4 | Output3 | 2 seconds | 256 megabytes | ['data structures', 'dp', '*2900'] |
C. Find a cartime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Le... | Input41 1 1 1 13 2 5 4 51 1 5 5 100001 4 2 5 2 | Output113930 | 4 seconds | 256 megabytes | ['combinatorics', 'divide and conquer', 'dp', '*2600'] |
B. Glad to see you!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. In the output section below you will see the information about flushing the output.On Sunday Leha the hacker took Nura from the house where she lives and went with her... | Input3 2NIETAKNIETAKTAKTAK | Output1 1 21 2 11 1 31 3 11 2 31 3 22 2 3 | 2 seconds | 256 megabytes | ['binary search', 'interactive', '*2200'] |
A. Do you want a date?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLeha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha man... | Input24 7 | Output3 | 2 seconds | 256 megabytes | ['implementation', 'math', 'sortings', '*1500'] |
G. Anthem of Berlandtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.Though there are lots and lots of victories in history of... | Inputwinlose???winl???w??win | Output5 | 3 seconds | 256 megabytes | ['dp', 'strings', '*2300'] |
F. Card Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDigital collectible card games have become very popular recently. So Vova decided to try one of these.Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number c... | Input5 85 5 11 5 44 6 31 12 43 12 1 | Output4 | 2 seconds | 256 megabytes | ['binary search', 'flows', 'graphs', '*2400'] |
E. Selling Souvenirstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for ... | Input1 12 1 | Output0 | 2 seconds | 256 megabytes | ['binary search', 'dp', 'greedy', 'ternary search', '*2300'] |
D. Array Divisiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the fir... | Input31 3 2 | OutputYES | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'implementation', '*1900'] |
C. Tea Partytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + .... | Input2 108 7 | Output6 4 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'sortings', '*1400'] |
B. Average Sleep Timetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days!When Polycarp went to a doctor with his problem, the doctor asked h... | Input3 23 4 7 | Output9.0000000000 | 1 second | 256 megabytes | ['data structures', 'implementation', 'math', '*1300'] |
A. Lucky Yeartime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputApart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000,... | Input4 | Output1 | 1 second | 256 megabytes | ['implementation', '*900'] |
B. T-Shirt Hunttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNot so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.Unfo... | Input239 10880 9889 | Output0 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*1300'] |
A. Is it rated?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIs it rated?Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.Another Codeforces round has been conducted. No two participants have t... | Input63060 30602194 21942876 29032624 26243007 29912884 2884 | Outputrated | 2 seconds | 256 megabytes | ['implementation', 'sortings', '*900'] |
B. 3-palindrometime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.He is too selfish, so for a given n he wants to obtain a string of n charac... | Input2 | Outputaa | 1 second | 256 megabytes | ['constructive algorithms', '*1000'] |
A. Fake NPtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.You are given l and r. For all integers from l to r, inclusive, we wrote down al... | Input19 29 | Output2 | 1 second | 256 megabytes | ['greedy', 'math', '*1000'] |
F. Fake bullionstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn Isart people don't die. There are n gangs of criminals. The i-th gang contains si evil people numerated from 0 to si - 1. Some of these people took part in a big mine robbery and picked one gold bull... | Input2 2 101005 110006 100000 | Output2 | 3 seconds | 512 megabytes | ['combinatorics', 'dfs and similar', 'dp', 'graphs', 'number theory', '*3400'] |
E. The same permutation time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSeyyed and MoJaK are friends of Sajjad. Sajjad likes a permutation. Seyyed wants to change the permutation in a way that Sajjad won't like it. Seyyed thinks more swaps yield more probability to ... | Input3 | OutputNO | 2 seconds | 256 megabytes | ['constructive algorithms', '*3100'] |
D. Expected diameter of a treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha is a good student and one of MoJaK's best friends. He always have a problem to think about. Today they had a talk about the following problem.We have a forest (acyclic undirected gra... | Input3 1 21 33 12 3 | Output-12.0000000000 | 3 seconds | 256 megabytes | ['binary search', 'brute force', 'dfs and similar', 'dp', 'sortings', 'trees', '*2500'] |
C. Ice cream coloringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIsart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?"We have a tree T with n vertices and ... | Input3 31 12 2 31 21 22 3 | Output21 1 2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'greedy', '*2200'] |
B. Minimum number of stepstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have n... | Inputab | Output1 | 1 second | 256 megabytes | ['combinatorics', 'greedy', 'implementation', 'math', '*1400'] |
A. Find Amirtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.There are n schools numerated from 1 to n. One ... | Input2 | Output0 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*1000'] |
G. Periodic RMQ Problemtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of positive integers and q queries to this array. There are two types of queries: 1 l r x — for each index i such that l ≤ i ≤ r set ai = x. 2 l r — find th... | Input3 11 2 332 1 31 1 2 42 1 3 | Output13 | 4 seconds | 512 megabytes | ['data structures', '*2300'] |
F. Coprime Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1.Given an array a consisting of n positive i... | Input31 2 3 | Output5 | 2 seconds | 256 megabytes | ['bitmasks', 'combinatorics', 'number theory', '*2000'] |
E. Roma and Pokertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 vi... | Input3 2L?? | OutputLDL | 2 seconds | 256 megabytes | ['dp', 'graphs', '*2000'] |
D. Magazine Adtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:There are space-separated non-empty words of lowercase and uppercase Latin letters.Th... | Input4garage for sa-le | Output7 | 1 second | 256 megabytes | ['binary search', 'greedy', '*1900'] |
C. Maximal GCDtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.Great... | Input6 3 | Output1 2 3 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*1900'] |
B. Distances to Zerotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in th... | Input92 1 0 3 0 0 3 2 4 | Output2 1 0 1 0 0 1 2 3 | 2 seconds | 256 megabytes | ['constructive algorithms', '*1200'] |
A. Maximal Binary Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagon... | Input2 1 | Output1 0 0 0 | 1 second | 256 megabytes | ['constructive algorithms', '*1400'] |
O. April Fools' Problem (hard)time limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe plans for HC2 are rather far-fetched: we are just over 500 000 days away from HC2 3387, for example, and accordingly we are planning to have a couple hundred thousand problems in that... | Input8 43 8 7 9 9 4 6 82 5 9 4 3 8 9 1 | Output32 | 10 seconds | 256 megabytes | ['binary search', 'data structures', 'flows', '*2900'] |
N. April Fools' Problem (medium)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe marmots need to prepare k problems for HC2 over n days. Each problem, once prepared, also has to be printed.The preparation of a problem on day i (at most one per day) costs ai CHF, ... | Input8 43 8 7 9 9 4 6 82 5 9 4 3 8 9 1 | Output32 | 4 seconds | 256 megabytes | ['binary search', 'flows', 'graphs', '*2400'] |
M. April Fools' Problem (easy)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beaut... | Input8 51 1 1 1 1 1 1 1 | Output5 | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*1200'] |
L. Send the Fool Further! (hard)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHeidi is terrified by your estimate and she found it unrealistic that her friends would collaborate to drive her into debt. She expects that, actually, each person will just pick a rando... | Input30 1 100 2 20 | Output15 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'math', 'trees', '*2400'] |
K. Send the Fool Further! (medium)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThank you for helping Heidi! It is now the second of April, but she has been summoned by Jenny again. The pranks do not seem to end...In the meantime, Heidi has decided that she does n... | Input9 30 1 10 2 11 3 21 4 21 5 22 6 32 7 32 8 3 | Output15 | 2 seconds | 256 megabytes | ['dp', 'trees', '*2100'] |
J. Send the Fool Further! (easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHeidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she susp... | Input40 1 40 2 22 3 3 | Output5 | 1 second | 256 megabytes | ['dfs and similar', 'graphs', 'trees', '*1400'] |
I. Fake News (hard)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow that you have proposed a fake post for the HC2 Facebook page, Heidi wants to measure the quality of the post before actually posting it. She recently came across a (possibly fake) article about t... | Input4aaabcdcccabcc | Output5101412 | 5 seconds | 256 megabytes | ['string suffix structures', '*2300'] |
H. Fake News (medium)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committ... | Input2 | OutputhHheidi Hei | 1 second | 256 megabytes | ['constructive algorithms', 'strings', '*2200'] |
G. Fake News (easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it co... | Inputabcheaibcdi | OutputYES | 1 second | 256 megabytes | ['implementation', 'strings', '*800'] |
D. Marmots (easy)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHeidi is a statistician to the core, and she likes to study the evolution of marmot populations in each of V (1 ≤ V ≤ 100) villages! So it comes that every spring, when Heidi sees the first snowdrops s... | Input292 100 99 109 93 105 103 106 101 99 ... (input is truncated)28 180 147 53 84 80 180 85 8 16 ... (input is truncated) | Outputpoissonuniform | 2 seconds | 256 megabytes | ['math', '*2100'] |
C. Heidi and Library (hard)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe good times at Heidi's library are over. Marmots finally got their internet connections and stopped coming to the library altogether. Not only that, but the bookstore has begun charging ex... | Input4 801 2 2 11 1 1 1 | Output2 | 2 seconds | 256 megabytes | ['flows', '*2600'] |
B. Heidi and Library (medium)time limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.InputSame ... | Input4 1001 2 2 1 | Output2 | 10 seconds | 256 megabytes | ['data structures', 'greedy', '*1800'] |
A. Heidi and Library (easy)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and k... | Input4 801 2 2 1 | Output2 | 2 seconds | 256 megabytes | ['greedy', '*1800'] |
B. Valued Keystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.The output of the function f is anoth... | Inputabaa | Outputba | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', 'strings', '*900'] |
A. Vicious Keyboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTonio has a keyboard with only two letters, "V" and "K".One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at mo... | InputVK | Output1 | 2 seconds | 256 megabytes | ['brute force', '*1100'] |
G. Cut the pietime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady reached the n-th level in Township game, so Masha decided to bake a pie for him! Of course, the pie has a shape of convex n-gon, i.e. a polygon with n vertices.Arkady decided to cut the pie in two ... | Input3 10 00 33 01 1 | Output2.67794504460098710000 | 3 seconds | 256 megabytes | ['binary search', 'data structures', 'geometry', '*3500'] |
F. Beautiful fountains rowstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputButler Ostin wants to show Arkady that rows of odd number of fountains are beautiful, while rows of even number of fountains are not.The butler wants to show Arkady n gardens. Each garden is ... | Input1 52 4 | Output23 | 3 seconds | 256 megabytes | ['data structures', '*3500'] |
E. Aquarium decorationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady and Masha want to choose decorations for thier aquarium in Fishdom game. They have n decorations to choose from, each of them has some cost. To complete a task Arkady and Masha need to choo... | Input4 3 23 2 2 121 221 3 | Output7 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'two pointers', '*2500'] |
D. Field expansiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a p... | Input3 3 2 4 42 5 4 10 | Output1 | 1 second | 256 megabytes | ['brute force', 'dp', 'meet-in-the-middle', '*2100'] |
C. Fountainstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins an... | Input3 7 610 8 C4 3 C5 6 D | Output9 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'implementation', '*1800'] |
B. T-shirt buyingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi i... | Input5300 200 400 500 9111 2 1 2 32 1 3 2 162 3 1 2 1 1 | Output200 400 300 500 911 -1 | 3 seconds | 256 megabytes | ['data structures', 'implementation', '*1400'] |
A. Carrot Cakestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task,... | Input8 6 4 5 | OutputYES | 1 second | 256 megabytes | ['brute force', 'implementation', '*1100'] |
E. Mike and code of a permutationtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMike has discovered a new way to encode permutations. If he has a permutation P = [p1, p2, ..., pn], he will encode it in the following way:Denote by A = [a1, a2, ..., an] a sequence of... | Input62 -1 1 5 -1 4 | Output2 6 1 4 5 3 | 4 seconds | 512 megabytes | ['constructive algorithms', 'data structures', 'graphs', 'sortings', '*3000'] |
D. Mike and distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences ... | Input58 7 4 8 34 2 5 3 7 | Output31 4 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'sortings', '*2400'] |
C. Mike and gcd problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. . Mike wants to change his s... | Input21 1 | OutputYES1 | 2 seconds | 256 megabytes | ['dp', 'greedy', 'number theory', '*1700'] |
B. Mike and stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, ... | Input4xzzwozwoxzzzwoxxzzwo | Output5 | 2 seconds | 256 megabytes | ['brute force', 'dp', 'strings', '*1300'] |
A. Mike and palindrometime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that ... | Inputabccaa | OutputYES | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'strings', '*1000'] |
F. Mice and Holestime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Masha came home and noticed n mice in the corridor of her flat. Of course, she shouted loudly, so scared mice started to run to the holes in the corridor.The corridor can be represeted as a n... | Input4 56 2 8 93 62 13 64 74 7 | Output11 | 1.5 seconds | 256 megabytes | ['data structures', 'dp', 'greedy', 'sortings', '*2600'] |
E. Array Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputa is an array of n positive integers, all of which are not greater than n.You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed ... | Input31 1 131 12 13 1 | Output211 | 2 seconds | 256 megabytes | ['brute force', 'data structures', 'dp', '*2000'] |
D. Broken BSTtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every... | Input315 -1 -110 1 35 -1 -1 | Output2 | 1 second | 256 megabytes | ['data structures', 'dfs and similar', '*2100'] |
C. Minimal stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the f... | Inputcab | Outputabc | 1 second | 256 megabytes | ['data structures', 'greedy', 'strings', '*1700'] |
B. Odd sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence con... | Input4-2 2 -3 1 | Output3 | 1 second | 256 megabytes | ['dp', 'greedy', 'implementation', '*1400'] |
A. k-Factorizationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.InputThe first line contains two integers... | Input100000 2 | Output2 50000 | 2 seconds | 256 megabytes | ['implementation', 'math', 'number theory', '*1100'] |
F. Sequence Recoverytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZane once had a good sequence a consisting of n integers a1, a2, ..., an — but he has lost it.A sequence is said to be good if and only if all of its integers are non-negative and do not exceed 109 ... | Input5 41 1 5 191 2 5 12 5 1001 1 5 100 | OutputYES19 0 0 0 1 | 2 seconds | 256 megabytes | ['bitmasks', 'data structures', 'greedy', '*2800'] |
E. Exam Cheatingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZane and Zane's crush have just decided to date! However, the girl is having a problem with her Physics final exam, and needs your help.There are n questions, numbered from 1 to n. Question i comes befo... | Input6 2 33 1 3 64 1 2 5 6 | Output4 | 2 seconds | 256 megabytes | ['binary search', 'dp', '*2400'] |
D. Police Stationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.Ruling a country is not an easy job. Thieves and terrorists are always ready to rui... | Input6 2 41 61 22 33 44 55 6 | Output15 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'dp', 'graphs', 'shortest paths', 'trees', '*2100'] |
C. Bank Hackingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlthough Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has dec... | Input51 2 3 4 51 22 33 44 5 | Output5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'data structures', 'dp', 'trees', '*1900'] |
B. Find The Bonetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZane the wizard is going to perform a magic show shuffling the cups.There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the tab... | Input7 3 43 4 61 22 55 77 1 | Output1 | 2 seconds | 256 megabytes | ['implementation', '*1300'] |
A. Buying A Housetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house m of a village. There are n houses in that village, lining i... | Input5 1 200 27 32 21 19 | Output40 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*800'] |
G. Replace Alltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor the analyst is at work. He learned about a feature in his text editor called "Replace All". Igor is too bored at work and thus he came up with the following problem:Given two strings x and y which co... | InputA??3 | Output2 | 2 seconds | 256 megabytes | ['combinatorics', 'dp', 'math', '*3400'] |
F. Leha and security systemtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBankopolis, the city you already know, finally got a new bank opened! Unfortunately, its security system is not yet working fine... Meanwhile hacker Leha arrived in Bankopolis and decided to ... | Input5 538 43 4 12 701 1 3 4 82 2 41 4 5 0 81 2 5 8 72 1 5 | Output103207 | 2 seconds | 512 megabytes | ['data structures', '*2800'] |
E. Choosing Carrottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves... | Input41 2 3 5 | Output3 3 5 5 | 2 seconds | 256 megabytes | ['games', 'math', '*2800'] |
D. Labelling Citiestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOleg the bank client lives in Bankopolia. There are n cities in Bankopolia and some pair of cities are connected directly by bi-directional roads. The cities are numbered from 1 to n. There are a tot... | Input4 41 21 31 43 4 | OutputYES2 3 1 1 | 3 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'hashing', '*2400'] |
C. Naming Companytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company... | Inputtinkoffzscoder | Outputfzfsirk | 2 seconds | 256 megabytes | ['games', 'greedy', 'sortings', '*1800'] |
B. Cutting Carrottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and th... | Input3 2 | Output1.154700538379 1.632993161855 | 2 seconds | 256 megabytes | ['geometry', 'math', '*1200'] |
A. Bank Robberytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.Oleg the bank client loves money (who doesn't), and decides to take advantage of this f... | Input5 3 784 7 5 5 3 6 2 8 | Output4 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*800'] |
G. Oleg and chesstime limit per test6.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOleg the bank client solves an interesting chess problem: place on n × n chessboard the maximum number of rooks so that they don't beat each other. Of course, no two rooks can share the same cell.Rem... | Input551 1 2 11 3 1 54 1 5 52 5 2 53 2 3 5 | Output3 | 6.5 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'flows', 'graph matchings', '*3400'] |
F. Julia the snailtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAfter hard work Igor decided to have some rest.He decided to have a snail. He bought an aquarium with a slippery tree trunk in the center, and put a snail named Julia into the aquarium.Igor noticed th... | Input841 23 42 56 751 21 41 62 76 8 | Output22557 | 2 seconds | 512 megabytes | ['data structures', 'divide and conquer', 'dp', '*3000'] |
E. Problem of officestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEarlier, when there was no Internet, each bank had a lot of offices all around Bankopolis, and it caused a lot of problems. Namely, each day the bank had to collect cash from all the offices.Once O... | Input52 3 4 51 1 1 1 | OutputYES | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'dp', 'trees', '*2900'] |
D. Presents in Bankopolistime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBankopolis is an incredible city in which all the n crossroads are located on a straight line and numbered from 1 to n along it. On each crossroad there is a bank office.The crossroads are conn... | Input7 441 6 26 2 22 4 22 7 1 | Output6 | 2 seconds | 256 megabytes | ['dp', 'graphs', 'shortest paths', '*2100'] |
C. Mice problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them.The desk can be considered as an infinite pl... | Input47 7 9 83 5 7 57 5 2 43 3 7 86 6 3 2 | Output0.57142857142857139685 | 2 seconds | 256 megabytes | ['geometry', 'implementation', 'math', 'sortings', '*2300'] |
B. Igor and his way to worktime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWoken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the road... | Input5 5..S..****.T....****...... | OutputYES | 3 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'implementation', 'shortest paths', '*1600'] |
A. Oleg and sharestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each se... | Input3 312 9 15 | Output3 | 1 second | 256 megabytes | ['implementation', 'math', '*900'] |
F. Mages and Monsterstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.Vova's character can learn new spells during the gam... | Input3 1001 4 92 19 492 19 49 | OutputYESNO | 2 seconds | 256 megabytes | ['data structures', 'geometry', '*3100'] |
E. Colored Ballstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains ai balls, all of which have color i. You have to write a program that will divide all balls into sets... | Input34 7 8 | Output5 | 1 second | 256 megabytes | ['greedy', 'math', 'number theory', '*2500'] |
D. Paths in a Complete Binary Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputT is a complete binary tree consisting of n vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has... | Input15 24UURL8LRLLLLLLLL | Output105 | 3 seconds | 256 megabytes | ['bitmasks', 'trees', '*1900'] |
C. Divide by Threetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as... | Input1033 | Output33 | 1 second | 256 megabytes | ['dp', 'greedy', 'math', 'number theory', '*2000'] |
B. Counting-out Rhymetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputn children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in ... | Input7 510 4 11 4 1 | Output4 2 5 6 1 | 1 second | 256 megabytes | ['implementation', '*1300'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.