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

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-0090/instruction.md +85 -0
  2. code_contests-0111/instruction.md +58 -0
  3. code_contests-0116/instruction.md +66 -0
  4. code_contests-0120/instruction.md +61 -0
  5. code_contests-0121/instruction.md +126 -0
  6. code_contests-0126/instruction.md +101 -0
  7. code_contests-0129/instruction.md +70 -0
  8. code_contests-0269/instruction.md +72 -0
  9. code_contests-0312/instruction.md +54 -0
  10. code_contests-0313/instruction.md +61 -0
  11. code_contests-0314/instruction.md +48 -0
  12. code_contests-0323/instruction.md +114 -0
  13. code_contests-0379/instruction.md +71 -0
  14. code_contests-0545/instruction.md +59 -0
  15. code_contests-0572/instruction.md +61 -0
  16. code_contests-0575/instruction.md +57 -0
  17. code_contests-0581/instruction.md +65 -0
  18. code_contests-0586/instruction.md +85 -0
  19. code_contests-0632/instruction.md +83 -0
  20. code_contests-0722/instruction.md +76 -0
  21. code_contests-0740/instruction.md +109 -0
  22. code_contests-0747/instruction.md +87 -0
  23. code_contests-0748/instruction.md +65 -0
  24. code_contests-0749/instruction.md +87 -0
  25. code_contests-0770/instruction.md +62 -0
  26. code_contests-0777/instruction.md +74 -0
  27. code_contests-0782/instruction.md +67 -0
  28. code_contests-0784/instruction.md +56 -0
  29. code_contests-0858/instruction.md +91 -0
  30. code_contests-0867/instruction.md +59 -0
  31. code_contests-0922/instruction.md +84 -0
  32. code_contests-0977/instruction.md +60 -0
  33. code_contests-0983/instruction.md +80 -0
  34. code_contests-1000/instruction.md +70 -0
  35. code_contests-1006/instruction.md +57 -0
  36. code_contests-1008/instruction.md +79 -0
  37. code_contests-10140/instruction.md +51 -0
  38. code_contests-10149/instruction.md +64 -0
  39. code_contests-10170/instruction.md +53 -0
  40. code_contests-10184/instruction.md +72 -0
  41. code_contests-10200/instruction.md +180 -0
  42. code_contests-1030/instruction.md +101 -0
  43. code_contests-10310/instruction.md +40 -0
  44. code_contests-10342/instruction.md +61 -0
  45. code_contests-10345/instruction.md +91 -0
  46. code_contests-1037/instruction.md +103 -0
  47. code_contests-10372/instruction.md +68 -0
  48. code_contests-10381/instruction.md +45 -0
  49. code_contests-10386/instruction.md +39 -0
  50. code_contests-1039/instruction.md +114 -0
