contest_id int32 1 2.13k | index stringclasses 62
values | problem_id stringlengths 2 6 | title stringlengths 0 67 | rating int32 0 3.5k | tags stringlengths 0 139 | statement stringlengths 0 6.96k | input_spec stringlengths 0 2.32k | output_spec stringlengths 0 1.52k | note stringlengths 0 5.06k | sample_tests stringlengths 0 1.02k | difficulty_category stringclasses 6
values | tag_count int8 0 11 | statement_length int32 0 6.96k | input_spec_length int16 0 2.32k | output_spec_length int16 0 1.52k | contest_year int16 0 21 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,904 | A | 1904A | A. Forked! | 900 | brute force; implementation | Lunchbox is done with playing chess! His queen and king just got forked again!In chess, a fork is when a knight attacks two pieces of higher value, commonly the king and the queen. Lunchbox knows that knights can be tricky, and in the version of chess that he is playing, knights are even trickier: instead of moving \(1... | Each test contains multiple test cases. The first line contains an integer \(t\) (\(1 \leq t \leq 1000\)) β the number of test cases. The description of the test cases follows.The first line of each test case contains two integers \(a\) and \(b\) (\(1 \le a, b \le 10^8\)) β describing the possible moves of the knight.T... | For each test case, output the number of positions on an infinite chessboard such that a knight can attack both the king and the queen. | In the first test case, the knight can move 2 squares in one direction and 1 square in the other (it is essentially the same as the knight in standard chess). A knight placed on \((2, 1)\) or \((1, 2)\) would attack both the king and queen. Example of a knight placement that forks the queen and king in the first test c... | Input: 42 10 03 31 13 11 34 40 08 04 21 43 4 | Output: 2 1 2 0 | Beginner | 2 | 825 | 699 | 135 | 19 |
1,663 | G | 1663G | G. Six Characters | 0 | *special; constructive algorithms; strings | Aenar should go to the string's home. | A string consisting of only \(6\) letters. | A string consisting of only \(6\) characters. | If many answers are possible, the jury will still only accept one! | Beginner | 3 | 37 | 42 | 45 | 16 | |
2,060 | D | 2060D | D. Subtract Min Sort | 1,100 | greedy | You are given a sequence \(a\) consisting of \(n\) positive integers.You can perform the following operation any number of times. Select an index \(i\) (\(1 \le i < n\)), and subtract \(\min(a_i,a_{i+1})\) from both \(a_i\) and \(a_{i+1}\). Determine if it is possible to make the sequence non-decreasing by using the op... | Each test contains multiple test cases. The first line contains the number of test cases \(t\) (\(1 \le t \le 10^4\)). The description of the test cases follows.The first line of each test case contains a single integer \(n\) (\(2 \le n \le 2 \cdot 10^5\)).The second line of each test case contains \(a_1,a_2,\ldots,a_n... | If it is possible to make the sequence non-decreasing, print ""YES"" on a new line. Otherwise, print ""NO"" on a new line.You can output the answer in any case. For example, the strings ""yEs"", ""yes"", and ""Yes"" will also be recognized as positive responses. | In the first test case, the array is already sorted.In the second test case, we can show that it is impossible.In the third test case, after performing an operation on \(i=1\), the array becomes \([0,1,2,3]\), which is now in nondecreasing order. | Input: 551 2 3 4 544 3 2 144 5 2 384 5 4 5 4 5 4 599 9 8 2 4 4 3 5 3 | Output: YES NO YES YES NO | Easy | 1 | 348 | 440 | 262 | 20 |
1,000 | B | 1000B | B. Light It Up | 1,500 | greedy | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment \(0\) and turn power off at moment \(M\). Moreover, the lamp allows you to set a program of switching its state (states are ""lights on"" and ""lights off""). Unf... | First line contains two space separated integers \(n\) and \(M\) (\(1 \le n \le 10^5\), \(2 \le M \le 10^9\)) β the length of program \(a\) and the moment when power turns off.Second line contains \(n\) space separated integers \(a_1, a_2, \dots, a_n\) (\(0 < a_1 < a_2 < \dots < a_n < M\)) β initially installed program... | Print the only integer β maximum possible total time when the lamp is lit. | In the first example, one of possible optimal solutions is to insert value \(x = 3\) before \(a_1\), so program will be \([3, 4, 6, 7]\) and time of lamp being lit equals \((3 - 0) + (6 - 4) + (10 - 7) = 8\). Other possible solution is to insert \(x = 5\) in appropriate place.In the second example, there is only one op... | Input: 3 104 6 7 | Output: 8 | Medium | 1 | 1,771 | 327 | 74 | 10 |
835 | B | 835B | B. The number on the board | 1,100 | greedy | Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.You have to find the minimum number of digits in which these two numbers can... | The first line contains integer k (1 β€ k β€ 109).The second line contains integer n (1 β€ n < 10100000).There are no leading zeros in n. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and n can differ. | In the first example, the initial number could be 12.In the second example the sum of the digits of n is not less than k. The initial number could be equal to n. | Input: 311 | Output: 1 | Easy | 1 | 328 | 183 | 80 | 8 |
1,100 | D | 1100D | D. Dasha and Chess | 2,500 | constructive algorithms; games; interactive | This is an interactive task.Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.There are \(666\) black rooks and \(1\) white king on the chess board of size \(999 \times 999\). The white king wins if he gets ch... | In the beginning your program will receive \(667\) lines from input. Each line contains two integers \(x\) and \(y\) (\(1 \leq x, y \leq 999\)) β the piece's coordinates. The first line contains the coordinates of the king and the next \(666\) contain the coordinates of the rooks. The first coordinate denotes the numbe... | After getting king checked, you program should terminate immediately without printing anything extra. | The example is trimmed. The full initial positions of the rooks in the first test are available at https://pastebin.com/qQCTXgKP. It is not guaranteed that they will behave as in the example. | Input: 999 9991 11 22 12 21 32 3<...>26 1326 1426 1526 161 700 8002 1 2<...>-1 -1 -1 | Output: 999 998999 997<...>999 26 | Expert | 3 | 1,637 | 493 | 101 | 11 |
960 | C | 960C | C. Subsequence Counting | 1,700 | bitmasks; constructive algorithms; greedy; implementation | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it. Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ ... | The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 109). | Output should consist of two lines.First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.Second line should consist of n space separated integers β a1, a2, ... , an (1 β€ ai < 1018).If there is no answer, print a single integer -1. If there are multiple answers, print a... | In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.Similarly,... | Input: 10 5 | Output: 65 50 7 15 6 100 | Medium | 4 | 759 | 89 | 331 | 9 |
803 | B | 803B | B. Distances to Zero | 1,200 | constructive algorithms | You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. | The first line contains integer n (1 β€ n β€ 2Β·105) β length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 β€ ai β€ 109). | Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j. | Input: 92 1 0 3 0 0 3 2 4 | Output: 2 1 0 1 0 0 1 2 3 | Easy | 1 | 212 | 177 | 146 | 8 | |
1,181 | E1 | 1181E1 | E1. A Story of One Country (Easy) | 2,500 | brute force; divide and conquer; sortings | This problem differs from the next problem only in constraints.Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusual.Initially, there were \(n\) different countries on the land that is now Berland. Each country had its own territory that was represen... | The first line contains a single integer \(n\) (\(1 \leq n \leq 1000\)) β the number of countries and castles.Each of the next \(n\) lines contains four integers \(a_i, b_i, c_i, d_i\) (\(0 \leq a_i < c_i \leq 10^9\), \(0 \leq b_i < d_i \leq 10^9\)) β the coordinates of the \(i\)-th castle, where \((a_i, b_i)\) are the... | If there exists a possible set of territories that satisfies the story, print ""YES"", otherwise print ""NO"".You can print each letter in any case (upper or lower). | The castles in the first and second examples are shown on the pictures below. | Input: 4 0 0 1 2 0 2 1 3 1 0 2 1 1 1 2 3 | Output: YES | Expert | 3 | 1,518 | 496 | 165 | 11 |
1,817 | C | 1817C | C. Similar Polynomials | 2,400 | combinatorics; math | A polynomial \(A(x)\) of degree \(d\) is an expression of the form \(A(x) = a_0 + a_1 x + a_2 x^2 + \dots + a_d x^d\), where \(a_i\) are integers, and \(a_d \neq 0\). Two polynomials \(A(x)\) and \(B(x)\) are called similar if there is an integer \(s\) such that for any integer \(x\) it holds that$$$\( B(x) \equiv A(x+... | The first line contains a single integer \(d\) (\(1 \le d \le 2\,500\,000\)).The second line contains \(d+1\) integers \(A(0), A(1), \ldots, A(d)\) (\(0 \le A(i) < 10^9+7\)) β the values of the polynomial \(A(x)\).The third line contains \(d+1\) integers \(B(0), B(1), \ldots, B(d)\) (\(0 \le B(i) < 10^9+7\)) β the valu... | Print a single integer \(s\) (\(0 \leq s < 10^9+7\)) such that \(B(x) \equiv A(x+s) \pmod{10^9+7}\) for all integers \(x\).If there are multiple solutions, print any. | In the first example, \(A(x) \equiv x-1 \pmod{10^9+7}\) and \(B(x)\equiv x+2 \pmod{10^9+7}\). They're similar because $$$\(B(x) \equiv A(x+3) \pmod{10^9+7}.\)\(In the second example, \)A(x) \equiv (x+1)^2 \pmod{10^9+7}\( and \)B(x) \equiv (x+10)^2 \pmod{10^9+7}\(, hence \)\(B(x) \equiv A(x+9) \pmod{10^9+7}.\)$$$ | Input: 1 1000000006 0 2 3 | Output: 3 | Expert | 2 | 576 | 542 | 166 | 18 |
653 | F | 653F | F. Paper task | 2,600 | data structures; string suffix structures; strings | Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time.For the purpose of this problem we consider only strings consis... | The first line of the input contains an integer n (1 β€ n β€ 500 000) β the length of the string s.The second line contains a string s of length n consisting of only '(' and ')'. | Print the number of distinct non-empty correct sequences that occur in s as substring. | In the first sample, there are 5 distinct substrings we should count: ""()"", ""()()"", ""()()()"", ""()()()()"" and ""()()()()()"".In the second sample, there are 3 distinct substrings we should count: ""()"", ""(())"" and ""(())()"". | Input: 10()()()()() | Output: 5 | Expert | 3 | 1,211 | 176 | 86 | 6 |
1,210 | D | 1210D | D. Konrad and Company Evaluation | 2,400 | graphs | Konrad is a Human Relations consultant working for VoltModder, a large electrical equipment producer. Today, he has been tasked with evaluating the level of happiness in the company.There are \(n\) people working for VoltModder, numbered from \(1\) to \(n\). Each employee earns a different amount of money in the compan... | The first line contains two integers \(n\) and \(m\) (\(1 \le n \le 100\,000\), \(0 \le m \le 100\,000\)) β the number of employees in the company and the number of pairs of people who don't like each other. Each of the following \(m\) lines contains two integers \(a_i\), \(b_i\) (\(1 \le a_i, b_i \le n\), \(a_i \neq b... | Output \(q + 1\) integers. The \(i\)-th of them should contain the number of dangerous triples in the company at the beginning of the \(i\)-th day. | Consider the first sample test. The \(i\)-th row in the following image shows the structure of the company at the beginning of the \(i\)-th day. A directed edge from \(a\) to \(b\) denotes that employee \(a\) brags to employee \(b\). The dangerous triples are marked by highlighted edges. | Input: 4 5 1 2 2 4 1 3 3 4 2 3 2 2 3 | Output: 4 3 2 | Expert | 1 | 1,212 | 787 | 147 | 12 |
612 | A | 612A | A. The Text Splitting | 1,300 | brute force; implementation; strings | You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.For example, the string ""Hello"" for p = 2, q = 3 can be split to the two strings ""Hel"" and ""lo"" or to the two strings ""He"" and ""llo"".Note it is allowed to split the string s to the strings only of lengt... | The first line contains three positive integers n, p, q (1 β€ p, q β€ n β€ 100).The second line contains the string s consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string s to the strings of length p and q print the only number ""-1"".Otherwise in the first line print integer k β the number of strings in partition of s.Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be ... | Input: 5 2 3Hello | Output: 2Hello | Easy | 3 | 388 | 176 | 430 | 6 | |
921 | 05 | 92105 | 05. Labyrinth-5 | 3,200 | See the problem statement here: http://codeforces.com/contest/921/problem/01. | Master | 0 | 77 | 0 | 0 | 9 | |||||
1,279 | C | 1279C | C. Stack of Presents | 1,400 | data structures; implementation | Santa has to send presents to the kids. He has a large stack of \(n\) presents, numbered from \(1\) to \(n\); the topmost present has number \(a_1\), the next present is \(a_2\), and so on; the bottom present has number \(a_n\). All numbers are distinct.Santa has a list of \(m\) distinct presents he has to send: \(b_1\... | The first line contains one integer \(t\) (\(1 \le t \le 100\)) β the number of test cases.Then the test cases follow, each represented by three lines.The first line contains two integers \(n\) and \(m\) (\(1 \le m \le n \le 10^5\)) β the number of presents in the stack and the number of presents Santa wants to send, r... | For each test case print one integer β the minimum number of seconds which Santa has to spend sending presents, if he reorders the presents optimally each time he returns them into the stack. | Input: 2 3 3 3 1 2 3 2 1 7 2 2 1 7 3 4 5 6 3 1 | Output: 5 8 | Easy | 2 | 1,236 | 713 | 191 | 12 | |
1,651 | C | 1651C | C. Fault-tolerant Network | 1,500 | brute force; data structures; implementation | There is a classroom with two rows of computers. There are \(n\) computers in each row and each computer has its own grade. Computers in the first row have grades \(a_1, a_2, \dots, a_n\) and in the second row β \(b_1, b_2, \dots, b_n\).Initially, all pairs of neighboring computers in each row are connected by wire (pa... | The first line contains a single integer \(t\) (\(1 \le t \le 10^4\)) β the number of test cases. Next, \(t\) cases follow.The first line of each test case contains the single integer \(n\) (\(3 \le n \le 2 \cdot 10^5\)) β the number of computers in each row.The second line contains \(n\) integers \(a_1, a_2, \dots, a_... | For each test case, print a single integer β the minimum total cost to make a fault-tolerant network. | In the first test case, it's optimal to connect four pairs of computers: computer \(1\) from the first row with computer \(2\) from the second row: cost \(|1 - 4| = 3\); computer \(3\) from the first row with computer \(2\) from the second row: cost \(|1 - 4| = 3\); computer \(2\) from the first row with computer \(1\)... | Input: 231 10 120 4 2541 1 1 11000000000 1000000000 1000000000 1000000000 | Output: 31 1999999998 | Medium | 3 | 1,062 | 601 | 101 | 16 |
1,698 | F | 1698F | F. Equal Reversal | 2,800 | constructive algorithms; graphs; implementation; math | There is an array \(a\) of length \(n\). You may perform the following operation on it: Choose two indices \(l\) and \(r\) where \(1 \le l \le r \le n\) and \(a_l = a_r\). Then, reverse the subsegment from the \(l\)-th to the \(r\)-th element, i. e. set \([a_l, a_{l + 1}, \ldots, a_{r - 1}, a_r]\) to \([a_r, a_{r-1}, \... | Each test contains multiple test cases. The first line contains a single integer \(t\) (\(1 \leq t \leq 100\)) β the number of test cases. The description of the test cases follows.The first line of each test case contains an integer \(n\) (\(1 \le n \le 500\)) β the length of array \(a\) and \(b\).The second line of e... | For each test case, output ""NO"" (without quotes) if it is impossible to turn \(a\) into \(b\) using at most \(n^2\) operations.Otherwise, output ""YES"" (without quotes). Then output an integer \(k\) (\(0 \leq k \leq n^2\)) denoting the number of operations you will perform. Note that you don't have to minimize the n... | In the first test case, we can perform the following operations: $$$\([1,2,4,3,1,2,1,1] \xrightarrow[l=5,\,r=8]{} [1,2,4,3,1,1,2,1] \xrightarrow[l=1,\,r=6]{} [1,1,3,4,2,1,2,1].\)\(In the second test case, we can perform the following operations: \)\([1,2,3,1,3,2,3] \xrightarrow[l=1,\,r=4]{} [1,3,2,1,3,2,3] \xrightarrow... | Input: 581 2 4 3 1 2 1 11 1 3 4 2 1 2 171 2 3 1 3 2 31 3 2 3 1 2 331 1 21 2 121 22 1111 | Output: YES 2 5 8 1 6 YES 2 1 4 3 6 NO NO YES 0 | Master | 4 | 557 | 708 | 750 | 16 |
1,418 | A | 1418A | A. Buying Torches | 1,000 | math | You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft \(k\) torches. One torch can be crafted using one stick and one coal.Hopefully, you've met a very handsome wandering trader who has two trade offers: exchange \(1\) stick for \(x\) sticks (you lose \(1\) stick and gain... | The first line of the input contains one integer \(t\) (\(1 \le t \le 2 \cdot 10^4\)) β the number of test cases. Then \(t\) test cases follow.The only line of the test case contains three integers \(x\), \(y\) and \(k\) (\(2 \le x \le 10^9\); \(1 \le y, k \le 10^9\)) β the number of sticks you can buy with one stick, ... | For each test case, print the answer: the minimum number of trades you need to craft at least \(k\) torches. The answer always exists under the given constraints. | Input: 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 | Output: 14 33 25 2000000003 1000000001999999999 | Beginner | 1 | 752 | 415 | 162 | 14 | |
1,949 | A | 1949A | A. Grove | 3,300 | brute force; dfs and similar; dp; geometry; probabilities | You want to plant trees in a square lawn of size \(n \times n\) whose corners have Cartesian coordinates \((0, 0)\), \((n, 0)\), \((0, n)\), and \((n, n)\). Trees can only be planted at locations with integer coordinates. Every tree will grow roots within a disk of radius \(r\) centered at the location where the tree w... | The first and only line contains an integer \(n\) (\(1 \leq n \leq 20\)) and a real number \(r\) (\(0 < r \leq n/2\)) β the length of the sides of the lawn, and the radius of the disks where each tree will grow roots. The real number \(r\) is given in decimal notation with at least \(1\) and at most \(3\) digits after ... | In the first line, print the maximum number \(m\) of trees that can be planted.In the next \(m\) lines, print a configuration that maximizes the number of trees. Specifically, in the \((i+1)\)-th line, print two integers \(x\) and \(y\) β the coordinates of the location where the \(i\)-th tree should be planted. You ca... | For the first sample, the sample output is shown in the following figure. Note that this is not the only configuration that maximizes the number of trees. For the second sample, the sample output is shown in the following figure. Note that this is not the only configuration that maximizes the number of trees. | Input: 6 1.241 | Output: 2 4 2 2 4 | Master | 5 | 534 | 338 | 402 | 19 |
624 | B | 624B | B. Making a String | 1,100 | greedy; sortings | You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than ai times; the number of occurrences of each letter in the string must be distinct for all the letters that occ... | The first line of the input contains a single integer n (2 β€ n β€ 26) β the number of letters in the alphabet.The next line contains n integers ai (1 β€ ai β€ 109) β i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string. | Print a single integer β the maximum length of the string that meets all the requirements. | For convenience let's consider an alphabet consisting of three letters: ""a"", ""b"", ""c"". In the first sample, some of the optimal strings are: ""cccaabbccbb"", ""aabcbcbcbcb"". In the second sample some of the optimal strings are: ""acc"", ""cbc"". | Input: 32 5 5 | Output: 11 | Easy | 2 | 354 | 272 | 90 | 6 |
1,208 | C | 1208C | C. Magic Grid | 1,800 | constructive algorithms | Let us define a magic grid to be a square matrix of integers of size \(n \times n\), satisfying the following conditions. All integers from \(0\) to \((n^2 - 1)\) inclusive appear in the matrix exactly once. Bitwise XOR of all elements in a row or a column must be the same for each row and column. You are given an inte... | The only line of input contains an integer \(n\) (\(4 \leq n \leq 1000\)). It is guaranteed that \(n\) is a multiple of \(4\). | Print a magic grid, i.e. \(n\) lines, the \(i\)-th of which contains \(n\) space-separated integers, representing the \(i\)-th row of the grid.If there are multiple answers, print any. We can show that an answer always exists. | In the first example, XOR of each row and each column is \(13\).In the second example, XOR of each row and each column is \(60\). | Input: 4 | Output: 8 9 1 13 3 12 7 5 0 2 4 11 6 10 15 14 | Medium | 1 | 406 | 126 | 226 | 12 |
1,116 | D4 | 1116D4 | D4. TIE fighter | 0 | *special | Implement a unitary operation on \(N\) qubits which is represented by a square matrix of size \(2^N\) which has non-zero elements in the following positions: the central 2x2 sub-matrix, the diagonals of the top right and bottom left square sub-matrices of size \(2^{N-1}-1\) that do not overlap with the central 2x2 sub-... | Beginner | 1 | 2,138 | 0 | 0 | 11 | ||||
1,266 | G | 1266G | G. Permutation Concatenation | 3,300 | string suffix structures | Let \(n\) be an integer. Consider all permutations on integers \(1\) to \(n\) in lexicographic order, and concatenate them into one big sequence \(P\). For example, if \(n = 3\), then \(P = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]\). The length of this sequence is \(n \cdot n!\).Let \(1 \leq i \leq j \leq... | The only line contains one integer \(n\) (\(1 \leq n \leq 10^6\)), as described in the problem statement. | Output a single integer β the number of distinct subarrays, modulo \(998244353\). | In the first example, the sequence \(P = [1, 2, 2, 1]\). It has eight distinct subarrays: \([1]\), \([2]\), \([1, 2]\), \([2, 1]\), \([2, 2]\), \([1, 2, 2]\), \([2, 2, 1]\) and \([1, 2, 2, 1]\). | Input: 2 | Output: 8 | Master | 1 | 587 | 105 | 81 | 12 |
494 | E | 494E | E. Sharti | 3,200 | data structures; games | During the last 24 hours Hamed and Malek spent all their time playing ""Sharti"". Now they are too exhausted to finish the last round. So they asked you for help to determine the winner of this round. ""Sharti"" is played on a n Γ n board with some of cells colored white and others colored black. The rows of the board ... | In this problem the initial board is specified as a set of m rectangles. All cells that lie inside at least one of these rectangles are colored white and the rest are colored black.In the first line of input three space-spereated integers n, m, k (1 β€ k β€ n β€ 109, 1 β€ m β€ 5Β·104) follow, denoting size of the board, numb... | If Hamed wins, print ""Hamed"", otherwise print ""Malek"" (without the quotes). | Input: 5 2 11 1 3 32 2 4 4 | Output: Malek | Master | 2 | 1,119 | 665 | 79 | 4 | |
454 | A | 454A | A. Little Pony and Crystal Mine | 800 | implementation | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n Γ n matrix with a diamond inscribed into it.You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character ""D"". All other cells of the matr... | The only line contains an integer n (3 β€ n β€ 101; n is odd). | Output a crystal of size n. | Input: 3 | Output: *D*DDD*D* | Beginner | 1 | 422 | 60 | 27 | 4 | |
1,973 | E | 1973E | E. Cat, Fox and Swaps | 2,500 | graphs; math; sortings | Fox has found an array \(p_1, p_2, \ldots, p_n\), that is a permutation of length \(n^\dagger\) of the numbers \(1, 2, \ldots, n\). She wants to sort the elements in increasing order. Cat wants to help her β he is able to swap any two numbers \(x\) and \(y\) in the array, but only if \(l \leq x + y \leq r\) (note that ... | Each test contains multiple test cases. The first line contains the number of test cases \(t\) (\(1 \le t \le 10^4\)). The description of the test cases follows.Description of each test case consists of two lines. The first line contains one integer \(n\) (\(1 \leq n \leq 10^5\)).The second line contains \(n\) integers... | For each test case, print the number of pairs of integers \((l, r)\) such that \(1 \leq l \leq r \leq 2 \cdot n\), and you can sort the array under the constraints. | In the first example, we need to be able to swap \(1\) and \(2\), so we must be able to swap numbers with sum \(3\). There are exactly \(6\) pairs satisfying the condition: \((1, 3), (2, 3), (3, 3), (1, 4), (2, 4)\) and \((3, 4)\), so the answer is \(6\).In the second example, the \(11\) pairs satisfying the condition ... | Input: 722 133 1 243 2 1 455 3 1 2 451 2 3 4 563 2 1 5 4 661 3 2 4 5 6 | Output: 6 11 23 29 55 46 58 | Expert | 3 | 1,200 | 532 | 164 | 19 |
1,523 | A | 1523A | A. Game of Life | 800 | implementation | William really likes the cellular automaton called ""Game of Life"" so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing \(n\) cells, with each cell either being alive or dead.Evolution of the array in William's cellular automaton occurs iterativ... | Each test contains multiple test cases. The first line contains the number of test cases \(t\) (\(1 \le t \le 10^3\)). Description of the test cases follows.The first line of each test case contains two integers \(n\) and \(m\) (\(2 \le n \le 10^3, 1 \le m \le 10^9\)), which are the total number of cells in the array a... | In each test case output a string of length \(n\), made up of characters ""0"" and ""1"" β the state of the array after \(m\) iterations of evolution. | Sequence of iterations of evolution for the first test case 01000000001 β initial state 11100000011 β first iteration of evolution 11110000111 β second iteration of evolution 11111001111 β third iteration of evolution Sequence of iterations of evolution for the second test case 0110100101 β initial state 1110111101 β f... | Input: 4 11 3 01000000001 10 2 0110100101 5 2 10101 3 100 000 | Output: 11111001111 1110111101 10101 000 | Beginner | 1 | 927 | 637 | 150 | 15 |
379 | B | 379B | B. New Year Present | 1,200 | constructive algorithms; implementation | The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to ... | The first line contains integer n (2 β€ n β€ 300) β the number of wallets. The next line contains n integers a1, a2, ..., an (0 β€ ai β€ 300).It is guaranteed that at least one ai is positive. | Print the sequence that consists of k (1 β€ k β€ 106) characters, each of them equals: ""L"", ""R"" or ""P"". Each character of the sequence is an instruction to the robot. Character ""L"" orders to move to the left, character ""R"" orders to move to the right, character ""P"" orders the robot to put a coin in the wallet... | Input: 21 2 | Output: PRPLRP | Easy | 2 | 1,069 | 188 | 637 | 3 | |
1,486 | B | 1486B | B. Eastern Exhibition | 1,500 | binary search; geometry; shortest paths; sortings | You and your friends live in \(n\) houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with in... | First line contains a single integer \(t\) \((1 \leq t \leq 1000)\) β the number of test cases.The first line of each test case contains a single integer \(n\) \((1 \leq n \leq 1000)\). Next \(n\) lines describe the positions of the houses \((x_i, y_i)\) \((0 \leq x_i, y_i \leq 10^9)\).It's guaranteed that the sum of a... | For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house. | Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at \((0, 0)\). | Input: 6 3 0 0 2 0 1 2 4 1 0 0 2 2 3 3 1 4 0 0 0 1 1 0 1 1 2 0 0 1 1 2 0 0 2 0 2 0 0 0 0 | Output: 1 4 4 4 3 1 | Medium | 4 | 625 | 354 | 159 | 14 |
1,358 | D | 1358D | D. The Best Vacation | 1,900 | binary search; brute force; greedy; implementation; two pointers | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly \(x\) days and that's the exact number of... | The first line of input contains two integers \(n\) and \(x\) (\(1 \le n \le 2 \cdot 10^5\)) β the number of months in the year and the number of days you can spend with your friend.The second line contains \(n\) integers \(d_1, d_2, \ldots, d_n\), \(d_i\) is the number of days in the \(i\)-th month (\(1 \le d_i \le 10... | Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \(\{1,1,2,3,1\}\). Coronavirus-chan will hug you the most if you come on the third day of the year: \(2+3=5\) hugs.In the second test case, the numbers of the days are \(\{1,2,3,1,2,3,1,2,3\}\). You will get the mos... | Input: 3 2 1 3 1 | Output: 5 | Hard | 5 | 1,118 | 389 | 124 | 13 |
581 | F | 581F | F. Zublicanes and Mumocrates | 2,400 | dp; trees; two pointers | It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on n main squares of the capital of Berland. Each of the n squares certainly can have demonstrations of only one party, otherwise it could lead to riots... | The first line of the input contains a single integer n (2 β€ n β€ 5000) β the number of squares in the capital of Berland.Next n - 1 lines contain the pairs of integers x, y (1 β€ x, y β€ n, x β y) β the numbers of the squares connected by the road. All squares are numbered with integers from 1 to n. It is guaranteed that... | Print a single number β the minimum number of roads connecting the squares with demonstrations of different parties. | Input: 81 42 43 46 57 58 54 5 | Output: 1 | Expert | 3 | 1,389 | 372 | 116 | 5 | |
841 | B | 841B | B. Godsend | 1,100 | games; math | Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a... | First line of input data contains single integer n (1 β€ n β€ 106) β length of the array.Next line contains n integers a1, a2, ..., an (0 β€ ai β€ 109). | Output answer in single line. ""First"", if first player wins, and ""Second"" otherwise (without quotes). | In first sample first player remove whole array in one move and win.In second sample first player can't make a move and lose. | Input: 41 3 2 3 | Output: First | Easy | 2 | 545 | 148 | 105 | 8 |
1,965 | D | 1965D | D. Missing Subarray Sum | 2,900 | constructive algorithms | There is a hidden array \(a\) of \(n\) positive integers. You know that \(a\) is a palindrome, or in other words, for all \(1 \le i \le n\), \(a_i = a_{n + 1 - i}\). You are given the sums of all but one of its distinct subarrays, in arbitrary order. The subarray whose sum is not given can be any of the \(\frac{n(n+1)}... | The first line of the input contains a single integer \(t\) (\(1 \le t \le 200\)) β the number of test cases. The description of the test cases follows.The first line of each test case contains a single integer \(n\) (\(3 \le n \le 1000\)) β the size of the array \(a\).The next line of each test case contains \(\frac{n... | For each test case, print one line containing \(n\) positive integers \(a_1, a_2, \cdots a_n\) β any valid array \(a\). Note that \(a\) must be a palindrome.If there are multiple solutions, print any. | For the first example case, the subarrays of \(a = [1, 2, 1]\) are: \([1]\) with sum \(1\), \([2]\) with sum \(2\), \([1]\) with sum \(1\), \([1, 2]\) with sum \(3\), \([2, 1]\) with sum \(3\), \([1, 2, 1]\) with sum \(4\). So the full list of subarray sums is \(1, 1, 2, 3, 3, 4\), and the sum that is missing from the ... | Input: 731 2 3 4 1418 2 11 9 7 11 7 2 945 10 5 16 3 3 13 8 848 10 4 6 4 20 14 14 651 2 3 4 5 4 3 2 1 1 2 3 2 151 1 2 2 2 3 3 3 3 4 5 5 6 83500000000 1000000000 500000000 500000000 1000000000 | Output: 1 2 1 7 2 2 7 3 5 5 3 6 4 4 6 1 1 1 1 1 2 1 2 1 2 500000000 500000000 500000000 | Master | 1 | 705 | 623 | 200 | 19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.