Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
stringlengths
2
6
contest_id
int32
1
2.27k
index
stringclasses
79 values
title
stringlengths
2
64
rating
int32
-1
3.5k
tags
listlengths
0
11
solved_count
int32
0
734k
points
float64
3
6k
βŒ€
contest_name
stringlengths
10
125
contest_start_date
stringdate
2010-02-19 00:00:00
2026-09-26 00:00:00
contest_division
stringclasses
8 values
url
stringlengths
45
49
time_limit_seconds
float64
0.4
15
βŒ€
memory_limit_mb
float64
4
1.02k
βŒ€
input_mode
stringclasses
2 values
is_interactive
bool
2 classes
description
stringlengths
1
9.92k
input_format
stringlengths
1
4.27k
βŒ€
output_format
stringlengths
1
2.36k
βŒ€
interaction_format
stringclasses
262 values
note
stringlengths
0
5.47k
βŒ€
examples
listlengths
0
10
statement_status
stringclasses
1 value
1A
1
A
Theatre Square
1,000
[ "math" ]
333,953
null
Codeforces Beta Round 1
2010-02-19
Other
https://codeforces.com/problemset/problem/1/A
1
256
file
false
Theatre Square in the capital city of Berland has a rectangular shape with the size *n* × *m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a* × *a*. What is the least number of flagstones needed to pave the Squ...
The input contains three positive integer numbers in the first line: *n*,  *m* and *a* (1 ≀  *n*, *m*, *a* ≀ 10^{9}).
Write the needed number of flagstones.
null
null
[ { "input": "6 6 4\n", "output": "4\n" } ]
ok
1B
1
B
Spreadsheets
1,600
[ "implementation", "math" ]
27,334
null
Codeforces Beta Round 1
2010-02-19
Other
https://codeforces.com/problemset/problem/1/B
10
64
file
false
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow th...
The first line of the input contains integer number *n* (1 ≀ *n* ≀ 10^{5}), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 10^{6} .
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
null
null
[ { "input": "2\nR23C55\nBC23\n", "output": "BC23\nR23C55\n" } ]
ok
1C
1
C
Ancient Berland Circus
2,100
[ "geometry", "math" ]
6,752
null
Codeforces Beta Round 1
2010-02-19
Other
https://codeforces.com/problemset/problem/1/C
2
64
file
false
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec...
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
null
null
[ { "input": "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n", "output": "1.00000000\n" } ]
ok
2A
2
A
Winner
1,500
[ "hashing", "implementation" ]
32,319
null
Codeforces Beta Round 2
2010-02-25
Other
https://codeforces.com/problemset/problem/2/A
1
64
file
false
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1  ≀  *n*  ≀  1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "`name score`" format in chronological order, where `name` is a string of lower-case Latin letters with the length from 1 to 32, and `score` is an...
Print the name of the winner.
null
null
[ { "input": "3\nmike 3\nandrew 5\nmike 2\n", "output": "andrew\n" }, { "input": "3\nandrew 3\nandrew 2\nmike 5\n", "output": "andrew\n" } ]
ok
2B
2
B
The least round way
2,000
[ "dp", "math" ]
13,603
null
Codeforces Beta Round 2
2010-02-25
Other
https://codeforces.com/problemset/problem/2/B
2
64
file
false
There is a square matrix *n* × *n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the n...
The first line contains an integer number *n* (2 ≀ *n* ≀ 1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 10^{9}).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
null
null
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9\n", "output": "0\nDDRR\n" } ]
ok
2C
2
C
Commentator problem
2,600
[ "geometry" ]
2,194
null
Codeforces Beta Round 2
2010-02-25
Other
https://codeforces.com/problemset/problem/2/C
1
64
file
false
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to cho...
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format *x*,  *y*,  *r*, where (*x*, *y*) are the coordinates of the stadium's center ( -  10^{3} ≀ *x*,  *y* ≀ 10^{3}), and *r* (1 ≀ *r*  ≀ 10^{3}) is its radius. All the numbers in the input data are integer,...
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
null
null
[ { "input": "0 0 10\n60 0 10\n30 30 10\n", "output": "30.00000 0.00000\n" } ]
ok
3A
3
A
Shortest path of the king
1,000
[ "greedy", "shortest paths" ]
22,817
null
Codeforces Beta Round 3
2010-03-07
Other
https://codeforces.com/problemset/problem/3/A
1
64
file
false
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le...
The first line contains the chessboard coordinates of square *s*, the second line β€” of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from `a` to `h`), the second one is a digit from `1` to `8`.
In the first line print *n* β€” minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: `L`, `R`, `U`, `D`, `LU`, `LD`, `RU` or `RD`. `L`, `R`, `U`, `D` stand respectively for moves left, right, up and down (according to the picture), and 2-letter combi...
null
null
[ { "input": "a8\nh1\n", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" } ]
ok
3B
3
B
Lorry
1,900
[ "greedy", "sortings" ]
5,445
null
Codeforces Beta Round 3
2010-03-07
Other
https://codeforces.com/problemset/problem/3/B
2
64
file
false
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
The first line contains a pair of integer numbers *n* and *v* (1 ≀ *n* ≀ 10^{5}; 1 ≀ *v* ≀ 10^{9}), where *n* is the number of waterborne vehicles in the boat depot, and *v* is the truck body volume of the lorry in cubic metres. The following *n* lines contain the information about the waterborne vehicles, that is a pa...
In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.
null
null
[ { "input": "3 2\n1 2\n2 7\n1 3\n", "output": "7\n2\n" } ]
ok
3C
3
C
Tic-tac-toe
1,800
[ "brute force", "games", "implementation" ]
8,517
null
Codeforces Beta Round 3
2010-03-07
Other
https://codeforces.com/problemset/problem/3/C
1
64
file
false
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other β€” noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the g...
The input consists of three lines, each of the lines contains characters "`.`", "`X`" or "`0`" (a period, a capital letter X, or a digit zero).
Print one of the six verdicts: `first`, `second`, `illegal`, `the first player won`, `the second player won` or `draw`.
null
null
[ { "input": "X0X\n.0.\n.X.\n", "output": "second\n" } ]
ok
3D
3
D
Least Cost Bracket Sequence
2,600
[ "greedy" ]
4,419
null
Codeforces Beta Round 3
2010-03-07
Other
https://codeforces.com/problemset/problem/3/D
1
64
file
false
This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "`+`" and "`1`" into it we get a correct mathematical expression. For example, sequences "`(())()`", "`()`" and "`(()(()))`" are regular, while "`)(`", "`(()`" and "`(()))(`" are not. You have a pattern of a...
The first line contains a non-empty pattern of even length, consisting of characters "`(`", "`)`" and "`?`". Its length doesn't exceed 5Β·10^{4}. Then there follow *m* lines, where *m* is the number of characters "`?`" in the pattern. Each line contains two integer numbers *a*_{*i*} and *b*_{*i*} (1 ≀ *a*_{*i*},  *b*_{*...
Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print `-1`, if there is no answer. If the answer is not unique, print any of them.
null
null
[ { "input": "(??)\n1 2\n2 8\n", "output": "4\n()()\n" } ]
ok
4A
4
A
Watermelon
800
[ "brute force", "math" ]
734,209
null
Codeforces Beta Round 4 (Div. 2 Only)
2010-03-12
Div. 2
https://codeforces.com/problemset/problem/4/A
1
64
file
false
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1 ≀ *w* ≀ 100) β€” the weight of the watermelon bought by the boys.
Print `YES`, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and `NO` in the opposite case.
null
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant β€” two parts of 4 and 4 kilos).
[ { "input": "8\n", "output": "YES\n" } ]
ok
4B
4
B
Before an Exam
1,200
[ "constructive algorithms", "greedy" ]
30,745
null
Codeforces Beta Round 4 (Div. 2 Only)
2010-03-12
Div. 2
https://codeforces.com/problemset/problem/4/B
0.5
64
file
false
Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime*_{*i*} and not more than *maxTime*_{*i*} hours per each *i*-th...
The first input line contains two integer numbers *d*, *sumTime* (1 ≀ *d* ≀ 30, 0 ≀ *sumTime* ≀ 240) β€” the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime*_{*i*}, *maxTime*_{*i*} (0 ≀ *minTime*_{*i*} ≀...
In the first line print `YES`, and in the second line print *d* numbers (separated by a space), each of the numbers β€” amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print `NO` in the unique line. If there are many solutions, print any of them.
null
null
[ { "input": "1 48\n5 7\n", "output": "NO\n" }, { "input": "2 5\n0 1\n3 5\n", "output": "YES\n1 4 \n" } ]
ok
4C
4
C
Registration system
1,300
[ "data structures", "hashing", "implementation" ]
116,401
null
Codeforces Beta Round 4 (Div. 2 Only)
2010-03-12
Div. 2
https://codeforces.com/problemset/problem/4/C
5
64
file
false
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. ...
The first line contains number *n* (1 ≀ *n* ≀ 10^{5}). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: `OK` in case of successful registration, or a prompt with a new name, if the requested name is already taken.
null
null
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab\n", "output": "OK\nOK\nabacaba1\nOK\n" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" } ]
ok
4D
4
D
Mysterious Present
1,700
[ "dp", "sortings" ]
12,667
null
Codeforces Beta Round 4 (Div. 2 Only)
2010-03-12
Div. 2
https://codeforces.com/problemset/problem/4/D
1
64
file
false
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a *chain*. Chain here is such a sequence of envelopes *A* = {*a*_{1},  *a*_{2},  ...,  *a*_{*n*}}, where the width and the height of the *i*-th envelope is strictly higher than ...
The first line contains integers *n*, *w*, *h* (1  ≀ *n* ≀ 5000, 1 ≀ *w*,  *h*  ≀ 10^{6}) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow *n* lines, each of them contains two integer numbers *w*_{*i*} and *h*_{*i*} β€” width and height of the *i*-th envelope (1 ≀ *w*_{*i*},  *h*...
In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, pr...
null
null
[ { "input": "2 1 1\n2 2\n2 2\n", "output": "1\n1 \n" }, { "input": "3 3 3\n5 4\n12 11\n9 8\n", "output": "3\n1 3 2 \n" } ]
ok
5A
5
A
Chat Server's Outgoing Traffic
1,000
[ "implementation" ]
11,525
null
Codeforces Beta Round 5
2010-03-20
Other
https://codeforces.com/problemset/problem/5/A
1
64
file
false
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person ...
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - `+<name>` for `'Add'` command. - `-<name>` for `'Remove'` command. - `<sender_name>:<message_text>` for `'Send'` command. `<name>` and `<sender_name>` is a non...
Print a single number β€” answer to the problem.
null
null
[ { "input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n", "output": "9\n" }, { "input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n", "output": "14\n" } ]
ok
5B
5
B
Center Alignment
1,200
[ "implementation", "strings" ]
7,084
null
Codeforces Beta Round 5
2010-03-20
Other
https://codeforces.com/problemset/problem/5/B
1
64
file
false
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment in the shortest possible time. Good luck!
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
Format the given text, aligning it center. Frame the whole text with characters Β«`*`Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and br...
null
null
[ { "input": "This is\n\nCodeforces\nBeta\nRound\n5\n", "output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n" }, { "input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n", "output": "****************\n*welcome...
ok
5C
5
C
Longest Regular Bracket Sequence
1,900
[ "constructive algorithms", "data structures", "dp", "greedy", "sortings", "strings" ]
19,367
null
Codeforces Beta Round 5
2010-03-20
Other
https://codeforces.com/problemset/problem/5/C
2
256
file
false
This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting Β«`+`Β» and Β«`1`Β» into it we can get a correct mathematical expression. For example, sequences Β«`(())()`Β», Β«`()`Β» and Β«`(()(()))`Β» are regular, while Β«`)(`Β», Β«`(()`Β» and Β«`(...
The first line of the input file contains a non-empty string, consisting of Β«`(`Β» and Β«`)`Β» characters. Its length does not exceed 10^{6}.
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "`0 1`".
null
null
[ { "input": ")((())))(()())\n", "output": "6 2\n" }, { "input": "))(\n", "output": "0 1\n" } ]
ok
5D
5
D
Follow Traffic Rules
2,100
[ "implementation", "math" ]
2,030
null
Codeforces Beta Round 5
2010-03-20
Other
https://codeforces.com/problemset/problem/5/D
1
64
file
false
Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the ro...
The first line of the input file contains two integer numbers *a* and *v* (1 ≀ *a*, *v* ≀ 10000). The second line contains three integer numbers *l*, *d* and *w* (2 ≀ *l* ≀ 10000; 1 ≀ *d* < *l*; 1 ≀ *w* ≀ 10000).
Print the answer with at least five digits after the decimal point.
null
null
[ { "input": "1 1\n2 1 3\n", "output": "2.500000000000\n" }, { "input": "5 70\n200 170 40\n", "output": "8.965874696353\n" } ]
ok
5E
5
E
Bindian Signalizing
2,400
[ "data structures" ]
2,646
null
Codeforces Beta Round 5
2010-03-20
Other
https://codeforces.com/problemset/problem/5/E
4
256
file
false
Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by *n* hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman co...
The first line of the input data contains an integer number *n* (3 ≀ *n* ≀ 10^{6}), *n* β€” the amount of hills around the capital. The second line contains *n* numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 10^{9}.
Print the required amount of pairs.
null
null
[ { "input": "5\n1 2 4 5 3\n", "output": "7\n" } ]
ok
6A
6
A
Triangle
900
[ "brute force", "geometry" ]
23,820
null
Codeforces Beta Round 6 (Div. 2 Only)
2010-03-27
Div. 2
https://codeforces.com/problemset/problem/6/A
2
64
file
false
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β€” lengthes of the sticks.
Output `TRIANGLE` if it is possible to construct a non-degenerate triangle. Output `SEGMENT` if the first case cannot take place and it is possible to construct a degenerate triangle. Output `IMPOSSIBLE` if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break...
null
null
[ { "input": "4 2 1 3\n", "output": "TRIANGLE\n" }, { "input": "7 2 2 4\n", "output": "SEGMENT\n" }, { "input": "3 5 9 1\n", "output": "IMPOSSIBLE\n" } ]
ok
6B
6
B
President's Office
1,100
[ "implementation" ]
15,363
null
Codeforces Beta Round 6 (Div. 2 Only)
2010-03-27
Div. 2
https://codeforces.com/problemset/problem/6/B
2
64
file
false
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ...
The first line contains two separated by a space integer numbers *n*, *m* (1 ≀ *n*, *m* ≀ 100) β€” the length and the width of the office-room, and *c* character β€” the President's desk colour. The following *n* lines contain *m* characters each β€” the office-room description. It is guaranteed that the colour of each desk ...
Print the only number β€” the amount of President's deputies.
null
null
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.\n", "output": "2\n" }, { "input": "3 3 Z\n...\n.H.\n..Z\n", "output": "0\n" } ]
ok
6C
6
C
Alice, Bob and Chocolate
1,200
[ "greedy", "two pointers" ]
19,005
null
Codeforces Beta Round 6 (Div. 2 Only)
2010-03-27
Div. 2
https://codeforces.com/problemset/problem/6/C
2
64
file
false
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi...
The first line contains one integer *n* (1 ≀ *n* ≀ 10^{5}) β€” the amount of bars on the table. The second line contains a sequence *t*_{1}, *t*_{2}, ..., *t*_{*n*} (1 ≀ *t*_{*i*} ≀ 1000), where *t*_{*i*} is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
null
null
[ { "input": "5\n2 9 8 2 7\n", "output": "2 3\n" } ]
ok
6D
6
D
Lizards and Basements 2
2,600
[ "brute force", "dp" ]
2,374
null
Codeforces Beta Round 6 (Div. 2 Only)
2010-03-27
Div. 2
https://codeforces.com/problemset/problem/6/D
2
64
file
false
*This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.* Polycarp likes to play computer role-playing game Β«Lizards and BasementsΒ». At the moment he is playing it as a magician. At one of the l...
The first line of the input contains three integers *n*, *a*, *b* (3 ≀ *n* ≀ 10; 1 ≀ *b* < *a* ≀ 10). The second line contains a sequence of *n* integers β€” *h*_{1}, *h*_{2}, ..., *h*_{*n*} (1 ≀ *h*_{*i*} ≀ 15), where *h*_{*i*} is the amount of health points the *i*-th archer has.
In the first line print *t* β€” the required minimum amount of fire balls. In the second line print *t* numbers β€” indexes of the archers that Polycarp should hit to kill all the archers in *t* shots. All these numbers should be between 2 and *n* - 1. Separate numbers with spaces. If there are several solutions, output a...
null
null
[ { "input": "3 2 1\n2 2 2\n", "output": "3\n2 2 2 \n" }, { "input": "4 3 1\n1 4 1 1\n", "output": "4\n2 2 3 3 \n" } ]
ok
6E
6
E
Exposition
1,900
[ "binary search", "data structures", "dsu", "trees", "two pointers" ]
4,112
null
Codeforces Beta Round 6 (Div. 2 Only)
2010-03-27
Div. 2
https://codeforces.com/problemset/problem/6/E
1.5
64
file
false
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub...
The first line of the input data contains two integer numbers separated by a space *n* (1 ≀ *n* ≀ 10^{5}) and *k* (0 ≀ *k* ≀ 10^{6}) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separate...
In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* β€” the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and th...
null
null
[ { "input": "3 3\n14 12 10\n", "output": "2 2\n1 2\n2 3\n" }, { "input": "2 0\n10 10\n", "output": "2 1\n1 2\n" }, { "input": "4 5\n8 19 10 13\n", "output": "2 1\n3 4\n" } ]
ok
7A
7
A
Kalevitch and Chess
1,100
[ "brute force", "constructive algorithms" ]
8,344
null
Codeforces Beta Round 7
2010-04-01
Other
https://codeforces.com/problemset/problem/7/A
2
64
file
false
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, th...
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, `W` character stands for a white square, and `B` character β€” for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertic...
Output the only number β€” the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
null
null
[ { "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n", "output": "3\n" }, { "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n", "output": "1\n" } ]
ok
7B
7
B
Memory Manager
1,600
[ "implementation" ]
3,050
null
Codeforces Beta Round 7
2010-04-01
Other
https://codeforces.com/problemset/problem/7/B
1
64
file
false
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet β€” the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations: -...
The first line of the input data contains two positive integers *t* and *m* (1 ≀ *t* ≀ 100;1 ≀ *m* ≀ 100), where *t* β€” the amount of operations given to the memory manager for processing, and *m* β€” the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The first opera...
Output the sequence of lines. Each line should contain either the result of `alloc` operation procession , or `ILLEGAL_ERASE_ARGUMENT` as a result of failed `erase` operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of `alloc` operation should ret...
null
null
[ { "input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n", "output": "1\n2\nNULL\n3\n" } ]
ok
7C
7
C
Line
1,800
[ "math", "number theory" ]
5,862
null
Codeforces Beta Round 7
2010-04-01
Other
https://codeforces.com/problemset/problem/7/C
1
256
file
false
A line on the plane is described by an equation *Ax* + *By* + *C* = 0. You are to find any point on this line, whose coordinates are integer numbers from  - 5Β·10^{18} to 5Β·10^{18} inclusive, or to find out that such points do not exist.
The first line contains three integers *A*, *B* and *C* ( - 2Β·10^{9} ≀ *A*, *B*, *C* ≀ 2Β·10^{9}) β€” corresponding coefficients of the line equation. It is guaranteed that *A*^{2} + *B*^{2} > 0.
If the required point exists, output its coordinates, otherwise output `-1`.
null
null
[ { "input": "2 5 3\n", "output": "6 -3\n" } ]
ok
7D
7
D
Palindrome Degree
2,200
[ "hashing", "strings" ]
4,861
null
Codeforces Beta Round 7
2010-04-01
Other
https://codeforces.com/problemset/problem/7/D
1
256
file
false
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length ![](https://espresso.codeforces.com/baaa1cf00a178570d9b63b0518b73899b9a96307.png) are (*k* - 1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of s...
The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5Β·10^{6}. The string is case-sensitive.
Output the only number β€” the sum of the polindrome degrees of all the string's prefixes.
null
null
[ { "input": "a2A\n", "output": "1\n" }, { "input": "abacaba\n", "output": "6\n" } ]
ok
7E
7
E
Defining Macros
2,600
[ "dp", "expression parsing", "implementation" ]
825
null
Codeforces Beta Round 7
2010-04-01
Other
https://codeforces.com/problemset/problem/7/E
3
256
file
false
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. T...
The first line contains the only number *n* (0 ≀ *n* ≀ 100) β€” the amount of #define constructions in the given program. Then there follow *n* lines, each of them contains just one #define construction. Each construction has the following syntax: **#define** *name* *expression* where - *name* β€” the macro name, - *ex...
Output "OK", if the expression is correct according to the above given criterion, otherwise output "Suspicious".
null
null
[ { "input": "1\n#define sum x + y\n1 * sum\n", "output": "Suspicious\n" }, { "input": "1\n#define sum (x + y)\nsum - sum\n", "output": "OK\n" }, { "input": "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr\n", "output": "OK\n" ...
ok
8A
8
A
Train and Peter
1,200
[ "strings" ]
6,979
null
Codeforces Beta Round 8
2010-04-08
Other
https://codeforces.com/problemset/problem/8/A
1
64
file
false
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy starte...
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 10^{5}, the string consists of lowercase Latin letters β€” the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second l...
Output one of the four words without inverted commas: - Β«`forward`Β» β€” if Peter could see such sequences only on the way from A to B; - Β«`backward`Β» β€” if Peter could see such sequences on the way from B to A; - Β«`both`Β» β€” if Peter could see such sequences both on the way from A to B, and on the way from B to A; - Β«`fan...
null
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
[ { "input": "atob\na\nb\n", "output": "forward\n" }, { "input": "aaacaaa\naca\naa\n", "output": "both\n" } ]
ok
8B
8
B
Obsession with Robots
1,400
[ "constructive algorithms", "graphs", "implementation" ]
5,140
null
Codeforces Beta Round 8
2010-04-08
Other
https://codeforces.com/problemset/problem/8/B
2
64
file
false
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ...
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters `L`, `R`, `U` and `D`, standing for movements left, right, up and down respectively. The length of the string does not exceed `100`.
In the first line output the only word `OK` (if the above described map exists), or `BUG` (if such a map does not exist).
null
null
[ { "input": "LLUUUR\n", "output": "OK\n" }, { "input": "RRUULLDD\n", "output": "BUG\n" } ]
ok
8C
8
C
Looking for Order
2,000
[ "bitmasks", "dp" ]
4,568
null
Codeforces Beta Round 8
2010-04-08
Other
https://codeforces.com/problemset/problem/8/C
4
512
file
false
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess β€” all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl canno...
The first line of the input file contains the handbag's coordinates *x*_{*s*}, *y*_{*s*}. The second line contains number *n* (1 ≀ *n* ≀ 24) β€” the amount of objects the girl has. The following *n* lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions ar...
In the first line output the only number β€” the minimum time the girl needs to put the objects into her handbag. In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to *n*), the handbag's point is described by number 0. The path should start and...
null
null
[ { "input": "0 0\n2\n1 1\n-1 1\n", "output": "8\n0 1 2 0 \n" }, { "input": "1 1\n3\n4 3\n3 4\n0 0\n", "output": "32\n0 1 2 0 3 0 \n" } ]
ok
8D
8
D
Two Friends
2,600
[ "binary search", "geometry" ]
605
null
Codeforces Beta Round 8
2010-04-08
Other
https://codeforces.com/problemset/problem/8/D
1
64
file
false
Two neighbours, Alan and Bob, live in the city, where there are three buildings only: a cinema, a shop and the house, where they live. The rest is a big asphalt square. Once they went to the cinema, and the film impressed them so deeply, that when they left the cinema, they did not want to stop discussing it. Bob wan...
The first line contains two integers: *t*_{1}, *t*_{2} (0 ≀ *t*_{1}, *t*_{2} ≀ 100). The second line contains the cinema's coordinates, the third one β€” the house's, and the last line β€” the shop's. All the coordinates are given in meters, are integer, and do not exceed 100 in absolute magnitude. No two given places are...
In the only line output one number β€” the maximum distance that Alan and Bob will cover together, discussing the film. Output the answer accurate to not less than 4 decimal places.
null
null
[ { "input": "0 2\n0 0\n4 0\n-3 0\n", "output": "1.0000000000\n" }, { "input": "0 0\n0 0\n2 0\n1 0\n", "output": "2.0000000000\n" } ]
ok
8E
8
E
Beads
2,600
[ "dp", "graphs" ]
832
null
Codeforces Beta Round 8
2010-04-08
Other
https://codeforces.com/problemset/problem/8/E
5
64
file
false
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth β€” Masha. He knows that Masha likes two colours: blue and red, β€” and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on...
The input file contains two integers *n* and *k* (2 ≀ *n* ≀ 50;1 ≀ *k* ≀ 10^{16}) β€”the length of a string of beads, and the index of the string, chosen by Zorg.
Output the *k*-th string of beads, putting 0 for a red bead, and 1 β€” for a blue one. If it s impossible to find the required string, output the only number `-1`.
null
Let's consider the example of strings of length 4 β€” 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110. Zorg will divide them into heaps: {0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}. Then he will choose the minimum strings of beads in each...
[ { "input": "4 4\n", "output": "0101\n" } ]
ok
9A
9
A
Die Roll
800
[ "math", "probabilities" ]
73,117
null
Codeforces Beta Round 9 (Div. 2 Only)
2010-04-11
Div. 2
https://codeforces.com/problemset/problem/9/A
1
64
file
false
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers `Y` and `W` β€” the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format Β«`A/B`Β», where `A` β€” the numerator, and `B` β€” the denominator. If the required probability equals to zero, output Β«`0/1`Β». If the required probability equals to 1, output Β«`1/1`Β».
null
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
[ { "input": "4 2\n", "output": "1/2\n" } ]
ok
9B
9
B
Running Student
1,200
[ "brute force", "geometry", "implementation" ]
6,375
null
Codeforces Beta Round 9 (Div. 2 Only)
2010-04-11
Div. 2
https://codeforces.com/problemset/problem/9/B
1
64
file
false
And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*. Poor Student knows the following: - during one run the minibus makes *n*...
The first line contains three integer numbers: 2 ≀ *n* ≀ 100, 1 ≀ *v*_{*b*}, *v*_{*s*} ≀ 1000. The second line contains *n* non-negative integers in ascending order: coordinates *x*_{*i*} of the bus stop with index *i*. It is guaranteed that *x*_{1} equals to zero, and *x*_{*n*} ≀ 10^{5}. The third line contains the co...
In the only line output the answer to the problem β€” index of the optimum bus stop.
null
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
[ { "input": "4 5 2\n0 2 4 6\n4 1\n", "output": "3\n" }, { "input": "2 1 1\n0 100000\n100000 100000\n", "output": "2\n" } ]
ok
9C
9
C
Hexadecimal's Numbers
1,200
[ "brute force", "implementation", "math" ]
14,669
null
Codeforces Beta Round 9 (Div. 2 Only)
2010-04-11
Div. 2
https://codeforces.com/problemset/problem/9/C
1
64
file
false
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy. But his plan failed. The reason for th...
Input data contains the only number *n* (1 ≀ *n* ≀ 10^{9}).
Output the only number β€” answer to the problem.
null
For *n* = 10 the answer includes numbers 1 and 10.
[ { "input": "10\n", "output": "2\n" } ]
ok
9D
9
D
How many trees?
1,900
[ "combinatorics", "divide and conquer", "dp" ]
4,711
null
Codeforces Beta Round 9 (Div. 2 Only)
2010-04-11
Div. 2
https://codeforces.com/problemset/problem/9/D
1
64
file
false
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong β€” the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure β€” and then terribl...
The input data contains two space-separated positive integer numbers *n* and *h* (*n* ≀ 35, *h* ≀ *n*).
Output one number β€” the answer to the problem. It is guaranteed that it does not exceed 9Β·10^{18}.
null
null
[ { "input": "3 2\n", "output": "5\n" }, { "input": "3 3\n", "output": "4\n" } ]
ok
9E
9
E
Interesting Graph and Apples
2,300
[ "dfs and similar", "dsu", "graphs" ]
1,208
null
Codeforces Beta Round 9 (Div. 2 Only)
2010-04-11
Div. 2
https://codeforces.com/problemset/problem/9/E
1
64
file
false
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life Β«interesting graph and applesΒ». An undirected graph is called interesting, if each of its vertices belongs to one cycle only β€” a funny ring β€” and does not belong to any other cycles. A f...
The first line of the input data contains a pair of integers *n* and *m* (1 ≀ *n* ≀ 50, 0 ≀ *m* ≀ 2500) β€” the amount of vertices and edges respectively. The following lines contain pairs of numbers *x*_{*i*} and *y*_{*i*} (1 ≀ *x*_{*i*}, *y*_{*i*} ≀ *n*) β€” the vertices that are already connected by edges. The initial g...
In the first line output Β«`YES`Β» or Β«`NO`Β»: if it is possible or not to construct an interesting graph. If the answer is Β«`YES`Β», in the second line output *k* β€” the amount of edges that should be added to the initial graph. Finally, output *k* lines: pairs of vertices *x*_{*j*} and *y*_{*j*}, between which edges shoul...
null
null
[ { "input": "3 2\n1 2\n2 3\n", "output": "YES\n1\n1 3\n" } ]
ok
10A
10
A
Power Consumption Calculation
900
[ "implementation" ]
8,661
null
Codeforces Beta Round 10
2010-04-15
Other
https://codeforces.com/problemset/problem/10/A
1
256
file
false
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*_{1} watt per minute. *T*_{1} minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*_{2} watt per minute. Finally,...
The first line contains 6 integer numbers *n*, *P*_{1}, *P*_{2}, *P*_{3}, *T*_{1}, *T*_{2} (1 ≀ *n* ≀ 100, 0 ≀ *P*_{1}, *P*_{2}, *P*_{3} ≀ 100, 1 ≀ *T*_{1}, *T*_{2} ≀ 60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l*_{*i*} and *r*_{*i*} ...
Output the answer to the problem.
null
null
[ { "input": "1 3 2 1 5 10\n0 10\n", "output": "30\n" }, { "input": "2 8 4 2 5 10\n20 30\n50 100\n", "output": "570\n" } ]
ok
10B
10
B
Cinema Cashier
1,500
[ "dp", "implementation" ]
2,150
null
Codeforces Beta Round 10
2010-04-15
Other
https://codeforces.com/problemset/problem/10/B
1
256
file
false
All cinema halls in Berland are rectangles with *K* rows of *K* seats each, and *K* is an odd number. Rows and seats are numbered from 1 to *K*. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is th...
The first line contains two integers *N* and *K* (1 ≀ *N* ≀ 1000, 1 ≀ *K* ≀ 99) β€” the amount of requests and the hall size respectively. The second line contains *N* space-separated integers *M*_{*i*} from the range [1, *K*] β€” requests to the program.
Output *N* lines. In the *i*-th line output Β«-1Β» (without quotes), if it is impossible to find *M*_{*i*} successive seats in one row, otherwise output three numbers *x*, *y*_{*l*}, *y*_{*r*}. Separate the numbers with a space.
null
null
[ { "input": "2 1\n1 1\n", "output": "1 1 1\n-1\n" }, { "input": "4 3\n1 2 3 1\n", "output": "2 2 2\n1 1 2\n3 1 3\n2 1 1\n" } ]
ok
10C
10
C
Digital Root
2,000
[ "number theory" ]
1,818
null
Codeforces Beta Round 10
2010-04-15
Other
https://codeforces.com/problemset/problem/10/C
2
256
file
false
Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1, *N*], and it was asked to check whether the equation *AB* = *C* is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root *d*(*x*) ...
The first line contains the only number *N* (1 ≀ *N* ≀ 10^{6}).
Output one number β€” the amount of required *A*, *B* and *C* from the range [1, *N*].
null
For the first sample the required triples are (3, 4, 3) and (4, 3, 3).
[ { "input": "4\n", "output": "2\n" }, { "input": "5\n", "output": "6\n" } ]
ok
10D
10
D
LCIS
2,800
[ "dp" ]
6,107
null
Codeforces Beta Round 10
2010-04-15
Other
https://codeforces.com/problemset/problem/10/D
1
256
file
false
*This problem differs from one which was on the online contest.* The sequence *a*_{1}, *a*_{2}, ..., *a*_{*n*} is called increasing, if *a*_{*i*} < *a*_{*i* + 1} for *i* < *n*. The sequence *s*_{1}, *s*_{2}, ..., *s*_{*k*} is called the subsequence of the sequence *a*_{1}, *a*_{2}, ..., *a*_{*n*}, if there exist such...
The first line contains an integer *n* (1 ≀ *n* ≀ 500) β€” the length of the first sequence. The second line contains *n* space-separated integers from the range [0, 10^{9}] β€” elements of the first sequence. The third line contains an integer *m* (1 ≀ *m* ≀ 500) β€” the length of the second sequence. The fourth line contai...
In the first line output *k* β€” the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.
null
null
[ { "input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n", "output": "3\n3 5 6 \n" }, { "input": "5\n1 2 0 2 1\n3\n1 0 1\n", "output": "2\n0 1 \n" } ]
ok
10E
10
E
Greedy Change
2,600
[ "constructive algorithms" ]
975
null
Codeforces Beta Round 10
2010-04-15
Other
https://codeforces.com/problemset/problem/10/E
2
256
file
false
Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of *n* coins of different face values, and the coins of each value are not limited in number. The task is to collect...
The first line contains an integer *n* (1 ≀ *n* ≀ 400) β€” the amount of the coins' face values. The second line contains *n* integers *a*_{*i*} (1 ≀ *a*_{*i*} ≀ 10^{9}), describing the face values. It is guaranteed that *a*_{1} > *a*_{2} > ... > *a*_{*n*} and *a*_{*n*} = 1.
If greedy algorithm collects any sum in an optimal way, output -1. Otherwise output the smallest sum that greedy algorithm collects in a non-optimal way.
null
null
[ { "input": "5\n25 10 5 2 1\n", "output": "-1\n" }, { "input": "3\n4 3 1\n", "output": "6\n" } ]
ok
11A
11
A
Increasing Sequence
900
[ "constructive algorithms", "implementation", "math" ]
16,101
null
Codeforces Beta Round 11
2010-04-26
Other
https://codeforces.com/problemset/problem/11/A
1
64
file
false
A sequence *a*_{0}, *a*_{1}, ..., *a*_{*t* - 1} is called increasing if *a*_{*i* - 1} < *a*_{*i*} for each *i*: 0 < *i* < *t*. You are given a sequence *b*_{0}, *b*_{1}, ..., *b*_{*n* - 1} and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least num...
The first line of the input contains two integer numbers *n* and *d* (2 ≀ *n* ≀ 2000, 1 ≀ *d* ≀ 10^{6}). The second line contains space separated sequence *b*_{0}, *b*_{1}, ..., *b*_{*n* - 1} (1 ≀ *b*_{*i*} ≀ 10^{6}).
Output the minimal number of moves needed to make the sequence increasing.
null
null
[ { "input": "4 2\n1 3 3 2\n", "output": "3\n" } ]
ok
11B
11
B
Jumping Jack
1,600
[ "math" ]
5,919
null
Codeforces Beta Round 11
2010-04-26
Other
https://codeforces.com/problemset/problem/11/B
1
64
file
false
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri...
The input data consists of only one integer *x* ( - 10^{9} ≀ *x* ≀ 10^{9}).
Output the minimal number of jumps that Jack requires to reach *x*.
null
null
[ { "input": "2\n", "output": "3\n" }, { "input": "6\n", "output": "3\n" }, { "input": "0\n", "output": "0\n" } ]
ok
11C
11
C
How Many Squares?
2,200
[ "implementation" ]
755
null
Codeforces Beta Round 11
2010-04-26
Other
https://codeforces.com/problemset/problem/11/C
2
64
file
false
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares: 1. squares with each side parallel to a side of the matrix; 2. squares with each side para...
The first line contains integer *t* (1 ≀ *t* ≀ 10000), where *t* is the number of test cases in the input. Then test cases follow. Each case starts with a line containing integers *n* and *m* (2 ≀ *n*, *m* ≀ 250), where *n* is the number of rows and *m* is the number of columns. The following *n* lines contain *m* char...
You should output exactly *t* lines, with the answer to the *i*-th test case on the *i*-th line.
null
null
[ { "input": "2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000\n", "output": "1\n2\n" }, { "input": "1\n12 11\n11111111111\n10000000001\n...
ok
11D
11
D
A Simple Task
2,200
[ "bitmasks", "dp", "graphs" ]
7,072
null
Codeforces Beta Round 11
2010-04-26
Other
https://codeforces.com/problemset/problem/11/D
2
256
file
false
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.
The first line of input contains two integers *n* and *m* (1 ≀ *n* ≀ 19, 0 ≀ *m*) – respectively the number of vertices and edges of the graph. Each of the subsequent *m* lines contains two integers *a* and *b*, (1 ≀ *a*, *b* ≀ *n*, *a* ≠ *b*) indicating that vertices *a* and *b* are connected by an undirected edge. Th...
Output the number of cycles in the given graph.
null
The example graph is a clique and contains four cycles of length 3 and three cycles of length 4.
[ { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "7\n" } ]
ok
11E
11
E
Forward, march!
2,800
[ "binary search", "dp", "greedy" ]
503
null
Codeforces Beta Round 11
2010-04-26
Other
https://codeforces.com/problemset/problem/11/E
1
64
file
false
Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or β€” horror of horrors! β€” stops for a while. For example, i...
The first line of input contains a sequence consisting only of characters '`L`', '`R`' and '`X`', where '`L`' corresponds to a step with the left foot, '`R`' β€” with the right foot, and '`X`' β€” to a break. The length of the sequence will not exceed 10^{6}.
Output the maximum percentage of time that Jack can spend marching correctly, **rounded down to exactly six digits after the decimal point**.
null
In the second example, if we add two breaks to receive `LXXRXR`, Jack will march: `LXXRXRLXXRXRL`... instead of `LRLRLRLRLRLRL`... and will make the correct step in half the cases. If we didn't add any breaks, the sequence would be incorrect β€” Jack can't step on his right foot twice in a row.
[ { "input": "X\n", "output": "0.000000\n" }, { "input": "LXRR\n", "output": "50.000000\n" } ]
ok
12A
12
A
Super Agent
800
[ "implementation" ]
16,105
null
Codeforces Beta Round 12 (Div 2 Only)
2010-04-29
Other
https://codeforces.com/problemset/problem/12/A
2
256
file
false
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
Input contains the matrix of three rows of three symbols each. Symbol Β«`X`Β» means that the corresponding button was pressed, and Β«`.`Β» means that is was not pressed. The matrix may contain no Β«`X`Β», also it may contain no Β«`.`Β».
Print `YES` if the password is symmetric with respect to the central button of the terminal and `NO` otherwise.
null
If you are not familiar with the term Β«central symmetryΒ», you may look into http://en.wikipedia.org/wiki/Central_symmetry
[ { "input": "XX.\n...\n.XX\n", "output": "YES\n" }, { "input": "X.X\nX..\n...\n", "output": "NO\n" } ]
ok
12B
12
B
Correct Solution?
1,100
[ "implementation", "sortings" ]
9,985
null
Codeforces Beta Round 12 (Div 2 Only)
2010-04-29
Other
https://codeforces.com/problemset/problem/12/B
2
256
file
false
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: β€”Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe...
The first line contains one integer *n* (0 ≀ *n* ≀ 10^{9}) without leading zeroes. The second lines contains one integer *m* (0 ≀ *m* ≀ 10^{9}) β€” Bob's answer, possibly with leading zeroes.
Print `OK` if Bob's answer is correct and `WRONG_ANSWER` otherwise.
null
null
[ { "input": "3310\n1033\n", "output": "OK\n" }, { "input": "4\n5\n", "output": "WRONG_ANSWER\n" } ]
ok
12C
12
C
Fruits
1,100
[ "greedy", "implementation", "sortings" ]
7,631
null
Codeforces Beta Round 12 (Div 2 Only)
2010-04-29
Other
https://codeforces.com/problemset/problem/12/C
1
256
file
false
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of As...
The first line of the input contains two integer number *n* and *m* (1 ≀ *n*, *m* ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them d...
Print two numbers *a* and *b* (*a* ≀ *b*) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
null
null
[ { "input": "5 3\n4 2 1 10 5\napple\norange\nmango\n", "output": "7 19\n" }, { "input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n", "output": "11 30\n" } ]
ok
12D
12
D
Ball
2,400
[ "data structures", "sortings" ]
3,147
null
Codeforces Beta Round 12 (Div 2 Only)
2010-04-29
Other
https://codeforces.com/problemset/problem/12/D
2
256
file
false
*N* ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ...
The first line contains one integer *N* (1 ≀ *N* ≀ 500000). The second line contains *N* integer numbers *B*_{*i*}, separated by single spaces. The third and the fourth lines contain sequences *I*_{*i*} and *R*_{*i*} in the same format. It is guaranteed that 0 ≀ *B*_{*i*}, *I*_{*i*}, *R*_{*i*} ≀ 10^{9}.
Output the answer to the problem.
null
null
[ { "input": "3\n1 4 2\n4 3 2\n2 5 3\n", "output": "1\n" } ]
ok
12E
12
E
Start of the season
2,100
[ "constructive algorithms" ]
1,608
null
Codeforces Beta Round 12 (Div 2 Only)
2010-04-29
Other
https://codeforces.com/problemset/problem/12/E
2
256
file
false
Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size *n* × *n* (*n* is even number). Gods will never allow to start the championship without it. Matrix should contain integers from 0 to *n* - 1, main diagonal should con...
The first line contains one integer *n* (2 ≀ *n* ≀ 1000), *n* is even.
Output *n* lines with *n* numbers each β€” the required matrix. Separate numbers with spaces. If there are several solutions, output any.
null
null
[ { "input": "2\n", "output": "0 1\n1 0\n" }, { "input": "4\n", "output": "0 1 3 2\n1 0 2 3\n3 2 0 1\n2 3 1 0\n" } ]
ok
13A
13
A
Numbers
1,000
[ "implementation", "math" ]
9,777
null
Codeforces Beta Round 13
2010-05-06
Other
https://codeforces.com/problemset/problem/13/A
1
64
file
false
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A* - 1. Note that all com...
Input contains one integer number *A* (3 ≀ *A* ≀ 1000).
Output should contain required average value in format Β«`X/Y`Β», where `X` is the numerator and `Y` is the denominator.
null
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
[ { "input": "5\n", "output": "7/3\n" }, { "input": "3\n", "output": "2/1\n" } ]
ok
13B
13
B
Letter A
2,000
[ "geometry", "implementation" ]
1,190
null
Codeforces Beta Round 13
2010-05-06
Other
https://codeforces.com/problemset/problem/13/B
0.5
64
file
false
Little Petya learns how to write. The teacher gave pupils the task to write the letter *A* on the sheet of paper. It is required to check whether Petya really had written the letter *A*. You are given three segments on the plane. They form the letter *A* if the following conditions hold: - Two segments have a common ...
The first line contains one integer *t* (1 ≀ *t* ≀ 10000) β€” the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β€” coordinates of the endpoints of one of the segments. All coordinates do not exceed 10^{8} by absolute value. All segments h...
Output one line for each test case. Print Β«`YES`Β» (without quotes), if the segments form the letter *A* and Β«`NO`Β» otherwise.
null
null
[ { "input": "3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1\n", "output": "YES\nNO\nYES\n" } ]
ok
13C
13
C
Sequence
2,200
[ "dp", "sortings" ]
5,766
null
Codeforces Beta Round 13
2010-05-06
Other
https://codeforces.com/problemset/problem/13/C
1
64
file
false
Little Petya likes to play very much. And most of all he likes to play the following game: He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of s...
The first line of the input contains single integer *N* (1 ≀ *N* ≀ 5000) β€” the length of the initial sequence. The following *N* lines contain one integer each β€” elements of the sequence. These numbers do not exceed 10^{9} by absolute value.
Output one integer β€” minimum number of steps required to achieve the goal.
null
null
[ { "input": "5\n3 2 -1 2 11\n", "output": "4\n" }, { "input": "5\n2 1 1 1 1\n", "output": "1\n" } ]
ok
13D
13
D
Triangles
2,600
[ "dp", "geometry" ]
786
null
Codeforces Beta Round 13
2010-05-06
Other
https://codeforces.com/problemset/problem/13/D
2
64
file
false
Little Petya likes to draw. He drew *N* red and *M* blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.
The first line contains two non-negative integer numbers *N* and *M* (0 ≀ *N* ≀ 500, 0 ≀ *M* ≀ 500) β€” the number of red and blue points respectively. The following *N* lines contain two integer numbers each β€” coordinates of red points. The following *M* lines contain two integer numbers each β€” coordinates of blue point...
Output one integer β€” the number of distinct triangles with vertices in red points which do not contain any blue point inside.
null
null
[ { "input": "4 1\n0 0\n10 0\n10 10\n5 4\n2 1\n", "output": "2\n" }, { "input": "5 5\n5 10\n6 1\n8 6\n-6 -7\n7 -1\n5 -1\n10 -4\n-10 -8\n-10 5\n-2 -8\n", "output": "7\n" } ]
ok
13E
13
E
Holes
2,700
[ "data structures", "dsu" ]
8,732
null
Codeforces Beta Round 13
2010-05-06
Other
https://codeforces.com/problemset/problem/13/E
1
64
file
false
Little Petya likes to play a lot. Most of all he likes to play a game Β«HolesΒ». This is a game for one person with following rules: There are *N* holes located in a single row and numbered from left to right with numbers from 1 to *N*. Each hole has it's own power (hole number *i* has the power *a*_{*i*}). If you throw...
The first line contains two integers *N* and *M* (1 ≀ *N* ≀ 10^{5}, 1 ≀ *M* ≀ 10^{5}) β€” the number of holes in a row and the number of moves. The second line contains *N* positive integers not exceeding *N* β€” initial values of holes power. The following *M* lines describe moves made by Petya. Each of these line can be ...
For each move of the type 1 output two space-separated numbers on a separate line β€” the number of the last hole the ball visited before leaving the row and the number of jumps it made.
null
null
[ { "input": "8 5\n1 1 1 1 1 2 8 2\n1 1\n0 1 3\n1 1\n0 3 4\n1 2\n", "output": "8 7\n8 5\n7 3\n" } ]
ok
14A
14
A
Letter
800
[ "implementation" ]
13,049
null
Codeforces Beta Round 14 (Div. 2)
2010-05-19
Div. 2
https://codeforces.com/problemset/problem/14/A
1
64
file
false
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w...
The first line of the input data contains numbers *n* and *m* (1 ≀ *n*, *m* ≀ 50), *n* β€” amount of lines, and *m* β€” amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character Β«`.`Β» stands for a non-shaded square on the sheet, and Β«`*`Β» β€” for a shaded square. It is guaranteed that B...
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
null
null
[ { "input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n", "output": "***\n*..\n***\n*..\n***\n" }, { "input": "3 3\n***\n*.*\n***\n", "output": "***\n*.*\n***\n" } ]
ok
14B
14
B
Young Photographer
1,000
[ "implementation" ]
8,536
null
Codeforces Beta Round 14 (Div. 2)
2010-05-19
Div. 2
https://codeforces.com/problemset/problem/14/B
2
64
file
false
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*_{0} of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training a...
The first line of the input file contains integers *n* and *x*_{0} (1 ≀ *n* ≀ 100; 0 ≀ *x*_{0} ≀ 1000). The following *n* lines contain pairs of integers *a*_{*i*}, *b*_{*i*} (0 ≀ *a*_{*i*}, *b*_{*i*} ≀ 1000; *a*_{*i*} ≠ *b*_{*i*}).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
null
null
[ { "input": "3 3\n0 7\n14 2\n4 6\n", "output": "1\n" } ]
ok
14C
14
C
Four Segments
1,700
[ "brute force", "constructive algorithms", "geometry", "implementation", "math" ]
3,967
null
Codeforces Beta Round 14 (Div. 2)
2010-05-19
Div. 2
https://codeforces.com/problemset/problem/14/C
2
64
file
false
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr...
The input data contain four lines. Each of these lines contains four integers *x*_{1}, *y*_{1}, *x*_{2}, *y*_{2} ( - 10^{9} ≀ *x*_{1}, *y*_{1}, *x*_{2}, *y*_{2} ≀ 10^{9}) β€” coordinates of segment's beginning and end positions. The given segments can degenerate into points.
Output the word Β«`YES`Β», if the given four segments form the required rectangle, otherwise output Β«`NO`Β».
null
null
[ { "input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n", "output": "YES\n" }, { "input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n", "output": "NO\n" } ]
ok
14D
14
D
Two Paths
1,900
[ "dfs and similar", "dp", "graphs", "shortest paths", "trees", "two pointers" ]
5,468
null
Codeforces Beta Round 14 (Div. 2)
2010-05-19
Div. 2
https://codeforces.com/problemset/problem/14/D
2
64
file
false
As you know, Bob's brother lives in Flatland. In Flatland there are *n* cities, connected by *n* - 1 two-way roads. The cities are numbered from 1 to *n*. You can get from one city to another moving along the roads. The Β«Two PathsΒ» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A...
The first line contains an integer *n* (2 ≀ *n* ≀ 200), where *n* is the amount of cities in the country. The following *n* - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road *a*_{*i*}, *b*_{*i*} (1 ≀ *a*_{*i*}, *b*_{*i*} ≀ *n*).
Output the maximum possible profit.
null
null
[ { "input": "4\n1 2\n2 3\n3 4\n", "output": "1\n" }, { "input": "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n", "output": "0\n" }, { "input": "6\n1 2\n2 3\n2 4\n5 4\n6 4\n", "output": "4\n" } ]
ok
14E
14
E
Camels
1,900
[ "dp" ]
2,157
null
Codeforces Beta Round 14 (Div. 2)
2010-05-19
Div. 2
https://codeforces.com/problemset/problem/14/E
2
64
file
false
Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with *t* humps, representing them as polylines in the plane. Each polyline consists of *n* vertices with coordinates (*x*_{1}, *y*_{1}), (*x*_{2}, *y*_{2}), ......
The first line contains a pair of integers *n* and *t* (3 ≀ *n* ≀ 20, 1 ≀ *t* ≀ 10).
Output the required amount of camels with *t* humps.
null
In the first sample test sequences of *y*-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 ΠΈ 234321 (each digit corresponds to one value of *y*_{*i*}).
[ { "input": "6 1\n", "output": "6\n" }, { "input": "4 2\n", "output": "0\n" } ]
ok
15A
15
A
Cottage Village
1,200
[ "implementation", "sortings" ]
4,632
null
Codeforces Beta Round 15
2010-05-29
Other
https://codeforces.com/problemset/problem/15/A
2
64
file
false
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, wher...
The first line of the input data contains numbers *n* and *t* (1 ≀ *n*, *t* ≀ 1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x*_{*i*} *a*_{*i*}, where *x*_{*i*} β€” *x*-coordinate of the centre of the *i*-th house, and *a*_{*i*} β€” length of its side ( - 1000 ≀ *x*_{*i*} ≀ ...
Output the amount of possible positions of the new house.
null
It is possible for the *x*-coordinate of the new house to have non-integer value.
[ { "input": "2 2\n0 4\n6 2\n", "output": "4\n" }, { "input": "2 2\n0 4\n5 2\n", "output": "3\n" }, { "input": "2 3\n0 4\n5 2\n", "output": "2\n" } ]
ok
15B
15
B
Laser
1,800
[ "math" ]
1,748
null
Codeforces Beta Round 15
2010-05-29
Other
https://codeforces.com/problemset/problem/15/B
1
64
file
false
Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of *n* × *m* cells and a robotic arm. Each cell of the field is a 1 × 1 square. The robotic arm has two laser...
The first line contains one integer number *t* (1 ≀ *t* ≀ 10000) β€” the number of test sets. Each of the following *t* lines describes one test set. Each line contains integer numbers *n*, *m*, *x*_{1}, *y*_{1}, *x*_{2}, *y*_{2}, separated by a space (2 ≀ *n*, *m* ≀ 10^{9}, 1 ≀ *x*_{1}, *x*_{2} ≀ *n*, 1 ≀ *y*_{1}, *y*_{...
Each of the *t* lines of the output should contain the answer to the corresponding input test set.
null
null
[ { "input": "2\n4 4 1 1 3 3\n4 3 1 1 2 2\n", "output": "8\n2\n" } ]
ok
15C
15
C
Industrial Nim
2,000
[ "games" ]
3,051
null
Codeforces Beta Round 15
2010-05-29
Other
https://codeforces.com/problemset/problem/15/C
2
64
file
false
There are *n* stone quarries in Petrograd. Each quarry owns *m*_{*i*} dumpers (1 ≀ *i* ≀ *n*). It is known that the first dumper of the *i*-th quarry has *x*_{*i*} stones in it, the second dumper has *x*_{*i*} + 1 stones in it, the third has *x*_{*i*} + 2, and the *m*_{*i*}-th dumper (the last for the *i*-th quarry) h...
The first line of the input contains one integer number *n* (1 ≀ *n* ≀ 10^{5}) β€” the amount of quarries. Then there follow *n* lines, each of them contains two space-separated integers *x*_{*i*} and *m*_{*i*} (1 ≀ *x*_{*i*}, *m*_{*i*} ≀ 10^{16}) β€” the amount of stones in the first dumper of the *i*-th quarry and the nu...
Output Β«`tolik`Β» if the oligarch who takes a stone first wins, and Β«`bolik`Β» otherwise.
null
null
[ { "input": "2\n2 1\n3 2\n", "output": "tolik\n" }, { "input": "4\n1 1\n1 1\n1 1\n1 1\n", "output": "bolik\n" } ]
ok
15D
15
D
Map
2,500
[ "data structures", "implementation", "sortings" ]
993
null
Codeforces Beta Round 15
2010-05-29
Other
https://codeforces.com/problemset/problem/15/D
2
128
file
false
There is an area map that is a rectangular matrix *n* × *m*, each cell of the matrix contains the average height of a corresponding area part. Peter works for a company that has to build several cities within this area, each of the cities will occupy a rectangle *a* × *b* cells on the map. To start construction works i...
The first line contains four space-separated integers: map sizes *n*, *m* and city sizes *a*, *b* (1 ≀ *a* ≀ *n* ≀ 1000, 1 ≀ *b* ≀ *m* ≀ 1000). Then there follow *n* lines, each contains *m* non-negative space-separated numbers, describing the height matrix. Each number doesn't exceed 10^{9}.
In the first line output *k* β€” the amount of constructed cities. In each of the following *k* lines output 3 space-separated numbers β€” the row number and the column number of the upper-left corner of a subsequent construction site, and the amount of the ground to remove from it. Output the sites in the order of their b...
null
null
[ { "input": "2 2 1 2\n1 2\n3 5\n", "output": "2\n1 1 1\n2 1 2\n" }, { "input": "4 4 2 2\n1 5 3 4\n2 7 6 1\n1 1 2 2\n2 2 1 2\n", "output": "3\n3 1 2\n3 3 3\n1 2 9\n" } ]
ok
15E
15
E
Triangles
2,600
[ "combinatorics", "dp" ]
705
null
Codeforces Beta Round 15
2010-05-29
Other
https://codeforces.com/problemset/problem/15/E
1
64
file
false
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has *n* level...
The input data contain the only even integer *n* (2 ≀ *n* ≀ 10^{6}).
Output the only number β€” the amount of Peter's routes modulo 1000000009.
null
null
[ { "input": "2\n", "output": "10\n" }, { "input": "4\n", "output": "74\n" } ]
ok
16A
16
A
Flag
800
[ "implementation" ]
18,055
null
Codeforces Beta Round 16 (Div. 2 Only)
2010-06-03
Div. 2
https://codeforces.com/problemset/problem/16/A
2
64
file
false
According to a new ISO standard, a flag of every country should have a chequered field *n* × *m*, each square should be of one of 10 colours, and the flag should be Β«stripedΒ»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berl...
The first line of the input contains numbers *n* and *m* (1 ≀ *n*, *m* ≀ 100), *n* β€” the amount of rows, *m* β€” the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between `0` and `9`, and stands f...
Output `YES`, if the flag meets the new ISO standard, and `NO` otherwise.
null
null
[ { "input": "3 3\n000\n111\n222\n", "output": "YES\n" }, { "input": "3 3\n000\n000\n111\n", "output": "NO\n" }, { "input": "3 3\n000\n111\n002\n", "output": "NO\n" } ]
ok
16B
16
B
Burglar and Matches
900
[ "greedy", "implementation", "sortings" ]
21,330
null
Codeforces Beta Round 16 (Div. 2 Only)
2010-06-03
Div. 2
https://codeforces.com/problemset/problem/16/B
0.5
64
file
false
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a*_{*i*} matchboxes, and each matchbox contains *b*_{*i*} matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes ...
The first line of the input contains integer *n* (1 ≀ *n* ≀ 2Β·10^{8}) and integer *m* (1 ≀ *m* ≀ 20). The *i* + 1-th line contains a pair of numbers *a*_{*i*} and *b*_{*i*} (1 ≀ *a*_{*i*} ≀ 10^{8}, 1 ≀ *b*_{*i*} ≀ 10). All the input numbers are integer.
Output the only number β€” answer to the problem.
null
null
[ { "input": "7 3\n5 10\n2 5\n3 6\n", "output": "62\n" }, { "input": "3 3\n1 3\n2 2\n3 1\n", "output": "7\n" } ]
ok
16C
16
C
Monitor
1,800
[ "binary search", "number theory" ]
5,568
null
Codeforces Beta Round 16 (Div. 2 Only)
2010-06-03
Div. 2
https://codeforces.com/problemset/problem/16/C
0.5
64
file
false
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a* × *b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*: *y* became popular with users. That's why the company wants to reduce monitor AB999 si...
The first line of the input contains 4 integers β€” *a*, *b*, *x* and *y* (1 ≀ *a*, *b*, *x*, *y* ≀ 2Β·10^{9}).
If the answer exists, output 2 positive integers β€” screen parameters of the reduced size model. Output `0 0` otherwise.
null
null
[ { "input": "800 600 4 3\n", "output": "800 600\n" }, { "input": "1920 1200 16 9\n", "output": "1920 1080\n" }, { "input": "1 1 1 2\n", "output": "0 0\n" } ]
ok
16D
16
D
Logging
1,900
[ "implementation", "strings" ]
1,909
null
Codeforces Beta Round 16 (Div. 2 Only)
2010-06-03
Div. 2
https://codeforces.com/problemset/problem/16/D
1
64
file
false
The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: Β«`[date:time]: message`Β», where for each Β«`[date:time]`Β» value existed not more than 10 lines. All the files were encoded in a very complicated manner, and only o...
The first input line contains number *n* (1 ≀ *n* ≀ 100). The following *n* lines contain recordings in format Β«`[time]: message`Β», where time is given in format Β«`hh:mm x.m.`Β». For `hh` two-digit numbers from `01` to `12` are used, for `mm` two-digit numbers from `00` to `59` are used, and `x` is either character Β«`a`...
Output one number β€” the minimum amount of days covered by the log.
null
Formally the 12-hour time format is described at: - `http://en.wikipedia.org/wiki/12-hour_clock`. The problem authors recommend you to look through these descriptions before you start with the problem.
[ { "input": "5\n[05:00 a.m.]: Server is started\n[05:00 a.m.]: Rescan initialized\n[01:13 p.m.]: Request processed\n[01:10 p.m.]: Request processed\n[11:40 p.m.]: Rescan completed\n", "output": "2\n" }, { "input": "3\n[09:00 a.m.]: User logged in\n[08:00 a.m.]: User logged in\n[07:00 a.m.]: User logg...
ok
16E
16
E
Fish
1,900
[ "bitmasks", "dp", "probabilities" ]
7,073
null
Codeforces Beta Round 16 (Div. 2 Only)
2010-06-03
Div. 2
https://codeforces.com/problemset/problem/16/E
3
128
file
false
*n* fish, numbered from 1 to *n*, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability *a*_{*ij*}, and the second will eat up the first with the probability *a*_{*ji...
The first line contains integer *n* (1 ≀ *n* ≀ 18) β€” the amount of fish in the lake. Then there follow *n* lines with *n* real numbers each β€” matrix *a*. *a*_{*ij*} (0 ≀ *a*_{*ij*} ≀ 1) β€” the probability that fish with index *i* eats up fish with index *j*. It's guaranteed that the main diagonal contains zeros only, an...
Output *n* space-separated real numbers accurate to not less than 6 decimal places. Number with index *i* should be equal to the probability that fish with index *i* will survive to be the last in the lake.
null
null
[ { "input": "2\n0 0.5\n0.5 0\n", "output": "0.500000 0.500000 \n" }, { "input": "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0\n", "output": "1.000000 0.000000 0.000000 0.000000 0.000000 \n" } ]
ok
17A
17
A
Noldbach problem
1,000
[ "brute force", "math", "number theory" ]
22,753
null
Codeforces Beta Round 17
2010-06-10
Other
https://codeforces.com/problemset/problem/17/A
2
64
file
false
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold...
The first line of the input contains two integers *n* (2 ≀ *n* ≀ 1000) and *k* (0 ≀ *k* ≀ 1000).
Output `YES` if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output `NO`.
null
In the first sample the answer is `YES` since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is `NO` since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
[ { "input": "27 2\n", "output": "YES\n" }, { "input": "45 7\n", "output": "NO\n" } ]
ok
17B
17
B
Hierarchy
1,500
[ "dfs and similar", "dsu", "greedy", "shortest paths" ]
6,819
null
Codeforces Beta Round 17
2010-06-10
Other
https://codeforces.com/problemset/problem/17/B
2
64
file
false
Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of Β«supervisor-surbodinateΒ» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applications written in the following form: Β«employee *a*_{*i*} is ready to become a supervisor of ...
The first input line contains integer *n* (1 ≀ *n* ≀ 1000) β€” amount of employees in the company. The following line contains *n* space-separated numbers *q*_{*j*} (0 ≀ *q*_{*j*} ≀ 10^{6})β€” the employees' qualifications. The following line contains number *m* (0 ≀ *m* ≀ 10000) β€” amount of received applications. The foll...
Output the only line β€” the minimum cost of building such a hierarchy, or `-1` if it is impossible to build it.
null
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is `-1`.
[ { "input": "4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5\n", "output": "11\n" }, { "input": "3\n1 2 3\n2\n3 1 2\n3 1 3\n", "output": "-1\n" } ]
ok
17C
17
C
Balance
2,500
[ "dp" ]
1,091
null
Codeforces Beta Round 17
2010-06-10
Other
https://codeforces.com/problemset/problem/17/C
3
128
file
false
Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters `a`, `b`, `c` on a piece of paper and began to perform the following operations: - to take two adjacent characters and replace the second character with the first one, -...
The first line contains integer *n* (1 ≀ *n* ≀ 150) β€” the length of the given string *s*. Next line contains the given string *s*. The initial string can be balanced as well, in this case it should be counted too. The given string *s* consists only of characters `a`, `b` and `c`.
Output the only number β€” the number of different balanced strings that can be obtained by performing the described operations, perhaps multiple times, on the given string *s*, modulo 51123987.
null
In the first sample it is possible to get 51 different strings through the described operations, but only 7 of them are balanced: Β«`abca`Β», Β«`bbca`Β», Β«`bcca`Β», Β«`bcaa`Β», Β«`abcc`Β», Β«`abbc`Β», Β«`aabc`Β». In the second sample: Β«`abbc`Β», Β«`aabc`Β», Β«`abcc`Β». In the third sample there is only one balanced string β€” Β«`ab`Β» itsel...
[ { "input": "4\nabca\n", "output": "7\n" }, { "input": "4\nabbc\n", "output": "3\n" }, { "input": "2\nab\n", "output": "1\n" } ]
ok
17D
17
D
Notepad
2,400
[ "number theory" ]
1,406
null
Codeforces Beta Round 17
2010-06-10
Other
https://codeforces.com/problemset/problem/17/D
2
64
file
false
Nick is attracted by everything unconventional. He doesn't like decimal number system any more, and he decided to study other number systems. A number system with base *b* caught his attention. Before he starts studying it, he wants to write in his notepad all the numbers of length *n* without leading zeros in this num...
The only input line contains three space-separated integers *b*, *n* and *c* (2 ≀ *b* < 10^{10^{6}}, 1 ≀ *n* < 10^{10^{6}}, 1 ≀ *c* ≀ 10^{9}). You may consider that Nick has infinite patience, endless amount of paper and representations of digits as characters. The numbers doesn't contain leading zeros.
In the only line output the amount of numbers written on the same page as the last number.
null
In both samples there are exactly 4 numbers of length 3 in binary number system. In the first sample Nick writes 3 numbers on the first page and 1 on the second page. In the second sample all the 4 numbers can be written on the first page.
[ { "input": "2 3 3\n", "output": "1\n" }, { "input": "2 3 4\n", "output": "4\n" } ]
ok
17E
17
E
Palisection
2,900
[ "strings" ]
2,244
null
Codeforces Beta Round 17
2010-06-10
Other
https://codeforces.com/problemset/problem/17/E
2
128
file
false
In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: Β«`eye`Β», Β«`pop`Β», Β«`level`Β», Β«`aba`Β», ...
The first input line contains integer *n* (1 ≀ *n* ≀ 2Β·10^{6}) β€” length of the text. The following line contains *n* lower-case Latin letters (from `a` to `z`).
In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987.
null
null
[ { "input": "4\nbabb\n", "output": "6\n" }, { "input": "2\naa\n", "output": "2\n" } ]
ok
18A
18
A
Triangle
1,500
[ "brute force", "geometry" ]
7,204
null
Codeforces Beta Round 18 (Div. 2 Only)
2010-06-16
Div. 2
https://codeforces.com/problemset/problem/18/A
2
64
file
false
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t...
The first input line contains 6 space-separated integers *x*_{1}, *y*_{1}, *x*_{2}, *y*_{2}, *x*_{3}, *y*_{3} β€” coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
If the given triangle is right-angled, output `RIGHT`, if it is almost right-angled, output `ALMOST`, and if it is neither of these, output `NEITHER`.
null
null
[ { "input": "0 0 2 0 0 1\n", "output": "RIGHT\n" }, { "input": "2 3 4 5 6 6\n", "output": "NEITHER\n" }, { "input": "-1 0 2 0 0 1\n", "output": "ALMOST\n" } ]
ok
18B
18
B
Platforms
1,700
[ "brute force", "math" ]
2,505
null
Codeforces Beta Round 18 (Div. 2 Only)
2010-06-16
Div. 2
https://codeforces.com/problemset/problem/18/B
2
64
file
false
In one one-dimensional world there are *n* platforms. Platform with index *k* (platforms are numbered from 1) is a segment with coordinates [(*k* - 1)*m*, (*k* - 1)*m* + *l*], and *l* < *m*. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly *d* units right. Find out the co...
The first input line contains 4 integer numbers *n*, *d*, *m*, *l* (1 ≀ *n*, *d*, *m*, *l* ≀ 10^{6}, *l* < *m*) β€” respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers *m* and *l* needed to find coordinates of the *k*-th platform: [(*k* - 1)*m*, (*k* - 1)*m* + *l*].
Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.
null
null
[ { "input": "2 2 5 3\n", "output": "4\n" }, { "input": "5 4 11 8\n", "output": "20\n" } ]
ok
18C
18
C
Stripe
1,200
[ "data structures", "implementation" ]
15,887
null
Codeforces Beta Round 18 (Div. 2 Only)
2010-06-16
Div. 2
https://codeforces.com/problemset/problem/18/C
2
64
file
false
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ...
The first input line contains integer *n* (1 ≀ *n* ≀ 10^{5}) β€” amount of squares in the stripe. The second line contains *n* space-separated numbers β€” they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
null
null
[ { "input": "9\n1 5 -6 7 9 -16 0 -2 2\n", "output": "3\n" }, { "input": "3\n1 1 1\n", "output": "0\n" }, { "input": "2\n0 0\n", "output": "1\n" } ]
ok
18D
18
D
Seller Bob
2,000
[ "brute force", "dp", "greedy" ]
1,339
null
Codeforces Beta Round 18 (Div. 2 Only)
2010-06-16
Div. 2
https://codeforces.com/problemset/problem/18/D
2
128
file
false
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2^{*x*} MB memory stick. If Bob had such a stick, he sold it and got 2^{*x*} berllars. - Bob won some programming competition and got a 2^{*x*}...
The first input line contains number *n* (1 ≀ *n* ≀ 5000) β€” amount of Bob's working days. The following *n* lines contain the description of the days. Line `sell x` stands for a day when a customer came to Bob to buy a 2^{*x*} MB memory stick (0 ≀ *x* ≀ 2000). It's guaranteed that for each *x* there is not more than on...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[ { "input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n", "output": "1056\n" }, { "input": "3\nwin 5\nsell 6\nsell 4\n", "output": "0\n" } ]
ok
18E
18
E
Flag 2
2,000
[ "dp" ]
1,326
null
Codeforces Beta Round 18 (Div. 2 Only)
2010-06-16
Div. 2
https://codeforces.com/problemset/problem/18/E
2
128
file
false
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field *n* × *m*, each square should be wholly painted one of 26 colours. The following restrictions are set: - In each row at most two different colours can be used. - No two adjacent squares can be painted the same col...
The first input line contains 2 integers *n* and *m* (1 ≀ *n*, *m* ≀ 500) β€” amount of rows and columns in Berland's flag respectively. Then there follows the flag's description: each of the following *n* lines contains *m* characters. Each character is a letter from `a` to `z`, and it stands for the colour of the corre...
In the first line output the minimum amount of squares that need to be repainted to make the flag meet the new ISO standard. The following *n* lines should contain one of the possible variants of the new flag. Don't forget that the variant of the flag, proposed by you, should be derived from the old flag with the minim...
null
null
[ { "input": "3 4\naaaa\nbbbb\ncccc\n", "output": "6\nabab\nbaba\nacac\n" }, { "input": "3 3\naba\naba\nzzz\n", "output": "4\naba\nbab\nzbz\n" } ]
ok
20A
20
A
BerOS file system
1,700
[ "implementation" ]
7,330
500
Codeforces Alpha Round 20 (Codeforces format)
2010-06-18
Other
https://codeforces.com/problemset/problem/20/A
2
64
file
false
The new operating system BerOS has a nice feature. It is possible to use any number of characters `'/'` as a delimiter in path instead of one traditional `'/'`. For example, strings `//usr///local//nginx/sbin//` and `/usr/local/nginx///sbin` are equivalent. The character `'/'` (or some sequence of such characters) at t...
The first line of the input contains only lowercase Latin letters and character `'/'`Β β€” the path to some directory. All paths start with at least one character `'/'`. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
null
null
[ { "input": "//usr///local//nginx/sbin\n", "output": "/usr/local/nginx/sbin\n" } ]
ok
20B
20
B
Equation
2,000
[ "math" ]
5,152
1,000
Codeforces Alpha Round 20 (Codeforces format)
2010-06-18
Other
https://codeforces.com/problemset/problem/20/B
1
256
file
false
You are given an equation: *Ax*^{2} + *Bx* + *C* = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
The first line contains three integer numbers *A*, *B* and *C* ( - 10^{5} ≀ *A*, *B*, *C* ≀ 10^{5}). Any coefficient may be equal to 0.
In case of infinite root count print the only integer `-1`. In case of no roots print the only integer `0`. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
null
null
[ { "input": "1 -5 6\n", "output": "2\n2.0000000000\n3.0000000000\n" } ]
ok
20C
20
C
Dijkstra?
1,900
[ "graphs", "shortest paths" ]
50,989
1,500
Codeforces Alpha Round 20 (Codeforces format)
2010-06-18
Other
https://codeforces.com/problemset/problem/20/C
1
64
file
false
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2 ≀ *n* ≀ 10^{5}, 0 ≀ *m* ≀ 10^{5}), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a*_{*i*}, *b*_{*i*} and *w*_{*i*} (1 ≀ *a*_{*i*}, *b*_{*i*} ≀ *n*, 1 ≀ *w*_{*i*} ≀ 10^{6}), where *a*_{*i*}, *b*_{...
Write the only integer `-1` in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
null
null
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "output": "1 4 3 5 \n" }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "output": "1 4 3 5 \n" } ]
ok
19A
19
A
World Football Cup
1,400
[ "implementation" ]
3,283
null
Codeforces Beta Round 19
2010-06-24
Other
https://codeforces.com/problemset/problem/19/A
2
64
file
false
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: - the final tournament features *n* teams (*n* is always even) - the first *n* / 2 teams...
The first input line contains the only integer *n* (1 ≀ *n* ≀ 50) β€” amount of the teams, taking part in the final tournament of World Cup. The following *n* lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following *n*Β·(...
Output *n* / 2 lines β€” names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.
null
null
[ { "input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n", "output": "A\nD\n" }, { "input": "2\na\nA\na-A 2:1\n", "output": "a\n" } ]
ok
19B
19
B
Checkout Assistant
1,900
[ "dp" ]
6,185
null
Codeforces Beta Round 19
2010-06-24
Other
https://codeforces.com/problemset/problem/19/B
1
256
file
false
Bob came to a cash & carry store, put *n* items into his trolley, and went to the checkout counter to pay. Each item is described by its price *c*_{*i*} and time *t*_{*i*} in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items fr...
The first input line contains number *n* (1 ≀ *n* ≀ 2000). In each of the following *n* lines each item is described by a pair of numbers *t*_{*i*}, *c*_{*i*} (0 ≀ *t*_{*i*} ≀ 2000, 1 ≀ *c*_{*i*} ≀ 10^{9}). If *t*_{*i*} is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item *i*.
Output one number β€” answer to the problem: what is the minimum amount of money that Bob will have to pay.
null
null
[ { "input": "4\n2 10\n0 20\n1 5\n1 3\n", "output": "8\n" }, { "input": "3\n0 1\n0 10\n0 100\n", "output": "111\n" } ]
ok
19C
19
C
Deletion of Repeats
2,200
[ "greedy", "hashing", "string suffix structures" ]
1,417
null
Codeforces Beta Round 19
2010-06-24
Other
https://codeforces.com/problemset/problem/19/C
2
256
file
false
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length *x* is such a substring of length 2*x*, that its first half ...
The first input line contains integer *n* (1 ≀ *n* ≀ 10^{5}) β€” length of the string. The following line contains *n* space-separated integer numbers from 0 to 10^{9} inclusive β€” numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.
In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.
null
null
[ { "input": "6\n1 2 3 1 2 3\n", "output": "3\n1 2 3 \n" }, { "input": "7\n4 5 6 5 6 7 7\n", "output": "1\n7 \n" } ]
ok
19D
19
D
Points
2,800
[ "data structures" ]
3,469
null
Codeforces Beta Round 19
2010-06-24
Other
https://codeforces.com/problemset/problem/19/D
2
256
file
false
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0, 0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is directed up. Pete gives Bob requests of three types: - `add x y` β€” on the sheet of paper Bob ...
The first input line contains number *n* (1 ≀ *n* ≀ 2Β·10^{5}) β€” amount of requests. Then there follow *n* lines β€” descriptions of the requests. `add x y` describes the request to add a point, `remove x y` β€” the request to erase a point, `find x y` β€” the request to find the bottom-left point. All the coordinates in the ...
For each request of type `find x y` output in a separate line the answer to it β€” coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (*x*, *y*). If there are no points strictly above and to the right of point (*x*, *y*), output `-1`.
null
null
[ { "input": "7\nadd 1 1\nadd 3 4\nfind 0 0\nremove 1 1\nfind 0 0\nadd 1 1\nfind 0 0\n", "output": "1 1\n3 4\n1 1\n" }, { "input": "13\nadd 5 5\nadd 5 6\nadd 5 7\nadd 6 5\nadd 6 6\nadd 6 7\nadd 7 5\nadd 7 6\nadd 7 7\nfind 6 6\nremove 7 7\nfind 6 6\nfind 4 4\n", "output": "7 7\n-1\n5 5\n" } ]
ok
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
23