problem_statement stringlengths 147 8.53k | input stringlengths 1 771 | output stringlengths 1 592 ⌀ | time_limit stringclasses 32
values | memory_limit stringclasses 21
values | tags stringlengths 6 168 |
|---|---|---|---|---|---|
E. Songwritertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndi is a mathematician, a computer scientist, and a songwriter. After spending so much time writing songs, he finally writes a catchy melody that he thought as his best creation. However, the singer who wi... | 16 1 8 6
1 3 5 6 7 8 9 10 3 7 8 9 10 11 12 12
| 1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 8 | 1 second | 256 megabytes | ['greedy', 'two pointers', '*2200'] |
D. Find String in a Gridtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a grid G containing R rows (numbered from 1 to R, top to bottom) and C columns (numbered from 1 to C, left to right) of uppercase characters. The character in the r^{th} row and the c^{... | 3 3 5
ABC
BCD
DAB
ABC
BC
BD
AC
A
| 2 3 1 0 2 | 5 seconds | 256 megabytes | ['data structures', 'dp', 'strings', 'trees', '*3000'] |
C. Even Pathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPathfinding is a task of finding a route between two points. It often appears in many problems. For example, in a GPS navigation software where a driver can query for a suggested route, or in a robot motion ... | 5 3
6 2 7 8 3
3 4 8 5 1
2 2 1 3
4 2 4 3
5 1 3 4
| YES YES NO | 1 second | 256 megabytes | ['data structures', 'implementation', '*1600'] |
B. Cleaning Robotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe new ICPC town has N junctions (numbered from 1 to N) which are connected by N-1 roads. It is possible from one junction to go to any other junctions by going through one or more roads. To make sure... | 6
1 3
2 3
3 4
4 5
4 6
| 5 | 1 second | 256 megabytes | ['dp', 'trees', '*2300'] |
A. Copying Homeworktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDanang and Darto are classmates. They are given homework to create a permutation of N integers from 1 to N. Danang has completed the homework and created a permutation A of N integers. Darto wants to ... | 4
1 3 2 4
| 4 2 3 1 | 1 second | 256 megabytes | ['*1000'] |
F. Red-White Fencetime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputPolycarp wants to build a fence near his house. He has n white boards and k red boards he can use to build it. Each board is characterised by its length, which is an integer.A good fence should consis... | 5 2
3 3 1 1 1
2 4
7
6 8 10 12 14 16 18
| 1 2 2 4 6 4 1 | 5 seconds | 512 megabytes | ['combinatorics', 'fft', '*2500'] |
E2. Voting (Hard Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.There are n voter... | 3
3
1 5
2 10
2 8
7
0 1
3 1
1 1
6 1
1 1
4 1
4 1
6
2 6
2 3
2 8
2 7
4 4
5 5
| 8 0 7 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', '*2400'] |
E1. Voting (Easy Version)time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.There are n voter... | 3
3
1 5
2 10
2 8
7
0 1
3 1
1 1
6 1
1 1
4 1
4 1
6
2 6
2 3
2 8
2 7
4 4
5 5
| 8 0 7 | 2 seconds | 512 megabytes | ['data structures', 'dp', 'greedy', '*2300'] |
D. Salary Changingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2).You have to distribute salaries to your employees. Initially, you have s dollars for it, and ... | 3
3 26
10 12
1 4
10 11
1 1337
1 1000000000
5 26
4 4
2 4
6 8
5 6
2 7
| 11 1337 6 | 3 seconds | 256 megabytes | ['binary search', 'greedy', 'sortings', '*1900'] |
C. Minimize The Integertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a huge integer a consisting of n digits (n is between 1 and 3 \cdot 10^5, inclusive). It may contain leading zeros.You can swap two digits on adjacent (neighboring) positions if the... | 3
0709
1337
246432
| 0079 1337 234642 | 2 seconds | 256 megabytes | ['greedy', 'two pointers', '*1600'] |
B. Binary Palindromestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA palindrome is a string t which reads the same backward as forward (formally, t[i] = t[|t| + 1 - i] for all i \in [1, |t|]). Here |t| denotes the length of a string t. For example, the strings 010... | 4
1
0
3
1110
100110
010101
2
11111
000001
2
001
11100111
| 1 2 2 2 | 2 seconds | 256 megabytes | ['greedy', 'strings', '*1400'] |
A. Broken Keyboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet)... | 4
a
zzaaz
ccff
cbddbb
| a z bc | 1 second | 256 megabytes | ['brute force', 'strings', 'two pointers', '*1000'] |
N. Wirestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputPolycarpus has a complex electronic device. The core of this device is a circuit board. The board has 10^9 contact points which are numbered from 1 to 10^9. Also there are n wires numbered from 1 to n, each con... | 2
1
4 7
4
1 2
2 3
4 5
5 6
| 0 1 2 3 5 | 3 seconds | 512 megabytes | ['dfs and similar', 'graphs', 'greedy', '*2000'] |
M. SmartGardentime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBerland Gardeners United Inc. hired you for the project called "SmartGarden". The main feature of this project is automatic garden watering.Formally the garden can be represented as a square of n \times n... | 2 | 2 1 1 1 2 1 1 1 2 | 2 seconds | 512 megabytes | ['constructive algorithms', 'divide and conquer', '*2500'] |
L. Divide The Studentstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA group of students has recently been admitted to the Faculty of Computer Sciences at the Berland State University. Now the programming teacher wants to divide them into three subgroups for practi... | 5
3 5 7
4 8 4
13 10 13
1000 1000 1000
13 22 7
| 5 6 13 1000 14 | 2 seconds | 512 megabytes | ['binary search', 'greedy', 'math', '*1500'] |
K. Projectorstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n lectures and m seminars to be conducted today at the Faculty of Approximate Sciences. The i-th lecture starts at a_i and ends at b_i (formally, time of the lecture spans an interval [a_i, b_i),... | 2
2 2 2 2
1 5
2 5
1 5
1 4
2 0 2 10
1 3
1 3
| YES 2 1 4 3 YES 2 1 | 3 seconds | 512 megabytes | ['flows', 'graphs', '*3100'] |
J. The Paradetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe Berland Army is preparing for a large military parade. It is already decided that the soldiers participating in it will be divided into k rows, and all rows will contain the same number of soldiers.Of ... | 5
3 4
7 1 13
1 1
100
1 3
100
2 1
1000000000000 1000000000000
4 1
10 2 11 1
| 16 100 99 2000000000000 13 | 2 seconds | 512 megabytes | ['binary search', 'greedy', '*1800'] |
I. Show Must Go Ontime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe director of the famous dance show plans a tour. It is already decided that the tour will consist of up to m concerts.There are n dancers in the troupe. Each dancer is characterized by her awkwardn... | 3
7 13 10
3 1 5 1 8 2 13
2 10 1
12 12
3 32 100000
2 1 5
| 10 5 12 4 7 4 9 4 10 4 11 4 11 4 12 4 13 3 4 3 5 2 4 1 0 7 3 8 2 3 2 6 2 7 1 1 1 2 1 5 3 | 5 seconds | 512 megabytes | ['binary search', 'brute force', 'greedy', 'shortest paths', '*3100'] |
H. Happy Birthdaytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou have a set of birthday cake candles. Each of such candles represents a digit between 0 and 9, inclusive. Example of birthday cake candles. Let's denote the candle representing the digit d as d-can... | 4
1 1 1 1 1 1 1 1 1 1
0 0 1 1 2 2 3 3 4 4
1 2 1 2 1 3 1 0 0 0
0 1 2 1 4 3 1 1 2 1
| 11 1 7 10 | 2 seconds | 512 megabytes | ['math', '*1500'] |
G. Discarding Gametime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputEulampius has created a game with the following rules: there are two players in the game: a human and a computer; the game lasts for no more than n rounds. Initially both players have 0 points. In th... | 3
4 17
1 3 5 7
3 5 7 9
11 17
5 2 8 2 4 6 1 2 7 2 5
4 6 3 3 5 1 7 4 2 5 3
6 17
6 1 2 7 2 5
1 7 4 2 5 3
| 0 2 2 4 -1 | 3 seconds | 512 megabytes | ['dp', 'greedy', 'two pointers', '*2300'] |
F. Data Centertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are developing a project to build a new data center. The data center will be a rectangle with an area of exactly n square meters. Each side of the data center must be an integer.Your goal is to minimi... | 36
| 24 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*800'] |
E. The Coronationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe coronation of King Berl XXII is soon! The whole royal family, including n daughters of Berl XXII, will be present.The King has ordered his jeweler to assemble n beautiful necklaces, so each of the ... | 5
5 7 2
1010100
0010101
1111010
1000010
0000101
6 9 3
011111110
100111000
111100000
000111111
110100111
111110111
3 4 2
0001
1000
0000
3 4 4
0001
1000
0000
2 4 3
0001
1000
| 2 1 3 1 3 0 -1 1 1 | 2 seconds | 512 megabytes | ['graphs', 'implementation', '*2300'] |
D. Conference Problemtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA large-scale conference on unnatural sciences is going to be held soon in Berland! In total, n scientists from all around the world have applied. All of them have indicated a time segment when the... | 2
4
1 10 30
5 6 30
6 12 0
1 1 0
4
1 2 1
2 3 0
3 4 0
4 5 2
| 4 2 | 2 seconds | 512 megabytes | ['dp', '*3000'] |
C. Trip to Saint Petersburgtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are planning your trip to Saint Petersburg. After doing some calculations, you estimated that you will have to spend k rubles each day you stay in Saint Petersburg — you have to rent a fl... | 4 5
1 1 3
3 3 11
5 5 17
7 7 4
| 13 3 5 2 3 2 | 3 seconds | 512 megabytes | ['data structures', '*2100'] |
B. The Feast and the Bustime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputEmployees of JebTrains are on their way to celebrate the 256-th day of the year! There are n employees and k teams in JebTrains. Each employee is a member of some (exactly one) team. All teams a... | 6 3
3 1 2 3 2 3
| 6 | 2 seconds | 512 megabytes | ['brute force', 'constructive algorithms', 'greedy', 'math', '*1800'] |
A. Berstagramtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputPolycarp recently signed up to a new social network Berstagram. He immediately published n posts there. He assigned numbers from 1 to n to all posts and published them one by one. So, just after publishing... | 3 5
3 2 1 3 3
| 1 2 2 3 1 3 | 3 seconds | 512 megabytes | ['implementation', '*1400'] |
F. Maximum Weight Subsettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree, which consists of n vertices. Recall that a tree is a connected undirected graph without cycles. Example of a tree. Vertices are numbered from 1 to n. All vertices have w... | 5 1
1 2 3 4 5
1 2
2 3
3 4
3 5
| 11 | 2 seconds | 256 megabytes | ['dp', 'trees', '*2200'] |
E. By Elevator or Stairs?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are planning to buy an apartment in a n-floor building. The floors are numbered from 1 to n from the bottom to the top. At first for each floor you want to know the minimum total time to re... | 10 2
7 6 18 6 16 18 1 17 17
6 9 3 10 9 1 10 1 5
| 0 7 13 18 24 35 36 37 40 45 | 2 seconds | 256 megabytes | ['dp', 'shortest paths', '*1700'] |
D2. Too Many Segments (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide.... | 7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9
| 3 4 6 7 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'sortings', '*1800'] |
D1. Too Many Segments (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. ... | 7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9
| 3 1 4 7 | 1 second | 256 megabytes | ['greedy', '*1800'] |
C2. Good Numbers (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the maximum value of n.You are given a positive integer number n. You really love good numbers so you want to find the smallest good ... | 8
1
2
6
13
14
3620
10000
1000000000000000000
| 1 3 9 13 27 6561 19683 1350851717672992089 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'math', 'meet-in-the-middle', '*1500'] |
C1. Good Numbers (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the maximum value of n.You are given a positive integer number n. You really love good numbers so you want to find the smallest good n... | 7
1
2
6
13
14
3620
10000
| 1 3 9 13 27 6561 19683 | 1 second | 256 megabytes | ['brute force', 'greedy', 'implementation', '*1300'] |
B2. Books Exchange (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p... | 6
5
1 2 3 4 5
3
2 3 1
6
4 6 2 1 5 3
1
1
4
3 4 1 2
5
5 1 2 4 3
| 1 1 1 1 1 3 3 3 2 3 3 2 1 3 1 2 2 2 2 4 4 4 1 4 | 1 second | 256 megabytes | ['dfs and similar', 'dsu', 'math', '*1300'] |
B1. Books Exchange (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p... | 6
5
1 2 3 4 5
3
2 3 1
6
4 6 2 1 5 3
1
1
4
3 4 1 2
5
5 1 2 4 3
| 1 1 1 1 1 3 3 3 2 3 3 2 1 3 1 2 2 2 2 4 4 4 1 4 | 1 second | 256 megabytes | ['dsu', 'math', '*1000'] |
A. Yet Another Dividing into Teamstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in suc... | 4
4
2 10 1 20
2
3 6
5
2 3 4 99 100
1
42
| 2 1 2 1 | 1 second | 256 megabytes | ['math', '*800'] |
D1. The World Is Just a Programming Task (Easy Version)time limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is an easier version of the problem. In this version, n \le 500.Vasya is an experienced developer of programming competitions' problems. As all great minds at ... | 10
()()())(()
| 5 8 7 | 1 second | 512 megabytes | ['brute force', 'dp', 'greedy', 'implementation', '*2000'] |
B. Grow The Treetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an... | 3
1 2 3
| 26 | 2 seconds | 512 megabytes | ['greedy', 'math', 'sortings', '*900'] |
A. Integer Pointstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew n distinct lines, given by equations y = x + p_i for some distinct p_1, p_2, \ldots, p_n.T... | 3
3
1 3 2
2
0 3
1
1
1
1
1
2
1
1
| 3 1 0 | 2 seconds | 512 megabytes | ['geometry', 'math', '*1000'] |
F. Cursor Distancetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a string s of lowercase English letters. A cursor is positioned on one of the characters. The cursor can be moved with the following operation: choose a letter c and a direction (left or righ... | abcde
| 20 | 2 seconds | 512 megabytes | ['*3500'] |
F. Daniel and Spring Cleaningtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute 1 + 3 using the calculator, he gets 2 i... | 3
1 4
323 323
1 1000000
| 8 0 3439863766 | 2 seconds | 256 megabytes | ['bitmasks', 'brute force', 'combinatorics', 'dp', '*2300'] |
E. Hyakugoku and Ladderstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "C... | 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
| 33.0476190476 | 1 second | 256 megabytes | ['dp', 'probabilities', 'shortest paths', '*2300'] |
D. Shichikuji and Power Gridtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputShichikuji is the new resident deity of the South Black Snail Temple. Her first job is as follows:There are n new cities located in Prefecture X. Cities are numbered from 1 to n. City i is l... | 3
2 3
1 1
3 2
3 2 3
3 2 3
| 8 3 1 2 3 0 | 2 seconds | 256 megabytes | ['dsu', 'graphs', 'greedy', 'shortest paths', 'trees', '*1900'] |
C. Constanze's Machinetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConstanze is the smartest girl in her village but she has bad eyesight.One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece... | ouuokarinn
| 4 | 1 second | 256 megabytes | ['dp', '*1400'] |
B. Restricted RPStime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. ... | 2
3
1 1 1
RPS
3
3 0 0
RPS
| YES PSR NO | 1 second | 256 megabytes | ['constructive algorithms', 'dp', 'greedy', '*1200'] |
A. Good ol' Numbers Coloringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the set of all nonnegative integers: {0, 1, 2, \dots}. Given two integers a and b (1 \le a, b \le 10^4). We paint all the numbers in increasing number first we paint 0, then we paint... | 4
10 10
1 10
6 9
7 3
| Infinite Finite Infinite Finite | 1 second | 256 megabytes | ['math', 'number theory', '*1000'] |
G. Running in Pairstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDemonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition!Berlatov team consists of 2n runners which are placed on two runn... | 5 20
| 20 1 2 3 4 5 5 2 4 3 1 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*2400'] |
F. Chipstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n chips arranged in a circle, numbered from 1 to n. Initially each chip has black or white color. Then k iterations occur. During each iteration the chips change their colors according to the following... | 6 1
BWBBWW
| WBBBWW | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*2300'] |
E. Minimizing Differencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a_1, a_2, \dots, a_n consisting of n integers.You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.Calc... | 4 5
3 1 7 5
| 2 | 2 seconds | 256 megabytes | ['binary search', 'constructive algorithms', 'greedy', 'sortings', 'ternary search', 'two pointers', '*2000'] |
D. Paint the Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of n vertices. A tree is an undirected connected acyclic graph. Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the... | 3
3 2 3
4 3 2
3 1 3
1 2
2 3
| 6 1 3 2 | 3 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'dp', 'graphs', 'implementation', 'trees', '*1800'] |
C. The Football Seasontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of ... | 30 60 3 1
| 17 9 4 | 1 second | 256 megabytes | ['brute force', 'math', 'number theory', '*2000'] |
B. Rooms and Staircasestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikolay lives in a two-storied house. There are n rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and th... | 4
5
00100
8
00000000
5
11111
3
110
| 6 8 10 6 | 1 second | 256 megabytes | ['brute force', 'implementation', '*1000'] |
A. Pens and Pencilstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.While preparing... | 3
7 5 4 5 8
7 5 4 5 2
20 53 45 26 4
| 7 1 -1 1 3 | 1 second | 256 megabytes | ['math', '*800'] |
B2. Character Swap (Hard Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k \le 1000, n \le 50 and it is necessary to print swaps themselves. You can hac... | 4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
| Yes 1 1 4 No No Yes 3 1 2 3 1 2 3 | 1 second | 256 megabytes | ['strings', '*1600'] |
B1. Character Swap (Easy Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.After struggling and failing m... | 4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
| Yes No No No | 1 second | 256 megabytes | ['strings', '*1000'] |
A. Maximum Squaretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUjan decided to make a new wooden roof for the house. He has n rectangular planks numbered from 1 to n. The i-th plank has size a_i \times 1 (that is, the width is 1 and the height is a_i).Now, Ujan wan... | 4
5
4 3 1 4 5
4
4 4 4 4
3
1 1 1
5
5 5 1 1 5
| 3 4 1 3 | 1 second | 256 megabytes | ['implementation', '*800'] |
E. Planar Perimetertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUjan has finally cleaned up his house and now wants to decorate the interior. He decided to place a beautiful carpet that would really tie the guest room together.He is interested in carpets that are ... | 2
3 3
| 4 2 1 4 1 2 3 | 1 second | 256 megabytes | ['constructive algorithms', 'graphs', '*3200'] |
D. Number Discoverytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputUjan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers n and k. He creates an infinite sequence s by repeating the following steps. Find k smallest di... | 2
10 2
40 5
| 11 12 | 2 seconds | 256 megabytes | ['math', '*3400'] |
C. Sum Balancetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUjan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.There are k boxes numbered from 1 to k. The i-th box contains n_i integer numbers. The integers can ... | 4
3 1 7 4
2 3 2
2 8 5
1 10
| Yes 7 2 2 3 5 1 10 4 | 1 second | 256 megabytes | ['bitmasks', 'dfs and similar', 'dp', 'graphs', '*2400'] |
B. 0-1 MSTtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUjan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a g... | 6 11
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
| 2 | 1 second | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', 'sortings', '*1900'] |
A. Tile Paintingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUjan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.The path consists of n consecutive tiles, numbered from 1 to... | 4
| 2 | 1 second | 256 megabytes | ['constructive algorithms', 'math', 'number theory', '*1500'] |
F. Footballtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n football teams in the world. The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. Let s_... | 7 11 3
4 7 8 10 10 9 3
6 2
6 1
7 6
4 3
4 6
3 1
5 3
7 5
7 3
4 2
1 4
| 3 2 1 1 3 1 2 1 2 3 2 | 1 second | 256 megabytes | ['graphs', '*3100'] |
F. Swiper, no swiping!time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputI'm the Map, I'm the Map! I'm the MAP!!!MapIn anticipation of new adventures Boots wanted to do a good deed. After discussion with the Map and Backpack, they decided to gift Dora a connected graph... | 3
3 3
1 2
2 3
3 1
6 6
1 2
1 3
2 3
2 5
2 6
2 4
8 12
1 2
1 3
2 3
1 4
4 5
5 1
3 6
3 7
3 8
6 1
7 1
8 1
| No Yes 3 4 5 6 Yes 3 6 7 8 | 2 seconds | 512 megabytes | ['graphs', 'implementation', '*3400'] |
E. Turtletime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKolya has a turtle and a field of size 2 \times n. The field rows are numbered from 1 to 2 from top to bottom, while the columns are numbered from 1 to n from left to right.Suppose in each cell of the field th... | 2
1 4
2 3
| 1 3 4 2 | 5 seconds | 512 megabytes | ['dp', 'implementation', '*3100'] |
D. Catowice Citytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are n residents and n cats in the Catowice, and each reside... | 4
3 4
1 1
2 2
3 3
1 3
3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3
1 1
1 1
2 4
1 1
1 2
2 1
2 2
| Yes 2 1 1 3 2 Yes 1 2 2 1 3 No No | 2 seconds | 512 megabytes | ['2-sat', 'dfs and similar', 'graph matchings', 'graphs', '*2400'] |
C. Queue in the Traintime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become h... | 5 314
0 310 942 628 0
| 314 628 1256 942 1570 | 1 second | 512 megabytes | ['data structures', 'greedy', 'implementation', '*2300'] |
B. The World Is Just a Programming Task (Hard Version)time limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. In this version, n \le 300\,000.Vasya is an experienced developer of programming competitions' problems. As all great minds ... | 10
()()())(()
| 5 8 7 | 1 second | 512 megabytes | ['implementation', '*2500'] |
A. Ivan the Fool and the Probability Theorytime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputRecently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he alre... | 2 3
| 8 | 1 second | 512 megabytes | ['combinatorics', 'dp', 'math', '*1700'] |
G. Adilbek and the Watering Systemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAdilbek has to water his garden. He is going to do it with the help of a complex watering system: he only has to deliver water to it, and the mechanisms will do all the remaining job.T... | 4
1 5 4 2
2 4 2
0 4 5 4
2 5 3 1
1 2 4
3 1 3
2 3 5 1
2 1 1
1 4 3
| 6 0 -1 4 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'sortings', '*2700'] |
F. The Maximum Subtreetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAssume that you have k one-dimensional segments s_1, s_2, \dots s_k (each segment is denoted by two integers — its endpoints). Then you can build the following graph on these segments. The graph c... | 1
10
1 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10
| 8 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'graphs', 'trees', '*2200'] |
E. Keyboard Purchasetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters.Since you spend a lot of time typing it, you want to bu... | 6 3
aacabc
| 5 | 1 second | 256 megabytes | ['bitmasks', 'dp', '*2200'] |
D. AB-stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe string t_1t_2 \dots t_k is good if each letter of this string belongs to at least one palindrome of length greater than 1.A palindrome is a string that reads the same backward as forward. For example, t... | 5
AABBB
| 6 | 2 seconds | 256 megabytes | ['binary search', 'combinatorics', 'dp', 'strings', '*1900'] |
C. Standard Free2playtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each hei... | 4
3 2
3 1
8 6
8 7 6 5 3 2
9 6
9 8 5 4 3 1
1 1
1
| 0 1 2 0 | 2 seconds | 256 megabytes | ['dp', 'greedy', 'math', '*1600'] |
B. Kill 'Em Alltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.The main part of the level is a large corridor (so large a... | 2
3 2
1 3 5
4 1
5 2 3 5
| 2 2 | 1 second | 256 megabytes | ['greedy', 'sortings', '*1300'] |
A. Prime Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?Recall that a pri... | 4
100 98
42 32
1000000000000000000 1
41 40
| YES YES YES NO | 2 seconds | 256 megabytes | ['math', 'number theory', '*900'] |
H. Balanced Reversalstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou have two strings a and b of equal even length n consisting of characters 0 and 1.We're in the endgame now. To finally make the universe perfectly balanced, you need to make strings a and b equa... | 4
0100011011
1101011000
10101010
10101010
0011
1001
100011
110010
| 3 6 4 10 0 -1 7 2 6 2 6 2 2 6 | 2 seconds | 512 megabytes | ['constructive algorithms', '*3300'] |
G. Balanced Distributiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n friends living on a circular street. The friends and their houses are numbered clockwise from 0 to n-1.Initially person i has a_i stones. The friends want to make the distribution of... | 6 3
2 6 1 10 3 2
| 3 2 7 3 4 5 4 4 2 1 4 4 4 | 2 seconds | 512 megabytes | ['data structures', 'dp', 'greedy', '*3500'] |
F. Balanced Domino Placementstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider a square grid with h rows and w columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one do... | 5 7 2
3 1 3 2
4 4 4 5
| 8 | 2 seconds | 512 megabytes | ['combinatorics', 'dp', '*2600'] |
E. Balanced Binary Search Treestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRecall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be great... | 4
| 1 | 3 seconds | 512 megabytes | ['dp', 'math', '*2400'] |
D. Balanced Playlisttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYour favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of n tracks numbered from 1 to n. The playlist is automatic and cyclic: whe... | 4
11 5 2 7
| 1 1 3 2 | 2 seconds | 512 megabytes | ['binary search', 'data structures', 'implementation', '*2000'] |
C2. Balanced Removals (Harder)time limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. In this version, n \le 50\,000.There are n distinct points in three-dimensional space numbered from 1 to n. The i-th point has coordinates (x_i, y_i... | 6
3 1 0
0 3 0
2 2 0
1 0 0
1 3 0
0 1 0
| 3 6 5 1 2 4 | 1 second | 512 megabytes | ['binary search', 'constructive algorithms', 'divide and conquer', 'greedy', 'implementation', 'sortings', '*1900'] |
C1. Balanced Removals (Easier)time limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is an easier version of the problem. In this version, n \le 2000.There are n distinct points in three-dimensional space numbered from 1 to n. The i-th point has coordinates (x_i, y_i, ... | 6
3 1 0
0 3 0
2 2 0
1 0 0
1 3 0
0 1 0
| 3 6 5 1 2 4 | 1 second | 512 megabytes | ['constructive algorithms', 'geometry', 'greedy', '*1700'] |
B. Balanced Tunneltime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider a tunnel on a one-way road. During a particular day, n cars numbered from 1 to n entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds.A traffic... | 5
3 5 2 1 4
4 3 2 5 1
| 2 | 1 second | 512 megabytes | ['data structures', 'sortings', 'two pointers', '*1300'] |
A. Balanced Rating Changestime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputAnother Codeforces Round has just finished! It has gathered n participants, and according to the results, the expected rating change of participant i is a_i. These rating changes are perfectly ... | 3
10
-5
-5
| 5 -2 -3 | 1 second | 512 megabytes | ['implementation', 'math', '*1000'] |
F. Alice and the Cactustime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice recently found some cactuses growing near her house! After several months, more and more cactuses appeared and soon they blocked the road. So Alice wants to clear them.A cactus is a connect... | 3 3
1 2
2 3
1 3
| 984375007 | 3 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'math', 'probabilities', '*3000'] |
E. Alice and the Unfair Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice is playing a game with her good friend, Marisa.There are n boxes arranged in a line, numbered with integers from 1 to n from left to right. Marisa will hide a doll in one of the boxes. ... | 3 3
2 2 2
| 7 | 1 second | 256 megabytes | ['binary search', 'data structures', 'dp', 'dsu', '*2500'] |
D. Alice and the Dolltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice got a new doll these days. It can even walk!Alice has built a maze for the doll and wants to test it. The maze is a grid with n rows and m columns. There are k obstacles, the i-th of them is o... | 3 3 2
2 2
2 1
| Yes | 1 second | 256 megabytes | ['brute force', 'data structures', 'greedy', 'implementation', '*2300'] |
C. Labstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn order to do some research, n^2 labs are built on different heights of a mountain. Let's enumerate them with integers from 1 to n^2, such that the lab with the number 1 is at the lowest place, the lab with the ... | 3
| 2 8 5 9 3 4 7 6 1 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', '*1300'] |
B. Alice and the List of Presentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice got many presents these days. So she decided to pack them into boxes and send them to her friends.There are n kinds of presents. Presents of one kind are identical (i.e. there is n... | 1 3
| 7 | 1 second | 256 megabytes | ['combinatorics', 'math', '*1500'] |
A. Stonestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.Each time she ca... | 3
3 4 5
1 0 5
5 3 2
| 9 0 6 | 1 second | 256 megabytes | ['brute force', 'greedy', 'math', '*800'] |
F. Yet Another Substring Reversetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting only of first 20 lowercase Latin letters ('a', 'b', ..., 't').Recall that the substring s[l; r] of the string s is the string s_l s_{l + 1} \dots s_r.... | abacaba
| 3 | 2 seconds | 256 megabytes | ['bitmasks', 'dp', '*2200'] |
E. Special Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define p_i(n) as the following permutation: [i, 1, 2, \dots, i - 1, i + 1, \dots, n]. This means that the i-th permutation is almost identity (i.e. which maps every element to itself) permu... | 4 4
1 2 3 4
| 3 4 6 5 | 2 seconds | 256 megabytes | ['math', '*2000'] |
D. Distinct Characters Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of lowercase Latin letters and q queries for this string.Recall that the substring s[l; r] of the string s is the string s_l s_{l + 1} \dots s_r. For ex... | abacaba
5
2 1 4
1 4 b
1 5 b
2 4 6
2 1 7
| 3 1 2 | 2 seconds | 256 megabytes | ['data structures', '*1600'] |
C. Pipestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a system of pipes. It consists of two rows, each row consists of n pipes. The top left pipe has the coordinates (1, 1) and the bottom right — (2, n).There are six types of pipes: two types of stra... | 6
7
2323216
1615124
1
3
4
2
13
24
2
12
34
3
536
345
2
46
54
| YES YES YES NO YES NO | 2 seconds | 256 megabytes | ['dp', 'implementation', '*1500'] |
B2. Social Network (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions are constraints on n and k.You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at mo... | 7 2
1 2 3 2 1 3 2
| 2 2 1 | 2 seconds | 256 megabytes | ['data structures', 'implementation', '*1300'] |
B1. Social Network (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions are constraints on n and k.You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at mo... | 7 2
1 2 3 2 1 3 2
| 2 2 1 | 2 seconds | 256 megabytes | ['implementation', '*1000'] |
A. Equalize Prices Againtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs a_i coins.You got tired of remembering the price of each product when customers ask f... | 3
5
1 2 3 4 5
3
1 2 2
4
1 1 1 1
| 3 2 1 | 1 second | 256 megabytes | ['math', '*800'] |
E. Middle-Outtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out.You are given ... | 3
9
iredppipe
piedpiper
4
estt
test
4
tste
test
| 2 1 2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', 'strings', '*2200'] |
C. Increasing Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem, a n \times m rectangular matrix a is called increasing if, for each row of i, when go from left to right, the values strictly increase (that is, a_{i,1}<a_{i,2}<\dots<a_{i,m}) and f... | 4 5
1 3 5 6 7
3 0 7 0 9
5 0 0 0 10
8 9 10 11 12
| 144 | 2 seconds | 256 megabytes | ['greedy', '*1100'] |
B. Ania and Minimizingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnia has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S ... | 5 3
51528
| 10028 | 1 second | 256 megabytes | ['greedy', 'implementation', '*1000'] |
A. Dawid and Bags of Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags ... | 1 7 11 5
| YES | 1 second | 256 megabytes | ['brute force', 'implementation', '*800'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.