EtashGuha commited on
Commit
e3941b2
·
verified ·
1 Parent(s): c68dece

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-0117/instruction.md +80 -0
  2. code_contests-0172/instruction.md +53 -0
  3. code_contests-0325/instruction.md +63 -0
  4. code_contests-0516/instruction.md +141 -0
  5. code_contests-0573/instruction.md +45 -0
  6. code_contests-0587/instruction.md +99 -0
  7. code_contests-0724/instruction.md +141 -0
  8. code_contests-0741/instruction.md +55 -0
  9. code_contests-0914/instruction.md +79 -0
  10. code_contests-1009/instruction.md +52 -0
  11. code_contests-10124/instruction.md +74 -0
  12. code_contests-10141/instruction.md +57 -0
  13. code_contests-1031/instruction.md +75 -0
  14. code_contests-10373/instruction.md +73 -0
  15. code_contests-10387/instruction.md +83 -0
  16. code_contests-10540/instruction.md +71 -0
  17. code_contests-10717/instruction.md +53 -0
  18. code_contests-10772/instruction.md +95 -0
  19. code_contests-10918/instruction.md +83 -0
  20. code_contests-10942/instruction.md +48 -0
  21. code_contests-10989/instruction.md +79 -0
  22. code_contests-11058/instruction.md +71 -0
  23. code_contests-11067/instruction.md +40 -0
  24. code_contests-11230/instruction.md +52 -0
  25. code_contests-11459/instruction.md +40 -0
  26. code_contests-11492/instruction.md +82 -0
  27. code_contests-11609/instruction.md +74 -0
  28. code_contests-11801/instruction.md +114 -0
  29. code_contests-11864/instruction.md +64 -0
  30. code_contests-12025/instruction.md +65 -0
  31. code_contests-1203/instruction.md +50 -0
  32. code_contests-12040/instruction.md +76 -0
  33. code_contests-12217/instruction.md +55 -0
  34. code_contests-12272/instruction.md +64 -0
  35. code_contests-12286/instruction.md +174 -0
  36. code_contests-12424/instruction.md +80 -0
  37. code_contests-12441/instruction.md +88 -0
  38. code_contests-1259/instruction.md +73 -0
  39. code_contests-12616/instruction.md +67 -0
  40. code_contests-12629/instruction.md +60 -0
  41. code_contests-12673/instruction.md +46 -0
  42. code_contests-12819/instruction.md +85 -0
  43. code_contests-13159/instruction.md +89 -0
  44. code_contests-1455/instruction.md +71 -0
  45. code_contests-1602/instruction.md +78 -0
  46. code_contests-1658/instruction.md +85 -0
  47. code_contests-1857/instruction.md +70 -0
  48. code_contests-2016/instruction.md +63 -0
  49. code_contests-2029/instruction.md +63 -0
  50. code_contests-2224/instruction.md +124 -0
