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

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-0144/instruction.md +70 -0
  2. code_contests-0376/instruction.md +74 -0
  3. code_contests-0382/instruction.md +48 -0
  4. code_contests-0384/instruction.md +56 -0
  5. code_contests-0385/instruction.md +54 -0
  6. code_contests-0520/instruction.md +95 -0
  7. code_contests-0527/instruction.md +91 -0
  8. code_contests-0529/instruction.md +68 -0
  9. code_contests-0715/instruction.md +68 -0
  10. code_contests-0940/instruction.md +53 -0
  11. code_contests-0947/instruction.md +63 -0
  12. code_contests-0971/instruction.md +79 -0
  13. code_contests-0978/instruction.md +57 -0
  14. code_contests-1007/instruction.md +42 -0
  15. code_contests-10114/instruction.md +115 -0
  16. code_contests-10115/instruction.md +95 -0
  17. code_contests-10183/instruction.md +98 -0
  18. code_contests-10329/instruction.md +108 -0
  19. code_contests-10549/instruction.md +55 -0
  20. code_contests-10571/instruction.md +64 -0
  21. code_contests-10576/instruction.md +45 -0
  22. code_contests-10582/instruction.md +69 -0
  23. code_contests-10585/instruction.md +46 -0
  24. code_contests-1064/instruction.md +77 -0
  25. code_contests-1065/instruction.md +139 -0
  26. code_contests-10744/instruction.md +58 -0
  27. code_contests-10911/instruction.md +65 -0
  28. code_contests-10927/instruction.md +26 -0
  29. code_contests-10928/instruction.md +108 -0
  30. code_contests-10929/instruction.md +164 -0
  31. code_contests-1096/instruction.md +70 -0
  32. code_contests-11032/instruction.md +82 -0
  33. code_contests-11033/instruction.md +147 -0
  34. code_contests-11034/instruction.md +98 -0
  35. code_contests-11201/instruction.md +92 -0
  36. code_contests-11206/instruction.md +60 -0
  37. code_contests-11239/instruction.md +110 -0
  38. code_contests-11263/instruction.md +70 -0
  39. code_contests-11450/instruction.md +91 -0
  40. code_contests-11456/instruction.md +46 -0
  41. code_contests-11457/instruction.md +79 -0
  42. code_contests-11607/instruction.md +55 -0
  43. code_contests-11665/instruction.md +58 -0
  44. code_contests-11691/instruction.md +96 -0
  45. code_contests-11696/instruction.md +69 -0
  46. code_contests-11808/instruction.md +89 -0
  47. code_contests-11837/instruction.md +52 -0
  48. code_contests-12013/instruction.md +69 -0
  49. code_contests-12082/instruction.md +45 -0
  50. code_contests-12221/instruction.md +52 -0
