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. Little Girl and Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following...
Inputaba
OutputFirst
2 seconds
256 megabytes
['games', 'greedy', '*1300']
A. Lunch Rushtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHaving written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.The Rabbits have a list of n restaurants to lunch in: ...
Input2 53 34 5
Output4
2 seconds
256 megabytes
['implementation', '*900']
B. Convex Shapetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell ...
Input3 4WWBWBWWWWWWB
OutputNO
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*1700']
A. Lights Outtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is t...
Input1 0 00 0 00 0 1
Output001010100
2 seconds
256 megabytes
['implementation', '*900']
E. Mirror Roomtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImagine an n × m grid with some blocked cells. The top left cell in the grid has coordinates (1, 1) and the bottom right cell has coordinates (n, m). There are k blocked cells in the grid and others are e...
Input3 3 01 2 SW
Output6
2 seconds
256 megabytes
['data structures', 'implementation', '*3000']
D. Lovely Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLenny had an n × m matrix of positive integers. He loved the matrix so much, because each row of the matrix was sorted in non-decreasing order. For the same reason he calls such matrices of integers lov...
Input3 31 -1 -11 2 12 -1 1
Output3 1 2
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'greedy', 'sortings', '*2200']
C. The Last Hole!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLuyi has n circles on the plane. The i-th circle is centered at (xi, yi). At the time zero circles start to grow simultaneously. In other words, the radius of each circle at time t (t > 0) is equal to ...
Input30 01 12 2
Output-1
2 seconds
256 megabytes
['brute force', 'geometry', '*2600']
B. Zero Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subt...
Input31 21 31 -1 1
Output3
2 seconds
256 megabytes
['dfs and similar', 'dp', 'greedy', 'trees', '*1800']
A. k-Multiple Free Settime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set...
Input6 22 3 6 5 4 10
Output3
2 seconds
256 megabytes
['binary search', 'greedy', 'sortings', '*1500']
E. Dima and Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima and Anya love playing different games. Now Dima has imagined a new game that he wants to play with Anya.Dima writes n pairs of integers on a piece of paper (li, ri) (1 ≀ li < ri ≀ p). Then players t...
Input2 2
Output0
1 second
256 megabytes
['dp', 'games', '*2600']
D. Dima and Figuretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima loves making pictures on a piece of squared paper. And yet more than that Dima loves the pictures that depict one of his favorite figures. A piece of squared paper of size n × m is represented by...
Input2 2
Output13
3 seconds
256 megabytes
['dp', '*2400']
E. Dima and Horsestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima came to the horse land. There are n horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the num...
Input3 31 23 23 1
Output100
2 seconds
256 megabytes
['combinatorics', 'constructive algorithms', 'graphs', '*2200']
D. Dima and Two Sequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).Now Dima wants to count the number of disti...
Input1127
Output1
2 seconds
256 megabytes
['combinatorics', 'math', 'sortings', '*1600']
C. Dima and Staircasetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≀ a1 ≀ a2 ≀ ... ≀ an). Dima decided to play with the staircase, ...
Input51 2 3 6 641 13 11 14 3
Output1346
2 seconds
256 megabytes
['data structures', 'implementation', '*1500']
B. Dima and Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0...
Input31 2 4
Output3
2 seconds
256 megabytes
['implementation', 'math', '*1400']
A. Dima and Friendstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.To decide who exactl...
Input11
Output3
2 seconds
256 megabytes
['implementation', 'math', '*1000']
E. Three Horsestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain t...
Input1 62
Output11
2 seconds
256 megabytes
['constructive algorithms', 'math', 'number theory', '*2200']
D. Good Substringstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.A substring s[l...r] (1 ≀ l ≀ r ≀ |s|) of string s  =  s1s2...s|s| (where |s| is the le...
Inputababab010000000000000000000000001
Output5
2 seconds
512 megabytes
['data structures', 'strings', '*1800']
C. Secrettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let's index them by positive integers from 1 to k), the i-th Keeper gets a n...
Input11 3
Output3 1 2 1 1 2 3 2 2 3 1
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*1500']
B. Prime Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element...
Input3 31 2 35 6 14 4 1
Output1
2 seconds
256 megabytes
['binary search', 'brute force', 'math', 'number theory', '*1300']
A. Beautiful Yeartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.Now you are suggested to solve the follow...
Input1987
Output2013
2 seconds
256 megabytes
['brute force', '*800']
B. Multithreadingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple...
Input55 2 1 3 4
Output2
2 seconds
256 megabytes
['data structures', 'greedy', 'implementation', '*1400']
A. Fancy Fencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single...
Input3306090
OutputNOYESYES
2 seconds
256 megabytes
['geometry', 'implementation', 'math', '*1100']
E. String Theorytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmuskald is an innovative musician and always tries to push the boundaries of music production. Now he has come up with an idea for a revolutionary musical instrument β€” a rectangular harp.A rectangular ...
Input3 4L T 1 3L B 2 2L B 3 3T R 1 2T B 2 1T R 4 1B R 4 3
Output1 2 3 3 2 1 4
2 seconds
256 megabytes
['geometry', 'math', 'strings', '*3100']
D. Maximum Waterfalltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmuskald was hired to design an artificial waterfall according to the latest trends in landscape architecture. A modern artificial waterfall consists of multiple horizontal panels affixed to a wide ...
Input5 64 1 63 2 75 9 113 10 151 13 16
Output4
2 seconds
256 megabytes
['data structures', 'dp', 'graphs', 'sortings', '*2600']
C. Flawed Flowtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet β€” it calculates the maximum flow in an undirected graph. The graph consists of n vertices and m ...
Input3 33 2 101 2 103 1 5
Output101
2 seconds
256 megabytes
['constructive algorithms', 'flows', 'graphs', 'greedy', '*2100']
B. Greenhouse Effecttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmuskald is an avid horticulturist and owns the world's longest greenhouse β€” it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different pl...
Input3 22 11 2.01 3.100
Output1
2 seconds
256 megabytes
['dp', '*1700']
A. Magical Boxestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.From the top view each magical box ...
Input20 31 5
Output3
2 seconds
256 megabytes
['greedy', 'math', '*1600']
E. Playlisttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputManao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a playlist. When he feels that his mind is open to new music, he opens the playlist and starts to ...
Input3150 20150 50100 50
Output537.500000000
1 second
256 megabytes
['math', 'probabilities', 'sortings', '*2100']
D. Wall Barstime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputManao is working for a construction company. Recently, an order came to build wall bars in a children's park. Manao was commissioned to develop a plan of construction, which will enable the company to save ...
Input5 1
Output4
4 seconds
512 megabytes
['dp', '*2300']
C. Beautiful Sets of Pointstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputManao has invented a new mathematical term β€” a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: The coordinates of each point in th...
Input2 2
Output30 11 22 0
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1500']
B. Buttonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputManao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pres...
Input2
Output3
1 second
256 megabytes
['implementation', 'math', '*1000']
A. Gamestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputManao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform an...
Input31 22 43 4
Output1
1 second
256 megabytes
['brute force', '*800']
C. Berland Traffictime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland traffic is very different from traffic in other countries. The capital of Berland consists of n junctions and m roads. Each road connects a pair of junctions. There can be multiple roads betwe...
Input231 2 21 2 42 1 1000
Output6.000002.000002.00000-2.00000
2 seconds
256 megabytes
['math', 'matrices', '*2700']
B. Dominoestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes tou...
Input51 22 42 46 42 1
Output2 -1 -5 -3 +4 -
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*2000']
A. Subtractionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. ...
Input24 177 987654321
Output8141093479
1 second
256 megabytes
['math', 'number theory', '*900']
E. More Queries to Array...time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an array, consisting of n integers: a1, a2, ..., an. Your task is to quickly run the queries of two types: Assign value x to all elements from l to r inclusive. After such query th...
Input4 55 10 2 1? 1 2 1= 2 2 0? 2 4 3= 1 4 1? 1 4 5
Output25431300
5 seconds
256 megabytes
['data structures', 'math', '*2500']
D. BerDonaldstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerDonalds, a well-known fast food restaurant, is going to open a cafe in Bertown. The important thing is to choose the new restaurant's location so that it would be easy to get there. The Bertown road sys...
Input2 11 2 1
Output0.50
5 seconds
256 megabytes
['graphs', 'math', 'shortest paths', '*2400']
C. Below the Diagonaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to n from left to right. So...
Input21 2
Output22 1 21 1 2
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'math', '*2100']
B. Queue at the Schooltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys ...
Input5 1BGGBG
OutputGBGGB
2 seconds
256 megabytes
['constructive algorithms', 'graph matchings', 'implementation', 'shortest paths', '*800']
A. Stones on the Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors....
Input3RRG
Output1
2 seconds
256 megabytes
['implementation', '*800']
B. Roadside Trees (Simplified Edition)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSquirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi....
Input212
Output5
2 seconds
256 megabytes
['greedy', 'implementation', '*1000']
A. Colorful Stones (Simplified Edition)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of ...
InputRGBRRR
Output2
2 seconds
256 megabytes
['implementation', '*800']
E. Roadside Treestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSquirrel Liss loves nuts. Liss asks you to plant some nut trees.There are n positions (numbered 1 to n from west to east) to plant a tree along a street. Trees grow one meter per month. At the beginnin...
Input4 61 1 11 4 41 3 42 21 2 82 3
Output123222
5 seconds
256 megabytes
['data structures', 'dp', '*3000']
D. Colorful Stonestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are two sequences of colorful stones. The color of each stone is one of red, green, or blue. You are given two strings s and t. The i-th (1-based) character of s represents the color of the i-th...
InputRBRRGG
Output5
2 seconds
256 megabytes
['dp', 'two pointers', '*2500']
C. Choosing Ballstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the i-th ball is ci and the value of the i-th ball is vi.Squirrel Li...
Input6 31 -2 3 4 0 -11 2 1 2 1 15 1-2 11 0
Output2094
5 seconds
256 megabytes
['dp', '*2000']
B. Good Sequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSquirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.Now she is interested in good sequences. A sequence x1, x2, ..., xk is cal...
Input52 3 4 6 9
Output4
2 seconds
256 megabytes
['dp', 'number theory', '*1500']
A. Escape from Stonestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSquirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will ...
Inputllrlr
Output35421
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'implementation', 'two pointers', '*1200']
E. Rhombustime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a table of size n × m. On the intersection of the i-th row (1 ≀ i ≀ n) and the j-th column (1 ≀ j ≀ m) there is a non-negative integer ai, j. Besides, you've got a non-negative integer k.Your task ...
Input4 4 21 2 3 41 1 1 12 2 2 24 3 2 1
Output3 2
3 seconds
256 megabytes
['brute force', 'data structures', 'dp', '*2500']
D. Cycle in Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k ...
Input3 3 21 22 33 1
Output31 2 3
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*1800']
C. Circle of Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each ...
Input51 22 33 44 55 11 32 43 54 15 2
Output1 2 3 4 5
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'implementation', '*2000']
B. Squarestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that po...
Input4 35 1 3 4
Output2 1
2 seconds
256 megabytes
['greedy', 'implementation', 'sortings', '*900']
A. Beautiful Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to ...
Input0 0 0 0 00 0 0 0 10 0 0 0 00 0 0 0 00 0 0 0 0
Output3
2 seconds
256 megabytes
['implementation', '*800']
B. Roma and Changing Signstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoma works in a company that sells TVs. Now he has to prepare a report for the last year.Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The t...
Input3 2-1 -1 1
Output3
2 seconds
256 megabytes
['greedy', '*1200']
A. Roma and Lucky Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.Let us remind you that lucky numbers are positive integers whose decimal representation only conta...
Input3 41 2 4
Output3
1 second
256 megabytes
['implementation', '*800']
E. Maxim and Calculatortime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaxim has got a calculator. The calculator has two integer cells. Initially, the first cell contains number 1, and the second cell contains number 0. In one move you can perform one of the follow...
Input2 10 3
Output1
4 seconds
256 megabytes
['brute force', 'dp', 'two pointers', '*2800']
D. Maxim and Increasing Subsequencetime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaxim loves sequences, especially those that strictly increase. He is wondering, what is the length of the longest increasing subsequence of the given sequence a?Sequence a is given a...
Input3 3 5 23 2 11 2 32 3 1
Output233
6 seconds
256 megabytes
['dp', '*2600']
C. Maxim and Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m + 1) × (m + 1):Maxim asks you to count, how many numbers m (1 ≀ m ≀ n) are there, such that...
Input1 1
Output1
2 seconds
256 megabytes
['constructive algorithms', 'dp', 'math', '*2000']
B. Maxim and Restauranttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of...
Input31 2 33
Output1.3333333333
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*1900']
A. Maxim and Discountstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.There are m types of discounts. We assume that the discounts are indexed from 1 to m....
Input12450 50 100 100
Output200
2 seconds
256 megabytes
['greedy', 'sortings', '*1400']
E. Dividing Kingdomtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA country called Flatland is an infinite two-dimensional plane. Flatland has n cities, each of them is a point on the plane.Flatland is ruled by king Circle IV. Circle IV has 9 sons. He wants to give...
Input91 11 21 32 12 22 33 13 23 31 1 1 1 1 1 1 1 1
Output1.5000000000 2.50000000001.5000000000 2.5000000000
2 seconds
256 megabytes
['binary search', 'brute force', 'data structures', '*2500']
D. Black and White Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.Each node of the graph...
Input31 31 20 5
Output3 1 33 2 2
1 second
256 megabytes
['constructive algorithms', 'dsu', 'graphs', 'greedy', 'trees', '*2100']
C. Balls and Boxestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.Once Vasya chose one of the boxes, let's assume that its number i...
Input4 44 3 1 6
Output3 2 5 4
1 second
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*1700']
B. Ancient Prophesytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".We'll say that some date is mentioned in th...
Input777-444---21-12-2013-12-2013-12-2013---444-777
Output13-12-2013
1 second
256 megabytes
['brute force', 'implementation', 'strings', '*1600']
A. Adding Digitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.One operation of lengthening a number means adding exact...
Input5 4 5
Output524848
2 seconds
256 megabytes
['implementation', 'math', '*1400']
B. Little Elephant and Magic Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Elephant loves magic squares very much.A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonal...
Input0 1 11 0 11 1 0
Output1 1 11 1 11 1 1
2 seconds
256 megabytes
['brute force', 'implementation', '*1100']
A. Little Elephant and Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 che...
InputWBWBWBWBBWBWBWBWBWBWBWBWBWBWBWBWWBWBWBWBWBWBWBWBBWBWBWBWWBWBWBWB
OutputYES
2 seconds
256 megabytes
['brute force', 'strings', '*1000']
E. Little Elephant and Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves trees very much, he especially loves root trees.He's got a tree consisting of n nodes (the nodes are numbered from 1 to n), with root at node number 1. Each node of ...
Input5 11 21 33 53 42 3
Output0 3 3 3 3
4 seconds
256 megabytes
['data structures', 'dfs and similar', 'trees', '*2400']
D. Little Elephant and Broken Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some ele...
Input2 11 21 2
Output0.500000000
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*2600']
C. Little Elephant and LCMtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves the LCM (least common multiple) operation of a non-empty set of positive integers. The result of the LCM operation of k positive integers x1, x2, ..., xk is the minim...
Input41 4 3 2
Output15
4 seconds
256 megabytes
['binary search', 'combinatorics', 'dp', 'math', '*2000']
B. Little Elephant and Electionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.Pol...
Input7
Output0
2 seconds
256 megabytes
['brute force', 'combinatorics', 'dp', '*1900']
A. Little Elephant and Bitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.To make sure that the number a fits on the piece of paper, the Little E...
Input101
Output11
2 seconds
256 megabytes
['greedy', 'math', '*1100']
E. Greedy Elevatortime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe m-floor (m > 1) office of international corporation CodeForces has the advanced elevator control system established. It works as follows.All office floors are sequentially numbered with integers f...
Input3 101 2 73 6 53 4 8
Output7118
3 seconds
256 megabytes
['data structures', 'implementation', '*2200']
D. Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≀ ai + 1 ≀ 2Β·ai for any positive i...
Input41 2 3 5
Output+++-
2 seconds
256 megabytes
['greedy', 'math', '*1900']
C. View Angletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFlatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum ang...
Input22 00 2
Output90.0000000000
2 seconds
256 megabytes
['brute force', 'geometry', 'math', '*1800']
B. Playing Cubestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from ...
Input3 1
Output2 1
2 seconds
256 megabytes
['games', 'greedy', 'implementation', '*1300']
A. Socketstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.Overall Vasya has got m devices and k electrical sockets in ...
Input3 5 33 1 2
Output1
2 seconds
256 megabytes
['greedy', 'implementation', 'sortings', '*1100']
E. Lucky Arraystime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Maxim loves interesting problems. He decided to share one such problem with you. Initially there is an array a, consisting of n zeroes. The elements of the array are indexed, starting from 1. Then...
Input3 101 1 01 0 01 1 11 11 32 23 02 13 03 12 03 11 0
Output3611221336
4 seconds
256 megabytes
['data structures', '*2400']
D. Liars and Sergetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n people, sitting in a line at the table. For each person we know that he always tells either the truth or lies.Little Serge asked them: how many of you always tell the truth? Each of the peo...
Input1 1
Output0
1 second
256 megabytes
['dp', '*2700']
E. Furlo and Rublo and Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: choose ...
Input11
OutputRublo
2 seconds
256 megabytes
['games', 'implementation', 'math', '*2200']
D. Mr. Bender and Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be ...
Input6 4 3 1
Output0
2 seconds
256 megabytes
['binary search', 'implementation', 'math', '*1800']
C. Almost Arithmetical Progressiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression...
Input23 5
Output2
1 second
256 megabytes
['brute force', 'dp', '*1500']
B. Code Parsingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operatio...
Inputx
Outputx
2 seconds
256 megabytes
['implementation', '*1200']
A. Greg's Workouttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGreg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, G...
Input22 8
Outputbiceps
2 seconds
256 megabytes
['implementation', '*800']
E. Dormitorytime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtStudent Vasya came to study in Berland State University from the country, so he is living in a dormitory. A semester has n days, and in each of those days his parents send him some food. In the morning of the i-th day...
Input4 13 2 5 431 3 21 4 13 4 2
Output71 21 23 2 1 32 2 3
1 second
256 megabytes
['dp', 'implementation', '*2100']
D. Ratstime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtRats have bred to hundreds and hundreds in the basement of the store, owned by Vasily Petrovich. Vasily Petrovich may have not noticed their presence, but they got into the habit of sneaking into the warehouse and stealing...
Input4 4 1XXXXXR.XX.RXXXXX
Output2 2 2 3
1 second
256 megabytes
['brute force', 'dfs and similar', 'graphs', 'implementation', 'shortest paths', '*2300']
C. Anagramtime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtString x is an anagram of string y, if we can rearrange the letters in string x and get exact string y. For example, strings "DOG" and "GOD" are anagrams, so are strings "BABA" and "AABB", but strings "ABBAC" and "CAABA...
InputABACBA
Output1ABC
1 second
256 megabytes
['greedy', 'strings', '*1800']
B. Jury Sizetime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtIn 2013, the writers of Berland State University should prepare problems for n Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to n. For each Olympiad we know how many member...
Input25 23 1 23 13 2 3
Output2
1 second
256 megabytes
['brute force', 'implementation', '*1500']
A. Cards with Numberstime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtPetya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card...
Input320 30 10 30 20 10
Output4 21 56 3
1 second
256 megabytes
['constructive algorithms', 'sortings', '*1200']
E. Printertime limit per test4 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtLet's consider a network printer that functions like that. It starts working at time 0. In each second it can print one page of a text. At some moments of time the printer receives printing tasks. We know that a printe...
Input34 3 -10 2 21 3 37
Output47 8 4
4 seconds
256 megabytes
['binary search', 'data structures', 'implementation', 'sortings', '*2200']
D. Table with Letters - 2time limit per test2 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtVasya has recently started to learn English. Now he needs to remember how to write English letters. He isn't sure about some of them, so he decided to train a little.He found a sheet of squared paper and...
Input3 4 4aabbbaabbaab
Output2
2 seconds
256 megabytes
['brute force', 'two pointers', '*2000']
C. Text Editortime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtVasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writ...
Input42 1 6 43 4 4 2
Output3
1 second
256 megabytes
['data structures', 'dfs and similar', 'graphs', 'greedy', 'shortest paths', '*1600']
B. Physics Practicaltime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtOne day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After t...
Input64 5 3 8 3 7
Output2
1 second
256 megabytes
['binary search', 'dp', 'sortings', 'two pointers', '*1400']
A. Boys and Girlstime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtThere are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right ...
Input3 3
OutputGBGBGB
1 second
256 megabytes
['greedy', '*1100']
B. Unsorting Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the ...
Input11
Output-1
2 seconds
256 megabytes
['brute force', 'sortings', '*1800']
A. Little Xortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of conse...
Input51 2 1 1 2
Output3
2 seconds
256 megabytes
['brute force', 'implementation', '*1100']
E. Tree and Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya likes trees a lot. Recently his mother has presented him a tree with 2n nodes. Petya immediately decided to place this tree on a rectangular table consisting of 2 rows and n columns so as ...
Input31 32 34 35 16 2
Output12
2 seconds
256 megabytes
['dfs and similar', 'dp', 'implementation', 'trees', '*3000']
D. Two Setstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediatel...
Input61 2 3 4 5 6
Output2 2 2 2 2 2
2 seconds
256 megabytes
['bitmasks', 'math', '*2700']
C. Number Transformationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya likes positive integers a lot. Recently his mom has presented him a positive integer a. There's only one thing Petya likes more than numbers: playing with little Masha. It turned ou...
Input10 1 4
Output6
2 seconds
256 megabytes
['dp', 'greedy', 'number theory', '*2000']
B. Playing with Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n.A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≀ a...
Input4 12 3 4 11 2 3 4
OutputNO
2 seconds
256 megabytes
['implementation', 'math', '*1800']