code_contests-0117/instruction.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1176_F. Destroy it!
2
+
3
+ ## Problem Description
4
+ You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
5
+
6
+ The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed 3. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.
7
+
8
+ Your character has also found an artifact that boosts the damage of some of your actions: every 10-th card you play deals double damage.
9
+
10
+ What is the maximum possible damage you can deal during n turns?
11
+
12
+ Input
13
+
14
+ The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of turns.
15
+
16
+ Then n blocks of input follow, the i-th block representing the cards you get during the i-th turn.
17
+
18
+ Each block begins with a line containing one integer k_i (1 ≤ k_i ≤ 2 ⋅ 10^5) — the number of cards you get during i-th turn. Then k_i lines follow, each containing two integers c_j and d_j (1 ≤ c_j ≤ 3, 1 ≤ d_j ≤ 10^9) — the parameters of the corresponding card.
19
+
20
+ It is guaranteed that ∑ _{i = 1}^{n} k_i ≤ 2 ⋅ 10^5.
21
+
22
+ Output
23
+
24
+ Print one integer — the maximum damage you may deal.
25
+
26
+ Example
27
+
28
+ Input
29
+
30
+
31
+ 5
32
+ 3
33
+ 1 6
34
+ 1 7
35
+ 1 5
36
+ 2
37
+ 1 4
38
+ 1 3
39
+ 3
40
+ 1 10
41
+ 3 5
42
+ 2 3
43
+ 3
44
+ 1 15
45
+ 2 4
46
+ 1 10
47
+ 1
48
+ 1 100
49
+
50
+
51
+ Output
52
+
53
+
54
+ 263
55
+
56
+ Note
57
+
58
+ In the example test the best course of action is as follows:
59
+
60
+ During the first turn, play all three cards in any order and deal 18 damage.
61
+
62
+ During the second turn, play both cards and deal 7 damage.
63
+
64
+ During the third turn, play the first and the third card and deal 13 damage.
65
+
66
+ During the fourth turn, play the first and the third card and deal 25 damage.
67
+
68
+ During the fifth turn, play the only card, which will deal double damage (200).
69
+
70
+ ## Contest Information
71
+ - **Contest ID**: 1176
72
+ - **Problem Index**: F
73
+ - **Points**: 0.0
74
+ - **Rating**: 2100
75
+ - **Tags**: dp, implementation, sortings
76
+ - **Time Limit**: {'seconds': 2, '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-0172/instruction.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # class-homework
2
+
3
+ ## Problem Description
4
+ Ramesh and Suresh were in the same class and got home work from their mathematics teacher. The Homework consists of N strings and each string consists of only digits. The task which they need to perform is that they need to divide the string into 4 integers such that their sum is maximum.
5
+
6
+ Note:
7
+
8
+ Each integer should be ≤ 10^12 and should not contain any leading zeroes.
9
+
10
+ As we know that Suresh and Ramesh are weak in mathematics and also they don't want to be punished. So, they need your help for finding the answer.
11
+ INPUT:
12
+ First line contains an integer N denoting the number of strings. Next N lines contain N strings each consists of digits only.
13
+ OUTPUT:
14
+ For each test case, Print the required answer if exists. Print "unlucky" otherwise.
15
+
16
+ CONSTRAINTS:
17
+
18
+ 1 ≤ N ≤ 10^4
19
+ 1 ≤ size of each string ≤ 20
20
+
21
+ SUBTASKS:
22
+
23
+ subtask 1 : 1 ≤ N ≤ 10^2 : ( 50 pts )
24
+ subtask 2 : 1 ≤ N ≤ 10^4 : ( 50 pts )
25
+
26
+ SAMPLE INPUT
27
+ 3
28
+ 4251
29
+ 52310
30
+ 00006
31
+
32
+ SAMPLE OUTPUT
33
+ 12
34
+ 56
35
+ unlucky
36
+
37
+ Explanation
38
+
39
+ In test case 1: 4 integers are 4,2,5,1. So maximum sum is 12.
40
+ In test case 2: 4 integers are 52,3,1,0. So maximum sum is 56.
41
+ In test case 3: None of division (0 , 0 , 0 , 06) , (0 , 00 , 0 , 6 ) is valid.
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-0325/instruction.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1165_A. Remainder
2
+
3
+ ## Problem Description
4
+ You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.
5
+
6
+ You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem.
7
+
8
+ You are also given two integers 0 ≤ y < x < n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x.
9
+
10
+ Input
11
+
12
+ The first line of the input contains three integers n, x, y (0 ≤ y < x < n ≤ 2 ⋅ 10^5) — the length of the number and the integers x and y, respectively.
13
+
14
+ The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1.
15
+
16
+ Output
17
+
18
+ Print one integer — the minimum number of operations you should perform to obtain the number having remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+
25
+ 11 5 2
26
+ 11010100101
27
+
28
+
29
+ Output
30
+
31
+
32
+ 1
33
+
34
+
35
+ Input
36
+
37
+
38
+ 11 5 1
39
+ 11010100101
40
+
41
+
42
+ Output
43
+
44
+
45
+ 3
46
+
47
+ Note
48
+
49
+ In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000.
50
+
51
+ In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.
52
+
53
+ ## Contest Information
54
+ - **Contest ID**: 1165
55
+ - **Problem Index**: A
56
+ - **Points**: 0.0
57
+ - **Rating**: 1100
58
+ - **Tags**: implementation, math
59
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
60
+ - **Memory Limit**: 256000000 bytes
61
+
62
+ ## Task
63
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0516/instruction.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01904 Minimum Enclosing Rectangle
2
+
3
+ ## Problem Description
4
+ G: Minimum Enclosing Rectangle-Minimum Enclosing Rectangle-
5
+
6
+ story
7
+
8
+ Hello everyone! It's Airi Aiza from the Hachimori Naka Prokon Club. Suddenly, I want everyone to solve the problem that Airi couldn't solve before. I solved the A problem of ICPC2010 in this front activity, but the problem at that time was difficult.
9
+
10
+ Oh, I have to explain about ICPC! ICPC is an abbreviation for "Intanashi Naru ... Chugakusei ... Progura Mingu ... Kontesu", and when translated into Japanese, it seems to be an international junior high school student competition programming contest! Airi is full of difficult words. Airi and his friends are working hard every day to compete in this world championship!
11
+
12
+ After returning from club activities, I asked my sister, "Wow, I don't know ... I don't know because of problem A ... I'm disqualified ..." But I was depressed ... But, "Professional" I know where people get together, so I'll contact you for a moment. Airi, ask me there! "He told me about the training camp here. It might be easy for all the "professionals" who gather here, but ... I want you to solve this problem!
13
+
14
+ problem
15
+
16
+ There are N squares with a length of 1 on a two-dimensional plane. Find the rectangle with the smallest area that contains all of these N squares.
17
+
18
+ Input format
19
+
20
+ The input consists of N lines.
21
+
22
+
23
+ N
24
+ n_1 d_1
25
+ n_2 d_2
26
+ n_3 d_3
27
+ ...
28
+ n_ {N − 1} d_ {N − 1}
29
+
30
+
31
+ The first row is given the number N of squares. Below, the N-1 line shows how to place the square. The i-th line from the top is given one integer n_ {i} and one character d_ {i} separated by blanks. This dictates how to place the i-th square. Here, the squares are numbered with the first square as the 0th square and then numbered 1, 2, ..., N − 1 in the order in which they are placed. There is no instruction on how to place the 0th square. Instructions on how to place the i-th square n_i, d_i indicate that the i-th square should be placed adjacent to the n_i-th square in the direction indicated by d_i. Where n_i is a non-negative integer less than i. In addition, d_i takes any value of 0, 1, 2, and 3, and if the value of d_i is 0, it indicates the left side, if it is 1, it indicates the lower side, if it is 2, it indicates the right side, and if it is 3, it indicates the upper side. The final arrangement of squares corresponding to each input example is shown below. From the left, the final square layout of Input Example 1, Input Example 2, Input Example 3, and Input Example 4. The numbers in the figure correspond to square numbers. The green line in the figure indicates a rectangle with the minimum area to be obtained.
32
+
33
+ <image>
34
+
35
+ Constraint
36
+
37
+ * All inputs are integers
38
+ * 1 ≤ N ≤ 100,000
39
+ * 1 ≤ n_i <i (1 ≤ i <N)
40
+ * 0 ≤ d_i ≤ 3 (1 ≤ i <N)
41
+ * No instructions are given to place a new square where it has already been placed.
42
+
43
+
44
+
45
+ Output format
46
+
47
+ Outputs the area of ​​the rectangle with the smallest area that includes all the given N points in one line. The output must not contain more than 10 ^ {-5} error.
48
+
49
+ Input example 1
50
+
51
+
52
+ 1
53
+
54
+ Output example 1
55
+
56
+
57
+ 1
58
+
59
+ Input example 2
60
+
61
+
62
+ Five
63
+ 0 0
64
+ 0 1
65
+ 0 2
66
+ 0 3
67
+
68
+
69
+ Output example 2
70
+
71
+
72
+ 8
73
+
74
+ Input example 3
75
+
76
+
77
+ 12
78
+ 0 0
79
+ Ten
80
+ 2 0
81
+ 3 1
82
+ 4 1
83
+ 5 1
84
+ 6 2
85
+ 7 2
86
+ 8 2
87
+ 9 3
88
+ 10 3
89
+
90
+
91
+ Output example 3
92
+
93
+
94
+ 16
95
+
96
+ Input example 4
97
+
98
+
99
+ Ten
100
+ 0 2
101
+ 1 2
102
+ twenty two
103
+ 3 2
104
+ twenty one
105
+ 5 1
106
+ 6 1
107
+ 7 1
108
+ 8 1
109
+
110
+
111
+ Output example 4
112
+
113
+
114
+ 30
115
+
116
+
117
+
118
+
119
+
120
+ Example
121
+
122
+ Input
123
+
124
+ 1
125
+
126
+
127
+ Output
128
+
129
+ 1
130
+
131
+ ## Contest Information
132
+ - **Contest ID**: 0
133
+ - **Problem Index**:
134
+ - **Points**: 0.0
135
+ - **Rating**: 0
136
+ - **Tags**:
137
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
138
+ - **Memory Limit**: 268435456 bytes
139
+
140
+ ## Task
141
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0573/instruction.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 661_D. Maximal Difference
2
+
3
+ ## Problem Description
4
+ You are given an array of integers ai. Find the largest absolute value of difference between adjacent elements of the array max(abs(ai - ai + 1)).
5
+
6
+ Input
7
+
8
+ The only line of the input contains a list of space-separated integers ai (1 ≤ ai ≤ 100) — elements of the array. The size of the array is between 2 and 10, inclusive. Note that the size of the array is not given explicitly!
9
+
10
+ Output
11
+
12
+ Output a single integer — the largest absolute value of difference between adjacent elements of the array.
13
+
14
+ Examples
15
+
16
+ Input
17
+
18
+ 2 10 4 8 6 12
19
+
20
+
21
+ Output
22
+
23
+ 8
24
+
25
+
26
+ Input
27
+
28
+ 3 3
29
+
30
+
31
+ Output
32
+
33
+ 0
34
+
35
+ ## Contest Information
36
+ - **Contest ID**: 661
37
+ - **Problem Index**: D
38
+ - **Points**: 0.0
39
+ - **Rating**: 2100
40
+ - **Tags**: *special
41
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
42
+ - **Memory Limit**: 64000000 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-0587/instruction.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 989_E. A Trance of Nightfall
2
+
3
+ ## Problem Description
4
+ The cool breeze blows gently, the flowing water ripples steadily.
5
+
6
+ "Flowing and passing like this, the water isn't gone ultimately; Waxing and waning like that, the moon doesn't shrink or grow eventually."
7
+
8
+ "Everything is transient in a way and perennial in another."
9
+
10
+ Kanno doesn't seem to make much sense out of Mino's isolated words, but maybe it's time that they enjoy the gentle breeze and the night sky — the inexhaustible gifts from nature.
11
+
12
+ Gazing into the sky of stars, Kanno indulges in a night's tranquil dreams.
13
+
14
+ There is a set S of n points on a coordinate plane.
15
+
16
+ Kanno starts from a point P that can be chosen on the plane. P is not added to S if it doesn't belong to S. Then the following sequence of operations (altogether called a move) is repeated several times, in the given order:
17
+
18
+ 1. Choose a line l such that it passes through at least two elements in S and passes through Kanno's current position. If there are multiple such lines, one is chosen equiprobably.
19
+ 2. Move to one of the points that belong to S and lie on l. The destination is chosen equiprobably among all possible ones, including Kanno's current position (if it does belong to S).
20
+
21
+
22
+
23
+ There are q queries each consisting of two integers (t_i, m_i). For each query, you're to help Kanno maximize the probability of the stopping position being the t_i-th element in S after m_i moves with a proper selection of P, and output this maximum probability. Note that according to rule 1, P should belong to at least one line that passes through at least two points from S.
24
+
25
+ Input
26
+
27
+ The first line contains a positive integer n (2 ≤ n ≤ 200) — the number of points in S.
28
+
29
+ The i-th of the following n lines contains two space-separated integers x_i and y_i (-10^4 ≤ x_i, y_i ≤ 10^4) — the coordinates of the i-th point in S. The input guarantees that for all 1 ≤ i < j ≤ n, (x_i, y_i) ≠ (x_j, y_j) holds.
30
+
31
+ The next line contains a positive integer q (1 ≤ q ≤ 200) — the number of queries.
32
+
33
+ Each of the following q lines contains two space-separated integers t and m (1 ≤ t_i ≤ n, 1 ≤ m_i ≤ 10^4) — the index of the target point and the number of moves, respectively.
34
+
35
+ Output
36
+
37
+ Output q lines each containing a decimal number — the i-th among them denotes the maximum probability of staying on the t_i-th point after m_i steps, with a proper choice of starting position P.
38
+
39
+ Your answer will be considered correct if each number in your output differs from the corresponding one in jury's answer by at most 10^{-6}.
40
+
41
+ Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if |a - b| ≤ 10^{-6}.
42
+
43
+ Example
44
+
45
+ Input
46
+
47
+ 5
48
+ 0 0
49
+ 1 3
50
+ 2 2
51
+ 3 1
52
+ 4 4
53
+ 10
54
+ 1 1
55
+ 2 1
56
+ 3 1
57
+ 4 1
58
+ 5 1
59
+ 3 2
60
+ 3 3
61
+ 3 4
62
+ 3 5
63
+ 3 6
64
+
65
+
66
+ Output
67
+
68
+ 0.50000000000000000000
69
+ 0.50000000000000000000
70
+ 0.33333333333333331483
71
+ 0.50000000000000000000
72
+ 0.50000000000000000000
73
+ 0.18518518518518517491
74
+ 0.15226337448559670862
75
+ 0.14494741655235482414
76
+ 0.14332164812274550414
77
+ 0.14296036624949901017
78
+
79
+ Note
80
+
81
+ The points in S and possible candidates for line l are depicted in the following figure.
82
+
83
+ <image>
84
+
85
+ For the first query, when P = (-1, -3), l is uniquely determined to be 3x = y, and thus Kanno will move to (0, 0) with a probability of \frac 1 2.
86
+
87
+ For the third query, when P = (2, 2), l is chosen equiprobably between x + y = 4 and x = y. Kanno will then move to the other four points with a probability of \frac 1 2 ⋅ \frac 1 3 = \frac 1 6 each, or stay at (2, 2) with a probability of \frac 1 3.
88
+
89
+ ## Contest Information
90
+ - **Contest ID**: 989
91
+ - **Problem Index**: E
92
+ - **Points**: 2500.0
93
+ - **Rating**: 2700
94
+ - **Tags**: dp, geometry, matrices, probabilities
95
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
96
+ - **Memory Limit**: 256000000 bytes
97
+
98
+ ## Task
99
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0724/instruction.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01856 Typhoon
2
+
3
+ ## Problem Description
4
+ Problem statement
5
+
6
+ There is a town with a size of H in the north-south direction and W in the east-west direction. In the town, square plots with a side length of 1 are maintained without gaps, and one house is built in each plot.
7
+
8
+ A typhoon broke out over a section of the town, causing damage and then changing to an extratropical cyclone over a section. No damage is done after the change. As shown in the figure below, a typhoon is a square with a height of 3 and a width of 3, and the square with a star is called the center. The typhoon moves to the vicinity of 8 in units of sections. In other words, the center of the typhoon moves with the whole so that it moves to the section that shares the sides or vertices (including the current section). However, the typhoon does not protrude outside the town, and the center of the typhoon is the 0th and H-1st sections from the north and the 0th and W-1st sections from the west, as shown in the shaded area in the figure below. Move so that it does not pass.
9
+
10
+ <image>
11
+
12
+ Once a typhoon hits the sky, the degree of damage to the house changes as follows.
13
+
14
+ > No damage → Partially damaged → Half destroyed → Completely destroyed → No trace
15
+
16
+ Fortunately, however, there seems to be no house that has become a trace pear. Since the damage situation of each house is given, find the point where the typhoon occurred and the point where it changed to an extratropical cyclone. However, if the generated section is s_ith from the north, s_jth from the west, and the section changed to an extratropical cyclone is t_ith from the north and t_jth from the west, the two points are 10000 t_i + t_j ≤ 10000 s_i + s_j. Determined to meet.
17
+
18
+ input
19
+
20
+
21
+ H \ W
22
+ D_ {11} \… \ D_ {1W}
23
+ D_ {21} \… \ D_ {2W}
24
+ ...
25
+ D_ {H1} \… \ D_ {HW}
26
+
27
+
28
+ D_ {ij} is an integer that expresses the degree of damage to the i-th house from the north and the j-th house from the west as follows.
29
+
30
+ * 0: No damage
31
+ * 1: Partially damaged
32
+ * 2: Half destroyed
33
+ * 3: Completely destroyed
34
+
35
+
36
+
37
+ Constraint
38
+
39
+ * An integer
40
+ * Input is given only if the answer is uniquely determined
41
+ * 3 ≤ H, W ≤ 500
42
+ * 0 ≤ D_ {ij} ≤ 3
43
+
44
+
45
+
46
+ output
47
+
48
+ Output the answer in one line as follows.
49
+
50
+
51
+ s_i \ s_j \ t_i \ t_j
52
+
53
+
54
+ sample
55
+
56
+ Sample input 1
57
+
58
+
59
+ 7 5
60
+ 0 0 0 0 0
61
+ 0 1 1 1 0
62
+ 0 2 2 2 0
63
+ 0 3 3 3 0
64
+ 0 2 2 2 0
65
+ 0 1 1 1 0
66
+ 0 0 0 0 0
67
+
68
+
69
+ Sample output 1
70
+
71
+
72
+ 4 2 2 2
73
+
74
+
75
+ Sample input 2
76
+
77
+
78
+ 6 6
79
+ 0 0 0 1 1 1
80
+ 0 0 0 2 2 2
81
+ 0 0 1 3 3 2
82
+ 1 2 3 3 2 1
83
+ 1 2 3 2 1 0
84
+ 1 2 2 1 0 0
85
+
86
+
87
+ Sample output 2
88
+
89
+
90
+ 4 1 1 4
91
+
92
+
93
+ Sample input 3
94
+
95
+
96
+ 4 4
97
+ 2 2 2 0
98
+ 2 2 2 0
99
+ 2 2 2 0
100
+ 0 0 0 0
101
+
102
+
103
+ Sample output 3
104
+
105
+
106
+ 1 1 1 1
107
+
108
+
109
+
110
+
111
+
112
+
113
+ Example
114
+
115
+ Input
116
+
117
+ 7 5
118
+ 0 0 0 0 0
119
+ 0 1 1 1 0
120
+ 0 2 2 2 0
121
+ 0 3 3 3 0
122
+ 0 2 2 2 0
123
+ 0 1 1 1 0
124
+ 0 0 0 0 0
125
+
126
+
127
+ Output
128
+
129
+ 4 2 2 2
130
+
131
+ ## Contest Information
132
+ - **Contest ID**: 0
133
+ - **Problem Index**:
134
+ - **Points**: 0.0
135
+ - **Rating**: 0
136
+ - **Tags**:
137
+ - **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
138
+ - **Memory Limit**: 268435456 bytes
139
+
140
+ ## Task
141
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0741/instruction.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1144_F. Graph Without Long Directed Paths
2
+
3
+ ## Problem Description
4
+ You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph.
5
+
6
+ You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the number of traversed edges).
7
+
8
+ Input
9
+
10
+ The first line contains two integer numbers n and m (2 ≤ n ≤ 2 ⋅ 10^5, n - 1 ≤ m ≤ 2 ⋅ 10^5) — the number of vertices and edges, respectively.
11
+
12
+ The following m lines contain edges: edge i is given as a pair of vertices u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i). There are no multiple edges in the given graph, i. e. for each pair (u_i, v_i) there are no other pairs (u_i, v_i) and (v_i, u_i) in the list of edges. It is also guaranteed that the given graph is connected (there is a path between any pair of vertex in the given graph).
13
+
14
+ Output
15
+
16
+ If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line.
17
+
18
+ Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0' and '1') of length m. The i-th element of this string should be '0' if the i-th edge of the graph should be directed from u_i to v_i, and '1' otherwise. Edges are numbered in the order they are given in the input.
19
+
20
+ Example
21
+
22
+ Input
23
+
24
+
25
+ 6 5
26
+ 1 5
27
+ 2 1
28
+ 1 4
29
+ 3 1
30
+ 6 1
31
+
32
+
33
+ Output
34
+
35
+
36
+ YES
37
+ 10100
38
+
39
+ Note
40
+
41
+ The picture corresponding to the first example: <image>
42
+
43
+ And one of possible answers: <image>
44
+
45
+ ## Contest Information
46
+ - **Contest ID**: 1144
47
+ - **Problem Index**: F
48
+ - **Points**: 0.0
49
+ - **Rating**: 1700
50
+ - **Tags**: dfs and similar, graphs
51
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
52
+ - **Memory Limit**: 256000000 bytes
53
+
54
+ ## Task
55
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0914/instruction.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03072 AtCoder Beginner Contest 124 - Great Ocean View
2
+
3
+ ## Problem Description
4
+ There are N mountains ranging from east to west, and an ocean to the west.
5
+
6
+ At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns.
7
+
8
+ The height of the i-th mountain from the west is H_i.
9
+
10
+ You can certainly see the ocean from the inn at the top of the westmost mountain.
11
+
12
+ For the inn at the top of the i-th mountain from the west (i = 2, 3, ..., N), you can see the ocean if and only if H_1 \leq H_i, H_2 \leq H_i, ..., and H_{i-1} \leq H_i.
13
+
14
+ From how many of these N inns can you see the ocean?
15
+
16
+ Constraints
17
+
18
+ * All values in input are integers.
19
+ * 1 \leq N \leq 20
20
+ * 1 \leq H_i \leq 100
21
+
22
+ Input
23
+
24
+ Input is given from Standard Input in the following format:
25
+
26
+
27
+ N
28
+ H_1 H_2 ... H_N
29
+
30
+
31
+ Output
32
+
33
+ Print the number of inns from which you can see the ocean.
34
+
35
+ Examples
36
+
37
+ Input
38
+
39
+ 4
40
+ 6 5 6 8
41
+
42
+
43
+ Output
44
+
45
+ 3
46
+
47
+
48
+ Input
49
+
50
+ 5
51
+ 4 5 3 5 4
52
+
53
+
54
+ Output
55
+
56
+ 3
57
+
58
+
59
+ Input
60
+
61
+ 5
62
+ 9 5 6 8 4
63
+
64
+
65
+ Output
66
+
67
+ 1
68
+
69
+ ## Contest Information
70
+ - **Contest ID**: 0
71
+ - **Problem Index**:
72
+ - **Points**: 0.0
73
+ - **Rating**: 0
74
+ - **Tags**:
75
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
76
+ - **Memory Limit**: 1073741824 bytes
77
+
78
+ ## Task
79
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1009/instruction.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ikshu-and-his-class-1
2
+
3
+ ## Problem Description
4
+ Ikshu and his class
5
+
6
+ Ikshu's class is very fond of playing games. Their teacher tied them with many ropes with each other, Such that each student is tied with exactly one rope. It means that if students 2 and 3 are connected and 2 is connected to 4 as well then 2,3 and 4 must be sharing the same rope.
7
+
8
+ Now, teacher asks them to divide themselves in group. One group for each rope, each group consists of the students tied to that particular rope. Each group exchanges gifts among themselves (each student is having exactly one gift before and after the game).
9
+
10
+ What is the total number of distinct exchanges possible ? Two exchanges are distinct if there is atleast one student having different gift with him.
11
+
12
+ NOTE: It is also possible that a student has same gift after exchanging as he had before exchanging. There might be a case where no exchange took place i.e each student is having same gift after exchanging as he was having before exchange.
13
+
14
+ Input:
15
+ First line of input contains two integers N and K, where N is the number of students and K is the number of connections between students. Next K lines contains two integers which are the indices(0 based) of students connected by a rope.
16
+
17
+ Output:
18
+ Print a single integer which is the total number of exchanges possible modulus (10^9 + 7)
19
+
20
+ Constraints:
21
+ 1 ≤ N ≤ 100000
22
+ 1 ≤ K ≤ 100000
23
+
24
+ SAMPLE INPUT
25
+ 5 2
26
+ 1 2
27
+ 3 4
28
+
29
+ SAMPLE OUTPUT
30
+ 4
31
+
32
+ Explanation
33
+
34
+ 0 is alone, [1,2] and [3,4] are tied to same rope.
35
+ Now, 0 cannot share gift with anyone whereas [1,2] can has two possible distinct exchanges
36
+ a) where 1 and 2 exchange gifts
37
+ b) where they do not exchange gift.
38
+ Same for [3,4]
39
+
40
+ So, there are 2*2 = 4 different states possible at the end.
41
+
42
+ ## Contest Information
43
+ - **Contest ID**: 0
44
+ - **Problem Index**:
45
+ - **Points**: 0.0
46
+ - **Rating**: 0
47
+ - **Tags**: None
48
+ - **Time Limit**: None seconds
49
+ - **Memory Limit**: 0 bytes
50
+
51
+ ## Task
52
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10124/instruction.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1354_B. Ternary String
2
+
3
+ ## Problem Description
4
+ You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once.
5
+
6
+ A contiguous substring of string s is a string that can be obtained from s by removing some (possibly zero) characters from the beginning of s and some (possibly zero) characters from the end of s.
7
+
8
+ Input
9
+
10
+ The first line contains one integer t (1 ≤ t ≤ 20000) — the number of test cases.
11
+
12
+ Each test case consists of one line containing the string s (1 ≤ |s| ≤ 200000). It is guaranteed that each character of s is either 1, 2, or 3.
13
+
14
+ The sum of lengths of all strings in all test cases does not exceed 200000.
15
+
16
+ Output
17
+
18
+ For each test case, print one integer — the length of the shortest contiguous substring of s containing all three types of characters at least once. If there is no such substring, print 0 instead.
19
+
20
+ Example
21
+
22
+ Input
23
+
24
+
25
+ 7
26
+ 123
27
+ 12222133333332
28
+ 112233
29
+ 332211
30
+ 12121212
31
+ 333333
32
+ 31121
33
+
34
+
35
+ Output
36
+
37
+
38
+ 3
39
+ 3
40
+ 4
41
+ 4
42
+ 0
43
+ 0
44
+ 4
45
+
46
+ Note
47
+
48
+ Consider the example test:
49
+
50
+ In the first test case, the substring 123 can be used.
51
+
52
+ In the second test case, the substring 213 can be used.
53
+
54
+ In the third test case, the substring 1223 can be used.
55
+
56
+ In the fourth test case, the substring 3221 can be used.
57
+
58
+ In the fifth test case, there is no character 3 in s.
59
+
60
+ In the sixth test case, there is no character 1 in s.
61
+
62
+ In the seventh test case, the substring 3112 can be used.
63
+
64
+ ## Contest Information
65
+ - **Contest ID**: 1354
66
+ - **Problem Index**: B
67
+ - **Points**: 0.0
68
+ - **Rating**: 1200
69
+ - **Tags**: binary search, dp, implementation, two pointers
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-10141/instruction.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 353_E. Antichain
2
+
3
+ ## Problem Description
4
+ You have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1) mod n, and it can be directed in either direction (from i to (i + 1) mod n, or vise versa).
5
+
6
+ Operation x mod y means taking the remainder after dividing number x by number y.
7
+
8
+ Let's call two vertexes u and v in graph G comparable if the graph contains a path either from u to v or from v to u. We'll assume that an antichain is a set of vertexes of graph G, where any two distinct vertexes are not comparable. The size of an antichain is the number of vertexes in the corresponding set. An antichain is maximum if the graph doesn't have antichains of a larger size.
9
+
10
+ Your task is to find the size of the maximum antichain in graph G.
11
+
12
+ Input
13
+
14
+ The first line contains the sequence of characters s0s1... sn - 1 (2 ≤ n ≤ 106), consisting of numbers zero and one. The length of the line (number n) corresponds to the number of vertexes and edges in graph G. If character si (i ≥ 0) equals 0, then the edge between vertexes i and (i + 1) mod n is directed from the i-th vertex to the (i + 1) mod n-th one, otherwise — to the opposite point.
15
+
16
+ It is guaranteed that the given graph is acyclic.
17
+
18
+ Output
19
+
20
+ Print a single integer — the size of the maximum antichain of graph G.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 001
27
+
28
+
29
+ Output
30
+
31
+ 1
32
+
33
+
34
+ Input
35
+
36
+ 110010
37
+
38
+
39
+ Output
40
+
41
+ 3
42
+
43
+ Note
44
+
45
+ Consider the first test sample. The graph's G edges are: 0 → 1, 1 → 2, 0 → 2. We can choose the set of vertexes [0] as the maximum antichain. We cannot choose an antichain of larger size.
46
+
47
+ ## Contest Information
48
+ - **Contest ID**: 353
49
+ - **Problem Index**: E
50
+ - **Points**: 3000.0
51
+ - **Rating**: 2200
52
+ - **Tags**: dp, graph matchings, greedy
53
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
54
+ - **Memory Limit**: 256000000 bytes
55
+
56
+ ## Task
57
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1031/instruction.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00876 Swimming Jam
2
+
3
+ ## Problem Description
4
+ Despite urging requests of the townspeople, the municipal office cannot afford to improve many of the apparently deficient city amenities under this recession. The city swimming pool is one of the typical examples. It has only two swimming lanes. The Municipal Fitness Agency, under this circumstances, settled usage rules so that the limited facilities can be utilized fully.
5
+
6
+ Two lanes are to be used for one-way swimming of different directions. Swimmers are requested to start swimming in one of the lanes, from its one end to the other, and then change the lane to swim his/her way back. When he or she reaches the original starting end, he/she should return to his/her initial lane and starts swimming again.
7
+
8
+ Each swimmer has his/her own natural constant pace. Swimmers, however, are not permitted to pass other swimmers except at the ends of the pool; as the lanes are not wide enough, that might cause accidents. If a swimmer is blocked by a slower swimmer, he/she has to follow the slower swimmer at the slower pace until the end of the lane is reached. Note that the blocking swimmer’s natural pace may be faster than the blocked swimmer; the blocking swimmer might also be blocked by another swimmer ahead, whose natural pace is slower than the blocked swimmer. Blocking would have taken place whether or not a faster swimmer was between them.
9
+
10
+ Swimmers can change their order if they reach the end of the lane simultaneously. They change their order so that ones with faster natural pace swim in front. When a group of two or more swimmers formed by a congestion reaches the end of the lane, they are considered to reach there simultaneously, and thus change their order there.
11
+
12
+ The number of swimmers, their natural paces in times to swim from one end to the other, and the numbers of laps they plan to swim are given. Note that here one "lap" means swimming from one end to the other and then swimming back to the original end. Your task is to calculate the time required for all the swimmers to finish their plans. All the swimmers start from the same end of the pool at the same time, the faster swimmers in front.
13
+
14
+ In solving this problem, you can ignore the sizes of swimmers' bodies, and also ignore the time required to change the lanes and the order in a group of swimmers at an end of the lanes.
15
+
16
+
17
+
18
+ Input
19
+
20
+ The input is a sequence of datasets. Each dataset is formatted as follows.
21
+
22
+ n
23
+ t1 c1
24
+ ...
25
+ tn cn
26
+
27
+
28
+ n is an integer (1 ≤ n ≤ 50) that represents the number of swimmers. ti and ci are integers (1 ≤ ti ≤ 300, 1 ≤ ci ≤ 250) that represent the natural pace in times to swim from one end to the other and the number of planned laps for the i-th swimmer, respectively. ti and ci are separated by a space.
29
+
30
+ The end of the input is indicated by a line containing one zero.
31
+
32
+ Output
33
+
34
+ For each dataset, output the time required for all the swimmers to finish their plans in a line. No extra characters should occur in the output.
35
+
36
+ Example
37
+
38
+ Input
39
+
40
+ 2
41
+ 10 30
42
+ 15 20
43
+ 2
44
+ 10 240
45
+ 15 160
46
+ 3
47
+ 2 6
48
+ 7 2
49
+ 8 2
50
+ 4
51
+ 2 4
52
+ 7 2
53
+ 8 2
54
+ 18 1
55
+ 0
56
+
57
+
58
+ Output
59
+
60
+ 600
61
+ 4800
62
+ 36
63
+ 40
64
+
65
+ ## Contest Information
66
+ - **Contest ID**: 0
67
+ - **Problem Index**:
68
+ - **Points**: 0.0
69
+ - **Rating**: 0
70
+ - **Tags**:
71
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
72
+ - **Memory Limit**: 134217728 bytes
73
+
74
+ ## Task
75
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10373/instruction.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 908_E. New Year and Entity Enumeration
2
+
3
+ ## Problem Description
4
+ You are given an integer m.
5
+
6
+ Let M = 2m - 1.
7
+
8
+ You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m.
9
+
10
+ A set of integers S is called "good" if the following hold.
11
+
12
+ 1. If <image>, then <image>.
13
+ 2. If <image>, then <image>
14
+ 3. <image>
15
+ 4. All elements of S are less than or equal to M.
16
+
17
+
18
+
19
+ Here, <image> and <image> refer to the bitwise XOR and bitwise AND operators, respectively.
20
+
21
+ Count the number of good sets S, modulo 109 + 7.
22
+
23
+ Input
24
+
25
+ The first line will contain two integers m and n (1 ≤ m ≤ 1 000, 1 ≤ n ≤ min(2m, 50)).
26
+
27
+ The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct.
28
+
29
+ Output
30
+
31
+ Print a single integer, the number of good sets modulo 109 + 7.
32
+
33
+ Examples
34
+
35
+ Input
36
+
37
+ 5 3
38
+ 11010
39
+ 00101
40
+ 11000
41
+
42
+
43
+ Output
44
+
45
+ 4
46
+
47
+
48
+ Input
49
+
50
+ 30 2
51
+ 010101010101010010101010101010
52
+ 110110110110110011011011011011
53
+
54
+
55
+ Output
56
+
57
+ 860616440
58
+
59
+ Note
60
+
61
+ An example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}.
62
+
63
+ ## Contest Information
64
+ - **Contest ID**: 908
65
+ - **Problem Index**: E
66
+ - **Points**: 1750.0
67
+ - **Rating**: 2500
68
+ - **Tags**: bitmasks, combinatorics, dp, math
69
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
70
+ - **Memory Limit**: 256000000 bytes
71
+
72
+ ## Task
73
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10387/instruction.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02567 AtCoder Library Practice Contest - Segment Tree
2
+
3
+ ## Problem Description
4
+ You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.
5
+
6
+ The type of i-th query is represented by T_i.
7
+
8
+ * T_i=1: You are given two integers X_i,V_i. Replace the value of A_{X_i} with V_i.
9
+ * T_i=2: You are given two integers L_i,R_i. Calculate the maximum value among A_{L_i},A_{L_i+1},\cdots,A_{R_i}.
10
+ * T_i=3: You are given two integers X_i,V_i. Calculate the minimum j such that X_i \leq j \leq N, V_i \leq A_j. If there is no such j, answer j=N+1 instead.
11
+
12
+ Constraints
13
+
14
+ * 1 \leq N \leq 2 \times 10^5
15
+ * 0 \leq A_i \leq 10^9
16
+ * 1 \leq Q \leq 2 \times 10^5
17
+ * 1 \leq T_i \leq 3
18
+ * 1 \leq X_i \leq N, 0 \leq V_i \leq 10^9 (T_i=1,3)
19
+ * 1 \leq L_i \leq R_i \leq N (T_i=2)
20
+ * All values in Input are integer.
21
+
22
+ Input
23
+
24
+ Input is given from Standard Input in the following format:
25
+
26
+
27
+ N Q
28
+ A_1 A_2 \cdots A_N
29
+ First query
30
+ Second query
31
+ \vdots
32
+ Q-th query
33
+
34
+
35
+ Each query is given in the following format:
36
+
37
+ If T_i=1,3,
38
+
39
+
40
+ T_i X_i V_i
41
+
42
+
43
+ If T_i=2,
44
+
45
+
46
+ T_i L_i R_i
47
+
48
+
49
+ Output
50
+
51
+ For each query with T_i=2, 3, print the answer.
52
+
53
+ Example
54
+
55
+ Input
56
+
57
+ 5 5
58
+ 1 2 3 2 1
59
+ 2 1 5
60
+ 3 2 3
61
+ 1 3 1
62
+ 2 2 4
63
+ 3 1 3
64
+
65
+
66
+ Output
67
+
68
+ 3
69
+ 3
70
+ 2
71
+ 6
72
+
73
+ ## Contest Information
74
+ - **Contest ID**: 0
75
+ - **Problem Index**:
76
+ - **Points**: 0.0
77
+ - **Rating**: 0
78
+ - **Tags**:
79
+ - **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
80
+ - **Memory Limit**: 1073741824 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-10540/instruction.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 135_C. Zero-One
2
+
3
+ ## Problem Description
4
+ Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.
5
+
6
+ Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card contains a digit: 0 or 1. Players move in turns and Masha moves first. During each move a player should remove a card from the table and shift all other cards so as to close the gap left by the removed card. For example, if before somebody's move the cards on the table formed a sequence 01010101, then after the fourth card is removed (the cards are numbered starting from 1), the sequence will look like that: 0100101.
7
+
8
+ The game ends when exactly two cards are left on the table. The digits on these cards determine the number in binary notation: the most significant bit is located to the left. Masha's aim is to minimize the number and Petya's aim is to maximize it.
9
+
10
+ An unpleasant accident occurred before the game started. The kids spilled juice on some of the cards and the digits on the cards got blurred. Each one of the spoiled cards could have either 0 or 1 written on it. Consider all possible variants of initial arrangement of the digits (before the juice spilling). For each variant, let's find which two cards are left by the end of the game, assuming that both Petya and Masha play optimally. An ordered pair of digits written on those two cards is called an outcome. Your task is to find the set of outcomes for all variants of initial digits arrangement.
11
+
12
+ Input
13
+
14
+ The first line contains a sequence of characters each of which can either be a "0", a "1" or a "?". This sequence determines the initial arrangement of cards on the table from the left to the right. The characters "?" mean that the given card was spoiled before the game. The sequence's length ranges from 2 to 105, inclusive.
15
+
16
+ Output
17
+
18
+ Print the set of outcomes for all possible initial digits arrangements. Print each possible outcome on a single line. Each outcome should be represented by two characters: the digits written on the cards that were left by the end of the game. The outcomes should be sorted lexicographically in ascending order (see the first sample).
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ ????
25
+
26
+
27
+ Output
28
+
29
+ 00
30
+ 01
31
+ 10
32
+ 11
33
+
34
+
35
+ Input
36
+
37
+ 1010
38
+
39
+
40
+ Output
41
+
42
+ 10
43
+
44
+
45
+ Input
46
+
47
+ 1?1
48
+
49
+
50
+ Output
51
+
52
+ 01
53
+ 11
54
+
55
+ Note
56
+
57
+ In the first sample all 16 variants of numbers arrangement are possible. For the variant 0000 the outcome is 00. For the variant 1111 the outcome is 11. For the variant 0011 the outcome is 01. For the variant 1100 the outcome is 10. Regardless of outcomes for all other variants the set which we are looking for will contain all 4 possible outcomes.
58
+
59
+ In the third sample only 2 variants of numbers arrangement are possible: 111 and 101. For the variant 111 the outcome is 11. For the variant 101 the outcome is 01, because on the first turn Masha can remove the first card from the left after which the game will end.
60
+
61
+ ## Contest Information
62
+ - **Contest ID**: 135
63
+ - **Problem Index**: C
64
+ - **Points**: 1500.0
65
+ - **Rating**: 1900
66
+ - **Tags**: constructive algorithms, games, greedy
67
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
68
+ - **Memory Limit**: 256000000 bytes
69
+
70
+ ## Task
71
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10717/instruction.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01261 Bitwise Kingdom
2
+
3
+ ## Problem Description
4
+ In the Bitwise Kingdom, located somewhere in the universe, there are exactly 2N citizens living and each of them has a unique identification string that represents his or her class in the society. An identification string is a binary string of length N which consists of characters ‘0’ or ‘1’. The order of classes is defined among the citizens by the following criteria:
5
+
6
+ 1. Citizens identified by a string containing a greater number of ones are ranked higher. For example, “011” indicates a higher class than “100”.
7
+ 2. Among those who have identification strings with the same number of ones, citizens identified by a lexicographically greater identification string are ranked higher. For example, “110” indicates a higher class than “101”.
8
+
9
+
10
+
11
+ For example, if N = 3, there are 8 (= 23) people in the country, and their identification strings are “000”, “001”, “010”, “100”, “011”, “101”, “110”, and “111” (from the lowest class to the highest).
12
+
13
+ You are given two numbers N (1 ≤ N ≤ 60) and M (1 ≤ M ≤ 2N), and you want to resolve the identification string of the person of the M-th lowest class among 2N citizens. Can you write a program to solve this problem?
14
+
15
+
16
+
17
+ Input
18
+
19
+ The input consists of multiple datasets.
20
+
21
+ Each dataset consists of a line which contains two integers N and M in this order, separated with a single space. The input does not contain any other extra characters such as leading or trailing spaces.
22
+
23
+ The end of input is indicated by a line with two zeros. This line is not part of any datasets.
24
+
25
+ Output
26
+
27
+ For each dataset, print the identification string of the person of the M-th lowest class in one line. Your program may not omit any leading zeros in the answer.
28
+
29
+ Example
30
+
31
+ Input
32
+
33
+ 3 3
34
+ 3 5
35
+ 0 0
36
+
37
+
38
+ Output
39
+
40
+ 010
41
+ 011
42
+
43
+ ## Contest Information
44
+ - **Contest ID**: 0
45
+ - **Problem Index**:
46
+ - **Points**: 0.0
47
+ - **Rating**: 0
48
+ - **Tags**:
49
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
50
+ - **Memory Limit**: 134217728 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-10772/instruction.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 527_B. Error Correct System
2
+
3
+ ## Problem Description
4
+ Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
5
+
6
+ Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
7
+
8
+ Help him do this!
9
+
10
+ Input
11
+
12
+ The first line contains integer n (1 ≤ n ≤ 200 000) — the length of strings S and T.
13
+
14
+ The second line contains string S.
15
+
16
+ The third line contains string T.
17
+
18
+ Each of the lines only contains lowercase Latin letters.
19
+
20
+ Output
21
+
22
+ In the first line, print number x — the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
23
+
24
+ In the second line, either print the indexes i and j (1 ≤ i, j ≤ n, i ≠ j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
25
+
26
+ If there are multiple possible answers, print any of them.
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+ 9
33
+ pergament
34
+ permanent
35
+
36
+
37
+ Output
38
+
39
+ 1
40
+ 4 6
41
+
42
+
43
+ Input
44
+
45
+ 6
46
+ wookie
47
+ cookie
48
+
49
+
50
+ Output
51
+
52
+ 1
53
+ -1 -1
54
+
55
+
56
+ Input
57
+
58
+ 4
59
+ petr
60
+ egor
61
+
62
+
63
+ Output
64
+
65
+ 2
66
+ 1 2
67
+
68
+
69
+ Input
70
+
71
+ 6
72
+ double
73
+ bundle
74
+
75
+
76
+ Output
77
+
78
+ 2
79
+ 4 1
80
+
81
+ Note
82
+
83
+ In the second test it is acceptable to print i = 2, j = 3.
84
+
85
+ ## Contest Information
86
+ - **Contest ID**: 527
87
+ - **Problem Index**: B
88
+ - **Points**: 1000.0
89
+ - **Rating**: 1500
90
+ - **Tags**: greedy
91
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
92
+ - **Memory Limit**: 256000000 bytes
93
+
94
+ ## Task
95
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10918/instruction.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00137 Middle-Square Method
2
+
3
+ ## Problem Description
4
+ Create a program of the square picking method, which is one of the classical random number generation methods. The square harvesting method was proposed by von Neumann in the mid-1940s.
5
+
6
+ In the square picking method, when the number of digits of the generated random number is n, the square of the initial value s is calculated, and the value is regarded as a 2n digit number (the number of squared digits as shown in the example below). If is not enough, make up for 0.) Let the n numbers in the center be the first random number. Then square this random number and take the n numbers in the center in the same way to get the next random number. For example, if 123 is the initial value
7
+
8
+
9
+ 1232 = 00015129 → 0151
10
+ 1512 = 00022801 → 0228
11
+ 2282 = 00051984 → 0519
12
+ 5192 = 00269361 → 2693
13
+ 26932 = 07252249 → 2522
14
+
15
+
16
+ It will be like. Use this method to create a program that takes the initial value s (a positive integer less than 10000) as an input and generates and outputs 10 random numbers when n = 4.
17
+
18
+
19
+
20
+ Input
21
+
22
+ Given multiple datasets. The first line gives the number of datasets d (d ≤ 10). For each dataset, one row is given the initial value s (integer, 1 ≤ s <10000).
23
+
24
+ Output
25
+
26
+ For each dataset
27
+
28
+
29
+ Case x: (x is a dataset number starting with 1)
30
+ The first generated random number (integer)
31
+ The second generated random number (integer)
32
+ :
33
+ :
34
+ 10th generated random number (integer)
35
+
36
+
37
+ Please output.
38
+
39
+ Example
40
+
41
+ Input
42
+
43
+ 2
44
+ 123
45
+ 567
46
+
47
+
48
+ Output
49
+
50
+ Case 1:
51
+ 151
52
+ 228
53
+ 519
54
+ 2693
55
+ 2522
56
+ 3604
57
+ 9888
58
+ 7725
59
+ 6756
60
+ 6435
61
+ Case 2:
62
+ 3214
63
+ 3297
64
+ 8702
65
+ 7248
66
+ 5335
67
+ 4622
68
+ 3628
69
+ 1623
70
+ 6341
71
+ 2082
72
+
73
+ ## Contest Information
74
+ - **Contest ID**: 0
75
+ - **Problem Index**:
76
+ - **Points**: 0.0
77
+ - **Rating**: 0
78
+ - **Tags**:
79
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
80
+ - **Memory Limit**: 134217728 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-10942/instruction.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1065_A. Vasya and Chocolate
2
+
3
+ ## Problem Description
4
+ There is a special offer in Vasya's favourite supermarket: if the customer buys a chocolate bars, he or she may take b additional bars for free. This special offer can be used any number of times.
5
+
6
+ Vasya currently has s roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs c roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!
7
+
8
+ Input
9
+
10
+ The first line contains one integer t (1 ≤ t ≤ 100) — the number of testcases.
11
+
12
+ Each of the next t lines contains four integers s, a, b, c~(1 ≤ s, a, b, c ≤ 10^9) — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.
13
+
14
+ Output
15
+
16
+ Print t lines. i-th line should contain the maximum possible number of chocolate bars Vasya can get in i-th test.
17
+
18
+ Example
19
+
20
+ Input
21
+
22
+ 2
23
+ 10 3 1 1
24
+ 1000000000 1 1000000000 1
25
+
26
+
27
+ Output
28
+
29
+ 13
30
+ 1000000001000000000
31
+
32
+ Note
33
+
34
+ In the first test of the example Vasya can buy 9 bars, get 3 for free, buy another bar, and so he will get 13 bars.
35
+
36
+ In the second test Vasya buys 1000000000 bars and gets 1000000000000000000 for free. So he has 1000000001000000000 bars.
37
+
38
+ ## Contest Information
39
+ - **Contest ID**: 1065
40
+ - **Problem Index**: A
41
+ - **Points**: 0.0
42
+ - **Rating**: 800
43
+ - **Tags**: implementation, math
44
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
45
+ - **Memory Limit**: 256000000 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-10989/instruction.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 736_A. Tennis Championship
2
+
3
+ ## Problem Description
4
+ Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
5
+
6
+ Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
7
+
8
+ Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
9
+
10
+ Input
11
+
12
+ The only line of the input contains a single integer n (2 ≤ n ≤ 1018) — the number of players to participate in the tournament.
13
+
14
+ Output
15
+
16
+ Print the maximum number of games in which the winner of the tournament can take part.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 2
23
+
24
+
25
+ Output
26
+
27
+ 1
28
+
29
+
30
+ Input
31
+
32
+ 3
33
+
34
+
35
+ Output
36
+
37
+ 2
38
+
39
+
40
+ Input
41
+
42
+ 4
43
+
44
+
45
+ Output
46
+
47
+ 2
48
+
49
+
50
+ Input
51
+
52
+ 10
53
+
54
+
55
+ Output
56
+
57
+ 4
58
+
59
+ Note
60
+
61
+ In all samples we consider that player number 1 is the winner.
62
+
63
+ In the first sample, there would be only one game so the answer is 1.
64
+
65
+ In the second sample, player 1 can consequently beat players 2 and 3.
66
+
67
+ In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
68
+
69
+ ## Contest Information
70
+ - **Contest ID**: 736
71
+ - **Problem Index**: A
72
+ - **Points**: 1750.0
73
+ - **Rating**: 1600
74
+ - **Tags**: combinatorics, constructive algorithms, greedy, math
75
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
76
+ - **Memory Limit**: 256000000 bytes
77
+
78
+ ## Task
79
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11058/instruction.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1300_B. Assigning to Classes
2
+
3
+ ## Problem Description
4
+ Reminder: the [median](https://en.wikipedia.org/wiki/Median) of the array [a_1, a_2, ..., a_{2k+1}] of odd number of elements is defined as follows: let [b_1, b_2, ..., b_{2k+1}] be the elements of the array in the sorted order. Then median of this array is equal to b_{k+1}.
5
+
6
+ There are 2n students, the i-th student has skill level a_i. It's not guaranteed that all skill levels are distinct.
7
+
8
+ Let's define skill level of a class as the median of skill levels of students of the class.
9
+
10
+ As a principal of the school, you would like to assign each student to one of the 2 classes such that each class has odd number of students (not divisible by 2). The number of students in the classes may be equal or different, by your choice. Every student has to be assigned to exactly one class. Among such partitions, you want to choose one in which the absolute difference between skill levels of the classes is minimized.
11
+
12
+ What is the minimum possible absolute difference you can achieve?
13
+
14
+ Input
15
+
16
+ Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The description of the test cases follows.
17
+
18
+ The first line of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of students halved.
19
+
20
+ The second line of each test case contains 2n integers a_1, a_2, ..., a_{2 n} (1 ≤ a_i ≤ 10^9) — skill levels of students.
21
+
22
+ It is guaranteed that the sum of n over all test cases does not exceed 10^5.
23
+
24
+ Output
25
+
26
+ For each test case, output a single integer, the minimum possible absolute difference between skill levels of two classes of odd sizes.
27
+
28
+ Example
29
+
30
+ Input
31
+
32
+
33
+ 3
34
+ 1
35
+ 1 1
36
+ 3
37
+ 6 5 4 1 2 3
38
+ 5
39
+ 13 4 20 13 2 5 8 3 17 16
40
+
41
+
42
+ Output
43
+
44
+
45
+ 0
46
+ 1
47
+ 5
48
+
49
+ Note
50
+
51
+ In the first test, there is only one way to partition students — one in each class. The absolute difference of the skill levels will be |1 - 1| = 0.
52
+
53
+ In the second test, one of the possible partitions is to make the first class of students with skill levels [6, 4, 2], so that the skill level of the first class will be 4, and second with [5, 1, 3], so that the skill level of the second class will be 3. Absolute difference will be |4 - 3| = 1.
54
+
55
+ Note that you can't assign like [2, 3], [6, 5, 4, 1] or [], [6, 5, 4, 1, 2, 3] because classes have even number of students.
56
+
57
+ [2], [1, 3, 4] is also not possible because students with skills 5 and 6 aren't assigned to a class.
58
+
59
+ In the third test you can assign the students in the following way: [3, 4, 13, 13, 20], [2, 5, 8, 16, 17] or [3, 8, 17], [2, 4, 5, 13, 13, 16, 20]. Both divisions give minimal possible absolute difference.
60
+
61
+ ## Contest Information
62
+ - **Contest ID**: 1300
63
+ - **Problem Index**: B
64
+ - **Points**: 750.0
65
+ - **Rating**: 1000
66
+ - **Tags**: greedy, implementation, sortings
67
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
68
+ - **Memory Limit**: 256000000 bytes
69
+
70
+ ## Task
71
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11067/instruction.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 14_B. Young Photographer
2
+
3
+ ## Problem Description
4
+ Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second — from a2 to b2
5
+
6
+ What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
7
+
8
+ Input
9
+
10
+ The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).
11
+
12
+ Output
13
+
14
+ Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ 3 3
21
+ 0 7
22
+ 14 2
23
+ 4 6
24
+
25
+
26
+ Output
27
+
28
+ 1
29
+
30
+ ## Contest Information
31
+ - **Contest ID**: 14
32
+ - **Problem Index**: B
33
+ - **Points**: 0.0
34
+ - **Rating**: 1000
35
+ - **Tags**: implementation
36
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
37
+ - **Memory Limit**: 64000000 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-11230/instruction.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00080 Third Root
2
+
3
+ ## Problem Description
4
+ The solution of $ x ^ 3 = q $ is to calculate the recurrence formula $ x_ {n + 1} = x_n-\ frac {x_ {n} ^ 3 --q} {3x_ {n} ^ 2} $ It can be calculated approximately with.
5
+
6
+ Put a positive number $ \ frac {q} {2} $ in $ x_1 $
7
+
8
+ $ x_2 = x_1-\ frac {x_ {1} ^ 3 --q} {3x_ {1} ^ 2} $, $ x_3 = x_2-\ frac {x_ {2} ^ 3 --q} {3x_ {2} ^ Calculate as 2} $,….
9
+
10
+ While doing this calculation
11
+
12
+ When the value of $ | x ^ 3 --q | $ becomes small enough, stop the calculation and use the last calculated $ x_n $ as an approximate solution of $ x ^ 3 = q $.
13
+
14
+ Follow this method to create a program that outputs an approximation of the cube root of $ q $ for the input positive integer $ q $. However, use $ | x ^ 3-q | <0.00001 q $ to determine that it is "small enough".
15
+
16
+
17
+
18
+ input
19
+
20
+ Multiple datasets are given. For each dataset, $ q $ ($ 1 \ leq q <2 ^ {31} $) (integer) is given on one line. The end of the input is -1.
21
+
22
+ The number of datasets does not exceed 50.
23
+
24
+ output
25
+
26
+ Print $ x $ (real number) on one line for each dataset. The output result may contain an error of 0.00001 or less.
27
+
28
+ Example
29
+
30
+ Input
31
+
32
+ 15
33
+ 15
34
+ -1
35
+
36
+
37
+ Output
38
+
39
+ 2.466212
40
+ 2.466212
41
+
42
+ ## Contest Information
43
+ - **Contest ID**: 0
44
+ - **Problem Index**:
45
+ - **Points**: 0.0
46
+ - **Rating**: 0
47
+ - **Tags**:
48
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
49
+ - **Memory Limit**: 134217728 bytes
50
+
51
+ ## Task
52
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11459/instruction.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # lch15jab
2
+
3
+ ## Problem Description
4
+ This is a very easy warm-up problem.
5
+ You are given a string. Your task is to determine whether number of occurrences of some character in the string is equal to the sum of the numbers of occurrences of other characters in the string. 
6
+
7
+ Input
8
+ The first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contains one string S consisting of lowercase latin letters.
9
+
10
+ Output
11
+ For each test case, output a single line containing "YES" if the string satisfies the condition given above or "NO" otherwise.
12
+
13
+ Constraints
14
+ 1 ≤ T ≤ 1000
15
+ 1 ≤ length of S ≤ 50
16
+
17
+ Example
18
+ Input:
19
+ 4
20
+ acab
21
+ zzqzqq
22
+ abc
23
+ kklkwwww
24
+ Output:
25
+ YES
26
+ YES
27
+ NO
28
+ YES
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-11492/instruction.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 278_C. Learning Languages
2
+
3
+ ## Problem Description
4
+ The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
5
+
6
+ Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
7
+
8
+ Input
9
+
10
+ The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages.
11
+
12
+ Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki integers — aij (1 ≤ aij ≤ m) — the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
13
+
14
+ The numbers in the lines are separated by single spaces.
15
+
16
+ Output
17
+
18
+ Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 5 5
25
+ 1 2
26
+ 2 2 3
27
+ 2 3 4
28
+ 2 4 5
29
+ 1 5
30
+
31
+
32
+ Output
33
+
34
+ 0
35
+
36
+
37
+ Input
38
+
39
+ 8 7
40
+ 0
41
+ 3 1 2 3
42
+ 1 1
43
+ 2 5 4
44
+ 2 6 7
45
+ 1 3
46
+ 2 7 4
47
+ 1 1
48
+
49
+
50
+ Output
51
+
52
+ 2
53
+
54
+
55
+ Input
56
+
57
+ 2 2
58
+ 1 2
59
+ 0
60
+
61
+
62
+ Output
63
+
64
+ 1
65
+
66
+ Note
67
+
68
+ In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
69
+
70
+ In the third sample employee 2 must learn language 2.
71
+
72
+ ## Contest Information
73
+ - **Contest ID**: 278
74
+ - **Problem Index**: C
75
+ - **Points**: 500.0
76
+ - **Rating**: 1400
77
+ - **Tags**: dfs and similar, dsu
78
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
79
+ - **Memory Limit**: 256000000 bytes
80
+
81
+ ## Task
82
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11609/instruction.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 583_E. Superior Periodic Subarrays
2
+
3
+ ## Problem Description
4
+ You are given an infinite periodic array a0, a1, ..., an - 1, ... with the period of length n. Formally, <image>. A periodic subarray (l, s) (0 ≤ l < n, 1 ≤ s < n) of array a is an infinite periodic array with a period of length s that is a subsegment of array a, starting with position l.
5
+
6
+ A periodic subarray (l, s) is superior, if when attaching it to the array a, starting from index l, any element of the subarray is larger than or equal to the corresponding element of array a. An example of attaching is given on the figure (top — infinite array a, bottom — its periodic subarray (l, s)):
7
+
8
+ <image>
9
+
10
+ Find the number of distinct pairs (l, s), corresponding to the superior periodic arrays.
11
+
12
+ Input
13
+
14
+ The first line contains number n (1 ≤ n ≤ 2·105). The second line contains n numbers a0, a1, ..., an - 1 (1 ≤ ai ≤ 106), separated by a space.
15
+
16
+ Output
17
+
18
+ Print a single integer — the sought number of pairs.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 4
25
+ 7 1 2 3
26
+
27
+
28
+ Output
29
+
30
+ 2
31
+
32
+
33
+ Input
34
+
35
+ 2
36
+ 2 1
37
+
38
+
39
+ Output
40
+
41
+ 1
42
+
43
+
44
+ Input
45
+
46
+ 3
47
+ 1 1 1
48
+
49
+
50
+ Output
51
+
52
+ 6
53
+
54
+ Note
55
+
56
+ In the first sample the superior subarrays are (0, 1) and (3, 2).
57
+
58
+ Subarray (0, 1) is superior, as a0 ≥ a0, a0 ≥ a1, a0 ≥ a2, a0 ≥ a3, a0 ≥ a0, ...
59
+
60
+ Subarray (3, 2) is superior a3 ≥ a3, a0 ≥ a0, a3 ≥ a1, a0 ≥ a2, a3 ≥ a3, ...
61
+
62
+ In the third sample any pair of (l, s) corresponds to a superior subarray as all the elements of an array are distinct.
63
+
64
+ ## Contest Information
65
+ - **Contest ID**: 583
66
+ - **Problem Index**: E
67
+ - **Points**: 1500.0
68
+ - **Rating**: 2400
69
+ - **Tags**: number theory
70
+ - **Time Limit**: {'seconds': 1, '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-11801/instruction.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 201_D. Brand New Problem
2
+
3
+ ## Problem Description
4
+ A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept.
5
+
6
+ You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs.
7
+
8
+ You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words.
9
+
10
+ The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer.
11
+
12
+ The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence.
13
+
14
+ Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise.
15
+
16
+ Input
17
+
18
+ The first line contains a single integer n (1 ≤ n ≤ 15) — the number of words in Lesha's problem. The second line contains n space-separated words — the short description of the problem.
19
+
20
+ The third line contains a single integer m (1 ≤ m ≤ 10) — the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 ≤ k ≤ 500000) is the number of words in the problem and si is a word of the problem description.
21
+
22
+ All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015.
23
+
24
+ Output
25
+
26
+ If Lesha's problem is brand new, print string "Brand new problem!" (without quotes).
27
+
28
+ Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input.
29
+
30
+ Examples
31
+
32
+ Input
33
+
34
+ 4
35
+ find the next palindrome
36
+ 1
37
+ 10 find the previous palindrome or print better luck next time
38
+
39
+
40
+ Output
41
+
42
+ 1
43
+ [:||||||:]
44
+
45
+
46
+ Input
47
+
48
+ 3
49
+ add two numbers
50
+ 3
51
+ 1 add
52
+ 2 two two
53
+ 3 numbers numbers numbers
54
+
55
+
56
+ Output
57
+
58
+ Brand new problem!
59
+
60
+
61
+ Input
62
+
63
+ 4
64
+ these papers are formulas
65
+ 3
66
+ 6 what are these formulas and papers
67
+ 5 papers are driving me crazy
68
+ 4 crazy into the night
69
+
70
+
71
+ Output
72
+
73
+ 1
74
+ [:||||:]
75
+
76
+
77
+ Input
78
+
79
+ 3
80
+ add two decimals
81
+ 5
82
+ 4 please two decimals add
83
+ 5 decimals want to be added
84
+ 4 two add decimals add
85
+ 4 add one two three
86
+ 7 one plus two plus three equals six
87
+
88
+
89
+ Output
90
+
91
+ 3
92
+ [:|||:]
93
+
94
+ Note
95
+
96
+ Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions — pairs of words "numbers" and "add", "numbers" and "two".
97
+
98
+ Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 ≤ i1 < i2 < ... < ik ≤ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements).
99
+
100
+ In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next").
101
+
102
+ In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence.
103
+
104
+ ## Contest Information
105
+ - **Contest ID**: 201
106
+ - **Problem Index**: D
107
+ - **Points**: 2000.0
108
+ - **Rating**: 2600
109
+ - **Tags**: bitmasks, brute force, dp
110
+ - **Time Limit**: {'seconds': 5, '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-11864/instruction.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01304 Heian-Kyo Walking
2
+
3
+ ## Problem Description
4
+ Heiankyo is known as a town with a grid of roads.
5
+
6
+ Hokusai, a cat who lives in Heiankyo, has to go from his home to a secret place on the outskirts of town every day for patrol. However, I get tired of following the same path every day, and there is a risk of being followed, so Hokusai wants to use a different route every day as much as possible. On the other hand, Hokusai has a troublesome smell, so I don't want to go down the road away from my destination.
7
+
8
+ There are Actinidia polygama on the roads here and there in Heiankyo, and Hokusai cannot go through the road where Actinidia polygama is falling. This is because if you go through such a road, you will be sick. Fortunately, there are no Actinidia polygama at the intersection.
9
+
10
+ Hokusai wants to know the number of possible routes from his home to a secret place. Here, Hokusai's home is at (0, 0) and the secret place is at (gx, gy). The roads are laid out in a grid with x = i (i is an integer) and y = j (j is an integer).
11
+
12
+ Notes on Submission
13
+
14
+ Multiple datasets are given in the above format. The first line of input data gives the number of datasets. Create a program that outputs the output for each data set in order in the above format.
15
+
16
+
17
+
18
+ Input
19
+
20
+ The first line of input is given the coordinates of the secret location (gx, gy). All of these are integers between 1 and 15 and are given separated by a single space. The second line is given the number of sections where Actinidia polygama is falling p (0 ≤ p ≤ 100), and the following lines p are given one section for each line where Actinidia polygama is falling. The p sections are different from each other. One interval is expressed in the form of x1 y1 x2 y2 and is a line segment of length 1 parallel to the x-axis or y-axis, with (x1, y1) and (x2, y2) as endpoints. x1 and x2 are in the range [0, gx] and y1 and y2 are in the range [0, gy].
21
+
22
+ Output
23
+
24
+ Output the number of possible routes. If there is no possible route, output "Miserable Hokusai!" On one line.
25
+
26
+ Example
27
+
28
+ Input
29
+
30
+ 4
31
+ 2 2
32
+ 0
33
+ 1 1
34
+ 2
35
+ 0 0 0 1
36
+ 0 0 1 0
37
+ 4 3
38
+ 4
39
+ 1 0 0 0
40
+ 3 3 4 3
41
+ 4 1 4 0
42
+ 0 2 0 3
43
+ 15 15
44
+ 0
45
+
46
+
47
+ Output
48
+
49
+ 6
50
+ Miserable Hokusai!
51
+ 5
52
+ 155117520
53
+
54
+ ## Contest Information
55
+ - **Contest ID**: 0
56
+ - **Problem Index**:
57
+ - **Points**: 0.0
58
+ - **Rating**: 0
59
+ - **Tags**:
60
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
61
+ - **Memory Limit**: 134217728 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-12025/instruction.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 588_A. Duff and Meat
2
+
3
+ ## Problem Description
4
+ Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
5
+
6
+ <image>
7
+
8
+ There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
9
+
10
+ Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
11
+
12
+ Input
13
+
14
+ The first line of input contains integer n (1 ≤ n ≤ 105), the number of days.
15
+
16
+ In the next n lines, i-th line contains two integers ai and pi (1 ≤ ai, pi ≤ 100), the amount of meat Duff needs and the cost of meat in that day.
17
+
18
+ Output
19
+
20
+ Print the minimum money needed to keep Duff happy for n days, in one line.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 3
27
+ 1 3
28
+ 2 2
29
+ 3 1
30
+
31
+
32
+ Output
33
+
34
+ 10
35
+
36
+
37
+ Input
38
+
39
+ 3
40
+ 1 3
41
+ 2 1
42
+ 3 2
43
+
44
+
45
+ Output
46
+
47
+ 8
48
+
49
+ Note
50
+
51
+ In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
52
+
53
+ In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
54
+
55
+ ## Contest Information
56
+ - **Contest ID**: 588
57
+ - **Problem Index**: A
58
+ - **Points**: 750.0
59
+ - **Rating**: 900
60
+ - **Tags**: greedy
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-1203/instruction.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 733_A. Grasshopper And the String
2
+
3
+ ## Problem Description
4
+ One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
5
+
6
+ Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
7
+
8
+ <image> The picture corresponds to the first example.
9
+
10
+ The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
11
+
12
+ Input
13
+
14
+ The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
15
+
16
+ Output
17
+
18
+ Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ ABABBBACFEYUKOTT
25
+
26
+
27
+ Output
28
+
29
+ 4
30
+
31
+ Input
32
+
33
+ AAA
34
+
35
+
36
+ Output
37
+
38
+ 1
39
+
40
+ ## Contest Information
41
+ - **Contest ID**: 733
42
+ - **Problem Index**: A
43
+ - **Points**: 500.0
44
+ - **Rating**: 1000
45
+ - **Tags**: implementation
46
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
47
+ - **Memory Limit**: 256000000 bytes
48
+
49
+ ## Task
50
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12040/instruction.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 932_B. Recursive Queries
2
+
3
+ ## Problem Description
4
+ Let us define two functions f and g on positive integer numbers.
5
+
6
+ <image>
7
+
8
+ <image>
9
+
10
+ You need to process Q queries. In each query, you will be given three integers l, r and k. You need to print the number of integers x between l and r inclusive, such that g(x) = k.
11
+
12
+ Input
13
+
14
+ The first line of the input contains an integer Q (1 ≤ Q ≤ 2 × 105) representing the number of queries.
15
+
16
+ Q lines follow, each of which contains 3 integers l, r and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).
17
+
18
+ Output
19
+
20
+ For each query, print a single line containing the answer for that query.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 4
27
+ 22 73 9
28
+ 45 64 6
29
+ 47 55 7
30
+ 2 62 4
31
+
32
+
33
+ Output
34
+
35
+ 1
36
+ 4
37
+ 0
38
+ 8
39
+
40
+
41
+ Input
42
+
43
+ 4
44
+ 82 94 6
45
+ 56 67 4
46
+ 28 59 9
47
+ 39 74 4
48
+
49
+
50
+ Output
51
+
52
+ 3
53
+ 1
54
+ 1
55
+ 5
56
+
57
+ Note
58
+
59
+ In the first example:
60
+
61
+ * g(33) = 9 as g(33) = g(3 × 3) = g(9) = 9
62
+ * g(47) = g(48) = g(60) = g(61) = 6
63
+ * There are no such integers between 47 and 55.
64
+ * g(4) = g(14) = g(22) = g(27) = g(39) = g(40) = g(41) = g(58) = 4
65
+
66
+ ## Contest Information
67
+ - **Contest ID**: 932
68
+ - **Problem Index**: B
69
+ - **Points**: 1000.0
70
+ - **Rating**: 1300
71
+ - **Tags**: binary search, data structures, dfs and similar
72
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
73
+ - **Memory Limit**: 256000000 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-12217/instruction.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 205_C. Little Elephant and Interval
2
+
3
+ ## Problem Description
4
+ The Little Elephant very much loves sums on intervals.
5
+
6
+ This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
7
+
8
+ Help him and count the number of described numbers x for a given pair l and r.
9
+
10
+ Input
11
+
12
+ The single line contains a pair of integers l and r (1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval.
13
+
14
+ Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
15
+
16
+ Output
17
+
18
+ On a single line print a single integer — the answer to the problem.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 2 47
25
+
26
+
27
+ Output
28
+
29
+ 12
30
+
31
+
32
+ Input
33
+
34
+ 47 1024
35
+
36
+
37
+ Output
38
+
39
+ 98
40
+
41
+ Note
42
+
43
+ In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
44
+
45
+ ## Contest Information
46
+ - **Contest ID**: 205
47
+ - **Problem Index**: C
48
+ - **Points**: 500.0
49
+ - **Rating**: 1500
50
+ - **Tags**: binary search, combinatorics, dp
51
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
52
+ - **Memory Limit**: 256000000 bytes
53
+
54
+ ## Task
55
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12272/instruction.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00135 Clock Short Hand and Long Hand
2
+
3
+ ## Problem Description
4
+ A mischievous notice has arrived from the primitive slow-life organization "Akaruda". Akaruda is famous for mischief such as throwing a pie at the face of a VIP, but recently it has become more radical, such as using gunpowder to sprinkle rat fireworks at the reception venue. The notice is the following text.
5
+
6
+
7
+ --- Personal computer Takes human time. not good.
8
+ When the short and long hands of the clock meet, Akaruda justice is done.
9
+ Slow life great.
10
+
11
+
12
+ It's terrifying and I'm not sure, but it seems to mean that the mischief is carried out when the minute hand and the minute hand of the clock overlap.
13
+
14
+ To be wary of this mischief, create a program that inputs the time and outputs "alert" if the short hand and the long hand are close, "safe" if they are far, and "warning" otherwise. However, "close" means that the angle between the short hand and the long hand is 0 ° or more and less than 30 °, and "far" means that the angle is 90 ° or more and 180 ° or less. The time should be between 00:00 and 11:59.
15
+
16
+
17
+
18
+ Input
19
+
20
+ The input is given in the following format:
21
+
22
+
23
+ n
24
+ hh1: mm1
25
+ hh2: mm2
26
+ ::
27
+ hhn: mmn
28
+
29
+
30
+ The number of times to be judged on the first line n (1 ≤ n ≤ 10000), and the i-th time hhi: mmi on the second and subsequent lines are given to each line.
31
+
32
+ Output
33
+
34
+ Output the judgment result of the i-th time safe, warning, or alert in order on one line.
35
+
36
+ Example
37
+
38
+ Input
39
+
40
+ 4
41
+ 02:15
42
+ 06:01
43
+ 11:55
44
+ 10:40
45
+
46
+
47
+ Output
48
+
49
+ alert
50
+ safe
51
+ alert
52
+ warning
53
+
54
+ ## Contest Information
55
+ - **Contest ID**: 0
56
+ - **Problem Index**:
57
+ - **Points**: 0.0
58
+ - **Rating**: 0
59
+ - **Tags**:
60
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
61
+ - **Memory Limit**: 134217728 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-12286/instruction.md ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02221 Tournament
2
+
3
+ ## Problem Description
4
+ Problem statement
5
+
6
+ A $ 2 $ human-player match-up game tournament is about to take place in front of Kyoto University Camphor Tree.
7
+
8
+ There are $ 2 ^ N $ participants in this tournament, numbered from $ 1 $ to $ 2 ^ N $.
9
+
10
+ Winning or losing when $ 2 $ of participants fight is represented by the $ 2 ^ N-1 $ string $ S $ consisting of $ 0 $ and $ 1 $.
11
+
12
+ When people $ x $ and people $ y $$ (1 \ le x <y \ le 2 ^ N) $ fight
13
+
14
+ * When $ S_ {y-x} = 0 $, the person $ x $ wins,
15
+ * When $ S_ {y-x} = 1 $, the person $ y $ wins
16
+
17
+
18
+
19
+ I know that.
20
+
21
+ The tournament begins with a line of participants and proceeds as follows:
22
+
23
+ 1. Make a pair of $ 2 $ people from the beginning of the column. For every pair, $ 2 $ people in the pair fight.
24
+ 2. Those who win the match in 1 will remain in the line, and those who lose will leave the line.
25
+ 3. If there are more than $ 2 $ left, fill the column back to 1.
26
+ 4. If there are $ 1 $ left, that person will be the winner.
27
+
28
+
29
+
30
+ Now, the participants are initially arranged so that the $ i $ th $ (1 \ le i \ le 2 ^ N) $ from the beginning becomes the person $ P_i $.
31
+
32
+ Solve the following problem for all integers $ k $ that satisfy $ 0 \ le k \ le 2 ^ N-1 $.
33
+
34
+ * From the initial state, the first $ k $ person moves to the end of the column without changing the order.
35
+ * In other words, if you list the number of participants in the moved column from the beginning, $ P_ {k + 1}, P_ {k + 2}, ..., P_ {2 ^ N}, P_1, P_2, ..., P_k $.
36
+ * Find the winner's number when you start the tournament from the line after the move.
37
+
38
+
39
+
40
+ Constraint
41
+
42
+ * $ 1 \ leq N \ leq 18 $
43
+ * $ N $ is an integer.
44
+ * $ S $ is a $ 2 ^ N-1 $ string consisting of $ 0 $ and $ 1 $.
45
+ * $ P $ is a permutation of integers from $ 1 $ to $ 2 ^ N $.
46
+
47
+
48
+
49
+ * * *
50
+
51
+ input
52
+
53
+ Input is given from standard input in the following format.
54
+
55
+
56
+ $ N $
57
+ $ S_1S_2 \ ldots S_ {2 ^ N-1} $
58
+ $ P_1 $ $ P_2 $ $ \ ldots $ $ P_ {2 ^ N} $
59
+
60
+
61
+ output
62
+
63
+ Output $ 2 ^ N $ lines.
64
+
65
+ In the $ i $ line $ (1 \ le i \ le 2 ^ N) $, output the answer to the above problem when $ k = i-1 $.
66
+
67
+ * * *
68
+
69
+ Input example 1
70
+
71
+
72
+ 2
73
+ 100
74
+ 1 4 2 3
75
+
76
+
77
+ Output example 1
78
+
79
+
80
+ 1
81
+ 2
82
+ 1
83
+ 2
84
+
85
+
86
+ For example, if $ k = 2 $, the number of participants in the moved column will be $ 2, 3, 1, 4 $ from the beginning.
87
+
88
+ When person $ 2 $ and person $ 3 $ fight, person $ 3 $ wins over $ S_1 = 1 $.
89
+
90
+ When person $ 1 $ and person $ 4 $ fight, person $ 1 $ wins over $ S_3 = 0 $.
91
+
92
+ When person $ 3 $ and person $ 1 $ fight, person $ 1 $ wins over $ S_2 = 0 $.
93
+
94
+ Therefore, if $ k = 2 $, the winner would be $ 1 $ person.
95
+
96
+ * * *
97
+
98
+ Input example 2
99
+
100
+
101
+ Four
102
+ 101011100101000
103
+ 8 15 2 9 12 5 1 7 14 10 11 3 4 6 16 13
104
+
105
+
106
+ Output example 2
107
+
108
+
109
+ 16
110
+ 1
111
+ 16
112
+ 2
113
+ 16
114
+ 12
115
+ Ten
116
+ 14
117
+ 16
118
+ 1
119
+ 16
120
+ 2
121
+ 16
122
+ 12
123
+ Ten
124
+ 14
125
+
126
+
127
+ * * *
128
+
129
+ Input example 3
130
+
131
+
132
+ 1
133
+ 0
134
+ 1 2
135
+
136
+
137
+ Output example 3
138
+
139
+
140
+ 1
141
+ 1
142
+
143
+
144
+
145
+
146
+
147
+
148
+ Example
149
+
150
+ Input
151
+
152
+ 2
153
+ 100
154
+ 1 4 2 3
155
+
156
+
157
+ Output
158
+
159
+ 1
160
+ 2
161
+ 1
162
+ 2
163
+
164
+ ## Contest Information
165
+ - **Contest ID**: 0
166
+ - **Problem Index**:
167
+ - **Points**: 0.0
168
+ - **Rating**: 0
169
+ - **Tags**:
170
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
171
+ - **Memory Limit**: 268435456 bytes
172
+
173
+ ## Task
174
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12424/instruction.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 189_E. Weak Memory
2
+
3
+ ## Problem Description
4
+ Zart PMP is qualified for ICPC World Finals in Harbin, China. After team excursion to Sun Island Park for snow sculpture art exposition, PMP should get back to buses before they leave. But the park is really big and he does not know how to find them.
5
+
6
+ The park has n intersections numbered 1 through n. There are m bidirectional roads that connect some pairs of these intersections. At k intersections, ICPC volunteers are helping the teams and showing them the way to their destinations. Locations of volunteers are fixed and distinct.
7
+
8
+ When PMP asks a volunteer the way to bus station, he/she can tell him the whole path. But the park is fully covered with ice and snow and everywhere looks almost the same. So PMP can only memorize at most q intersections after each question (excluding the intersection they are currently standing). He always tells volunteers about his weak memory and if there is no direct path of length (in number of roads) at most q that leads to bus station, the volunteer will guide PMP to another volunteer (who is at most q intersections away, of course). ICPC volunteers know the area very well and always tell PMP the best way. So if there exists a way to bus stations, PMP will definitely find it.
9
+
10
+ PMP's initial location is intersection s and the buses are at intersection t. There will always be a volunteer at intersection s. Your job is to find out the minimum q which guarantees that PMP can find the buses.
11
+
12
+ Input
13
+
14
+ The first line contains three space-separated integers n, m, k (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105, 1 ≤ k ≤ n) — the number of intersections, roads and volunteers, respectively. Next line contains k distinct space-separated integers between 1 and n inclusive — the numbers of cities where volunteers are located.
15
+
16
+ Next m lines describe the roads. The i-th of these lines contains two space-separated integers ui, vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — two intersections that i-th road connects. There will be at most one road between any two intersections.
17
+
18
+ Last line of input contains two space-separated integers s, t (1 ≤ s, t ≤ n, s ≠ t) — the initial location of PMP and the location of the buses. It might not always be possible to reach t from s.
19
+
20
+ It is guaranteed that there is always a volunteer at intersection s.
21
+
22
+ Output
23
+
24
+ Print on the only line the answer to the problem — the minimum value of q which guarantees that PMP can find the buses. If PMP cannot reach the buses at all, output -1 instead.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 6 6 3
31
+ 1 3 6
32
+ 1 2
33
+ 2 3
34
+ 4 2
35
+ 5 6
36
+ 4 5
37
+ 3 4
38
+ 1 6
39
+
40
+
41
+ Output
42
+
43
+ 3
44
+
45
+
46
+ Input
47
+
48
+ 6 5 3
49
+ 1 5 6
50
+ 1 2
51
+ 2 3
52
+ 3 4
53
+ 4 5
54
+ 6 3
55
+ 1 5
56
+
57
+
58
+ Output
59
+
60
+ 3
61
+
62
+ Note
63
+
64
+ The first sample is illustrated below. Blue intersections are where volunteers are located. If PMP goes in the path of dashed line, it can reach the buses with q = 3:
65
+
66
+ <image>
67
+
68
+ In the second sample, PMP uses intersection 6 as an intermediate intersection, thus the answer is 3.
69
+
70
+ ## Contest Information
71
+ - **Contest ID**: 189
72
+ - **Problem Index**: E
73
+ - **Points**: 1500.0
74
+ - **Rating**: 2000
75
+ - **Tags**: dfs and similar, dsu
76
+ - **Time Limit**: {'seconds': 2, '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-12441/instruction.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 594_D. REQ
2
+
3
+ ## Problem Description
4
+ Today on a math lesson the teacher told Vovochka that the Euler function of a positive integer φ(n) is an arithmetic function that counts the positive integers less than or equal to n that are relatively prime to n. The number 1 is coprime to all the positive integers and φ(1) = 1.
5
+
6
+ Now the teacher gave Vovochka an array of n positive integers a1, a2, ..., an and a task to process q queries li ri — to calculate and print <image> modulo 109 + 7. As it is too hard for a second grade school student, you've decided to help Vovochka.
7
+
8
+ Input
9
+
10
+ The first line of the input contains number n (1 ≤ n ≤ 200 000) — the length of the array given to Vovochka. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106).
11
+
12
+ The third line contains integer q (1 ≤ q ≤ 200 000) — the number of queries. Next q lines contain the queries, one per line. Each query is defined by the boundaries of the segment li and ri (1 ≤ li ≤ ri ≤ n).
13
+
14
+ Output
15
+
16
+ Print q numbers — the value of the Euler function for each query, calculated modulo 109 + 7.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 10
23
+ 1 2 3 4 5 6 7 8 9 10
24
+ 7
25
+ 1 1
26
+ 3 8
27
+ 5 6
28
+ 4 8
29
+ 8 10
30
+ 7 9
31
+ 7 10
32
+
33
+
34
+ Output
35
+
36
+ 1
37
+ 4608
38
+ 8
39
+ 1536
40
+ 192
41
+ 144
42
+ 1152
43
+
44
+
45
+ Input
46
+
47
+ 7
48
+ 24 63 13 52 6 10 1
49
+ 6
50
+ 3 5
51
+ 4 7
52
+ 1 7
53
+ 2 4
54
+ 3 6
55
+ 2 6
56
+
57
+
58
+ Output
59
+
60
+ 1248
61
+ 768
62
+ 12939264
63
+ 11232
64
+ 9984
65
+ 539136
66
+
67
+ Note
68
+
69
+ In the second sample the values are calculated like that:
70
+
71
+ * φ(13·52·6) = φ(4056) = 1248
72
+ * φ(52·6·10·1) = φ(3120) = 768
73
+ * φ(24·63·13·52·6·10·1) = φ(61326720) = 12939264
74
+ * φ(63·13·52) = φ(42588) = 11232
75
+ * φ(13·52·6·10) = φ(40560) = 9984
76
+ * φ(63·13·52·6·10) = φ(2555280) = 539136
77
+
78
+ ## Contest Information
79
+ - **Contest ID**: 594
80
+ - **Problem Index**: D
81
+ - **Points**: 2000.0
82
+ - **Rating**: 2500
83
+ - **Tags**: data structures, number theory
84
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
85
+ - **Memory Limit**: 256000000 bytes
86
+
87
+ ## Task
88
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1259/instruction.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1027_A. Palindromic Twist
2
+
3
+ ## Problem Description
4
+ You are given a string s consisting of n lowercase Latin letters. n is even.
5
+
6
+ For each position i (1 ≤ i ≤ n) in string s you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.
7
+
8
+ For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.
9
+
10
+ That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' → 'd', 'o' → 'p', 'd' → 'e', 'e' → 'd', 'f' → 'e', 'o' → 'p', 'r' → 'q', 'c' → 'b', 'e' → 'f', 's' → 't').
11
+
12
+ String s is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.
13
+
14
+ Your goal is to check if it's possible to make string s a palindrome by applying the aforementioned changes to every position. Print "YES" if string s can be transformed to a palindrome and "NO" otherwise.
15
+
16
+ Each testcase contains several strings, for each of them you are required to solve the problem separately.
17
+
18
+ Input
19
+
20
+ The first line contains a single integer T (1 ≤ T ≤ 50) — the number of strings in a testcase.
21
+
22
+ Then 2T lines follow — lines (2i - 1) and 2i of them describe the i-th string. The first line of the pair contains a single integer n (2 ≤ n ≤ 100, n is even) — the length of the corresponding string. The second line of the pair contains a string s, consisting of n lowercase Latin letters.
23
+
24
+ Output
25
+
26
+ Print T lines. The i-th line should contain the answer to the i-th string of the input. Print "YES" if it's possible to make the i-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise.
27
+
28
+ Example
29
+
30
+ Input
31
+
32
+ 5
33
+ 6
34
+ abccba
35
+ 2
36
+ cf
37
+ 4
38
+ adfa
39
+ 8
40
+ abaazaba
41
+ 2
42
+ ml
43
+
44
+
45
+ Output
46
+
47
+ YES
48
+ NO
49
+ YES
50
+ NO
51
+ NO
52
+
53
+ Note
54
+
55
+ The first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.
56
+
57
+ The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.
58
+
59
+ The third string can be changed to "beeb" which is a palindrome.
60
+
61
+ The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm".
62
+
63
+ ## Contest Information
64
+ - **Contest ID**: 1027
65
+ - **Problem Index**: A
66
+ - **Points**: 0.0
67
+ - **Rating**: 1000
68
+ - **Tags**: implementation, strings
69
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
70
+ - **Memory Limit**: 256000000 bytes
71
+
72
+ ## Task
73
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12616/instruction.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1228_E. Another Filling the Grid
2
+
3
+ ## Problem Description
4
+ You have n × n square grid and an integer k. Put an integer in each cell while satisfying the conditions below.
5
+
6
+ * All numbers in the grid should be between 1 and k inclusive.
7
+ * Minimum number of the i-th row is 1 (1 ≤ i ≤ n).
8
+ * Minimum number of the j-th column is 1 (1 ≤ j ≤ n).
9
+
10
+
11
+
12
+ Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo (10^{9} + 7).
13
+
14
+ <image> These are the examples of valid and invalid grid when n=k=2.
15
+
16
+ Input
17
+
18
+ The only line contains two integers n and k (1 ≤ n ≤ 250, 1 ≤ k ≤ 10^{9}).
19
+
20
+ Output
21
+
22
+ Print the answer modulo (10^{9} + 7).
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+
29
+ 2 2
30
+
31
+
32
+ Output
33
+
34
+
35
+ 7
36
+
37
+
38
+ Input
39
+
40
+
41
+ 123 456789
42
+
43
+
44
+ Output
45
+
46
+
47
+ 689974806
48
+
49
+ Note
50
+
51
+ In the first example, following 7 cases are possible.
52
+
53
+ <image>
54
+
55
+ In the second example, make sure you print the answer modulo (10^{9} + 7).
56
+
57
+ ## Contest Information
58
+ - **Contest ID**: 1228
59
+ - **Problem Index**: E
60
+ - **Points**: 2250.0
61
+ - **Rating**: 2300
62
+ - **Tags**: combinatorics, dp, math
63
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
64
+ - **Memory Limit**: 256000000 bytes
65
+
66
+ ## Task
67
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12629/instruction.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1515_B. Phoenix and Puzzle
2
+
3
+ ## Problem Description
4
+ Phoenix is playing with a new puzzle, which consists of n identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.
5
+
6
+ <image> A puzzle piece
7
+
8
+ The goal of the puzzle is to create a square using the n pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all n pieces must be used (of course, the square shouldn't contain any holes as well). Can he do it?
9
+
10
+ Input
11
+
12
+ The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases.
13
+
14
+ The first line of each test case contains an integer n (1 ≤ n ≤ 10^9) — the number of puzzle pieces.
15
+
16
+ Output
17
+
18
+ For each test case, if Phoenix can create a square with the n puzzle pieces, print YES. Otherwise, print NO.
19
+
20
+ Example
21
+
22
+ Input
23
+
24
+
25
+ 3
26
+ 2
27
+ 4
28
+ 6
29
+
30
+
31
+ Output
32
+
33
+
34
+ YES
35
+ YES
36
+ NO
37
+
38
+ Note
39
+
40
+ For n=2, Phoenix can create a square like this:
41
+
42
+ <image>
43
+
44
+ For n=4, Phoenix can create a square like this:
45
+
46
+ <image>
47
+
48
+ For n=6, it is impossible for Phoenix to create a square.
49
+
50
+ ## Contest Information
51
+ - **Contest ID**: 1515
52
+ - **Problem Index**: B
53
+ - **Points**: 1000.0
54
+ - **Rating**: 1000
55
+ - **Tags**: brute force, geometry, math, number theory
56
+ - **Time Limit**: {'seconds': 2, '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-12673/instruction.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # precedence-rule
2
+
3
+ ## Problem Description
4
+ In the Mathematical world of Dr. Ramanujam, every new student must have to pass a exam to take the classes of Advance mathematics from Dr. Ramanujam.
5
+ One day Ram wants to have classes of Advance mathematics, so he arrived at class of Dr. Ramanujam. He asked ram to solve a given mathematical expression then only he will be eligible to take classes. Mathematical expression is in a string form of numbers(0-9) and operators(+,-,).* Dr. Ramanujam asked him to find the answer of the expression but there is a twist that, he does not want him to follow "Operator precedence rule", rather he have his own precedence rule in which he need to operate operations from right to left.
6
+
7
+ For eg: Given string 2 + 3 * 5, So 3 * 5 will be operated first then +2 will be performed in result of 3 * 5.
8
+
9
+ He asked him to solve as fast as possible. So Ram needs your help to solve the expression.
10
+
11
+ INPUT:
12
+
13
+ First line contain test cases T. Next T lines contain one string of odd length always.
14
+
15
+ 1 ≤ T ≤ 100
16
+
17
+ 1 ≤ Length of the String(L) ≤ 31
18
+
19
+ Number of operands=(L+1)/2
20
+
21
+ Number of operator=(L-1)/2
22
+
23
+ OUTPUT:
24
+
25
+ Answer of the given expression.
26
+
27
+ SAMPLE INPUT
28
+ 2
29
+ 2+3*5
30
+ 1*2*3
31
+
32
+ SAMPLE OUTPUT
33
+ 17
34
+ 6
35
+
36
+ ## Contest Information
37
+ - **Contest ID**: 0
38
+ - **Problem Index**:
39
+ - **Points**: 0.0
40
+ - **Rating**: 0
41
+ - **Tags**: None
42
+ - **Time Limit**: None seconds
43
+ - **Memory Limit**: 0 bytes
44
+
45
+ ## Task
46
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12819/instruction.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1130_C. Connect
2
+
3
+ ## Problem Description
4
+ Alice lives on a flat planet that can be modeled as a square grid of size n × n, with rows and columns enumerated from 1 to n. We represent the cell at the intersection of row r and column c with ordered pair (r, c). Each cell in the grid is either land or water.
5
+
6
+ <image> An example planet with n = 5. It also appears in the first sample test.
7
+
8
+ Alice resides in land cell (r_1, c_1). She wishes to travel to land cell (r_2, c_2). At any moment, she may move to one of the cells adjacent to where she is—in one of the four directions (i.e., up, down, left, or right).
9
+
10
+ Unfortunately, Alice cannot swim, and there is no viable transportation means other than by foot (i.e., she can walk only on land). As a result, Alice's trip may be impossible.
11
+
12
+ To help Alice, you plan to create at most one tunnel between some two land cells. The tunnel will allow Alice to freely travel between the two endpoints. Indeed, creating a tunnel is a lot of effort: the cost of creating a tunnel between cells (r_s, c_s) and (r_t, c_t) is (r_s-r_t)^2 + (c_s-c_t)^2.
13
+
14
+ For now, your task is to find the minimum possible cost of creating at most one tunnel so that Alice could travel from (r_1, c_1) to (r_2, c_2). If no tunnel needs to be created, the cost is 0.
15
+
16
+ Input
17
+
18
+ The first line contains one integer n (1 ≤ n ≤ 50) — the width of the square grid.
19
+
20
+ The second line contains two space-separated integers r_1 and c_1 (1 ≤ r_1, c_1 ≤ n) — denoting the cell where Alice resides.
21
+
22
+ The third line contains two space-separated integers r_2 and c_2 (1 ≤ r_2, c_2 ≤ n) — denoting the cell to which Alice wishes to travel.
23
+
24
+ Each of the following n lines contains a string of n characters. The j-th character of the i-th such line (1 ≤ i, j ≤ n) is 0 if (i, j) is land or 1 if (i, j) is water.
25
+
26
+ It is guaranteed that (r_1, c_1) and (r_2, c_2) are land.
27
+
28
+ Output
29
+
30
+ Print an integer that is the minimum possible cost of creating at most one tunnel so that Alice could travel from (r_1, c_1) to (r_2, c_2).
31
+
32
+ Examples
33
+
34
+ Input
35
+
36
+
37
+ 5
38
+ 1 1
39
+ 5 5
40
+ 00001
41
+ 11111
42
+ 00111
43
+ 00110
44
+ 00110
45
+
46
+
47
+ Output
48
+
49
+
50
+ 10
51
+
52
+
53
+ Input
54
+
55
+
56
+ 3
57
+ 1 3
58
+ 3 1
59
+ 010
60
+ 101
61
+ 010
62
+
63
+
64
+ Output
65
+
66
+
67
+ 8
68
+
69
+ Note
70
+
71
+ In the first sample, a tunnel between cells (1, 4) and (4, 5) should be created. The cost of doing so is (1-4)^2 + (4-5)^2 = 10, which is optimal. This way, Alice could walk from (1, 1) to (1, 4), use the tunnel from (1, 4) to (4, 5), and lastly walk from (4, 5) to (5, 5).
72
+
73
+ In the second sample, clearly a tunnel between cells (1, 3) and (3, 1) needs to be created. The cost of doing so is (1-3)^2 + (3-1)^2 = 8.
74
+
75
+ ## Contest Information
76
+ - **Contest ID**: 1130
77
+ - **Problem Index**: C
78
+ - **Points**: 1500.0
79
+ - **Rating**: 1400
80
+ - **Tags**: brute force, dfs and similar, dsu
81
+ - **Time Limit**: {'seconds': 1, '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-13159/instruction.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 355_B. Vasya and Public Transport
2
+
3
+ ## Problem Description
4
+ Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m.
5
+
6
+ Public transport is not free. There are 4 types of tickets:
7
+
8
+ 1. A ticket for one ride on some bus or trolley. It costs c1 burles;
9
+ 2. A ticket for an unlimited number of rides on some bus or on some trolley. It costs c2 burles;
10
+ 3. A ticket for an unlimited number of rides on all buses or all trolleys. It costs c3 burles;
11
+ 4. A ticket for an unlimited number of rides on all buses and trolleys. It costs c4 burles.
12
+
13
+
14
+
15
+ Vasya knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of burles he will have to spend on the tickets.
16
+
17
+ Input
18
+
19
+ The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets.
20
+
21
+ The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use.
22
+
23
+ The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is going to use the bus number i.
24
+
25
+ The fourth line contains m integers bi (0 ≤ bi ≤ 1000) — the number of times Vasya is going to use the trolley number i.
26
+
27
+ Output
28
+
29
+ Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
30
+
31
+ Examples
32
+
33
+ Input
34
+
35
+ 1 3 7 19
36
+ 2 3
37
+ 2 5
38
+ 4 4 4
39
+
40
+
41
+ Output
42
+
43
+ 12
44
+
45
+
46
+ Input
47
+
48
+ 4 3 2 1
49
+ 1 3
50
+ 798
51
+ 1 2 3
52
+
53
+
54
+ Output
55
+
56
+ 1
57
+
58
+
59
+ Input
60
+
61
+ 100 100 8 100
62
+ 3 5
63
+ 7 94 12
64
+ 100 1 47 0 42
65
+
66
+
67
+ Output
68
+
69
+ 16
70
+
71
+ Note
72
+
73
+ In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles.
74
+
75
+ In the second sample the profitable strategy is to buy one ticket of the fourth type.
76
+
77
+ In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.
78
+
79
+ ## Contest Information
80
+ - **Contest ID**: 355
81
+ - **Problem Index**: B
82
+ - **Points**: 1000.0
83
+ - **Rating**: 1100
84
+ - **Tags**: greedy, implementation
85
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
86
+ - **Memory Limit**: 256000000 bytes
87
+
88
+ ## Task
89
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1455/instruction.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01608 1
2
+
3
+ ## Problem Description
4
+ 1
5
+
6
+ Problem Statement
7
+
8
+ There is a bit string of length n.
9
+
10
+ When the i-th bit from the left is 1, the score is a_i points.
11
+ The number of 1s within the distance w around the i-th bit from the left (= | \\ {j \ in \\ {1, ..., n \\} ∩ \\ {iw, ..., i + w \\} | When the jth bit from the left is 1 \\} |) is odd, the score is b_i.
12
+
13
+ Find the bit string that gives the most scores.
14
+
15
+ Constraints
16
+
17
+ * 1 ≤ n ≤ 1,000
18
+ * 1 ≤ w ≤ 1,000
19
+ * 0 ≤ a_i ≤ 10 ^ 5
20
+ * 0 ≤ b_i ≤ 10 ^ 5
21
+
22
+ Input
23
+
24
+ Input follows the following format. All given numbers are integers.
25
+
26
+
27
+ n w
28
+ a_1 ... a_n
29
+ b_1 ... b_n
30
+
31
+ Output
32
+
33
+ Output the bit string that gives the most scores on one line.
34
+ If there are multiple such solutions, any of them may be output.
35
+
36
+ Examples
37
+
38
+ Input
39
+
40
+ 4 1
41
+ 3 1 2 7
42
+ 13 8 25 9
43
+
44
+
45
+ Output
46
+
47
+ 1001
48
+
49
+
50
+ Input
51
+
52
+ 2 1
53
+ 1 1
54
+ 3 3
55
+
56
+
57
+ Output
58
+
59
+ 10
60
+
61
+ ## Contest Information
62
+ - **Contest ID**: 0
63
+ - **Problem Index**:
64
+ - **Points**: 0.0
65
+ - **Rating**: 0
66
+ - **Tags**:
67
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
68
+ - **Memory Limit**: 134217728 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-1602/instruction.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 283_C. Coin Troubles
2
+
3
+ ## Problem Description
4
+ In the Isle of Guernsey there are n different types of coins. For each i (1 ≤ i ≤ n), coin of type i is worth ai cents. It is possible that ai = aj for some i and j (i ≠ j).
5
+
6
+ Bessie has some set of these coins totaling t cents. She tells Jessie q pairs of integers. For each i (1 ≤ i ≤ q), the pair bi, ci tells Jessie that Bessie has a strictly greater number of coins of type bi than coins of type ci. It is known that all bi are distinct and all ci are distinct.
7
+
8
+ Help Jessie find the number of possible combinations of coins Bessie could have. Two combinations are considered different if there is some i (1 ≤ i ≤ n), such that the number of coins Bessie has of type i is different in the two combinations. Since the answer can be very large, output it modulo 1000000007 (109 + 7).
9
+
10
+ If there are no possible combinations of coins totaling t cents that satisfy Bessie's conditions, output 0.
11
+
12
+ Input
13
+
14
+ The first line contains three space-separated integers, n, q and t (1 ≤ n ≤ 300; 0 ≤ q ≤ n; 1 ≤ t ≤ 105). The second line contains n space separated integers, a1, a2, ..., an (1 ≤ ai ≤ 105). The next q lines each contain two distinct space-separated integers, bi and ci (1 ≤ bi, ci ≤ n; bi ≠ ci).
15
+
16
+ It's guaranteed that all bi are distinct and all ci are distinct.
17
+
18
+ Output
19
+
20
+ A single integer, the number of valid coin combinations that Bessie could have, modulo 1000000007 (109 + 7).
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 4 2 17
27
+ 3 1 2 5
28
+ 4 2
29
+ 3 4
30
+
31
+
32
+ Output
33
+
34
+ 3
35
+
36
+
37
+ Input
38
+
39
+ 3 2 6
40
+ 3 1 1
41
+ 1 2
42
+ 2 3
43
+
44
+
45
+ Output
46
+
47
+ 0
48
+
49
+
50
+ Input
51
+
52
+ 3 2 10
53
+ 1 2 3
54
+ 1 2
55
+ 2 1
56
+
57
+
58
+ Output
59
+
60
+ 0
61
+
62
+ Note
63
+
64
+ For the first sample, the following 3 combinations give a total of 17 cents and satisfy the given conditions: {0 of type 1, 1 of type 2, 3 of type 3, 2 of type 4}, {0, 0, 6, 1}, {2, 0, 3, 1}.
65
+
66
+ No other combinations exist. Note that even though 4 occurs in both bi and ci, the problem conditions are still satisfied because all bi are distinct and all ci are distinct.
67
+
68
+ ## Contest Information
69
+ - **Contest ID**: 283
70
+ - **Problem Index**: C
71
+ - **Points**: 1500.0
72
+ - **Rating**: 2100
73
+ - **Tags**: dp
74
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
75
+ - **Memory Limit**: 256000000 bytes
76
+
77
+ ## Task
78
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1658/instruction.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00818 Viva Confetti
2
+
3
+ ## Problem Description
4
+ Do you know confetti? They are small discs of colored paper, and people throw them around during parties or festivals. Since people throw lots of confetti, they may end up stacked one on another, so there may be hidden ones underneath.
5
+
6
+ A handful of various sized confetti have been dropped on a table. Given their positions and sizes, can you tell us how many of them you can see?
7
+
8
+ The following figure represents the disc configuration for the first sample input, where the bottom disc is still visible.
9
+
10
+ <image>
11
+
12
+
13
+
14
+ Input
15
+
16
+ The input is composed of a number of configurations of the following form.
17
+
18
+
19
+ n
20
+ x1 y1 z1
21
+ x2 y2 z2
22
+ .
23
+ .
24
+ .
25
+ xn yn zn
26
+
27
+
28
+ The first line in a configuration is the number of discs in the configuration (a positive integer not more than 100), followed by one Ine descriptions of each disc: coordinates of its center and radius, expressed as real numbers in decimal notation, with up to 12 digits after the decimal point. The imprecision margin is ±5 × 10-13. That is, it is guaranteed that variations of less than ±5 × 10-13 on input values do not change which discs are visible. Coordinates of all points contained in discs are between -10 and 10.
29
+
30
+ Confetti are listed in their stacking order, x1 y1 r1 being the bottom one and xn yn rn the top one. You are observing from the top.
31
+
32
+ The end of the input is marked by a zero on a single line.
33
+
34
+ Output
35
+
36
+ For each configuration you should output the number of visible confetti on a single line.
37
+
38
+ Example
39
+
40
+ Input
41
+
42
+ 3
43
+ 0 0 0.5
44
+ -0.9 0 1.00000000001
45
+ 0.9 0 1.00000000001
46
+ 5
47
+ 0 1 0.5
48
+ 1 1 1.00000000001
49
+ 0 2 1.00000000001
50
+ -1 1 1.00000000001
51
+ 0 -0.00001 1.00000000001
52
+ 5
53
+ 0 1 0.5
54
+ 1 1 1.00000000001
55
+ 0 2 1.00000000001
56
+ -1 1 1.00000000001
57
+ 0 0 1.00000000001
58
+ 2
59
+ 0 0 1.0000001
60
+ 0 0 1
61
+ 2
62
+ 0 0 1
63
+ 0.00000001 0 1
64
+ 0
65
+
66
+
67
+ Output
68
+
69
+ 3
70
+ 5
71
+ 4
72
+ 2
73
+ 2
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**: 134217728 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-1857/instruction.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03434 AtCoder Beginner Contest 088 - Card Game for Two
2
+
3
+ ## Problem Description
4
+ We have N cards. A number a_i is written on the i-th card.
5
+ Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
6
+ The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
7
+
8
+ Constraints
9
+
10
+ * N is an integer between 1 and 100 (inclusive).
11
+ * a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
12
+
13
+ Input
14
+
15
+ Input is given from Standard Input in the following format:
16
+
17
+
18
+ N
19
+ a_1 a_2 a_3 ... a_N
20
+
21
+
22
+ Output
23
+
24
+ Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 2
31
+ 3 1
32
+
33
+
34
+ Output
35
+
36
+ 2
37
+
38
+
39
+ Input
40
+
41
+ 3
42
+ 2 7 4
43
+
44
+
45
+ Output
46
+
47
+ 5
48
+
49
+
50
+ Input
51
+
52
+ 4
53
+ 20 18 2 18
54
+
55
+
56
+ Output
57
+
58
+ 18
59
+
60
+ ## Contest Information
61
+ - **Contest ID**: 0
62
+ - **Problem Index**:
63
+ - **Points**: 0.0
64
+ - **Rating**: 0
65
+ - **Tags**:
66
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
67
+ - **Memory Limit**: 268435456 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-2016/instruction.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 241_D. Numbers
2
+
3
+ ## Problem Description
4
+ You have a sequence of n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). You want to remove some integers in such a way that the resulting sequence of integers satisfies the following three conditions:
5
+
6
+ 1. the resulting sequence is not empty;
7
+ 2. the exclusive or (xor operation) of all the integers in the resulting sequence equals 0;
8
+ 3. if you write all the integers of the resulting sequence (from beginning to the end) in a row in the decimal numeral system and without any spaces, the written number is divisible by p.
9
+
10
+
11
+
12
+ You are given the sequence of n integers a and a prime number p, find a way to satisfy the described conditions.
13
+
14
+ Input
15
+
16
+ The first line of the input contains two integers n and p (1 ≤ n, p ≤ 50000). Next line contains n space-separated distinct integers a1, a2, ..., an (1 ≤ ai ≤ n).
17
+
18
+ It is guaranteed that p is a prime number.
19
+
20
+ Output
21
+
22
+ If there is no solution for the given input, print "No" (without quotes) in the only line of the output.
23
+
24
+ Otherwise print "Yes" in the first line of output. The second line should contain an integer k (k > 0) specifying the number of remaining elements and the third line should contain k distinct integers x1, x2, ..., xk (1 ≤ xi ≤ n). These integers mean that you should remove all integers from the sequence except integers ax1, ax2, ..., axk to satisfy the described conditions.
25
+
26
+ If there are multiple solutions, any of them will be accepted.
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+ 3 3
33
+ 1 2 3
34
+
35
+
36
+ Output
37
+
38
+ Yes
39
+ 3
40
+ 1 2 3
41
+
42
+
43
+ Input
44
+
45
+ 3 5
46
+ 1 2 3
47
+
48
+
49
+ Output
50
+
51
+ No
52
+
53
+ ## Contest Information
54
+ - **Contest ID**: 241
55
+ - **Problem Index**: D
56
+ - **Points**: 0.0
57
+ - **Rating**: 2900
58
+ - **Tags**: None
59
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
60
+ - **Memory Limit**: 256000000 bytes
61
+
62
+ ## Task
63
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-2029/instruction.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 550_A. Two Substrings
2
+
3
+ ## Problem Description
4
+ You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
5
+
6
+ Input
7
+
8
+ The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
9
+
10
+ Output
11
+
12
+ Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
13
+
14
+ Examples
15
+
16
+ Input
17
+
18
+ ABA
19
+
20
+
21
+ Output
22
+
23
+ NO
24
+
25
+
26
+ Input
27
+
28
+ BACFAB
29
+
30
+
31
+ Output
32
+
33
+ YES
34
+
35
+
36
+ Input
37
+
38
+ AXBYBXA
39
+
40
+
41
+ Output
42
+
43
+ NO
44
+
45
+ Note
46
+
47
+ In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
48
+
49
+ In the second sample test there are the following occurrences of the substrings: BACFAB.
50
+
51
+ In the third sample test there is no substring "AB" nor substring "BA".
52
+
53
+ ## Contest Information
54
+ - **Contest ID**: 550
55
+ - **Problem Index**: A
56
+ - **Points**: 1000.0
57
+ - **Rating**: 1500
58
+ - **Tags**: brute force, dp, greedy, implementation, strings
59
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
60
+ - **Memory Limit**: 256000000 bytes
61
+
62
+ ## Task
63
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-2224/instruction.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 240_A. Cinema
2
+
3
+ ## Problem Description
4
+ Overall there are m actors in Berland. Each actor has a personal identifier — an integer from 1 to m (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has k favorite actors. He watched the movie trailers for the next month and wrote the following information for every movie: the movie title, the number of actors who starred in it, and the identifiers of these actors. Besides, he managed to copy the movie titles and how many actors starred there, but he didn't manage to write down the identifiers of some actors. Vasya looks at his records and wonders which movies may be his favourite, and which ones may not be. Once Vasya learns the exact cast of all movies, his favorite movies will be determined as follows: a movie becomes favorite movie, if no other movie from Vasya's list has more favorite actors.
5
+
6
+ Help the boy to determine the following for each movie:
7
+
8
+ * whether it surely will be his favourite movie;
9
+ * whether it surely won't be his favourite movie;
10
+ * can either be favourite or not.
11
+
12
+ Input
13
+
14
+ The first line of the input contains two integers m and k (1 ≤ m ≤ 100, 1 ≤ k ≤ m) — the number of actors in Berland and the number of Vasya's favourite actors.
15
+
16
+ The second line contains k distinct integers ai (1 ≤ ai ≤ m) — the identifiers of Vasya's favourite actors.
17
+
18
+ The third line contains a single integer n (1 ≤ n ≤ 100) — the number of movies in Vasya's list.
19
+
20
+ Then follow n blocks of lines, each block contains a movie's description. The i-th movie's description contains three lines:
21
+
22
+ * the first line contains string si (si consists of lowercase English letters and can have the length of from 1 to 10 characters, inclusive) — the movie's title,
23
+ * the second line contains a non-negative integer di (1 ≤ di ≤ m) — the number of actors who starred in this movie,
24
+ * the third line has di integers bi, j (0 ≤ bi, j ≤ m) — the identifiers of the actors who star in this movie. If bi, j = 0, than Vasya doesn't remember the identifier of the j-th actor. It is guaranteed that the list of actors for a movie doesn't contain the same actors.
25
+
26
+
27
+
28
+ All movies have distinct names. The numbers on the lines are separated by single spaces.
29
+
30
+ Output
31
+
32
+ Print n lines in the output. In the i-th line print:
33
+
34
+ * 0, if the i-th movie will surely be the favourite;
35
+ * 1, if the i-th movie won't surely be the favourite;
36
+ * 2, if the i-th movie can either be favourite, or not favourite.
37
+
38
+ Examples
39
+
40
+ Input
41
+
42
+ 5 3
43
+ 1 2 3
44
+ 6
45
+ firstfilm
46
+ 3
47
+ 0 0 0
48
+ secondfilm
49
+ 4
50
+ 0 0 4 5
51
+ thirdfilm
52
+ 1
53
+ 2
54
+ fourthfilm
55
+ 1
56
+ 5
57
+ fifthfilm
58
+ 1
59
+ 4
60
+ sixthfilm
61
+ 2
62
+ 1 0
63
+
64
+
65
+ Output
66
+
67
+ 2
68
+ 2
69
+ 1
70
+ 1
71
+ 1
72
+ 2
73
+
74
+
75
+ Input
76
+
77
+ 5 3
78
+ 1 3 5
79
+ 4
80
+ jumanji
81
+ 3
82
+ 0 0 0
83
+ theeagle
84
+ 5
85
+ 1 2 3 4 0
86
+ matrix
87
+ 3
88
+ 2 4 0
89
+ sourcecode
90
+ 2
91
+ 2 4
92
+
93
+
94
+ Output
95
+
96
+ 2
97
+ 0
98
+ 1
99
+ 1
100
+
101
+ Note
102
+
103
+ Note to the second sample:
104
+
105
+ * Movie jumanji can theoretically have from 1 to 3 Vasya's favourite actors.
106
+ * Movie theeagle has all three favourite actors, as the actor Vasya failed to remember, can only have identifier 5.
107
+ * Movie matrix can have exactly one favourite actor.
108
+ * Movie sourcecode doesn't have any favourite actors.
109
+
110
+
111
+
112
+ Thus, movie theeagle will surely be favourite, movies matrix and sourcecode won't surely be favourite, and movie jumanji can be either favourite (if it has all three favourite actors), or not favourite.
113
+
114
+ ## Contest Information
115
+ - **Contest ID**: 240
116
+ - **Problem Index**: A
117
+ - **Points**: 0.0
118
+ - **Rating**: 1600
119
+ - **Tags**: implementation
120
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
121
+ - **Memory Limit**: 256000000 bytes
122
+
123
+ ## Task
124
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.