EtashGuha commited on
Commit
6ff944e
·
verified ·
1 Parent(s): b0519d6

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. code_contests-0001/instruction.md +60 -0
  2. code_contests-0006/instruction.md +81 -0
  3. code_contests-0008/instruction.md +72 -0
  4. code_contests-0052/instruction.md +59 -0
  5. code_contests-0055/instruction.md +75 -0
  6. code_contests-0118/instruction.md +67 -0
  7. code_contests-0205/instruction.md +110 -0
  8. code_contests-0234/instruction.md +74 -0
  9. code_contests-0258/instruction.md +68 -0
  10. code_contests-0260/instruction.md +42 -0
  11. code_contests-0267/instruction.md +69 -0
  12. code_contests-0293/instruction.md +103 -0
  13. code_contests-0315/instruction.md +99 -0
  14. code_contests-0407/instruction.md +97 -0
  15. code_contests-0409/instruction.md +34 -0
  16. code_contests-0431/instruction.md +102 -0
  17. code_contests-0436/instruction.md +91 -0
  18. code_contests-0438/instruction.md +78 -0
  19. code_contests-0453/instruction.md +66 -0
  20. code_contests-0462/instruction.md +67 -0
  21. code_contests-0465/instruction.md +66 -0
  22. code_contests-0491/instruction.md +39 -0
  23. code_contests-0498/instruction.md +100 -0
  24. code_contests-0543/instruction.md +65 -0
  25. code_contests-0544/instruction.md +67 -0
  26. code_contests-0588/instruction.md +68 -0
  27. code_contests-0603/instruction.md +79 -0
  28. code_contests-0635/instruction.md +63 -0
  29. code_contests-0650/instruction.md +147 -0
  30. code_contests-0657/instruction.md +83 -0
  31. code_contests-0668/instruction.md +84 -0
  32. code_contests-0695/instruction.md +43 -0
  33. code_contests-0771/instruction.md +77 -0
  34. code_contests-0776/instruction.md +51 -0
  35. code_contests-0785/instruction.md +88 -0
  36. code_contests-0805/instruction.md +41 -0
  37. code_contests-0833/instruction.md +66 -0
  38. code_contests-0834/instruction.md +50 -0
  39. code_contests-0851/instruction.md +87 -0
  40. code_contests-0856/instruction.md +72 -0
  41. code_contests-0860/instruction.md +79 -0
  42. code_contests-0893/instruction.md +69 -0
  43. code_contests-0894/instruction.md +59 -0
  44. code_contests-0912/instruction.md +130 -0
  45. code_contests-0924/instruction.md +56 -0
  46. code_contests-10004/instruction.md +57 -0
  47. code_contests-1001/instruction.md +109 -0
  48. code_contests-10035/instruction.md +58 -0
  49. code_contests-10050/instruction.md +71 -0
  50. code_contests-10057/instruction.md +59 -0