code_contests-0144/instruction.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 385_A. Bear and Raspberry
2
+
3
+ ## Problem Description
4
+ The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
5
+
6
+ Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1 ≤ d < n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d + 1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day d + 1) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel.
7
+
8
+ The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
9
+
10
+ Input
11
+
12
+ The first line contains two space-separated integers, n and c (2 ≤ n ≤ 100, 0 ≤ c ≤ 100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
13
+
14
+ The second line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100), the price of a honey barrel on day i.
15
+
16
+ Output
17
+
18
+ Print a single integer — the answer to the problem.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 5 1
25
+ 5 10 7 3 20
26
+
27
+
28
+ Output
29
+
30
+ 3
31
+
32
+
33
+ Input
34
+
35
+ 6 2
36
+ 100 1 10 40 10 40
37
+
38
+
39
+ Output
40
+
41
+ 97
42
+
43
+
44
+ Input
45
+
46
+ 3 0
47
+ 1 2 3
48
+
49
+
50
+ Output
51
+
52
+ 0
53
+
54
+ Note
55
+
56
+ In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
57
+
58
+ In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
59
+
60
+ ## Contest Information
61
+ - **Contest ID**: 385
62
+ - **Problem Index**: A
63
+ - **Points**: 500.0
64
+ - **Rating**: 1000
65
+ - **Tags**: brute force, greedy, implementation
66
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
67
+ - **Memory Limit**: 256000000 bytes
68
+
69
+ ## Task
70
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0376/instruction.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 931_A. Friends Meeting
2
+
3
+ ## Problem Description
4
+ Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b.
5
+
6
+ Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6.
7
+
8
+ The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
9
+
10
+ Input
11
+
12
+ The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend.
13
+
14
+ The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend.
15
+
16
+ It is guaranteed that a ≠ b.
17
+
18
+ Output
19
+
20
+ Print the minimum possible total tiredness if the friends meet in the same point.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 3
27
+ 4
28
+
29
+
30
+ Output
31
+
32
+ 1
33
+
34
+
35
+ Input
36
+
37
+ 101
38
+ 99
39
+
40
+
41
+ Output
42
+
43
+ 2
44
+
45
+
46
+ Input
47
+
48
+ 5
49
+ 10
50
+
51
+
52
+ Output
53
+
54
+ 9
55
+
56
+ Note
57
+
58
+ In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
59
+
60
+ In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
61
+
62
+ In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
63
+
64
+ ## Contest Information
65
+ - **Contest ID**: 931
66
+ - **Problem Index**: A
67
+ - **Points**: 500.0
68
+ - **Rating**: 800
69
+ - **Tags**: brute force, greedy, implementation, math
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-0382/instruction.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # friendless-dr-sheldon-cooper-14
2
+
3
+ ## Problem Description
4
+ Leonard has decided to quit living with Dr. Sheldon Cooper and has started to live with Penny. Yes, you read it right. (And you read it here for the first time!) He is fed up of Sheldon, after all. Since, Sheldon no more has Leonard to drive him all around the city for various things, he's feeling a lot uneasy so he decides to set up a network of drivers all around the city to drive him to various places.
5
+
6
+ But, not every driver wants to go every place in the city for various personal reasons, so Sheldon needs to trust many different cab drivers. (Which is a very serious issue for him, by the way!) The problem occurs mainly when Sheldon needs to go to - for example, the Comic book store - and there's no cab driver who goes directly to that place. So, he has to take a cab till another place, and then take a cab from there - making him more scared!
7
+
8
+ Sheldon wants to limit his trust issues. Really. Once. And. For. All.
9
+
10
+ Let's say that you're given the schedule of all the cabs from the major points where he travels to and from - can you help Sheldon figure out the least number of cab drivers he needs to trust, in order to go to all the places he wants to?
11
+
12
+ Input Format:
13
+ The first line contains a number with the number of test cases.
14
+ Every test case has the following input:
15
+
16
+ - Two integers a, b.
17
+ a - number of places he needs to go. b - number of cab drivers.
18
+
19
+ Output Format:
20
+ Print the minimum number of cab drivers he needs to have faith in to travel between places in the city.
21
+
22
+ Constraints:
23
+ 1 ≤ t ≤ 100
24
+ 2 ≤ a ≤ 1000 | 1 ≤ b ≤ 1000
25
+ m NOT equal to n | 1 ≤ m | n ≤ b
26
+ The graph is connected.
27
+
28
+ SAMPLE INPUT
29
+ 1
30
+ 3 3
31
+ 1 2
32
+ 2 3
33
+ 1 3
34
+
35
+ SAMPLE OUTPUT
36
+ 2
37
+
38
+ ## Contest Information
39
+ - **Contest ID**: 0
40
+ - **Problem Index**:
41
+ - **Points**: 0.0
42
+ - **Rating**: 0
43
+ - **Tags**: None
44
+ - **Time Limit**: None seconds
45
+ - **Memory Limit**: 0 bytes
46
+
47
+ ## Task
48
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0384/instruction.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mind-palaces-3
2
+
3
+ ## Problem Description
4
+ Sherlock Holmes loves mind palaces! We all know that.
5
+
6
+ A mind palace, according to Mr. Holmes is something that lets him retrieve a given memory in the least time posible. For this, he structures his mind palace in a very special way. Let a NxM Matrix denote the mind palace of Mr. Holmes. For fast retrieval he keeps each row and each column sorted. Now given a memory X, you have to tell the position of the memory in Sherlock's mind palace.
7
+
8
+ Input
9
+ Input begins with a line containing space separated N and M.
10
+ The next N lines each contain M numbers, each referring to a memory Y.
11
+ The next line contains Q, the number of queries.
12
+ The next Q lines contain a single element X, the memory you have to search in Sherlock's mind palace.
13
+
14
+ Output
15
+ If Y is present in Mr. Holmes memory, output its position (0-based indexing).
16
+ Else output "-1 -1" (quotes for clarity only).
17
+
18
+ Constraints
19
+ 2 ≤ N,M ≤ 1000
20
+ 2 ≤ Q ≤ 1000
21
+ -10^9 ≤ X,Y ≤ 10^9
22
+
23
+ Note : Large Input Files. Use faster I/O methods.
24
+
25
+ SAMPLE INPUT
26
+ 5 5
27
+ -10 -5 -3 4 9
28
+ -6 -2 0 5 10
29
+ -4 -1 1 6 12
30
+ 2 3 7 8 13
31
+ 100 120 130 140 150
32
+ 3
33
+ 0
34
+ -2
35
+ 170
36
+
37
+ SAMPLE OUTPUT
38
+ 1 2
39
+ 1 1
40
+ -1 -1
41
+
42
+ Explanation
43
+
44
+ The sample is self-explanatory.
45
+
46
+ ## Contest Information
47
+ - **Contest ID**: 0
48
+ - **Problem Index**:
49
+ - **Points**: 0.0
50
+ - **Rating**: 0
51
+ - **Tags**: None
52
+ - **Time Limit**: None seconds
53
+ - **Memory Limit**: 0 bytes
54
+
55
+ ## Task
56
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0385/instruction.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # palin-pairs
2
+
3
+ ## Problem Description
4
+ Panda has a thing for palindromes. Hence he was a given a problem by his master. The master will give Panda an array of strings S having N strings. Now Panda has to select the Palin Pairs from the given strings .
5
+
6
+ A Palin Pair is defined as :
7
+
8
+ (i,j) is a Palin Pair if Si = reverse(Sj) and i < j
9
+
10
+ Panda wants to know how many such Palin Pairs are there in S.
11
+ Please help him in calculating this.
12
+
13
+ Input:
14
+
15
+ The first line contains N, the number of strings present in S.
16
+ Then N strings follow.
17
+
18
+ Output:
19
+
20
+ Output the query of Panda in single line.
21
+
22
+ Constraints:
23
+
24
+ 1 ≤ N ≤ 100000
25
+ 1 ≤ |Si| ≤ 10 (length of string)
26
+
27
+ The string consists of Upper and Lower case alphabets only.
28
+
29
+ SAMPLE INPUT
30
+ 3
31
+ bba
32
+ abb
33
+ abb
34
+
35
+ SAMPLE OUTPUT
36
+ 2
37
+
38
+ Explanation
39
+
40
+ Only two pairs exists. Those are :
41
+ 1. (0,1) since S0 = reverse(S1) ( "bba" = reverse("abb") )
42
+ 2. (0,2) since S0 = reverse(S2) ( "bba" = reverse("abb") )
43
+
44
+ ## Contest Information
45
+ - **Contest ID**: 0
46
+ - **Problem Index**:
47
+ - **Points**: 0.0
48
+ - **Rating**: 0
49
+ - **Tags**: None
50
+ - **Time Limit**: None seconds
51
+ - **Memory Limit**: 0 bytes
52
+
53
+ ## Task
54
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0520/instruction.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02472 Addition of Big Integers
2
+
3
+ ## Problem Description
4
+ Addition of Big Integers
5
+
6
+ Given two integers $A$ and $B$, compute the sum, $A + B$.
7
+
8
+ Input
9
+
10
+ Two integers $A$ and $B$ separated by a space character are given in a line.
11
+
12
+ Output
13
+
14
+ Print the sum in a line.
15
+
16
+ Constraints
17
+
18
+ * $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$
19
+
20
+
21
+
22
+ Sample Input 1
23
+
24
+
25
+ 5 8
26
+
27
+
28
+ Sample Output 1
29
+
30
+
31
+ 13
32
+
33
+
34
+ Sample Input 2
35
+
36
+
37
+ 100 25
38
+
39
+
40
+ Sample Output 2
41
+
42
+
43
+ 125
44
+
45
+
46
+ Sample Input 3
47
+
48
+
49
+ -1 1
50
+
51
+
52
+ Sample Output 3
53
+
54
+
55
+ 0
56
+
57
+
58
+ Sample Input 4
59
+
60
+
61
+ 12 -3
62
+
63
+
64
+ Sample Output 4
65
+
66
+
67
+ 9
68
+
69
+
70
+
71
+
72
+
73
+
74
+ Example
75
+
76
+ Input
77
+
78
+ 5 8
79
+
80
+
81
+ Output
82
+
83
+ 13
84
+
85
+ ## Contest Information
86
+ - **Contest ID**: 0
87
+ - **Problem Index**:
88
+ - **Points**: 0.0
89
+ - **Rating**: 0
90
+ - **Tags**:
91
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
92
+ - **Memory Limit**: 268435456 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-0527/instruction.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1011_A. Stages
2
+
3
+ ## Problem Description
4
+ Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
5
+
6
+ There are n stages available. The rocket must contain exactly k of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
7
+
8
+ For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — 26 tons.
9
+
10
+ Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
11
+
12
+ Input
13
+
14
+ The first line of input contains two integers — n and k (1 ≤ k ≤ n ≤ 50) – the number of available stages and the number of stages to use in the rocket.
15
+
16
+ The second line contains string s, which consists of exactly n lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
17
+
18
+ Output
19
+
20
+ Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 5 3
27
+ xyabd
28
+
29
+
30
+ Output
31
+
32
+ 29
33
+
34
+ Input
35
+
36
+ 7 4
37
+ problem
38
+
39
+
40
+ Output
41
+
42
+ 34
43
+
44
+ Input
45
+
46
+ 2 2
47
+ ab
48
+
49
+
50
+ Output
51
+
52
+ -1
53
+
54
+ Input
55
+
56
+ 12 1
57
+ abaabbaaabbb
58
+
59
+
60
+ Output
61
+
62
+ 1
63
+
64
+ Note
65
+
66
+ In the first example, the following rockets satisfy the condition:
67
+
68
+ * "adx" (weight is 1+4+24=29);
69
+ * "ady" (weight is 1+4+25=30);
70
+ * "bdx" (weight is 2+4+24=30);
71
+ * "bdy" (weight is 2+4+25=31).
72
+
73
+
74
+
75
+ Rocket "adx" has the minimal weight, so the answer is 29.
76
+
77
+ In the second example, target rocket is "belo". Its weight is 2+5+12+15=34.
78
+
79
+ In the third example, n=k=2, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.
80
+
81
+ ## Contest Information
82
+ - **Contest ID**: 1011
83
+ - **Problem Index**: A
84
+ - **Points**: 500.0
85
+ - **Rating**: 900
86
+ - **Tags**: greedy, implementation, sortings
87
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
88
+ - **Memory Limit**: 256000000 bytes
89
+
90
+ ## Task
91
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0529/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1059_A. Cashier
2
+
3
+ ## Problem Description
4
+ Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.
5
+
6
+ Vasya is a bit lazy, so he likes taking smoke breaks for a minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
7
+
8
+ Input
9
+
10
+ The first line contains three integers n, L and a (0 ≤ n ≤ 10^{5}, 1 ≤ L ≤ 10^{9}, 1 ≤ a ≤ L).
11
+
12
+ The i-th of the next n lines contains two integers t_{i} and l_{i} (0 ≤ t_{i} ≤ L - 1, 1 ≤ l_{i} ≤ L). It is guaranteed that t_{i} + l_{i} ≤ t_{i + 1} and t_{n} + l_{n} ≤ L.
13
+
14
+ Output
15
+
16
+ Output one integer — the maximum number of breaks.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 2 11 3
23
+ 0 1
24
+ 1 1
25
+
26
+
27
+ Output
28
+
29
+ 3
30
+
31
+ Input
32
+
33
+ 0 5 2
34
+
35
+
36
+ Output
37
+
38
+ 2
39
+
40
+ Input
41
+
42
+ 1 3 2
43
+ 1 2
44
+
45
+
46
+ Output
47
+
48
+ 0
49
+
50
+ Note
51
+
52
+ In the first sample Vasya can take 3 breaks starting after 2, 5 and 8 minutes after the beginning of the day.
53
+
54
+ In the second sample Vasya can take 2 breaks starting after 0 and 2 minutes after the beginning of the day.
55
+
56
+ In the third sample Vasya can't take any breaks.
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 1059
60
+ - **Problem Index**: A
61
+ - **Points**: 500.0
62
+ - **Rating**: 1000
63
+ - **Tags**: implementation
64
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
65
+ - **Memory Limit**: 256000000 bytes
66
+
67
+ ## Task
68
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0715/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00534 Silk Road
2
+
3
+ ## Problem Description
4
+ problem
5
+
6
+ In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road".
7
+
8
+ There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (1 ≤ i ≤ N) is Di.
9
+
10
+ JOI, a trader, decided to start from city 0, go through the cities in order, and carry silk to city N. Must travel from city 0 to city N within M days. JOI chooses one of the following two actions for each day.
11
+
12
+ * Move: Move from the current city to the city one east in one day. If you are currently in city i -1 (1 ≤ i ≤ N), move to city i.
13
+ * Wait: Do not move and wait for one day in your current city.
14
+
15
+
16
+
17
+ It is difficult to move, and the degree of fatigue accumulates each time you move. The weather on the Silk Road fluctuates from day to day, and the worse the weather, the harder it is to move.
18
+
19
+ It is known that the bad weather on the jth day (1 ≤ j ≤ M) of the M days that JOI can use to carry silk is Cj. When moving from city i -1 to city i (1 ≤ i ≤ N) to day j (1 ≤ j ≤ M), the degree of fatigue accumulates by Di × Cj. Fatigue does not accumulate on days when you are waiting without moving.
20
+
21
+ JOI wants to move with as little fatigue as possible by choosing the behavior of each day. Find the minimum total fatigue that JOI will accumulate from the start to the end of the move to city N within M days.
22
+
23
+
24
+
25
+ input
26
+
27
+ The input consists of 1 + N + M lines.
28
+
29
+ On the first line, two integers N and M (1 ≤ N ≤ M ≤ 1000) are written separated by a blank. This means that the Silk Road consists of N + 1 cities and JOI must carry the silk from city 0 to city N within M days.
30
+
31
+ The integer Di (1 ≤ Di ≤ 1000) is written on the i-th line (1 ≤ i ≤ N) of the following N lines. This means that the distance between city i -1 and city i is Di.
32
+
33
+ The integer Cj (1 ≤ Cj ≤ 1000) is written on the jth line (1 ≤ j ≤ M) of the following M lines. This means that the bad weather on day j is Cj.
34
+
35
+ output
36
+
37
+ Output the minimum value of the total fatigue level accumulated from the start to the end of the movement when JOI moves to the city N within M days in one line.
38
+
39
+ Example
40
+
41
+ Input
42
+
43
+ 3 5
44
+ 10
45
+ 25
46
+ 15
47
+ 50
48
+ 30
49
+ 15
50
+ 40
51
+ 30
52
+
53
+
54
+ Output
55
+
56
+ 1125
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 0
60
+ - **Problem Index**:
61
+ - **Points**: 0.0
62
+ - **Rating**: 0
63
+ - **Tags**:
64
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
65
+ - **Memory Limit**: 268435456 bytes
66
+
67
+ ## Task
68
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0940/instruction.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # digjump
2
+
3
+ ## Problem Description
4
+ Chef loves games! But he likes to invent his own. Now he plays game "Digit Jump". Chef has sequence of digits S1, S2,..., SN,. He is staying in the first digit (S1) and want to reach the last digit (SN) in the minimal number of jumps.
5
+ While staying in some digit x with index i (digit Si) Chef can jump into digits with indices i - 1 (Si-1) and i + 1 (Si+1) but he can't jump out from sequence. Or he can jump into any digit with the same value x.
6
+ Help Chef to find the minimal number of jumps he need to reach digit SN from digit S1. 
7
+  
8
+
9
+ Input
10
+ Input contains a single line consist of string S of length N- the sequence of digits.
11
+  
12
+
13
+ Output
14
+ In a single line print single integer - the minimal number of jumps he needs.
15
+  
16
+
17
+ Constraints
18
+
19
+ 1 ≤ N ≤ 10^5
20
+ Each symbol of S is a digit from 0 to 9.
21
+
22
+  
23
+
24
+ Example
25
+ Input:
26
+ 01234567890
27
+
28
+ Output:
29
+ 1
30
+
31
+ Input:
32
+ 012134444444443
33
+
34
+ Output:
35
+ 4
36
+
37
+  
38
+
39
+ Explanation
40
+ In the first case Chef can directly jump from the first digit (it is 0) to the last (as it is also 0).
41
+ In the second case Chef should jump in such sequence (the number of digits from 1: 1-2-4-5-15).
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-0947/instruction.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1068_D. Array Without Local Maximums
2
+
3
+ ## Problem Description
4
+ Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:
5
+
6
+ a_{1} ≤ a_{2},
7
+
8
+ a_{n} ≤ a_{n-1} and
9
+
10
+ a_{i} ≤ max(a_{i-1}, a_{i+1}) for all i from 2 to n-1.
11
+
12
+ Ivan does not remember the array and asks to find the number of ways to restore it. Restored elements also should be integers from 1 to 200. Since the number of ways can be big, print it modulo 998244353.
13
+
14
+ Input
15
+
16
+ First line of input contains one integer n (2 ≤ n ≤ 10^{5}) — size of the array.
17
+
18
+ Second line of input contains n integers a_{i} — elements of array. Either a_{i} = -1 or 1 ≤ a_{i} ≤ 200. a_{i} = -1 means that i-th element can't be read.
19
+
20
+ Output
21
+
22
+ Print number of ways to restore the array modulo 998244353.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 3
29
+ 1 -1 2
30
+
31
+
32
+ Output
33
+
34
+ 1
35
+
36
+
37
+ Input
38
+
39
+ 2
40
+ -1 -1
41
+
42
+
43
+ Output
44
+
45
+ 200
46
+
47
+ Note
48
+
49
+ In the first example, only possible value of a_{2} is 2.
50
+
51
+ In the second example, a_{1} = a_{2} so there are 200 different values because all restored elements should be integers between 1 and 200.
52
+
53
+ ## Contest Information
54
+ - **Contest ID**: 1068
55
+ - **Problem Index**: D
56
+ - **Points**: 500.0
57
+ - **Rating**: 1900
58
+ - **Tags**: dp
59
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
60
+ - **Memory Limit**: 512000000 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-0971/instruction.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 198_B. Jumping on Walls
2
+
3
+ ## Problem Description
4
+ Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
5
+
6
+ The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
7
+
8
+ Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
9
+
10
+ * climb one area up;
11
+ * climb one area down;
12
+ * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
13
+
14
+
15
+
16
+ If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
17
+
18
+ The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
19
+
20
+ The level is considered completed if the ninja manages to get out of the canyon.
21
+
22
+ After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
23
+
24
+ Input
25
+
26
+ The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly.
27
+
28
+ The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
29
+
30
+ The third line describes the right wall in the same format.
31
+
32
+ It is guaranteed that the first area of the left wall is not dangerous.
33
+
34
+ Output
35
+
36
+ Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
37
+
38
+ Examples
39
+
40
+ Input
41
+
42
+ 7 3
43
+ ---X--X
44
+ -X--XX-
45
+
46
+
47
+ Output
48
+
49
+ YES
50
+
51
+
52
+ Input
53
+
54
+ 6 2
55
+ --X-X-
56
+ X--XX-
57
+
58
+
59
+ Output
60
+
61
+ NO
62
+
63
+ Note
64
+
65
+ In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
66
+
67
+ In the second sample there's no way the ninja can get out of the canyon.
68
+
69
+ ## Contest Information
70
+ - **Contest ID**: 198
71
+ - **Problem Index**: B
72
+ - **Points**: 1000.0
73
+ - **Rating**: 1400
74
+ - **Tags**: shortest paths
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-0978/instruction.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 364_D. Ghd
2
+
3
+ ## Problem Description
4
+ John Doe offered his sister Jane Doe find the gcd of some set of numbers a.
5
+
6
+ Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbers of the set are evenly divisible by g'.
7
+
8
+ Unfortunately Jane couldn't cope with the task and John offered her to find the ghd of the same subset of numbers.
9
+
10
+ Ghd is a positive integer g, such that at least half of numbers from the set are evenly divisible by g and there isn't such g' (g' > g) that at least half of the numbers from the set are evenly divisible by g'.
11
+
12
+ Jane coped with the task for two hours. Please try it, too.
13
+
14
+ Input
15
+
16
+ The first line contains an integer n (1 ≤ n ≤ 106) showing how many numbers are in set a. The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1012). Please note, that given set can contain equal numbers.
17
+
18
+ Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the %I64d specifier.
19
+
20
+ Output
21
+
22
+ Print a single integer g — the Ghd of set a.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 6
29
+ 6 2 3 4 5 6
30
+
31
+
32
+ Output
33
+
34
+ 3
35
+
36
+
37
+ Input
38
+
39
+ 5
40
+ 5 5 6 10 15
41
+
42
+
43
+ Output
44
+
45
+ 5
46
+
47
+ ## Contest Information
48
+ - **Contest ID**: 364
49
+ - **Problem Index**: D
50
+ - **Points**: 2000.0
51
+ - **Rating**: 2900
52
+ - **Tags**: brute force, math, probabilities
53
+ - **Time Limit**: {'seconds': 4, '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-1007/instruction.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # compiler-version-2
2
+
3
+ ## Problem Description
4
+ You are converting an old code for a new version of the compiler.
5
+
6
+ In the old code we have used "->" for pointers. But now we have to replace each "->" with a ".". But this replacement shouldn't be done inside commments. A comment is a string that starts with "//" and terminates at the end of the line.
7
+
8
+ Input:
9
+
10
+ At max. 2000 lines of code.
11
+
12
+ Each line of code consists of at maximum 60 characters.
13
+
14
+ Output:
15
+
16
+ New code with required changes.
17
+
18
+ SAMPLE INPUT
19
+ int t; //variable t
20
+ t->a=0; //t->a does something
21
+ return 0;
22
+
23
+ SAMPLE OUTPUT
24
+ int t; //variable t
25
+ t.a=0; //t->a does something
26
+ return 0;
27
+
28
+ Explanation
29
+
30
+ "->" is not converted to "." inside comments.
31
+
32
+ ## Contest Information
33
+ - **Contest ID**: 0
34
+ - **Problem Index**:
35
+ - **Points**: 0.0
36
+ - **Rating**: 0
37
+ - **Tags**: None
38
+ - **Time Limit**: None seconds
39
+ - **Memory Limit**: 0 bytes
40
+
41
+ ## Task
42
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10114/instruction.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1148_H. Holy Diver
2
+
3
+ ## Problem Description
4
+ You are given an array which is initially empty. You need to perform n operations of the given format:
5
+
6
+ * "a l r k": append a to the end of the array. After that count the number of integer pairs x, y such that l ≤ x ≤ y ≤ r and \operatorname{mex}(a_{x}, a_{x+1}, …, a_{y}) = k.
7
+
8
+
9
+
10
+ The elements of the array are numerated from 1 in the order they are added to the array.
11
+
12
+ To make this problem more tricky we don't say your real parameters of the queries. Instead your are given a', l', r', k'. To get a, l, r, k on the i-th operation you need to perform the following:
13
+
14
+ * a := (a' + lans) mod(n + 1),
15
+ * l := (l' + lans) mod{i} + 1,
16
+ * r := (r' + lans) mod{i} + 1,
17
+ * if l > r swap l and r,
18
+ * k := (k' + lans) mod(n + 1),
19
+
20
+ where lans is the answer to the previous operation, initially lans is equal to zero. i is the id of the operation, operations are numbered from 1.
21
+
22
+ The \operatorname{mex}(S), where S is a multiset of non-negative integers, is the smallest non-negative integer which does not appear in the set. For example, \operatorname{mex}(\{2, 2, 3\}) = 0 and \operatorname{mex} (\{0, 1, 4, 1, 6\}) = 2.
23
+
24
+ Input
25
+
26
+ The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array.
27
+
28
+ The next n lines contain the description of queries.
29
+
30
+ Each of them n lines contains four non-negative integers a', l', r', k' (0, ≤ a', l', r', k' ≤ 10^9), describing one operation.
31
+
32
+ Output
33
+
34
+ For each query print a single integer — the answer to this query.
35
+
36
+ Examples
37
+
38
+ Input
39
+
40
+
41
+ 5
42
+ 0 0 0 1
43
+ 0 1 0 5
44
+ 5 2 1 0
45
+ 5 2 1 0
46
+ 2 4 3 3
47
+
48
+
49
+ Output
50
+
51
+
52
+ 1
53
+ 1
54
+ 2
55
+ 6
56
+ 3
57
+
58
+
59
+ Input
60
+
61
+
62
+ 5
63
+ 2 0 0 2
64
+ 2 0 1 1
65
+ 0 0 2 0
66
+ 3 2 2 0
67
+ 0 2 3 0
68
+
69
+
70
+ Output
71
+
72
+
73
+ 0
74
+ 0
75
+ 3
76
+ 0
77
+ 0
78
+
79
+ Note
80
+
81
+ For the first example the decoded values of a, l, r, k are the following:
82
+
83
+ a_1=0,l_1=1,r_1=1,k_1=1
84
+
85
+ a_2=1,l_2=1,r_2=2,k_2=0
86
+
87
+ a_3=0,l_3=1,r_3=3,k_3=1
88
+
89
+ a_4=1,l_4=1,r_4=4,k_4=2
90
+
91
+ a_5=2,l_5=1,r_5=5,k_5=3
92
+
93
+ For the second example the decoded values of a, l, r, k are the following:
94
+
95
+ a_1=2,l_1=1,r_1=1,k_1=2
96
+
97
+ a_2=2,l_2=1,r_2=2,k_2=1
98
+
99
+ a_3=0,l_3=1,r_3=3,k_3=0
100
+
101
+ a_4=0,l_4=2,r_4=2,k_4=3
102
+
103
+ a_5=0,l_5=3,r_5=4,k_5=0
104
+
105
+ ## Contest Information
106
+ - **Contest ID**: 1148
107
+ - **Problem Index**: H
108
+ - **Points**: 4000.0
109
+ - **Rating**: 3500
110
+ - **Tags**: data structures
111
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
112
+ - **Memory Limit**: 1024000000 bytes
113
+
114
+ ## Task
115
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10115/instruction.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 116_E. Plumber
2
+
3
+ ## Problem Description
4
+ Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells.
5
+
6
+ In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as follows:
7
+
8
+ <image>
9
+
10
+ Each pipe segment has two ends, illustrated by the arrows in the picture above. For example, segment 1 has ends at top and left side of it.
11
+
12
+ Little John considers the piping system to be leaking if there is at least one pipe segment inside the grid whose end is not connected to another pipe's end or to the border of the grid. The image below shows an example of leaking and non-leaking systems of size 1 × 2.
13
+
14
+ <image>
15
+
16
+ Now, you will be given the grid that has been partially filled by Little John. Each cell will either contain one of the four segments above, or be empty. Find the number of possible different non-leaking final systems after Little John finishes filling all of the empty cells with pipe segments. Print this number modulo 1000003 (106 + 3).
17
+
18
+ Note that rotations or flipping of the grid are not allowed and so two configurations that are identical only when one of them has been rotated or flipped either horizontally or vertically are considered two different configurations.
19
+
20
+ Input
21
+
22
+ The first line will contain two single-space separated integers n and m (1 ≤ n, m, n·m ≤ 5·105) — the number of rows and columns respectively. Then n lines follow, each contains exactly m characters — the description of the grid. Each character describes a cell and is either one of these:
23
+
24
+ * "1" - "4" — a pipe segment of one of four types as described above
25
+ * "." — an empty cell
26
+
27
+ Output
28
+
29
+ Print a single integer denoting the number of possible final non-leaking pipe systems modulo 1000003 (106 + 3). If there are no such configurations, print 0.
30
+
31
+ Examples
32
+
33
+ Input
34
+
35
+ 2 2
36
+ 13
37
+ ..
38
+
39
+
40
+ Output
41
+
42
+ 2
43
+
44
+
45
+ Input
46
+
47
+ 3 1
48
+ 1
49
+ 4
50
+ .
51
+
52
+
53
+ Output
54
+
55
+ 0
56
+
57
+
58
+ Input
59
+
60
+ 2 2
61
+ 3.
62
+ .1
63
+
64
+
65
+ Output
66
+
67
+ 1
68
+
69
+ Note
70
+
71
+ For the first example, the initial configuration of the grid is as follows.
72
+
73
+ <image>
74
+
75
+ The only two possible final non-leaking pipe configurations are as follows:
76
+
77
+ <image> <image>
78
+
79
+ For the second example, the initial grid is already leaking, so there will be no final grid that is non-leaking.
80
+
81
+ For the final example, there's only one possible non-leaking final grid as follows.
82
+
83
+ <image>
84
+
85
+ ## Contest Information
86
+ - **Contest ID**: 116
87
+ - **Problem Index**: E
88
+ - **Points**: 1500.0
89
+ - **Rating**: 2200
90
+ - **Tags**: math
91
+ - **Time Limit**: {'seconds': 3, '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-10183/instruction.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03148 AtCoder Beginner Contest 116 - Various Sushi
2
+
3
+ ## Problem Description
4
+ There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows:
5
+
6
+ * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus".
7
+ * The base total deliciousness is the sum of the deliciousness of the pieces you eat.
8
+ * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat.
9
+
10
+
11
+
12
+ You want to have as much satisfaction as possible. Find this maximum satisfaction.
13
+
14
+ Constraints
15
+
16
+ * 1 \leq K \leq N \leq 10^5
17
+ * 1 \leq t_i \leq N
18
+ * 1 \leq d_i \leq 10^9
19
+ * All values in input are integers.
20
+
21
+ Input
22
+
23
+ Input is given from Standard Input in the following format:
24
+
25
+
26
+ N K
27
+ t_1 d_1
28
+ t_2 d_2
29
+ .
30
+ .
31
+ .
32
+ t_N d_N
33
+
34
+
35
+ Output
36
+
37
+ Print the maximum satisfaction that you can obtain.
38
+
39
+ Examples
40
+
41
+ Input
42
+
43
+ 5 3
44
+ 1 9
45
+ 1 7
46
+ 2 6
47
+ 2 5
48
+ 3 1
49
+
50
+
51
+ Output
52
+
53
+ 26
54
+
55
+
56
+ Input
57
+
58
+ 7 4
59
+ 1 1
60
+ 2 1
61
+ 3 1
62
+ 4 6
63
+ 4 5
64
+ 4 5
65
+ 4 5
66
+
67
+
68
+ Output
69
+
70
+ 25
71
+
72
+
73
+ Input
74
+
75
+ 6 5
76
+ 5 1000000000
77
+ 2 990000000
78
+ 3 980000000
79
+ 6 970000000
80
+ 6 960000000
81
+ 4 950000000
82
+
83
+
84
+ Output
85
+
86
+ 4900000016
87
+
88
+ ## Contest Information
89
+ - **Contest ID**: 0
90
+ - **Problem Index**:
91
+ - **Points**: 0.0
92
+ - **Rating**: 0
93
+ - **Tags**:
94
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
95
+ - **Memory Limit**: 1073741824 bytes
96
+
97
+ ## Task
98
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10329/instruction.md ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1284_C. New Year and Permutation
2
+
3
+ ## Problem Description
4
+ Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
5
+
6
+ A sequence a is a subsegment of a sequence b if a can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as [l, r], where l, r are two integers with 1 ≤ l ≤ r ≤ n. This indicates the subsegment where l-1 elements from the beginning and n-r elements from the end are deleted from the sequence.
7
+
8
+ For a permutation p_1, p_2, …, p_n, we define a framed segment as a subsegment [l,r] where max\\{p_l, p_{l+1}, ..., p_r\} - min\\{p_l, p_{l+1}, ..., p_r\} = r - l. For example, for the permutation (6, 7, 1, 8, 5, 3, 2, 4) some of its framed segments are: [1, 2], [5, 8], [6, 7], [3, 3], [8, 8]. In particular, a subsegment [i,i] is always a framed segments for any i between 1 and n, inclusive.
9
+
10
+ We define the happiness of a permutation p as the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n, and [l, r] is a framed segment. For example, the permutation [3, 1, 2] has happiness 5: all segments except [1, 2] are framed segments.
11
+
12
+ Given integers n and m, Jongwon wants to compute the sum of happiness for all permutations of length n, modulo the prime number m. Note that there exist n! (factorial of n) different permutations of length n.
13
+
14
+ Input
15
+
16
+ The only line contains two integers n and m (1 ≤ n ≤ 250 000, 10^8 ≤ m ≤ 10^9, m is prime).
17
+
18
+ Output
19
+
20
+ Print r (0 ≤ r < m), the sum of happiness for all permutations of length n, modulo a prime number m.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+
27
+ 1 993244853
28
+
29
+
30
+ Output
31
+
32
+
33
+ 1
34
+
35
+
36
+ Input
37
+
38
+
39
+ 2 993244853
40
+
41
+
42
+ Output
43
+
44
+
45
+ 6
46
+
47
+
48
+ Input
49
+
50
+
51
+ 3 993244853
52
+
53
+
54
+ Output
55
+
56
+
57
+ 32
58
+
59
+
60
+ Input
61
+
62
+
63
+ 2019 993244853
64
+
65
+
66
+ Output
67
+
68
+
69
+ 923958830
70
+
71
+
72
+ Input
73
+
74
+
75
+ 2020 437122297
76
+
77
+
78
+ Output
79
+
80
+
81
+ 265955509
82
+
83
+ Note
84
+
85
+ For sample input n=3, let's consider all permutations of length 3:
86
+
87
+ * [1, 2, 3], all subsegments are framed segment. Happiness is 6.
88
+ * [1, 3, 2], all subsegments except [1, 2] are framed segment. Happiness is 5.
89
+ * [2, 1, 3], all subsegments except [2, 3] are framed segment. Happiness is 5.
90
+ * [2, 3, 1], all subsegments except [2, 3] are framed segment. Happiness is 5.
91
+ * [3, 1, 2], all subsegments except [1, 2] are framed segment. Happiness is 5.
92
+ * [3, 2, 1], all subsegments are framed segment. Happiness is 6.
93
+
94
+
95
+
96
+ Thus, the sum of happiness is 6+5+5+5+5+6 = 32.
97
+
98
+ ## Contest Information
99
+ - **Contest ID**: 1284
100
+ - **Problem Index**: C
101
+ - **Points**: 1750.0
102
+ - **Rating**: 1600
103
+ - **Tags**: combinatorics, math
104
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
105
+ - **Memory Limit**: 1024000000 bytes
106
+
107
+ ## Task
108
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10549/instruction.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 171_H. A polyline
2
+
3
+ ## Problem Description
4
+ <image>
5
+
6
+ Input
7
+
8
+ The input contains two integers a, b (1 ≤ a ≤ 10, 0 ≤ b ≤ 22·a - 1) separated by a single space.
9
+
10
+ Output
11
+
12
+ Output two integers separated by a single space.
13
+
14
+ Examples
15
+
16
+ Input
17
+
18
+ 1 0
19
+
20
+
21
+ Output
22
+
23
+ 0 0
24
+
25
+
26
+ Input
27
+
28
+ 2 15
29
+
30
+
31
+ Output
32
+
33
+ 3 0
34
+
35
+
36
+ Input
37
+
38
+ 4 160
39
+
40
+
41
+ Output
42
+
43
+ 12 12
44
+
45
+ ## Contest Information
46
+ - **Contest ID**: 171
47
+ - **Problem Index**: H
48
+ - **Points**: 0.0
49
+ - **Rating**: 1700
50
+ - **Tags**: *special, implementation
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-10571/instruction.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 690_B3. Recover Polygon (hard)
2
+
3
+ ## Problem Description
4
+ Zombies have found out about the Zombie Contamination level checker and managed to damage it! Now detecting the shape of their main compound will be a real challenge for Heidi. As before, a lair can be represented as a strictly convex polygon on a lattice. Each vertex of the polygon occupies a point on the lattice. However, the damaged Zombie Contamination level checker can only tell, for each cell, whether the level of Zombie Contamination for that cell is in the set {1, 2, 3}. In other words, Heidi knows all the cells of the lattice for which the Contamination level is not 0 and not 4.
5
+
6
+ Given this information, Heidi still wants to know the exact shape of the lair to rain destruction on the zombies. Help her!
7
+
8
+ Input
9
+
10
+ The input contains multiple test cases.
11
+
12
+ The first line of each test case contains two space-separated integers N and M, where N is the size of the lattice grid (5 ≤ N ≤ 100000) and M is the number of lattice points for which the Zombie Contamination level is 1, 2, or 3 (8 ≤ M ≤ 200000).
13
+
14
+ The second line of each test case contains M pairs of integers x1, y1, ..., xM, yM – coordinates of the cells with Zombie Contamination level not equal to 0 nor 4. It is guaranteed that 1 ≤ xi, yi ≤ N. All pairs xi, yi are different.
15
+
16
+ Cells are enumerated based on the coordinates of their upper right corner. This means that the bottommost leftmost cell that touches the origin has coordinates (1, 1), and the uppermost leftmost cell is identified as (1, N).
17
+
18
+ The last line of the file contains two zeroes. This line should not be treated as a test case. The sum of the M values for all tests in one file will not exceed 200000.
19
+
20
+ Output
21
+
22
+ For each test case, the following output is expected:
23
+
24
+ The first line of the output should contain one integer V, the number of vertices of the polygon that is the secret lair. The next V lines each should contain two integers, denoting the vertices of the polygon in the clockwise order, starting from the lexicographically smallest vertex.
25
+
26
+ Example
27
+
28
+ Input
29
+
30
+ 8 19
31
+ 2 3 2 4 2 5 3 3 3 5 4 3 4 5 4 6 5 2 5 3 5 6 6 2 6 3 6 4 6 5 6 6 6 7 7 6 7 7
32
+ 5 8
33
+ 2 2 2 3 2 4 3 2 3 4 4 2 4 3 4 4
34
+ 0 0
35
+
36
+
37
+ Output
38
+
39
+ 4
40
+ 2 3
41
+ 2 4
42
+ 6 6
43
+ 5 2
44
+ 4
45
+ 2 2
46
+ 2 3
47
+ 3 3
48
+ 3 2
49
+
50
+ Note
51
+
52
+ It is guaranteed that the solution always exists and is unique. It is guaranteed that in the correct solution the coordinates of the polygon vertices are between 1 and N - 1. A vertex (x1, y1) is lexicographically smaller than vertex (x2, y2) if x1 < x2 or <image>.
53
+
54
+ ## Contest Information
55
+ - **Contest ID**: 690
56
+ - **Problem Index**: B3
57
+ - **Points**: 0.0
58
+ - **Rating**: 2600
59
+ - **Tags**: data structures
60
+ - **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
61
+ - **Memory Limit**: 256000000 bytes
62
+
63
+ ## Task
64
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10576/instruction.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 802_N. April Fools' Problem (medium)
2
+
3
+ ## Problem Description
4
+ The marmots need to prepare k problems for HC2 over n days. Each problem, once prepared, also has to be printed.
5
+
6
+ The preparation of a problem on day i (at most one per day) costs ai CHF, and the printing of a problem on day i (also at most one per day) costs bi CHF. Of course, a problem cannot be printed before it has been prepared (but doing both on the same day is fine).
7
+
8
+ What is the minimum cost of preparation and printing?
9
+
10
+ Input
11
+
12
+ The first line of input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (<image>) — the preparation costs. The third line contains n space-separated integers b1, ..., bn (<image>) — the printing costs.
13
+
14
+ Output
15
+
16
+ Output the minimum cost of preparation and printing k problems — that is, the minimum possible sum ai1 + ai2 + ... + aik + bj1 + bj2 + ... + bjk, where 1 ≤ i1 < i2 < ... < ik ≤ n, 1 ≤ j1 < j2 < ... < jk ≤ n and i1 ≤ j1, i2 ≤ j2, ..., ik ≤ jk.
17
+
18
+ Example
19
+
20
+ Input
21
+
22
+ 8 4
23
+ 3 8 7 9 9 4 6 8
24
+ 2 5 9 4 3 8 9 1
25
+
26
+
27
+ Output
28
+
29
+ 32
30
+
31
+ Note
32
+
33
+ In the sample testcase, one optimum solution is to prepare the first problem on day 1 and print it on day 1, prepare the second problem on day 2 and print it on day 4, prepare the third problem on day 3 and print it on day 5, and prepare the fourth problem on day 6 and print it on day 8.
34
+
35
+ ## Contest Information
36
+ - **Contest ID**: 802
37
+ - **Problem Index**: N
38
+ - **Points**: 0.0
39
+ - **Rating**: 2400
40
+ - **Tags**: binary search, flows, graphs
41
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
42
+ - **Memory Limit**: 256000000 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-10582/instruction.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 940_F. Machine Learning
2
+
3
+ ## Problem Description
4
+ You come home and fell some unpleasant smell. Where is it coming from?
5
+
6
+ You are given an array a. You have to answer the following queries:
7
+
8
+ 1. You are given two integers l and r. Let ci be the number of occurrences of i in al: r, where al: r is the subarray of a from l-th element to r-th inclusive. Find the Mex of {c0, c1, ..., c109}
9
+ 2. You are given two integers p to x. Change ap to x.
10
+
11
+
12
+
13
+ The Mex of a multiset of numbers is the smallest non-negative integer not in the set.
14
+
15
+ Note that in this problem all elements of a are positive, which means that c0 = 0 and 0 is never the answer for the query of the second type.
16
+
17
+ Input
18
+
19
+ The first line of input contains two integers n and q (1 ≤ n, q ≤ 100 000) — the length of the array and the number of queries respectively.
20
+
21
+ The second line of input contains n integers — a1, a2, ..., an (1 ≤ ai ≤ 109).
22
+
23
+ Each of the next q lines describes a single query.
24
+
25
+ The first type of query is described by three integers ti = 1, li, ri, where 1 ≤ li ≤ ri ≤ n — the bounds of the subarray.
26
+
27
+ The second type of query is described by three integers ti = 2, pi, xi, where 1 ≤ pi ≤ n is the index of the element, which must be changed and 1 ≤ xi ≤ 109 is the new value.
28
+
29
+ Output
30
+
31
+ For each query of the first type output a single integer — the Mex of {c0, c1, ..., c109}.
32
+
33
+ Example
34
+
35
+ Input
36
+
37
+ 10 4
38
+ 1 2 3 1 1 2 2 2 9 9
39
+ 1 1 1
40
+ 1 2 8
41
+ 2 7 1
42
+ 1 2 8
43
+
44
+
45
+ Output
46
+
47
+ 2
48
+ 3
49
+ 2
50
+
51
+ Note
52
+
53
+ The subarray of the first query consists of the single element — 1.
54
+
55
+ The subarray of the second query consists of four 2s, one 3 and two 1s.
56
+
57
+ The subarray of the fourth query consists of three 1s, three 2s and one 3.
58
+
59
+ ## Contest Information
60
+ - **Contest ID**: 940
61
+ - **Problem Index**: F
62
+ - **Points**: 2750.0
63
+ - **Rating**: 2600
64
+ - **Tags**: brute force, data structures
65
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
66
+ - **Memory Limit**: 512000000 bytes
67
+
68
+ ## Task
69
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10585/instruction.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # avoid-boredom
2
+
3
+ ## Problem Description
4
+ Exams are approaching soon and everyone tries to get ready for them. So, Omar decides to begin studying his subjects. He has N subjects and he wants to study M of them today. According to Omar, every subject has an interest level, A_i which indicates how much Omar likes that subject. Unfortunately, Omar feels bored easily, so he decides to choose a collection of interesting and boring subjects. Actually, Omar wants to choose M subjects such that the summation S of the absolute difference between every two adjacent subjects' interest levels is maximum as possible. Omar will put the selected M subjects in a group in the same order as described in the input, and then he will proceed to calculate S.
5
+
6
+ Please help Omar and rescue him from boredom
7
+
8
+ Input:
9
+
10
+ First line of the input contains an integer T denoting the number of test cases.
11
+ First line of every test-case contains two space separated integers N and M.
12
+ Second line of every test case contains N space separated integers A_i denoting the interest level for i^{th} subject.
13
+
14
+ *Output: *
15
+
16
+ For each case, print the above described S in a separate line.
17
+
18
+ Constraints:
19
+
20
+ 1 ≤ N ≤ 100.
21
+ 1 ≤ M ≤ N.
22
+ 1 ≤ A_i ≤ 10^{9}
23
+
24
+ SAMPLE INPUT
25
+ 1
26
+ 5 3
27
+ 100 50 3000 4000 40
28
+
29
+ SAMPLE OUTPUT
30
+ 7910
31
+
32
+ Explanation
33
+
34
+ You should choose the following group (50,4000,40) in the same order that appears in the input. S = |50-4000|+|4000-40| = 7910.
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-1064/instruction.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1325_C. Ehab and Path-etic MEXs
2
+
3
+ ## Problem Description
4
+ You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:
5
+
6
+ * Every label is an integer between 0 and n-2 inclusive.
7
+ * All the written labels are distinct.
8
+ * The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as possible.
9
+
10
+
11
+
12
+ Here, MEX(u,v) denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node u to node v.
13
+
14
+ Input
15
+
16
+ The first line contains the integer n (2 ≤ n ≤ 10^5) — the number of nodes in the tree.
17
+
18
+ Each of the next n-1 lines contains two space-separated integers u and v (1 ≤ u,v ≤ n) that mean there's an edge between nodes u and v. It's guaranteed that the given graph is a tree.
19
+
20
+ Output
21
+
22
+ Output n-1 integers. The i^{th} of them will be the number written on the i^{th} edge (in the input order).
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+
29
+ 3
30
+ 1 2
31
+ 1 3
32
+
33
+
34
+ Output
35
+
36
+
37
+ 0
38
+ 1
39
+
40
+
41
+ Input
42
+
43
+
44
+ 6
45
+ 1 2
46
+ 1 3
47
+ 2 4
48
+ 2 5
49
+ 5 6
50
+
51
+
52
+ Output
53
+
54
+
55
+ 0
56
+ 3
57
+ 2
58
+ 4
59
+ 1
60
+
61
+ Note
62
+
63
+ The tree from the second sample:
64
+
65
+ <image>
66
+
67
+ ## Contest Information
68
+ - **Contest ID**: 1325
69
+ - **Problem Index**: C
70
+ - **Points**: 1250.0
71
+ - **Rating**: 1500
72
+ - **Tags**: constructive algorithms, dfs and similar, greedy, trees
73
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
74
+ - **Memory Limit**: 256000000 bytes
75
+
76
+ ## Task
77
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1065/instruction.md ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1344_B. Monopole Magnets
2
+
3
+ ## Problem Description
4
+ A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.
5
+
6
+ There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowed to place as many magnets as you like, even multiple in the same cell.
7
+
8
+ An operation is performed as follows. Choose a north magnet and a south magnet to activate. If they are in the same row or the same column and they occupy different cells, then the north magnet moves one unit closer to the south magnet. Otherwise, if they occupy the same cell or do not share a row or column, then nothing changes. Note that the south magnets are immovable.
9
+
10
+ Each cell of the grid is colored black or white. Let's consider ways to place magnets in the cells so that the following conditions are met.
11
+
12
+ 1. There is at least one south magnet in every row and every column.
13
+ 2. If a cell is colored black, then it is possible for a north magnet to occupy this cell after some sequence of operations from the initial placement.
14
+ 3. If a cell is colored white, then it is impossible for a north magnet to occupy this cell after some sequence of operations from the initial placement.
15
+
16
+
17
+
18
+ Determine if it is possible to place magnets such that these conditions are met. If it is possible, find the minimum number of north magnets required (there are no requirements on the number of south magnets).
19
+
20
+ Input
21
+
22
+ The first line contains two integers n and m (1≤ n,m≤ 1000) — the number of rows and the number of columns, respectively.
23
+
24
+ The next n lines describe the coloring. The i-th of these lines contains a string of length m, where the j-th character denotes the color of the cell in row i and column j. The characters "#" and "." represent black and white, respectively. It is guaranteed, that the string will not contain any other characters.
25
+
26
+ Output
27
+
28
+ Output a single integer, the minimum possible number of north magnets required.
29
+
30
+ If there is no placement of magnets that satisfies all conditions, print a single integer -1.
31
+
32
+ Examples
33
+
34
+ Input
35
+
36
+
37
+ 3 3
38
+ .#.
39
+ ###
40
+ ##.
41
+
42
+
43
+ Output
44
+
45
+
46
+ 1
47
+
48
+
49
+ Input
50
+
51
+
52
+ 4 2
53
+ ##
54
+ .#
55
+ .#
56
+ ##
57
+
58
+
59
+ Output
60
+
61
+
62
+ -1
63
+
64
+
65
+ Input
66
+
67
+
68
+ 4 5
69
+ ....#
70
+ ####.
71
+ .###.
72
+ .#...
73
+
74
+
75
+ Output
76
+
77
+
78
+ 2
79
+
80
+
81
+ Input
82
+
83
+
84
+ 2 1
85
+ .
86
+ #
87
+
88
+
89
+ Output
90
+
91
+
92
+ -1
93
+
94
+
95
+ Input
96
+
97
+
98
+ 3 5
99
+ .....
100
+ .....
101
+ .....
102
+
103
+
104
+ Output
105
+
106
+
107
+ 0
108
+
109
+ Note
110
+
111
+ In the first test, here is an example placement of magnets:
112
+
113
+ <image>
114
+
115
+ In the second test, we can show that no required placement of magnets exists. Here are three example placements that fail to meet the requirements. The first example violates rule 3 since we can move the north magnet down onto a white square. The second example violates rule 2 since we cannot move the north magnet to the bottom-left black square by any sequence of operations. The third example violates rule 1 since there is no south magnet in the first column.
116
+
117
+ <image>
118
+
119
+ In the third test, here is an example placement of magnets. We can show that there is no required placement of magnets with fewer north magnets.
120
+
121
+ <image>
122
+
123
+ In the fourth test, we can show that no required placement of magnets exists. Here are two example placements that fail to meet the requirements. The first example violates rule 1 since there is no south magnet in the first row. The second example violates rules 1 and 3 since there is no south magnet in the second row and we can move the north magnet up one unit onto a white square.
124
+
125
+ <image>
126
+
127
+ In the fifth test, we can put the south magnet in each cell and no north magnets. Because there are no black cells, it will be a correct placement.
128
+
129
+ ## Contest Information
130
+ - **Contest ID**: 1344
131
+ - **Problem Index**: B
132
+ - **Points**: 1000.0
133
+ - **Rating**: 2000
134
+ - **Tags**: constructive algorithms, dfs and similar, dsu, graphs
135
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
136
+ - **Memory Limit**: 256000000 bytes
137
+
138
+ ## Task
139
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10744/instruction.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1279_A. New Year Garland
2
+
3
+ ## Problem Description
4
+ Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
5
+
6
+ The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!
7
+
8
+ For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.
9
+
10
+ However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.
11
+
12
+ So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.
13
+
14
+ Input
15
+
16
+ The first line contains a single integer t (1 ≤ t ≤ 100) — the number of sets of lamps Polycarp has bought.
17
+
18
+ Each of the next t lines contains three integers r, g and b (1 ≤ r, g, b ≤ 10^9) — the number of red, green and blue lamps in the set, respectively.
19
+
20
+ Output
21
+
22
+ Print t lines — for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.
23
+
24
+ Example
25
+
26
+ Input
27
+
28
+
29
+ 3
30
+ 3 3 3
31
+ 1 10 2
32
+ 2 1 1
33
+
34
+
35
+ Output
36
+
37
+
38
+ Yes
39
+ No
40
+ Yes
41
+
42
+ Note
43
+
44
+ The first two sets are desribed in the statement.
45
+
46
+ The third set produces garland "RBRG", for example.
47
+
48
+ ## Contest Information
49
+ - **Contest ID**: 1279
50
+ - **Problem Index**: A
51
+ - **Points**: 0.0
52
+ - **Rating**: 900
53
+ - **Tags**: math
54
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
55
+ - **Memory Limit**: 256000000 bytes
56
+
57
+ ## Task
58
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10911/instruction.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03122 World Tour Finals 2019 - Triangular Lamps Hard
2
+
3
+ ## Problem Description
4
+ Red bold fonts show the difference from C1.
5
+
6
+ There is an infinitely large triangular grid, as shown below. Each point with integer coordinates contains a lamp.
7
+
8
+ <image>
9
+
10
+ Initially, only the lamp at (X, Y) was on, and all other lamps were off. Then, Snuke performed the following operation zero or more times:
11
+
12
+ * Choose two integers x and y. Toggle (on to off, off to on) the following three lamps: (x, y), (x, y+1), (x+1, y).
13
+
14
+
15
+
16
+ After the operations, N lamps (x_1, y_1), \cdots, (x_N, y_N) are on, and all other lamps are off. Find X and Y.
17
+
18
+ Constraints
19
+
20
+ * 1 \leq N \leq 10^4
21
+ * -10^{17} \leq x_i, y_i \leq 10^{17}
22
+ * (x_i, y_i) are pairwise distinct.
23
+ * The input is consistent with the statement, and you can uniquely determine X and Y.
24
+
25
+ Input
26
+
27
+ Input is given from Standard Input in the following format:
28
+
29
+
30
+ N
31
+ x_1 y_1
32
+ :
33
+ x_N y_N
34
+
35
+
36
+ Output
37
+
38
+ Print X and Y, separated by a space.
39
+
40
+ Example
41
+
42
+ Input
43
+
44
+ 4
45
+ -2 1
46
+ -2 2
47
+ 0 1
48
+ 1 0
49
+
50
+
51
+ Output
52
+
53
+ -1 0
54
+
55
+ ## Contest Information
56
+ - **Contest ID**: 0
57
+ - **Problem Index**:
58
+ - **Points**: 0.0
59
+ - **Rating**: 0
60
+ - **Tags**:
61
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
62
+ - **Memory Limit**: 1073741824 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-10927/instruction.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01494 ThreeRooks
2
+
3
+ ## Problem Description
4
+ Example
5
+
6
+ Input
7
+
8
+ 3 3 1
9
+ 0 0
10
+
11
+
12
+ Output
13
+
14
+ 4
15
+
16
+ ## Contest Information
17
+ - **Contest ID**: 0
18
+ - **Problem Index**:
19
+ - **Points**: 0.0
20
+ - **Rating**: 0
21
+ - **Tags**:
22
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
23
+ - **Memory Limit**: 134217728 bytes
24
+
25
+ ## Task
26
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10928/instruction.md ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01660 Sugoroku
2
+
3
+ ## Problem Description
4
+ E-Sugoroku
5
+
6
+ Bob, a fox with no friends, decided to spend his time playing sugoroku alone today. A 6-sided die with integers a_1, a_2, a_3, a_4, a_5, a_6 written on each side, a piece, and M squares on a straight line, and numbers from 1 to M are assigned in order from the left. I decided to use a board. Instructions are written in numbers in each square of the sugoroku board, and the number N_i is written in the i-th square. This means that if the value is positive, move it to the right, if it is negative, move it to the left, and move the piece by its absolute value. That is, it means to move the piece to the i + N_ith square. Bob plays sugoroku as follows. First, place the piece at the starting point. Next, roll the dice, look at the number of dice rolled, and select whether to "move the piece to the right from the current square", "move to the left", or "stay in the current square". it can. When moving from a square, move the piece by the distance of the dice roll and follow the instructions of the square to which you have moved. Do not follow the instructions of the square to which you moved according to the instructions. After that, Bob repeats rolling the dice and moving the pieces as described above. If a piece comes out of the sugoroku board as a result of moving, Bob loses and it is judged as a wrong answer (Wrong Answer). The purpose of this problem is to reach this sugoroku goal. The number of dice rolls should be 3000 or less.
7
+
8
+ Input / output format
9
+
10
+ The input is given in the following format.
11
+
12
+
13
+ M
14
+ a_1 a_2 a_3 a_4 a_5 a_6
15
+ s g
16
+ N_1 ... N_M
17
+
18
+
19
+ M is the number of squares on the sugoroku board. a_1 ... a_6 is the integer value written on each side of the dice. s and g are the start and goal numbers of the sugoroku board, respectively. N_i is the instruction written in the i-th cell. After these inputs, the value dice, which represents the result of rolling the dice, is given by the input, followed by a line break. This means that the roll of the dice is adice. On the other hand, your program must decide whether to advance the piece and output the selection. Output `1` to move the piece to the right,` -1` to move it to the left, and `0` to stay in the current cell. Output a line break after the output. If you output whether your program advances, returns, or stays, you can receive the result of rolling the next dice from the input. Repeat this. For example in C / C ++
20
+
21
+
22
+ scanf ("% d", & dice;);
23
+
24
+ If you receive the number of the face of the dice as, and move to the left against this
25
+
26
+
27
+ printf ("-1 \ n"); fflush (stdout);
28
+
29
+ Let. next,
30
+
31
+
32
+ scanf ("% d", & dice;);
33
+
34
+ Then, you can receive the number of the next dice face. End the program as soon as you reach the goal. The number of dice rolls must be 3000 or less before reaching the goal. If the number of dice rolls exceeds 3000 in the middle, it is judged as an incorrect answer.
35
+
36
+ Constraint
37
+
38
+ * 2 ≤ M ≤ 300
39
+ * 1 ≤ s ≤ M, 1 ≤ g ≤ M
40
+ * s \ neq g
41
+ * 1 ≤ a_i ≤ M-1
42
+ * 1 ≤ dice ≤ 6
43
+ * N_s = N_g = 0
44
+ * You will not advance the piece according to the command of the square and go out of the frame.
45
+ * dice is uniformly and randomly selected from \\ {1,2,…, 6 \\} with pseudo-random numbers.
46
+ * No matter how much you roll the dice, you will not be given a board that you cannot reach the goal.
47
+ * All input values ​​are integers.
48
+
49
+ Input / output example 1
50
+
51
+
52
+
53
+
54
+ Sugoroku explanation | Program output | Program input | Dice roll |
55
+ --- | --- | --- | --- | ---
56
+
57
+ | | 10
58
+ 1 6 2 5 3 4
59
+ 1 10
60
+ 0 -1 3 -1 3 -2 -6 -5 -7 0
61
+ | |
62
+
63
+ 1st dice | | 1 | 1 |
64
+
65
+ Output of the first program | 0 | | | 1
66
+
67
+ Second dice | | 3 | 2 |
68
+
69
+ Second program output | 1 | | | 6
70
+
71
+ 3rd dice | | 5 | 3 |
72
+
73
+ Output of the third program | 0 | | | 6
74
+
75
+ 4th dice | | 1 | 1 |
76
+
77
+ Output of the 4th program | -1 | | | 8
78
+
79
+ 5th dice | | 3 | 2 |
80
+ | 5th program output | 1 | | | 10
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ Example
90
+
91
+ Input
92
+
93
+
94
+
95
+
96
+ Output
97
+
98
+ ## Contest Information
99
+ - **Contest ID**: 0
100
+ - **Problem Index**:
101
+ - **Points**: 0.0
102
+ - **Rating**: 0
103
+ - **Tags**:
104
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
105
+ - **Memory Limit**: 134217728 bytes
106
+
107
+ ## Task
108
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10929/instruction.md ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01807 Stamp Rally
2
+
3
+ ## Problem Description
4
+ Stamp Rally
5
+
6
+ Stamp Rally
7
+
8
+ The Japan Amusement Group (JAG) is planning an event at a theme park that imitates an island country. In this event, each time a participant crosses a bridge, the stamps decided for each bridge are stamped in order on the stamp book. The prepared stamp is one of the following seven types.
9
+
10
+
11
+ a () [] + *
12
+
13
+ It is clear if you walk across the bridge from the start to the goal and the sequence of stamps stamped is the correct formula. However, the direction of crossing the bridge is fixed, and it is not possible to cross in the opposite direction. You can cross the same bridge many times, and if you finally reach the goal point, you may continue to collect stamps after reaching the goal point. The correct formula is <expression> defined by BNF below.
14
+
15
+
16
+ <expression> :: = <term> | <expression> "+" <term>
17
+ <term> :: = <factor> | <term> "*" <factor>
18
+ <factor> :: = "a" | "(" <expression> ")" | "[" <expression> "]"
19
+
20
+ Since I decided the start goal and the stamp for each bridge, I tried it with the people concerned, but no one appeared to clear it. Perhaps it cannot be cleared with this setting.
21
+
22
+ Since the start / goal and bridge information is given, write a program to judge whether it can be cleared.
23
+
24
+ Input
25
+
26
+ The input consists of 50 or less datasets. Each data set is represented in the following format.
27
+
28
+ > n m s t
29
+ > a1 b1 c1
30
+ > ...
31
+ > am bm cm
32
+
33
+ The first line of the dataset consists of four integers n, m, s, and t separated by a single whitespace character. n is the number of islands, and we can assume that 1 ≤ n ≤ 200. Each island is numbered from 1 to n. m is the number of bridges and we can assume that 1 ≤ m ≤ 100,000. s is the starting island number and t is the goal island number. Sometimes the start and finish are on the same island. Each of the following m lines consists of two integers separated by one space character and one character. ai and bi represent the crossing from island ai to island bi by the i-th bridge, and ci represents the stamp stamped by the i-th bridge. There may be multiple bridges between two islands, or there may be bridges within one island.
34
+
35
+ The end of the input is indicated by a single line of four zeros.
36
+
37
+ Output
38
+
39
+ For each dataset, output "Yes" if it can be cleared, and "No" if it cannot be cleared on one line.
40
+
41
+ Sample Input
42
+
43
+
44
+ 4 5 1 4
45
+ 1 2 (
46
+ 1 3 a
47
+ 2 4 a
48
+ 3 4)
49
+ 3 2 +
50
+ 4 4 1 2
51
+ 13 (
52
+ 3 4 a
53
+ 4 1 +
54
+ 3 2 a
55
+ 3 4 1 1
56
+ 1 2 a
57
+ 2 2 +
58
+ 2 3 a
59
+ 3 1 a
60
+ 5 8 1 5
61
+ 1 1 [
62
+ 1 2 (
63
+ twenty one *
64
+ 2 2 a
65
+ 2 3 a
66
+ 3 3)
67
+ 3 4]
68
+ 4 5)
69
+ 2 14 1 1
70
+ 1 2 a
71
+ 1 2 (
72
+ 1 2)
73
+ 1 2 [
74
+ 1 2]
75
+ 1 2 +
76
+ 1 2 *
77
+ 2 1 a
78
+ twenty one (
79
+ twenty one )
80
+ twenty one [
81
+ twenty one ]
82
+ 2 1 +
83
+ twenty one *
84
+ 0 0 0 0
85
+
86
+ Output for Sample Input
87
+
88
+
89
+ Yes
90
+ No
91
+ No
92
+ Yes
93
+ No
94
+
95
+
96
+
97
+
98
+
99
+ Example
100
+
101
+ Input
102
+
103
+ 4 5 1 4
104
+ 1 2 (
105
+ 1 3 a
106
+ 2 4 a
107
+ 3 4 )
108
+ 3 2 +
109
+ 4 4 1 2
110
+ 1 3 (
111
+ 3 4 a
112
+ 4 1 +
113
+ 3 2 a
114
+ 3 4 1 1
115
+ 1 2 a
116
+ 2 2 +
117
+ 2 3 a
118
+ 3 1 a
119
+ 5 8 1 5
120
+ 1 1 [
121
+ 1 2 (
122
+ 2 1 *
123
+ 2 2 a
124
+ 2 3 a
125
+ 3 3 )
126
+ 3 4 ]
127
+ 4 5 )
128
+ 2 14 1 1
129
+ 1 2 a
130
+ 1 2 (
131
+ 1 2 )
132
+ 1 2 [
133
+ 1 2 ]
134
+ 1 2 +
135
+ 1 2 *
136
+ 2 1 a
137
+ 2 1 (
138
+ 2 1 )
139
+ 2 1 [
140
+ 2 1 ]
141
+ 2 1 +
142
+ 2 1 *
143
+ 0 0 0 0
144
+
145
+
146
+ Output
147
+
148
+ Yes
149
+ No
150
+ No
151
+ Yes
152
+ No
153
+
154
+ ## Contest Information
155
+ - **Contest ID**: 0
156
+ - **Problem Index**:
157
+ - **Points**: 0.0
158
+ - **Rating**: 0
159
+ - **Tags**:
160
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
161
+ - **Memory Limit**: 268435456 bytes
162
+
163
+ ## Task
164
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1096/instruction.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 676_A. Nicholas and Permutation
2
+
3
+ ## Problem Description
4
+ Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
5
+
6
+ Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
7
+
8
+ Input
9
+
10
+ The first line of the input contains a single integer n (2 ≤ n ≤ 100) — the size of the permutation.
11
+
12
+ The second line of the input contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is equal to the element at the i-th position.
13
+
14
+ Output
15
+
16
+ Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 5
23
+ 4 5 1 3 2
24
+
25
+
26
+ Output
27
+
28
+ 3
29
+
30
+
31
+ Input
32
+
33
+ 7
34
+ 1 6 5 3 4 7 2
35
+
36
+
37
+ Output
38
+
39
+ 6
40
+
41
+
42
+ Input
43
+
44
+ 6
45
+ 6 5 4 3 2 1
46
+
47
+
48
+ Output
49
+
50
+ 5
51
+
52
+ Note
53
+
54
+ In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
55
+
56
+ In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
57
+
58
+ In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
59
+
60
+ ## Contest Information
61
+ - **Contest ID**: 676
62
+ - **Problem Index**: A
63
+ - **Points**: 500.0
64
+ - **Rating**: 800
65
+ - **Tags**: constructive algorithms, implementation
66
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
67
+ - **Memory Limit**: 256000000 bytes
68
+
69
+ ## Task
70
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11032/instruction.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01733 Fox Observation
2
+
3
+ ## Problem Description
4
+ Ievan Ritola is a researcher of behavioral ecology. Her group visited a forest to analyze an ecological system of some kinds of foxes.
5
+
6
+ The forest can be expressed as a two-dimensional plane. With her previous research, foxes in the forest are known to live at lattice points. Here, lattice points are the points whose x and y coordinates are both integers. Two or more foxes might live at the same point.
7
+
8
+ To observe the biology of these foxes, they decided to put a pair of sensors in the forest. The sensors can be put at lattice points. Then, they will be able to observe all foxes inside the bounding rectangle (including the boundary) where the sensors are catty-corner to each other. The sensors cannot be placed at the points that have the same x or y coordinate; in other words the rectangle must have non-zero area.
9
+
10
+ The more foxes can be observed, the more data can be collected; on the other hand, monitoring a large area consumes a large amount of energy. So they want to maximize the value given by N' / (|x_1 − x_2| × |y_1 − y_2|), where N' is the number of foxes observed and (x_1, y_1) and (x_2, y_2) are the positions of the two sensors.
11
+
12
+ Let's help her observe cute foxes!
13
+
14
+ Input
15
+
16
+ The input is formatted as follows.
17
+
18
+
19
+ N
20
+ x_1 y_1 w_1
21
+ x_2 y_2 w_2
22
+ :
23
+ :
24
+ x_N y_N w_N
25
+
26
+
27
+ The first line contains a single integer N (1 ≤ N ≤ 10^5) indicating the number of the fox lairs in the forest. Each of the next N lines contains three integers x_i, y_i (|x_i|,\, |y_i| ≤ 10^9) and w_i (1 ≤ w_i ≤ 10^4), which represent there are w_i foxes at the point (x_i, y_i). It is guaranteed that all points are mutually different.
28
+
29
+ Output
30
+
31
+ Output the maximized value as a fraction:
32
+
33
+
34
+ a / b
35
+
36
+
37
+ where a and b are integers representing the numerator and the denominato respectively. There should be exactly one space before and after the slash. The fraction should be written in the simplest form, that is, a and b must not have a common integer divisor greater than one.
38
+
39
+ If the value becomes an integer, print a fraction with the denominator of one (e.g. `5 / 1` to represent 5). This implies zero should be printed as `0 / 1` (without quotes).
40
+
41
+ Sample Input 1
42
+
43
+
44
+ 2
45
+ 1 1 2
46
+ 2 2 3
47
+
48
+
49
+ Output for the Sample Input 1
50
+
51
+
52
+ 5 / 1
53
+
54
+
55
+
56
+
57
+
58
+
59
+ Example
60
+
61
+ Input
62
+
63
+ 2
64
+ 1 1 2
65
+ 2 2 3
66
+
67
+
68
+ Output
69
+
70
+ 5 / 1
71
+
72
+ ## Contest Information
73
+ - **Contest ID**: 0
74
+ - **Problem Index**:
75
+ - **Points**: 0.0
76
+ - **Rating**: 0
77
+ - **Tags**:
78
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
79
+ - **Memory Limit**: 268435456 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-11033/instruction.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01872 My Number
2
+
3
+ ## Problem Description
4
+ A: My Number-My Number-
5
+
6
+ problem
7
+
8
+ I'm sorry! Late late!
9
+
10
+ Ah! I'm starting to work for this company I've been longing for today!
11
+
12
+ Even so, I've been oversleeping since the first day ...! ??
13
+
14
+ Today is an important day when I have to tell my number to the company ...!
15
+
16
+ I think everyone knows, but I'll explain my number for the time being!
17
+
18
+ My Number is a 12-digit number string (P_ {11} P_ {10} P_ {9} ... P_ {1} P_ {0}) used to identify an individual in administrative procedures.
19
+
20
+ The P_ {0} at the end is called a check digit and is defined by the following equation as stipulated in Chapter 5 of the Ordinance No. 85 of the Ministry of Internal Affairs and Communications.
21
+
22
+ * 11 − (({\ rm Σ} _ {n = 1} ^ {11} P_ {n} × Q_ {n}) divided by 11)
23
+ * However, if (({\ rm Σ} _ {n = 1} ^ {11} P_ {n} × Q_ {n}) is the remainder divided by 11) \ ≤ 1, it is set to 0.
24
+
25
+
26
+
27
+ Here, Q_ {n} (n = 1, 2, ..., 11) is defined as follows.
28
+
29
+ * 1 When \ ≤ n \ ≤ 6 n + 1
30
+ * 7 \ ≤ n \ ≤ 11 n − 5
31
+
32
+
33
+
34
+ do you understand?
35
+
36
+ But I can't remember the 12-digit number string, so I took a picture of my number notice just before I left home!
37
+
38
+ You see, my number is cool!
39
+
40
+ What is that?
41
+
42
+ Why are natto grains on my number! ??
43
+
44
+ Then, I can't tell my number because I don't know only one digit!
45
+
46
+ What will happen to me from now on ...! ??
47
+
48
+ That's it!
49
+
50
+ Find a number that is consistent with the check digit definition!
51
+
52
+ But it's difficult to calculate ...
53
+
54
+ Hey, help me find the numbers I don't know so I won't fail my first day! ??
55
+
56
+ eh?
57
+
58
+ Did you find it hard to understand what you were saying?
59
+
60
+ In short, what I want you to do
61
+
62
+ Since you will be given a 12-digit My Number whose number is unknown by only one digit, ask for an unknown digit number so as not to contradict the definition of the check digit.
63
+
64
+ However, if there are multiple such numbers, output “MULTIPLE”.
65
+
66
+ That's it!
67
+
68
+ Nice to meet you!
69
+
70
+ Input format
71
+
72
+ The input is a 12-character string S = P_ {11} P_ {10} P_ {9} ... P_ {1} P_ {0} and one line feed is given in this order. Note that the P subscripts are in descending order. Each character in this string is “0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “?” Is one of. “?” Represents an unknown digit, and other characters represent the number of My Number. Also, the “?” Appears exactly once in S. It is guaranteed that there is at least one number in an unknown digit that does not contradict the definition of the check digit.
73
+
74
+ Output format
75
+
76
+ If there is only one number in an unknown digit that does not contradict the definition of the check digit, output that number. If there are multiple numbers that do not conflict, output “MULTIPLE”. In either case, start a new line only once at the end.
77
+
78
+ Input example 1
79
+
80
+
81
+ ? 12345678901
82
+
83
+ Output example 1
84
+
85
+
86
+ Four
87
+
88
+ From the check digit definition, the “?” Cannot be anything other than 4.
89
+
90
+ Input example 2
91
+
92
+
93
+ 2016030810? 0
94
+
95
+ Output example 2
96
+
97
+
98
+ MULTIPLE
99
+
100
+ Whether the “?” Is 0 or 6, the check digit definition is satisfied.
101
+
102
+ Input example 3
103
+
104
+
105
+ 20160308100?
106
+
107
+ Output example 3
108
+
109
+
110
+ 0
111
+
112
+ Input example 4
113
+
114
+
115
+ 0012300-0450
116
+
117
+ Output example 4
118
+
119
+
120
+ 8
121
+
122
+
123
+
124
+
125
+
126
+ Example
127
+
128
+ Input
129
+
130
+ ?12345678901
131
+
132
+
133
+ Output
134
+
135
+ 4
136
+
137
+ ## Contest Information
138
+ - **Contest ID**: 0
139
+ - **Problem Index**:
140
+ - **Points**: 0.0
141
+ - **Rating**: 0
142
+ - **Tags**:
143
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
144
+ - **Memory Limit**: 268435456 bytes
145
+
146
+ ## Task
147
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11034/instruction.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02009 Nim without Zero
2
+
3
+ ## Problem Description
4
+ Alice: "Hi, Bob! Let's play Nim!"
5
+ Bob: "Are you serious? I don't want to play it. I know how to win the game."
6
+ Alice: "Right, there is an algorithm to calculate the optimal move using XOR. How about changing the rule so that a player loses a game if he or she makes the XOR to $0$?"
7
+ Bob: "It sounds much better now, but I suspect you know the surefire way to win."
8
+ Alice: "Do you wanna test me?"
9
+ This game is defined as follows.
10
+
11
+
12
+ 1. The game starts with $N$ heaps where the $i$-th of them consists of $a_i$ stones.
13
+ 2. A player takes any positive number of stones from any single one of the heaps in one move.
14
+ 3. Alice moves first. The two players alternately move.
15
+ 4. If the XOR sum, $a_1$ XOR $a_2$ XOR $...$ XOR $a_N$, of the numbers of remaining stones of these heaps becomes $0$ as a result of a player's move, the player loses.
16
+
17
+
18
+
19
+ Your task is to find which player will win if they do the best move.
20
+
21
+
22
+
23
+ Input
24
+
25
+ The input consists of a single test case in the format below.
26
+
27
+
28
+ $N$
29
+ $a_1$
30
+ $\vdots$
31
+ $a_N$
32
+
33
+
34
+ The first line contains an integer $N$ which is the number of the heaps ($1 \leq N \leq 10^5$). Each of the following $N$ lines gives the number of stones in each heap ($1 \leq a_i \leq 10^9$).
35
+
36
+ Output
37
+
38
+ Output the winner, Alice or Bob, when they do the best move.
39
+
40
+ Examples
41
+
42
+ Input
43
+
44
+ 2
45
+ 1
46
+ 1
47
+
48
+
49
+ Output
50
+
51
+ Alice
52
+
53
+
54
+ Input
55
+
56
+ 5
57
+ 1
58
+ 2
59
+ 3
60
+ 4
61
+ 5
62
+
63
+
64
+ Output
65
+
66
+ Bob
67
+
68
+
69
+ Input
70
+
71
+ 10
72
+ 1
73
+ 2
74
+ 3
75
+ 4
76
+ 5
77
+ 6
78
+ 7
79
+ 8
80
+ 9
81
+ 10
82
+
83
+
84
+ Output
85
+
86
+ Alice
87
+
88
+ ## Contest Information
89
+ - **Contest ID**: 0
90
+ - **Problem Index**:
91
+ - **Points**: 0.0
92
+ - **Rating**: 0
93
+ - **Tags**:
94
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
95
+ - **Memory Limit**: 536870912 bytes
96
+
97
+ ## Task
98
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11201/instruction.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 807_A. Is it rated?
2
+
3
+ ## Problem Description
4
+ Is it rated?
5
+
6
+ Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
7
+
8
+ Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
9
+
10
+ It's known that if at least one participant's rating has changed, then the round was rated for sure.
11
+
12
+ It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
13
+
14
+ In this problem, you should not make any other assumptions about the rating system.
15
+
16
+ Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
17
+
18
+ Input
19
+
20
+ The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants.
21
+
22
+ Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
23
+
24
+ Output
25
+
26
+ If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+ 6
33
+ 3060 3060
34
+ 2194 2194
35
+ 2876 2903
36
+ 2624 2624
37
+ 3007 2991
38
+ 2884 2884
39
+
40
+
41
+ Output
42
+
43
+ rated
44
+
45
+
46
+ Input
47
+
48
+ 4
49
+ 1500 1500
50
+ 1300 1300
51
+ 1200 1200
52
+ 1400 1400
53
+
54
+
55
+ Output
56
+
57
+ unrated
58
+
59
+
60
+ Input
61
+
62
+ 5
63
+ 3123 3123
64
+ 2777 2777
65
+ 2246 2246
66
+ 2246 2246
67
+ 1699 1699
68
+
69
+
70
+ Output
71
+
72
+ maybe
73
+
74
+ Note
75
+
76
+ In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
77
+
78
+ In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
79
+
80
+ In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
81
+
82
+ ## Contest Information
83
+ - **Contest ID**: 807
84
+ - **Problem Index**: A
85
+ - **Points**: 500.0
86
+ - **Rating**: 900
87
+ - **Tags**: implementation, sortings
88
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
89
+ - **Memory Limit**: 256000000 bytes
90
+
91
+ ## Task
92
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11206/instruction.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 922_C. Cave Painting
2
+
3
+ ## Problem Description
4
+ Imp is watching a documentary about cave painting.
5
+
6
+ <image>
7
+
8
+ Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.
9
+
10
+ Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all <image>, 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that:
11
+
12
+ * 1 ≤ i < j ≤ k,
13
+ * <image>, where <image> is the remainder of division x by y.
14
+
15
+ Input
16
+
17
+ The only line contains two integers n, k (1 ≤ n, k ≤ 1018).
18
+
19
+ Output
20
+
21
+ Print "Yes", if all the remainders are distinct, and "No" otherwise.
22
+
23
+ You can print each letter in arbitrary case (lower or upper).
24
+
25
+ Examples
26
+
27
+ Input
28
+
29
+ 4 4
30
+
31
+
32
+ Output
33
+
34
+ No
35
+
36
+
37
+ Input
38
+
39
+ 5 3
40
+
41
+
42
+ Output
43
+
44
+ Yes
45
+
46
+ Note
47
+
48
+ In the first sample remainders modulo 1 and 4 coincide.
49
+
50
+ ## Contest Information
51
+ - **Contest ID**: 922
52
+ - **Problem Index**: C
53
+ - **Points**: 1250.0
54
+ - **Rating**: 1600
55
+ - **Tags**: brute force, number theory
56
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
57
+ - **Memory Limit**: 256000000 bytes
58
+
59
+ ## Task
60
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11239/instruction.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01438 Butterfly
2
+
3
+ ## Problem Description
4
+ Claire is a man-eater. She's a real man-eater. She's going around with dozens of guys. She's dating all the time. And one day she found some conflicts in her date schedule. D'oh!
5
+
6
+ So she needs to pick some dates and give the others up. The dates are set by hours like 13:00 to 15:00. She may have more than one date with a guy. For example, she can have dates with Adam from 10:00 to 12:00 and from 14:00 to 16:00 and with Bob from 12:00 to 13:00 and from 18:00 to 20:00. She can have these dates as long as there is no overlap of time. Time of traveling, time of make-up, trouble from love triangles, and the likes are not of her concern. Thus she can keep all the dates with Adam and Bob in the previous example. All dates are set between 6:00 and 22:00 on the same day.
7
+
8
+ She wants to get the maximum amount of satisfaction in total. Each guy gives her some satisfaction if he has all scheduled dates. Let's say, for example, Adam's satisfaction is 100 and Bob's satisfaction is 200. Then, since she can make it with both guys, she can get 300 in total. Your task is to write a program to satisfy her demand. Then she could spend a few hours with you... if you really want.
9
+
10
+
11
+
12
+ Input
13
+
14
+ The input consists of a sequence of datasets. Each dataset has the following format:
15
+
16
+ N
17
+ Guy1
18
+ ...
19
+ GuyN
20
+
21
+
22
+ The first line of the input contains an integer N (1 ≤ N ≤ 100), the number of guys. Then there come the descriptions of guys. Each description is given in this format:
23
+
24
+ M L
25
+ S1 E1
26
+ ...
27
+ SM EM
28
+
29
+
30
+ The first line contains two integers Mi (1 ≤ Mi ≤ 16) and Li (1 ≤ Li ≤ 100,000,000), the number of dates set for the guy and the satisfaction she would get from him respectively. Then M lines follow. The i-th line contains two integers Si and Ei (6 ≤ Si < Ei ≤ 22), the starting and ending time of the i-th date.
31
+
32
+ The end of input is indicated by N = 0.
33
+
34
+ Output
35
+
36
+ For each dataset, output in a line the maximum amount of satisfaction she can get.
37
+
38
+ Example
39
+
40
+ Input
41
+
42
+ 2
43
+ 2 100
44
+ 10 12
45
+ 14 16
46
+ 2 200
47
+ 12 13
48
+ 18 20
49
+ 4
50
+ 1 100
51
+ 6 22
52
+ 1 1000
53
+ 6 22
54
+ 1 10000
55
+ 6 22
56
+ 1 100000
57
+ 6 22
58
+ 16
59
+ 1 100000000
60
+ 6 7
61
+ 1 100000000
62
+ 7 8
63
+ 1 100000000
64
+ 8 9
65
+ 1 100000000
66
+ 9 10
67
+ 1 100000000
68
+ 10 11
69
+ 1 100000000
70
+ 11 12
71
+ 1 100000000
72
+ 12 13
73
+ 1 100000000
74
+ 13 14
75
+ 1 100000000
76
+ 14 15
77
+ 1 100000000
78
+ 15 16
79
+ 1 100000000
80
+ 16 17
81
+ 1 100000000
82
+ 17 18
83
+ 1 100000000
84
+ 18 19
85
+ 1 100000000
86
+ 19 20
87
+ 1 100000000
88
+ 20 21
89
+ 1 100000000
90
+ 21 22
91
+ 0
92
+
93
+
94
+ Output
95
+
96
+ 300
97
+ 100000
98
+ 1600000000
99
+
100
+ ## Contest Information
101
+ - **Contest ID**: 0
102
+ - **Problem Index**:
103
+ - **Points**: 0.0
104
+ - **Rating**: 0
105
+ - **Tags**:
106
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
107
+ - **Memory Limit**: 134217728 bytes
108
+
109
+ ## Task
110
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11263/instruction.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1231_B. Ania and Minimizing
2
+
3
+ ## Problem Description
4
+ Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?
5
+
6
+ Input
7
+
8
+ The first line contains two integers n and k (1 ≤ n ≤ 200 000, 0 ≤ k ≤ n) — the number of digits in the decimal representation of S and the maximum allowed number of changed digits.
9
+
10
+ The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes.
11
+
12
+ Output
13
+
14
+ Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+
21
+ 5 3
22
+ 51528
23
+
24
+
25
+ Output
26
+
27
+
28
+ 10028
29
+
30
+
31
+ Input
32
+
33
+
34
+ 3 2
35
+ 102
36
+
37
+
38
+ Output
39
+
40
+
41
+ 100
42
+
43
+
44
+ Input
45
+
46
+
47
+ 1 1
48
+ 1
49
+
50
+
51
+ Output
52
+
53
+
54
+ 0
55
+
56
+ Note
57
+
58
+ A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
59
+
60
+ ## Contest Information
61
+ - **Contest ID**: 1231
62
+ - **Problem Index**: B
63
+ - **Points**: 750.0
64
+ - **Rating**: 1000
65
+ - **Tags**: greedy, implementation
66
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
67
+ - **Memory Limit**: 256000000 bytes
68
+
69
+ ## Task
70
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11450/instruction.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01772 A-Z Cat
2
+
3
+ ## Problem Description
4
+ A: A-Z Cat / A-Z Cat
5
+
6
+ story
7
+
8
+ Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. It's so cute. Aizu Nyan was asked by her friend Joy to take care of her cat. It is a rare cat called A-Z cat. Aizunyan named the A-Z cat he had entrusted to him as "Aizunyan No. 2" (without permission), and he was very much loved.
9
+
10
+ A-Z cats are said to prefer strings that meet certain conditions. Then, when Aizunyan gave a character string as a trial, Aizunyan No. 2 had a satisfying expression after cutting a part of the character string with his nails. Apparently, I'm trying to rewrite it to my favorite character string.
11
+
12
+ D, who is crazy about Aizu Nyan, who is cute like an angel, found out the character string conditions that A-Z Cat likes for Aizu Nyan. It is a string in which'A'and'Z'are repeated alternately, and a string that starts with'A' and ends with'Z'. The A-Z cat is so smart that it tries to convert it to a string of your choice with minimal erasing. D, who wants to look good, decided to write a program to find out what kind of string the A-Z cat would convert from a given string consisting only of'A'and'Z'.
13
+
14
+ problem
15
+
16
+ Given a string S consisting only of uppercase letters. By deleting any number of S characters as much as you like, you can create a string in which'A'and'Z' appear alternately, and start with'A' and end with'Z'. Find the character string obtained when the number of deletions is minimized.
17
+
18
+ Input format
19
+
20
+ The string S is given on one line as input. S consists of uppercase letters only and satisfies 1 ≤ | S | ≤ 20.
21
+
22
+ Output format
23
+
24
+ Output the string that is obtained by deleting the minimum number of characters for S, in which'A'and'Z' appear alternately, and start with'A' and end with'Z' on one line. If no character string that meets the conditions is obtained by deleting any character, output -1 on one line.
25
+
26
+ Input example 1
27
+
28
+
29
+ AIZUNYAN PEROPERO
30
+
31
+ Output example 1
32
+
33
+
34
+ AZ
35
+
36
+ Input example 2
37
+
38
+
39
+ AZAZ
40
+
41
+ Output example 2
42
+
43
+
44
+ AZAZ
45
+
46
+ Input example 3
47
+
48
+
49
+ ZDDYAZAWABDDZAZPIDDA
50
+
51
+ Output example 3
52
+
53
+
54
+ AZAZAZ
55
+
56
+ Input example 4
57
+
58
+
59
+ ZZZZAAAAAA
60
+
61
+ Output example 4
62
+
63
+
64
+ -1
65
+
66
+
67
+
68
+
69
+
70
+ Example
71
+
72
+ Input
73
+
74
+ AIZUNYANPEROPERO
75
+
76
+
77
+ Output
78
+
79
+ AZ
80
+
81
+ ## Contest Information
82
+ - **Contest ID**: 0
83
+ - **Problem Index**:
84
+ - **Points**: 0.0
85
+ - **Rating**: 0
86
+ - **Tags**:
87
+ - **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
88
+ - **Memory Limit**: 134217728 bytes
89
+
90
+ ## Task
91
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11456/instruction.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # aran01
2
+
3
+ ## Problem Description
4
+ Oh my God!!! Someone is trying to break into Thapar University's Database and steal sensitive research information. It is now up to us to stop this attack. Fortunately our defense mechanisms have traced the attacks to their source. The fastest way to stop the attacks is to disable the source. So all we need to do is to teach that guy a lesson, by planting a virus in his own system. But before we can do that, we need to break through all the layers of the security he has put around himself.
5
+ Our sources tell us that the first layer is based on ASCII encryption. We must penetrate through this layer as fast as we can to reach the source...
6
+
7
+
8
+ Input:
9
+
10
+ The first line will consist of the total number of test cases T.
11
+ The next T lines will consist of one string on each line.The length of the string should be greater than 2.
12
+
13
+
14
+ Output:
15
+
16
+ For each test case, output is a single character.
17
+
18
+
19
+
20
+ Example:
21
+ Input:
22
+
23
+ 3
24
+ abcd
25
+ reverse
26
+ gear
27
+
28
+
29
+
30
+ Output:
31
+
32
+ b
33
+ m
34
+ g
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-11457/instruction.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # cieltomy
2
+
3
+ ## Problem Description
4
+ Tomya is a girl. She loves Chef Ciel very much.
5
+
6
+
7
+ Today, too, Tomya is going to Ciel's restaurant.
8
+ Of course, Tomya would like to go to Ciel's restaurant as soon as possible.
9
+ Therefore Tomya uses one of the shortest paths from Tomya's house to Ciel's restaurant.
10
+ On the other hand, Tomya is boring now to use the same path many times.
11
+ So Tomya wants to know the number of shortest paths from Tomya's house to Ciel's restaurant.
12
+ Your task is to calculate the number under the following assumptions.
13
+
14
+
15
+ This town has N intersections and M two way roads.
16
+ The i-th road connects from the Ai-th intersection to the Bi-th intersection, and its length is
17
+
18
+ Ci.
19
+ Tomya's house is in the 1st intersection, and Ciel's restaurant is in the N-th intersection.
20
+
21
+
22
+ Input
23
+
24
+ The first line contains an integer T, the number of test cases.
25
+ Then T test cases follow.
26
+ The first line of each test case contains 2 integers N, M.
27
+ Then next M lines contains 3 integers denoting Ai, Bi and Ci.
28
+
29
+
30
+ Output
31
+
32
+ For each test case, print the number of shortest paths from Tomya's house to Ciel's restaurant.
33
+
34
+
35
+ Constraints
36
+
37
+ 1 ≤ T ≤ 10
38
+ 2 ≤ N ≤ 10
39
+ 1 ≤ M ≤ N ∙ (N – 1) / 2
40
+ 1 ≤ Ai, Bi ≤ N
41
+ 1 ≤ Ci ≤ 10
42
+ Ai ≠ Bi
43
+ If i ≠ j and Ai = Aj, then Bi ≠ Bj
44
+ There is at least one path from Tomya's house to Ciel's restaurant.
45
+
46
+
47
+ Sample Input
48
+ 2
49
+ 3 3
50
+ 1 2 3
51
+ 2 3 6
52
+ 1 3 7
53
+ 3 3
54
+ 1 2 3
55
+ 2 3 6
56
+ 1 3 9
57
+
58
+ Sample Output
59
+ 1
60
+ 2
61
+
62
+ Explanations
63
+
64
+ In the first sample, only one shortest path exists, which is 1-3.
65
+
66
+
67
+ In the second sample, both paths 1-2-3 and 1-3 are the shortest paths.
68
+
69
+ ## Contest Information
70
+ - **Contest ID**: 0
71
+ - **Problem Index**:
72
+ - **Points**: 0.0
73
+ - **Rating**: 0
74
+ - **Tags**: None
75
+ - **Time Limit**: None seconds
76
+ - **Memory Limit**: 0 bytes
77
+
78
+ ## Task
79
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11607/instruction.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 533_C. Board Game
2
+
3
+ ## Problem Description
4
+ Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move.
5
+
6
+ There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0).
7
+
8
+ You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.
9
+
10
+ Input
11
+
12
+ The first line contains four integers: xp, yp, xv, yv (0 ≤ xp, yp, xv, yv ≤ 105) — Polycarp's and Vasiliy's starting coordinates.
13
+
14
+ It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0).
15
+
16
+ Output
17
+
18
+ Output the name of the winner: "Polycarp" or "Vasiliy".
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 2 1 2 2
25
+
26
+
27
+ Output
28
+
29
+ Polycarp
30
+
31
+
32
+ Input
33
+
34
+ 4 7 7 4
35
+
36
+
37
+ Output
38
+
39
+ Vasiliy
40
+
41
+ Note
42
+
43
+ In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn.
44
+
45
+ ## Contest Information
46
+ - **Contest ID**: 533
47
+ - **Problem Index**: C
48
+ - **Points**: 250.0
49
+ - **Rating**: 1700
50
+ - **Tags**: games, greedy, implementation, math
51
+ - **Time Limit**: {'seconds': 1, '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-11665/instruction.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # devhand
2
+
3
+ ## Problem Description
4
+ As you have probably realized up to now that Devu is not a normal guy, he is a very weird and abnormal guy. Normally people have two hands, but Devu has three of them. So he wears three wrist watches on his hands.
5
+
6
+
7
+ Devu loves to write name of his friends on his wrist watches. So he want to attach a string corresponding to name of his friends on each wrist watch. He is a quite particular about natural beauty, so he will not attach strings such that one of the string on a watch is prefix (not necessarily proper prefix) of some other string on other watch. Also alphabet size of characters in the string is equal to first K English Alphabets. (i.e. 1 ≤ K ≤ 26).
8
+
9
+
10
+ Now Devu wonders in how many ways he can select three non empty strings of length less than or equal to N to attach with his wrist watches. As answer could be very large, he wants you to print answer modulo 10^9 + 7.
11
+
12
+
13
+ Input
14
+ First line of test case contains a single integer T corresponding to the number of test cases.
15
+ For each test case, there will be a single line containing two space separated integers N, K.
16
+
17
+ Output
18
+ For each test case, print a single line corresponding to the answer of the problem.
19
+
20
+ Constraints
21
+
22
+ Example
23
+ Input:
24
+ 3
25
+ 1 2
26
+ 1 3
27
+ 2 2
28
+
29
+ Output:
30
+ 0
31
+ 6
32
+ 36
33
+
34
+ Explanation
35
+ Example #1.
36
+ There is no valid arrangement of three strings to the watches, because at least one of the string will be equal to other which will violate the property stated in the problem.
37
+
38
+ Example #2.
39
+ There are 6 possible arrangements of the strings to the watches.
40
+
41
+ {"a", "b", "c"}
42
+ {"a", "c", "b"}
43
+ {"b", "a", "c"}
44
+ {"b", "c", "a"}
45
+ {"c", "a", "b"}
46
+ {"c", "b", "a"}
47
+
48
+ ## Contest Information
49
+ - **Contest ID**: 0
50
+ - **Problem Index**:
51
+ - **Points**: 0.0
52
+ - **Rating**: 0
53
+ - **Tags**: None
54
+ - **Time Limit**: None seconds
55
+ - **Memory Limit**: 0 bytes
56
+
57
+ ## Task
58
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11691/instruction.md ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1473_D. Program
2
+
3
+ ## Problem Description
4
+ You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
5
+
6
+ * increase x by 1;
7
+ * decrease x by 1.
8
+
9
+
10
+
11
+ You are given m queries of the following format:
12
+
13
+ * query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
14
+
15
+ Input
16
+
17
+ The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
18
+
19
+ Then the description of t testcases follows.
20
+
21
+ The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
22
+
23
+ The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
24
+
25
+ Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
26
+
27
+ The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
28
+
29
+ Output
30
+
31
+ For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
32
+
33
+ Example
34
+
35
+ Input
36
+
37
+
38
+ 2
39
+ 8 4
40
+ -+--+--+
41
+ 1 8
42
+ 2 8
43
+ 2 5
44
+ 1 1
45
+ 4 10
46
+ +-++
47
+ 1 1
48
+ 1 2
49
+ 2 2
50
+ 1 3
51
+ 2 3
52
+ 3 3
53
+ 1 4
54
+ 2 4
55
+ 3 4
56
+ 4 4
57
+
58
+
59
+ Output
60
+
61
+
62
+ 1
63
+ 2
64
+ 4
65
+ 4
66
+ 3
67
+ 3
68
+ 4
69
+ 2
70
+ 3
71
+ 2
72
+ 1
73
+ 2
74
+ 2
75
+ 2
76
+
77
+ Note
78
+
79
+ The instructions that remain for each query of the first testcase are:
80
+
81
+ 1. empty program — x was only equal to 0;
82
+ 2. "-" — x had values 0 and -1;
83
+ 3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
84
+ 4. "+--+--+" — the distinct values are 1, 0, -1, -2.
85
+
86
+ ## Contest Information
87
+ - **Contest ID**: 1473
88
+ - **Problem Index**: D
89
+ - **Points**: 0.0
90
+ - **Rating**: 1700
91
+ - **Tags**: data structures, dp, implementation, strings
92
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
93
+ - **Memory Limit**: 256000000 bytes
94
+
95
+ ## Task
96
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11696/instruction.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 197_D. Infinite Maze
2
+
3
+ ## Problem Description
4
+ We've got a rectangular n × m-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell (x, y) is a wall if and only if cell <image> is a wall.
5
+
6
+ In this problem <image> is a remainder of dividing number a by number b.
7
+
8
+ The little boy stood at some cell on the plane and he wondered whether he can walk infinitely far away from his starting position. From cell (x, y) he can go to one of the following cells: (x, y - 1), (x, y + 1), (x - 1, y) and (x + 1, y), provided that the cell he goes to is not a wall.
9
+
10
+ Input
11
+
12
+ The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 1500) — the height and the width of the maze that the boy used to cyclically tile the plane.
13
+
14
+ Each of the next n lines contains m characters — the description of the labyrinth. Each character is either a "#", that marks a wall, a ".", that marks a passable cell, or an "S", that marks the little boy's starting point.
15
+
16
+ The starting point is a passable cell. It is guaranteed that character "S" occurs exactly once in the input.
17
+
18
+ Output
19
+
20
+ Print "Yes" (without the quotes), if the little boy can walk infinitely far from the starting point. Otherwise, print "No" (without the quotes).
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 5 4
27
+ ##.#
28
+ ##S#
29
+ #..#
30
+ #.##
31
+ #..#
32
+
33
+
34
+ Output
35
+
36
+ Yes
37
+
38
+
39
+ Input
40
+
41
+ 5 4
42
+ ##.#
43
+ ##S#
44
+ #..#
45
+ ..#.
46
+ #.##
47
+
48
+
49
+ Output
50
+
51
+ No
52
+
53
+ Note
54
+
55
+ In the first sample the little boy can go up for infinitely long as there is a "clear path" that goes vertically. He just needs to repeat the following steps infinitely: up, up, left, up, up, right, up.
56
+
57
+ In the second sample the vertical path is blocked. The path to the left doesn't work, too — the next "copy" of the maze traps the boy.
58
+
59
+ ## Contest Information
60
+ - **Contest ID**: 197
61
+ - **Problem Index**: D
62
+ - **Points**: 1000.0
63
+ - **Rating**: 2000
64
+ - **Tags**: dfs and similar, graphs
65
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
66
+ - **Memory Limit**: 256000000 bytes
67
+
68
+ ## Task
69
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11808/instruction.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 369_D. Valera and Fools
2
+
3
+ ## Problem Description
4
+ One fine morning, n fools lined up in a row. After that, they numbered each other with numbers from 1 to n, inclusive. Each fool got a unique number. The fools decided not to change their numbers before the end of the fun.
5
+
6
+ Every fool has exactly k bullets and a pistol. In addition, the fool number i has probability of pi (in percent) that he kills the fool he shoots at.
7
+
8
+ The fools decided to have several rounds of the fun. Each round of the fun looks like this: each currently living fool shoots at another living fool with the smallest number (a fool is not stupid enough to shoot at himself). All shots of the round are perfomed at one time (simultaneously). If there is exactly one living fool, he does not shoot.
9
+
10
+ Let's define a situation as the set of numbers of all the living fools at the some time. We say that a situation is possible if for some integer number j (0 ≤ j ≤ k) there is a nonzero probability that after j rounds of the fun this situation will occur.
11
+
12
+ Valera knows numbers p1, p2, ..., pn and k. Help Valera determine the number of distinct possible situations.
13
+
14
+ Input
15
+
16
+ The first line contains two integers n, k (1 ≤ n, k ≤ 3000) — the initial number of fools and the number of bullets for each fool.
17
+
18
+ The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 100) — the given probabilities (in percent).
19
+
20
+ Output
21
+
22
+ Print a single number — the answer to the problem.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 3 3
29
+ 50 50 50
30
+
31
+
32
+ Output
33
+
34
+ 7
35
+
36
+
37
+ Input
38
+
39
+ 1 1
40
+ 100
41
+
42
+
43
+ Output
44
+
45
+ 1
46
+
47
+
48
+ Input
49
+
50
+ 2 1
51
+ 100 100
52
+
53
+
54
+ Output
55
+
56
+ 2
57
+
58
+
59
+ Input
60
+
61
+ 3 3
62
+ 0 0 0
63
+
64
+
65
+ Output
66
+
67
+ 1
68
+
69
+ Note
70
+
71
+ In the first sample, any situation is possible, except for situation {1, 2}.
72
+
73
+ In the second sample there is exactly one fool, so he does not make shots.
74
+
75
+ In the third sample the possible situations are {1, 2} (after zero rounds) and the "empty" situation {} (after one round).
76
+
77
+ In the fourth sample, the only possible situation is {1, 2, 3}.
78
+
79
+ ## Contest Information
80
+ - **Contest ID**: 369
81
+ - **Problem Index**: D
82
+ - **Points**: 2000.0
83
+ - **Rating**: 2200
84
+ - **Tags**: dfs and similar, dp, graphs, shortest paths
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-11837/instruction.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # crazy-kangaroo
2
+
3
+ ## Problem Description
4
+ Little Jhool is a world renowned kangaroo trainer. He's now living in Australia, and is training kangaroos for his research project on mobile soccer. (We don't know the connection, too.) Anyway, for the project to be completed he observes kangaroos for a lot of time - because he wants to figure out the hop count for various kangaroos he's training.
5
+
6
+ Now, he makes a kangaroo stand at the starting point, and lets him jump to the finishing point - given the hop count
7
+ of that particular kangaroo, figure out the number of jumps he would take between the starting point to the ending point. Both the starting point and the ending points are inclusive.
8
+
9
+ Note: He will jump only to those positions which are multiples of M or hop count.
10
+
11
+ Input:
12
+ First line contains number of test cases T. Next T lines contains three integers A, B and M separated by single space. A denoted the starting point, B the finishing point - and M, the hop count - the distance covered by that kangaroo in one jump.
13
+
14
+ Output:
15
+ For each test case print the number of jumps the kangaroo had to make in the range [A, B] inclusive.
16
+
17
+ Constraints:
18
+ 1 ≤ T ≤ 100000
19
+ 1 ≤ A ≤ B ≤ 10^12
20
+ 1 ≤ M ≤ 10^12
21
+
22
+ SAMPLE INPUT
23
+ 3
24
+ 1 10 2
25
+ 5 10 3
26
+ 7 9 5SAMPLE OUTPUT
27
+ 5
28
+ 2
29
+ 0
30
+
31
+ Explanation
32
+
33
+ Test Case #1:
34
+ There are 5 multiples of 2 that are {2,4,6,8,10} in range [1,10] .
35
+
36
+ Test Case#2:
37
+ There are 2 multiples of 3 that are {6,9} in range [5,10] .
38
+
39
+ Test Case#3:
40
+ There are no any multiple of 5 is there in range [7,9].
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-12013/instruction.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 300_D. Painting Square
2
+
3
+ ## Problem Description
4
+ Vasily the bear has got a large square white table of n rows and n columns. The table has got a black border around this table.
5
+
6
+ <image> The example of the initial table at n = 5.
7
+
8
+ Vasily the bear wants to paint his square table in exactly k moves. Each move is sequence of actions:
9
+
10
+ 1. The bear chooses some square inside his table. At that the square must have a black border painted around it. Also, the square shouldn't contain a black cell. The number of cells in the square shouldn't be less than 2.
11
+ 2. The bear chooses some row and some column inside the chosen square. Then he paints each cell of this row and this column inside the chosen square. After that the rectangles, formed by the square's border and the newly painted cells, must be squares of a non-zero area.
12
+
13
+ <image> An example of correct painting at n = 7 и k = 2.
14
+
15
+ The bear already knows numbers n and k. Help him — find the number of ways to paint the square in exactly k moves. Two ways to paint are called distinct if the resulting tables will differ in at least one cell. As the answer can be rather large, print the remainder after dividing it by 7340033.
16
+
17
+ Input
18
+
19
+ The first line contains integer q (1 ≤ q ≤ 105) — the number of test data.
20
+
21
+ Each of the following q lines contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 1000) — the size of the initial table and the number of moves for the corresponding test.
22
+
23
+ Output
24
+
25
+ For each test from the input print the answer to the problem modulo 7340033. Print the answers to the tests in the order in which the tests are given in the input.
26
+
27
+ Examples
28
+
29
+ Input
30
+
31
+ 8
32
+ 1 0
33
+ 1 1
34
+ 3 0
35
+ 3 1
36
+ 2 0
37
+ 2 1
38
+ 3 2
39
+ 7 2
40
+
41
+
42
+ Output
43
+
44
+ 1
45
+ 0
46
+ 1
47
+ 1
48
+ 1
49
+ 0
50
+ 0
51
+ 4
52
+
53
+ Note
54
+
55
+ All possible painting ways for the test n = 7 and k = 2 are:
56
+
57
+ <image>
58
+
59
+ ## Contest Information
60
+ - **Contest ID**: 300
61
+ - **Problem Index**: D
62
+ - **Points**: 3000.0
63
+ - **Rating**: 2300
64
+ - **Tags**: dp, fft
65
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
66
+ - **Memory Limit**: 256000000 bytes
67
+
68
+ ## Task
69
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12082/instruction.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # equatio
2
+
3
+ ## Problem Description
4
+ x*y = a + b*lcm(x,y) + c*gcd(x,y)
5
+ It's easy: you are to write a program which for given a, b and c finds the number of pairs of positive integers (x, y) satisfying this equation.
6
+
7
+ Here * stands for multiplication, gcd(x,y) stands for the greatest common divisor of x and y, while lcm(x,y) stands for the least common multiple of x and y.
8
+
9
+
10
+ Input
11
+ The first line of the input file contains one integer T -- the number of test cases (no more than 10). Each of the next T lines contains exactly three space-separated integers a, b and c (0 ≤ a, b, c ≤ 10^6).
12
+
13
+
14
+ Output
15
+ For each test case output one line containing the sought number of solutions to the equation. If there is an infinite number of solutions, output -1 instead.
16
+
17
+
18
+ Example
19
+
20
+ Input:
21
+ 3
22
+ 2 1 1
23
+ 160 0 90
24
+ 300 7 5
25
+
26
+ Output:
27
+ 2
28
+ 8
29
+ 4
30
+
31
+ Explanation:
32
+
33
+ In the first test case, the only pairs are (2,4) and (4,2).
34
+
35
+ ## Contest Information
36
+ - **Contest ID**: 0
37
+ - **Problem Index**:
38
+ - **Points**: 0.0
39
+ - **Rating**: 0
40
+ - **Tags**: None
41
+ - **Time Limit**: None seconds
42
+ - **Memory Limit**: 0 bytes
43
+
44
+ ## Task
45
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12221/instruction.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 300_E. Empire Strikes Back
2
+
3
+ ## Problem Description
4
+ In a far away galaxy there is war again. The treacherous Republic made k precision strikes of power ai on the Empire possessions. To cope with the republican threat, the Supreme Council decided to deal a decisive blow to the enemy forces.
5
+
6
+ To successfully complete the conflict, the confrontation balance after the blow should be a positive integer. The balance of confrontation is a number that looks like <image>, where p = n! (n is the power of the Imperial strike), <image>. After many years of war the Empire's resources are low. So to reduce the costs, n should be a minimum positive integer that is approved by the commanders.
7
+
8
+ Help the Empire, find the minimum positive integer n, where the described fraction is a positive integer.
9
+
10
+ Input
11
+
12
+ The first line contains integer k (1 ≤ k ≤ 106). The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 107).
13
+
14
+ Output
15
+
16
+ Print the minimum positive integer n, needed for the Empire to win.
17
+
18
+ Please, do not use the %lld to read or write 64-but integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 2
25
+ 1000 1000
26
+
27
+
28
+ Output
29
+
30
+ 2000
31
+
32
+ Input
33
+
34
+ 1
35
+ 2
36
+
37
+
38
+ Output
39
+
40
+ 2
41
+
42
+ ## Contest Information
43
+ - **Contest ID**: 300
44
+ - **Problem Index**: E
45
+ - **Points**: 3000.0
46
+ - **Rating**: 2300
47
+ - **Tags**: binary search, math, number theory
48
+ - **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
49
+ - **Memory Limit**: 512000000 bytes
50
+
51
+ ## Task
52
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.