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
E. Olympic Gamestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem was deleted from the contest, because it was used previously at another competition.InputOutputExamplesInput1 11 2 100Output6
Input1 11 2 100
Output6
2 seconds
256 megabytes
['math', '*2500']
D. Roman and Numberstime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRoman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, ...
Input104 2
Output3
4 seconds
512 megabytes
['bitmasks', 'brute force', 'combinatorics', 'dp', 'number theory', '*2000']
C. Teamtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in tea...
Input1 2
Output101
1 second
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*1400']
B. Sereja and Conteststime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (...
Input3 22 12 2
Output0 0
1 second
256 megabytes
['greedy', 'implementation', 'math', '*1200']
A. Vanya and Cardstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, ...
Input3 2-1 1 2
Output1
1 second
256 megabytes
['implementation', 'math', '*800']
E. Inna and Binary Logictime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna is fed up with jokes about female logic. So she started using binary logic instead.Inna has an array of n elements a1[1], a1[2], ..., a1[n]. Girl likes to train in her binary logic, so she ...
Input3 41 1 11 12 23 21 2
Output64712
3 seconds
256 megabytes
['binary search', 'bitmasks', 'data structures', '*2100']
D. Dima and Bacteriatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i...
Input4 4 21 32 3 03 4 02 4 12 1 2
OutputYes0 22 0
2 seconds
256 megabytes
['dsu', 'graphs', 'shortest paths', '*2000']
C. Inna and Huge Candy Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the...
Input3 3 3 1 1 91 11 21 32 12 22 33 13 23 3
Output1 31 21 12 32 22 13 33 23 1
2 seconds
256 megabytes
['implementation', 'math', '*1500']
B. Inna and New Matrix of Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".The field for the new game is a rectangle table of size n × m. Each ...
Input3 4*G*SG**S*G*S
Output2
1 second
256 megabytes
['brute force', 'implementation', 'schedules', '*1200']
A. Inna and Choose Optionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:There is one person p...
Input4OXXXOXOOXOOXOXOXOXOXOXOXXXXXXXXXXXXXOOOOOOOOOOOO
Output3 1x12 2x6 4x34 1x12 2x6 3x4 6x26 1x12 2x6 3x4 4x3 6x2 12x10
1 second
256 megabytes
['implementation', '*1000']
A. Pagestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUser ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The naviga...
Input17 5 2
Output<< 3 4 (5) 6 7 >>
1 second
256 megabytes
['implementation']
D. Instant Messangertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputUser ainta decided to make a new instant messenger called "aintalk". With aintalk, each user can chat with other people. User ainta made the prototype of some functions to implement this thing. log...
Input5 2 9141 33 4C 3A 2 5O 1D 1 3A 1 2A 4 2C 2F 4C 2
Output121
2 seconds
256 megabytes
['data structures']
C. Tree and Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUser ainta likes trees. This time he is going to make an undirected tree with n vertices numbered by integers from 1 to n. The tree is weighted, so each edge of the tree will have some integer weight.Al...
Input7
Output1 4 11 2 22 3 53 5 32 6 26 7 34 55 65 7
1 second
256 megabytes
['constructive algorithms']
B. Painting The Walltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUser ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will fo...
Input5 22 34 1
Output11.7669491886
1 second
256 megabytes
['dp', 'probabilities']
A. Cardstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUser ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below. At first, ...
Input2 3
Output-1xoxox
1 second
256 megabytes
['constructive algorithms', 'implementation']
B. On Corruption and Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity ...
Input25 2 36 4 5
OutputYesNo
1 second
256 megabytes
['constructive algorithms', 'implementation', 'math']
A. On Segment's Own Pointstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOur old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexe...
Input30 52 81 6
Output1
1 second
256 megabytes
['implementation']
E. On Iteration of One Well-Known Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOf course, many of you can calculate φ(n) — the number of positive integers that are less than or equal to n, that are coprime with n. But what if we need to calculate φ(φ(...φ(...
Input17 11
Output22 13 1
1 second
256 megabytes
['math']
D. On Sum of Number of Inversions in Permutationstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p. Calculate the total number of inversions in all permutations that lexicographically do not exceed the given one.As this number can be very...
Input22 1
Output1
3 seconds
256 megabytes
['combinatorics', 'math']
C. On Changing Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree consisting of n vertices numbered from 1 to n. The root of the tree is a vertex number 1.Initially all vertices contain number 0. Then come q queries, each query has one o...
Input31 131 1 2 12 12 2
Output21
2 seconds
256 megabytes
['data structures', 'graphs', 'trees']
B. On Sum of Fractionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest prime number strictly greater than n. Find .InputThe first line contains integer t (1 ≤ t ≤ 500) ...
Input223
Output1/67/30
2 seconds
256 megabytes
['math', 'number theory']
A. On Number of Decompositions into Multiplierstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer m as a product of integers a1, a2, ... an . Your task is to find the number of distinct decompositions of number m into the product of n ordered po...
Input115
Output1
1 second
256 megabytes
['combinatorics', 'math', 'number theory']
E. Lightbulb for Ministertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Minister for education is coming! Naturally, nobody wants to perform poorly in front of such a honored guest. However, two hours before the arrival it turned out that one of the classes has ...
Input43 23 45 45 243 34 45 34 2
Output8.00000000
1 second
256 megabytes
['geometry']
D. Physical Education and Bunstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-de...
Input5-3 -4 -2 -3 3
Output2-3 1
2 seconds
256 megabytes
['brute force', 'implementation', 'math']
C. Dominoestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.The teacher responded instantly at our request. He put nm dominoes on th...
Input2 301 11 0000 01 11
Output11 11 1000 00 01
2 seconds
256 megabytes
['constructive algorithms', 'greedy']
B. Very Beautiful Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTeacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number"...
Input6 5
Output142857
1 second
256 megabytes
['math']
A. Counting Stickstime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot ...
Input||+|=|||||
Output|||+|=||||
0.5 seconds
256 megabytes
['brute force', 'implementation']
D. Three Arraystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are three arrays a, b and c. Each of them consists of n integers. SmallY wants to find three integers u, v, w (0 ≤ u, v, w ≤ n) such that the following condition holds: each number that appears in t...
Input31 1 1011 2 13 2 1
Output5
1 second
256 megabytes
['data structures']
C. Yet Another Number Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEveryone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation: F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2 (i > 2).We'll define a new number sequence Ai(k)...
Input1 1
Output1
1 second
256 megabytes
['combinatorics', 'math', 'matrices']
B. Tower of Hanoitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack...
Input0 1 11 0 11 1 03
Output7
1 second
256 megabytes
['dp']
A. Blocked Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only...
Input1
Output4
2 seconds
256 megabytes
['math']
F2. Stock Tradingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 ...
Input10 22739879719
Output15
3 seconds
256 megabytes
['greedy']
F1. Stock Tradingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 ...
Input10 22739879719
Output15
3 seconds
256 megabytes
['dp']
D2. Supercollidertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem consists of two subproblems: for solving subproblem D1 you will receive 3 points, and for solving subproblem D2 you will receive 16 points.Manao is the chief architect involved in planning...
Input1 24 0 91 1 81 2 7
Output2
3 seconds
256 megabytes
['data structures']
D1. Supercollidertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem consists of two subproblems: for solving subproblem D1 you will receive 3 points, and for solving subproblem D2 you will receive 16 points.Manao is the chief architect involved in planning...
Input1 24 0 91 1 81 2 7
Output2
3 seconds
256 megabytes
['brute force']
C2. The Tournamenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 p...
Input3 21 11 42 2
Output3
2 seconds
256 megabytes
['greedy']
C1. The Tournamenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 p...
Input3 21 11 42 2
Output3
2 seconds
256 megabytes
['brute force']
B. Word Foldingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou will receive 5 points for solving this problem.Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part ...
InputABRACADABRA
Output3
1 second
256 megabytes
['brute force']
A. Genetic Engineeringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou will receive 3 points for solving this problem.Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that ...
InputGTTAAAG
Output1
1 second
256 megabytes
['implementation', 'two pointers']
D. Inna and Sweet Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna loves sweets very much. That's why she decided to play a game called "Sweet Matrix".Inna sees an n × m matrix and k candies. We'll index the matrix rows from 1 to n and the matrix columns fr...
Input4 4 4
Output8(1,1) (2,1) (2,2)(1,1) (1,2)(1,1) (2,1)(1,1)
1 second
256 megabytes
['constructive algorithms']
C. Inna and Candy Boxestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume th...
Input10 3 310101000111 31 64 9
Output132
1 second
256 megabytes
['data structures']
B. Inna, Dima and Songtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song ...
Input31 1 22 2 3
Output4
1 second
256 megabytes
['implementation']
A. Inna and Alarm Clocktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper r...
Input40 00 10 21 0
Output2
1 second
256 megabytes
['implementation']
B. Fox and Crosstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a symbol '#'.A cross on the board is a connected set of exactly five cell...
Input5.#...####..####...#......
OutputYES
1 second
256 megabytes
['greedy', 'implementation', '*1100']
A. Fox and Number Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such tha...
Input21 2
Output2
1 second
256 megabytes
['greedy', 'math', '*1000']
E. Fox and Meteor Showertime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a meteor shower on the sky and there are n meteors. The sky can be viewed as a 2D Euclid Plane and the meteor is point on this plane. Fox Ciel looks at the sky. She finds out that the o...
Input20 0 1 1 0 20 1 0 1 2 0
Output2
6 seconds
256 megabytes
['geometry', '*3100']
D. Fox and Perfect Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFox Ciel studies number theory.She thinks a non-empty set S contains non-negative integers is perfect if and only if for any (a can be equal to b), . Where operation xor means exclusive or operat...
Input1
Output2
1 second
256 megabytes
['math', '*2700']
C. Fox and Card Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.The players take turns and Ciel takes the first turn. I...
Input21 1002 1 10
Output101 10
1 second
256 megabytes
['games', 'greedy', 'sortings', '*2000']
B. Fox and Minimal pathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of s...
Input2
Output4NNYYNNYYYYNNYYNN
1 second
256 megabytes
['bitmasks', 'constructive algorithms', 'graphs', 'implementation', 'math', '*1900']
A. Fox and Box Accumulationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of t...
Input30 0 10
Output2
1 second
256 megabytes
['greedy', 'sortings', '*1400']
E. George and Cardstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeorge is a cat, so he loves playing very much.Vitaly put n cards in a row in front of George. Each card has one integer written on it. All cards had distinct numbers written on them. Let's number th...
Input3 22 1 31 3
Output1
2 seconds
256 megabytes
['binary search', 'data structures', '*2200']
D. George and Interesting Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeorge loves graphs. Most of all, he loves interesting graphs. We will assume that a directed graph is interesting, if it meets the following criteria: The graph doesn't contain any mult...
Input3 71 12 23 11 33 22 33 3
Output0
1 second
256 megabytes
['graph matchings', '*2200']
C. George and Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeorge is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George...
Input9555
Output4
1 second
256 megabytes
['greedy', 'implementation', '*1700']
B. George and Roundtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeorge decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by intege...
Input3 51 2 31 2 2 3 3
Output0
1 second
256 megabytes
['brute force', 'greedy', 'two pointers', '*1200']
A. George and Sleeptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeorge woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p whe...
Input05:5005:44
Output00:06
1 second
256 megabytes
['implementation', '*900']
D. Game with Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing the following game. There are n points on a plane. They are the vertices of a regular n-polygon. Points are labeled with integer numbers from 1 to n. Each pair of distinct points is c...
Input42 3 4*abaa*abba*babb*
Output14 1
2 seconds
256 megabytes
['dp', 'graphs', 'implementation', 'shortest paths', '*2100']
C. Diverse Substringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputString diversity is the number of symbols that occur in the string at least once. Diversity of s will be denoted by d(s). For example , d("aaa")=1, d("abacaba")=3.Given a string s, consisting of low...
Inputabca
Output3433
1 second
256 megabytes
['dp', 'strings', 'two pointers', '*2000']
B. Fly, freebies, fly!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEveryone loves a freebie. Especially students.It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, ...
Input64 1 7 8 3 81
Output3
1 second
256 megabytes
['binary search', 'brute force', 'implementation', '*1400']
A. Second-Price Auctiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is...
Input25 7
Output2 5
1 second
256 megabytes
['implementation', '*800']
E. Bear in the Fieldtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOur bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's de...
Input5 1 2 0 1 2
Output3 1
1 second
256 megabytes
['math', 'matrices', '*2300']
D. Bear and Floodlighttime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day a bear lived on the Oxy axis. He was afraid of the dark, so he couldn't move at night along the plane points that aren't lit. One day the bear wanted to have a night walk from his house at...
Input2 3 53 1 455 1 45
Output2.000000000
4 seconds
256 megabytes
['bitmasks', 'dp', 'geometry', '*2200']
C. Bear and Prime Numberstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRecently, the bear started studying data structures and faced the following problem.You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized...
Input65 5 7 10 14 1532 113 124 4
Output970
2 seconds
512 megabytes
['binary search', 'brute force', 'data structures', 'dp', 'implementation', 'math', 'number theory', '*1700']
B. Bear and Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|),...
Inputbearbtear
Output6
1 second
256 megabytes
['brute force', 'greedy', 'implementation', 'math', 'strings', '*1200']
A. Bear and Raspberrytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, ...
Input5 15 10 7 3 20
Output3
1 second
256 megabytes
['brute force', 'greedy', 'implementation', '*1000']
B. Multitaskingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.Iahub can choose a pair of distinct indices i and j (1...
Input2 5 01 3 2 5 41 4 3 2 5
Output32 42 34 5
1 second
256 megabytes
['greedy', 'implementation', 'sortings', 'two pointers', '*1500']
A. Codertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he ca...
Input2
Output2C..C
1 second
256 megabytes
['implementation', '*800']
E. Vowelstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahubina is tired of so many complicated languages, so she decided to invent a new, simple language. She already made a dictionary consisting of n 3-words. A 3-word is a sequence of exactly 3 lowercase letters...
Input5abcaaaadabcddef
Output0
4 seconds
256 megabytes
['combinatorics', 'divide and conquer', 'dp', '*2700']
D. Antimattertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of...
Input41 1 1 1
Output12
1 second
256 megabytes
['dp', '*2300']
C. Propagating treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The root of ...
Input5 51 2 1 1 21 21 32 42 51 2 31 1 22 12 22 4
Output330
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'trees', '*2000']
B. Volcanoestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub got lost in a very big desert. The desert can be represented as a n × n square matrix, where each cell is a zone of the desert. The cell (i, j) represents the cell at row i and column j (1 ≤ i, j ≤ n)....
Input4 21 31 4
Output6
1 second
256 megabytes
['binary search', 'implementation', 'sortings', 'two pointers', '*2500']
A. Milking cowstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the rig...
Input40 0 1 0
Output1
1 second
256 megabytes
['data structures', 'greedy', '*1600']
E. Ksenia and Combinatoricstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKsenia has her winter exams. Today she is learning combinatorics. Here's one of the problems she needs to learn to solve.How many distinct trees are there consisting of n vertices, each with t...
Input1 1
Output0
1 second
256 megabytes
['combinatorics', 'dp', '*2600']
D. Ksenia and Pawnstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKsenia has a chessboard of size n × m. Each cell of the chessboard contains one of the characters: "<", ">", "^", "v", "#". The cells that contain character "#" are blocked. We know that all chessboa...
Input1 1#
Output0
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'implementation', 'trees', '*2200']
C. Arithmetic Progressiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condi...
Input34 1 7
Output2-2 10
1 second
256 megabytes
['implementation', 'sortings', '*1700']
B. Number Busterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArthur and Alexander are number busters. Today they've got a competition. Arthur took a group of four integers a, b, w, x (0 ≤ b < w, 0 < x < w) and Alexander took integer с. Arthur and Alexander use di...
Input4 2 3 1 6
Output2
1 second
256 megabytes
['binary search', 'math', '*2000']
A. Ksenia and Pan Scalestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKsenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is po...
InputAC|TL
OutputAC|TL
1 second
256 megabytes
['greedy', 'implementation', '*1100']
B. Sereja and Stairstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja loves integer sequences very much. He especially likes stairs.Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 ≤ i ≤ |a|), that the followin...
Input51 2 3 4 5
Output55 4 3 2 1
1 second
256 megabytes
['greedy', 'implementation', 'sortings', '*1100']
A. Sereja and Dimatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja...
Input44 1 2 10
Output12 5
1 second
256 megabytes
['greedy', 'implementation', 'two pointers', '*800']
E. Sereja and Dividingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's assume that we have a sequence of doubles a1, a2, ..., a|a| and a double variable x. You are allowed to perform the following two-staged operation: choose an index of the sequence element i...
Input51 2 3 4 1
Output1.238750000000000
2 seconds
256 megabytes
['data structures', '*2600']
D. Sereja and Cinematime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe cinema theater hall in Sereja's city is n seats lined up in front of one large screen. There are slots for personal possessions to the left and to the right of each seat. Any two adjacent seats h...
Input110 0 0 0 0 0 0 0 0 0 0
Output1024
1 second
256 megabytes
['combinatorics', 'math', '*2500']
C. Sereja and Bracketstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(" and ")".Sereja needs to answer m queries, each of them is described by two in...
Input())(())(())(71 12 31 21 128 125 112 10
Output00210466
1 second
256 megabytes
['data structures', 'schedules', '*2000']
B. Sereja and Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja adores trees. Today he came up with a revolutionary new type of binary root trees.His new tree consists of n levels, each vertex is indexed by two integers: the number of the level and the numb...
Input4 51 4 4 7 11 3 1 2 22 1 12 4 12 3 3
Output201
2 seconds
256 megabytes
['graphs', 'implementation', '*2400']
A. Sereja and Prefixestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm.Sereja takes a blank piece of paper. Then he starts writing out the sequence i...
Input61 11 22 2 11 32 5 21 4161 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Output1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4
1 second
256 megabytes
['binary search', 'brute force', '*1600']
G. New Year Cactustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJack and Jill are tired of the New Year tree, now they've got a New Year cactus at home! A cactus is a connected undirected graph where any two simple cycles have at most one common vertex. In other w...
Input1 0
Output1 0
2 seconds
256 megabytes
['dp', '*3100']
F. New Year Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a programmer and you have a New Year Tree (not the traditional fur tree, though) — a tree of four vertices: one vertex of degree three (has number 1), connected with three leaves (their numbers ...
Input523485
Output34456
2 seconds
256 megabytes
['data structures', 'divide and conquer', 'trees', '*2400']
E. New Year Tree Decorationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDue to atheistic Soviet past, Christmas wasn't officially celebrated in Russia for most of the twentieth century. As a result, the Russian traditions for Christmas and New Year mixed into one...
Input2 22 1 21 2 1
Output3.0000000000000.500000000000
1 second
256 megabytes
['geometry', 'schedules', 'sortings', '*2500']
D. New Year Lettertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMany countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to w...
Input3 2 2 2
OutputACAC
1 second
256 megabytes
['bitmasks', 'brute force', 'dp', '*2000']
C. New Year Ratings Changetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.There are n users on the site, for...
Input35 1 1
Output5 1 2
1 second
256 megabytes
['greedy', 'sortings', '*1400']
B. New Year Presenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. H...
Input21 2
OutputPRPLRP
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1200']
A. New Year Candlestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily the Programmer loves romance, so this year he decided to illuminate his room with candles.Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes ou...
Input4 2
Output7
1 second
256 megabytes
['implementation', '*1000']
B. Semifinalstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k peo...
Input49840 99209860 99809930 1002010040 10090
Output11101100
1 second
256 megabytes
['implementation', 'sortings', '*1300']
A. Playing with Dicetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers ...
Input2 5
Output3 0 3
1 second
256 megabytes
['brute force', '*800']
E. Cookie Clickertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKostya is playing the computer game Cookie Clicker. The goal of this game is to gather cookies. You can get cookies using different buildings: you can just click a special field on the screen and get t...
Input3 91 02 35 4
Output6
2 seconds
256 megabytes
['dp', 'geometry', '*2800']
D. Developing Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the...
Input42 8 91 4 73 6 85 8 10
Output31 3 4
2 seconds
256 megabytes
['data structures', '*2400']
C. Captains Modetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, ...
Input22 12p 1p 2
Output1
2 seconds
256 megabytes
['bitmasks', 'dp', 'games', '*2200']
B. Preparing for the Contesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSoon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has no choice but to attract univers...
Input3 4 91 3 1 22 1 34 3 6
OutputYES2 3 2 3
2 seconds
256 megabytes
['binary search', 'data structures', 'greedy', 'sortings', '*1900']
A. Mazetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.Pavel drew a ...
Input3 4 2#..#..#.#...
Output#.X#X.#.#...
2 seconds
256 megabytes
['dfs and similar', '*1600']
B. I.O.U.time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputImagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal man...
Input5 31 2 102 3 12 4 1
Output10
1 second
256 megabytes
['implementation', '*1300']
A. Levertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that...
Input=^==
Outputbalance
1 second
256 megabytes
['implementation', 'math', '*900']
E. Red and Black Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a weighted tree, consisting of n vertices. Each vertex is either painted black or is painted red. A red and black tree is called beautiful, if for any its vertex we can find a black vertex ...
Input3 21 0 01 2 22 3 2
Output1
1 second
256 megabytes
['dp', 'implementation', 'math', '*3000']