code_contests-0001/instruction.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # comm3
2
+
3
+ ## Problem Description
4
+ The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly.
5
+
6
+
7
+ The Chef invested in top-of-the-line transceivers which have a few advanced features. One is that even if two people cannot talk directly because they are out of range, if there is another transceiver that is close enough to both, then the two transceivers can still communicate with each other using the third transceiver as an intermediate device.
8
+
9
+
10
+ There has been a minor emergency in the Chef's restaurant
11
+ and he needs to communicate with both the head server and the sous-chef right away. Help the Chef determine if it is possible for all three people to communicate with each other, even if two must communicate through the third because they are too far apart.
12
+
13
+
14
+ Input
15
+
16
+ The first line contains a single positive integer T ≤ 100 indicating the number of test cases to follow. The first line of each test case contains a positive integer R ≤ 1,000 indicating that two transceivers can communicate directly without an intermediate transceiver if they are at most R meters away from each other. The remaining three lines of the test case describe the current locations of the Chef, the head server, and the sous-chef, respectively. Each such line contains two integers X,Y (at most 10,000 in absolute value) indicating that the respective person is located at position X,Y.
17
+
18
+
19
+ Output
20
+
21
+ For each test case you are to output a single line containing a single string. If it is possible for all three to communicate then you should output "yes". Otherwise, you should output "no".
22
+
23
+
24
+ To be clear, we say that two transceivers are close enough to communicate directly if the length of the straight line connecting their X,Y coordinates is at most R.
25
+
26
+
27
+ Example
28
+
29
+ Input:
30
+ 3
31
+ 1
32
+ 0 1
33
+ 0 0
34
+ 1 0
35
+ 2
36
+ 0 1
37
+ 0 0
38
+ 1 0
39
+ 2
40
+ 0 0
41
+ 0 2
42
+ 2 1
43
+
44
+
45
+ Output:
46
+ yes
47
+ yes
48
+ no
49
+
50
+ ## Contest Information
51
+ - **Contest ID**: 0
52
+ - **Problem Index**:
53
+ - **Points**: 0.0
54
+ - **Rating**: 0
55
+ - **Tags**: None
56
+ - **Time Limit**: None seconds
57
+ - **Memory Limit**: 0 bytes
58
+
59
+ ## Task
60
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0006/instruction.md ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1012_E. Cycle sort
2
+
3
+ ## Problem Description
4
+ You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., the number at the position i_k to the position i_1. In other words, the operation cyclically shifts elements: i_1 → i_2 → … i_k → i_1.
5
+
6
+ For example, if you have n=4, an array a_1=10, a_2=20, a_3=30, a_4=40, and you choose three indices i_1=2, i_2=1, i_3=4, then the resulting array would become a_1=20, a_2=40, a_3=30, a_4=10.
7
+
8
+ Your goal is to make the array sorted in non-decreasing order with the minimum number of operations. The additional constraint is that the sum of cycle lengths over all operations should be less than or equal to a number s. If it's impossible to sort the array while satisfying that constraint, your solution should report that as well.
9
+
10
+ Input
11
+
12
+ The first line of the input contains two integers n and s (1 ≤ n ≤ 200 000, 0 ≤ s ≤ 200 000)—the number of elements in the array and the upper bound on the sum of cycle lengths.
13
+
14
+ The next line contains n integers a_1, a_2, ..., a_n—elements of the array (1 ≤ a_i ≤ 10^9).
15
+
16
+ Output
17
+
18
+ If it's impossible to sort the array using cycles of total length not exceeding s, print a single number "-1" (quotes for clarity).
19
+
20
+ Otherwise, print a single number q— the minimum number of operations required to sort the array.
21
+
22
+ On the next 2 ⋅ q lines print descriptions of operations in the order they are applied to the array. The description of i-th operation begins with a single line containing one integer k (1 ≤ k ≤ n)—the length of the cycle (that is, the number of selected indices). The next line should contain k distinct integers i_1, i_2, ..., i_k (1 ≤ i_j ≤ n)—the indices of the cycle.
23
+
24
+ The sum of lengths of these cycles should be less than or equal to s, and the array should be sorted after applying these q operations.
25
+
26
+ If there are several possible answers with the optimal q, print any of them.
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+ 5 5
33
+ 3 2 3 1 1
34
+
35
+
36
+ Output
37
+
38
+ 1
39
+ 5
40
+ 1 4 2 3 5
41
+
42
+
43
+ Input
44
+
45
+ 4 3
46
+ 2 1 4 3
47
+
48
+
49
+ Output
50
+
51
+ -1
52
+
53
+ Input
54
+
55
+ 2 0
56
+ 2 2
57
+
58
+
59
+ Output
60
+
61
+ 0
62
+
63
+ Note
64
+
65
+ In the first example, it's also possible to sort the array with two operations of total length 5: first apply the cycle 1 → 4 → 1 (of length 2), then apply the cycle 2 → 3 → 5 → 2 (of length 3). However, it would be wrong answer as you're asked to use the minimal possible number of operations, which is 1 in that case.
66
+
67
+ In the second example, it's possible to the sort the array with two cycles of total length 4 (1 → 2 → 1 and 3 → 4 → 3). However, it's impossible to achieve the same using shorter cycles, which is required by s=3.
68
+
69
+ In the third example, the array is already sorted, so no operations are needed. Total length of empty set of cycles is considered to be zero.
70
+
71
+ ## Contest Information
72
+ - **Contest ID**: 1012
73
+ - **Problem Index**: E
74
+ - **Points**: 2500.0
75
+ - **Rating**: 3100
76
+ - **Tags**: dsu, math
77
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
78
+ - **Memory Limit**: 256000000 bytes
79
+
80
+ ## Task
81
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0008/instruction.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1060_A. Phone Numbers
2
+
3
+ ## Problem Description
4
+ Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
5
+
6
+ For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
7
+
8
+ You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
9
+
10
+ Input
11
+
12
+ The first line contains an integer n — the number of cards with digits that you have (1 ≤ n ≤ 100).
13
+
14
+ The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, …, s_n. The string will not contain any other characters, such as leading or trailing spaces.
15
+
16
+ Output
17
+
18
+ If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 11
25
+ 00000000008
26
+
27
+
28
+ Output
29
+
30
+ 1
31
+
32
+
33
+ Input
34
+
35
+ 22
36
+ 0011223344556677889988
37
+
38
+
39
+ Output
40
+
41
+ 2
42
+
43
+
44
+ Input
45
+
46
+ 11
47
+ 31415926535
48
+
49
+
50
+ Output
51
+
52
+ 0
53
+
54
+ Note
55
+
56
+ In the first example, one phone number, "8000000000", can be made from these cards.
57
+
58
+ In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
59
+
60
+ In the third example you can't make any phone number from the given cards.
61
+
62
+ ## Contest Information
63
+ - **Contest ID**: 1060
64
+ - **Problem Index**: A
65
+ - **Points**: 500.0
66
+ - **Rating**: 800
67
+ - **Tags**: brute force
68
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
69
+ - **Memory Limit**: 512000000 bytes
70
+
71
+ ## Task
72
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0052/instruction.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 663_A. Rebus
2
+
3
+ ## Problem Description
4
+ You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
5
+
6
+ Input
7
+
8
+ The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer n is positive and doesn't exceed 1 000 000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.
9
+
10
+ Output
11
+
12
+ The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise.
13
+
14
+ If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to n. Follow the format given in the samples.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ ? + ? - ? + ? + ? = 42
21
+
22
+
23
+ Output
24
+
25
+ Possible
26
+ 9 + 13 - 39 + 28 + 31 = 42
27
+
28
+
29
+ Input
30
+
31
+ ? - ? = 1
32
+
33
+
34
+ Output
35
+
36
+ Impossible
37
+
38
+
39
+ Input
40
+
41
+ ? = 1000000
42
+
43
+
44
+ Output
45
+
46
+ Possible
47
+ 1000000 = 1000000
48
+
49
+ ## Contest Information
50
+ - **Contest ID**: 663
51
+ - **Problem Index**: A
52
+ - **Points**: 500.0
53
+ - **Rating**: 1800
54
+ - **Tags**: constructive algorithms, expression parsing, greedy, math
55
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
56
+ - **Memory Limit**: 256000000 bytes
57
+
58
+ ## Task
59
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0055/instruction.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 730_J. Bottles
2
+
3
+ ## Problem Description
4
+ Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).
5
+
6
+ Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda from one bottle to another.
7
+
8
+ Nick asks you to help him to determine k — the minimal number of bottles to store all remaining soda and t — the minimal time to pour soda into k bottles. A bottle can't store more soda than its volume. All remaining soda should be saved.
9
+
10
+ Input
11
+
12
+ The first line contains positive integer n (1 ≤ n ≤ 100) — the number of bottles.
13
+
14
+ The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the amount of soda remaining in the i-th bottle.
15
+
16
+ The third line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ 100), where bi is the volume of the i-th bottle.
17
+
18
+ It is guaranteed that ai ≤ bi for any i.
19
+
20
+ Output
21
+
22
+ The only line should contain two integers k and t, where k is the minimal number of bottles that can store all the soda and t is the minimal time to pour the soda into k bottles.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 4
29
+ 3 3 4 3
30
+ 4 7 6 5
31
+
32
+
33
+ Output
34
+
35
+ 2 6
36
+
37
+
38
+ Input
39
+
40
+ 2
41
+ 1 1
42
+ 100 100
43
+
44
+
45
+ Output
46
+
47
+ 1 1
48
+
49
+
50
+ Input
51
+
52
+ 5
53
+ 10 30 5 6 24
54
+ 10 41 7 8 24
55
+
56
+
57
+ Output
58
+
59
+ 3 11
60
+
61
+ Note
62
+
63
+ In the first example Nick can pour soda from the first bottle to the second bottle. It will take 3 seconds. After it the second bottle will contain 3 + 3 = 6 units of soda. Then he can pour soda from the fourth bottle to the second bottle and to the third bottle: one unit to the second and two units to the third. It will take 1 + 2 = 3 seconds. So, all the soda will be in two bottles and he will spend 3 + 3 = 6 seconds to do it.
64
+
65
+ ## Contest Information
66
+ - **Contest ID**: 730
67
+ - **Problem Index**: J
68
+ - **Points**: 0.0
69
+ - **Rating**: 1900
70
+ - **Tags**: dp
71
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
72
+ - **Memory Limit**: 512000000 bytes
73
+
74
+ ## Task
75
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0118/instruction.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1195_D2. Submarine in the Rybinsk Sea (hard edition)
2
+
3
+ ## Problem Description
4
+ This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
5
+
6
+ A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.
7
+
8
+ Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros.
9
+
10
+ In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.
11
+
12
+ For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$
13
+
14
+ Formally,
15
+
16
+ * if p ≥ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q;
17
+ * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q.
18
+
19
+
20
+
21
+ Mishanya gives you an array consisting of n integers a_i, your task is to help students to calculate ∑_{i = 1}^{n}∑_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353.
22
+
23
+ Input
24
+
25
+ The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.
26
+
27
+ Output
28
+
29
+ Print the answer modulo 998 244 353.
30
+
31
+ Examples
32
+
33
+ Input
34
+
35
+
36
+ 3
37
+ 12 3 45
38
+
39
+
40
+ Output
41
+
42
+
43
+ 12330
44
+
45
+ Input
46
+
47
+
48
+ 2
49
+ 123 456
50
+
51
+
52
+ Output
53
+
54
+
55
+ 1115598
56
+
57
+ ## Contest Information
58
+ - **Contest ID**: 1195
59
+ - **Problem Index**: D2
60
+ - **Points**: 1500.0
61
+ - **Rating**: 1800
62
+ - **Tags**: combinatorics, math, number theory
63
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
64
+ - **Memory Limit**: 256000000 bytes
65
+
66
+ ## Task
67
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0205/instruction.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02157 Shuffle 2
2
+
3
+ ## Problem Description
4
+ Problem
5
+
6
+ There is a bundle of $ n $ cards, with $ i $ written on the $ i $ th card from the bottom. Shuffle this bundle as defined below $ q $ times.
7
+
8
+
9
+ * When looking at the bundle from below, consider a bundle $ x $ made by stacking odd-numbered cards on top, and a bundle $ y $ made by stacking even-numbered cards on top. Then do whatever you like out of the following $ 2 $.
10
+ * Operation $ 0 $: Put the bundle $ y $ on the bundle $ x $ to make a bundle of $ 1 $.
11
+ * Operation $ 1 $: Put the bundle $ x $ on the bundle $ y $ to make a bundle of $ 1 $.
12
+
13
+
14
+
15
+ For example, if you consider shuffling $ 1 $ times for a bundle of $ 6 $ cards (123456 from the bottom), the bundle you get when you perform the operation $ 0 $ is ~~ 246135 ~~ from the bottom. 135246, the bundle obtained by performing the operation $ 1 $ is ~~ 135246 ~~ 246135 from the bottom. (Corrected at 14:52)
16
+
17
+ After $ q $ shuffle, I want the card with $ k $ to be $ d $ th from the bottom of the bunch.
18
+ If possible, print $ q $ of shuffle operations in sequence, and if not, print $ -1 $.
19
+
20
+ Constraints
21
+
22
+ The input satisfies the following conditions.
23
+
24
+ * $ 2 \ le n \ le 10 ^ {15} $
25
+ * $ 1 \ le q \ le 10 ^ 6 $
26
+ * $ 1 \ le k, d \ le n $
27
+ * $ n $ is even
28
+
29
+ Input
30
+
31
+ The input is given in the following format.
32
+
33
+
34
+ $ n $ $ q $ $ k $ $ d $
35
+
36
+
37
+ Output
38
+
39
+ If it is possible to shuffle the conditions, output the shuffle operation on the $ q $ line.
40
+
41
+ If not possible, output $ -1 $.
42
+
43
+ Examples
44
+
45
+ Input
46
+
47
+ 4 2 1 1
48
+
49
+
50
+ Output
51
+
52
+ 0
53
+ 0
54
+
55
+
56
+ Input
57
+
58
+ 4 2 3 1
59
+
60
+
61
+ Output
62
+
63
+ 0
64
+ 1
65
+
66
+
67
+ Input
68
+
69
+ 4 1 1 4
70
+
71
+
72
+ Output
73
+
74
+ -1
75
+
76
+
77
+ Input
78
+
79
+ 7834164883628 15 2189823423122 5771212644938
80
+
81
+
82
+ Output
83
+
84
+ 0
85
+ 1
86
+ 1
87
+ 1
88
+ 1
89
+ 1
90
+ 0
91
+ 1
92
+ 0
93
+ 1
94
+ 0
95
+ 0
96
+ 0
97
+ 0
98
+ 0
99
+
100
+ ## Contest Information
101
+ - **Contest ID**: 0
102
+ - **Problem Index**:
103
+ - **Points**: 0.0
104
+ - **Rating**: 0
105
+ - **Tags**:
106
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
107
+ - **Memory Limit**: 268435456 bytes
108
+
109
+ ## Task
110
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0234/instruction.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1439_C. Greedy Shopping
2
+
3
+ ## Problem Description
4
+ You are given an array a_1, a_2, …, a_n of integers. This array is non-increasing.
5
+
6
+ Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.
7
+
8
+ You should process q queries of two types:
9
+
10
+ * 1 x y: for each shop 1 ≤ i ≤ x set a_{i} = max(a_{i}, y).
11
+ * 2 x y: let's consider a hungry man with y money. He visits the shops from x-th shop to n-th and if he can buy a meal in the current shop he buys one item of it. Find how many meals he will purchase. The man can buy a meal in the shop i if he has at least a_i money, and after it his money decreases by a_i.
12
+
13
+ Input
14
+
15
+ The first line contains two integers n, q (1 ≤ n, q ≤ 2 ⋅ 10^5).
16
+
17
+ The second line contains n integers a_{1},a_{2}, …, a_{n} (1 ≤ a_{i} ≤ 10^9) — the costs of the meals. It is guaranteed, that a_1 ≥ a_2 ≥ … ≥ a_n.
18
+
19
+ Each of the next q lines contains three integers t, x, y (1 ≤ t ≤ 2, 1≤ x ≤ n, 1 ≤ y ≤ 10^9), each describing the next query.
20
+
21
+ It is guaranteed that there exists at least one query of type 2.
22
+
23
+ Output
24
+
25
+ For each query of type 2 output the answer on the new line.
26
+
27
+ Example
28
+
29
+ Input
30
+
31
+
32
+ 10 6
33
+ 10 10 10 6 6 5 5 5 3 1
34
+ 2 3 50
35
+ 2 4 10
36
+ 1 3 10
37
+ 2 2 36
38
+ 1 4 7
39
+ 2 2 17
40
+
41
+
42
+ Output
43
+
44
+
45
+ 8
46
+ 3
47
+ 6
48
+ 2
49
+
50
+ Note
51
+
52
+ In the first query a hungry man will buy meals in all shops from 3 to 10.
53
+
54
+ In the second query a hungry man will buy meals in shops 4, 9, and 10.
55
+
56
+ After the third query the array a_1, a_2, …, a_n of costs won't change and will be \{10, 10, 10, 6, 6, 5, 5, 5, 3, 1\}.
57
+
58
+ In the fourth query a hungry man will buy meals in shops 2, 3, 4, 5, 9, and 10.
59
+
60
+ After the fifth query the array a of costs will be \{10, 10, 10, 7, 6, 5, 5, 5, 3, 1\}.
61
+
62
+ In the sixth query a hungry man will buy meals in shops 2 and 4.
63
+
64
+ ## Contest Information
65
+ - **Contest ID**: 1439
66
+ - **Problem Index**: C
67
+ - **Points**: 1750.0
68
+ - **Rating**: 2600
69
+ - **Tags**: binary search, data structures, divide and conquer, greedy, implementation
70
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
71
+ - **Memory Limit**: 256000000 bytes
72
+
73
+ ## Task
74
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0258/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 614_C. Peter and Snow Blower
2
+
3
+ ## Problem Description
4
+ Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.
5
+
6
+ Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.
7
+
8
+ Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him.
9
+
10
+ Input
11
+
12
+ The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P.
13
+
14
+ Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.
15
+
16
+ All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value.
17
+
18
+ Output
19
+
20
+ Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
21
+
22
+ Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 3 0 0
29
+ 0 1
30
+ -1 2
31
+ 1 2
32
+
33
+
34
+ Output
35
+
36
+ 12.566370614359172464
37
+
38
+
39
+ Input
40
+
41
+ 4 1 -1
42
+ 0 0
43
+ 1 2
44
+ 2 0
45
+ 1 1
46
+
47
+
48
+ Output
49
+
50
+ 21.991148575128551812
51
+
52
+ Note
53
+
54
+ In the first sample snow will be removed from that area:
55
+
56
+ <image>
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 614
60
+ - **Problem Index**: C
61
+ - **Points**: 750.0
62
+ - **Rating**: 1900
63
+ - **Tags**: binary search, geometry, ternary search
64
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
65
+ - **Memory Limit**: 256000000 bytes
66
+
67
+ ## Task
68
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0260/instruction.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 662_C. Binary Table
2
+
3
+ ## Problem Description
4
+ You are given a table consisting of n rows and m columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa.
5
+
6
+ What is the minimum number of cells with value 1 you can get after applying some number of operations?
7
+
8
+ Input
9
+
10
+ The first line of the input contains two integers n and m (1 ≤ n ≤ 20, 1 ≤ m ≤ 100 000) — the number of rows and the number of columns, respectively.
11
+
12
+ Then n lines follows with the descriptions of the rows. Each line has length m and contains only digits '0' and '1'.
13
+
14
+ Output
15
+
16
+ Output a single integer — the minimum possible number of ones you can get after applying some sequence of operations.
17
+
18
+ Example
19
+
20
+ Input
21
+
22
+ 3 4
23
+ 0110
24
+ 1010
25
+ 0111
26
+
27
+
28
+ Output
29
+
30
+ 2
31
+
32
+ ## Contest Information
33
+ - **Contest ID**: 662
34
+ - **Problem Index**: C
35
+ - **Points**: 2250.0
36
+ - **Rating**: 2600
37
+ - **Tags**: bitmasks, brute force, divide and conquer, dp, fft, math
38
+ - **Time Limit**: {'seconds': 6, 'nanos': 0} seconds
39
+ - **Memory Limit**: 256000000 bytes
40
+
41
+ ## Task
42
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0267/instruction.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 820_A. Mister B and Book Reading
2
+
3
+ ## Problem Description
4
+ Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
5
+
6
+ At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.
7
+
8
+ Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.
9
+
10
+ Help Mister B to calculate how many days he needed to finish the book.
11
+
12
+ Input
13
+
14
+ First and only line contains five space-separated integers: c, v0, v1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v0 ≤ v1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.
15
+
16
+ Output
17
+
18
+ Print one integer — the number of days Mister B needed to finish the book.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 5 5 10 5 4
25
+
26
+
27
+ Output
28
+
29
+ 1
30
+
31
+
32
+ Input
33
+
34
+ 12 4 12 4 1
35
+
36
+
37
+ Output
38
+
39
+ 3
40
+
41
+
42
+ Input
43
+
44
+ 15 1 100 0 0
45
+
46
+
47
+ Output
48
+
49
+ 15
50
+
51
+ Note
52
+
53
+ In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
54
+
55
+ In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
56
+
57
+ In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
58
+
59
+ ## Contest Information
60
+ - **Contest ID**: 820
61
+ - **Problem Index**: A
62
+ - **Points**: 500.0
63
+ - **Rating**: 900
64
+ - **Tags**: implementation
65
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
66
+ - **Memory Limit**: 256000000 bytes
67
+
68
+ ## Task
69
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0293/instruction.md ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03771 AtCoder Grand Contest 012 - Camel and Oases
2
+
3
+ ## Problem Description
4
+ There are N oases on a number line. The coordinate of the i-th oases from the left is x_i.
5
+
6
+ Camel hopes to visit all these oases. Initially, the volume of the hump on his back is V. When the volume of the hump is v, water of volume at most v can be stored. Water is only supplied at oases. He can get as much water as he can store at a oasis, and the same oasis can be used any number of times.
7
+
8
+ Camel can travel on the line by either walking or jumping:
9
+
10
+ * Walking over a distance of d costs water of volume d from the hump. A walk that leads to a negative amount of stored water cannot be done.
11
+ * Let v be the amount of water stored at the moment. When v>0, Camel can jump to any point on the line of his choice. After this move, the volume of the hump becomes v/2 (rounded down to the nearest integer), and the amount of stored water becomes 0.
12
+
13
+
14
+
15
+ For each of the oases, determine whether it is possible to start from that oasis and visit all the oases.
16
+
17
+ Constraints
18
+
19
+ * 2 ≤ N,V ≤ 2 × 10^5
20
+ * -10^9 ≤ x_1 < x_2 < ... < x_N ≤ 10^9
21
+ * V and x_i are all integers.
22
+
23
+ Input
24
+
25
+ Input is given from Standard Input in the following format:
26
+
27
+
28
+ N V
29
+ x_1 x_2 ... x_{N}
30
+
31
+
32
+ Output
33
+
34
+ Print N lines. The i-th line should contain `Possible` if it is possible to start from the i-th oasis and visit all the oases, and `Impossible` otherwise.
35
+
36
+ Examples
37
+
38
+ Input
39
+
40
+ 3 2
41
+ 1 3 6
42
+
43
+
44
+ Output
45
+
46
+ Possible
47
+ Possible
48
+ Possible
49
+
50
+
51
+ Input
52
+
53
+ 7 2
54
+ -10 -4 -2 0 2 4 10
55
+
56
+
57
+ Output
58
+
59
+ Impossible
60
+ Possible
61
+ Possible
62
+ Possible
63
+ Possible
64
+ Possible
65
+ Impossible
66
+
67
+
68
+ Input
69
+
70
+ 16 19
71
+ -49 -48 -33 -30 -21 -14 0 15 19 23 44 52 80 81 82 84
72
+
73
+
74
+ Output
75
+
76
+ Possible
77
+ Possible
78
+ Possible
79
+ Possible
80
+ Possible
81
+ Possible
82
+ Possible
83
+ Possible
84
+ Possible
85
+ Possible
86
+ Possible
87
+ Possible
88
+ Impossible
89
+ Impossible
90
+ Impossible
91
+ Impossible
92
+
93
+ ## Contest Information
94
+ - **Contest ID**: 0
95
+ - **Problem Index**:
96
+ - **Points**: 0.0
97
+ - **Rating**: 0
98
+ - **Tags**:
99
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
100
+ - **Memory Limit**: 268435456 bytes
101
+
102
+ ## Task
103
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0315/instruction.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # laddu
2
+
3
+ ## Problem Description
4
+ You might have heard about our new goodie distribution program aka the "Laddu Accrual System". This problem is designed to give you a glimpse of its rules. You can read the page once before attempting the problem if you wish, nonetheless we will be providing all the information needed here itself.
5
+
6
+
7
+ Laddu Accrual System is our new goodie distribution program. In this program, we will be distributing Laddus in place of goodies for your winnings and various other activities (described below), that you perform on our system. Once you collect enough number of Laddus, you can then redeem them to get yourself anything from a wide range of CodeChef goodies.
8
+
9
+
10
+ Let us know about various activities and amount of laddus you get corresponding to them.
11
+
12
+ Contest Win (CodeChef’s Long, Cook-Off, LTIME, or any contest hosted with us) : 300 + Bonus (Bonus = 20 - contest rank). Note that if your rank is > 20, then you won't get any bonus.
13
+ Top Contributor on Discuss : 300
14
+ Bug Finder : 50 - 1000 (depending on the bug severity). It may also fetch you a CodeChef internship!
15
+ Contest Hosting : 50
16
+
17
+
18
+ You can do a checkout for redeeming laddus once a month. The minimum laddus redeemable at Check Out are 200 for Indians and 400 for the rest of the world.
19
+
20
+
21
+ You are given history of various activities of a user. The user has not redeemed any of the its laddus accrued.. Now the user just wants to redeem as less amount of laddus he/she can, so that the laddus can last for as long as possible. Find out for how many maximum number of months he can redeem the laddus.
22
+
23
+
24
+ Input
25
+
26
+ The first line of input contains a single integer T denoting number of test cases
27
+ For each test case:
28
+
29
+ First line contains an integer followed by a string denoting activities, origin respectively, where activities denotes number of activities of the user, origin denotes whether the user is Indian or the rest of the world. origin can be "INDIAN" or "NON_INDIAN".
30
+ For each of the next activities lines, each line contains an activity.
31
+ An activity can be of four types as defined above.
32
+
33
+ Contest Win : Input will be of form of CONTEST_WON rank, where rank denotes the rank of the user.
34
+ Top Contributor : Input will be of form of TOP_CONTRIBUTOR.
35
+ Bug Finder : Input will be of form of BUG_FOUND severity, where severity denotes the severity of the bug.
36
+ Contest Hosting : Input will be of form of CONTEST_HOSTED.
37
+
38
+
39
+
40
+
41
+
42
+
43
+ Output
44
+
45
+ For each test case, find out the maximum number of months for which the user can redeem the laddus accrued.
46
+
47
+
48
+ Constraints
49
+
50
+ 1 ≤ T, activities ≤ 100
51
+ 1 ≤ rank ≤ 5000
52
+ 50 ≤ severity ≤ 1000
53
+
54
+
55
+ Example
56
+ Input:
57
+ 2
58
+ 4 INDIAN
59
+ CONTEST_WON 1
60
+ TOP_CONTRIBUTOR
61
+ BUG_FOUND 100
62
+ CONTEST_HOSTED
63
+ 4 NON_INDIAN
64
+ CONTEST_WON 1
65
+ TOP_CONTRIBUTOR
66
+ BUG_FOUND 100
67
+ CONTEST_HOSTED
68
+
69
+ Output:
70
+ 3
71
+ 1
72
+
73
+ Explanation
74
+ In the first example,
75
+
76
+ For winning contest with rank 1, user gets 300 + 20 - 1 = 319 laddus.
77
+ For top contributor, user gets 300 laddus.
78
+ For finding a bug with severity of 100, user gets 100 laddus.
79
+ For hosting a contest, user gets 50 laddus.
80
+
81
+
82
+ So, overall user gets 319 + 300 + 100 + 50 = 769 laddus.
83
+ Now, the user is an Indian user, he can redeem only 200 laddus per month. So, for first three months, he will redeem 200 * 3 = 600 laddus. The remaining 169 laddus, he can not redeem as he requires at least 200 laddues in a month to redeem.
84
+ So, answer is 3.
85
+
86
+ In the second example, user is a non-Indian user, he can redeem 400 laddues per month. So, in the first month, he will redeem 400 laddus. The remaining 369 laddus, he can not redeem as he requires at least 400 laddues in a month to redeem.
87
+ So, answer is 1.
88
+
89
+ ## Contest Information
90
+ - **Contest ID**: 0
91
+ - **Problem Index**:
92
+ - **Points**: 0.0
93
+ - **Rating**: 0
94
+ - **Tags**: None
95
+ - **Time Limit**: None seconds
96
+ - **Memory Limit**: 0 bytes
97
+
98
+ ## Task
99
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0407/instruction.md ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01179 Cousin's Aunt
2
+
3
+ ## Problem Description
4
+ Sarah is a girl who likes reading books.
5
+
6
+ One day, she wondered about the relationship of a family in a mystery novel. The story said,
7
+
8
+ * B is A’s father’s brother’s son, and
9
+ * C is B’s aunt.
10
+
11
+
12
+
13
+ Then she asked herself, “So how many degrees of kinship are there between A and C?”
14
+
15
+ There are two possible relationships between B and C, that is, C is either B’s father’s sister or B’s mother’s sister in the story. If C is B’s father’s sister, C is in the third degree of kinship to A (A’s father’s sister). On the other hand, if C is B’s mother’s sister, C is in the fifth degree of kinship to A (A’s father’s brother’s wife’s sister).
16
+
17
+ You are a friend of Sarah’s and good at programming. You can help her by writing a general program to calculate the maximum and minimum degrees of kinship between A and C under given relationship.
18
+
19
+ The relationship of A and C is represented by a sequence of the following basic relations: father, mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, and niece. Here are some descriptions about these relations:
20
+
21
+ * X’s brother is equivalent to X’s father’s or mother’s son not identical to X.
22
+ * X’s grandfather is equivalent to X’s father’s or mother’s father.
23
+ * X’s grandson is equivalent to X’s son’s or daughter’s son.
24
+ * X’s uncle is equivalent to X’s father’s or mother’s brother.
25
+ * X’s nephew is equivalent to X’s brother’s or sister’s son.
26
+ * Similar rules apply to sister, grandmother, granddaughter, aunt and niece.
27
+
28
+
29
+
30
+ In this problem, you can assume there are none of the following relations in the family: adoptions, marriages between relatives (i.e. the family tree has no cycles), divorces, remarriages, bigamous marriages and same-sex marriages.
31
+
32
+ The degree of kinship is defined as follows:
33
+
34
+ * The distance from X to X’s father, X’s mother, X’s son or X’s daughter is one.
35
+ * The distance from X to X’s husband or X’s wife is zero.
36
+ * The degree of kinship between X and Y is equal to the shortest distance from X to Y deduced from the above rules.
37
+
38
+
39
+
40
+ Input
41
+
42
+ The input contains multiple datasets. The first line consists of a positive integer that indicates the number of datasets.
43
+
44
+ Each dataset is given by one line in the following format:
45
+
46
+
47
+ C is A(’s relation)*
48
+
49
+
50
+ Here, relation is one of the following:
51
+
52
+
53
+ father, mother, son, daughter, husband, wife, brother,
54
+ sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, niece.
55
+
56
+
57
+ An asterisk denotes zero or more occurance of portion surrounded by the parentheses. The number of relations in each dataset is at most ten.
58
+
59
+ Output
60
+
61
+ For each dataset, print a line containing the maximum and minimum degrees of kinship separated by exact one space. No extra characters are allowed of the output.
62
+
63
+ Example
64
+
65
+ Input
66
+
67
+ 7
68
+ C is A’s father’s brother’s son’s aunt
69
+ C is A’s mother’s brother’s son’s aunt
70
+ C is A’s son’s mother’s mother’s son
71
+ C is A’s aunt’s niece’s aunt’s niece
72
+ C is A’s father’s son’s brother
73
+ C is A’s son’s son’s mother
74
+ C is A
75
+
76
+
77
+ Output
78
+
79
+ 5 3
80
+ 5 1
81
+ 2 2
82
+ 6 0
83
+ 2 0
84
+ 1 1
85
+ 0 0
86
+
87
+ ## Contest Information
88
+ - **Contest ID**: 0
89
+ - **Problem Index**:
90
+ - **Points**: 0.0
91
+ - **Rating**: 0
92
+ - **Tags**:
93
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
94
+ - **Memory Limit**: 134217728 bytes
95
+
96
+ ## Task
97
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0409/instruction.md ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01484 Icy Composer
2
+
3
+ ## Problem Description
4
+ Time Limit: 8 sec / Memory Limit: 64 MB
5
+
6
+
7
+
8
+
9
+
10
+ Example
11
+
12
+ Input
13
+
14
+ 5 3 2
15
+ aaaaa
16
+ aaa
17
+ aab
18
+
19
+
20
+ Output
21
+
22
+ 1 6
23
+
24
+ ## Contest Information
25
+ - **Contest ID**: 0
26
+ - **Problem Index**:
27
+ - **Points**: 0.0
28
+ - **Rating**: 0
29
+ - **Tags**:
30
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
31
+ - **Memory Limit**: 134217728 bytes
32
+
33
+ ## Task
34
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0431/instruction.md ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1199_E. Matching vs Independent Set
2
+
3
+ ## Problem Description
4
+ You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices.
5
+
6
+ A set of edges is called a matching if no two edges share an endpoint.
7
+
8
+ A set of vertices is called an independent set if no two vertices are connected with an edge.
9
+
10
+ Input
11
+
12
+ The first line contains a single integer T ≥ 1 — the number of graphs you need to process. The description of T graphs follows.
13
+
14
+ The first line of description of a single graph contains two integers n and m, where 3 ⋅ n is the number of vertices, and m is the number of edges in the graph (1 ≤ n ≤ 10^{5}, 0 ≤ m ≤ 5 ⋅ 10^{5}).
15
+
16
+ Each of the next m lines contains two integers v_i and u_i (1 ≤ v_i, u_i ≤ 3 ⋅ n), meaning that there is an edge between vertices v_i and u_i.
17
+
18
+ It is guaranteed that there are no self-loops and no multiple edges in the graph.
19
+
20
+ It is guaranteed that the sum of all n over all graphs in a single test does not exceed 10^{5}, and the sum of all m over all graphs in a single test does not exceed 5 ⋅ 10^{5}.
21
+
22
+ Output
23
+
24
+ Print your answer for each of the T graphs. Output your answer for a single graph in the following format.
25
+
26
+ If you found a matching of size n, on the first line print "Matching" (without quotes), and on the second line print n integers — the indices of the edges in the matching. The edges are numbered from 1 to m in the input order.
27
+
28
+ If you found an independent set of size n, on the first line print "IndSet" (without quotes), and on the second line print n integers — the indices of the vertices in the independent set.
29
+
30
+ If there is no matching and no independent set of the specified size, print "Impossible" (without quotes).
31
+
32
+ You can print edges and vertices in any order.
33
+
34
+ If there are several solutions, print any. In particular, if there are both a matching of size n, and an independent set of size n, then you should print exactly one of such matchings or exactly one of such independent sets.
35
+
36
+ Example
37
+
38
+ Input
39
+
40
+
41
+ 4
42
+ 1 2
43
+ 1 3
44
+ 1 2
45
+ 1 2
46
+ 1 3
47
+ 1 2
48
+ 2 5
49
+ 1 2
50
+ 3 1
51
+ 1 4
52
+ 5 1
53
+ 1 6
54
+ 2 15
55
+ 1 2
56
+ 1 3
57
+ 1 4
58
+ 1 5
59
+ 1 6
60
+ 2 3
61
+ 2 4
62
+ 2 5
63
+ 2 6
64
+ 3 4
65
+ 3 5
66
+ 3 6
67
+ 4 5
68
+ 4 6
69
+ 5 6
70
+
71
+
72
+ Output
73
+
74
+
75
+ Matching
76
+ 2
77
+ IndSet
78
+ 1
79
+ IndSet
80
+ 2 4
81
+ Matching
82
+ 1 15
83
+
84
+ Note
85
+
86
+ The first two graphs are same, and there are both a matching of size 1 and an independent set of size 1. Any of these matchings and independent sets is a correct answer.
87
+
88
+ The third graph does not have a matching of size 2, however, there is an independent set of size 2. Moreover, there is an independent set of size 5: 2 3 4 5 6. However such answer is not correct, because you are asked to find an independent set (or matching) of size exactly n.
89
+
90
+ The fourth graph does not have an independent set of size 2, but there is a matching of size 2.
91
+
92
+ ## Contest Information
93
+ - **Contest ID**: 1199
94
+ - **Problem Index**: E
95
+ - **Points**: 1250.0
96
+ - **Rating**: 2000
97
+ - **Tags**: constructive algorithms, graphs, greedy, sortings
98
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
99
+ - **Memory Limit**: 256000000 bytes
100
+
101
+ ## Task
102
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0436/instruction.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1301_B. Motarack's Birthday
2
+
3
+ ## Problem Description
4
+ Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
5
+
6
+ Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them. He doesn't have much time so he wants to choose an integer k (0 ≤ k ≤ 10^{9}) and replaces all missing elements in the array a with k.
7
+
8
+ Let m be the maximum absolute difference between all adjacent elements (i.e. the maximum value of |a_i - a_{i+1}| for all 1 ≤ i ≤ n - 1) in the array a after Dark replaces all missing elements with k.
9
+
10
+ Dark should choose an integer k so that m is minimized. Can you help him?
11
+
12
+ Input
13
+
14
+ The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. The description of the test cases follows.
15
+
16
+ The first line of each test case contains one integer n (2 ≤ n ≤ 10^{5}) — the size of the array a.
17
+
18
+ The second line of each test case contains n integers a_1, a_2, …, a_n (-1 ≤ a_i ≤ 10 ^ {9}). If a_i = -1, then the i-th integer is missing. It is guaranteed that at least one integer is missing in every test case.
19
+
20
+ It is guaranteed, that the sum of n for all test cases does not exceed 4 ⋅ 10 ^ {5}.
21
+
22
+ Output
23
+
24
+ Print the answers for each test case in the following format:
25
+
26
+ You should print two integers, the minimum possible value of m and an integer k (0 ≤ k ≤ 10^{9}) that makes the maximum absolute difference between adjacent elements in the array a equal to m.
27
+
28
+ Make sure that after replacing all the missing elements with k, the maximum absolute difference between adjacent elements becomes m.
29
+
30
+ If there is more than one possible k, you can print any of them.
31
+
32
+ Example
33
+
34
+ Input
35
+
36
+
37
+ 7
38
+ 5
39
+ -1 10 -1 12 -1
40
+ 5
41
+ -1 40 35 -1 35
42
+ 6
43
+ -1 -1 9 -1 3 -1
44
+ 2
45
+ -1 -1
46
+ 2
47
+ 0 -1
48
+ 4
49
+ 1 -1 3 -1
50
+ 7
51
+ 1 -1 7 5 2 -1 5
52
+
53
+
54
+ Output
55
+
56
+
57
+ 1 11
58
+ 5 35
59
+ 3 6
60
+ 0 42
61
+ 0 0
62
+ 1 2
63
+ 3 4
64
+
65
+ Note
66
+
67
+ In the first test case after replacing all missing elements with 11 the array becomes [11, 10, 11, 12, 11]. The absolute difference between any adjacent elements is 1. It is impossible to choose a value of k, such that the absolute difference between any adjacent element will be ≤ 0. So, the answer is 1.
68
+
69
+ In the third test case after replacing all missing elements with 6 the array becomes [6, 6, 9, 6, 3, 6].
70
+
71
+ * |a_1 - a_2| = |6 - 6| = 0;
72
+ * |a_2 - a_3| = |6 - 9| = 3;
73
+ * |a_3 - a_4| = |9 - 6| = 3;
74
+ * |a_4 - a_5| = |6 - 3| = 3;
75
+ * |a_5 - a_6| = |3 - 6| = 3.
76
+
77
+
78
+
79
+ So, the maximum difference between any adjacent elements is 3.
80
+
81
+ ## Contest Information
82
+ - **Contest ID**: 1301
83
+ - **Problem Index**: B
84
+ - **Points**: 1000.0
85
+ - **Rating**: 1500
86
+ - **Tags**: binary search, greedy, ternary search
87
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
88
+ - **Memory Limit**: 256000000 bytes
89
+
90
+ ## Task
91
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0438/instruction.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1344_A. Hilbert's Hotel
2
+
3
+ ## Problem Description
4
+ Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
5
+
6
+ For any integer k and positive integer n, let kmod n denote the remainder when k is divided by n. More formally, r=kmod n is the smallest non-negative integer such that k-r is divisible by n. It always holds that 0≤ kmod n≤ n-1. For example, 100mod 12=4 and (-1337)mod 3=1.
7
+
8
+ Then the shuffling works as follows. There is an array of n integers a_0,a_1,…,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}.
9
+
10
+ After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
11
+
12
+ Input
13
+
14
+ Each test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases. Next 2t lines contain descriptions of test cases.
15
+
16
+ The first line of each test case contains a single integer n (1≤ n≤ 2⋅ 10^5) — the length of the array.
17
+
18
+ The second line of each test case contains n integers a_0,a_1,…,a_{n-1} (-10^9≤ a_i≤ 10^9).
19
+
20
+ It is guaranteed that the sum of n over all test cases does not exceed 2⋅ 10^5.
21
+
22
+ Output
23
+
24
+ For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
25
+
26
+ Example
27
+
28
+ Input
29
+
30
+
31
+ 6
32
+ 1
33
+ 14
34
+ 2
35
+ 1 -1
36
+ 4
37
+ 5 5 5 1
38
+ 3
39
+ 3 2 1
40
+ 2
41
+ 0 1
42
+ 5
43
+ -239 -2 -100 -3 -11
44
+
45
+
46
+ Output
47
+
48
+
49
+ YES
50
+ YES
51
+ YES
52
+ NO
53
+ NO
54
+ YES
55
+
56
+ Note
57
+
58
+ In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.
59
+
60
+ In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.
61
+
62
+ In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.
63
+
64
+ In the fourth test case, guests 0 and 1 are both assigned to room 3.
65
+
66
+ In the fifth test case, guests 1 and 2 are both assigned to room 2.
67
+
68
+ ## Contest Information
69
+ - **Contest ID**: 1344
70
+ - **Problem Index**: A
71
+ - **Points**: 500.0
72
+ - **Rating**: 1600
73
+ - **Tags**: math, number theory, sortings
74
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
75
+ - **Memory Limit**: 256000000 bytes
76
+
77
+ ## Task
78
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0453/instruction.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 295_D. Greg and Caves
2
+
3
+ ## Problem Description
4
+ Greg has a pad. The pad's screen is an n × m rectangle, each cell can be either black or white. We'll consider the pad rows to be numbered with integers from 1 to n from top to bottom. Similarly, the pad's columns are numbered with integers from 1 to m from left to right.
5
+
6
+ Greg thinks that the pad's screen displays a cave if the following conditions hold:
7
+
8
+ * There is a segment [l, r] (1 ≤ l ≤ r ≤ n), such that each of the rows l, l + 1, ..., r has exactly two black cells and all other rows have only white cells.
9
+ * There is a row number t (l ≤ t ≤ r), such that for all pairs of rows with numbers i and j (l ≤ i ≤ j ≤ t) the set of columns between the black cells in row i (with the columns where is these black cells) is the subset of the set of columns between the black cells in row j (with the columns where is these black cells). Similarly, for all pairs of rows with numbers i and j (t ≤ i ≤ j ≤ r) the set of columns between the black cells in row j (with the columns where is these black cells) is the subset of the set of columns between the black cells in row i (with the columns where is these black cells).
10
+
11
+
12
+
13
+ Greg wondered, how many ways there are to paint a cave on his pad. Two ways can be considered distinct if there is a cell that has distinct colors on the two pictures.
14
+
15
+ Help Greg.
16
+
17
+ Input
18
+
19
+ The first line contains two integers n, m — the pad's screen size (1 ≤ n, m ≤ 2000).
20
+
21
+ Output
22
+
23
+ In the single line print the remainder after dividing the answer to the problem by 1000000007 (109 + 7).
24
+
25
+ Examples
26
+
27
+ Input
28
+
29
+ 1 1
30
+
31
+
32
+ Output
33
+
34
+ 0
35
+
36
+
37
+ Input
38
+
39
+ 4 4
40
+
41
+
42
+ Output
43
+
44
+ 485
45
+
46
+
47
+ Input
48
+
49
+ 3 5
50
+
51
+
52
+ Output
53
+
54
+ 451
55
+
56
+ ## Contest Information
57
+ - **Contest ID**: 295
58
+ - **Problem Index**: D
59
+ - **Points**: 2000.0
60
+ - **Rating**: 2400
61
+ - **Tags**: combinatorics, dp
62
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
63
+ - **Memory Limit**: 256000000 bytes
64
+
65
+ ## Task
66
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0462/instruction.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 507_B. Amr and Pins
2
+
3
+ ## Problem Description
4
+ Amr loves Geometry. One day he came up with a very interesting problem.
5
+
6
+ Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
7
+
8
+ In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
9
+
10
+ Help Amr to achieve his goal in minimum number of steps.
11
+
12
+ Input
13
+
14
+ Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105, - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
15
+
16
+ Output
17
+
18
+ Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 2 0 0 0 4
25
+
26
+
27
+ Output
28
+
29
+ 1
30
+
31
+
32
+ Input
33
+
34
+ 1 1 1 4 4
35
+
36
+
37
+ Output
38
+
39
+ 3
40
+
41
+
42
+ Input
43
+
44
+ 4 5 6 5 6
45
+
46
+
47
+ Output
48
+
49
+ 0
50
+
51
+ Note
52
+
53
+ In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
54
+
55
+ <image>
56
+
57
+ ## Contest Information
58
+ - **Contest ID**: 507
59
+ - **Problem Index**: B
60
+ - **Points**: 1000.0
61
+ - **Rating**: 1400
62
+ - **Tags**: geometry, math
63
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
64
+ - **Memory Limit**: 256000000 bytes
65
+
66
+ ## Task
67
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0465/instruction.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 582_A. GCD Table
2
+
3
+ ## Problem Description
4
+ The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
5
+
6
+ <image>
7
+
8
+ Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
9
+
10
+ <image>
11
+
12
+ Given all the numbers of the GCD table G, restore array a.
13
+
14
+ Input
15
+
16
+ The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
17
+
18
+ All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
19
+
20
+ Output
21
+
22
+ In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 4
29
+ 2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
30
+
31
+
32
+ Output
33
+
34
+ 4 3 6 2
35
+
36
+ Input
37
+
38
+ 1
39
+ 42
40
+
41
+
42
+ Output
43
+
44
+ 42
45
+
46
+ Input
47
+
48
+ 2
49
+ 1 1 1 1
50
+
51
+
52
+ Output
53
+
54
+ 1 1
55
+
56
+ ## Contest Information
57
+ - **Contest ID**: 582
58
+ - **Problem Index**: A
59
+ - **Points**: 750.0
60
+ - **Rating**: 1700
61
+ - **Tags**: constructive algorithms, greedy, number theory
62
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
63
+ - **Memory Limit**: 256000000 bytes
64
+
65
+ ## Task
66
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0491/instruction.md ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # simple-prime-factorization
2
+
3
+ ## Problem Description
4
+ Surya loves to play with primes. One day, he asked his friend don to print any number in the form of multiple of prime factors. Help don in solving the problem.
5
+
6
+ Input
7
+ The first line will contain an integer t (1 ≤ t ≤ 10^6) denoting number of test case.
8
+ For each test case, you will be given an integer n (2 ≤ n ≤ 10^6).
9
+
10
+ Output
11
+ Print a string showing prime factors which should look like :
12
+ 2^e1 * p2^e2 * .........* pk^ek
13
+ where p1, p2, ...., pn are the prime factors and e1, e2, ....., en is the degree of corresponding prime factor.
14
+
15
+ Note: power of 2 should always be given.
16
+ For a prime number , only 2^0 is printed.
17
+
18
+ SAMPLE INPUT
19
+ 3
20
+ 32
21
+ 100
22
+ 9085
23
+
24
+ SAMPLE OUTPUT
25
+ 2^5
26
+ 2^2*5^2
27
+ 2^0*5^1*23^1*79^1
28
+
29
+ ## Contest Information
30
+ - **Contest ID**: 0
31
+ - **Problem Index**:
32
+ - **Points**: 0.0
33
+ - **Rating**: 0
34
+ - **Tags**: None
35
+ - **Time Limit**: None seconds
36
+ - **Memory Limit**: 0 bytes
37
+
38
+ ## Task
39
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0498/instruction.md ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03225 Tenka1 Programmer Contest - Equilateral
2
+
3
+ ## Problem Description
4
+ There are some coins in the xy-plane. The positions of the coins are represented by a grid of characters with H rows and W columns. If the character at the i-th row and j-th column, s_{ij}, is `#`, there is one coin at point (i,j); if that character is `.`, there is no coin at point (i,j). There are no other coins in the xy-plane.
5
+
6
+ There is no coin at point (x,y) where 1\leq i\leq H,1\leq j\leq W does not hold. There is also no coin at point (x,y) where x or y (or both) is not an integer. Additionally, two or more coins never exist at the same point.
7
+
8
+ Find the number of triples of different coins that satisfy the following condition:
9
+
10
+ * Choosing any two of the three coins would result in the same Manhattan distance between the points where they exist.
11
+
12
+
13
+
14
+ Here, the Manhattan distance between points (x,y) and (x',y') is |x-x'|+|y-y'|. Two triples are considered the same if the only difference between them is the order of the coins.
15
+
16
+ Constraints
17
+
18
+ * 1 \leq H,W \leq 300
19
+ * s_{ij} is `#` or `.`.
20
+
21
+ Input
22
+
23
+ Input is given from Standard Input in the following format:
24
+
25
+
26
+ H W
27
+ s_{11}...s_{1W}
28
+ :
29
+ s_{H1}...s_{HW}
30
+
31
+
32
+ Output
33
+
34
+ Print the number of triples that satisfy the condition.
35
+
36
+ Examples
37
+
38
+ Input
39
+
40
+ 5 4
41
+ #.##
42
+ .##.
43
+ #...
44
+ ..##
45
+ ...#
46
+
47
+
48
+ Output
49
+
50
+ 3
51
+
52
+
53
+ Input
54
+
55
+ 5 4
56
+ .##
57
+ .##.
58
+ ...
59
+ ..##
60
+ ...#
61
+
62
+
63
+ Output
64
+
65
+ 3
66
+
67
+
68
+ Input
69
+
70
+ 13 27
71
+ ......#.........#.......#..
72
+ ...#.....###..
73
+ ..............#####...##...
74
+ ...#######......#...#######
75
+ ...#.....#.....###...#...#.
76
+ ...#######....#.#.#.#.###.#
77
+ ..............#.#.#...#.#..
78
+ .#.#.#...###..
79
+ ...........#...#...#######
80
+ ..#######..#...#...#.....#
81
+ ..#.....#..#...#...#.###.#
82
+ ..#######..#...#...#.#.#.#
83
+ ..........##...#...#.#####
84
+
85
+
86
+ Output
87
+
88
+ 870
89
+
90
+ ## Contest Information
91
+ - **Contest ID**: 0
92
+ - **Problem Index**:
93
+ - **Points**: 0.0
94
+ - **Rating**: 0
95
+ - **Tags**:
96
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
97
+ - **Memory Limit**: 1073741824 bytes
98
+
99
+ ## Task
100
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0543/instruction.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1353_C. Board Moves
2
+
3
+ ## Problem Description
4
+ You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure.
5
+
6
+ In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move the figure to cells:
7
+
8
+ * (i - 1, j - 1);
9
+ * (i - 1, j);
10
+ * (i - 1, j + 1);
11
+ * (i, j - 1);
12
+ * (i, j + 1);
13
+ * (i + 1, j - 1);
14
+ * (i + 1, j);
15
+ * (i + 1, j + 1);
16
+
17
+
18
+
19
+ Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.
20
+
21
+ Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. n^2-1 cells should contain 0 figures and one cell should contain n^2 figures).
22
+
23
+ You have to answer t independent test cases.
24
+
25
+ Input
26
+
27
+ The first line of the input contains one integer t (1 ≤ t ≤ 200) — the number of test cases. Then t test cases follow.
28
+
29
+ The only line of the test case contains one integer n (1 ≤ n < 5 ⋅ 10^5) — the size of the board. It is guaranteed that n is odd (not divisible by 2).
30
+
31
+ It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5 (∑ n ≤ 5 ⋅ 10^5).
32
+
33
+ Output
34
+
35
+ For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.
36
+
37
+ Example
38
+
39
+ Input
40
+
41
+
42
+ 3
43
+ 1
44
+ 5
45
+ 499993
46
+
47
+
48
+ Output
49
+
50
+
51
+ 0
52
+ 40
53
+ 41664916690999888
54
+
55
+ ## Contest Information
56
+ - **Contest ID**: 1353
57
+ - **Problem Index**: C
58
+ - **Points**: 0.0
59
+ - **Rating**: 1000
60
+ - **Tags**: math
61
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
62
+ - **Memory Limit**: 256000000 bytes
63
+
64
+ ## Task
65
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0544/instruction.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1373_B. 01 Game
2
+
3
+ ## Problem Description
4
+ Alica and Bob are playing a game.
5
+
6
+ Initially they have a binary string s consisting of only characters 0 and 1.
7
+
8
+ Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent characters of string s and delete them. For example, if s = 1011001 then the following moves are possible:
9
+
10
+ 1. delete s_1 and s_2: 1011001 → 11001;
11
+ 2. delete s_2 and s_3: 1011001 → 11001;
12
+ 3. delete s_4 and s_5: 1011001 → 10101;
13
+ 4. delete s_6 and s_7: 1011001 → 10110.
14
+
15
+
16
+
17
+ If a player can't make any move, they lose. Both players play optimally. You have to determine if Alice can win.
18
+
19
+ Input
20
+
21
+ First line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
22
+
23
+ Only line of each test case contains one string s (1 ≤ |s| ≤ 100), consisting of only characters 0 and 1.
24
+
25
+ Output
26
+
27
+ For each test case print answer in the single line.
28
+
29
+ If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register.
30
+
31
+ Example
32
+
33
+ Input
34
+
35
+
36
+ 3
37
+ 01
38
+ 1111
39
+ 0011
40
+
41
+
42
+ Output
43
+
44
+
45
+ DA
46
+ NET
47
+ NET
48
+
49
+ Note
50
+
51
+ In the first test case after Alice's move string s become empty and Bob can not make any move.
52
+
53
+ In the second test case Alice can not make any move initially.
54
+
55
+ In the third test case after Alice's move string s turn into 01. Then, after Bob's move string s become empty and Alice can not make any move.
56
+
57
+ ## Contest Information
58
+ - **Contest ID**: 1373
59
+ - **Problem Index**: B
60
+ - **Points**: 0.0
61
+ - **Rating**: 900
62
+ - **Tags**: games
63
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
64
+ - **Memory Limit**: 256000000 bytes
65
+
66
+ ## Task
67
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0588/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # anagrams-1
2
+
3
+ ## Problem Description
4
+ Two strings are said to be anagrams of each other if the letters of one string may be rearranged to make the other string. For example, the words 'elvis' and 'lives' are anagrams.
5
+
6
+ In this problem you’ll be given two strings. Your job is to find if the two strings are anagrams of each other or not. If they are not anagrams then find the lexicographically smallest palindrome (in lowercase alphabets) that may be appended to the end of either one of the two strings so that they become anagrams of each other.
7
+
8
+ The lower and upper case letters are considered equivalent. The number of spaces or any other punctuation or digit is not important.
9
+
10
+ One string is called lexicographically smaller than another if, at the first position where they differ the first one has smaller alphabet. For example, the strings 'hello' and 'herd' first differ at the third alphabet; 'l' is smaller than 'r', so 'hello' is lexicographically smaller than 'herd'.
11
+
12
+ A Palindrome is a string that is the same when read forward or backward. For example, the string 'bird rib' is a palindrome, whereas 'hello' is not.
13
+
14
+ INPUT:
15
+
16
+ The first line of the input contains a number T, the number of test cases. T test cases follow. Each test case consists of two lines, one string in each line.
17
+
18
+ OUTPUT:
19
+
20
+ For each test case output a single line. Print ‘YES’ (without the quotes) if the two strings are anagrams of each other. If they are not, then print the lexicographically smallest palindromic string as discussed above. If no such string exists, then print ‘NO LUCK’ (without the quotes).
21
+
22
+ CONSTRAINTS:
23
+
24
+ 1 ≤ T ≤ 100
25
+
26
+ 1 ≤ length of the strings ≤ 100
27
+
28
+ SAMPLE INPUT
29
+ 5
30
+ Computer programmer
31
+ mature germ romp crop
32
+ Awaaay
33
+ away
34
+ internet
35
+ web
36
+ abc221
37
+ abcdede
38
+ the terminator
39
+ I?m rotten hater
40
+
41
+ SAMPLE OUTPUT
42
+ YES
43
+ aa
44
+ NO LUCK
45
+ deed
46
+ YES
47
+
48
+ Explanation
49
+
50
+ 'Computer programmer' and 'mature germ romp crop' are anagrams so the output is YES.
51
+
52
+ 'Awaaay' and 'away' are not anagrams, but 'aa' may be appended to the end of 'away' so that 'Awaaay' and 'awayaa' become anagrams. Therefore the output is 'aa' ( without the quotes).
53
+
54
+ 'internet' and 'web' are not anagrams and no palindromic string can be added to the end of any one of them to make them anagrams, therefore the answer is 'NO LUCK'.
55
+
56
+ 'abc' and 'abcdede' are not anagrams. But 'deed' or 'edde' may be appended to the end of 'abc' to make them anagrams. As, 'deed' is lexicographically smaller than 'edde', the output is 'deed'
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 0
60
+ - **Problem Index**:
61
+ - **Points**: 0.0
62
+ - **Rating**: 0
63
+ - **Tags**: None
64
+ - **Time Limit**: None seconds
65
+ - **Memory Limit**: 0 bytes
66
+
67
+ ## Task
68
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0603/instruction.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03287 AtCoder Beginner Contest 105 - Candy Distribution
2
+
3
+ ## Problem Description
4
+ There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies.
5
+
6
+ You will take out the candies from some consecutive boxes and distribute them evenly to M children.
7
+
8
+ Such being the case, find the number of the pairs (l, r) that satisfy the following:
9
+
10
+ * l and r are both integers and satisfy 1 \leq l \leq r \leq N.
11
+ * A_l + A_{l+1} + ... + A_r is a multiple of M.
12
+
13
+ Constraints
14
+
15
+ * All values in input are integers.
16
+ * 1 \leq N \leq 10^5
17
+ * 2 \leq M \leq 10^9
18
+ * 1 \leq A_i \leq 10^9
19
+
20
+ Input
21
+
22
+ Input is given from Standard Input in the following format:
23
+
24
+
25
+ N M
26
+ A_1 A_2 ... A_N
27
+
28
+
29
+ Output
30
+
31
+ Print the number of the pairs (l, r) that satisfy the conditions.
32
+
33
+ Note that the number may not fit into a 32-bit integer type.
34
+
35
+ Examples
36
+
37
+ Input
38
+
39
+ 3 2
40
+ 4 1 5
41
+
42
+
43
+ Output
44
+
45
+ 3
46
+
47
+
48
+ Input
49
+
50
+ 13 17
51
+ 29 7 5 7 9 51 7 13 8 55 42 9 81
52
+
53
+
54
+ Output
55
+
56
+ 6
57
+
58
+
59
+ Input
60
+
61
+ 10 400000000
62
+ 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
63
+
64
+
65
+ Output
66
+
67
+ 25
68
+
69
+ ## Contest Information
70
+ - **Contest ID**: 0
71
+ - **Problem Index**:
72
+ - **Points**: 0.0
73
+ - **Rating**: 0
74
+ - **Tags**:
75
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
76
+ - **Memory Limit**: 1073741824 bytes
77
+
78
+ ## Task
79
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0635/instruction.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1103_E. Radix sum
2
+
3
+ ## Problem Description
4
+ Let's define radix sum of number a consisting of digits a_1, … ,a_k and number b consisting of digits b_1, … ,b_k(we add leading zeroes to the shorter number to match longer length) as number s(a,b) consisting of digits (a_1+b_1)mod 10, … ,(a_k+b_k)mod 10. The radix sum of several integers is defined as follows: s(t_1, … ,t_n)=s(t_1,s(t_2, … ,t_n))
5
+
6
+ You are given an array x_1, … ,x_n. The task is to compute for each integer i (0 ≤ i < n) number of ways to consequently choose one of the integers from the array n times, so that the radix sum of these integers is equal to i. Calculate these values modulo 2^{58}.
7
+
8
+ Input
9
+
10
+ The first line contains integer n — the length of the array(1 ≤ n ≤ 100000).
11
+
12
+ The second line contains n integers x_1, … x_n — array elements(0 ≤ x_i < 100000).
13
+
14
+ Output
15
+
16
+ Output n integers y_0, …, y_{n-1} — y_i should be equal to corresponding number of ways modulo 2^{58}.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+
23
+ 2
24
+ 5 6
25
+
26
+
27
+ Output
28
+
29
+
30
+ 1
31
+ 2
32
+
33
+
34
+ Input
35
+
36
+
37
+ 4
38
+ 5 7 5 7
39
+
40
+
41
+ Output
42
+
43
+
44
+ 16
45
+ 0
46
+ 64
47
+ 0
48
+
49
+ Note
50
+
51
+ In the first example there exist sequences: sequence (5,5) with radix sum 0, sequence (5,6) with radix sum 1, sequence (6,5) with radix sum 1, sequence (6,6) with radix sum 2.
52
+
53
+ ## Contest Information
54
+ - **Contest ID**: 1103
55
+ - **Problem Index**: E
56
+ - **Points**: 3500.0
57
+ - **Rating**: 3400
58
+ - **Tags**: fft, math, number theory
59
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
60
+ - **Memory Limit**: 256000000 bytes
61
+
62
+ ## Task
63
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0650/instruction.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1423_H. Virus
2
+
3
+ ## Problem Description
4
+ In Bubbleland a group of special programming forces gets a top secret job to calculate the number of potentially infected people by a new unknown virus. The state has a population of n people and every day there is new information about new contacts between people. The job of special programming forces is to calculate how many contacts in the last k days a given person had.
5
+
6
+ The new virus has an incubation period of k days, and after that time people consider as non-infectious. Because the new virus is an extremely dangerous, government mark as suspicious everybody who had direct or indirect contact in the last k days, independently of the order of contacts.
7
+
8
+ This virus is very strange, and people can't get durable immunity.
9
+
10
+ You need to help special programming forces to calculate the number of suspicious people for a given person (number of people who had contact with a given person).
11
+
12
+ There are 3 given inputs on beginning n where n is population, q number of queries, k virus incubation time in days. Each query is one of three types:
13
+
14
+ 1. (x, y) person x and person y met that day (x ≠ y).
15
+ 2. (z) return the number of people in contact with z, counting himself.
16
+ 3. The end of the current day moves on to the next day.
17
+
18
+ Input
19
+
20
+ The first line of input contains three integers n (1 ≤ n≤ 10^5) the number of people in the state, q (1 ≤ q≤ 5×10^5) number of queries and k (1 ≤ k≤ 10^5) virus incubation time in days.
21
+
22
+ Each of the next q lines starts with an integer t (1 ≤ t≤ 3) the type of the query.
23
+
24
+ A pair of integers x and y (1 ≤ x, y ≤ n) follows in the query of the first type (x ≠ y).
25
+
26
+ An integer i (1 ≤ i≤ n) follows in the query of the second type.
27
+
28
+ Query of third type does not have the following number.
29
+
30
+ Output
31
+
32
+ For the queries of the second type print on a separate line the current number of people in contact with a given person.
33
+
34
+ Examples
35
+
36
+ Input
37
+
38
+
39
+ 5 12 1
40
+ 1 1 2
41
+ 1 1 3
42
+ 1 3 4
43
+ 2 4
44
+ 2 5
45
+ 3
46
+ 2 1
47
+ 1 1 2
48
+ 1 3 2
49
+ 2 1
50
+ 3
51
+ 2 1
52
+
53
+
54
+ Output
55
+
56
+
57
+ 4
58
+ 1
59
+ 1
60
+ 3
61
+ 1
62
+
63
+
64
+ Input
65
+
66
+
67
+ 5 12 2
68
+ 1 1 2
69
+ 1 1 3
70
+ 1 3 4
71
+ 2 4
72
+ 2 5
73
+ 3
74
+ 2 1
75
+ 1 1 2
76
+ 1 3 2
77
+ 2 1
78
+ 3
79
+ 2 1
80
+
81
+
82
+ Output
83
+
84
+
85
+ 4
86
+ 1
87
+ 4
88
+ 4
89
+ 3
90
+
91
+
92
+ Input
93
+
94
+
95
+ 10 25 2
96
+ 1 9 3
97
+ 2 5
98
+ 1 1 3
99
+ 1 3 1
100
+ 2 2
101
+ 1 8 3
102
+ 1 5 6
103
+ 3
104
+ 1 9 2
105
+ 1 8 3
106
+ 2 9
107
+ 1 3 1
108
+ 2 5
109
+ 1 6 4
110
+ 3
111
+ 3
112
+ 2 4
113
+ 3
114
+ 1 10 9
115
+ 1 1 7
116
+ 3
117
+ 2 2
118
+ 3
119
+ 1 5 6
120
+ 1 1 4
121
+
122
+
123
+ Output
124
+
125
+
126
+ 1
127
+ 1
128
+ 5
129
+ 2
130
+ 1
131
+ 1
132
+
133
+ Note
134
+
135
+ Pay attention if persons 1 and 2 had contact first day and next day persons 1 and 3 had contact, for k>1 number of contacts of person 3 is 3(persons:1,2,3).
136
+
137
+ ## Contest Information
138
+ - **Contest ID**: 1423
139
+ - **Problem Index**: H
140
+ - **Points**: 0.0
141
+ - **Rating**: 2500
142
+ - **Tags**: data structures, divide and conquer, dsu, graphs
143
+ - **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
144
+ - **Memory Limit**: 256000000 bytes
145
+
146
+ ## Task
147
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0657/instruction.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 191_A. Dynasty Puzzles
2
+
3
+ ## Problem Description
4
+ The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the king, whose name was Victorious Vasily Pupkin, was always called by the berlanders VVP.
5
+
6
+ In Berland over its long history many dynasties of kings replaced each other, but they were all united by common traditions. Thus, according to one Berland traditions, to maintain stability in the country, the first name of the heir should be the same as the last name his predecessor (hence, the first letter of the abbreviated name of the heir coincides with the last letter of the abbreviated name of the predecessor). Berlanders appreciate stability, so this tradition has never been broken. Also Berlanders like perfection, so another tradition requires that the first name of the first king in the dynasty coincides with the last name of the last king in this dynasty (hence, the first letter of the abbreviated name of the first king coincides with the last letter of the abbreviated name of the last king). This tradition, of course, has also been always observed.
7
+
8
+ The name of a dynasty is formed by very simple rules: we take all the short names of the kings in the order in which they ruled, and write them in one line. Thus, a dynasty of kings "ab" and "ba" is called "abba", and the dynasty, which had only the king "abca", is called "abca".
9
+
10
+ Vasya, a historian, has recently found a list of abbreviated names of all Berland kings and their relatives. Help Vasya to find the maximally long name of the dynasty that could have existed in Berland.
11
+
12
+ Note that in his list all the names are ordered by the time, that is, if name A is earlier in the list than B, then if A and B were kings, then king A ruled before king B.
13
+
14
+ Input
15
+
16
+ The first line contains integer n (1 ≤ n ≤ 5·105) — the number of names in Vasya's list. Next n lines contain n abbreviated names, one per line. An abbreviated name is a non-empty sequence of lowercase Latin letters. Its length does not exceed 10 characters.
17
+
18
+ Output
19
+
20
+ Print a single number — length of the sought dynasty's name in letters.
21
+
22
+ If Vasya's list is wrong and no dynasty can be found there, print a single number 0.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 3
29
+ abc
30
+ ca
31
+ cba
32
+
33
+
34
+ Output
35
+
36
+ 6
37
+
38
+
39
+ Input
40
+
41
+ 4
42
+ vvp
43
+ vvp
44
+ dam
45
+ vvp
46
+
47
+
48
+ Output
49
+
50
+ 0
51
+
52
+
53
+ Input
54
+
55
+ 3
56
+ ab
57
+ c
58
+ def
59
+
60
+
61
+ Output
62
+
63
+ 1
64
+
65
+ Note
66
+
67
+ In the first sample two dynasties can exist: the one called "abcca" (with the first and second kings) and the one called "abccba" (with the first and third kings).
68
+
69
+ In the second sample there aren't acceptable dynasties.
70
+
71
+ The only dynasty in the third sample consists of one king, his name is "c".
72
+
73
+ ## Contest Information
74
+ - **Contest ID**: 191
75
+ - **Problem Index**: A
76
+ - **Points**: 500.0
77
+ - **Rating**: 1500
78
+ - **Tags**: dp
79
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
80
+ - **Memory Limit**: 256000000 bytes
81
+
82
+ ## Task
83
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0668/instruction.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 451_D. Count Good Substrings
2
+
3
+ ## Problem Description
4
+ We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".
5
+
6
+ Given a string, you have to find two values:
7
+
8
+ 1. the number of good substrings of even length;
9
+ 2. the number of good substrings of odd length.
10
+
11
+ Input
12
+
13
+ The first line of the input contains a single string of length n (1 ≤ n ≤ 105). Each character of the string will be either 'a' or 'b'.
14
+
15
+ Output
16
+
17
+ Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.
18
+
19
+ Examples
20
+
21
+ Input
22
+
23
+ bb
24
+
25
+
26
+ Output
27
+
28
+ 1 2
29
+
30
+
31
+ Input
32
+
33
+ baab
34
+
35
+
36
+ Output
37
+
38
+ 2 4
39
+
40
+
41
+ Input
42
+
43
+ babb
44
+
45
+
46
+ Output
47
+
48
+ 2 5
49
+
50
+
51
+ Input
52
+
53
+ babaa
54
+
55
+
56
+ Output
57
+
58
+ 2 7
59
+
60
+ Note
61
+
62
+ In example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.
63
+
64
+ In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.
65
+
66
+ In example 3, there are seven good substrings (i.e. "b", "a", "b", "b", "bb", "bab", "babb"). Two of them have even length and five of them have odd length.
67
+
68
+ Definitions
69
+
70
+ A substring s[l, r] (1 ≤ l ≤ r ≤ n) of string s = s1s2... sn is string slsl + 1... sr.
71
+
72
+ A string s = s1s2... sn is a palindrome if it is equal to string snsn - 1... s1.
73
+
74
+ ## Contest Information
75
+ - **Contest ID**: 451
76
+ - **Problem Index**: D
77
+ - **Points**: 2500.0
78
+ - **Rating**: 2000
79
+ - **Tags**: math
80
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
81
+ - **Memory Limit**: 256000000 bytes
82
+
83
+ ## Task
84
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0695/instruction.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # guess-the-permutation-easy-contest
2
+
3
+ ## Problem Description
4
+ In this problem your goal is to guess some secret permutation A of integers from 1 to 16.
5
+
6
+ There are 17 tests in this problem. Test number i for 1 ≤ i ≤ 16 will have the following form:
7
+ the first line of the input contains string "ELEMENT" (without quotes)
8
+ the second line of the input of the test i contains two integers from 1 to 16 each - i and element A[i] of the secret permutation
9
+ the only line of the output file contains one integer - A[i] too.
10
+
11
+ Input of the last (the 17-th test) will contain the only string "PERMUTATION" (without quotes). For this test your program should output some permutation of integers from 1 to 16 - your variant of the secret permutation.
12
+
13
+ If this permutation equals to the secret permuation A and passes all the 17 tests with your solution , you will receive 100 points. Otherwise you will receive 0 points. Note that for each wrong try you will receive 20 minutes penalty time after you solved this problem (as in ACM ICPC format)
14
+
15
+ Let us remind you that after you submit solution you can see a detailed feedback for each test separately.
16
+
17
+ You can't use "compile and test" without using custom input. If you want to test your solution on hackerearth platform , please use custom input.
18
+
19
+ SAMPLE INPUT
20
+ [EXAMPLE OF POSSIBLE TEST #2]
21
+ ELEMENT
22
+ 2 4
23
+
24
+ [EXAMPLE OF POSSIBLE TEST #17]
25
+ PERMUTATION
26
+
27
+ SAMPLE OUTPUT
28
+ 4
29
+
30
+
31
+ 3 4 5 6 7 1 8 9 10 11 13 15 16 12 2 14
32
+
33
+ ## Contest Information
34
+ - **Contest ID**: 0
35
+ - **Problem Index**:
36
+ - **Points**: 0.0
37
+ - **Rating**: 0
38
+ - **Tags**: None
39
+ - **Time Limit**: None seconds
40
+ - **Memory Limit**: 0 bytes
41
+
42
+ ## Task
43
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0771/instruction.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 416_D. Population Size
2
+
3
+ ## Problem Description
4
+ Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.
5
+
6
+ Polycarpus believes that if he writes out the population of the capital for several consecutive years in the sequence a1, a2, ..., an, then it is convenient to consider the array as several arithmetic progressions, written one after the other. For example, sequence (8, 6, 4, 2, 1, 4, 7, 10, 2) can be considered as a sequence of three arithmetic progressions (8, 6, 4, 2), (1, 4, 7, 10) and (2), which are written one after another.
7
+
8
+ Unfortunately, Polycarpus may not have all the data for the n consecutive years (a census of the population doesn't occur every year, after all). For this reason, some values of ai ​​may be unknown. Such values are represented by number -1.
9
+
10
+ For a given sequence a = (a1, a2, ..., an), which consists of positive integers and values ​​-1, find the minimum number of arithmetic progressions Polycarpus needs to get a. To get a, the progressions need to be written down one after the other. Values ​​-1 may correspond to an arbitrary positive integer and the values ai > 0 must be equal to the corresponding elements of sought consecutive record of the progressions.
11
+
12
+ Let us remind you that a finite sequence c is called an arithmetic progression if the difference ci + 1 - ci of any two consecutive elements in it is constant. By definition, any sequence of length 1 is an arithmetic progression.
13
+
14
+ Input
15
+
16
+ The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
17
+
18
+ Output
19
+
20
+ Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 9
27
+ 8 6 4 2 1 4 7 10 2
28
+
29
+
30
+ Output
31
+
32
+ 3
33
+
34
+
35
+ Input
36
+
37
+ 9
38
+ -1 6 -1 2 -1 4 7 -1 2
39
+
40
+
41
+ Output
42
+
43
+ 3
44
+
45
+
46
+ Input
47
+
48
+ 5
49
+ -1 -1 -1 -1 -1
50
+
51
+
52
+ Output
53
+
54
+ 1
55
+
56
+
57
+ Input
58
+
59
+ 7
60
+ -1 -1 4 5 1 2 3
61
+
62
+
63
+ Output
64
+
65
+ 2
66
+
67
+ ## Contest Information
68
+ - **Contest ID**: 416
69
+ - **Problem Index**: D
70
+ - **Points**: 2000.0
71
+ - **Rating**: 2400
72
+ - **Tags**: greedy, implementation, math
73
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
74
+ - **Memory Limit**: 256000000 bytes
75
+
76
+ ## Task
77
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0776/instruction.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 538_B. Quasi Binary
2
+
3
+ ## Problem Description
4
+ A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
5
+
6
+ You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
7
+
8
+ Input
9
+
10
+ The first line contains a single integer n (1 ≤ n ≤ 106).
11
+
12
+ Output
13
+
14
+ In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
15
+
16
+ In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 9
23
+
24
+
25
+ Output
26
+
27
+ 9
28
+ 1 1 1 1 1 1 1 1 1
29
+
30
+
31
+ Input
32
+
33
+ 32
34
+
35
+
36
+ Output
37
+
38
+ 3
39
+ 10 11 11
40
+
41
+ ## Contest Information
42
+ - **Contest ID**: 538
43
+ - **Problem Index**: B
44
+ - **Points**: 1000.0
45
+ - **Rating**: 1400
46
+ - **Tags**: constructive algorithms, dp, greedy, implementation
47
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
48
+ - **Memory Limit**: 256000000 bytes
49
+
50
+ ## Task
51
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0785/instruction.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 747_C. Servers
2
+
3
+ ## Problem Description
4
+ There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.
5
+
6
+ It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All ti are distinct.
7
+
8
+ To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored.
9
+
10
+ Write the program that determines which tasks will be performed and which will be ignored.
11
+
12
+ Input
13
+
14
+ The first line contains two positive integers n and q (1 ≤ n ≤ 100, 1 ≤ q ≤ 105) — the number of servers and the number of tasks.
15
+
16
+ Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≤ ti ≤ 106, 1 ≤ ki ≤ n, 1 ≤ di ≤ 1000) — the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
17
+
18
+ Output
19
+
20
+ Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 4 3
27
+ 1 3 2
28
+ 2 2 1
29
+ 3 4 3
30
+
31
+
32
+ Output
33
+
34
+ 6
35
+ -1
36
+ 10
37
+
38
+
39
+ Input
40
+
41
+ 3 2
42
+ 3 2 3
43
+ 5 1 2
44
+
45
+
46
+ Output
47
+
48
+ 3
49
+ 3
50
+
51
+
52
+ Input
53
+
54
+ 8 6
55
+ 1 3 20
56
+ 4 2 1
57
+ 6 5 5
58
+ 10 1 1
59
+ 15 3 6
60
+ 21 8 8
61
+
62
+
63
+ Output
64
+
65
+ 6
66
+ 9
67
+ 30
68
+ -1
69
+ 15
70
+ 36
71
+
72
+ Note
73
+
74
+ In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).
75
+
76
+ In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
77
+
78
+ ## Contest Information
79
+ - **Contest ID**: 747
80
+ - **Problem Index**: C
81
+ - **Points**: 1500.0
82
+ - **Rating**: 1300
83
+ - **Tags**: implementation
84
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
85
+ - **Memory Limit**: 256000000 bytes
86
+
87
+ ## Task
88
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0805/instruction.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # trick-with-the-cards
2
+
3
+ ## Problem Description
4
+ Mr. X is performing a trick with the cards. He has N cards, lets name them 1.....N, on a round table.
5
+ So card 1 is in between 2nd card and Nth card. Initially all cards are upside down. His trick involves making all cards face up.
6
+
7
+ His trick is whenever he taps on a card, it flips (if card was originally upside down, after flipping its faces up, and vice-versa), but he is no ordinary magician, he makes the two adjacent cards (if any) also to flip with the single tap. Formally, if he taps ith card, then i-1, i, i+1 cards are flipped. (Note that if he taps Nth card, then he flips (N-1)th, Nth and 1st card.)
8
+
9
+ Our magician needs a helper, to assist him in his magic tricks. He is looking for someone who can predict minimum number of taps needed to turn all the cards facing up.
10
+
11
+ Input :
12
+ First line of input contains T, the number of test cases.
13
+ Then T lines follows, each line contains N, the number of cards for that particular case.
14
+
15
+ Output :
16
+ Print the output for each case in a single line.
17
+
18
+ Constraints :
19
+ 1 ≤ T ≤ 10^5
20
+ 0 ≤ N ≤ 10^15
21
+
22
+ SAMPLE INPUT
23
+ 2
24
+ 2
25
+ 3
26
+
27
+ SAMPLE OUTPUT
28
+ 1
29
+ 1
30
+
31
+ ## Contest Information
32
+ - **Contest ID**: 0
33
+ - **Problem Index**:
34
+ - **Points**: 0.0
35
+ - **Rating**: 0
36
+ - **Tags**: None
37
+ - **Time Limit**: None seconds
38
+ - **Memory Limit**: 0 bytes
39
+
40
+ ## Task
41
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0833/instruction.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # aba15f
2
+
3
+ ## Problem Description
4
+ Problem description.
5
+
6
+
7
+ “Murphy’s Law doesn’t meant that something bad will happen. It means that whatever can happen, will happen.”
8
+ —Cooper
9
+
10
+
11
+ While traveling across space-time,the data sent by NASA to "The Endurance" spaceship is sent in the format of,
12
+
13
+
14
+ For example,
15
+
16
+ Bit4 Bit3 Bit2 Bit1 Bit0
17
+ D2 E1 D1 E0 D0
18
+
19
+ D - Databit
20
+ E - Error Check bit
21
+
22
+ The input file contains 32 bit number.
23
+
24
+ This format is chosen because often noises affect the data stream.
25
+ That is in the stream alternate bit contains the data bit.Your task is simple.. You just need to reset the error check bit ,leave the data bit unaffected .Cakewalk right? :-)Can you write the code to get the data bits alone.
26
+
27
+  
28
+
29
+ Input
30
+
31
+ First line contains the T number of test cases.
32
+ Next T lines contains a 32 bit integer.
33
+ T varies from 1 to 100000
34
+  
35
+
36
+ Output
37
+
38
+ Print the output for each input.
39
+
40
+ Example
41
+ Input:
42
+ 5
43
+ 100
44
+ 23
45
+ 4
46
+ 1000
47
+ 5
48
+
49
+ Output:
50
+ 68
51
+ 21
52
+ 4
53
+ 320
54
+ 5
55
+
56
+ ## Contest Information
57
+ - **Contest ID**: 0
58
+ - **Problem Index**:
59
+ - **Points**: 0.0
60
+ - **Rating**: 0
61
+ - **Tags**: None
62
+ - **Time Limit**: None seconds
63
+ - **Memory Limit**: 0 bytes
64
+
65
+ ## Task
66
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0834/instruction.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # chefch
2
+
3
+ ## Problem Description
4
+ Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighboring symbols of sequence are either '-+' or '+-'.
5
+ For example sequence '-+-+-+' is a Chain but sequence '-+-+--+' is not.
6
+ Help Chef to calculate the minimum number of symbols he need to replace (ex. '-' to '+' or '+' to '-') to receive a Chain sequence.
7
+
8
+ Input
9
+
10
+ First line contains single integer T denoting the number of test cases.
11
+ Line of each test case contains the string S consisting of symbols '-' and '+'.
12
+
13
+
14
+ Output
15
+
16
+ For each test case, in a single line print single interger - the minimal number of symbols Chef needs to replace to receive a Chain.
17
+
18
+
19
+ Constraints
20
+
21
+ 1 ≤ T ≤ 7
22
+ 1 ≤ |S| ≤ 10^5
23
+
24
+
25
+ Example
26
+ Input:
27
+ 2
28
+ ---+-+-+++
29
+ -------
30
+ Output:
31
+ 2
32
+ 3
33
+
34
+ Explanation
35
+ Example case 1.
36
+ We can change symbol 2 from '-' to '+' and symbol 9 from '+' to '-' and receive '-+-+-+-+-+'.
37
+ Example case 2.
38
+ We can change symbols 2, 4 and 6 from '-' to '+' and receive '-+-+-+-'.
39
+
40
+ ## Contest Information
41
+ - **Contest ID**: 0
42
+ - **Problem Index**:
43
+ - **Points**: 0.0
44
+ - **Rating**: 0
45
+ - **Tags**: None
46
+ - **Time Limit**: None seconds
47
+ - **Memory Limit**: 0 bytes
48
+
49
+ ## Task
50
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0851/instruction.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1256_E. Yet Another Division Into Teams
2
+
3
+ ## Problem Description
4
+ There are n students at your university. The programming skill of the i-th student is a_i. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has 2 ⋅ 10^5 students ready for the finals!
5
+
6
+ Each team should consist of at least three students. Each student should belong to exactly one team. The diversity of a team is the difference between the maximum programming skill of some student that belongs to this team and the minimum programming skill of some student that belongs to this team (in other words, if the team consists of k students with programming skills a[i_1], a[i_2], ..., a[i_k], then the diversity of this team is max_{j=1}^{k} a[i_j] - min_{j=1}^{k} a[i_j]).
7
+
8
+ The total diversity is the sum of diversities of all teams formed.
9
+
10
+ Your task is to minimize the total diversity of the division of students and find the optimal way to divide the students.
11
+
12
+ Input
13
+
14
+ The first line of the input contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of students.
15
+
16
+ The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the programming skill of the i-th student.
17
+
18
+ Output
19
+
20
+ In the first line print two integers res and k — the minimum total diversity of the division of students and the number of teams in your division, correspondingly.
21
+
22
+ In the second line print n integers t_1, t_2, ..., t_n (1 ≤ t_i ≤ k), where t_i is the number of team to which the i-th student belong.
23
+
24
+ If there are multiple answers, you can print any. Note that you don't need to minimize the number of teams. Each team should consist of at least three students.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+
31
+ 5
32
+ 1 1 3 4 2
33
+
34
+
35
+ Output
36
+
37
+
38
+ 3 1
39
+ 1 1 1 1 1
40
+
41
+
42
+ Input
43
+
44
+
45
+ 6
46
+ 1 5 12 13 2 15
47
+
48
+
49
+ Output
50
+
51
+
52
+ 7 2
53
+ 2 2 1 1 2 1
54
+
55
+
56
+ Input
57
+
58
+
59
+ 10
60
+ 1 2 5 129 185 581 1041 1909 1580 8150
61
+
62
+
63
+ Output
64
+
65
+
66
+ 7486 3
67
+ 3 3 3 2 2 2 2 1 1 1
68
+
69
+ Note
70
+
71
+ In the first example, there is only one team with skills [1, 1, 2, 3, 4] so the answer is 3. It can be shown that you cannot achieve a better answer.
72
+
73
+ In the second example, there are two teams with skills [1, 2, 5] and [12, 13, 15] so the answer is 4 + 3 = 7.
74
+
75
+ In the third example, there are three teams with skills [1, 2, 5], [129, 185, 581, 1041] and [1580, 1909, 8150] so the answer is 4 + 912 + 6570 = 7486.
76
+
77
+ ## Contest Information
78
+ - **Contest ID**: 1256
79
+ - **Problem Index**: E
80
+ - **Points**: 0.0
81
+ - **Rating**: 2000
82
+ - **Tags**: dp, greedy, sortings
83
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
84
+ - **Memory Limit**: 256000000 bytes
85
+
86
+ ## Task
87
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0856/instruction.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1364_E. X-OR
2
+
3
+ ## Problem Description
4
+ This is an interactive problem!
5
+
6
+ Ehab has a hidden permutation p of length n consisting of the elements from 0 to n-1. You, for some reason, want to figure out the permutation. To do that, you can give Ehab 2 different indices i and j, and he'll reply with (p_i|p_j) where | is the [bitwise-or](https://en.wikipedia.org/wiki/Bitwise_operation#OR) operation.
7
+
8
+ Ehab has just enough free time to answer 4269 questions, and while he's OK with answering that many questions, he's too lazy to play your silly games, so he'll fix the permutation beforehand and will not change it depending on your queries. Can you guess the permutation?
9
+
10
+ Input
11
+
12
+ The only line contains the integer n (3 ≤ n ≤ 2048) — the length of the permutation.
13
+
14
+ Interaction
15
+
16
+ To ask a question, print "? i j" (without quotes, i ≠ j) Then, you should read the answer, which will be (p_i|p_j).
17
+
18
+ If we answer with -1 instead of a valid answer, that means you exceeded the number of queries or made an invalid query.
19
+
20
+ Exit immediately after receiving -1 and you will see wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
21
+
22
+ To print the answer, print "! p_1 p_2 … p_n" (without quotes). Note that answering doesn't count as one of the 4269 queries.
23
+
24
+ After printing a query or printing the answer, do not forget to output end of line and flush the output. Otherwise, you will get idleness limit exceeded. To do this, use:
25
+
26
+ * fflush(stdout) or cout.flush() in C++;
27
+ * System.out.flush() in Java;
28
+ * flush(output) in Pascal;
29
+ * stdout.flush() in Python;
30
+ * See the documentation for other languages.
31
+
32
+
33
+
34
+ Hacks:
35
+
36
+ The first line should contain the integer n (3 ≤ n ≤ 2^{11}) — the length of the permutation p.
37
+
38
+ The second line should contain n space-separated integers p_1, p_2, …, p_n (0 ≤ p_i < n) — the elements of the permutation p.
39
+
40
+ Example
41
+
42
+ Input
43
+
44
+
45
+ 3
46
+ 1
47
+ 3
48
+ 2
49
+
50
+ Output
51
+
52
+
53
+ ? 1 2
54
+ ? 1 3
55
+ ? 2 3
56
+ ! 1 0 2
57
+
58
+ Note
59
+
60
+ In the first sample, the permutation is [1,0,2]. You start by asking about p_1|p_2 and Ehab replies with 1. You then ask about p_1|p_3 and Ehab replies with 3. Finally, you ask about p_2|p_3 and Ehab replies with 2. You then guess the permutation.
61
+
62
+ ## Contest Information
63
+ - **Contest ID**: 1364
64
+ - **Problem Index**: E
65
+ - **Points**: 2500.0
66
+ - **Rating**: 2700
67
+ - **Tags**: bitmasks, constructive algorithms, divide and conquer, interactive, probabilities
68
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
69
+ - **Memory Limit**: 256000000 bytes
70
+
71
+ ## Task
72
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0860/instruction.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1450_D. Rating Compression
2
+
3
+ ## Problem Description
4
+ On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers a of length n. You are now updating the infrastructure, so you've created a program to compress these graphs.
5
+
6
+ The program works as follows. Given an integer parameter k, the program takes the minimum of each contiguous subarray of length k in a.
7
+
8
+ More formally, for an array a of length n and an integer k, define the k-compression array of a as an array b of length n-k+1, such that $$$b_j =min_{j≤ i≤ j+k-1}a_i$$$
9
+
10
+ For example, the 3-compression array of [1, 3, 4, 5, 2] is [min\{1, 3, 4\}, min\{3, 4, 5\}, min\{4, 5, 2\}]=[1, 3, 2].
11
+
12
+ A permutation of length m is an array consisting of m distinct integers from 1 to m in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (m=3 but there is 4 in the array).
13
+
14
+ A k-compression array will make CodeCook users happy if it will be a permutation. Given an array a, determine for all 1≤ k≤ n if CodeCook users will be happy after a k-compression of this array or not.
15
+
16
+ Input
17
+
18
+ The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases.
19
+
20
+ The first line of the description of each test case contains a single integer n (1≤ n≤ 3⋅ 10^5) — the length of the array.
21
+
22
+ The second line of the description of each test case contains n integers a_1,…,a_n (1≤ a_i≤ n) — the elements of the array.
23
+
24
+ It is guaranteed, that the sum of n for all test cases does not exceed 3⋅ 10^5.
25
+
26
+ Output
27
+
28
+ For each test case, print a binary string of length n.
29
+
30
+ The k-th character of the string should be 1 if CodeCook users will be happy after a k-compression of the array a, and 0 otherwise.
31
+
32
+ Example
33
+
34
+ Input
35
+
36
+
37
+ 5
38
+ 5
39
+ 1 5 3 4 2
40
+ 4
41
+ 1 3 2 1
42
+ 5
43
+ 1 3 3 3 2
44
+ 10
45
+ 1 2 3 4 5 6 7 8 9 10
46
+ 3
47
+ 3 3 2
48
+
49
+
50
+ Output
51
+
52
+
53
+ 10111
54
+ 0001
55
+ 00111
56
+ 1111111111
57
+ 000
58
+
59
+ Note
60
+
61
+ In the first test case, a=[1, 5, 3, 4, 2].
62
+
63
+ * The 1-compression of a is [1, 5, 3, 4, 2] and it is a permutation.
64
+ * The 2-compression of a is [1, 3, 3, 2] and it is not a permutation, since 3 appears twice.
65
+ * The 3-compression of a is [1, 3, 2] and it is a permutation.
66
+ * The 4-compression of a is [1, 2] and it is a permutation.
67
+ * The 5-compression of a is [1] and it is a permutation.
68
+
69
+ ## Contest Information
70
+ - **Contest ID**: 1450
71
+ - **Problem Index**: D
72
+ - **Points**: 1750.0
73
+ - **Rating**: 1800
74
+ - **Tags**: binary search, data structures, greedy, implementation, two pointers
75
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
76
+ - **Memory Limit**: 256000000 bytes
77
+
78
+ ## Task
79
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0893/instruction.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 833_C. Ever-Hungry Krakozyabra
2
+
3
+ ## Problem Description
4
+ <image>
5
+
6
+ Recently, a wild Krakozyabra appeared at Jelly Castle. It is, truth to be said, always eager to have something for dinner.
7
+
8
+ Its favorite meal is natural numbers (typically served with honey sauce), or, to be more precise, the zeros in their corresponding decimal representations. As for other digits, Krakozyabra dislikes them; moreover, they often cause it indigestion! So, as a necessary precaution, Krakozyabra prefers to sort the digits of a number in non-descending order before proceeding to feast. Then, the leading zeros of the resulting number are eaten and the remaining part is discarded as an inedible tail.
9
+
10
+ For example, if Krakozyabra is to have the number 57040 for dinner, its inedible tail would be the number 457.
11
+
12
+ Slastyona is not really fond of the idea of Krakozyabra living in her castle. Hovewer, her natural hospitality prevents her from leaving her guest without food. Slastyona has a range of natural numbers from L to R, which she is going to feed the guest with. Help her determine how many distinct inedible tails are going to be discarded by Krakozyabra by the end of the dinner.
13
+
14
+ Input
15
+
16
+ In the first and only string, the numbers L and R are given – the boundaries of the range (1 ≤ L ≤ R ≤ 1018).
17
+
18
+ Output
19
+
20
+ Output the sole number – the answer for the problem.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 1 10
27
+
28
+
29
+ Output
30
+
31
+ 9
32
+
33
+
34
+ Input
35
+
36
+ 40 57
37
+
38
+
39
+ Output
40
+
41
+ 17
42
+
43
+
44
+ Input
45
+
46
+ 157 165
47
+
48
+
49
+ Output
50
+
51
+ 9
52
+
53
+ Note
54
+
55
+ In the first sample case, the inedible tails are the numbers from 1 to 9. Note that 10 and 1 have the same inedible tail – the number 1.
56
+
57
+ In the second sample case, each number has a unique inedible tail, except for the pair 45, 54. The answer to this sample case is going to be (57 - 40 + 1) - 1 = 17.
58
+
59
+ ## Contest Information
60
+ - **Contest ID**: 833
61
+ - **Problem Index**: C
62
+ - **Points**: 1500.0
63
+ - **Rating**: 2700
64
+ - **Tags**: brute force, combinatorics, greedy, math
65
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
66
+ - **Memory Limit**: 256000000 bytes
67
+
68
+ ## Task
69
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0894/instruction.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 854_A. Fraction
2
+
3
+ ## Problem Description
4
+ Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction <image> is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
5
+
6
+ During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button ( + ) instead of division button (÷) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation.
7
+
8
+ Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction <image> such that sum of its numerator and denominator equals n. Help Petya deal with this problem.
9
+
10
+ Input
11
+
12
+ In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.
13
+
14
+ Output
15
+
16
+ Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 3
23
+
24
+
25
+ Output
26
+
27
+ 1 2
28
+
29
+
30
+ Input
31
+
32
+ 4
33
+
34
+
35
+ Output
36
+
37
+ 1 3
38
+
39
+
40
+ Input
41
+
42
+ 12
43
+
44
+
45
+ Output
46
+
47
+ 5 7
48
+
49
+ ## Contest Information
50
+ - **Contest ID**: 854
51
+ - **Problem Index**: A
52
+ - **Points**: 500.0
53
+ - **Rating**: 800
54
+ - **Tags**: brute force, constructive algorithms, math
55
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
56
+ - **Memory Limit**: 512000000 bytes
57
+
58
+ ## Task
59
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0912/instruction.md ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02799 Keyence Programming Contest 2020 - Bichromization
2
+
3
+ ## Problem Description
4
+ We have a connected undirected graph with N vertices and M edges. Edge i in this graph (1 \leq i \leq M) connects Vertex U_i and Vertex V_i bidirectionally. We are additionally given N integers D_1, D_2, ..., D_N.
5
+
6
+ Determine whether the conditions below can be satisfied by assigning a color - white or black - to each vertex and an integer weight between 1 and 10^9 (inclusive) to each edge in this graph. If the answer is yes, find one such assignment of colors and integers, too.
7
+
8
+ * There is at least one vertex assigned white and at least one vertex assigned black.
9
+ * For each vertex v (1 \leq v \leq N), the following holds.
10
+ * The minimum cost to travel from Vertex v to a vertex whose color assigned is different from that of Vertex v by traversing the edges is equal to D_v.
11
+
12
+
13
+
14
+ Here, the cost of traversing the edges is the sum of the weights of the edges traversed.
15
+
16
+ Constraints
17
+
18
+ * 2 \leq N \leq 100,000
19
+ * 1 \leq M \leq 200,000
20
+ * 1 \leq D_i \leq 10^9
21
+ * 1 \leq U_i, V_i \leq N
22
+ * The given graph is connected and has no self-loops or multiple edges.
23
+ * All values in input are integers.
24
+
25
+ Input
26
+
27
+ Input is given from Standard Input in the following format:
28
+
29
+
30
+ N M
31
+ D_1 D_2 ... D_N
32
+ U_1 V_1
33
+ U_2 V_2
34
+ \vdots
35
+ U_M V_M
36
+
37
+
38
+ Output
39
+
40
+ If there is no assignment satisfying the conditions, print a single line containing `-1`.
41
+
42
+ If such an assignment exists, print one such assignment in the following format:
43
+
44
+
45
+ S
46
+ C_1
47
+ C_2
48
+ \vdots
49
+ C_M
50
+
51
+
52
+ Here,
53
+
54
+ * the first line should contain the string S of length N. Its i-th character (1 \leq i \leq N) should be `W` if Vertex i is assigned white and `B` if it is assigned black.
55
+ * The (i + 1)-th line (1 \leq i \leq M) should contain the integer weight C_i assigned to Edge i.
56
+
57
+ Examples
58
+
59
+ Input
60
+
61
+ 5 5
62
+ 3 4 3 5 7
63
+ 1 2
64
+ 1 3
65
+ 3 2
66
+ 4 2
67
+ 4 5
68
+
69
+
70
+ Output
71
+
72
+ BWWBB
73
+ 4
74
+ 3
75
+ 1
76
+ 5
77
+ 2
78
+
79
+
80
+ Input
81
+
82
+ 5 7
83
+ 1 2 3 4 5
84
+ 1 2
85
+ 1 3
86
+ 1 4
87
+ 2 3
88
+ 2 5
89
+ 3 5
90
+ 4 5
91
+
92
+
93
+ Output
94
+
95
+ -1
96
+
97
+
98
+ Input
99
+
100
+ 4 6
101
+ 1 1 1 1
102
+ 1 2
103
+ 1 3
104
+ 1 4
105
+ 2 3
106
+ 2 4
107
+ 3 4
108
+
109
+
110
+ Output
111
+
112
+ BBBW
113
+ 1
114
+ 1
115
+ 1
116
+ 2
117
+ 1
118
+ 1
119
+
120
+ ## Contest Information
121
+ - **Contest ID**: 0
122
+ - **Problem Index**:
123
+ - **Points**: 0.0
124
+ - **Rating**: 0
125
+ - **Tags**:
126
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
127
+ - **Memory Limit**: 1073741824 bytes
128
+
129
+ ## Task
130
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0924/instruction.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00602 Fibonacci Sets
2
+
3
+ ## Problem Description
4
+ Fibonacci number f(i) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule f(i) = f(i - 1) + f(i - 2), where we set f(0) = 1 = f(-1).
5
+
6
+ Let V and d be two certain positive integers and be N ≡ 1001 a constant. Consider a set of V nodes, each node i having a Fibonacci label F[i] = (f(i) mod N) assigned for i = 1,..., V ≤ N. If |F(i) - F(j)| < d, then the nodes i and j are connected.
7
+
8
+ Given V and d, how many connected subsets of nodes will you obtain?
9
+
10
+ <image>
11
+
12
+ Figure 1: There are 4 connected subsets for V = 20 and d = 100.
13
+
14
+ Constraints
15
+
16
+ * 1 ≤ V ≤ 1000
17
+ * 1 ≤ d ≤ 150
18
+
19
+ Input
20
+
21
+ Each data set is defined as one line with two integers as follows:
22
+
23
+ Line 1: Number of nodes V and the distance d.
24
+
25
+ Input includes several data sets (i.e., several lines). The number of dat sets is less than or equal to 50.
26
+
27
+ Output
28
+
29
+ Output line contains one integer - the number of connected subsets - for each input line.
30
+
31
+ Example
32
+
33
+ Input
34
+
35
+ 5 5
36
+ 50 1
37
+ 13 13
38
+
39
+
40
+ Output
41
+
42
+ 2
43
+ 50
44
+ 8
45
+
46
+ ## Contest Information
47
+ - **Contest ID**: 0
48
+ - **Problem Index**:
49
+ - **Points**: 0.0
50
+ - **Rating**: 0
51
+ - **Tags**:
52
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
53
+ - **Memory Limit**: 134217728 bytes
54
+
55
+ ## Task
56
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10004/instruction.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1023_C. Bracket Subsequence
2
+
3
+ ## Problem Description
4
+ A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
5
+
6
+ Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
7
+
8
+ You are given a regular bracket sequence s and an integer number k. Your task is to find a regular bracket sequence of length exactly k such that it is also a subsequence of s.
9
+
10
+ It is guaranteed that such sequence always exists.
11
+
12
+ Input
13
+
14
+ The first line contains two integers n and k (2 ≤ k ≤ n ≤ 2 ⋅ 10^5, both n and k are even) — the length of s and the length of the sequence you are asked to find.
15
+
16
+ The second line is a string s — regular bracket sequence of length n.
17
+
18
+ Output
19
+
20
+ Print a single string — a regular bracket sequence of length exactly k such that it is also a subsequence of s.
21
+
22
+ It is guaranteed that such sequence always exists.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 6 4
29
+ ()(())
30
+
31
+
32
+ Output
33
+
34
+ ()()
35
+
36
+
37
+ Input
38
+
39
+ 8 8
40
+ (()(()))
41
+
42
+
43
+ Output
44
+
45
+ (()(()))
46
+
47
+ ## Contest Information
48
+ - **Contest ID**: 1023
49
+ - **Problem Index**: C
50
+ - **Points**: 1500.0
51
+ - **Rating**: 1200
52
+ - **Tags**: greedy
53
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
54
+ - **Memory Limit**: 256000000 bytes
55
+
56
+ ## Task
57
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1001/instruction.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 901_D. Weighting a Tree
2
+
3
+ ## Problem Description
4
+ You are given a connected undirected graph with n vertices and m edges. The vertices are enumerated from 1 to n.
5
+
6
+ You are given n integers c1, c2, ..., cn, each of them is between - n and n, inclusive. It is also guaranteed that the parity of cv equals the parity of degree of vertex v. The degree of a vertex is the number of edges connected to it.
7
+
8
+ You are to write a weight between - 2·n2 and 2·n2 (inclusive) on each edge in such a way, that for each vertex v the sum of weights on edges connected to this vertex is equal to cv, or determine that this is impossible.
9
+
10
+ Input
11
+
12
+ The first line contains two integers n and m (2 ≤ n ≤ 105, n - 1 ≤ m ≤ 105) — the number of vertices and the number of edges.
13
+
14
+ The next line contains n integers c1, c2, ..., cn ( - n ≤ ci ≤ n), where ci is the required sum of weights of edges connected to vertex i. It is guaranteed that the parity of ci equals the parity of degree of vertex i.
15
+
16
+ The next m lines describe edges of the graph. The i-th of these lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), meaning that the i-th edge connects vertices ai and bi.
17
+
18
+ It is guaranteed that the given graph is connected and does not contain loops and multiple edges.
19
+
20
+ Output
21
+
22
+ If there is no solution, print "NO".
23
+
24
+ Otherwise print "YES" and then m lines, the i-th of them is the weight of the i-th edge wi ( - 2·n2 ≤ wi ≤ 2·n2).
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 3 3
31
+ 2 2 2
32
+ 1 2
33
+ 2 3
34
+ 1 3
35
+
36
+
37
+ Output
38
+
39
+ YES
40
+ 1
41
+ 1
42
+ 1
43
+
44
+
45
+ Input
46
+
47
+ 4 3
48
+ -1 0 2 1
49
+ 1 2
50
+ 2 3
51
+ 3 4
52
+
53
+
54
+ Output
55
+
56
+ YES
57
+ -1
58
+ 1
59
+ 1
60
+
61
+
62
+ Input
63
+
64
+ 6 6
65
+ 3 5 5 5 1 5
66
+ 1 4
67
+ 3 2
68
+ 4 3
69
+ 4 5
70
+ 3 5
71
+ 5 6
72
+
73
+
74
+ Output
75
+
76
+ YES
77
+ 3
78
+ 5
79
+ 3
80
+ -1
81
+ -3
82
+ 5
83
+
84
+
85
+ Input
86
+
87
+ 4 4
88
+ 4 4 2 4
89
+ 1 2
90
+ 2 3
91
+ 3 4
92
+ 4 1
93
+
94
+
95
+ Output
96
+
97
+ NO
98
+
99
+ ## Contest Information
100
+ - **Contest ID**: 901
101
+ - **Problem Index**: D
102
+ - **Points**: 2000.0
103
+ - **Rating**: 2700
104
+ - **Tags**: constructive algorithms, dfs and similar, graphs
105
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
106
+ - **Memory Limit**: 256000000 bytes
107
+
108
+ ## Task
109
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10035/instruction.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 316_F2. Suns and Rays
2
+
3
+ ## Problem Description
4
+ Smart Beaver became interested in drawing. He draws suns. However, at some point, Smart Beaver realized that simply drawing suns is boring. So he decided to design a program that will process his drawings. You are given a picture drawn by the beaver. It will have two colors: one for the background and one for the suns in the image. Your task will be to count the number of suns in the image and for each of them to count the number of rays.
5
+
6
+ Sun is arbitrarily rotated ellipse with rays. Ray is a segment which connects point on boundary of the ellipse with some point outside ellipse.
7
+
8
+ <image> An image where all suns are circles. <image> An image where all suns are ellipses, their axes are parallel to the coordinate axes. <image> An image where all suns are rotated ellipses.
9
+
10
+ It is guaranteed that:
11
+
12
+ * No two suns have common points.
13
+ * The rays’ width is 3 pixels.
14
+ * The lengths of the ellipsis suns’ axes will lie between 40 and 200 pixels.
15
+ * No two rays intersect.
16
+ * The lengths of all rays will lie between 10 and 30 pixels.
17
+
18
+ Input
19
+
20
+ The first line contains two integers h and w — the height and width of the image (1 ≤ h, w ≤ 1600). Next h lines will contain w space-separated integers each. They describe Smart Beaver’s picture. Each number equals either a 0 (the image background), or a 1 (the sun color).
21
+
22
+ The input limits for scoring 30 points are (subproblem F1):
23
+
24
+ * All suns on the image are circles.
25
+
26
+
27
+
28
+ The input limits for scoring 70 points are (subproblems F1+F2):
29
+
30
+ * All suns on the image are ellipses with axes parallel to the coordinate axes.
31
+
32
+
33
+
34
+ The input limits for scoring 100 points are (subproblems F1+F2+F3):
35
+
36
+ * All suns on the image are ellipses, they can be arbitrarily rotated.
37
+
38
+ Output
39
+
40
+ The first line must contain a single number k — the number of suns on the beaver’s image. The second line must contain exactly k space-separated integers, corresponding to the number of rays on each sun. The numbers of the second line must be sorted in the increasing order.
41
+
42
+ Examples
43
+
44
+ Note
45
+
46
+ For each complexity level you are suggested a sample in the initial data. You can download the samples at http://www.abbyy.ru/sun.zip.
47
+
48
+ ## Contest Information
49
+ - **Contest ID**: 316
50
+ - **Problem Index**: F2
51
+ - **Points**: 40.0
52
+ - **Rating**: 2300
53
+ - **Tags**: dfs and similar, implementation
54
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
55
+ - **Memory Limit**: 256000000 bytes
56
+
57
+ ## Task
58
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10050/instruction.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 671_E. Organizing a Race
2
+
3
+ ## Problem Description
4
+ Kekoland is a country with n beautiful cities numbered from left to right and connected by n - 1 roads. The i-th road connects cities i and i + 1 and length of this road is wi kilometers.
5
+
6
+ When you drive in Kekoland, each time you arrive in city i by car you immediately receive gi liters of gas. There is no other way to get gas in Kekoland.
7
+
8
+ You were hired by the Kekoland president Keko to organize the most beautiful race Kekoland has ever seen. Let race be between cities l and r (l ≤ r). Race will consist of two stages. On the first stage cars will go from city l to city r. After completing first stage, next day second stage will be held, now racers will go from r to l with their cars. Of course, as it is a race, racers drive directly from start city to finish city. It means that at the first stage they will go only right, and at the second stage they go only left. Beauty of the race between l and r is equal to r - l + 1 since racers will see r - l + 1 beautiful cities of Kekoland. Cars have infinite tank so racers will take all the gas given to them.
9
+
10
+ At the beginning of each stage racers start the race with empty tank (0 liters of gasoline). They will immediately take their gasoline in start cities (l for the first stage and r for the second stage) right after the race starts.
11
+
12
+ It may not be possible to organize a race between l and r if cars will run out of gas before they reach finish.
13
+
14
+ You have k presents. Each time you give a present to city i its value gi increases by 1. You may distribute presents among cities in any way (also give many presents to one city, each time increasing gi by 1). What is the most beautiful race you can organize?
15
+
16
+ Each car consumes 1 liter of gas per one kilometer.
17
+
18
+ Input
19
+
20
+ The first line of the input contains two integers n and k (2 ≤ n ≤ 100 000, 0 ≤ k ≤ 109) — the number of cities in Kekoland and the number of presents you have, respectively.
21
+
22
+ Next line contains n - 1 integers. The i-th of them is wi (1 ≤ wi ≤ 109) — the length of the road between city i and i + 1.
23
+
24
+ Next line contains n integers. The i-th of them is gi (0 ≤ gi ≤ 109) — the amount of gas you receive every time you enter city i.
25
+
26
+ Output
27
+
28
+ Print a single line — the beauty of the most beautiful race you can organize.
29
+
30
+ Examples
31
+
32
+ Input
33
+
34
+ 4 4
35
+ 2 2 2
36
+ 1 1 1 1
37
+
38
+
39
+ Output
40
+
41
+ 4
42
+
43
+
44
+ Input
45
+
46
+ 8 5
47
+ 2 2 2 3 7 3 1
48
+ 1 3 1 5 4 0 2 5
49
+
50
+
51
+ Output
52
+
53
+ 7
54
+
55
+ Note
56
+
57
+ In first sample if you give one present to each city then it will be possible to make a race between city 1 and city 4.
58
+
59
+ In second sample you should add 1 to g5 and 4 to g6, then it will be possible to make a race between cities 2 and 8.
60
+
61
+ ## Contest Information
62
+ - **Contest ID**: 671
63
+ - **Problem Index**: E
64
+ - **Points**: 3000.0
65
+ - **Rating**: 3300
66
+ - **Tags**: data structures, greedy
67
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
68
+ - **Memory Limit**: 256000000 bytes
69
+
70
+ ## Task
71
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10057/instruction.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 831_F. Bamboo Partition
2
+
3
+ ## Problem Description
4
+ Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is ai meters high.
5
+
6
+ Vladimir has just planted n bamboos in a row, each of which has height 0 meters right now, but they grow 1 meter each day. In order to make the partition nice Vladimir can cut each bamboo once at any height (no greater that the height of the bamboo), and then the bamboo will stop growing.
7
+
8
+ Vladimir wants to check the bamboos each d days (i.e. d days after he planted, then after 2d days and so on), and cut the bamboos that reached the required height. Vladimir wants the total length of bamboo parts he will cut off to be no greater than k meters.
9
+
10
+ What is the maximum value d he can choose so that he can achieve what he wants without cutting off more than k meters of bamboo?
11
+
12
+ Input
13
+
14
+ The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1011) — the number of bamboos and the maximum total length of cut parts, in meters.
15
+
16
+ The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the required heights of bamboos, in meters.
17
+
18
+ Output
19
+
20
+ Print a single integer — the maximum value of d such that Vladimir can reach his goal.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 3 4
27
+ 1 3 5
28
+
29
+
30
+ Output
31
+
32
+ 3
33
+
34
+
35
+ Input
36
+
37
+ 3 40
38
+ 10 30 50
39
+
40
+
41
+ Output
42
+
43
+ 32
44
+
45
+ Note
46
+
47
+ In the first example Vladimir can check bamboos each 3 days. Then he will cut the first and the second bamboos after 3 days, and the third bamboo after 6 days. The total length of cut parts is 2 + 0 + 1 = 3 meters.
48
+
49
+ ## Contest Information
50
+ - **Contest ID**: 831
51
+ - **Problem Index**: F
52
+ - **Points**: 1500.0
53
+ - **Rating**: 2300
54
+ - **Tags**: brute force, data structures, implementation, math, number theory, sortings, two pointers
55
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
56
+ - **Memory Limit**: 512000000 bytes
57
+
58
+ ## Task
59
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.