code_contests-0090/instruction.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00493 Zig-Zag Numbers
2
+
3
+ ## Problem Description
4
+ problem
5
+
6
+ If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza". Let's call it. For example, 2947 is a zigzag number because the digit numbers are in the order of 2 → 9 → 4 → 7 and increase → decrease → increase. In addition, 71946 is a zigzag number because it is in the order of decrease → increase → decrease → increase. On the other hand, 123, 71446, 71442 and 88 are not zigzag numbers. A one-digit positive integer is considered to be a zigzag number.
7
+
8
+ Create a program that finds the remainder of the number of zigzags divided by 10000 out of multiples of M between A and B.
9
+
10
+ input
11
+
12
+ The input consists of three lines, with one positive integer written on each line.
13
+
14
+ The integer on the first line represents A, the integer on the second line represents B, and the integer on the third line represents M. These satisfy 1 ≤ A ≤ B ≤ 10500 and 1 ≤ M ≤ 500.
15
+
16
+ * Note that the values ​​of A and B may not fit in the data types that represent ordinary integers.
17
+
18
+ output
19
+
20
+ Output the remainder of the number of zigzag numbers divided by 10000 out of multiples of M between A and B in one line.
21
+
22
+ Input / output example
23
+
24
+ Input example 1
25
+
26
+
27
+ 100
28
+ 200
29
+ Five
30
+
31
+
32
+ Output example 1
33
+
34
+
35
+ 13
36
+
37
+
38
+ In I / O example 1, the number of zigzags that are multiples of 5 from 100 to 200 is 13 of 105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195. ..
39
+
40
+ Input example 2
41
+
42
+
43
+ 6
44
+ 1234567
45
+ 3
46
+
47
+
48
+ Output example 2
49
+
50
+
51
+ 246
52
+
53
+
54
+ In I / O example 2, there are 50246 zigzag numbers that are multiples of 3 from 6 to 1234567, so 246, which is the remainder of dividing it by 10000, is output.
55
+
56
+ The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
57
+
58
+
59
+
60
+
61
+
62
+ Example
63
+
64
+ Input
65
+
66
+ 100
67
+ 200
68
+ 5
69
+
70
+
71
+ Output
72
+
73
+ 13
74
+
75
+ ## Contest Information
76
+ - **Contest ID**: 0
77
+ - **Problem Index**:
78
+ - **Points**: 0.0
79
+ - **Rating**: 0
80
+ - **Tags**:
81
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
82
+ - **Memory Limit**: 268435456 bytes
83
+
84
+ ## Task
85
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0111/instruction.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1043_A. Elections
2
+
3
+ ## Problem Description
4
+ Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from this person. Of course 0 ≤ k - a_i holds.
5
+
6
+ Awruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows a_1, a_2, ..., a_n — how many votes for Elodreip each student wants to give. Now he wants to change the number k to win the elections. Of course he knows that bigger k means bigger chance that somebody may notice that he has changed something and then he will be disqualified.
7
+
8
+ So, Awruk knows a_1, a_2, ..., a_n — how many votes each student will give to his opponent. Help him select the smallest winning number k. In order to win, Awruk needs to get strictly more votes than Elodreip.
9
+
10
+ Input
11
+
12
+ The first line contains integer n (1 ≤ n ≤ 100) — the number of students in the school.
13
+
14
+ The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 100) — the number of votes each student gives to Elodreip.
15
+
16
+ Output
17
+
18
+ Output the smallest integer k (k ≥ max a_i) which gives Awruk the victory. In order to win, Awruk needs to get strictly more votes than Elodreip.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 5
25
+ 1 1 1 5 1
26
+
27
+
28
+ Output
29
+
30
+ 5
31
+
32
+ Input
33
+
34
+ 5
35
+ 2 2 3 2 2
36
+
37
+
38
+ Output
39
+
40
+ 5
41
+
42
+ Note
43
+
44
+ In the first example, Elodreip gets 1 + 1 + 1 + 5 + 1 = 9 votes. The smallest possible k is 5 (it surely can't be less due to the fourth person), and it leads to 4 + 4 + 4 + 0 + 4 = 16 votes for Awruk, which is enough to win.
45
+
46
+ In the second example, Elodreip gets 11 votes. If k = 4, Awruk gets 9 votes and loses to Elodreip.
47
+
48
+ ## Contest Information
49
+ - **Contest ID**: 1043
50
+ - **Problem Index**: A
51
+ - **Points**: 500.0
52
+ - **Rating**: 800
53
+ - **Tags**: implementation, math
54
+ - **Time Limit**: {'seconds': 1, '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-0116/instruction.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1155_A. Reverse a Substring
2
+
3
+ ## Problem Description
4
+ You are given a string s consisting of n lowercase Latin letters.
5
+
6
+ Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from position l to position r is s[l; r] = s_l s_{l + 1} ... s_r.
7
+
8
+ You have to choose exactly one of the substrings of the given string and reverse it (i. e. make s[l; r] = s_r s_{r - 1} ... s_l) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string.
9
+
10
+ If it is impossible to reverse some substring of the given string to obtain a string that is less, print "NO". Otherwise print "YES" and any suitable substring.
11
+
12
+ String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that x_i < y_i, and for any j (1 ≤ j < i) x_j = y_j. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​.
13
+
14
+ Input
15
+
16
+ The first line of the input contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the length of s.
17
+
18
+ The second line of the input contains the string s of length n consisting only of lowercase Latin letters.
19
+
20
+ Output
21
+
22
+ If it is impossible to reverse some substring of the given string to obtain a string which is lexicographically less, print "NO". Otherwise print "YES" and two indices l and r (1 ≤ l < r ≤ n) denoting the substring you have to reverse. If there are multiple answers, you can print any.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+
29
+ 7
30
+ abacaba
31
+
32
+
33
+ Output
34
+
35
+
36
+ YES
37
+ 2 5
38
+
39
+
40
+ Input
41
+
42
+
43
+ 6
44
+ aabcfg
45
+
46
+
47
+ Output
48
+
49
+
50
+ NO
51
+
52
+ Note
53
+
54
+ In the first testcase the resulting string is "aacabba".
55
+
56
+ ## Contest Information
57
+ - **Contest ID**: 1155
58
+ - **Problem Index**: A
59
+ - **Points**: 0.0
60
+ - **Rating**: 1000
61
+ - **Tags**: implementation, sortings, strings
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-0120/instruction.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1236_A. Stones
2
+
3
+ ## Problem Description
4
+ Alice is playing with some stones.
5
+
6
+ Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
7
+
8
+ Each time she can do one of two operations:
9
+
10
+ 1. take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
11
+ 2. take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
12
+
13
+
14
+
15
+ She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 0 stones. Can you help her?
16
+
17
+ Input
18
+
19
+ The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines describe test cases in the following format:
20
+
21
+ Line contains three non-negative integers a, b and c, separated by spaces (0 ≤ a,b,c ≤ 100) — the number of stones in the first, the second and the third heap, respectively.
22
+
23
+ In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.
24
+
25
+ Output
26
+
27
+ Print t lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
28
+
29
+ Example
30
+
31
+ Input
32
+
33
+
34
+ 3
35
+ 3 4 5
36
+ 1 0 5
37
+ 5 3 2
38
+
39
+
40
+ Output
41
+
42
+
43
+ 9
44
+ 0
45
+ 6
46
+
47
+ Note
48
+
49
+ For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9.
50
+
51
+ ## Contest Information
52
+ - **Contest ID**: 1236
53
+ - **Problem Index**: A
54
+ - **Points**: 500.0
55
+ - **Rating**: 800
56
+ - **Tags**: brute force, greedy, math
57
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
58
+ - **Memory Limit**: 256000000 bytes
59
+
60
+ ## Task
61
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0121/instruction.md ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1253_F. Cheap Robot
2
+
3
+ ## Problem Description
4
+ You're given a simple, undirected, connected, weighted graph with n nodes and m edges.
5
+
6
+ Nodes are numbered from 1 to n. There are exactly k centrals (recharge points), which are nodes 1, 2, …, k.
7
+
8
+ We consider a robot moving into this graph, with a battery of capacity c, not fixed by the constructor yet. At any time, the battery contains an integer amount x of energy between 0 and c inclusive.
9
+
10
+ Traversing an edge of weight w_i is possible only if x ≥ w_i, and costs w_i energy points (x := x - w_i).
11
+
12
+ Moreover, when the robot reaches a central, its battery is entirely recharged (x := c).
13
+
14
+ You're given q independent missions, the i-th mission requires to move the robot from central a_i to central b_i.
15
+
16
+ For each mission, you should tell the minimum capacity required to acheive it.
17
+
18
+ Input
19
+
20
+ The first line contains four integers n, m, k and q (2 ≤ k ≤ n ≤ 10^5 and 1 ≤ m, q ≤ 3 ⋅ 10^5).
21
+
22
+ The i-th of the next m lines contains three integers u_i, v_i and w_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i, 1 ≤ w_i ≤ 10^9), that mean that there's an edge between nodes u and v, with a weight w_i.
23
+
24
+ It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes) and connected.
25
+
26
+ The i-th of the next q lines contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ k, a_i ≠ b_i).
27
+
28
+ Output
29
+
30
+ You have to output q lines, where the i-th line contains a single integer : the minimum capacity required to acheive the i-th mission.
31
+
32
+ Examples
33
+
34
+ Input
35
+
36
+
37
+ 10 9 3 1
38
+ 10 9 11
39
+ 9 2 37
40
+ 2 4 4
41
+ 4 1 8
42
+ 1 5 2
43
+ 5 7 3
44
+ 7 3 2
45
+ 3 8 4
46
+ 8 6 13
47
+ 2 3
48
+
49
+
50
+ Output
51
+
52
+
53
+ 12
54
+
55
+
56
+ Input
57
+
58
+
59
+ 9 11 3 2
60
+ 1 3 99
61
+ 1 4 5
62
+ 4 5 3
63
+ 5 6 3
64
+ 6 4 11
65
+ 6 7 21
66
+ 7 2 6
67
+ 7 8 4
68
+ 8 9 3
69
+ 9 2 57
70
+ 9 3 2
71
+ 3 1
72
+ 2 3
73
+
74
+
75
+ Output
76
+
77
+
78
+ 38
79
+ 15
80
+
81
+ Note
82
+
83
+ In the first example, the graph is the chain 10 - 9 - 2^C - 4 - 1^C - 5 - 7 - 3^C - 8 - 6, where centrals are nodes 1, 2 and 3.
84
+
85
+ For the mission (2, 3), there is only one simple path possible. Here is a simulation of this mission when the capacity is 12.
86
+
87
+ * The robot begins on the node 2, with c = 12 energy points.
88
+ * The robot uses an edge of weight 4.
89
+ * The robot reaches the node 4, with 12 - 4 = 8 energy points.
90
+ * The robot uses an edge of weight 8.
91
+ * The robot reaches the node 1 with 8 - 8 = 0 energy points.
92
+ * The robot is on a central, so its battery is recharged. He has now c = 12 energy points.
93
+ * The robot uses an edge of weight 2.
94
+ * The robot is on the node 5, with 12 - 2 = 10 energy points.
95
+ * The robot uses an edge of weight 3.
96
+ * The robot is on the node 7, with 10 - 3 = 7 energy points.
97
+ * The robot uses an edge of weight 2.
98
+ * The robot is on the node 3, with 7 - 2 = 5 energy points.
99
+ * The robot is on a central, so its battery is recharged. He has now c = 12 energy points.
100
+ * End of the simulation.
101
+
102
+
103
+
104
+ Note that if value of c was lower than 12, we would have less than 8 energy points on node 4, and we would be unable to use the edge 4 ↔ 1 of weight 8. Hence 12 is the minimum capacity required to acheive the mission.
105
+
106
+
107
+
108
+ The graph of the second example is described here (centrals are red nodes):
109
+
110
+ <image>
111
+
112
+ The robot can acheive the mission (3, 1) with a battery of capacity c = 38, using the path 3 → 9 → 8 → 7 → 2 → 7 → 6 → 5 → 4 → 1
113
+
114
+ The robot can acheive the mission (2, 3) with a battery of capacity c = 15, using the path 2 → 7 → 8 → 9 → 3
115
+
116
+ ## Contest Information
117
+ - **Contest ID**: 1253
118
+ - **Problem Index**: F
119
+ - **Points**: 2750.0
120
+ - **Rating**: 2500
121
+ - **Tags**: binary search, dsu, graphs, shortest paths, trees
122
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
123
+ - **Memory Limit**: 512000000 bytes
124
+
125
+ ## Task
126
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0126/instruction.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1361_E. James and the Chase
2
+
3
+ ## Problem Description
4
+ James Bond has a new plan for catching his enemy. There are some cities and directed roads between them, such that it is possible to travel between any two cities using these roads. When the enemy appears in some city, Bond knows her next destination but has no idea which path she will choose to move there.
5
+
6
+ The city a is called interesting, if for each city b, there is exactly one simple path from a to b. By a simple path, we understand a sequence of distinct cities, such that for every two neighboring cities, there exists a directed road from the first to the second city.
7
+
8
+ Bond's enemy is the mistress of escapes, so only the chase started in an interesting city gives the possibility of catching her. James wants to arrange his people in such cities. However, if there are not enough interesting cities, the whole action doesn't make sense since Bond's people may wait too long for the enemy.
9
+
10
+ You are responsible for finding all the interesting cities or saying that there is not enough of them. By not enough, James means strictly less than 20\% of all cities.
11
+
12
+ Input
13
+
14
+ The first line contains one integer t (1 ≤ t ≤ 2 000) — the number of test cases. Each test case is described as follows:
15
+
16
+ The first line contains two integers n and m (1 ≤ n ≤ 10^5, 0 ≤ m ≤ 2 ⋅ 10^5) — the number of cities and roads between them. Each of the following m lines contains two integers u, v (u ≠ v; 1 ≤ u, v ≤ n), which denote that there is a directed road from u to v.
17
+
18
+ You can assume that between each ordered pair of cities there is at most one road. The sum of n over all test cases doesn't exceed 10^5, and the sum of m doesn't exceed 2 ⋅ 10^5.
19
+
20
+ Output
21
+
22
+ If strictly less than 20\% of all cities are interesting, print -1. Otherwise, let k be the number of interesting cities. Print k distinct integers in increasing order — the indices of interesting cities.
23
+
24
+ Example
25
+
26
+ Input
27
+
28
+
29
+ 4
30
+ 3 3
31
+ 1 2
32
+ 2 3
33
+ 3 1
34
+ 3 6
35
+ 1 2
36
+ 2 1
37
+ 2 3
38
+ 3 2
39
+ 1 3
40
+ 3 1
41
+ 7 10
42
+ 1 2
43
+ 2 3
44
+ 3 1
45
+ 1 4
46
+ 4 5
47
+ 5 1
48
+ 4 6
49
+ 6 7
50
+ 7 4
51
+ 6 1
52
+ 6 8
53
+ 1 2
54
+ 2 3
55
+ 3 4
56
+ 4 5
57
+ 5 6
58
+ 6 1
59
+ 6 2
60
+ 5 1
61
+
62
+
63
+ Output
64
+
65
+
66
+ 1 2 3
67
+ -1
68
+ 1 2 3 5
69
+ -1
70
+
71
+ Note
72
+
73
+ In all drawings, if a city is colored green, then it is interesting; otherwise, it is colored red.
74
+
75
+ In the first sample, each city is interesting.
76
+
77
+ <image>
78
+
79
+ In the second sample, no city is interesting.
80
+
81
+ <image>
82
+
83
+ In the third sample, cities 1, 2, 3 and 5 are interesting.
84
+
85
+ <image>
86
+
87
+ In the last sample, only the city 1 is interesting. It is strictly less than 20\% of all cities, so the answer is -1.
88
+
89
+ <image>
90
+
91
+ ## Contest Information
92
+ - **Contest ID**: 1361
93
+ - **Problem Index**: E
94
+ - **Points**: 3000.0
95
+ - **Rating**: 3000
96
+ - **Tags**: dfs and similar, graphs, probabilities, trees
97
+ - **Time Limit**: {'seconds': 2, 'nanos': 500000000} seconds
98
+ - **Memory Limit**: 256000000 bytes
99
+
100
+ ## Task
101
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0129/instruction.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1424_N. BubbleSquare Tokens
2
+
3
+ ## Problem Description
4
+ BubbleSquare social network is celebrating 13^{th} anniversary and it is rewarding its members with special edition BubbleSquare tokens. Every member receives one personal token. Also, two additional tokens are awarded to each member for every friend they have on the network. Yet, there is a twist – everyone should end up with different number of tokens from all their friends. Each member may return one received token. Also, each two friends may agree to each return one or two tokens they have obtained on behalf of their friendship.
5
+
6
+ Input
7
+
8
+ First line of input contains two integer numbers n and k (2 ≤ n ≤ 12500, 1 ≤ k ≤ 1000000) - number of members in network and number of friendships.
9
+
10
+ Next k lines contain two integer numbers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) - meaning members a_i and b_i are friends.
11
+
12
+ Output
13
+
14
+ First line of output should specify the number of members who are keeping their personal token.
15
+
16
+ The second line should contain space separated list of members who are keeping their personal token.
17
+
18
+ Each of the following k lines should contain three space separated numbers, representing friend pairs and number of tokens each of them gets on behalf of their friendship.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+
25
+ 2 1
26
+ 1 2
27
+
28
+
29
+ Output
30
+
31
+
32
+ 1
33
+ 1
34
+ 1 2 0
35
+
36
+
37
+ Input
38
+
39
+
40
+ 3 3
41
+ 1 2
42
+ 1 3
43
+ 2 3
44
+
45
+
46
+ Output
47
+
48
+
49
+ 0
50
+ 1 2 0
51
+ 2 3 1
52
+ 1 3 2
53
+
54
+ Note
55
+
56
+ In the first test case, only the first member will keep its personal token and no tokens will be awarded for friendship between the first and the second member.
57
+
58
+ In the second test case, none of the members will keep their personal token. The first member will receive two tokens (for friendship with the third member), the second member will receive one token (for friendship with the third member) and the third member will receive three tokens (for friendships with the first and the second member).
59
+
60
+ ## Contest Information
61
+ - **Contest ID**: 1424
62
+ - **Problem Index**: N
63
+ - **Points**: 0.0
64
+ - **Rating**: 3500
65
+ - **Tags**: None
66
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
67
+ - **Memory Limit**: 256000000 bytes
68
+
69
+ ## Task
70
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0269/instruction.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 867_D. Gotta Go Fast
2
+
3
+ ## Problem Description
4
+ You're trying to set the record on your favorite video game. The game consists of N levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower. Specifically, you will complete the i-th level in either Fi seconds or Si seconds, where Fi < Si, and there's a Pi percent chance of completing it in Fi seconds. After completing a level, you may decide to either continue the game and play the next level, or reset the game and start again from the first level. Both the decision and the action are instant.
5
+
6
+ Your goal is to complete all the levels sequentially in at most R total seconds. You want to minimize the expected amount of time playing before achieving that goal. If you continue and reset optimally, how much total time can you expect to spend playing?
7
+
8
+ Input
9
+
10
+ The first line of input contains integers N and R <image>, the number of levels and number of seconds you want to complete the game in, respectively. N lines follow. The ith such line contains integers Fi, Si, Pi (1 ≤ Fi < Si ≤ 100, 80 ≤ Pi ≤ 99), the fast time for level i, the slow time for level i, and the probability (as a percentage) of completing level i with the fast time.
11
+
12
+ Output
13
+
14
+ Print the total expected time. Your answer must be correct within an absolute or relative error of 10 - 9.
15
+
16
+ Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if <image>.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 1 8
23
+ 2 8 81
24
+
25
+
26
+ Output
27
+
28
+ 3.14
29
+
30
+
31
+ Input
32
+
33
+ 2 30
34
+ 20 30 80
35
+ 3 9 85
36
+
37
+
38
+ Output
39
+
40
+ 31.4
41
+
42
+
43
+ Input
44
+
45
+ 4 319
46
+ 63 79 89
47
+ 79 97 91
48
+ 75 87 88
49
+ 75 90 83
50
+
51
+
52
+ Output
53
+
54
+ 314.159265358
55
+
56
+ Note
57
+
58
+ In the first example, you never need to reset. There's an 81% chance of completing the level in 2 seconds and a 19% chance of needing 8 seconds, both of which are within the goal time. The expected time is 0.81·2 + 0.19·8 = 3.14.
59
+
60
+ In the second example, you should reset after the first level if you complete it slowly. On average it will take 0.25 slow attempts before your first fast attempt. Then it doesn't matter whether you complete the second level fast or slow. The expected time is 0.25·30 + 20 + 0.85·3 + 0.15·9 = 31.4.
61
+
62
+ ## Contest Information
63
+ - **Contest ID**: 867
64
+ - **Problem Index**: D
65
+ - **Points**: 1500.0
66
+ - **Rating**: 2400
67
+ - **Tags**: binary search, dp
68
+ - **Time Limit**: {'seconds': 2, '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-0312/instruction.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # anuwta
2
+
3
+ ## Problem Description
4
+ There are N+1 lights. Lights are placed at (0, 0), (1, 0), (2, 0) ... (N, 0). Initially all the lights are on. You want to turn off all of them one after one. You want to follow a special pattern in turning off the lights.
5
+
6
+
7
+ You will start at (0, 0). First, you walk to the right most light that is on, turn it off. Then you walk to the left most light that is on, turn it off. Then again to the right most light that is on and so on. You will stop after turning off all lights. You want to know how much distance you walked in the process. Note that distance between (a,0) and (b,0) is |a-b|.
8
+
9
+
10
+ Input
11
+ The first line of the input contains an integer T denoting the number of test cases. Each test case has a single integer N on separate line.
12
+
13
+
14
+ Output
15
+ For each test case, output the distance you walked.
16
+
17
+ Constraints
18
+
19
+ 1 ≤ T ≤ 10^5
20
+ 1 ≤ N ≤ 10^5
21
+
22
+
23
+ Example
24
+ Input
25
+ 2
26
+ 1
27
+ 2
28
+
29
+ Output
30
+ 2
31
+ 5
32
+
33
+ Explanation
34
+ Testcase #2
35
+ You are initially at (0, 0)
36
+ Right most on-light is (2, 0). Distance = 2.
37
+ Now you are at (2, 0).
38
+ Left most on-light is (0, 0). Distance = 2.
39
+ Now you are at (0, 0)
40
+ Right most on-light is (1, 0). Distance = 1.
41
+ Now you are at (1, 0) and all lights are turned off.
42
+ Total distance walked = 5.
43
+
44
+ ## Contest Information
45
+ - **Contest ID**: 0
46
+ - **Problem Index**:
47
+ - **Points**: 0.0
48
+ - **Rating**: 0
49
+ - **Tags**: None
50
+ - **Time Limit**: None seconds
51
+ - **Memory Limit**: 0 bytes
52
+
53
+ ## Task
54
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0313/instruction.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # chsparr
2
+
3
+ ## Problem Description
4
+ Chef has a an array A consisting of N elements. He wants to add some elements into the array as per the below mentioned process.
5
+ After each minute, Chef iterates over the array in order from left to right, and takes every two neighbouring pair of elements, say x and y, he adds a new element x + y in the middle of elements x and y.
6
+ For example, if initial array A = {1, 6, 9}.
7
+
8
+ After first minute, the array A will be equal to {1, 7, 6, 15, 9}. Please note that the elements shown in the bold font are the newly added elements during first minute. As you can observe that 7 = 1 + 6, and 15 = 6 + 9.
9
+ After second minute, the array will be {1, 8, 7, 13, 6, 21, 15, 24, 9}. Once again, elements added during the second minute, are shown in bold.
10
+
11
+ Chef wants to know the sum of elements between x^th and y^th positions in the array A (i.e. Ax + Ax + 1 + ... + Ay) after m minutes. As the answer could be large, output it modulo 10^9+7 (1000000007). Please note that we use 1 based indexing in the problem.
12
+
13
+ Input
14
+
15
+ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
16
+ The first line of each test case contains four space-separated integers N, m, x, y denoting the number of elements in the array A in the beginning, amount of minutes and range for finding sum.
17
+ The second line contains N space-separated integers A1, A2, ..., AN denoting the array A in the beginning.
18
+
19
+
20
+ Output
21
+
22
+ For each test case, output a single line containing an integer corresponding to the sum of elements between x^th and y^th positions in the array A after m minutes modulo 10^9+7.
23
+
24
+
25
+ Constraints
26
+
27
+ 1 ≤ T ≤ 10
28
+ 1 ≤ N ≤ 10^5
29
+ 1 ≤ Ai ≤ 10^3
30
+ 1 ≤ m ≤ 30
31
+ 1 ≤ x ≤ y ≤ size of the array A (|A|) after m minutes
32
+
33
+
34
+ Example
35
+ Input:
36
+ 2
37
+ 3 1 1 5
38
+ 1 6 9
39
+ 3 2 6 7
40
+ 1 6 9
41
+
42
+ Output:
43
+ 38
44
+ 36
45
+
46
+
47
+ Explanation
48
+ Example case 1. After the first minute A = {1, 7, 6, 15, 9} and sum of all elements will be 38.
49
+ Example case 2. After the second minute the array A will be {1, 8, 7, 13, 6, 21, 15, 24, 9} and sum of elements between 6^th and 7^th equals to 21 + 15 = 36.
50
+
51
+ ## Contest Information
52
+ - **Contest ID**: 0
53
+ - **Problem Index**:
54
+ - **Points**: 0.0
55
+ - **Rating**: 0
56
+ - **Tags**: None
57
+ - **Time Limit**: None seconds
58
+ - **Memory Limit**: 0 bytes
59
+
60
+ ## Task
61
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0314/instruction.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # etmx05
2
+
3
+ ## Problem Description
4
+ Middle Strings
5
+
6
+ Miss Roma has got a new job in a computer agency. To test her skills the manager has appointed her with a small project.
7
+ She will get a string of any length but of ODD length and what she has to do
8
+ is finding a center string of length 3 in the original string.
9
+
10
+ For Example: She gets a string 'CANDY' then she needs to display the output 'AND'.
11
+
12
+ You have to help her. So, develop a code which accepts a string and displays the middle string of length 3.
13
+
14
+ Strings must be submitted in UPPER CASE only.
15
+ If String is of length less than 3 display output as 0.
16
+
17
+ Input
18
+ First line consists of a string of ODD length which is in uppercase.
19
+
20
+ Output
21
+ Second Line displays the appropriate output of length 3
22
+
23
+ Example
24
+
25
+ Input:
26
+ CANDY
27
+
28
+ Output:
29
+ AND
30
+
31
+
32
+ Input:
33
+ SOLVING
34
+
35
+ Output:
36
+ LVI
37
+
38
+ ## Contest Information
39
+ - **Contest ID**: 0
40
+ - **Problem Index**:
41
+ - **Points**: 0.0
42
+ - **Rating**: 0
43
+ - **Tags**: None
44
+ - **Time Limit**: None seconds
45
+ - **Memory Limit**: 0 bytes
46
+
47
+ ## Task
48
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0323/instruction.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1117_F. Crisp String
2
+
3
+ ## Problem Description
4
+ You are given a string of length n. Each character is one of the first p lowercase Latin letters.
5
+
6
+ You are also given a matrix A with binary values of size p × p. This matrix is symmetric (A_{ij} = A_{ji}). A_{ij} = 1 means that the string can have the i-th and j-th letters of Latin alphabet adjacent.
7
+
8
+ Let's call the string crisp if all of the adjacent characters in it can be adjacent (have 1 in the corresponding cell of matrix A).
9
+
10
+ You are allowed to do the following move. Choose any letter, remove all its occurrences and join the remaining parts of the string without changing their order. For example, removing letter 'a' from "abacaba" will yield "bcb".
11
+
12
+ The string you are given is crisp. The string should remain crisp after every move you make.
13
+
14
+ You are allowed to do arbitrary number of moves (possible zero). What is the shortest resulting string you can obtain?
15
+
16
+ Input
17
+
18
+ The first line contains two integers n and p (1 ≤ n ≤ 10^5, 1 ≤ p ≤ 17) — the length of the initial string and the length of the allowed prefix of Latin alphabet.
19
+
20
+ The second line contains the initial string. It is guaranteed that it contains only first p lowercase Latin letters and that is it crisp. Some of these p first Latin letters might not be present in the string.
21
+
22
+ Each of the next p lines contains p integer numbers — the matrix A (0 ≤ A_{ij} ≤ 1, A_{ij} = A_{ji}). A_{ij} = 1 means that the string can have the i-th and j-th letters of Latin alphabet adjacent.
23
+
24
+ Output
25
+
26
+ Print a single integer — the length of the shortest string after you make arbitrary number of moves (possible zero).
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+
33
+ 7 3
34
+ abacaba
35
+ 0 1 1
36
+ 1 0 0
37
+ 1 0 0
38
+
39
+
40
+ Output
41
+
42
+
43
+ 7
44
+
45
+
46
+ Input
47
+
48
+
49
+ 7 3
50
+ abacaba
51
+ 1 1 1
52
+ 1 0 0
53
+ 1 0 0
54
+
55
+
56
+ Output
57
+
58
+
59
+ 0
60
+
61
+
62
+ Input
63
+
64
+
65
+ 7 4
66
+ bacadab
67
+ 0 1 1 1
68
+ 1 0 0 0
69
+ 1 0 0 0
70
+ 1 0 0 0
71
+
72
+
73
+ Output
74
+
75
+
76
+ 5
77
+
78
+
79
+ Input
80
+
81
+
82
+ 3 3
83
+ cbc
84
+ 0 0 0
85
+ 0 0 1
86
+ 0 1 0
87
+
88
+
89
+ Output
90
+
91
+
92
+ 0
93
+
94
+ Note
95
+
96
+ In the first example no letter can be removed from the initial string.
97
+
98
+ In the second example you can remove letters in order: 'b', 'c', 'a'. The strings on the intermediate steps will be: "abacaba" → "aacaa" → "aaaa" → "".
99
+
100
+ In the third example you can remove letter 'b' and that's it.
101
+
102
+ In the fourth example you can remove letters in order 'c', 'b', but not in the order 'b', 'c' because two letters 'c' can't be adjacent.
103
+
104
+ ## Contest Information
105
+ - **Contest ID**: 1117
106
+ - **Problem Index**: F
107
+ - **Points**: 0.0
108
+ - **Rating**: 2500
109
+ - **Tags**: bitmasks, dp
110
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
111
+ - **Memory Limit**: 256000000 bytes
112
+
113
+ ## Task
114
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0379/instruction.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # abc-garfield
2
+
3
+ ## Problem Description
4
+ Garfield the cat likes candies A LOT. He always keeps a huge stock of it at his home. Today John, his owner, brought home three types of candies. He brought A pieces of Red candy, B pieces of Green candy and C pieces of Blue candy. Garfield is really happy. But the problem is that John won’t allow him to eat all of it at once. He will allow him to eat at most N candies. Garfield is very confused. His love for candies is clouding his judgement and he can’t make a decision on how to choose the N candies. Garfield is a dumb cat. So he asks you to find out in how many ways he can choose from the available type of candies so that he eats a total of N candies or less. Note: There is no difference between candies of the same color
5
+
6
+ Input:
7
+
8
+ The first line contains an integer t, the number of test cases. Each test case contains four space separated integers N,A,B,C.
9
+
10
+ Output:
11
+
12
+ For each test case output a single line containing the number of ways Garfield can choose the N candies.
13
+
14
+ Constraints:
15
+
16
+ 0 ≤ N,A,B,C ≤ 2500
17
+
18
+ SAMPLE INPUT
19
+ 3
20
+ 2 1 2 3
21
+ 1 1 1 1
22
+ 2 1 0 1
23
+
24
+ SAMPLE OUTPUT
25
+ 9
26
+ 4
27
+ 4
28
+
29
+ Explanation
30
+
31
+ Explanation for the sample test case 2:
32
+
33
+ For the test case 2 1 2 3
34
+
35
+ There is 1 piece of Red candy, 2 pieces of Green and 3 pieces of Blue. Garfield can eat at most 2 candies.
36
+
37
+ the possible combinations are:
38
+
39
+ (R,G,B)
40
+
41
+ (0,0,0)
42
+
43
+ (0,0,1)
44
+
45
+ (0,0,2)
46
+
47
+ (0,1,1)
48
+
49
+ (1,0,1)
50
+
51
+ (0,1,0)
52
+
53
+ (0,2,0)
54
+
55
+ (1,1,0)
56
+
57
+ (1,0,0)
58
+
59
+ Therefore 9 is the answer.
60
+
61
+ ## Contest Information
62
+ - **Contest ID**: 0
63
+ - **Problem Index**:
64
+ - **Points**: 0.0
65
+ - **Rating**: 0
66
+ - **Tags**: None
67
+ - **Time Limit**: None seconds
68
+ - **Memory Limit**: 0 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-0545/instruction.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1396_A. Multiples of Length
2
+
3
+ ## Problem Description
4
+ You are given an array a of n integers.
5
+
6
+ You want to make all elements of a equal to zero by doing the following operation exactly three times:
7
+
8
+ * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different).
9
+
10
+
11
+
12
+ It can be proven that it is always possible to make all elements of a equal to zero.
13
+
14
+ Input
15
+
16
+ The first line contains one integer n (1 ≤ n ≤ 100 000): the number of elements of the array.
17
+
18
+ The second line contains n elements of an array a separated by spaces: a_1, a_2, ..., a_n (-10^9 ≤ a_i ≤ 10^9).
19
+
20
+ Output
21
+
22
+ The output should contain six lines representing three operations.
23
+
24
+ For each operation, print two lines:
25
+
26
+ * The first line contains two integers l, r (1 ≤ l ≤ r ≤ n): the bounds of the selected segment.
27
+
28
+ * The second line contains r-l+1 integers b_l, b_{l+1}, ..., b_r (-10^{18} ≤ b_i ≤ 10^{18}): the numbers to add to a_l, a_{l+1}, …, a_r, respectively; b_i should be divisible by r - l + 1.
29
+
30
+ Example
31
+
32
+ Input
33
+
34
+
35
+ 4
36
+ 1 3 2 4
37
+
38
+
39
+ Output
40
+
41
+
42
+ 1 1
43
+ -1
44
+ 3 4
45
+ 4 2
46
+ 2 4
47
+ -3 -6 -6
48
+
49
+ ## Contest Information
50
+ - **Contest ID**: 1396
51
+ - **Problem Index**: A
52
+ - **Points**: 500.0
53
+ - **Rating**: 1600
54
+ - **Tags**: constructive algorithms, greedy, number theory
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-0572/instruction.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 633_A. Ebony and Ivory
2
+
3
+ ## Problem Description
4
+ Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
5
+
6
+ For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible.
7
+
8
+ Input
9
+
10
+ The first line of the input contains three integers a, b, c (1 ≤ a, b ≤ 100, 1 ≤ c ≤ 10 000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
11
+
12
+ Output
13
+
14
+ Print "Yes" (without quotes) if Dante can deal exactly c damage to the shield and "No" (without quotes) otherwise.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ 4 6 15
21
+
22
+
23
+ Output
24
+
25
+ No
26
+
27
+
28
+ Input
29
+
30
+ 3 2 7
31
+
32
+
33
+ Output
34
+
35
+ Yes
36
+
37
+
38
+ Input
39
+
40
+ 6 11 6
41
+
42
+
43
+ Output
44
+
45
+ Yes
46
+
47
+ Note
48
+
49
+ In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
50
+
51
+ ## Contest Information
52
+ - **Contest ID**: 633
53
+ - **Problem Index**: A
54
+ - **Points**: 250.0
55
+ - **Rating**: 1100
56
+ - **Tags**: brute force, math, number theory
57
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
58
+ - **Memory Limit**: 256000000 bytes
59
+
60
+ ## Task
61
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0575/instruction.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 708_C. Centroids
2
+
3
+ ## Problem Description
4
+ Tree is a connected acyclic graph. Suppose you are given a tree consisting of n vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed <image>.
5
+
6
+ You are given a tree of size n and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.
7
+
8
+ Input
9
+
10
+ The first line of the input contains an integer n (2 ≤ n ≤ 400 000) — the number of vertices in the tree. Each of the next n - 1 lines contains a pair of vertex indices ui and vi (1 ≤ ui, vi ≤ n) — endpoints of the corresponding edge.
11
+
12
+ Output
13
+
14
+ Print n integers. The i-th of them should be equal to 1 if the i-th vertex can be made centroid by replacing no more than one edge, and should be equal to 0 otherwise.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ 3
21
+ 1 2
22
+ 2 3
23
+
24
+
25
+ Output
26
+
27
+ 1 1 1
28
+
29
+
30
+ Input
31
+
32
+ 5
33
+ 1 2
34
+ 1 3
35
+ 1 4
36
+ 1 5
37
+
38
+
39
+ Output
40
+
41
+ 1 0 0 0 0
42
+
43
+ Note
44
+
45
+ In the first sample each vertex can be made a centroid. For example, in order to turn vertex 1 to centroid one have to replace the edge (2, 3) with the edge (1, 3).
46
+
47
+ ## Contest Information
48
+ - **Contest ID**: 708
49
+ - **Problem Index**: C
50
+ - **Points**: 1500.0
51
+ - **Rating**: 2300
52
+ - **Tags**: data structures, dfs and similar, dp, graphs, greedy, trees
53
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
54
+ - **Memory Limit**: 512000000 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-0581/instruction.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 845_B. Luba And The Ticket
2
+
3
+ ## Problem Description
4
+ Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
5
+
6
+ The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
7
+
8
+ Input
9
+
10
+ You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
11
+
12
+ Output
13
+
14
+ Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ 000000
21
+
22
+
23
+ Output
24
+
25
+ 0
26
+
27
+
28
+ Input
29
+
30
+ 123456
31
+
32
+
33
+ Output
34
+
35
+ 2
36
+
37
+
38
+ Input
39
+
40
+ 111000
41
+
42
+
43
+ Output
44
+
45
+ 1
46
+
47
+ Note
48
+
49
+ In the first example the ticket is already lucky, so the answer is 0.
50
+
51
+ In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
52
+
53
+ In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
54
+
55
+ ## Contest Information
56
+ - **Contest ID**: 845
57
+ - **Problem Index**: B
58
+ - **Points**: 0.0
59
+ - **Rating**: 1600
60
+ - **Tags**: brute force, greedy, implementation
61
+ - **Time Limit**: {'seconds': 2, '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-0586/instruction.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 961_F. k-substrings
2
+
3
+ ## Problem Description
4
+ You are given a string s consisting of n lowercase Latin letters.
5
+
6
+ Let's denote k-substring of s as a string subsk = sksk + 1..sn + 1 - k. Obviously, subs1 = s, and there are exactly <image> such substrings.
7
+
8
+ Let's call some string t an odd proper suprefix of a string T iff the following conditions are met:
9
+
10
+ * |T| > |t|;
11
+ * |t| is an odd number;
12
+ * t is simultaneously a prefix and a suffix of T.
13
+
14
+
15
+
16
+ For evey k-substring (<image>) of s you have to calculate the maximum length of its odd proper suprefix.
17
+
18
+ Input
19
+
20
+ The first line contains one integer n (2 ≤ n ≤ 106) — the length s.
21
+
22
+ The second line contains the string s consisting of n lowercase Latin letters.
23
+
24
+ Output
25
+
26
+ Print <image> integers. i-th of them should be equal to maximum length of an odd proper suprefix of i-substring of s (or - 1, if there is no such string that is an odd proper suprefix of i-substring).
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+ 15
33
+ bcabcabcabcabca
34
+
35
+
36
+ Output
37
+
38
+ 9 7 5 3 1 -1 -1 -1
39
+
40
+
41
+ Input
42
+
43
+ 24
44
+ abaaabaaaabaaabaaaabaaab
45
+
46
+
47
+ Output
48
+
49
+ 15 13 11 9 7 5 3 1 1 -1 -1 1
50
+
51
+
52
+ Input
53
+
54
+ 19
55
+ cabcabbcabcabbcabca
56
+
57
+
58
+ Output
59
+
60
+ 5 3 1 -1 -1 1 1 -1 -1 -1
61
+
62
+ Note
63
+
64
+ The answer for first sample test is folowing:
65
+
66
+ * 1-substring: bcabcabcabcabca
67
+ * 2-substring: cabcabcabcabc
68
+ * 3-substring: abcabcabcab
69
+ * 4-substring: bcabcabca
70
+ * 5-substring: cabcabc
71
+ * 6-substring: abcab
72
+ * 7-substring: bca
73
+ * 8-substring: c
74
+
75
+ ## Contest Information
76
+ - **Contest ID**: 961
77
+ - **Problem Index**: F
78
+ - **Points**: 0.0
79
+ - **Rating**: 2700
80
+ - **Tags**: binary search, hashing, string suffix structures
81
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
82
+ - **Memory Limit**: 256000000 bytes
83
+
84
+ ## Task
85
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0632/instruction.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 103_C. Russian Roulette
2
+
3
+ ## Problem Description
4
+ After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all.
5
+
6
+ Sasha selects any k out of n slots he wishes and puts bullets there. Roma spins the cylinder so that every of n possible cylinder's shifts is equiprobable. Then the game starts, the players take turns, Sasha starts: he puts the gun to his head and shoots. If there was no bullet in front of the trigger, the cylinder shifts by one position and the weapon is given to Roma for make the same move. The game continues until someone is shot, the survivor is the winner.
7
+
8
+ Sasha does not want to lose, so he must choose slots for bullets in such a way as to minimize the probability of its own loss. Of all the possible variant he wants to select the lexicographically minimal one, where an empty slot is lexicographically less than a charged one.
9
+
10
+ More formally, the cylinder of n bullet slots able to contain k bullets can be represented as a string of n characters. Exactly k of them are "X" (charged slots) and the others are "." (uncharged slots).
11
+
12
+ Let us describe the process of a shot. Suppose that the trigger is in front of the first character of the string (the first slot). If a shot doesn't kill anyone and the cylinder shifts, then the string shifts left. So the first character becomes the last one, the second character becomes the first one, and so on. But the trigger doesn't move. It will be in front of the first character of the resulting string.
13
+
14
+ Among all the strings that give the minimal probability of loss, Sasha choose the lexicographically minimal one. According to this very string, he charges the gun. You have to help Sasha to charge the gun. For that, each xi query must be answered: is there a bullet in the positions xi?
15
+
16
+ Input
17
+
18
+ The first line contains three integers n, k and p (1 ≤ n ≤ 1018, 0 ≤ k ≤ n, 1 ≤ p ≤ 1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow p lines; they are the queries. Each line contains one integer xi (1 ≤ xi ≤ n) the number of slot to describe.
19
+
20
+ Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
21
+
22
+ Output
23
+
24
+ For each query print "." if the slot should be empty and "X" if the slot should be charged.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 3 1 3
31
+ 1
32
+ 2
33
+ 3
34
+
35
+
36
+ Output
37
+
38
+ ..X
39
+
40
+ Input
41
+
42
+ 6 3 6
43
+ 1
44
+ 2
45
+ 3
46
+ 4
47
+ 5
48
+ 6
49
+
50
+
51
+ Output
52
+
53
+ .X.X.X
54
+
55
+ Input
56
+
57
+ 5 2 5
58
+ 1
59
+ 2
60
+ 3
61
+ 4
62
+ 5
63
+
64
+
65
+ Output
66
+
67
+ ...XX
68
+
69
+ Note
70
+
71
+ The lexicographical comparison of is performed by the < operator in modern programming languages. The a string is lexicographically less that the b string, if there exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.
72
+
73
+ ## Contest Information
74
+ - **Contest ID**: 103
75
+ - **Problem Index**: C
76
+ - **Points**: 1500.0
77
+ - **Rating**: 1900
78
+ - **Tags**: constructive algorithms, greedy
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-0722/instruction.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01556 ConvexCut
2
+
3
+ ## Problem Description
4
+ A convex polygon consisting of N vertices is given. The coordinates of each vertex are represented counterclockwise by (X1, Y1), (X2, Y2), ……, (XN, YN). No matter what straight line passes through the point P, find the coordinates of the point P so that the areas of the two convex polygons obtained after cutting are equal.
5
+
6
+ Constraints
7
+
8
+ * All inputs are integers
9
+
10
+ * 3 ≤ N ≤ 50
11
+
12
+ * 0 ≤ | Xi |, | Yi | ≤ 1000000
13
+
14
+ * The input polygon is a simple convex polygon.
15
+
16
+ * The output must satisfy max (| X-cX |, | Y-cY |) ≤ 0.0001 when the output coordinates are (X, Y) and the exact solution is (cX, cY).
17
+
18
+ Input
19
+
20
+ The input is given in the following format.
21
+
22
+ > N
23
+ > X1 Y1
24
+ > X2 Y2
25
+ > ……
26
+ > XN YN
27
+ >
28
+
29
+ Output
30
+
31
+ If there is a point that satisfies the condition of the problem statement, the coordinates of that point
32
+
33
+ > X Y
34
+ >
35
+
36
+ Output in the format of. If the point does not exist, output "NA" on one line.
37
+
38
+ Examples
39
+
40
+ Input
41
+
42
+ 4
43
+ 100 100
44
+ 0 100
45
+ 0 0
46
+ 100 0
47
+
48
+
49
+ Output
50
+
51
+ 50.00000 50.00000
52
+
53
+
54
+ Input
55
+
56
+ 3
57
+ 100 100
58
+ 0 100
59
+ 0 0
60
+
61
+
62
+ Output
63
+
64
+ NA
65
+
66
+ ## Contest Information
67
+ - **Contest ID**: 0
68
+ - **Problem Index**:
69
+ - **Points**: 0.0
70
+ - **Rating**: 0
71
+ - **Tags**:
72
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
73
+ - **Memory Limit**: 134217728 bytes
74
+
75
+ ## Task
76
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0740/instruction.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1118_C. Palindromic Matrix
2
+
3
+ ## Problem Description
4
+ Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
5
+
6
+ For example, the following matrices are palindromic:
7
+
8
+ <image>
9
+
10
+ The following matrices are not palindromic because they change after the order of rows is reversed:
11
+
12
+ <image>
13
+
14
+ The following matrices are not palindromic because they change after the order of columns is reversed:
15
+
16
+ <image>
17
+
18
+ You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
19
+
20
+ Input
21
+
22
+ The first line contains one integer n (1 ≤ n ≤ 20).
23
+
24
+ The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.
25
+
26
+ Output
27
+
28
+ If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.
29
+
30
+ If it's impossible to construct any matrix, then print "NO".
31
+
32
+ You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
33
+
34
+ Examples
35
+
36
+ Input
37
+
38
+
39
+ 4
40
+ 1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
41
+
42
+
43
+ Output
44
+
45
+
46
+ YES
47
+ 1 2 2 1
48
+ 8 2 2 8
49
+ 8 2 2 8
50
+ 1 2 2 1
51
+
52
+
53
+ Input
54
+
55
+
56
+ 3
57
+ 1 1 1 1 1 3 3 3 3
58
+
59
+
60
+ Output
61
+
62
+
63
+ YES
64
+ 1 3 1
65
+ 3 1 3
66
+ 1 3 1
67
+
68
+
69
+ Input
70
+
71
+
72
+ 4
73
+ 1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
74
+
75
+
76
+ Output
77
+
78
+
79
+ NO
80
+
81
+
82
+ Input
83
+
84
+
85
+ 1
86
+ 10
87
+
88
+
89
+ Output
90
+
91
+
92
+ YES
93
+ 10
94
+
95
+ Note
96
+
97
+ Note that there exist multiple answers for the first two examples.
98
+
99
+ ## Contest Information
100
+ - **Contest ID**: 1118
101
+ - **Problem Index**: C
102
+ - **Points**: 0.0
103
+ - **Rating**: 1700
104
+ - **Tags**: constructive algorithms, implementation
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-0747/instruction.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1264_D2. Beautiful Bracket Sequence (hard version)
2
+
3
+ ## Problem Description
4
+ This is the hard version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 10^6.
5
+
6
+ Let's define a correct bracket sequence and its depth as follow:
7
+
8
+ * An empty string is a correct bracket sequence with depth 0.
9
+ * If "s" is a correct bracket sequence with depth d then "(s)" is a correct bracket sequence with depth d + 1.
10
+ * If "s" and "t" are both correct bracket sequences then their concatenation "st" is a correct bracket sequence with depth equal to the maximum depth of s and t.
11
+
12
+
13
+
14
+ For a (not necessarily correct) bracket sequence s, we define its depth as the maximum depth of any correct bracket sequence induced by removing some characters from s (possibly zero). For example: the bracket sequence s = "())(())" has depth 2, because by removing the third character we obtain a correct bracket sequence "()(())" with depth 2.
15
+
16
+ Given a string a consists of only characters '(', ')' and '?'. Consider all (not necessarily correct) bracket sequences obtained by replacing all characters '?' in a by either '(' or ')'. Calculate the sum of all the depths of all these bracket sequences. As this number can be large, find it modulo 998244353.
17
+
18
+ Hacks in this problem can be done only if easy and hard versions of this problem was solved.
19
+
20
+ Input
21
+
22
+ The only line contains a non-empty string consist of only '(', ')' and '?'. The length of the string is at most 10^6.
23
+
24
+ Output
25
+
26
+ Print the answer modulo 998244353 in a single line.
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+
33
+ ??
34
+
35
+
36
+ Output
37
+
38
+
39
+ 1
40
+
41
+
42
+ Input
43
+
44
+
45
+ (?(?))
46
+
47
+
48
+ Output
49
+
50
+
51
+ 9
52
+
53
+ Note
54
+
55
+ In the first test case, we can obtain 4 bracket sequences by replacing all characters '?' with either '(' or ')':
56
+
57
+ * "((". Its depth is 0;
58
+ * "))". Its depth is 0;
59
+ * ")(". Its depth is 0;
60
+ * "()". Its depth is 1.
61
+
62
+
63
+
64
+ So, the answer is 1 = 0 + 0 + 0 + 1.
65
+
66
+ In the second test case, we can obtain 4 bracket sequences by replacing all characters '?' with either '(' or ')':
67
+
68
+ * "(((())". Its depth is 2;
69
+ * "()()))". Its depth is 2;
70
+ * "((()))". Its depth is 3;
71
+ * "()(())". Its depth is 2.
72
+
73
+
74
+
75
+ So, the answer is 9 = 2 + 2 + 3 + 2.
76
+
77
+ ## Contest Information
78
+ - **Contest ID**: 1264
79
+ - **Problem Index**: D2
80
+ - **Points**: 1000.0
81
+ - **Rating**: 2900
82
+ - **Tags**: combinatorics, probabilities
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-0748/instruction.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1286_A. Garland
2
+
3
+ ## Problem Description
4
+ Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.
5
+
6
+ <image>
7
+
8
+ Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by 2). For example, the complexity of 1 4 2 3 5 is 2 and the complexity of 1 3 5 7 6 4 2 is 1.
9
+
10
+ No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.
11
+
12
+ Input
13
+
14
+ The first line contains a single integer n (1 ≤ n ≤ 100) — the number of light bulbs on the garland.
15
+
16
+ The second line contains n integers p_1,\ p_2,\ …,\ p_n (0 ≤ p_i ≤ n) — the number on the i-th bulb, or 0 if it was removed.
17
+
18
+ Output
19
+
20
+ Output a single number — the minimum complexity of the garland.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+
27
+ 5
28
+ 0 5 0 2 3
29
+
30
+
31
+ Output
32
+
33
+
34
+ 2
35
+
36
+
37
+ Input
38
+
39
+
40
+ 7
41
+ 1 0 0 5 0 0 2
42
+
43
+
44
+ Output
45
+
46
+
47
+ 1
48
+
49
+ Note
50
+
51
+ In the first example, one should place light bulbs as 1 5 4 2 3. In that case, the complexity would be equal to 2, because only (5, 4) and (2, 3) are the pairs of adjacent bulbs that have different parity.
52
+
53
+ In the second case, one of the correct answers is 1 7 3 5 6 4 2.
54
+
55
+ ## Contest Information
56
+ - **Contest ID**: 1286
57
+ - **Problem Index**: A
58
+ - **Points**: 500.0
59
+ - **Rating**: 1800
60
+ - **Tags**: dp, greedy, sortings
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-0749/instruction.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1305_B. Kuroni and Simple Strings
2
+
3
+ ## Problem Description
4
+ Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!
5
+
6
+ We say that a string formed by n characters '(' or ')' is simple if its length n is even and positive, its first n/2 characters are '(', and its last n/2 characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.
7
+
8
+ Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'.
9
+
10
+ Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.
11
+
12
+ Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?
13
+
14
+ A sequence of characters a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters.
15
+
16
+ Input
17
+
18
+ The only line of input contains a string s (1 ≤ |s| ≤ 1000) formed by characters '(' and ')', where |s| is the length of s.
19
+
20
+ Output
21
+
22
+ In the first line, print an integer k — the minimum number of operations you have to apply. Then, print 2k lines describing the operations in the following format:
23
+
24
+ For each operation, print a line containing an integer m — the number of characters in the subsequence you will remove.
25
+
26
+ Then, print a line containing m integers 1 ≤ a_1 < a_2 < ... < a_m — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string.
27
+
28
+ If there are multiple valid sequences of operations with the smallest k, you may print any of them.
29
+
30
+ Examples
31
+
32
+ Input
33
+
34
+
35
+ (()((
36
+
37
+
38
+ Output
39
+
40
+
41
+ 1
42
+ 2
43
+ 1 3
44
+
45
+
46
+ Input
47
+
48
+
49
+ )(
50
+
51
+
52
+ Output
53
+
54
+
55
+ 0
56
+
57
+
58
+ Input
59
+
60
+
61
+ (()())
62
+
63
+
64
+ Output
65
+
66
+
67
+ 1
68
+ 4
69
+ 1 2 5 6
70
+
71
+ Note
72
+
73
+ In the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices 2 and 3, which results in the same final string.
74
+
75
+ In the second sample, it is already impossible to perform any operations.
76
+
77
+ ## Contest Information
78
+ - **Contest ID**: 1305
79
+ - **Problem Index**: B
80
+ - **Points**: 1000.0
81
+ - **Rating**: 1200
82
+ - **Tags**: constructive algorithms, greedy, strings, two pointers
83
+ - **Time Limit**: {'seconds': 1, '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-0770/instruction.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 393_C. Blocked Points
2
+
3
+ ## Problem Description
4
+ Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:
5
+
6
+ * the Euclidean distance between A and B is one unit and neither A nor B is blocked;
7
+ * or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B.
8
+
9
+
10
+
11
+ Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick?
12
+
13
+ Input
14
+
15
+ The first line contains an integer n (0 ≤ n ≤ 4·107).
16
+
17
+ Output
18
+
19
+ Print a single integer — the minimum number of points that should be blocked.
20
+
21
+ Examples
22
+
23
+ Input
24
+
25
+ 1
26
+
27
+
28
+ Output
29
+
30
+ 4
31
+
32
+
33
+ Input
34
+
35
+ 2
36
+
37
+
38
+ Output
39
+
40
+ 8
41
+
42
+
43
+ Input
44
+
45
+ 3
46
+
47
+
48
+ Output
49
+
50
+ 16
51
+
52
+ ## Contest Information
53
+ - **Contest ID**: 393
54
+ - **Problem Index**: C
55
+ - **Points**: 500.0
56
+ - **Rating**: 0
57
+ - **Tags**: math
58
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
59
+ - **Memory Limit**: 256000000 bytes
60
+
61
+ ## Task
62
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0777/instruction.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 566_C. Logistical Questions
2
+
3
+ ## Problem Description
4
+ Some country consists of n cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (n - 1) bidirectional roads (in the other words, the graph of roads is a tree). The i-th road that directly connects cities ai and bi, has the length of li kilometers.
5
+
6
+ The transport network is served by a state transporting company FRR (Fabulous Rail Roads). In order to simplify the price policy, it offers a single ride fare on the train. In order to follow the route of length t kilometers, you need to pay <image> burles. Note that it is forbidden to split a long route into short segments and pay them separately (a special railroad police, or RRP, controls that the law doesn't get violated).
7
+
8
+ A Large Software Company decided to organize a programming tournament. Having conducted several online rounds, the company employees determined a list of finalists and sent it to the logistical department to find a place where to conduct finals. The Large Software Company can easily organize the tournament finals in any of the n cities of the country, so the the main factor in choosing the city for the last stage of the tournament is the total cost of buying tickets for all the finalists. We know that the i-th city of the country has wi cup finalists living there.
9
+
10
+ Help the company employees find the city such that the total cost of travel of all the participants to it is minimum.
11
+
12
+ Input
13
+
14
+ The first line of the input contains number n (1 ≤ n ≤ 200 000) — the number of cities in the country.
15
+
16
+ The next line contains n integers w1, w2, ..., wn (0 ≤ wi ≤ 108) — the number of finalists living in each city of the country.
17
+
18
+ Next (n - 1) lines contain the descriptions of the railroad, the i-th line contains three integers, ai, bi, li (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ li ≤ 1000).
19
+
20
+ Output
21
+
22
+ Print two numbers — an integer f that is the number of the optimal city to conduct the competition, and the real number c, equal to the minimum total cost of transporting all the finalists to the competition. Your answer will be considered correct if two conditions are fulfilled at the same time:
23
+
24
+ 1. The absolute or relative error of the printed number c in comparison with the cost of setting up a final in city f doesn't exceed 10 - 6;
25
+ 2. Absolute or relative error of the printed number c in comparison to the answer of the jury doesn't exceed 10 - 6.
26
+
27
+
28
+
29
+ If there are multiple answers, you are allowed to print any of them.
30
+
31
+ Examples
32
+
33
+ Input
34
+
35
+ 5
36
+ 3 1 2 6 5
37
+ 1 2 3
38
+ 2 3 1
39
+ 4 3 9
40
+ 5 3 1
41
+
42
+
43
+ Output
44
+
45
+ 3 192.0
46
+
47
+ Input
48
+
49
+ 2
50
+ 5 5
51
+ 1 2 2
52
+
53
+
54
+ Output
55
+
56
+ 1 14.142135623730951000
57
+
58
+ Note
59
+
60
+ In the sample test an optimal variant of choosing a city to conduct the finals of the competition is 3. At such choice the cost of conducting is <image> burles.
61
+
62
+ In the second sample test, whatever city you would choose, you will need to pay for the transport for five participants, so you will need to pay <image> burles for each one of them.
63
+
64
+ ## Contest Information
65
+ - **Contest ID**: 566
66
+ - **Problem Index**: C
67
+ - **Points**: 3000.0
68
+ - **Rating**: 3000
69
+ - **Tags**: dfs and similar, divide and conquer, trees
70
+ - **Time Limit**: {'seconds': 2, '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-0782/instruction.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 680_D. Bear and Tower of Cubes
2
+
3
+ ## Problem Description
4
+ Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
5
+
6
+ A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.
7
+
8
+ Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.
9
+
10
+ Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.
11
+
12
+ Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.
13
+
14
+ Input
15
+
16
+ The only line of the input contains one integer m (1 ≤ m ≤ 1015), meaning that Limak wants you to choose X between 1 and m, inclusive.
17
+
18
+ Output
19
+
20
+ Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 48
27
+
28
+
29
+ Output
30
+
31
+ 9 42
32
+
33
+
34
+ Input
35
+
36
+ 6
37
+
38
+
39
+ Output
40
+
41
+ 6 6
42
+
43
+ Note
44
+
45
+ In the first sample test, there will be 9 blocks if you choose X = 23 or X = 42. Limak wants to maximize X secondarily so you should choose 42.
46
+
47
+ In more detail, after choosing X = 42 the process of building a tower is:
48
+
49
+ * Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42 - 27 = 15.
50
+ * The second added block has side 2, so the remaining volume is 15 - 8 = 7.
51
+ * Finally, Limak adds 7 blocks with side 1, one by one.
52
+
53
+
54
+
55
+ So, there are 9 blocks in the tower. The total volume is is 33 + 23 + 7·13 = 27 + 8 + 7 = 42.
56
+
57
+ ## Contest Information
58
+ - **Contest ID**: 680
59
+ - **Problem Index**: D
60
+ - **Points**: 1250.0
61
+ - **Rating**: 2200
62
+ - **Tags**: binary search, dp, greedy
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-0784/instruction.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 725_C. Hidden Word
2
+
3
+ ## Problem Description
4
+ Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:
5
+
6
+
7
+ ABCDEFGHIJKLM
8
+ NOPQRSTUVWXYZ
9
+
10
+ We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.
11
+
12
+ A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).
13
+
14
+ You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).
15
+
16
+ Input
17
+
18
+ The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.
19
+
20
+ Output
21
+
22
+ Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ ABCDEFGHIJKLMNOPQRSGTUVWXYZ
29
+
30
+
31
+ Output
32
+
33
+ YXWVUTGHIJKLM
34
+ ZABCDEFSRQPON
35
+
36
+
37
+ Input
38
+
39
+ BUVTYZFQSNRIWOXXGJLKACPEMDH
40
+
41
+
42
+ Output
43
+
44
+ Impossible
45
+
46
+ ## Contest Information
47
+ - **Contest ID**: 725
48
+ - **Problem Index**: C
49
+ - **Points**: 1500.0
50
+ - **Rating**: 1600
51
+ - **Tags**: brute force, constructive algorithms, implementation, strings
52
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
53
+ - **Memory Limit**: 256000000 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-0858/instruction.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1406_C. Link Cut Centroids
2
+
3
+ ## Problem Description
4
+ Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles.
5
+
6
+ A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the smallest possible.
7
+
8
+ For example, the centroid of the following tree is 2, because when you cut it, the size of the largest connected component of the remaining graph is 2 and it can't be smaller.
9
+
10
+ <image>
11
+
12
+ However, in some trees, there might be more than one centroid, for example:
13
+
14
+ <image>
15
+
16
+ Both vertex 1 and vertex 2 are centroids because the size of the largest connected component is 3 after cutting each of them.
17
+
18
+ Now Fishing Prince has a tree. He should cut one edge of the tree (it means to remove the edge). After that, he should add one edge. The resulting graph after these two operations should be a tree. He can add the edge that he cut.
19
+
20
+ He wants the centroid of the resulting tree to be unique. Help him and find any possible way to make the operations. It can be proved, that at least one such way always exists.
21
+
22
+ Input
23
+
24
+ The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 10^4) — the number of test cases. The description of the test cases follows.
25
+
26
+ The first line of each test case contains an integer n (3≤ n≤ 10^5) — the number of vertices.
27
+
28
+ Each of the next n-1 lines contains two integers x, y (1≤ x,y≤ n). It means, that there exists an edge connecting vertices x and y.
29
+
30
+ It's guaranteed that the given graph is a tree.
31
+
32
+ It's guaranteed that the sum of n for all test cases does not exceed 10^5.
33
+
34
+ Output
35
+
36
+ For each test case, print two lines.
37
+
38
+ In the first line print two integers x_1, y_1 (1 ≤ x_1, y_1 ≤ n), which means you cut the edge between vertices x_1 and y_1. There should exist edge connecting vertices x_1 and y_1.
39
+
40
+ In the second line print two integers x_2, y_2 (1 ≤ x_2, y_2 ≤ n), which means you add the edge between vertices x_2 and y_2.
41
+
42
+ The graph after these two operations should be a tree.
43
+
44
+ If there are multiple solutions you can print any.
45
+
46
+ Example
47
+
48
+ Input
49
+
50
+
51
+ 2
52
+ 5
53
+ 1 2
54
+ 1 3
55
+ 2 4
56
+ 2 5
57
+ 6
58
+ 1 2
59
+ 1 3
60
+ 1 4
61
+ 2 5
62
+ 2 6
63
+
64
+
65
+ Output
66
+
67
+
68
+ 1 2
69
+ 1 2
70
+ 1 3
71
+ 2 3
72
+
73
+ Note
74
+
75
+ Note that you can add the same edge that you cut.
76
+
77
+ In the first test case, after cutting and adding the same edge, the vertex 2 is still the only centroid.
78
+
79
+ In the second test case, the vertex 2 becomes the only centroid after cutting the edge between vertices 1 and 3 and adding the edge between vertices 2 and 3.
80
+
81
+ ## Contest Information
82
+ - **Contest ID**: 1406
83
+ - **Problem Index**: C
84
+ - **Points**: 1500.0
85
+ - **Rating**: 1700
86
+ - **Tags**: constructive algorithms, dfs and similar, graphs, trees
87
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
88
+ - **Memory Limit**: 512000000 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-0867/instruction.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 221_E. Little Elephant and Shifts
2
+
3
+ ## Problem Description
4
+ The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b — as bj.
5
+
6
+ The distance between permutations a and b is the minimum absolute value of the difference between the positions of the occurrences of some number in a and in b. More formally, it's such minimum |i - j|, that ai = bj.
7
+
8
+ A cyclic shift number i (1 ≤ i ≤ n) of permutation b consisting from n elements is a permutation bibi + 1... bnb1b2... bi - 1. Overall a permutation has n cyclic shifts.
9
+
10
+ The Little Elephant wonders, for all cyclic shifts of permutation b, what is the distance between the cyclic shift and permutation a?
11
+
12
+ Input
13
+
14
+ The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the permutations. The second line contains permutation a as n distinct numbers from 1 to n, inclusive. The numbers are separated with single spaces. The third line contains permutation b in the same format.
15
+
16
+ Output
17
+
18
+ In n lines print n integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation b, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 2
25
+ 1 2
26
+ 2 1
27
+
28
+
29
+ Output
30
+
31
+ 1
32
+ 0
33
+
34
+
35
+ Input
36
+
37
+ 4
38
+ 2 1 3 4
39
+ 3 4 2 1
40
+
41
+
42
+ Output
43
+
44
+ 2
45
+ 1
46
+ 0
47
+ 1
48
+
49
+ ## Contest Information
50
+ - **Contest ID**: 221
51
+ - **Problem Index**: E
52
+ - **Points**: 1500.0
53
+ - **Rating**: 2100
54
+ - **Tags**: data structures
55
+ - **Time Limit**: {'seconds': 2, '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-0922/instruction.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00224 Bicycle Diet
2
+
3
+ ## Problem Description
4
+ Mr. A loves sweets, but recently his wife has told him to go on a diet. One day, when Mr. A went out from his home to the city hall, his wife recommended that he go by bicycle. There, Mr. A reluctantly went out on a bicycle, but Mr. A, who likes sweets, came up with the idea of ​​stopping by a cake shop on the way to eat cake.
5
+
6
+ If you ride a bicycle, calories are consumed according to the mileage, but if you eat cake, you will consume that much calories. The net calories burned is the calories burned on the bike minus the calories burned by eating the cake. Therefore, the net calories burned may be less than zero.
7
+
8
+ If you buy a cake at a cake shop, Mr. A will eat all the cake on the spot. Mr. A does not stop at all cake shops, but when he passes through the point where the cake shop exists, he always stops and buys and eats one cake. However, it's really tempting to pass in front of the same cake shop many times, so each cake shop should only be visited once. In addition, you may stop by the cake shop after passing the destination city hall, and then return to the city hall to finish your work, and you may visit as many times as you like except the cake shop.
9
+
10
+ Enter the map information from Mr. A's home to the city hall, a list of calories of cakes that can be eaten at the cake shop on the way, and the calories burned by traveling a unit distance, from leaving home to entering the city hall. Create a program that outputs the minimum net calories burned.
11
+
12
+ The map shows Mr. A's home and city hall, a cake shop and a landmark building. The input data representing the map contains a line consisting of a symbol representing the two points and the distance between them, when there is a road connecting Mr. A's home, city hall, cake shop and each point of the landmark. For example, if the distance between the 5th cake shop and the 3rd landmark is 10, the input data will contain a line similar to the following:
13
+
14
+
15
+ C5 L3 10
16
+
17
+
18
+ In this way, cake shops are represented by C, and landmarks are represented by L in front of the number. Also, Mr. A's home is represented by H and the city hall is represented by D. If the input data is given two points and the distance between them, advance between the two points in either direction. For example, in the example above, you can go from a cake shop to a landmark and vice versa. In addition, you must be able to reach the city hall from your home. Other input data given are the number of cake shops m, the number of landmarks n, the calories burned per unit distance k, and the cakes that can be bought at each of the first cake shop to the mth cake shop. The total number of m data representing calories and distance data d.
19
+
20
+
21
+
22
+ Input
23
+
24
+ A sequence of multiple datasets is given as input. The end of the input is indicated by four 0 lines. Each dataset is given in the following format:
25
+
26
+
27
+ m n k d
28
+ c1 c2 ... cm
29
+ s1 t1 e1
30
+ s2 t2 e2
31
+ ::
32
+ sd td ed
33
+
34
+
35
+ Number of cake shops m (1 ≤ m ≤ 6), number of landmarks n (1 ≤ n ≤ 100), calories burned per unit distance k (1 ≤ k ≤ 5), distance data on the first line The total number d (5 ≤ d ≤ 256) is given.
36
+
37
+ The second line gives the calories ci (1 ≤ ci ≤ 100) of the cake you buy at each cake shop.
38
+
39
+ The following d line is given the distance data si, ti, ei (1 ≤ ei ≤ 20) between the i-th two points.
40
+
41
+ The number of datasets does not exceed 100.
42
+
43
+ Output
44
+
45
+ Outputs the minimum total calories burned on one line for each input dataset.
46
+
47
+ Example
48
+
49
+ Input
50
+
51
+ 1 1 2 5
52
+ 35
53
+ H L1 5
54
+ C1 D 6
55
+ C1 H 12
56
+ L1 D 10
57
+ C1 L1 20
58
+ 2 1 4 6
59
+ 100 70
60
+ H L1 5
61
+ C1 L1 12
62
+ C1 D 11
63
+ C2 L1 7
64
+ C2 D 15
65
+ L1 D 8
66
+ 0 0 0 0
67
+
68
+
69
+ Output
70
+
71
+ 1
72
+ -2
73
+
74
+ ## Contest Information
75
+ - **Contest ID**: 0
76
+ - **Problem Index**:
77
+ - **Points**: 0.0
78
+ - **Rating**: 0
79
+ - **Tags**:
80
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
81
+ - **Memory Limit**: 134217728 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-0977/instruction.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 341_B. Bubble Sort Graph
2
+
3
+ ## Problem Description
4
+ Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear as described in the following algorithm (pseudocode).
5
+
6
+
7
+
8
+ procedure bubbleSortGraph()
9
+ build a graph G with n vertices and 0 edges
10
+ repeat
11
+ swapped = false
12
+ for i = 1 to n - 1 inclusive do:
13
+ if a[i] > a[i + 1] then
14
+ add an undirected edge in G between a[i] and a[i + 1]
15
+ swap( a[i], a[i + 1] )
16
+ swapped = true
17
+ end if
18
+ end for
19
+ until not swapped
20
+ /* repeat the algorithm as long as swapped value is true. */
21
+ end procedure
22
+
23
+
24
+ For a graph, an independent set is a set of vertices in a graph, no two of which are adjacent (so there are no edges between vertices of an independent set). A maximum independent set is an independent set which has maximum cardinality. Given the permutation, find the size of the maximum independent set of graph G, if we use such permutation as the premutation a in procedure bubbleSortGraph.
25
+
26
+ Input
27
+
28
+ The first line of the input contains an integer n (2 ≤ n ≤ 105). The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n).
29
+
30
+ Output
31
+
32
+ Output a single integer — the answer to the problem.
33
+
34
+ Examples
35
+
36
+ Input
37
+
38
+ 3
39
+ 3 1 2
40
+
41
+
42
+ Output
43
+
44
+ 2
45
+
46
+ Note
47
+
48
+ Consider the first example. Bubble sort swaps elements 3 and 1. We add edge (1, 3). Permutation is now [1, 3, 2]. Then bubble sort swaps elements 3 and 2. We add edge (2, 3). Permutation is now sorted. We have a graph with 3 vertices and 2 edges (1, 3) and (2, 3). Its maximal independent set is [1, 2].
49
+
50
+ ## Contest Information
51
+ - **Contest ID**: 341
52
+ - **Problem Index**: B
53
+ - **Points**: 2000.0
54
+ - **Rating**: 1500
55
+ - **Tags**: binary search, data structures, dp
56
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
57
+ - **Memory Limit**: 256000000 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-0983/instruction.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 480_B. Long Jumps
2
+
3
+ ## Problem Description
4
+ Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
5
+
6
+ However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
7
+
8
+ Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
9
+
10
+ Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
11
+
12
+ Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
13
+
14
+ Input
15
+
16
+ The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
17
+
18
+ The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
19
+
20
+ Output
21
+
22
+ In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
23
+
24
+ In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 3 250 185 230
31
+ 0 185 250
32
+
33
+
34
+ Output
35
+
36
+ 1
37
+ 230
38
+
39
+
40
+ Input
41
+
42
+ 4 250 185 230
43
+ 0 20 185 250
44
+
45
+
46
+ Output
47
+
48
+ 0
49
+
50
+
51
+ Input
52
+
53
+ 2 300 185 230
54
+ 0 300
55
+
56
+
57
+ Output
58
+
59
+ 2
60
+ 185 230
61
+
62
+ Note
63
+
64
+ In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
65
+
66
+ In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
67
+
68
+ In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
69
+
70
+ ## Contest Information
71
+ - **Contest ID**: 480
72
+ - **Problem Index**: B
73
+ - **Points**: 2000.0
74
+ - **Rating**: 1700
75
+ - **Tags**: binary search, greedy, implementation
76
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
77
+ - **Memory Limit**: 256000000 bytes
78
+
79
+ ## Task
80
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1000/instruction.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 878_B. Teams Formation
2
+
3
+ ## Problem Description
4
+ This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
5
+
6
+ Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).
7
+
8
+ After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.
9
+
10
+ Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.
11
+
12
+ Input
13
+
14
+ The first line contains three integers n, k and m (1 ≤ n ≤ 105, 2 ≤ k ≤ 109, 1 ≤ m ≤ 109).
15
+
16
+ The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number of city, person from which must take seat i in the bus.
17
+
18
+ Output
19
+
20
+ Output the number of remaining participants in the line.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 4 2 5
27
+ 1 2 3 1
28
+
29
+
30
+ Output
31
+
32
+ 12
33
+
34
+
35
+ Input
36
+
37
+ 1 9 10
38
+ 1
39
+
40
+
41
+ Output
42
+
43
+ 1
44
+
45
+
46
+ Input
47
+
48
+ 3 2 10
49
+ 1 2 1
50
+
51
+
52
+ Output
53
+
54
+ 0
55
+
56
+ Note
57
+
58
+ In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
59
+
60
+ ## Contest Information
61
+ - **Contest ID**: 878
62
+ - **Problem Index**: B
63
+ - **Points**: 1250.0
64
+ - **Rating**: 2300
65
+ - **Tags**: data structures, implementation
66
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
67
+ - **Memory Limit**: 256000000 bytes
68
+
69
+ ## Task
70
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1006/instruction.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # benny-and-shopping
2
+
3
+ ## Problem Description
4
+ Yesterday, Benny decided to buy something from a television shop. She created a list that consisted of small description of N orders. The description for an order number i is a string Si.
5
+
6
+ The description may consist of uppercase/lowercase Latin letters, digits and a '$' sign. But, every time after the sign '$', Benny has written one integer C. This specific integer C is the price of the items contained in the order and it might have leading zeroes.
7
+
8
+ It's guaranteed that every string contains exactly one '$' character.
9
+
10
+ As, it was rainy yesterday, there are some white spaces present within the description of each order. Therefore, the digits might be separated by some amount of spaces.
11
+
12
+ Your task is to determine the price of each order and print it without leading zeroes.
13
+
14
+ Input format
15
+
16
+ The first line contains a single integer N denoting the number of orders.
17
+
18
+ The next N lines contain a strings Si denoting the description for each i^th order.
19
+
20
+ Output format
21
+
22
+ Print the cost to each of the order in a single line .
23
+
24
+ Constraints
25
+ 1 ≤ N ≤ 500
26
+ 2 ≤ |Si| ≤ 1000
27
+
28
+ SAMPLE INPUT
29
+ 4
30
+ I want to buy Microsoft for $10000
31
+ this house costs $0 5 0 00 0 Just buy it
32
+ siejfsuhn $ 1 2 3 4 5 6 7 8 9 hello123
33
+ the cost is zero $ 0 0 0 0 0 0
34
+
35
+ SAMPLE OUTPUT
36
+ $10000
37
+ $50000
38
+ $123456789
39
+ $0
40
+
41
+ Explanation
42
+ In the first sample test case, it is clear from the order description that the amount is 10000$
43
+ In the second test case, you have to ignore a leading zero and delete spaces between the digits. So, the answer is $50000.
44
+ The third test case is similar to the second one.
45
+ And the fourth test case has the cost equal to $0 but with many leading zeroes. Hence, to show that the order was free, it is necessary to print a single 0.
46
+
47
+ ## Contest Information
48
+ - **Contest ID**: 0
49
+ - **Problem Index**:
50
+ - **Points**: 0.0
51
+ - **Rating**: 0
52
+ - **Tags**: None
53
+ - **Time Limit**: None seconds
54
+ - **Memory Limit**: 0 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-1008/instruction.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # fight-for-chocolate
2
+
3
+ ## Problem Description
4
+ Tapan and Divya have a rectangular shaped chocolate bar with chocolates labeled T, D and U. They want to split the bar into exactly two pieces such that:
5
+
6
+ Tapan's piece can not contain any chocolate labeled D and similarly, Divya's piece can not contain any chocolate labeled T. All chocolates in each piece must be connected (two chocolates are connected if they share an edge), i.e. the chocolates should form one connected component.
7
+
8
+ The absolute difference between the number of chocolates in pieces should be at most K.
9
+
10
+ In any piece, there should not be 4 adjacent chocolates that form a square, i.e. there should not be a fragment like this:
11
+
12
+ XX
13
+ XX
14
+
15
+ Input Format
16
+
17
+ The first line of the input contains 3 integers M, N and K separated by a single space.
18
+ M lines follow, each of which contains N characters. Each character is 'T','D' or 'U'.
19
+
20
+ Constraints
21
+
22
+ 0≤ M, N ≤8
23
+ 0≤ K ≤ M * N
24
+
25
+ Output Format
26
+
27
+ A single line containing the number of ways to divide the chocolate bar.
28
+
29
+ SAMPLE INPUT
30
+ 2 2 4
31
+ UU
32
+ UU
33
+
34
+ SAMPLE OUTPUT
35
+ 12
36
+
37
+ Explanation
38
+
39
+ There are 24 = 16 possible separations. The 4 invalid are:
40
+
41
+ TT
42
+
43
+ TT
44
+ DD
45
+
46
+ DD
47
+ DT
48
+
49
+ TD
50
+ TD
51
+
52
+ DT
53
+
54
+ Some of the valid ones are:
55
+
56
+ TD
57
+
58
+ TD
59
+ TT
60
+
61
+ DD
62
+ DD
63
+
64
+ TT
65
+ DT
66
+
67
+ DT
68
+
69
+ ## Contest Information
70
+ - **Contest ID**: 0
71
+ - **Problem Index**:
72
+ - **Points**: 0.0
73
+ - **Rating**: 0
74
+ - **Tags**: None
75
+ - **Time Limit**: None seconds
76
+ - **Memory Limit**: 0 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-10140/instruction.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 331_C3. The Great Julya Calendar
2
+
3
+ ## Problem Description
4
+ Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
5
+
6
+ The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
7
+
8
+ "May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"
9
+
10
+ Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.
11
+
12
+ Input
13
+
14
+ The single line contains the magic integer n, 0 ≤ n.
15
+
16
+ * to get 20 points, you need to solve the problem with constraints: n ≤ 106 (subproblem C1);
17
+ * to get 40 points, you need to solve the problem with constraints: n ≤ 1012 (subproblems C1+C2);
18
+ * to get 100 points, you need to solve the problem with constraints: n ≤ 1018 (subproblems C1+C2+C3).
19
+
20
+ Output
21
+
22
+ Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 24
29
+
30
+
31
+ Output
32
+
33
+ 5
34
+
35
+ Note
36
+
37
+ In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
38
+
39
+ 24 → 20 → 18 → 10 → 9 → 0
40
+
41
+ ## Contest Information
42
+ - **Contest ID**: 331
43
+ - **Problem Index**: C3
44
+ - **Points**: 60.0
45
+ - **Rating**: 2500
46
+ - **Tags**: dp
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-10149/instruction.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 544_C. Writing Code
2
+
3
+ ## Problem Description
4
+ Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.
5
+
6
+ Let's call a sequence of non-negative integers v1, v2, ..., vn a plan, if v1 + v2 + ... + vn = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v1 lines of the given task, then the second programmer writes v2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let's call a plan good, if all the written lines of the task contain at most b bugs in total.
7
+
8
+ Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer mod.
9
+
10
+ Input
11
+
12
+ The first line contains four integers n, m, b, mod (1 ≤ n, m ≤ 500, 0 ≤ b ≤ 500; 1 ≤ mod ≤ 109 + 7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer.
13
+
14
+ The next line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of bugs per line for each programmer.
15
+
16
+ Output
17
+
18
+ Print a single integer — the answer to the problem modulo mod.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 3 3 3 100
25
+ 1 1 1
26
+
27
+
28
+ Output
29
+
30
+ 10
31
+
32
+
33
+ Input
34
+
35
+ 3 6 5 1000000007
36
+ 1 2 3
37
+
38
+
39
+ Output
40
+
41
+ 0
42
+
43
+
44
+ Input
45
+
46
+ 3 5 6 11
47
+ 1 2 1
48
+
49
+
50
+ Output
51
+
52
+ 0
53
+
54
+ ## Contest Information
55
+ - **Contest ID**: 544
56
+ - **Problem Index**: C
57
+ - **Points**: 500.0
58
+ - **Rating**: 1800
59
+ - **Tags**: dp
60
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
61
+ - **Memory Limit**: 256000000 bytes
62
+
63
+ ## Task
64
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10170/instruction.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # chandler-and-joey
2
+
3
+ ## Problem Description
4
+ Chandler and Joey
5
+
6
+ Joey and Chandler got bored of playing foosball, so they thought of trying something new.As Joey is very intelligent so he invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Joey or Chandler (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x-y|. Then this player adds integer |x-y| to the set and gets |x-y| points.
7
+ If the current player has no valid move, he loses the game. The question is who will finally win the game if both players play optimally. Remember that as Joey invented the game so he always moves first.
8
+
9
+ Input
10
+ The first line contains an integer t - the number of test cases,For each test case First line contains an integer n — the initial number of elements in the set. The second line contains n distinct space-separated integers a1,a2,...,an — the elements of the set.
11
+ Constraints:
12
+
13
+ t ≤ 10
14
+ 2 ≤ n ≤ 100
15
+ 1 ≤ ai ≤ 10^9
16
+
17
+ Output:
18
+
19
+ Print a single line with the winner's name and the total sum of points of both players. If Joey wins print "Joey"(without quotes) and total points separated by space, otherwise print "Chandler"(without quotes) and total points separated by space.
20
+
21
+ SAMPLE INPUT
22
+ 2
23
+ 2
24
+ 1 2
25
+ 2
26
+ 5 3
27
+
28
+ SAMPLE OUTPUT
29
+ Chandler 0
30
+ Joey 7
31
+
32
+ Explanation
33
+
34
+ Test Case 1:
35
+ Joey can not make a starting move so Chandler wins the game.Both players have no points.
36
+
37
+ Test Case 2:
38
+ Joey can get 2 points and 2 will be added to set so new set will be 5 3 2
39
+ Chandler can get 1 point and 1 will be added to set so new set will be 5 3 2 1
40
+ joey can get 4 points and 4 will be added to set so new set will be 5 3 2 1 4
41
+ Then there is no Possible move so Joey wins the game and total points of both players are 2+1+4=7 points
42
+
43
+ ## Contest Information
44
+ - **Contest ID**: 0
45
+ - **Problem Index**:
46
+ - **Points**: 0.0
47
+ - **Rating**: 0
48
+ - **Tags**: None
49
+ - **Time Limit**: None seconds
50
+ - **Memory Limit**: 0 bytes
51
+
52
+ ## Task
53
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10184/instruction.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03292 AtCoder Beginner Contest 103 - Task Scheduling Problem
2
+
3
+ ## Problem Description
4
+ You have three tasks, all of which need to be completed.
5
+
6
+ First, you can complete any one task at cost 0.
7
+
8
+ Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.
9
+
10
+ Here, |x| denotes the absolute value of x.
11
+
12
+ Find the minimum total cost required to complete all the task.
13
+
14
+ Constraints
15
+
16
+ * All values in input are integers.
17
+ * 1 \leq A_1, A_2, A_3 \leq 100
18
+
19
+ Input
20
+
21
+ Input is given from Standard Input in the following format:
22
+
23
+
24
+ A_1 A_2 A_3
25
+
26
+
27
+ Output
28
+
29
+ Print the minimum total cost required to complete all the task.
30
+
31
+ Examples
32
+
33
+ Input
34
+
35
+ 1 6 3
36
+
37
+
38
+ Output
39
+
40
+ 5
41
+
42
+
43
+ Input
44
+
45
+ 11 5 5
46
+
47
+
48
+ Output
49
+
50
+ 6
51
+
52
+
53
+ Input
54
+
55
+ 100 100 100
56
+
57
+
58
+ Output
59
+
60
+ 0
61
+
62
+ ## Contest Information
63
+ - **Contest ID**: 0
64
+ - **Problem Index**:
65
+ - **Points**: 0.0
66
+ - **Rating**: 0
67
+ - **Tags**:
68
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
69
+ - **Memory Limit**: 1073741824 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-10200/instruction.md ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01689 Dowsing Machine
2
+
3
+ ## Problem Description
4
+ C --Dowsing Machine
5
+
6
+ Story
7
+
8
+ People make noise with X and Y, but the coming era will be "D". "Paklin Monster D" is a very popular game in which "D people" search for treasure using the "D machine" developed by the secret society "R team".
9
+
10
+ In this game, the person D in the square with the grid map repeatedly moves to the adjacent squares up, down, left, and right, aiming to reach the square where the treasure exists. There is only one square on the map where the treasure exists. Since the square where the treasure exists has not been clarified, I would like to use the D machine to narrow down the squares where the treasure exists and then move to the square where the treasure exists.
11
+
12
+ When using the D machine, it shows the reaction to multiple squares including the square where the treasure exists. The reaction is expressed based on the square where the D person was when using the D machine. However, the D-machine can be broken, and when using the D-machine, it may react to squares where treasure cannot exist. Also, since there is a wall square on the map that D person cannot move, it may not be possible to move to the square where the treasure exists. Person D used the D machine in various squares and observed the reaction. Can the person of D reach the square where the treasure exists?
13
+
14
+ Problem
15
+
16
+ Consider a two-dimensional lattice with height h and width w. A cell t_ {i, j} is represented by one of the following characters:
17
+
18
+ * ".": Indicates that it is passable. There may be treasure in this square.
19
+ * "#": Indicates that there is a wall and it is impassable. There are no treasures in this square.
20
+ * "D": It means that it is passable and there is a person of D. There may be treasure in this square.
21
+
22
+
23
+
24
+ Person D can move to a passable square adjacent to the top, bottom, left, and right.
25
+
26
+ The D-machine shows the reaction to any mass set in the two-dimensional lattice as shown in the figure, depending on the position used. Each rectangle in the figure below is a square with radii r_1, r_2, ..., r_d. A square radius of r_k means that the length of one side of the square is 2 r_k + 1.
27
+
28
+ fig1.png
29
+
30
+
31
+ Let s be the reaction shown when using the D machine at (x, y). When 1 \ leq s \ leq d-1, the treasure exists in the square included in the figure excluding the square with radius r_s + 1 from the square with radius r_ {s + 1} centered on (x, y). Represents that. When s = 0, it means that the treasure exists in the square included in the square with radius r_1 centered on (x, y). When s = d, it means that the treasure exists in the square outside the square with radius r_d centered on (x, y). There is always only one square with treasure. However, if the D machine is broken, the D machine reacts inconsistently to this.
32
+
33
+ Multiple reactions shown by the use of the D machine are given. "Broken" if the D machine is definitely broken, "Yes" if you can always reach the square where the treasure exists from the position where the D person is, "No" if you can never reach it, I do not know if you can reach it If so, output "Unknown".
34
+
35
+ Input
36
+
37
+ Input can be given in the following format.
38
+
39
+
40
+ h w d n
41
+ t_ {0,0} t_ {0,1} ... t_ {0, w-1}
42
+ ...
43
+ t_ {h-1,0} t_ {h-1,1} ... t_ {h-1, w-1}
44
+ r_1 r_2 ... r_d
45
+ x_1 y_1 s_1
46
+ ...
47
+ x_n y_n s_n
48
+
49
+ The first line consists of four integers, each of which has a vertical width h, a horizontal width w, the number of squares d, and the number of times n using the D machine, separated by one blank character. In the following h line, the character of each cell is given. The character t_ {i, j} at the j + 1th (0 \ leq j <w) on the second line (0 \ leq i <h) of i + represents the character of the square (j, i). In the h + 2nd line, the radius r_k (1 \ leq k \ leq d) of each square is given by one space delimiter. The next n lines give the reaction of the D machine. In line l + h + 3 (1 \ leq l \ leq n), x_l, y_l, s_l are given with one space delimiter, and the reaction s_l is shown when using the D machine in the mass (x_l, y_l) Indicates that it was done.
50
+
51
+ Constraint
52
+
53
+ * 1 \ leq h \ leq 50, 1 \ leq w \ leq 50, 1 \ leq d \ leq 10, 1 \ leq n \ leq 50
54
+ * t_ {i, j} is one of "#", ".", "D", and there is always only one letter "D"
55
+ * 0 \ leq r_k \ leq 50, and for k> 1, r_ {k-1} <r_k
56
+ * 0 \ leq x_l <w, 0 \ leq y_l <h, 0 \ leq s_l \ leq d
57
+ * You can reach the square (x_l, y_l) by repeating the movement from the square represented by the letter "D".
58
+
59
+
60
+
61
+ Output
62
+
63
+ Output the appropriate one of "Broken", "Yes", "No", and "Unknown" on one line. Be sure to start a new line at the end of the line.
64
+
65
+ Sample Input 1
66
+
67
+
68
+ 6 10 3 4
69
+
70
+ ........ #
71
+ ... D .... #
72
+ ........ #
73
+ ........ #
74
+
75
+ 2 4 6
76
+ 3 2 0
77
+ 7 4 2
78
+ 8 4 3
79
+ 1 4 1
80
+
81
+ Sample Output 1
82
+
83
+
84
+ Yes
85
+
86
+ Sample Input 2
87
+
88
+
89
+ 6 10 2 3
90
+
91
+ . # ...... #
92
+ ...... #
93
+ ...... D. #
94
+ ........ #
95
+
96
+ 1 2
97
+ 3 2 1
98
+ 3 1 1
99
+ 1 3 1
100
+
101
+ Sample Output 2
102
+
103
+
104
+ No
105
+
106
+ Sample Input 3
107
+
108
+
109
+ 6 10 3 1
110
+
111
+ ........ #
112
+ ... D .... #
113
+ ........ #
114
+ ........ #
115
+
116
+ 2 4 6
117
+ 3 4 3
118
+
119
+ Sample Output 3
120
+
121
+
122
+ Broken
123
+
124
+ Sample Input 4
125
+
126
+
127
+ 6 10 3 3
128
+
129
+ . # ...... #
130
+ .D .... #
131
+ . # ...... #
132
+ ........ #
133
+
134
+ 2 4 6
135
+ 3 2 0
136
+ 7 4 2
137
+ 8 4 3
138
+
139
+ Sample Output 4
140
+
141
+
142
+ Unknown
143
+
144
+
145
+
146
+
147
+
148
+ Example
149
+
150
+ Input
151
+
152
+ 6 10 3 4
153
+ ##########
154
+ #........#
155
+ #...D....#
156
+ #........#
157
+ #........#
158
+ ##########
159
+ 2 4 6
160
+ 3 2 0
161
+ 7 4 2
162
+ 8 4 3
163
+ 1 4 1
164
+
165
+
166
+ Output
167
+
168
+ Yes
169
+
170
+ ## Contest Information
171
+ - **Contest ID**: 0
172
+ - **Problem Index**:
173
+ - **Points**: 0.0
174
+ - **Rating**: 0
175
+ - **Tags**:
176
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
177
+ - **Memory Limit**: 536870912 bytes
178
+
179
+ ## Task
180
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1030/instruction.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00736 How can I satisfy thee? Let me count the ways...
2
+
3
+ ## Problem Description
4
+ Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "true" are represented by 0, 1 and 2 respectively.
5
+
6
+ Let "-" be a unary operator (i.e. a symbol representing one argument function) and let both "*" and "+" be binary operators (i.e. symbols representing two argument functions). These operators represent negation (NOT), conjunction (AND) and disjunction (OR) respectively. These operators in three-valued logic can be defined in Table C-1.
7
+
8
+ Table C-1: Truth tables of three-valued logic operators
9
+ -X| | (X*Y)| | (X+Y) | <image>| | <image>| | <image> |
10
+ ---|---|---|---|---|---
11
+
12
+ Let P, Q and R be variables ranging over three-valued logic values. For a given formula, you are asked to answer the number of triples (P,Q,R) that satisfy the formula, that is, those which make the value of the given formula 2. A formula is one of the following form (X and Y represent formulas).
13
+
14
+ * Constants: 0, 1 or 2
15
+ * Variables: P, Q or R
16
+ * Negations: -X
17
+ * Conjunctions: (X*Y)
18
+ * Disjunctions: (X+Y)
19
+
20
+
21
+ Note that conjunctions and disjunctions of two formulas are always parenthesized.
22
+
23
+ For example, when formula (P*Q) is given as an input, the value of this formula is 2 when and only when (P,Q,R) is (2,2,0), (2,2,1) or (2,2,2). Therefore, you should output 3.
24
+
25
+ Input
26
+
27
+ The input consists of one or more lines. Each line contains a formula. A formula is a string which consists of 0, 1, 2, P, Q, R, -, *, +, (, ). Other characters such as spaces are not contained. The grammar of formulas is given by the following BNF.
28
+
29
+
30
+ <formula> ::= 0 | 1 | 2 | P | Q | R |
31
+ -<formula> | (<formula>*<formula>) | (<formula>+<formula>)
32
+
33
+
34
+ All the formulas obey this syntax and thus you do not have to care about grammatical errors. Input lines never exceed 80 characters.
35
+
36
+ Finally, a line which contains only a "." (period) comes, indicating the end of the input.
37
+
38
+ Output
39
+
40
+ You should answer the number (in decimal) of triples (P,Q,R) that make the value of the given formula 2. One line containing the number should be output for each of the formulas, and no other characters should be output.
41
+
42
+ Sample Input
43
+
44
+
45
+ (P*Q)
46
+ (--R+(P*Q))
47
+ (P*-P)
48
+ 2
49
+ 1
50
+ (-1+(((---P+Q)*(--Q+---R))*(-R+-P)))
51
+ .
52
+
53
+
54
+ Output for the Sample Input
55
+
56
+
57
+ 3
58
+ 11
59
+ 0
60
+ 27
61
+ 0
62
+ 7
63
+
64
+
65
+
66
+
67
+
68
+
69
+ Example
70
+
71
+ Input
72
+
73
+ (P*Q)
74
+ (--R+(P*Q))
75
+ (P*-P)
76
+ 2
77
+ 1
78
+ (-1+(((---P+Q)*(--Q+---R))*(-R+-P)))
79
+ .
80
+
81
+
82
+ Output
83
+
84
+ 3
85
+ 11
86
+ 0
87
+ 27
88
+ 0
89
+ 7
90
+
91
+ ## Contest Information
92
+ - **Contest ID**: 0
93
+ - **Problem Index**:
94
+ - **Points**: 0.0
95
+ - **Rating**: 0
96
+ - **Tags**:
97
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
98
+ - **Memory Limit**: 134217728 bytes
99
+
100
+ ## Task
101
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10310/instruction.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # and
2
+
3
+ ## Problem Description
4
+ You are given a sequence of N integer numbers A. Calculate the sum of Ai AND Aj for all the pairs (i, j) where i < j.
5
+ The AND operation is the Bitwise AND operation, defined as in here.
6
+
7
+ Input
8
+ The first line of input consists of the integer N.
9
+ The second line contains N integer numbers - the sequence A.
10
+
11
+ Output
12
+ Output the answer to the problem on the first line of the output.
13
+
14
+ Example
15
+ Input:
16
+ 5
17
+ 1 2 3 4 5
18
+
19
+ Output:
20
+ 9
21
+
22
+
23
+ Scoring
24
+
25
+ Subtask 1 (13 points): N <= 1000, Ai <= 1.
26
+ Subtask 2 (39 points): N <= 1000, Ai <= 10^9.
27
+ Subtask 3 (21 points): N <= 10^5, Ai <= 1.
28
+ Subtask 4 (27 points): N <= 10^5, Ai <= 10^6.
29
+
30
+ ## Contest Information
31
+ - **Contest ID**: 0
32
+ - **Problem Index**:
33
+ - **Points**: 0.0
34
+ - **Rating**: 0
35
+ - **Tags**: None
36
+ - **Time Limit**: None seconds
37
+ - **Memory Limit**: 0 bytes
38
+
39
+ ## Task
40
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10342/instruction.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17_B. Hierarchy
2
+
3
+ ## Problem Description
4
+ Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
5
+
6
+ Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
7
+
8
+ Input
9
+
10
+ The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
11
+
12
+ Output
13
+
14
+ Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ 4
21
+ 7 2 3 1
22
+ 4
23
+ 1 2 5
24
+ 2 4 1
25
+ 3 4 1
26
+ 1 3 5
27
+
28
+
29
+ Output
30
+
31
+ 11
32
+
33
+
34
+ Input
35
+
36
+ 3
37
+ 1 2 3
38
+ 2
39
+ 3 1 2
40
+ 3 1 3
41
+
42
+
43
+ Output
44
+
45
+ -1
46
+
47
+ Note
48
+
49
+ In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
50
+
51
+ ## Contest Information
52
+ - **Contest ID**: 17
53
+ - **Problem Index**: B
54
+ - **Points**: 0.0
55
+ - **Rating**: 1500
56
+ - **Tags**: dfs and similar, dsu, greedy, shortest paths
57
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
58
+ - **Memory Limit**: 64000000 bytes
59
+
60
+ ## Task
61
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10345/instruction.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 250_E. Mad Joe
2
+
3
+ ## Problem Description
4
+ Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path.
5
+
6
+ Joe's house has n floors, each floor is a segment of m cells. Each cell either contains nothing (it is an empty cell), or has a brick or a concrete wall (always something one of three). It is believed that each floor is surrounded by a concrete wall on the left and on the right.
7
+
8
+ Now Joe is on the n-th floor and in the first cell, counting from left to right. At each moment of time, Joe has the direction of his gaze, to the right or to the left (always one direction of the two). Initially, Joe looks to the right.
9
+
10
+ Joe moves by a particular algorithm. Every second he makes one of the following actions:
11
+
12
+ * If the cell directly under Joe is empty, then Joe falls down. That is, he moves to this cell, the gaze direction is preserved.
13
+ * Otherwise consider the next cell in the current direction of the gaze.
14
+ * If the cell is empty, then Joe moves into it, the gaze direction is preserved.
15
+ * If this cell has bricks, then Joe breaks them with his forehead (the cell becomes empty), and changes the direction of his gaze to the opposite.
16
+ * If this cell has a concrete wall, then Joe just changes the direction of his gaze to the opposite (concrete can withstand any number of forehead hits).
17
+
18
+
19
+
20
+ Joe calms down as soon as he reaches any cell of the first floor.
21
+
22
+ The figure below shows an example Joe's movements around the house.
23
+
24
+ <image>
25
+
26
+ Determine how many seconds Joe will need to calm down.
27
+
28
+ Input
29
+
30
+ The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 104).
31
+
32
+ Next n lines contain the description of Joe's house. The i-th of these lines contains the description of the (n - i + 1)-th floor of the house — a line that consists of m characters: "." means an empty cell, "+" means bricks and "#" means a concrete wall.
33
+
34
+ It is guaranteed that the first cell of the n-th floor is empty.
35
+
36
+ Output
37
+
38
+ Print a single number — the number of seconds Joe needs to reach the first floor; or else, print word "Never" (without the quotes), if it can never happen.
39
+
40
+ Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
41
+
42
+ Examples
43
+
44
+ Input
45
+
46
+ 3 5
47
+ ..+.#
48
+ #+..+
49
+ +.#+.
50
+
51
+
52
+ Output
53
+
54
+ 14
55
+
56
+ Input
57
+
58
+ 4 10
59
+ ...+.##+.+
60
+ +#++..+++#
61
+ ++.#++++..
62
+ .+##.++#.+
63
+
64
+
65
+ Output
66
+
67
+ 42
68
+
69
+
70
+ Input
71
+
72
+ 2 2
73
+ ..
74
+ ++
75
+
76
+
77
+ Output
78
+
79
+ Never
80
+
81
+ ## Contest Information
82
+ - **Contest ID**: 250
83
+ - **Problem Index**: E
84
+ - **Points**: 2000.0
85
+ - **Rating**: 2000
86
+ - **Tags**: brute force
87
+ - **Time Limit**: {'seconds': 1, '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-1037/instruction.md ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01754 Dinner
2
+
3
+ ## Problem Description
4
+ In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
5
+
6
+ He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
7
+
8
+ His dinner options are two, either head to a nearby dining room or cook for himself.
9
+
10
+ The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
11
+
12
+ The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
13
+
14
+ Find the maximum sum of happiness for him.
15
+
16
+ Constraints
17
+
18
+ * 1 ≤ N ≤ 500,000
19
+ * 0 ≤ P ≤ 500,000
20
+ * | Q | ≤ 500,000
21
+ * | Ci | ≤ 500,000
22
+
23
+ Input
24
+
25
+ The input is given in the following format as N + 1 line.
26
+
27
+
28
+ N P Q
29
+ C1
30
+ C2
31
+ ::
32
+ CN
33
+
34
+
35
+ * The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
36
+ * From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
37
+
38
+ Output
39
+
40
+ Output the maximum value of happiness that can be taken in one line.
41
+
42
+ Examples
43
+
44
+ Input
45
+
46
+ 1 1 1
47
+ 2
48
+
49
+
50
+ Output
51
+
52
+ 2
53
+
54
+
55
+ Input
56
+
57
+ 3 2 1
58
+ 3
59
+ 3
60
+ 3
61
+
62
+
63
+ Output
64
+
65
+ 12
66
+
67
+
68
+ Input
69
+
70
+ 3 1 -1
71
+ 2
72
+ -3
73
+ 2
74
+
75
+
76
+ Output
77
+
78
+ 2
79
+
80
+
81
+ Input
82
+
83
+ 3 1 -10
84
+ -10
85
+ -10
86
+ -10
87
+
88
+
89
+ Output
90
+
91
+ -27
92
+
93
+ ## Contest Information
94
+ - **Contest ID**: 0
95
+ - **Problem Index**:
96
+ - **Points**: 0.0
97
+ - **Rating**: 0
98
+ - **Tags**:
99
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
100
+ - **Memory Limit**: 134217728 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-10372/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 884_C. Bertown Subway
2
+
3
+ ## Problem Description
4
+ The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
5
+
6
+ There are n stations in the subway. It was built according to the Bertown Transport Law:
7
+
8
+ 1. For each station i there exists exactly one train that goes from this station. Its destination station is pi, possibly pi = i;
9
+ 2. For each station i there exists exactly one station j such that pj = i.
10
+
11
+
12
+
13
+ The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (x, y) such that person can start at station x and, after taking some subway trains (possibly zero), arrive at station y (1 ≤ x, y ≤ n).
14
+
15
+ The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of pi for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes.
16
+
17
+ The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get!
18
+
19
+ Input
20
+
21
+ The first line contains one integer number n (1 ≤ n ≤ 100000) — the number of stations.
22
+
23
+ The second line contains n integer numbers p1, p2, ..., pn (1 ≤ pi ≤ n) — the current structure of the subway. All these numbers are distinct.
24
+
25
+ Output
26
+
27
+ Print one number — the maximum possible value of convenience.
28
+
29
+ Examples
30
+
31
+ Input
32
+
33
+ 3
34
+ 2 1 3
35
+
36
+
37
+ Output
38
+
39
+ 9
40
+
41
+
42
+ Input
43
+
44
+ 5
45
+ 1 5 4 3 2
46
+
47
+
48
+ Output
49
+
50
+ 17
51
+
52
+ Note
53
+
54
+ In the first example the mayor can change p2 to 3 and p3 to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3).
55
+
56
+ In the second example the mayor can change p2 to 4 and p3 to 5.
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 884
60
+ - **Problem Index**: C
61
+ - **Points**: 0.0
62
+ - **Rating**: 1500
63
+ - **Tags**: dfs and similar, greedy, math
64
+ - **Time Limit**: {'seconds': 1, '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-10381/instruction.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # john-and-hesa
2
+
3
+ ## Problem Description
4
+ John is very good in shooting. We wants to get admitted in HackerEarth Shooting Academy (HESA). But HESA take very hard interview process to select the candidates. In the Interview process, an assignment is given to John.
5
+
6
+ In this assignment, some amount X will be given to John. There are some targets to shoot and to fire a bullet there is some cost P is associated. When John will fire a bullet, P amount will be divided from its amount X.
7
+
8
+ NOTE: The amount will be divided if and only if P completely divides X.
9
+
10
+ At last, John will have to tell, On now many targets he shoot i.e. N and as well as remaining amount of the John. Help John to get selected in HESA.
11
+
12
+ INPUT:
13
+
14
+ First line contains number of test cases T.
15
+
16
+ For each test case, a single line represents two space separated integers X and P.
17
+
18
+ OUTPUT:
19
+
20
+ For each test case, print the value of N.
21
+
22
+ Constraints:
23
+
24
+ 1 ≤ T ≤ 10
25
+
26
+ 1 ≤ X , P ≤ 100000
27
+
28
+ SAMPLE INPUT
29
+ 1
30
+ 4 2
31
+
32
+ SAMPLE OUTPUT
33
+ 2 0
34
+
35
+ ## Contest Information
36
+ - **Contest ID**: 0
37
+ - **Problem Index**:
38
+ - **Points**: 0.0
39
+ - **Rating**: 0
40
+ - **Tags**: None
41
+ - **Time Limit**: None seconds
42
+ - **Memory Limit**: 0 bytes
43
+
44
+ ## Task
45
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10386/instruction.md ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # tom-in-gym
2
+
3
+ ## Problem Description
4
+ The Tom has become health conscious and is now lifting weights at the gym. But its his first time so the trainer gives him a simple job to do.
5
+
6
+ He has been given a weight lifting rod and N heavy weights, each weighing 2^0, 2^1, .... , 2^n-1. He has to stick each of the "N" weights on the rod, one after another, in such a way that the right side is never heavier than the left side. At each step he chooses one of the weights that has not yet been fixed on the rod, and fix it on either the left side of the rod or the right, until all of the weights have been placed. Now help the Tom and find out, in how many ways the Tom can accomplish this?
7
+
8
+ Input
9
+
10
+ First line of input contains an integer T, the number of test cases. Then T test cases follow. Each line of test case contains one integer, N denoting the number of weights
11
+
12
+ Output
13
+
14
+ The output contains T lines, each containing an integer denoting all possible combinations.
15
+
16
+ SAMPLE INPUT
17
+ 4
18
+ 2
19
+ 5
20
+ 4
21
+ 7
22
+
23
+ SAMPLE OUTPUT
24
+ 3
25
+ 945
26
+ 105
27
+ 135135
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-1039/instruction.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02031 Parentheses Number
2
+
3
+ ## Problem Description
4
+ B: Parentheses Number
5
+
6
+ problem
7
+
8
+ Define the correct parenthesis string as follows:
9
+
10
+ * The empty string is the correct parenthesis string
11
+ * For the correct parenthesis string S, `(` S `)` is the correct parenthesis string
12
+ * For correct parentheses S, T ST is the correct parentheses
13
+
14
+
15
+
16
+ Here, the permutations are associated with the correct parentheses according to the following rules.
17
+
18
+ * When the i-th closing brace corresponds to the j-th opening brace, the i-th value in the sequence is j.
19
+
20
+
21
+
22
+ Given a permutation of length n, P = (p_1, p_2, $ \ ldots $, p_n), restore the corresponding parenthesis string.
23
+
24
+ However, if the parenthesis string corresponding to the permutation does not exist, output `: (`.
25
+
26
+ Input format
27
+
28
+
29
+ n
30
+ p_1 p_2 $ \ ldots $ p_n
31
+
32
+
33
+ The number of permutations n is given in the first row.
34
+
35
+ Permutations p_1, p_2, $ \ ldots $, p_i, $ \ ldots $, p_n are given in the second row, separated by blanks.
36
+
37
+ Constraint
38
+
39
+ * 1 \ leq n \ leq 10 ^ 5
40
+ * 1 \ leq p_i \ leq n
41
+ * All inputs are integers.
42
+ * P = (p_1, p_2, $ \ ldots $, p_n) is a permutation.
43
+
44
+
45
+
46
+ Output format
47
+
48
+ Output the parenthesized string corresponding to the permutation.
49
+
50
+ Print `: (` if such a parenthesis string does not exist.
51
+
52
+ Input example 1
53
+
54
+
55
+ 2
56
+ twenty one
57
+
58
+
59
+ Output example 1
60
+
61
+
62
+ (())
63
+
64
+ Input example 2
65
+
66
+
67
+ Ten
68
+ 1 2 3 4 5 6 7 8 9 10
69
+
70
+
71
+ Output example 2
72
+
73
+
74
+ () () () () () () () () () ()
75
+
76
+ Input example 3
77
+
78
+
79
+ 3
80
+ 3 1 2
81
+
82
+
83
+ Output example 3
84
+
85
+
86
+ :(
87
+
88
+
89
+
90
+
91
+
92
+ Example
93
+
94
+ Input
95
+
96
+ 2
97
+ 2 1
98
+
99
+
100
+ Output
101
+
102
+ (())
103
+
104
+ ## Contest Information
105
+ - **Contest ID**: 0
106
+ - **Problem Index**:
107
+ - **Points**: 0.0
108
+ - **Rating**: 0
109
+ - **Tags**:
110
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
111
+ - **Memory Limit**: 268435456 bytes
112
+
113
+ ## Task
114
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.