EtashGuha commited on
Commit
6bc5462
·
verified ·
1 Parent(s): 3cee1f8

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-0186/instruction.md +77 -0
  2. code_contests-0779/instruction.md +73 -0
  3. code_contests-0976/instruction.md +69 -0
  4. code_contests-0982/instruction.md +52 -0
  5. code_contests-10179/instruction.md +70 -0
  6. code_contests-1054/instruction.md +139 -0
  7. code_contests-10578/instruction.md +73 -0
  8. code_contests-10786/instruction.md +64 -0
  9. code_contests-10920/instruction.md +73 -0
  10. code_contests-10945/instruction.md +112 -0
  11. code_contests-11002/instruction.md +49 -0
  12. code_contests-11208/instruction.md +68 -0
  13. code_contests-11466/instruction.md +90 -0
  14. code_contests-11653/instruction.md +114 -0
  15. code_contests-11654/instruction.md +130 -0
  16. code_contests-11698/instruction.md +66 -0
  17. code_contests-11806/instruction.md +98 -0
  18. code_contests-11863/instruction.md +46 -0
  19. code_contests-12078/instruction.md +159 -0
  20. code_contests-12479/instruction.md +52 -0
  21. code_contests-12687/instruction.md +49 -0
  22. code_contests-12844/instruction.md +73 -0
  23. code_contests-13103/instruction.md +67 -0
  24. code_contests-1408/instruction.md +63 -0
  25. code_contests-1430/instruction.md +42 -0
  26. code_contests-1660/instruction.md +87 -0
  27. code_contests-1850/instruction.md +48 -0
  28. code_contests-1868/instruction.md +116 -0
  29. code_contests-2087/instruction.md +45 -0
  30. code_contests-2812/instruction.md +74 -0
  31. code_contests-2877/instruction.md +105 -0
  32. code_contests-2883/instruction.md +58 -0
  33. code_contests-3108/instruction.md +66 -0
  34. code_contests-3367/instruction.md +58 -0
  35. code_contests-3509/instruction.md +35 -0
  36. code_contests-3531/instruction.md +113 -0
  37. code_contests-3598/instruction.md +83 -0
  38. code_contests-3703/instruction.md +60 -0
  39. code_contests-3934/instruction.md +68 -0
  40. code_contests-3951/instruction.md +91 -0
  41. code_contests-4142/instruction.md +55 -0
  42. code_contests-4348/instruction.md +44 -0
  43. code_contests-4714/instruction.md +68 -0
  44. code_contests-4923/instruction.md +72 -0
  45. code_contests-4946/instruction.md +85 -0
  46. code_contests-5039/instruction.md +58 -0
  47. code_contests-5090/instruction.md +80 -0
  48. code_contests-5438/instruction.md +121 -0
  49. code_contests-5805/instruction.md +44 -0
  50. code_contests-5894/instruction.md +88 -0
code_contests-0186/instruction.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03343 AtCoder Regular Contest 098 - Range Minimum Queries
2
+
3
+ ## Problem Description
4
+ You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
5
+
6
+ * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
7
+
8
+
9
+
10
+ Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
11
+
12
+ Constraints
13
+
14
+ * 1 \leq N \leq 2000
15
+ * 1 \leq K \leq N
16
+ * 1 \leq Q \leq N-K+1
17
+ * 1 \leq A_i \leq 10^9
18
+ * All values in input are integers.
19
+
20
+ Input
21
+
22
+ Input is given from Standard Input in the following format:
23
+
24
+
25
+ N K Q
26
+ A_1 A_2 ... A_N
27
+
28
+
29
+ Output
30
+
31
+ Print the smallest possible value of X-Y.
32
+
33
+ Examples
34
+
35
+ Input
36
+
37
+ 5 3 2
38
+ 4 3 1 5 2
39
+
40
+
41
+ Output
42
+
43
+ 1
44
+
45
+
46
+ Input
47
+
48
+ 10 1 6
49
+ 1 1 2 3 5 8 13 21 34 55
50
+
51
+
52
+ Output
53
+
54
+ 7
55
+
56
+
57
+ Input
58
+
59
+ 11 7 5
60
+ 24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
61
+
62
+
63
+ Output
64
+
65
+ 451211184
66
+
67
+ ## Contest Information
68
+ - **Contest ID**: 0
69
+ - **Problem Index**:
70
+ - **Points**: 0.0
71
+ - **Rating**: 0
72
+ - **Tags**:
73
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
74
+ - **Memory Limit**: 1073741824 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-0779/instruction.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 609_F. Frogs and mosquitoes
2
+
3
+ ## Problem Description
4
+ There are n frogs sitting on the coordinate axis Ox. For each frog two values xi, ti are known — the position and the initial length of the tongue of the i-th frog (it is guaranteed that all positions xi are different). m mosquitoes one by one are landing to the coordinate axis. For each mosquito two values are known pj — the coordinate of the position where the j-th mosquito lands and bj — the size of the j-th mosquito. Frogs and mosquitoes are represented as points on the coordinate axis.
5
+
6
+ The frog can eat mosquito if mosquito is in the same position with the frog or to the right, and the distance between them is not greater than the length of the tongue of the frog.
7
+
8
+ If at some moment several frogs can eat a mosquito the leftmost frog will eat it (with minimal xi). After eating a mosquito the length of the tongue of a frog increases with the value of the size of eaten mosquito. It's possible that after it the frog will be able to eat some other mosquitoes (the frog should eat them in this case).
9
+
10
+ For each frog print two values — the number of eaten mosquitoes and the length of the tongue after landing all mosquitoes and after eating all possible mosquitoes by frogs.
11
+
12
+ Each mosquito is landing to the coordinate axis only after frogs eat all possible mosquitoes landed before. Mosquitoes are given in order of their landing to the coordinate axis.
13
+
14
+ Input
15
+
16
+ First line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of frogs and mosquitoes.
17
+
18
+ Each of the next n lines contains two integers xi, ti (0 ≤ xi, ti ≤ 109) — the position and the initial length of the tongue of the i-th frog. It is guaranteed that all xi are different.
19
+
20
+ Next m lines contain two integers each pj, bj (0 ≤ pj, bj ≤ 109) — the position and the size of the j-th mosquito.
21
+
22
+ Output
23
+
24
+ Print n lines. The i-th line should contain two integer values ci, li — the number of mosquitoes eaten by the i-th frog and the length of the tongue of the i-th frog.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 4 6
31
+ 10 2
32
+ 15 0
33
+ 6 1
34
+ 0 1
35
+ 110 10
36
+ 1 1
37
+ 6 0
38
+ 15 10
39
+ 14 100
40
+ 12 2
41
+
42
+
43
+ Output
44
+
45
+ 3 114
46
+ 1 10
47
+ 1 1
48
+ 1 2
49
+
50
+
51
+ Input
52
+
53
+ 1 2
54
+ 10 2
55
+ 20 2
56
+ 12 1
57
+
58
+
59
+ Output
60
+
61
+ 1 3
62
+
63
+ ## Contest Information
64
+ - **Contest ID**: 609
65
+ - **Problem Index**: F
66
+ - **Points**: 0.0
67
+ - **Rating**: 2500
68
+ - **Tags**: data structures, greedy
69
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
70
+ - **Memory Limit**: 512000000 bytes
71
+
72
+ ## Task
73
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0976/instruction.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 317_B. Ants
2
+
3
+ ## Problem Description
4
+ It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1) — one ant in each direction. No other ant movements will happen. Ants never interfere with each other.
5
+
6
+ Scientists have put a colony of n ants into the junction (0, 0) and now they wish to know how many ants will there be at some given junctions, when the movement of the ants stops.
7
+
8
+ Input
9
+
10
+ First input line contains integers n (0 ≤ n ≤ 30000) and t (1 ≤ t ≤ 50000), where n is the number of ants in the colony and t is the number of queries. Each of the next t lines contains coordinates of a query junction: integers xi, yi ( - 109 ≤ xi, yi ≤ 109). Queries may coincide.
11
+
12
+ It is guaranteed that there will be a certain moment of time when no possible movements can happen (in other words, the process will eventually end).
13
+
14
+ Output
15
+
16
+ Print t integers, one per line — the number of ants at the corresponding junctions when the movement of the ants stops.
17
+
18
+ Examples
19
+
20
+ Input
21
+
22
+ 1 3
23
+ 0 1
24
+ 0 0
25
+ 0 -1
26
+
27
+
28
+ Output
29
+
30
+ 0
31
+ 1
32
+ 0
33
+
34
+
35
+ Input
36
+
37
+ 6 5
38
+ 0 -2
39
+ 0 -1
40
+ 0 0
41
+ 0 1
42
+ 0 2
43
+
44
+
45
+ Output
46
+
47
+ 0
48
+ 1
49
+ 2
50
+ 1
51
+ 0
52
+
53
+ Note
54
+
55
+ In the first sample the colony consists of the one ant, so nothing happens at all.
56
+
57
+ In the second sample the colony consists of 6 ants. At the first minute 4 ants scatter from (0, 0) to the neighbouring junctions. After that the process stops.
58
+
59
+ ## Contest Information
60
+ - **Contest ID**: 317
61
+ - **Problem Index**: B
62
+ - **Points**: 1000.0
63
+ - **Rating**: 2000
64
+ - **Tags**: brute force, implementation
65
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
66
+ - **Memory Limit**: 256000000 bytes
67
+
68
+ ## Task
69
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-0982/instruction.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 459_C. Pashmak and Buses
2
+
3
+ ## Problem Description
4
+ Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.
5
+
6
+ Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.
7
+
8
+ Input
9
+
10
+ The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).
11
+
12
+ Output
13
+
14
+ If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ 3 2 2
21
+
22
+
23
+ Output
24
+
25
+ 1 1 2
26
+ 1 2 1
27
+
28
+
29
+ Input
30
+
31
+ 3 2 1
32
+
33
+
34
+ Output
35
+
36
+ -1
37
+
38
+ Note
39
+
40
+ Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.
41
+
42
+ ## Contest Information
43
+ - **Contest ID**: 459
44
+ - **Problem Index**: C
45
+ - **Points**: 2000.0
46
+ - **Rating**: 1900
47
+ - **Tags**: combinatorics, constructive algorithms, math
48
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
49
+ - **Memory Limit**: 256000000 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-10179/instruction.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02608 AIsing Programming Contest 2020 - XYZ Triplets
2
+
3
+ ## Problem Description
4
+ Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:
5
+
6
+ * 1 \leq x,y,z
7
+ * x^2 + y^2 + z^2 + xy + yz + zx = n
8
+
9
+
10
+
11
+ Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
12
+
13
+ Constraints
14
+
15
+ * All values in input are integers.
16
+ * 1 \leq N \leq 10^4
17
+
18
+ Input
19
+
20
+ Input is given from Standard Input in the following format:
21
+
22
+
23
+ N
24
+
25
+
26
+ Output
27
+
28
+ Print N lines. The i-th line should contain the value f(i).
29
+
30
+ Example
31
+
32
+ Input
33
+
34
+ 20
35
+
36
+
37
+ Output
38
+
39
+ 0
40
+ 0
41
+ 0
42
+ 0
43
+ 0
44
+ 1
45
+ 0
46
+ 0
47
+ 0
48
+ 0
49
+ 3
50
+ 0
51
+ 0
52
+ 0
53
+ 0
54
+ 0
55
+ 3
56
+ 3
57
+ 0
58
+ 0
59
+
60
+ ## Contest Information
61
+ - **Contest ID**: 0
62
+ - **Problem Index**:
63
+ - **Points**: 0.0
64
+ - **Rating**: 0
65
+ - **Tags**:
66
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
67
+ - **Memory Limit**: 1073741824 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-1054/instruction.md ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1110_F. Nearest Leaf
2
+
3
+ ## Problem Description
4
+ Let's define the Eulerian traversal of a tree (a connected undirected graph without cycles) as follows: consider a depth-first search algorithm which traverses vertices of the tree and enumerates them in the order of visiting (only the first visit of each vertex counts). This function starts from the vertex number 1 and then recursively runs from all vertices which are connected with an edge with the current vertex and are not yet visited in increasing numbers order. Formally, you can describe this function using the following pseudocode:
5
+
6
+
7
+
8
+ next_id = 1
9
+ id = array of length n filled with -1
10
+ visited = array of length n filled with false
11
+
12
+ function dfs(v):
13
+ visited[v] = true
14
+ id[v] = next_id
15
+ next_id += 1
16
+ for to in neighbors of v in increasing order:
17
+ if not visited[to]:
18
+ dfs(to)
19
+
20
+
21
+ You are given a weighted tree, the vertices of which were enumerated with integers from 1 to n using the algorithm described above.
22
+
23
+ A leaf is a vertex of the tree which is connected with only one other vertex. In the tree given to you, the vertex 1 is not a leaf. The distance between two vertices in the tree is the sum of weights of the edges on the simple path between them.
24
+
25
+ You have to answer q queries of the following type: given integers v, l and r, find the shortest distance from vertex v to one of the leaves with indices from l to r inclusive.
26
+
27
+ Input
28
+
29
+ The first line contains two integers n and q (3 ≤ n ≤ 500 000, 1 ≤ q ≤ 500 000) — the number of vertices in the tree and the number of queries, respectively.
30
+
31
+ The (i - 1)-th of the following n - 1 lines contains two integers p_i and w_i (1 ≤ p_i < i, 1 ≤ w_i ≤ 10^9), denoting an edge between vertices p_i and i with the weight w_i.
32
+
33
+ It's guaranteed that the given edges form a tree and the vertices are enumerated in the Eulerian traversal order and that the vertex with index 1 is not a leaf.
34
+
35
+ The next q lines describe the queries. Each of them contains three integers v_i, l_i, r_i (1 ≤ v_i ≤ n, 1 ≤ l_i ≤ r_i ≤ n), describing the parameters of the query. It is guaranteed that there is at least one leaf with index x such that l_i ≤ x ≤ r_i.
36
+
37
+ Output
38
+
39
+ Output q integers — the answers for the queries in the order they are given in the input.
40
+
41
+ Examples
42
+
43
+ Input
44
+
45
+
46
+ 5 3
47
+ 1 10
48
+ 1 1
49
+ 3 2
50
+ 3 3
51
+ 1 1 5
52
+ 5 4 5
53
+ 4 1 2
54
+
55
+
56
+ Output
57
+
58
+
59
+ 3
60
+ 0
61
+ 13
62
+
63
+
64
+ Input
65
+
66
+
67
+ 5 3
68
+ 1 1000000000
69
+ 2 1000000000
70
+ 1 1000000000
71
+ 1 1000000000
72
+ 3 4 5
73
+ 2 1 5
74
+ 2 4 5
75
+
76
+
77
+ Output
78
+
79
+
80
+ 3000000000
81
+ 1000000000
82
+ 2000000000
83
+
84
+
85
+ Input
86
+
87
+
88
+ 11 8
89
+ 1 7
90
+ 2 1
91
+ 1 20
92
+ 1 2
93
+ 5 6
94
+ 6 2
95
+ 6 3
96
+ 5 1
97
+ 9 10
98
+ 9 11
99
+ 5 1 11
100
+ 1 1 4
101
+ 9 4 8
102
+ 6 1 4
103
+ 9 7 11
104
+ 9 10 11
105
+ 8 1 11
106
+ 11 4 5
107
+
108
+
109
+ Output
110
+
111
+
112
+ 8
113
+ 8
114
+ 9
115
+ 16
116
+ 9
117
+ 10
118
+ 0
119
+ 34
120
+
121
+ Note
122
+
123
+ In the first example, the tree looks like this:
124
+
125
+ <image>
126
+
127
+ In the first query, the nearest leaf for the vertex 1 is vertex 4 with distance 3. In the second query, the nearest leaf for vertex 5 is vertex 5 with distance 0. In the third query the nearest leaf for vertex 4 is vertex 4; however, it is not inside interval [1, 2] of the query. The only leaf in interval [1, 2] is vertex 2 with distance 13 from vertex 4.
128
+
129
+ ## Contest Information
130
+ - **Contest ID**: 1110
131
+ - **Problem Index**: F
132
+ - **Points**: 3000.0
133
+ - **Rating**: 2600
134
+ - **Tags**: data structures, trees
135
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
136
+ - **Memory Limit**: 512000000 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-10578/instruction.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 849_C. From Y to Y
2
+
3
+ ## Problem Description
4
+ From beginning till end, this message has been waiting to be conveyed.
5
+
6
+ For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:
7
+
8
+ * Remove any two elements s and t from the set, and add their concatenation s + t to the set.
9
+
10
+
11
+
12
+ The cost of such operation is defined to be <image>, where f(s, c) denotes the number of times character c appears in string s.
13
+
14
+ Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.
15
+
16
+ Input
17
+
18
+ The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.
19
+
20
+ Output
21
+
22
+ Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.
23
+
24
+ Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 12
31
+
32
+
33
+ Output
34
+
35
+ abababab
36
+
37
+
38
+ Input
39
+
40
+ 3
41
+
42
+
43
+ Output
44
+
45
+ codeforces
46
+
47
+ Note
48
+
49
+ For the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:
50
+
51
+ * {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;
52
+ * {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;
53
+ * {"abab", "a", "b", "a", "b"}, with a cost of 1;
54
+ * {"abab", "ab", "a", "b"}, with a cost of 0;
55
+ * {"abab", "aba", "b"}, with a cost of 1;
56
+ * {"abab", "abab"}, with a cost of 1;
57
+ * {"abababab"}, with a cost of 8.
58
+
59
+
60
+
61
+ The total cost is 12, and it can be proved to be the minimum cost of the process.
62
+
63
+ ## Contest Information
64
+ - **Contest ID**: 849
65
+ - **Problem Index**: C
66
+ - **Points**: 500.0
67
+ - **Rating**: 1600
68
+ - **Tags**: constructive algorithms
69
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
70
+ - **Memory Limit**: 256000000 bytes
71
+
72
+ ## Task
73
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10786/instruction.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 852_E. Casinos and travel
2
+
3
+ ## Problem Description
4
+ John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N.
5
+
6
+ John first has to select from which city he will start his journey. After that, he spends one day in a city and then travels to a randomly choosen city which is directly connected to his current one and which he has not yet visited. He does this until he can't continue obeying these rules.
7
+
8
+ To select the starting city, he calls his friend Jack for advice. Jack is also starting a big casino business and wants to open casinos in some of the cities (max 1 per city, maybe nowhere). Jack knows John well and he knows that if he visits a city with a casino, he will gamble exactly once before continuing his journey.
9
+
10
+ He also knows that if John enters a casino in a good mood, he will leave it in a bad mood and vice versa. Since he is John's friend, he wants him to be in a good mood at the moment when he finishes his journey. John is in a good mood before starting the journey.
11
+
12
+ In how many ways can Jack select a starting city for John and cities where he will build casinos such that no matter how John travels, he will be in a good mood at the end? Print answer modulo 109 + 7.
13
+
14
+ Input
15
+
16
+ In the first line, a positive integer N (1 ≤ N ≤ 100000), the number of cities.
17
+
18
+ In the next N - 1 lines, two numbers a, b (1 ≤ a, b ≤ N) separated by a single space meaning that cities a and b are connected by a bidirectional road.
19
+
20
+ Output
21
+
22
+ Output one number, the answer to the problem modulo 109 + 7.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 2
29
+ 1 2
30
+
31
+
32
+ Output
33
+
34
+ 4
35
+
36
+
37
+ Input
38
+
39
+ 3
40
+ 1 2
41
+ 2 3
42
+
43
+
44
+ Output
45
+
46
+ 10
47
+
48
+ Note
49
+
50
+ Example 1: If Jack selects city 1 as John's starting city, he can either build 0 casinos, so John will be happy all the time, or build a casino in both cities, so John would visit a casino in city 1, become unhappy, then go to city 2, visit a casino there and become happy and his journey ends there because he can't go back to city 1. If Jack selects city 2 for start, everything is symmetrical, so the answer is 4.
51
+
52
+ Example 2: If Jack tells John to start from city 1, he can either build casinos in 0 or 2 cities (total 4 possibilities). If he tells him to start from city 2, then John's journey will either contain cities 2 and 1 or 2 and 3. Therefore, Jack will either have to build no casinos, or build them in all three cities. With other options, he risks John ending his journey unhappy. Starting from 3 is symmetric to starting from 1, so in total we have 4 + 2 + 4 = 10 options.
53
+
54
+ ## Contest Information
55
+ - **Contest ID**: 852
56
+ - **Problem Index**: E
57
+ - **Points**: 0.0
58
+ - **Rating**: 2100
59
+ - **Tags**: dp
60
+ - **Time Limit**: {'seconds': 1, '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-10920/instruction.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00458 Crossing Black Ice
2
+
3
+ ## Problem Description
4
+ problem
5
+
6
+ One day in the cold winter, JOI Taro decided to break the thin ice in the plaza and play. The square is rectangular and is divided into m sections in the east-west direction and n sections in the north-south direction, that is, m × n. In addition, there are sections with and without thin ice. JOI Taro decided to move the plot while breaking the thin ice according to the following rules.
7
+
8
+ * You can start breaking thin ice from any compartment with thin ice.
9
+ * Adjacent to either north, south, east, or west, you can move to a section with thin ice that has not yet been broken.
10
+ * Be sure to break the thin ice in the area you moved to.
11
+
12
+
13
+
14
+ Create a program to find the maximum number of sections that JOI Taro can move while breaking thin ice. However, 1 ≤ m ≤ 90 and 1 ≤ n ≤ 90. With the input data given, there are no more than 200,000 ways to move.
15
+
16
+
17
+
18
+ input
19
+
20
+ The input consists of multiple datasets. Each dataset is given in the following format.
21
+
22
+ The input is n + 2 lines. The integer m is written on the first line. The integer n is written on the second line. In each line from the 3rd line to the n + 2nd line, m 0s or 1s are written, separated by blanks, and indicates whether or not there is thin ice in each section. If we write the i-th section from the north and the j-th section from the west as (i, j) (1 ≤ i ≤ n, 1 ≤ j ≤ m), the j-th value on the second line of i + 2 is It is 1 if there is thin ice in compartment (i, j) and 0 if there is no thin ice in compartment (i, j).
23
+
24
+ When both m and n are 0, it indicates the end of input. The number of data sets does not exceed 5.
25
+
26
+ output
27
+
28
+ Output the maximum number of sections that can be moved for each data set on one line.
29
+
30
+ Examples
31
+
32
+ Input
33
+
34
+ 3
35
+ 3
36
+ 1 1 0
37
+ 1 0 1
38
+ 1 1 0
39
+ 5
40
+ 3
41
+ 1 1 1 0 1
42
+ 1 1 0 0 0
43
+ 1 0 0 0 1
44
+ 0
45
+ 0
46
+
47
+
48
+ Output
49
+
50
+ 5
51
+ 5
52
+
53
+
54
+ Input
55
+
56
+ None
57
+
58
+
59
+ Output
60
+
61
+ None
62
+
63
+ ## Contest Information
64
+ - **Contest ID**: 0
65
+ - **Problem Index**:
66
+ - **Points**: 0.0
67
+ - **Rating**: 0
68
+ - **Tags**:
69
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
70
+ - **Memory Limit**: 134217728 bytes
71
+
72
+ ## Task
73
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-10945/instruction.md ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1133_F1. Spanning Tree with Maximum Degree
2
+
3
+ ## Problem Description
4
+ You are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
5
+
6
+ Your task is to find any spanning tree of this graph such that the maximum degree over all vertices is maximum possible. Recall that the degree of a vertex is the number of edges incident to it.
7
+
8
+ Input
9
+
10
+ The first line contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, n - 1 ≤ m ≤ min(2 ⋅ 10^5, (n(n-1))/(2))) — the number of vertices and edges, respectively.
11
+
12
+ The following m lines denote edges: edge i is represented by a pair of integers v_i, u_i (1 ≤ v_i, u_i ≤ n, u_i ≠ v_i), which are the indices of vertices connected by the edge. There are no loops or multiple edges in the given graph, i. e. for each pair (v_i, u_i) there are no other pairs (v_i, u_i) or (u_i, v_i) in the list of edges, and for each pair (v_i, u_i) the condition v_i ≠ u_i is satisfied.
13
+
14
+ Output
15
+
16
+ Print n-1 lines describing the edges of a spanning tree such that the maximum degree over all vertices is maximum possible. Make sure that the edges of the printed spanning tree form some subset of the input edges (order doesn't matter and edge (v, u) is considered the same as the edge (u, v)).
17
+
18
+ If there are multiple possible answers, print any of them.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+
25
+ 5 5
26
+ 1 2
27
+ 2 3
28
+ 3 5
29
+ 4 3
30
+ 1 5
31
+
32
+
33
+ Output
34
+
35
+
36
+ 3 5
37
+ 2 1
38
+ 3 2
39
+ 3 4
40
+
41
+
42
+ Input
43
+
44
+
45
+ 4 6
46
+ 1 2
47
+ 1 3
48
+ 1 4
49
+ 2 3
50
+ 2 4
51
+ 3 4
52
+
53
+
54
+ Output
55
+
56
+
57
+ 4 1
58
+ 1 2
59
+ 1 3
60
+
61
+
62
+ Input
63
+
64
+
65
+ 8 9
66
+ 1 2
67
+ 2 3
68
+ 2 5
69
+ 1 6
70
+ 3 4
71
+ 6 5
72
+ 4 5
73
+ 2 7
74
+ 5 8
75
+
76
+
77
+ Output
78
+
79
+
80
+ 3 2
81
+ 2 5
82
+ 8 5
83
+ 6 1
84
+ 2 7
85
+ 1 2
86
+ 3 4
87
+
88
+ Note
89
+
90
+ Picture corresponding to the first example: <image>
91
+
92
+ In this example the number of edges of spanning tree incident to the vertex 3 is 3. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer.
93
+
94
+ Picture corresponding to the second example: <image>
95
+
96
+ In this example the number of edges of spanning tree incident to the vertex 1 is 3. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer.
97
+
98
+ Picture corresponding to the third example: <image>
99
+
100
+ In this example the number of edges of spanning tree incident to the vertex 2 is 4. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer. But because this example is symmetric, we can choose almost the same spanning tree but with vertex 5 instead of 2.
101
+
102
+ ## Contest Information
103
+ - **Contest ID**: 1133
104
+ - **Problem Index**: F1
105
+ - **Points**: 0.0
106
+ - **Rating**: 1600
107
+ - **Tags**: graphs
108
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
109
+ - **Memory Limit**: 256000000 bytes
110
+
111
+ ## Task
112
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11002/instruction.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # circles-in-rectangles
2
+
3
+ ## Problem Description
4
+ This question is straight-forward.
5
+
6
+ Given length L cm and breadth B cm of a rectangular cardboard. You need to cut out the circles of diameter D cm from it. Find out the maximum number of circles you can cut out from it.
7
+ Since the value can be very large, give your answer in mod 10^9 + 7
8
+
9
+ Input:
10
+
11
+ First line of input contains an integer T - no. of testcases.
12
+ After that, each line contains three space-separated integers L B D
13
+
14
+ Output:
15
+
16
+ For every testcase, print out one integer per line that is the maximum no. of circles that can be cut out from board.
17
+ The integer should be printed in mod 10^9 + 7
18
+
19
+ Constraints
20
+
21
+ 1 ≤ T ≤ 10
22
+
23
+ 1 ≤ L,B,D ≤ 10^18
24
+
25
+ SAMPLE INPUT
26
+ 2
27
+ 20 10 30
28
+ 30 20 10
29
+
30
+ SAMPLE OUTPUT
31
+ 0
32
+ 6
33
+
34
+ Explanation
35
+
36
+ In the first case, rectangle is 20x10 whereas the circle is larger than it with diameter 30 hence 0 circles can be cut out.
37
+ In second testcase, you can make a figure of rectangle of 30x20, you will see that 6 circles of diameter 10 can be cut out from it.
38
+
39
+ ## Contest Information
40
+ - **Contest ID**: 0
41
+ - **Problem Index**:
42
+ - **Points**: 0.0
43
+ - **Rating**: 0
44
+ - **Tags**: None
45
+ - **Time Limit**: None seconds
46
+ - **Memory Limit**: 0 bytes
47
+
48
+ ## Task
49
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11208/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 978_B. File Name
2
+
3
+ ## Problem Description
4
+ You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
5
+
6
+ Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".
7
+
8
+ You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii".
9
+
10
+ Input
11
+
12
+ The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name.
13
+
14
+ The second line contains a string of length n consisting of lowercase Latin letters only — the file name.
15
+
16
+ Output
17
+
18
+ Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
19
+
20
+ Examples
21
+
22
+ Input
23
+
24
+ 6
25
+ xxxiii
26
+
27
+
28
+ Output
29
+
30
+ 1
31
+
32
+
33
+ Input
34
+
35
+ 5
36
+ xxoxx
37
+
38
+
39
+ Output
40
+
41
+ 0
42
+
43
+
44
+ Input
45
+
46
+ 10
47
+ xxxxxxxxxx
48
+
49
+
50
+ Output
51
+
52
+ 8
53
+
54
+ Note
55
+
56
+ In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 978
60
+ - **Problem Index**: B
61
+ - **Points**: 0.0
62
+ - **Rating**: 800
63
+ - **Tags**: greedy, strings
64
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
65
+ - **Memory Limit**: 256000000 bytes
66
+
67
+ ## Task
68
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11466/instruction.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1097_C. Yuhao and a Parenthesis
2
+
3
+ ## Problem Description
4
+ One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences.
5
+
6
+ A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequence if it's possible to obtain a correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, the sequences "(())()", "()" and "(()(()))" are correct, while the bracket sequences ")(", "(()" and "(()))(" are not correct.
7
+
8
+ Yuhao found this problem too simple for him so he decided to make the problem harder. You are given many (not necessarily correct) bracket sequences. The task is to connect some of them into ordered pairs so that each bracket sequence occurs in at most one pair and the concatenation of the bracket sequences in each pair is a correct bracket sequence. The goal is to create as many pairs as possible.
9
+
10
+ This problem unfortunately turned out to be too difficult for Yuhao. Can you help him and solve it?
11
+
12
+ Input
13
+
14
+ The first line contains one integer n (1 ≤ n ≤ 10^5) — the number of bracket sequences.
15
+
16
+ Each of the following n lines contains one bracket sequence — a non-empty string which consists only of characters "(" and ")".
17
+
18
+ The sum of lengths of all bracket sequences in the input is at most 5 ⋅ 10^5.
19
+
20
+ Note that a bracket sequence may appear in the input multiple times. In this case, you can use each copy of the sequence separately. Also note that the order in which strings appear in the input doesn't matter.
21
+
22
+ Output
23
+
24
+ Print a single integer — the maximum number of pairs which can be made, adhering to the conditions in the statement.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+
31
+ 7
32
+ )())
33
+ )
34
+ ((
35
+ ((
36
+ (
37
+ )
38
+ )
39
+
40
+
41
+ Output
42
+
43
+
44
+ 2
45
+
46
+
47
+ Input
48
+
49
+
50
+ 4
51
+ (
52
+ ((
53
+ (((
54
+ (())
55
+
56
+
57
+ Output
58
+
59
+
60
+ 0
61
+
62
+
63
+ Input
64
+
65
+
66
+ 2
67
+ (())
68
+ ()
69
+
70
+
71
+ Output
72
+
73
+
74
+ 1
75
+
76
+ Note
77
+
78
+ In the first example, it's optimal to construct two pairs: "(( )())" and "( )".
79
+
80
+ ## Contest Information
81
+ - **Contest ID**: 1097
82
+ - **Problem Index**: C
83
+ - **Points**: 1500.0
84
+ - **Rating**: 1400
85
+ - **Tags**: greedy, implementation
86
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
87
+ - **Memory Limit**: 256000000 bytes
88
+
89
+ ## Task
90
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11653/instruction.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00895 The Sorcerer's Donut
2
+
3
+ ## Problem Description
4
+ Your master went to the town for a day. You could have a relaxed day without hearing his scolding. But he ordered you to make donuts dough by the evening. Loving donuts so much, he can't live without eating tens of donuts everyday. What a chore for such a beautiful day.
5
+
6
+ But last week, you overheard a magic spell that your master was using. It was the time to try. You casted the spell on a broomstick sitting on a corner of the kitchen. With a flash of lights, the broom sprouted two arms and two legs, and became alive. You ordered him, then he brought flour from the storage, and started kneading dough. The spell worked, and how fast he kneaded it!
7
+
8
+ A few minutes later, there was a tall pile of dough on the kitchen table. That was enough for the next week. \OK, stop now." You ordered. But he didn't stop. Help! You didn't know the spell to stop him! Soon the kitchen table was filled with hundreds of pieces of dough, and he still worked as fast as he could. If you could not stop him now, you would be choked in the kitchen filled with pieces of dough.
9
+
10
+ Wait, didn't your master write his spells on his notebooks? You went to his den, and found the notebook that recorded the spell of cessation.
11
+
12
+ But it was not the end of the story. The spell written in the notebook is not easily read by others. He used a plastic model of a donut as a notebook for recording the spell. He split the surface of the donut-shaped model into square mesh (Figure B.1), and filled with the letters (Figure B.2). He hid the spell so carefully that the pattern on the surface looked meaningless. But you knew that he wrote the pattern so that the spell "appears" more than once (see the next paragraph for the precise conditions). The spell was not necessarily written in the left-to-right direction, but any of the 8 directions, namely left-to-right, right-to-left, top-down, bottom-up, and the 4 diagonal directions.
13
+
14
+ You should be able to find the spell as the longest string that appears more than once. Here, a string is considered to appear more than once if there are square sequences having the string on the donut that satisfy the following conditions.
15
+
16
+
17
+ * Each square sequence does not overlap itself. (Two square sequences can share some squares.)
18
+ * The square sequences start from different squares, and/or go to different directions.
19
+
20
+ <image> | <image> | Figure B.1: The Sorcerer's Donut Before Filled with Letters, Showing the Mesh and 8 Possible Spell Directions | Figure B.2: The Sorcerer's Donut After Filled with Letters
21
+ ---|---
22
+
23
+ Note that a palindrome (i.e., a string that is the same whether you read it backwards or forwards) that satisfies the first condition "appears" twice.
24
+
25
+ The pattern on the donut is given as a matrix of letters as follows.
26
+
27
+
28
+ ABCD
29
+ EFGH
30
+ IJKL
31
+
32
+
33
+ Note that the surface of the donut has no ends; the top and bottom sides, and the left and right sides of the pattern are respectively connected. There can be square sequences longer than both the vertical and horizontal lengths of the pattern. For example, from the letter F in the above pattern, the strings in the longest non-self-overlapping sequences towards the 8 directions are as follows.
34
+
35
+
36
+ FGHE
37
+ FKDEJCHIBGLA
38
+ FJB
39
+ FIDGJAHKBELC
40
+ FEHG
41
+ FALGBIHCJEDK
42
+ FBJ
43
+ FCLEBKHAJGDI
44
+
45
+
46
+ Please write a program that finds the magic spell before you will be choked with pieces of donuts dough.
47
+
48
+
49
+
50
+ Input
51
+
52
+ The input is a sequence of datasets. Each dataset begins with a line of two integers h and w, which denote the size of the pattern, followed by h lines of w uppercase letters from A to Z, inclusive, which denote the pattern on the donut. You may assume 3 ≤ h ≤ 10 and 3 ≤ w ≤ 20.
53
+
54
+ The end of the input is indicated by a line containing two zeros.
55
+
56
+ Output
57
+
58
+ For each dataset, output the magic spell. If there is more than one longest string of the same length, the first one in the dictionary order must be the spell. The spell is known to be at least two letters long. When no spell is found, output 0 (zero).
59
+
60
+ Example
61
+
62
+ Input
63
+
64
+ 5 7
65
+ RRCABXT
66
+ AABMFAB
67
+ RROMJAC
68
+ APTADAB
69
+ YABADAO
70
+ 3 13
71
+ ABCDEFGHIJKLM
72
+ XMADAMIMADAMY
73
+ ACEGIKMOQSUWY
74
+ 3 4
75
+ DEFG
76
+ ACAB
77
+ HIJK
78
+ 3 6
79
+ ABCDEF
80
+ GHIAKL
81
+ MNOPQR
82
+ 10 19
83
+ JFZODYDXMZZPEYTRNCW
84
+ XVGHPOKEYNZTQFZJKOD
85
+ EYEHHQKHFZOVNRGOOLP
86
+ QFZOIHRQMGHPNISHXOC
87
+ DRGILJHSQEHHQLYTILL
88
+ NCSHQMKHTZZIHRPAUJA
89
+ NCCTINCLAUTFJHSZBVK
90
+ LPBAUJIUMBVQYKHTZCW
91
+ XMYHBVKUGNCWTLLAUID
92
+ EYNDCCWLEOODXYUMBVN
93
+ 0 0
94
+
95
+
96
+ Output
97
+
98
+ ABRACADABRA
99
+ MADAMIMADAM
100
+ ABAC
101
+ 0
102
+ ABCDEFGHIJKLMNOPQRSTUVWXYZHHHHHABCDEFGHIJKLMNOPQRSTUVWXYZ
103
+
104
+ ## Contest Information
105
+ - **Contest ID**: 0
106
+ - **Problem Index**:
107
+ - **Points**: 0.0
108
+ - **Rating**: 0
109
+ - **Tags**:
110
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
111
+ - **Memory Limit**: 134217728 bytes
112
+
113
+ ## Task
114
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11654/instruction.md ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01028 Yu-kun Likes an Integer
2
+
3
+ ## Problem Description
4
+ Hint
5
+
6
+ In solving this problem, the following may be referred to. Shows how to convert an integer value to a string. Assign value as a string to str.
7
+
8
+ For C
9
+
10
+
11
+ include <stdio.h>
12
+
13
+ int main () {
14
+ int value = 123; // Convert this value to a string
15
+ char str [6]; // This variable contains a string of value
16
+ sprintf (str, "% d", value);
17
+ return 0;
18
+ }
19
+
20
+
21
+
22
+ For C ++
23
+
24
+
25
+ include <sstream>
26
+
27
+ using namespace std;
28
+
29
+ int main () {
30
+ int value = 123; // Convert this value to a string
31
+ string str; // This variable contains a string of value
32
+ stringstream ss;
33
+ ss << value;
34
+ ss >> str;
35
+ return 0;
36
+ }
37
+
38
+
39
+ For JAVA
40
+
41
+
42
+ class Main {
43
+ public static void main (String args []) {
44
+ int value = 123; // Convert this value to a string
45
+ String str = new Integer (value) .toString (); // This variable contains a string of value
46
+ }
47
+ }
48
+
49
+
50
+ Constraints
51
+
52
+ The input satisfies the following conditions.
53
+
54
+ * 1 ≤ n ≤ 5
55
+ * 0 ≤ m ≤ 500
56
+ * 1 ≤ ci ≤ 1000 (0 ≤ i ≤ 9)
57
+
58
+ Input
59
+
60
+
61
+ n m
62
+ c0 c1 c2 ... c9
63
+
64
+
65
+ Two integers n and m are given on the first line, separated by blanks. n is the number of plates to purchase, and m is the amount of money you have.
66
+
67
+ On the second line, 10 integers are given, separated by blanks. ci (i is 0 or more and 9 or less) represents the price of the plate with i written in the table.
68
+
69
+ Output
70
+
71
+ Buy n plates and put them in any order to output the minimum number of values ​​you can.
72
+
73
+ If some 0s are included at the beginning, output as it is. (For example, if the answer is 0019, output 0019 as it is instead of removing the leading 0 to make it 19.) If you cannot purchase n plates with the amount of money you have, output "NA".
74
+
75
+ Examples
76
+
77
+ Input
78
+
79
+ 1 10
80
+ 1 2 3 4 5 6 7 8 9 10
81
+
82
+
83
+ Output
84
+
85
+ 0
86
+
87
+
88
+ Input
89
+
90
+ 3 10
91
+ 8 4 5 3 5 6 9 10 11 2
92
+
93
+
94
+ Output
95
+
96
+ 119
97
+
98
+
99
+ Input
100
+
101
+ 5 30
102
+ 25 51 32 9 2 1 10 2 5 10
103
+
104
+
105
+ Output
106
+
107
+ 04555
108
+
109
+
110
+ Input
111
+
112
+ 5 100
113
+ 101 101 101 101 101 101 101 101 101 101
114
+
115
+
116
+ Output
117
+
118
+ NA
119
+
120
+ ## Contest Information
121
+ - **Contest ID**: 0
122
+ - **Problem Index**:
123
+ - **Points**: 0.0
124
+ - **Rating**: 0
125
+ - **Tags**:
126
+ - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
127
+ - **Memory Limit**: 268435456 bytes
128
+
129
+ ## Task
130
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11698/instruction.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 245_A. System Administrator
2
+
3
+ ## Problem Description
4
+ Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.
5
+
6
+ Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.
7
+
8
+ Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
9
+
10
+ Input
11
+
12
+ The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost.
13
+
14
+ It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
15
+
16
+ Output
17
+
18
+ In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).
19
+
20
+ In the second line print the state of server b in the similar format.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 2
27
+ 1 5 5
28
+ 2 6 4
29
+
30
+
31
+ Output
32
+
33
+ LIVE
34
+ LIVE
35
+
36
+
37
+ Input
38
+
39
+ 3
40
+ 1 0 10
41
+ 2 0 10
42
+ 1 10 0
43
+
44
+
45
+ Output
46
+
47
+ LIVE
48
+ DEAD
49
+
50
+ Note
51
+
52
+ Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.
53
+
54
+ Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
55
+
56
+ ## Contest Information
57
+ - **Contest ID**: 245
58
+ - **Problem Index**: A
59
+ - **Points**: 0.0
60
+ - **Rating**: 800
61
+ - **Tags**: implementation
62
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
63
+ - **Memory Limit**: 256000000 bytes
64
+
65
+ ## Task
66
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-11806/instruction.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 321_B. Ciel and Duel
2
+
3
+ ## Problem Description
4
+ Fox Ciel is playing a card game with her friend Jiro.
5
+
6
+ Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
7
+
8
+ Now is Ciel's battle phase, Ciel can do the following operation many times:
9
+
10
+ 1. Choose one of her cards X. This card mustn't be chosen before.
11
+ 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then:
12
+ * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength).
13
+ * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage.
14
+
15
+
16
+
17
+ Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.
18
+
19
+ Input
20
+
21
+ The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have.
22
+
23
+ Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense.
24
+
25
+ Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card.
26
+
27
+ Output
28
+
29
+ Output an integer: the maximal damage Jiro can get.
30
+
31
+ Examples
32
+
33
+ Input
34
+
35
+ 2 3
36
+ ATK 2000
37
+ DEF 1700
38
+ 2500
39
+ 2500
40
+ 2500
41
+
42
+
43
+ Output
44
+
45
+ 3000
46
+
47
+
48
+ Input
49
+
50
+ 3 4
51
+ ATK 10
52
+ ATK 100
53
+ ATK 1000
54
+ 1
55
+ 11
56
+ 101
57
+ 1001
58
+
59
+
60
+ Output
61
+
62
+ 992
63
+
64
+
65
+ Input
66
+
67
+ 2 4
68
+ DEF 0
69
+ ATK 0
70
+ 0
71
+ 0
72
+ 1
73
+ 1
74
+
75
+
76
+ Output
77
+
78
+ 1
79
+
80
+ Note
81
+
82
+ In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000.
83
+
84
+ In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992.
85
+
86
+ In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card.
87
+
88
+ ## Contest Information
89
+ - **Contest ID**: 321
90
+ - **Problem Index**: B
91
+ - **Points**: 1000.0
92
+ - **Rating**: 1900
93
+ - **Tags**: dp, flows, greedy
94
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
95
+ - **Memory Limit**: 256000000 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-11863/instruction.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01168 Lying about Your Age
2
+
3
+ ## Problem Description
4
+ You have moved to a new town. As starting a new life, you have made up your mind to do one thing: lying about your age. Since no person in this town knows your history, you don’t have to worry about immediate exposure. Also, in order to ease your conscience somewhat, you have decided to claim ages that represent your real ages when interpreted as the base-M numbers (2 ≤ M ≤ 16). People will misunderstand your age as they interpret the claimed age as a decimal number (i.e. of the base 10).
5
+
6
+ Needless to say, you don’t want to have your real age revealed to the people in the future. So you should claim only one age each year, it should contain digits of decimal numbers (i.e. ‘0’ through ‘9’), and it should always be equal to or greater than that of the previous year (when interpreted as decimal).
7
+
8
+ How old can you claim you are, after some years?
9
+
10
+
11
+
12
+ Input
13
+
14
+ The input consists of multiple datasets. Each dataset is a single line that contains three integers A, B, and C, where A is the present real age (in decimal), B is the age you presently claim (which can be a non-decimal number), and C is the real age at which you are to find the age you will claim (in decimal). It is guaranteed that 0 ≤ A < C ≤ 200, while B may contain up to eight digits. No digits other than ‘0’ through ‘9’ appear in those numbers.
15
+
16
+ The end of input is indicated by A = B = C = -1, which should not be processed.
17
+
18
+ Output
19
+
20
+ For each dataset, print in a line the minimum age you can claim when you become C years old. In case the age you presently claim cannot be interpreted as your real age with the base from 2 through 16, print -1 instead.
21
+
22
+ Example
23
+
24
+ Input
25
+
26
+ 23 18 53
27
+ 46 30 47
28
+ -1 -1 -1
29
+
30
+
31
+ Output
32
+
33
+ 49
34
+ -1
35
+
36
+ ## Contest Information
37
+ - **Contest ID**: 0
38
+ - **Problem Index**:
39
+ - **Points**: 0.0
40
+ - **Rating**: 0
41
+ - **Tags**:
42
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
43
+ - **Memory Limit**: 134217728 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-12078/instruction.md ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02220 Parity Sort
2
+
3
+ ## Problem Description
4
+ Problem statement
5
+
6
+ Given a permutation $ P $ of length $ N $, sorted integers from $ 0 $ to $ N-1 $.
7
+
8
+ Sort $ P $ in ascending order by doing the following up to $ 30 $.
9
+
10
+ operation
11
+
12
+ For $ 1 $ operations, do the following 1 through 4 in sequence:
13
+
14
+ 1. Declare the string $ S $ of length $ N $ consisting of `0` and` 1` and the integer $ t $ ($ t = 0 $ or $ t = 1 $).
15
+ 2. Prepare an empty sequence $ A, B $ and do the following while moving the integer $ i $ from $ 1 $ to $ N $.
16
+ * When $ S_i $ is `0`, do nothing.
17
+ * When $ S_i $ is `1`
18
+ * If $ P_i $ is even, add $ P_i $ to the end of $ A $.
19
+ * If $ P_i $ is odd, add $ P_i $ to the end of $ B $.
20
+ 3. Define the sequence $ C $ as follows.
21
+ * When $ t = 0 $, $ C $ assumes that $ A $ and $ B $ are concatenated in this order.
22
+ * When $ t = 1 $, $ C $ is the concatenation of $ B $ and $ A $ in this order.
23
+ 4. While moving the integer $ i $ from $ 1 $ to $ N $, do the following:
24
+ * When $ S_i $ is `0`, do nothing.
25
+ * When $ S_i $ is `1`, replace $ P_i $ with the first element of $ C $ and delete the first element of $ C $.
26
+
27
+
28
+
29
+ For example, $ N = 7, P = {0, 4, 2, 3, 6, 5, 1} $.
30
+
31
+ When $ S $ is set to "1101101" and $ t = 1 $ is set to $ 1 $, $ P = {3, 1, 2, 0, 4, 5, 6} $ as shown in the figure below. I will.
32
+
33
+ parity-sort-example
34
+
35
+ Constraint
36
+
37
+ * $ 1 \ leq N \ leq 15000 $
38
+ * $ P $ is a permutation of integers from $ 0 $ to $ N-1 $
39
+
40
+
41
+
42
+ * * *
43
+
44
+ input
45
+
46
+ Input is given from standard input in the following format.
47
+
48
+
49
+ $ N $
50
+ $ P_1 $ $ P_2 $ $ \ ldots $ $ P_N $
51
+
52
+
53
+ output
54
+
55
+ Output $ 1 $ of the operation column that sorts $ P $ in ascending order within $ 30 $ in the following format. There may be multiple such operation sequences, but any output will be the correct answer.
56
+
57
+ * On the $ 1 $ line, output $ K $ for the number of operations to be performed. However, it must be $ 0 \ le K \ le 30 $.
58
+ * $ i + 1 $ line $ (1 \ le i \ le K) $ is the integer $ t_i (t_i = 0,1) $ declared in the $ i $ th operation and the character $ N $ in length. Output the column $ S_i $ in this order.
59
+
60
+
61
+
62
+
63
+ $ K $
64
+ $ t_1 $ $ S_1 $
65
+ $ t_2 $ $ S_2 $
66
+ $ \ vdots $
67
+ $ t_K $ $ S_K $
68
+
69
+
70
+ * * *
71
+
72
+ Input example 1
73
+
74
+
75
+ 7
76
+ 0 4 2 3 6 5 1
77
+
78
+
79
+ Output example 1
80
+
81
+
82
+ 1
83
+ 1 0100101
84
+
85
+
86
+ When the operation is performed, $ A = {4, 6}, B = {1} $, and from $ t = 1 $, $ C = {1, 4, 6} $.
87
+
88
+ Replacing the elements of $ P $ with $ C $ yields $ P = {0, 1, 2, 3, 4, 5, 6} $, so you can sort $ P $ in ascending order with this operation. I will.
89
+
90
+ * * *
91
+
92
+ Input example 2
93
+
94
+
95
+ Four
96
+ 1 0 3 2
97
+
98
+
99
+ Output example 2
100
+
101
+
102
+ 2
103
+ 0 1100
104
+ 0 0011
105
+
106
+
107
+ For example, the following output is also a correct answer.
108
+
109
+
110
+ 2
111
+ 0 1111
112
+ 1 0110
113
+
114
+
115
+ * * *
116
+
117
+ Input example 3
118
+
119
+
120
+ 1
121
+ 0
122
+
123
+
124
+ Output example 3
125
+
126
+
127
+ 0
128
+
129
+
130
+ You do not have to perform any operation.
131
+
132
+
133
+
134
+
135
+
136
+ Example
137
+
138
+ Input
139
+
140
+ 7
141
+ 0 4 2 3 6 5 1
142
+
143
+
144
+ Output
145
+
146
+ 1
147
+ 1 0100101
148
+
149
+ ## Contest Information
150
+ - **Contest ID**: 0
151
+ - **Problem Index**:
152
+ - **Points**: 0.0
153
+ - **Rating**: 0
154
+ - **Tags**:
155
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
156
+ - **Memory Limit**: 268435456 bytes
157
+
158
+ ## Task
159
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12479/instruction.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00041 Expression
2
+
3
+ ## Problem Description
4
+ Using the given four integers from 1 to 9, we create an expression that gives an answer of 10. When you enter four integers a, b, c, d, write a program that outputs an expression that gives an answer of 10 according to the following conditions. Also, if there are multiple answers, only the first answer found will be output. If there is no answer, output 0.
5
+
6
+ * Use only addition (+), subtraction (-), and multiplication (*) as operators. Do not use division (/). You can use three operators.
7
+ * You must use all four numbers.
8
+ * You can freely change the order of the four numbers.
9
+ * You can use parentheses. You can use up to 3 sets (6) of parentheses.
10
+
11
+
12
+
13
+ Input
14
+
15
+ Given multiple datasets. The format of each dataset is as follows:
16
+
17
+
18
+ a b c d
19
+
20
+ Input ends with four 0s. The number of datasets does not exceed 40.
21
+
22
+ Output
23
+
24
+ For each dataset, combine the given four integers with the above arithmetic symbols and parentheses to output an expression or 0 with a value of 10 on one line. The expression string must not exceed 1024 characters.
25
+
26
+ Example
27
+
28
+ Input
29
+
30
+ 8 7 9 9
31
+ 4 4 4 4
32
+ 5 5 7 5
33
+ 0 0 0 0
34
+
35
+
36
+ Output
37
+
38
+ ((9 * (9 - 7)) - 8)
39
+ 0
40
+ ((7 * 5) - (5 * 5))
41
+
42
+ ## Contest Information
43
+ - **Contest ID**: 0
44
+ - **Problem Index**:
45
+ - **Points**: 0.0
46
+ - **Rating**: 0
47
+ - **Tags**:
48
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
49
+ - **Memory Limit**: 134217728 bytes
50
+
51
+ ## Task
52
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12687/instruction.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00045 Sum and Average
2
+
3
+ ## Problem Description
4
+ Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity.
5
+
6
+
7
+
8
+ Input
9
+
10
+ The input is given in the following format:
11
+
12
+
13
+ Sales unit price, sales quantity
14
+ Sales unit price, sales quantity
15
+ ::
16
+ ::
17
+
18
+
19
+ A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100.
20
+
21
+ Output
22
+
23
+ Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place.
24
+
25
+ Example
26
+
27
+ Input
28
+
29
+ 100,20
30
+ 50,10
31
+ 70,35
32
+
33
+
34
+ Output
35
+
36
+ 4950
37
+ 22
38
+
39
+ ## Contest Information
40
+ - **Contest ID**: 0
41
+ - **Problem Index**:
42
+ - **Points**: 0.0
43
+ - **Rating**: 0
44
+ - **Tags**:
45
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
46
+ - **Memory Limit**: 134217728 bytes
47
+
48
+ ## Task
49
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-12844/instruction.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 286_A. Lucky Permutation
2
+
3
+ ## Problem Description
4
+ A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
5
+
6
+ A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
7
+
8
+ You have integer n. Find some lucky permutation p of size n.
9
+
10
+ Input
11
+
12
+ The first line contains integer n (1 ≤ n ≤ 105) — the required permutation size.
13
+
14
+ Output
15
+
16
+ Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
17
+
18
+ Otherwise, print n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) after a space — the required permutation.
19
+
20
+ If there are multiple answers, you can print any of them.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 1
27
+
28
+
29
+ Output
30
+
31
+ 1
32
+
33
+
34
+ Input
35
+
36
+ 2
37
+
38
+
39
+ Output
40
+
41
+ -1
42
+
43
+
44
+ Input
45
+
46
+ 4
47
+
48
+
49
+ Output
50
+
51
+ 2 4 1 3
52
+
53
+
54
+ Input
55
+
56
+ 5
57
+
58
+
59
+ Output
60
+
61
+ 2 5 3 1 4
62
+
63
+ ## Contest Information
64
+ - **Contest ID**: 286
65
+ - **Problem Index**: A
66
+ - **Points**: 500.0
67
+ - **Rating**: 1400
68
+ - **Tags**: constructive algorithms, math
69
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
70
+ - **Memory Limit**: 256000000 bytes
71
+
72
+ ## Task
73
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-13103/instruction.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00043 Puzzle
2
+
3
+ ## Problem Description
4
+ There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.
5
+
6
+ The conditions for completing the puzzle are
7
+
8
+ * You must have one combination of the same numbers.
9
+ * The remaining 12 numbers are 4 combinations of 3 numbers.
10
+ The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
11
+ * The same number can be used up to 4 times.
12
+
13
+
14
+
15
+ Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.
16
+
17
+ For example, if the given string is 3456666777999
18
+
19
+ If there is a "2", 234 567 666 77 999
20
+ If there is a "3", then 33 456 666 777 999
21
+ If there is a "5", then 345 567 666 77 999
22
+ If there is an "8", then 345 666 678 77 999
23
+
24
+ And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.
25
+
26
+
27
+
28
+ Input
29
+
30
+ The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.
31
+
32
+ Output
33
+
34
+ For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.
35
+
36
+ Example
37
+
38
+ Input
39
+
40
+ 3649596966777
41
+ 6358665788577
42
+ 9118992346175
43
+ 9643871425498
44
+ 7755542764533
45
+ 1133557799246
46
+
47
+
48
+ Output
49
+
50
+ 2 3 5 8
51
+ 3 4
52
+ 1 2 3 4 5 6 7 8 9
53
+ 7 8 9
54
+ 1 2 3 4 6 7 8
55
+ 0
56
+
57
+ ## Contest Information
58
+ - **Contest ID**: 0
59
+ - **Problem Index**:
60
+ - **Points**: 0.0
61
+ - **Rating**: 0
62
+ - **Tags**:
63
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
64
+ - **Memory Limit**: 134217728 bytes
65
+
66
+ ## Task
67
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1408/instruction.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 626_C. Block Towers
2
+
3
+ ## Problem Description
4
+ Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
5
+
6
+ The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
7
+
8
+ Input
9
+
10
+ The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
11
+
12
+ Output
13
+
14
+ Print a single integer, denoting the minimum possible height of the tallest tower.
15
+
16
+ Examples
17
+
18
+ Input
19
+
20
+ 1 3
21
+
22
+
23
+ Output
24
+
25
+ 9
26
+
27
+
28
+ Input
29
+
30
+ 3 2
31
+
32
+
33
+ Output
34
+
35
+ 8
36
+
37
+
38
+ Input
39
+
40
+ 5 0
41
+
42
+
43
+ Output
44
+
45
+ 10
46
+
47
+ Note
48
+
49
+ In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
50
+
51
+ In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
52
+
53
+ ## Contest Information
54
+ - **Contest ID**: 626
55
+ - **Problem Index**: C
56
+ - **Points**: 1000.0
57
+ - **Rating**: 1600
58
+ - **Tags**: brute force, greedy, math, number theory
59
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
60
+ - **Memory Limit**: 256000000 bytes
61
+
62
+ ## Task
63
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1430/instruction.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # om-nom-and-candies
2
+
3
+ ## Problem Description
4
+ There are N boxes .The i^th box contains ai candies . The frog Om Nom is sitting in box number 1 .Om Nom wants to collect as many candies as he can . However , Om Nom jumps in a peculiar fashion . Om Nom can jump from box number j to box number i only if j | i (j divides i) . Whenever Om Nom lands in a box , he collects all the candies in that box. You have to report the maximum number of Candies that Om Nom can collect for all i from 1 to N if i is the last box that Om Nom visits.See the samples for more details.
5
+
6
+ Constraints
7
+ 0 ≤ ai ≤ 100000
8
+ 1 ≤ N ≤ 100000
9
+
10
+ Input
11
+ The first line contains the number N.
12
+ The second line contains the array a , the i^th integer denoting the number of candies in the i^th box.
13
+
14
+ Output
15
+ Print N integers-the i^th integer should be the maximum number of candies that Om Nom can collect if the i^th box is his final box (i.e his sequence of jumps ends at i).
16
+
17
+ SAMPLE INPUT
18
+ 5
19
+ 2 3 1 4 6
20
+
21
+ SAMPLE OUTPUT
22
+ 2 5 3 9 8
23
+
24
+ Explanation
25
+
26
+ For i=1,Om Nom stops at box number 1 itself and so he can collect only 2 candies.
27
+ For i=2,the sequence of jumps is 1 2(array indices)
28
+ For i=3,the sequence of jumps is 1 3
29
+ For i=4,the sequence of jumps is 1 2 4
30
+ For i=5,the sequence of jumps is 1 5
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-1660/instruction.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01082 Escape of Lappin the Phantom Thief
2
+
3
+ ## Problem Description
4
+ Problem
5
+
6
+ Phantom thief Rappan came to steal the jewels. It was easy to get the jewel, but the jewel was equipped with a sensor and was surrounded by security robots.
7
+
8
+ The guard robot is designed to move towards the jewel. The sensor didn't seem to be easy to remove, so I decided to put a jewel and escape. I decided to keep the jewels as far away from the guard robot as possible to give me time to escape.
9
+
10
+ The site has a rectangular shape consisting of n x m squares and there are no obstacles. The k-body security robots are arranged in squares (xi, yi) (0 ≤ xi ≤ n−1, 0 ≤ yi ≤ m−1), respectively, and can move to the upper, lower, left and right squares in a unit time. The security robot moves to the square with the jewel in the shortest path.
11
+
12
+ Find the maximum travel time it takes for one or more guard robots to reach the jeweled square when you are free to place jewels on the premises.
13
+
14
+ Constraints
15
+
16
+ * 1 ≤ n, m ≤ 5 × 104
17
+ * 1 ≤ k ≤ min (105, n x m)
18
+ * 0 ≤ xi ≤ n−1
19
+ * 0 ≤ yi ≤ m−1
20
+ * All given coordinates are different
21
+
22
+ Input
23
+
24
+
25
+ n m k
26
+ x1 y1
27
+ x2 y2
28
+ ...
29
+ xk yk
30
+
31
+
32
+ All inputs are given as integers.
33
+ The first line is given n, m, k separated by blanks.
34
+ The coordinates (xi, yi) of the square where the guard robot is located are given in the second and subsequent lines k, separated by blanks.
35
+
36
+ Output
37
+
38
+ Output the travel time to the place where it takes the longest time for the security robot to reach in one line.
39
+
40
+ Examples
41
+
42
+ Input
43
+
44
+ 20 10 1
45
+ 0 0
46
+
47
+
48
+ Output
49
+
50
+ 28
51
+
52
+
53
+ Input
54
+
55
+ 20 10 2
56
+ 0 0
57
+ 17 5
58
+
59
+
60
+ Output
61
+
62
+ 15
63
+
64
+
65
+ Input
66
+
67
+ 20 10 3
68
+ 0 0
69
+ 17 5
70
+ 6 9
71
+
72
+
73
+ Output
74
+
75
+ 11
76
+
77
+ ## Contest Information
78
+ - **Contest ID**: 0
79
+ - **Problem Index**:
80
+ - **Points**: 0.0
81
+ - **Rating**: 0
82
+ - **Tags**:
83
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
84
+ - **Memory Limit**: 268435456 bytes
85
+
86
+ ## Task
87
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-1850/instruction.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # utkarsh-and-jumps
2
+
3
+ ## Problem Description
4
+ Utkarsh being a very talkative child, was scolded by his teacher multiple times. One day, the teacher became very angry and decided to give him a very rigorous punishment. He made him stand on the school field which is X axis.
5
+
6
+ Utkarsh initially stood at X = 0. The teacher asked him to run to X = N. But, to make the process quick, Utkarsh decided that he will make jumps of 2 or 3 steps only, i.e., from X = S he can jump to X = S+2 or X = S+3.
7
+
8
+ Utkarsh decided that he will jump 2 steps with probability P/100 and jump 3 steps with probability 1-P/100.
9
+
10
+ You need to find the probability that he will reach exactly on X = N.
11
+
12
+ Constraints:
13
+ 0 < N ≤ 10^6
14
+ 0 ≤ P ≤ 100
15
+
16
+ Input Constraints:
17
+ The first line contains two integer N and P.
18
+
19
+ Output Constraints:
20
+ Your answer must contain exactly 6 digits after the decimal point.
21
+
22
+ SAMPLE INPUT
23
+ 5 20
24
+
25
+ SAMPLE OUTPUT
26
+ 0.320000
27
+
28
+ Explanation
29
+
30
+ There are two ways to reach 5.
31
+
32
+ 2+3 with probability =0.2 * 0.8=0.16
33
+
34
+ 3+2 with probability =0.8 * 0.2=0.16
35
+
36
+ So, total probability = 0.32.
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-1868/instruction.md ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01068 Equivalent Vertices
2
+
3
+ ## Problem Description
4
+ Background
5
+
6
+ The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu-kun, one of the kindergarten children, loves drawing as much as programming. So far, Yu has drawn many pictures with circles, hexagons and arrows. One day Yu finds out that these pictures are graphs. It seems that circles and hexagons are called vertices, and arrows are called sides. Yu draws an arrow connecting the two vertices, and then writes 0 or 1 on it. A graph consisting of directed edges with weights (0 or 1) on the edges is called a weighted directed graph. Also, given a vertex and the number x (0 or 1), moving to another vertex according to the arrow with the same weight as x among the arrows coming out of that vertex is called transition according to x. Today, Yu-kun noticed that there are pairs of vertices that have the same type of vertices (circle or hexagon) that will eventually be reached no matter what sequence of 0s and 1s are followed. Yu-kun came up with a problem about this.
7
+
8
+ Problem
9
+
10
+ A weighted directed graph is given. Each vertex of this graph is numbered from 0 to n-1 in order. In addition, each vertex has a total of two sides, one with a weight of 0 and the other with a weight of 1. Furthermore, there are two types of vertices, round vertices and hexagonal vertices, and each vertex is one of them. The weighted directed graph given by Sample Input 2 is shown below.
11
+
12
+
13
+ Figure 1
14
+ Figure 1. Sample Input 2
15
+
16
+
17
+ You will be given m questions in the following format, so output the answers for each.
18
+
19
+ * Given the number q of the vertices, output the number of vertices equivalent to this vertex.
20
+
21
+
22
+
23
+ When two vertices a and b satisfy the following two conditions, a and b are equivalent.
24
+
25
+ 1. a and b are the same kind of vertices
26
+ 2. For any sequence of lengths 1 or more consisting of 0s and 1s, the types of vertices that are finally reached when the transition is started from each of a and b are the same.
27
+
28
+
29
+
30
+ For example, if the transition is started from vertex 3 in Fig. 1 according to the sequence 0,0,1,0, the transition is made in the order of 3-> 2-> 1-> 1-> 1, and the final reach is 1. ..
31
+
32
+ In Sample Input 2, vertex 0 and vertex 2 and vertex 0 and vertex 4 are equivalent. Consider vertex 0 and vertex 4. Both of these are round vertices, so the first condition is met. Also, the number of vertices reached as a result of transitioning from these vertices by 0 or 1 is 1 or 5. Vertices 1 and 5 continue to stay at the vertices regardless of the sequence of numbers. Both are hexagonal vertices. From this, the second condition is also satisfied because the vertices that finally reach the vertices 0 and 4 according to any sequence are hexagonal vertices. Vertex 0 and vertex 4 are equivalent because both conditions are met. Note that the final vertices do not have to be the same number, as long as they are of the same type. Also, vertex 0 and vertex 1 are not equivalent. Since vertex 0 is a round vertex and vertex 1 is a hexagonal vertex, the first condition is not satisfied.
33
+
34
+ Constraints
35
+
36
+ * All inputs are given as integers
37
+ * 1 ≤ n ≤ 3000
38
+ * 1 ≤ m ≤ n
39
+ * 0 ≤ si, ti, qj ≤ n-1
40
+ * 0 ≤ vi ≤ 1
41
+ * Assuming that the edges of a given graph can move in both directions, there is a set of edges that connects any two points, that is, the given graph is concatenated.
42
+
43
+ Input
44
+
45
+
46
+ n m
47
+ v0 s0 t0
48
+ v1 s1 t1
49
+ ...
50
+ vn−1 sn−1 tn−1
51
+ q0
52
+ q1
53
+ ...
54
+ qm−1
55
+
56
+
57
+ * vi, si, ti are the type of vertex i, the vertex number of the transition destination by 0, and the vertex number of the transition destination by 1.
58
+ * When vi is 0, the apex of number i is a round vertex, and when vi is 1, it is a hexagonal vertex.
59
+ * qj is the number of vertices given in the jth question
60
+
61
+ Output
62
+
63
+ For the vertex number qj given in each question, output the number of vertices equivalent to it on one line.
64
+
65
+ Examples
66
+
67
+ Input
68
+
69
+ 2 1
70
+ 0 0 1
71
+ 0 1 0
72
+ 0
73
+
74
+
75
+ Output
76
+
77
+ 2
78
+
79
+
80
+ Input
81
+
82
+ 6 6
83
+ 0 1 5
84
+ 1 1 1
85
+ 0 1 5
86
+ 0 2 1
87
+ 0 5 1
88
+ 1 5 5
89
+ 0
90
+ 1
91
+ 2
92
+ 3
93
+ 4
94
+ 5
95
+
96
+
97
+ Output
98
+
99
+ 3
100
+ 2
101
+ 3
102
+ 1
103
+ 3
104
+ 2
105
+
106
+ ## Contest Information
107
+ - **Contest ID**: 0
108
+ - **Problem Index**:
109
+ - **Points**: 0.0
110
+ - **Rating**: 0
111
+ - **Tags**:
112
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
113
+ - **Memory Limit**: 536870912 bytes
114
+
115
+ ## Task
116
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-2087/instruction.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # chrl2
2
+
3
+ ## Problem Description
4
+ Chef likes playing with strings. The most interesting game are named "CHEF in string". The move of the game consists of the following: Chef takes a subsequence of string's letters that form the word "CHEF" and then he removes that symbols. The goal of the game is to make the maximal number of moves. Please, help Chef and tell him the maximal possible number of moves that he is able to make for the given string S.
5
+
6
+ Input
7
+ The first line of each test case contains a given string. This string consists of uppercase letters from the set {"C", "H", "E", "F"}.
8
+
9
+ Output
10
+ Output a single line containing the maximal possible number of moves.
11
+
12
+ Constraints
13
+
14
+ 1 ≤ |S| ≤ 100000
15
+
16
+
17
+ Example
18
+ Input:
19
+ CHEFCHEFFFF
20
+
21
+ Output:
22
+ 2
23
+
24
+ Input:
25
+ CHHHEEEFFCC
26
+
27
+ Output:
28
+ 1
29
+
30
+
31
+ Scoring
32
+ Subtask 1 (25 points): |S| ≤ 2000
33
+ Subtask 2 (75 points): See the constraints.
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-2812/instruction.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02268 Binary Search
2
+
3
+ ## Problem Description
4
+ You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
5
+
6
+ Notes
7
+
8
+ Constraints
9
+
10
+ * Elements in S is sorted in ascending order
11
+ * n ≤ 100000
12
+ * q ≤ 50000
13
+ * 0 ≤ an element in S ≤ 109
14
+ * 0 ≤ an element in T ≤ 109
15
+
16
+ Input
17
+
18
+ In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.
19
+
20
+ Output
21
+
22
+ Print C in a line.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 5
29
+ 1 2 3 4 5
30
+ 3
31
+ 3 4 1
32
+
33
+
34
+ Output
35
+
36
+ 3
37
+
38
+
39
+ Input
40
+
41
+ 3
42
+ 1 2 3
43
+ 1
44
+ 5
45
+
46
+
47
+ Output
48
+
49
+ 0
50
+
51
+
52
+ Input
53
+
54
+ 5
55
+ 1 1 2 2 3
56
+ 2
57
+ 1 2
58
+
59
+
60
+ Output
61
+
62
+ 2
63
+
64
+ ## Contest Information
65
+ - **Contest ID**: 0
66
+ - **Problem Index**:
67
+ - **Points**: 0.0
68
+ - **Rating**: 0
69
+ - **Tags**:
70
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
71
+ - **Memory Limit**: 134217728 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-2877/instruction.md ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 902_B. Coloring a Tree
2
+
3
+ ## Problem Description
4
+ You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.
5
+
6
+ Each vertex has a color, let's denote the color of vertex v by cv. Initially cv = 0.
7
+
8
+ You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex v and a color x, and then color all vectices in the subtree of v (including v itself) in color x. In other words, for every vertex u, such that the path from root to u passes through v, set cu = x.
9
+
10
+ It is guaranteed that you have to color each vertex in a color different from 0.
11
+
12
+ You can learn what a rooted tree is using the link: https://en.wikipedia.org/wiki/Tree_(graph_theory).
13
+
14
+ Input
15
+
16
+ The first line contains a single integer n (2 ≤ n ≤ 104) — the number of vertices in the tree.
17
+
18
+ The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi < i), where pi means that there is an edge between vertices i and pi.
19
+
20
+ The third line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ n), where ci is the color you should color the i-th vertex into.
21
+
22
+ It is guaranteed that the given graph is a tree.
23
+
24
+ Output
25
+
26
+ Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.
27
+
28
+ Examples
29
+
30
+ Input
31
+
32
+ 6
33
+ 1 2 2 1 5
34
+ 2 1 1 1 1 1
35
+
36
+
37
+ Output
38
+
39
+ 3
40
+
41
+
42
+ Input
43
+
44
+ 7
45
+ 1 1 2 3 1 4
46
+ 3 3 1 1 1 2 3
47
+
48
+
49
+ Output
50
+
51
+ 5
52
+
53
+ Note
54
+
55
+ The tree from the first sample is shown on the picture (numbers are vetices' indices):
56
+
57
+ <image>
58
+
59
+ On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):
60
+
61
+ <image>
62
+
63
+ On seond step we color all vertices in the subtree of vertex 5 into color 1:
64
+
65
+ <image>
66
+
67
+ On third step we color all vertices in the subtree of vertex 2 into color 1:
68
+
69
+ <image>
70
+
71
+ The tree from the second sample is shown on the picture (numbers are vetices' indices):
72
+
73
+ <image>
74
+
75
+ On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors):
76
+
77
+ <image>
78
+
79
+ On second step we color all vertices in the subtree of vertex 3 into color 1:
80
+
81
+ <image>
82
+
83
+ On third step we color all vertices in the subtree of vertex 6 into color 2:
84
+
85
+ <image>
86
+
87
+ On fourth step we color all vertices in the subtree of vertex 4 into color 1:
88
+
89
+ <image>
90
+
91
+ On fith step we color all vertices in the subtree of vertex 7 into color 3:
92
+
93
+ <image>
94
+
95
+ ## Contest Information
96
+ - **Contest ID**: 902
97
+ - **Problem Index**: B
98
+ - **Points**: 1000.0
99
+ - **Rating**: 1200
100
+ - **Tags**: dfs and similar, dsu, greedy
101
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
102
+ - **Memory Limit**: 256000000 bytes
103
+
104
+ ## Task
105
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-2883/instruction.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # compound-conversion-1
2
+
3
+ ## Problem Description
4
+ Jesse and Walter recently got a into a problem. They need to check if a compound can be converted to the other one.
5
+ A compound is decoded into a binary strings of 0s and 1s. They have 2 binary strings. First string contains characters
6
+ '0', '1' and '?', whereas second contains '0' and '1' only. As Jesse and Walter are busy cooking meth, they need your
7
+ help.
8
+
9
+ For each case, you need to calculate number of steps needed to convert first compound to second. You can perform the
10
+ following operations:
11
+
12
+ Change '0' to '1'
13
+
14
+ Change '?' to '0' or '1'
15
+
16
+ Swap any two characters
17
+
18
+ Input:
19
+
20
+ First Line of the Input contains T, denoting number of test cases.
21
+ Then for each test case, there are two lines containg 2 strings denoting the compounds.
22
+
23
+ Output:
24
+
25
+ For each test case
26
+ Print minimum number of steps needed to convert 1st compound to the 2nd in seperate lines.
27
+ If it is not possible, output -1.
28
+
29
+ Constraints:
30
+
31
+ 1 ≤ Length of strings ≤ 100
32
+ Register for IndiaHacksSAMPLE INPUT
33
+ 3
34
+ 01??00
35
+ 001010
36
+ 01
37
+ 10
38
+ 110001
39
+ 000000
40
+
41
+ SAMPLE OUTPUT
42
+ Case 1: 3
43
+ Case 2: 1
44
+ Case 3: -1
45
+
46
+ Register for IndiaHacks
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-3108/instruction.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p03773 AtCoder Beginner Contest 057 - Remaining Time
2
+
3
+ ## Problem Description
4
+ Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
5
+ In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
6
+ The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
7
+
8
+ Constraints
9
+
10
+ * 0 \leq A,B \leq 23
11
+ * A and B are integers.
12
+
13
+ Input
14
+
15
+ The input is given from Standard Input in the following format:
16
+
17
+
18
+ A B
19
+
20
+
21
+ Output
22
+
23
+ Print the hour of the starting time of the contest in 24-hour time.
24
+
25
+ Examples
26
+
27
+ Input
28
+
29
+ 9 12
30
+
31
+
32
+ Output
33
+
34
+ 21
35
+
36
+
37
+ Input
38
+
39
+ 19 0
40
+
41
+
42
+ Output
43
+
44
+ 19
45
+
46
+
47
+ Input
48
+
49
+ 23 2
50
+
51
+
52
+ Output
53
+
54
+ 1
55
+
56
+ ## Contest Information
57
+ - **Contest ID**: 0
58
+ - **Problem Index**:
59
+ - **Points**: 0.0
60
+ - **Rating**: 0
61
+ - **Tags**:
62
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
63
+ - **Memory Limit**: 268435456 bytes
64
+
65
+ ## Task
66
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-3367/instruction.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 185_E. Soap Time! - 2
2
+
3
+ ## Problem Description
4
+ Imagine the Cartesian coordinate system. There are k different points containing subway stations. One can get from any subway station to any one instantly. That is, the duration of the transfer between any two subway stations can be considered equal to zero. You are allowed to travel only between subway stations, that is, you are not allowed to leave the subway somewhere in the middle of your path, in-between the stations.
5
+
6
+ There are n dwarves, they are represented by their coordinates on the plane. The dwarves want to come together and watch a soap opera at some integer point on the plane. For that, they choose the gathering point and start moving towards it simultaneously. In one second a dwarf can move from point (x, y) to one of the following points: (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1). Besides, the dwarves can use the subway as many times as they want (the subway transfers the dwarves instantly). The dwarves do not interfere with each other as they move (that is, the dwarves move simultaneously and independently from each other).
7
+
8
+ Help the dwarves and find the minimum time they need to gather at one point.
9
+
10
+ Input
11
+
12
+ The first line contains two integers n and k (1 ≤ n ≤ 105; 0 ≤ k ≤ 105) — the number of dwarves and the number of subway stations, correspondingly.
13
+
14
+ The next n lines contain the coordinates of the dwarves. The i-th line contains two space-separated integers xi and yi (|xi|, |yi| ≤ 108) — the coordinates of the i-th dwarf. It is guaranteed that all dwarves are located at different points.
15
+
16
+ The next k lines contain the coordinates of the subway stations. The t-th line contains two space-separated integers xt and yt (|xt|, |yt| ≤ 108) — the coordinates of the t-th subway station. It is guaranteed that all subway stations are located at different points.
17
+
18
+ Output
19
+
20
+ Print a single number — the minimum time, in which all dwarves can gather together at one point to watch the soap.
21
+
22
+ Examples
23
+
24
+ Input
25
+
26
+ 1 0
27
+ 2 -2
28
+
29
+
30
+ Output
31
+
32
+ 0
33
+
34
+
35
+ Input
36
+
37
+ 2 2
38
+ 5 -3
39
+ -4 -5
40
+ -4 0
41
+ -3 -2
42
+
43
+
44
+ Output
45
+
46
+ 6
47
+
48
+ ## Contest Information
49
+ - **Contest ID**: 185
50
+ - **Problem Index**: E
51
+ - **Points**: 2500.0
52
+ - **Rating**: 3000
53
+ - **Tags**: binary search, data structures
54
+ - **Time Limit**: {'seconds': 6, '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-3509/instruction.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # guess-the-triangle
2
+
3
+ ## Problem Description
4
+ You are given 3 points - middles of the sides of some triangle. Find coordinates of the triangle vertices.
5
+
6
+ Input
7
+ Input has 3 lines with 2 space-separated reals each - coordinates of the middles of the sides.
8
+
9
+ Output
10
+ Output 3 lines with 2 space-separated reals - coordinates of the triangle vertices. Each number should have exactly 4 digits after dot. Vertices should be sorted in first coordinate ascending order. If two points have the same first coordinate than they should have second coordinate ascending order.
11
+
12
+ Constraints
13
+ 0 ≤ xi, yi ≤ 1000
14
+
15
+ SAMPLE INPUT
16
+ 5.00 3.00
17
+ 4.0 4.0
18
+ 5.0 5.000
19
+
20
+ SAMPLE OUTPUT
21
+ 4.0000 2.0000
22
+ 4.0000 6.0000
23
+ 6.0000 4.0000
24
+
25
+ ## Contest Information
26
+ - **Contest ID**: 0
27
+ - **Problem Index**:
28
+ - **Points**: 0.0
29
+ - **Rating**: 0
30
+ - **Tags**: None
31
+ - **Time Limit**: None seconds
32
+ - **Memory Limit**: 0 bytes
33
+
34
+ ## Task
35
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-3531/instruction.md ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00840 Mobile Computing
2
+
3
+ ## Problem Description
4
+ There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful stones on the planet, and the Yaen people love to collect them. They bring the stones back home and make nice mobile arts of them to decorate their 2-dimensional living rooms.
5
+
6
+ In their 2-dimensional world, a mobile is defined recursively as follows:
7
+
8
+ * a stone hung by a string, or
9
+ * a rod of length 1 with two sub-mobiles at both ends; the rod is hung by a string at the center of gravity of sub-mobiles. When the weights of the sub-mobiles are n and m, and their distances from the center of gravity are a and b respectively, the equation n × a = m × b holds.
10
+
11
+
12
+ <image>
13
+
14
+
15
+ For example, if you got three stones with weights 1, 1, and 2, here are some possible mobiles and their widths:
16
+
17
+ <image>
18
+
19
+ Given the weights of stones and the width of the room, your task is to design the widest possible mobile satisfying both of the following conditions.
20
+
21
+ * It uses all the stones.
22
+ * Its width is less than the width of the room.
23
+
24
+
25
+
26
+ You should ignore the widths of stones.
27
+
28
+ In some cases two sub-mobiles hung from both ends of a rod might overlap (see the figure on the below). Such mobiles are acceptable. The width of the example is (1/3) + 1 + (1/4).
29
+
30
+
31
+ <image>
32
+
33
+
34
+
35
+ Input
36
+
37
+ The first line of the input gives the number of datasets. Then the specified number of datasets follow. A dataset has the following format.
38
+
39
+
40
+ r
41
+ s
42
+ w1
43
+ .
44
+ .
45
+ .
46
+ ws
47
+
48
+
49
+ r is a decimal fraction representing the width of the room, which satisfies 0 < r < 10. s is the number of the stones. You may assume 1 ≤ s ≤ 6. wi is the weight of the i-th stone, which is an integer. You may assume 1 ≤ wi ≤ 1000.
50
+
51
+ You can assume that no mobiles whose widths are between r - 0.00001 and r + 0.00001 can be made of given stones.
52
+
53
+ Output
54
+
55
+ For each dataset in the input, one line containing a decimal fraction should be output. The decimal fraction should give the width of the widest possible mobile as defined above. An output line should not contain extra characters such as spaces.
56
+
57
+ In case there is no mobile which satisfies the requirement, answer -1 instead.
58
+
59
+ The answer should not have an error greater than 0.00000001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.
60
+
61
+ Example
62
+
63
+ Input
64
+
65
+ 5
66
+ 1.3
67
+ 3
68
+ 1
69
+ 2
70
+ 1
71
+ 1.4
72
+ 3
73
+ 1
74
+ 2
75
+ 1
76
+ 2.0
77
+ 3
78
+ 1
79
+ 2
80
+ 1
81
+ 1.59
82
+ 4
83
+ 2
84
+ 1
85
+ 1
86
+ 3
87
+ 1.7143
88
+ 4
89
+ 1
90
+ 2
91
+ 3
92
+ 5
93
+
94
+
95
+ Output
96
+
97
+ -1
98
+ 1.3333333333333335
99
+ 1.6666666666666667
100
+ 1.5833333333333335
101
+ 1.7142857142857142
102
+
103
+ ## Contest Information
104
+ - **Contest ID**: 0
105
+ - **Problem Index**:
106
+ - **Points**: 0.0
107
+ - **Rating**: 0
108
+ - **Tags**:
109
+ - **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
110
+ - **Memory Limit**: 134217728 bytes
111
+
112
+ ## Task
113
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-3598/instruction.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 730_B. Minimum and Maximum
2
+
3
+ ## Problem Description
4
+ This is an interactive problem. You have to use flush operation right after printing each line. For example, in C++ you should use function fflush(stdout), in Java — System.out.flush(), in Pascal — flush(output) and in Python — sys.stdout.flush().
5
+
6
+ In this problem, you need to find maximal and minimal elements of an array. What could be simpler?
7
+
8
+ You can imagine that the jury has an array, and initially you know the only number n — array's length.
9
+
10
+ Array's elements are numbered from 1 to n. You are allowed to compare two elements of the array by using their indices i and j. There are three possible responses to this query: '<' (if ai is less than aj), '=' (if ai is equal to aj) and finally '>' (if ai is greater than aj).
11
+
12
+ It's known that it's always possible to find both maximal and minimal elements of the array by using no more than <image> comparisons, where ⌈ x⌉ is the result of rounding x up.
13
+
14
+ Write the program that will find positions of the minimum and the maximum in the jury's array of length n, by using no more than f(n) comparisons.
15
+
16
+ Interaction
17
+
18
+ Each test for this problem will contain one or more arrays. You have to find positions of minimal and maximal elements for each of these arrays. The first line of the input contains integer T (1 ≤ T ≤ 1000) — number of arrays in the test.
19
+
20
+ Thus, at the beginning, you program should read number T, and then it should solve the problem for T jury's arrays one by one.
21
+
22
+ Then input for each array goes. Firstly, your program has to read the number n (1 ≤ n ≤ 50) — the length of the array. It will be provided in the next line of the input.
23
+
24
+ Further, your program can perform comparisons or report that the answer is found.
25
+
26
+ * To perform a comparison, you have to output string of the following pattern «? i j» (i and j must be integer numbers from 1 to n) — the indices of the elements to compare in the current query.
27
+ * To report the indices of minimal and maximal elements of the hidden array, your program have to output a line in the form «! i j» (i and j must be integer numbers from 1 to n), where i is an index of the minimal element of array, and j is an index of the maximal element of the array. If there are several possible answers to the problem, you can output any of them.
28
+
29
+
30
+
31
+ There are several possible responses for a comparison:
32
+
33
+ * '<' — if ai is less than aj,
34
+ * '=' — if ai is equal to aj,
35
+ * '>' — if ai is greater than aj.
36
+
37
+
38
+
39
+ For an array of length n your program can make at most <image> comparisons. Note that the operation of reporting an answer («! i j» ) is not included into the value of f(n).
40
+
41
+ After the answer is reported, your program has to solve the problem for the next array or it should terminate if all T arrays are processed.
42
+
43
+ Example
44
+
45
+ Input
46
+
47
+ 2
48
+ 2
49
+  
50
+ &gt;
51
+  
52
+ 3
53
+  
54
+ =
55
+  
56
+ =
57
+  
58
+
59
+ Output
60
+
61
+  
62
+  
63
+ ? 1 2
64
+  
65
+ ! 2 1
66
+  
67
+ ? 3 1
68
+  
69
+ ? 2 1
70
+  
71
+ ! 2 3
72
+
73
+ ## Contest Information
74
+ - **Contest ID**: 730
75
+ - **Problem Index**: B
76
+ - **Points**: 0.0
77
+ - **Rating**: 1800
78
+ - **Tags**: constructive algorithms, interactive
79
+ - **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
80
+ - **Memory Limit**: 512000000 bytes
81
+
82
+ ## Task
83
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-3703/instruction.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 741_C. Arpa’s overnight party and Mehrdad’s silent entering
2
+
3
+ ## Problem Description
4
+ Note that girls in Arpa’s land are really attractive.
5
+
6
+ Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs were numbered 1 through 2n in clockwise direction. There was exactly one person sitting on each chair.
7
+
8
+ <image>
9
+
10
+ There were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that:
11
+
12
+ * Each person had exactly one type of food,
13
+ * No boy had the same type of food as his girlfriend,
14
+ * Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2n and 1 are considered consecutive.
15
+
16
+
17
+
18
+ Find the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions.
19
+
20
+ Input
21
+
22
+ The first line contains an integer n (1 ≤ n ≤ 105) — the number of pairs of guests.
23
+
24
+ The i-th of the next n lines contains a pair of integers ai and bi (1 ≤ ai, bi ≤ 2n) — the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair.
25
+
26
+ Output
27
+
28
+ If there is no solution, print -1.
29
+
30
+ Otherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2.
31
+
32
+ If there are multiple solutions, print any of them.
33
+
34
+ Example
35
+
36
+ Input
37
+
38
+ 3
39
+ 1 4
40
+ 2 5
41
+ 3 6
42
+
43
+
44
+ Output
45
+
46
+ 1 2
47
+ 2 1
48
+ 1 2
49
+
50
+ ## Contest Information
51
+ - **Contest ID**: 741
52
+ - **Problem Index**: C
53
+ - **Points**: 1250.0
54
+ - **Rating**: 2600
55
+ - **Tags**: constructive algorithms, dfs and similar, graphs
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-3934/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02699 AtCoder Beginner Contest 164 - Sheep and Wolves
2
+
3
+ ## Problem Description
4
+ There are S sheep and W wolves.
5
+
6
+ If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.
7
+
8
+ If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
9
+
10
+ Constraints
11
+
12
+ * 1 \leq S \leq 100
13
+ * 1 \leq W \leq 100
14
+
15
+ Input
16
+
17
+ Input is given from Standard Input in the following format:
18
+
19
+
20
+ S W
21
+
22
+
23
+ Output
24
+
25
+ If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
26
+
27
+ Examples
28
+
29
+ Input
30
+
31
+ 4 5
32
+
33
+
34
+ Output
35
+
36
+ unsafe
37
+
38
+
39
+ Input
40
+
41
+ 100 2
42
+
43
+
44
+ Output
45
+
46
+ safe
47
+
48
+
49
+ Input
50
+
51
+ 10 10
52
+
53
+
54
+ Output
55
+
56
+ unsafe
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 0
60
+ - **Problem Index**:
61
+ - **Points**: 0.0
62
+ - **Rating**: 0
63
+ - **Tags**:
64
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
65
+ - **Memory Limit**: 1073741824 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-3951/instruction.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p01173 Dig or Climb
2
+
3
+ ## Problem Description
4
+ Benjamin Forest VIII is a king of a country. One of his best friends Nod lives in a village far from his castle. Nod gets seriously sick and is on the verge of death. Benjamin orders his subordinate Red to bring good medicine for him as soon as possible. However, there is no road from the castle to the village. Therefore, Red needs to climb over mountains and across canyons to reach the village. He has decided to get to the village on the shortest path on a map, that is, he will move on the straight line between the castle and the village. Then his way can be considered as polyline with n points (x1, y1) . . . (xn , yn ) as illustlated in the following figure.
5
+
6
+ <image>
7
+
8
+ Figure 1: An example route from the castle to the village
9
+
10
+ Here, xi indicates the distance between the castle and the point i, as the crow flies, and yi indicates the height of the point i. The castle is located on the point (x1 , y1 ), and the village is located on the point (xn , yn).
11
+
12
+ Red can walk in speed vw . Also, since he has a skill to cut a tunnel through a mountain horizontally, he can move inside the mountain in speed vc.
13
+
14
+ Your job is to write a program to the minimum time to get to the village.
15
+
16
+
17
+
18
+ Input
19
+
20
+ The input is a sequence of datasets. Each dataset is given in the following format:
21
+
22
+
23
+ n
24
+ vw vc
25
+ x1 y1
26
+ ...
27
+ xn yn
28
+
29
+
30
+ You may assume all the following: n ≤ 1,000, 1 ≤ vw, vc ≤ 10, -10,000 ≤ xi, yi ≤ 10,000, and xi < xj for all i < j.
31
+
32
+ The input is terminated in case of n = 0. This is not part of any datasets and thus should not be processed.
33
+
34
+ Output
35
+
36
+ For each dataset, you should print the minimum time required to get to the village in a line. Each minimum time should be given as a decimal with an arbitrary number of fractional digits and with an absolute error of at most 10-6 . No extra space or character is allowed.
37
+
38
+ Example
39
+
40
+ Input
41
+
42
+ 3
43
+ 2 1
44
+ 0 0
45
+ 50 50
46
+ 100 0
47
+ 3
48
+ 1 1
49
+ 0 0
50
+ 50 50
51
+ 100 0
52
+ 3
53
+ 1 2
54
+ 0 0
55
+ 50 50
56
+ 100 0
57
+ 3
58
+ 2 1
59
+ 0 0
60
+ 100 100
61
+ 150 50
62
+ 6
63
+ 1 2
64
+ 0 0
65
+ 50 50
66
+ 100 0
67
+ 150 0
68
+ 200 50
69
+ 250 0
70
+ 0
71
+
72
+
73
+ Output
74
+
75
+ 70.710678
76
+ 100.000000
77
+ 50.000000
78
+ 106.066017
79
+ 150.000000
80
+
81
+ ## Contest Information
82
+ - **Contest ID**: 0
83
+ - **Problem Index**:
84
+ - **Points**: 0.0
85
+ - **Rating**: 0
86
+ - **Tags**:
87
+ - **Time Limit**: {'seconds': 8, '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-4142/instruction.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p02657 AtCoder Beginner Contest 169 - Multiplication 1
2
+
3
+ ## Problem Description
4
+ Compute A \times B.
5
+
6
+ Constraints
7
+
8
+ * 1 \leq A \leq 100
9
+ * 1 \leq B \leq 100
10
+ * All values in input are integers.
11
+
12
+ Input
13
+
14
+ Input is given from Standard Input in the following format:
15
+
16
+
17
+ A B
18
+
19
+
20
+ Output
21
+
22
+ Print the value A \times B as an integer.
23
+
24
+ Examples
25
+
26
+ Input
27
+
28
+ 2 5
29
+
30
+
31
+ Output
32
+
33
+ 10
34
+
35
+
36
+ Input
37
+
38
+ 100 100
39
+
40
+
41
+ Output
42
+
43
+ 10000
44
+
45
+ ## Contest Information
46
+ - **Contest ID**: 0
47
+ - **Problem Index**:
48
+ - **Points**: 0.0
49
+ - **Rating**: 0
50
+ - **Tags**:
51
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
52
+ - **Memory Limit**: 1073741824 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-4348/instruction.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # swapping-game-6
2
+
3
+ ## Problem Description
4
+ Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string.
5
+ One swap on a string is performed in this way:
6
+ Assuming 1 indexing, the i'th letter from the end is inserted
7
+ between i'th and (i+1)'th letter from the starting.
8
+
9
+ For example, we have "contest". After one swap, it would change to "ctosnet".
10
+ Check this image:
11
+
12
+ Input:
13
+ First line contains K, the number of swaps performed by Watson. Next line contains S, the string Watson gives to Sherlock.
14
+
15
+ Output:
16
+ You have to print in one line the original string with which Watson had started.
17
+
18
+ Constraints:
19
+ 1 ≤ K ≤ 10^9
20
+ 3 ≤ Length(S) ≤ 1000
21
+ All characters in S will be small English alphabets.
22
+
23
+ SAMPLE INPUT
24
+ 3
25
+ hrrkhceaate
26
+
27
+ SAMPLE OUTPUT
28
+ hackerearth
29
+
30
+ Explanation
31
+
32
+ When swapping is done on "hackerearth" 3 times, it transforms to "hrrkhceaate".
33
+
34
+ ## Contest Information
35
+ - **Contest ID**: 0
36
+ - **Problem Index**:
37
+ - **Points**: 0.0
38
+ - **Rating**: 0
39
+ - **Tags**: None
40
+ - **Time Limit**: None seconds
41
+ - **Memory Limit**: 0 bytes
42
+
43
+ ## Task
44
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-4714/instruction.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1424_C. Dušan's Railway
2
+
3
+ ## Problem Description
4
+ As you may already know, Dušan is keen on playing with railway models. He has a big map with cities that are connected with railways. His map can be seen as a graph where vertices are cities and the railways connecting them are the edges. So far, the graph corresponding to his map is a tree. As you already know, a tree is a connected acyclic undirected graph.
5
+
6
+ He is curious to find out whether his railway can be optimized somehow. He wants to add so-called shortcuts, which are also railways connecting pairs of cities. This shortcut will represent the railways in the unique path in the tree between the pair of cities it connects. Since Dušan doesn't like repeating the railways, he has also defined good paths in his newly obtained network (notice that after adding the shortcuts, his graph is no more a tree). He calls a path good, if no edge appears more than once, either as a regular railway edge or as an edge represented by some shortcut (Every shortcut in a good path has length 1, but uses up all the edges it represents - they can't appear again in that path). Having defined good paths, he defines good distance between two cities to be the length of the shortest good path between them. Finally, the shortcutting diameter of his network is the largest good distance between any two cities.
7
+
8
+ Now he is curious to find out whether it is possible to achieve shortcutting diameter less or equal than k, while adding as few shortcuts as possible.
9
+
10
+ Your solution should add no more than 10 ⋅ n shortcuts.
11
+
12
+ Input
13
+
14
+ The first line in the standard input contains an integer n (1 ≤ n ≤ 10^4), representing the number of the cities in Dušan's railway map, and an integer k (3 ≤ k ≤ n) representing the shortcutting diameter that he wants to achieve.
15
+
16
+ Each of the following n - 1 lines will contain two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), meaning that there is a railway between cities u_i and v_i.
17
+
18
+ Output
19
+
20
+ The first line of the output should contain a number t representing the number of the shortcuts that were added.
21
+
22
+ Each of the following t lines should contain two integers u_i and v_i, signifying that a shortcut is added between cities u_i and v_i.
23
+
24
+ Example
25
+
26
+ Input
27
+
28
+
29
+ 10 3
30
+ 1 2
31
+ 2 3
32
+ 3 4
33
+ 4 5
34
+ 5 6
35
+ 6 7
36
+ 7 8
37
+ 8 9
38
+ 9 10
39
+
40
+
41
+ Output
42
+
43
+
44
+ 8
45
+ 3 7
46
+ 3 5
47
+ 3 6
48
+ 3 1
49
+ 7 9
50
+ 7 10
51
+ 7 4
52
+ 7 5
53
+
54
+ Note
55
+
56
+ Notice that adding a shortcut between all cities and city 1 will make a graph theoretic diameter become 2. On the other hand, the paths obtained that way might not be good, since some of the edges might get duplicated. In the example, adding a shortcut between all cities and city 1 doesn't create a valid solution, because for cities 5 and 10 the path that uses shortcuts 5-1 and 1-10 is not valid because it uses edges 1-2, 2-3, 3-4, 4-5 twice.
57
+
58
+ ## Contest Information
59
+ - **Contest ID**: 1424
60
+ - **Problem Index**: C
61
+ - **Points**: 0.0
62
+ - **Rating**: 3500
63
+ - **Tags**: divide and conquer, graphs, trees
64
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
65
+ - **Memory Limit**: 256000000 bytes
66
+
67
+ ## Task
68
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-4923/instruction.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1440_A. Buy the String
2
+
3
+ ## Problem Description
4
+ You are given four integers n, c_0, c_1 and h and a binary string s of length n.
5
+
6
+ A binary string is a string consisting of characters 0 and 1.
7
+
8
+ You can change any character of the string s (the string should be still binary after the change). You should pay h coins for each change.
9
+
10
+ After some changes (possibly zero) you want to buy the string. To buy the string you should buy all its characters. To buy the character 0 you should pay c_0 coins, to buy the character 1 you should pay c_1 coins.
11
+
12
+ Find the minimum number of coins needed to buy the string.
13
+
14
+ Input
15
+
16
+ The first line contains a single integer t (1 ≤ t ≤ 10) — the number of test cases. Next 2t lines contain descriptions of test cases.
17
+
18
+ The first line of the description of each test case contains four integers n, c_{0}, c_{1}, h (1 ≤ n, c_{0}, c_{1}, h ≤ 1000).
19
+
20
+ The second line of the description of each test case contains the binary string s of length n.
21
+
22
+ Output
23
+
24
+ For each test case print a single integer — the minimum number of coins needed to buy the string.
25
+
26
+ Example
27
+
28
+ Input
29
+
30
+
31
+ 6
32
+ 3 1 1 1
33
+ 100
34
+ 5 10 100 1
35
+ 01010
36
+ 5 10 1 1
37
+ 11111
38
+ 5 1 10 1
39
+ 11111
40
+ 12 2 1 10
41
+ 101110110101
42
+ 2 100 1 10
43
+ 00
44
+
45
+
46
+ Output
47
+
48
+
49
+ 3
50
+ 52
51
+ 5
52
+ 10
53
+ 16
54
+ 22
55
+
56
+ Note
57
+
58
+ In the first test case, you can buy all characters and pay 3 coins, because both characters 0 and 1 costs 1 coin.
59
+
60
+ In the second test case, you can firstly change 2-nd and 4-th symbols of the string from 1 to 0 and pay 2 coins for that. Your string will be 00000. After that, you can buy the string and pay 5 ⋅ 10 = 50 coins for that. The total number of coins paid will be 2 + 50 = 52.
61
+
62
+ ## Contest Information
63
+ - **Contest ID**: 1440
64
+ - **Problem Index**: A
65
+ - **Points**: 500.0
66
+ - **Rating**: 800
67
+ - **Tags**: implementation, math
68
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
69
+ - **Memory Limit**: 256000000 bytes
70
+
71
+ ## Task
72
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-4946/instruction.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 594_C. Edo and Magnets
2
+
3
+ ## Problem Description
4
+ Edo has got a collection of n refrigerator magnets!
5
+
6
+ He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be positive integers.
7
+
8
+ Edo figured out how he wants to place the magnets on the refrigerator. He introduced a system of coordinates on the plane, where each magnet is represented as a rectangle with sides parallel to the coordinate axes.
9
+
10
+ Now he wants to remove no more than k magnets (he may choose to keep all of them) and attach all remaining magnets to the refrigerator door, and the area of ​​the door should be as small as possible. A magnet is considered to be attached to the refrigerator door if its center lies on the door or on its boundary. The relative positions of all the remaining magnets must correspond to the plan.
11
+
12
+ Let us explain the last two sentences. Let's suppose we want to hang two magnets on the refrigerator. If the magnet in the plan has coordinates of the lower left corner (x1, y1) and the upper right corner (x2, y2), then its center is located at (<image>, <image>) (may not be integers). By saying the relative position should correspond to the plan we mean that the only available operation is translation, i.e. the vector connecting the centers of two magnets in the original plan, must be equal to the vector connecting the centers of these two magnets on the refrigerator.
13
+
14
+ The sides of the refrigerator door must also be parallel to coordinate axes.
15
+
16
+ Input
17
+
18
+ The first line contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ min(10, n - 1)) — the number of magnets that Edo has and the maximum number of magnets Edo may not place on the refrigerator.
19
+
20
+ Next n lines describe the initial plan of placing magnets. Each line contains four integers x1, y1, x2, y2 (1 ≤ x1 < x2 ≤ 109, 1 ≤ y1 < y2 ≤ 109) — the coordinates of the lower left and upper right corners of the current magnet. The magnets can partially overlap or even fully coincide.
21
+
22
+ Output
23
+
24
+ Print a single integer — the minimum area of the door of refrigerator, which can be used to place at least n - k magnets, preserving the relative positions.
25
+
26
+ Examples
27
+
28
+ Input
29
+
30
+ 3 1
31
+ 1 1 2 2
32
+ 2 2 3 3
33
+ 3 3 4 4
34
+
35
+
36
+ Output
37
+
38
+ 1
39
+
40
+
41
+ Input
42
+
43
+ 4 1
44
+ 1 1 2 2
45
+ 1 9 2 10
46
+ 9 9 10 10
47
+ 9 1 10 2
48
+
49
+
50
+ Output
51
+
52
+ 64
53
+
54
+
55
+ Input
56
+
57
+ 3 0
58
+ 1 1 2 2
59
+ 1 1 1000000000 1000000000
60
+ 1 3 8 12
61
+
62
+
63
+ Output
64
+
65
+ 249999999000000001
66
+
67
+ Note
68
+
69
+ In the first test sample it is optimal to remove either the first or the third magnet. If we remove the first magnet, the centers of two others will lie at points (2.5, 2.5) and (3.5, 3.5). Thus, it is enough to buy a fridge with door width 1 and door height 1, the area of the door also equals one, correspondingly.
70
+
71
+ In the second test sample it doesn't matter which magnet to remove, the answer will not change — we need a fridge with door width 8 and door height 8.
72
+
73
+ In the third sample you cannot remove anything as k = 0.
74
+
75
+ ## Contest Information
76
+ - **Contest ID**: 594
77
+ - **Problem Index**: C
78
+ - **Points**: 1500.0
79
+ - **Rating**: 2300
80
+ - **Tags**: brute force, greedy, implementation, two pointers
81
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
82
+ - **Memory Limit**: 256000000 bytes
83
+
84
+ ## Task
85
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-5039/instruction.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 33_C. Wonderful Randomized Sum
2
+
3
+ ## Problem Description
4
+ Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
5
+
6
+ Input
7
+
8
+ The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
9
+
10
+ Output
11
+
12
+ The first and the only line of the output should contain the answer to the problem.
13
+
14
+ Examples
15
+
16
+ Input
17
+
18
+ 3
19
+ -1 -2 -3
20
+
21
+
22
+ Output
23
+
24
+ 6
25
+
26
+
27
+ Input
28
+
29
+ 5
30
+ -4 2 0 5 0
31
+
32
+
33
+ Output
34
+
35
+ 11
36
+
37
+
38
+ Input
39
+
40
+ 5
41
+ -1 10 -5 10 -2
42
+
43
+
44
+ Output
45
+
46
+ 18
47
+
48
+ ## Contest Information
49
+ - **Contest ID**: 33
50
+ - **Problem Index**: C
51
+ - **Points**: 1500.0
52
+ - **Rating**: 1800
53
+ - **Tags**: greedy
54
+ - **Time Limit**: {'seconds': 2, '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-5090/instruction.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # p00373 Aerial Photo
2
+
3
+ ## Problem Description
4
+ Hideyo has come by two aerial photos of the same scale and orientation. You can see various types of buildings, but some areas are hidden by clouds. Apparently, they are of the same area, and the area covered by the second photograph falls entirely within the first. However, because they were taken at different time points, different shapes and distribution of clouds obscure identification where the area in the second photograph is located in the first. There may even be more than one area within the first that the second fits equally well.
5
+
6
+ A set of pixel information is given for each of the photographs. Write a program to extract candidate sub-areas within the first photograph that compare with the second equally well and output the number of the candidates.
7
+
8
+
9
+
10
+ Input
11
+
12
+ The input is given in the following format.
13
+
14
+
15
+ AW AH BW BH
16
+ arow1
17
+ arow2
18
+ :
19
+ arowAH
20
+ brow1
21
+ brow2
22
+ :
23
+ browBH
24
+
25
+
26
+ The first line provides the number of pixels in the horizontal and the vertical direction AW (1 ≤ AW ≤ 800) and AH (1 ≤ AH ≤ 800) for the first photograph, followed by those for the second BW (1 ≤ BW ≤ 100) and BH (1 ≤ BH ≤ 100) (AW ≥ BW andAH ≥ BH). Each of the subsequent AH lines provides pixel information (arowi) of the i-th row from the top of the first photograph. Each of the BH lines that follows provides pixel information (browi) of the i-th row from the top of the second photograph.
27
+
28
+ Each of the pixel information arowi and browi is a string of length AW and BW, respectively, consisting of upper/lower-case letters, numeric characters, or "?". Each one character represents a pixel, whereby upper/lower-case letters and numeric characters represent a type of building, and "?" indicates a cloud-covered area.
29
+
30
+ Output
31
+
32
+ Output the number of the candidates.
33
+
34
+ Examples
35
+
36
+ Input
37
+
38
+ 5 5 3 3
39
+ AF??z
40
+ W?p88
41
+ ???Hk
42
+ pU?m?
43
+ F???c
44
+ F??
45
+ p?8
46
+ ?H?
47
+
48
+
49
+ Output
50
+
51
+ 4
52
+
53
+
54
+ Input
55
+
56
+ 6 5 4 2
57
+ aaaaaa
58
+ aaaaaa
59
+ aaaaaa
60
+ aaaaaa
61
+ aaaaaa
62
+ aaaa
63
+ aaaa
64
+
65
+
66
+ Output
67
+
68
+ 12
69
+
70
+ ## Contest Information
71
+ - **Contest ID**: 0
72
+ - **Problem Index**:
73
+ - **Points**: 0.0
74
+ - **Rating**: 0
75
+ - **Tags**:
76
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
77
+ - **Memory Limit**: 268435456 bytes
78
+
79
+ ## Task
80
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-5438/instruction.md ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1331_F. Elementary!
2
+
3
+ ## Problem Description
4
+
5
+
6
+ Input
7
+
8
+ The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
9
+
10
+ Output
11
+
12
+ Output "YES" or "NO".
13
+
14
+ Examples
15
+
16
+ Input
17
+
18
+
19
+ GENIUS
20
+
21
+
22
+ Output
23
+
24
+
25
+ YES
26
+
27
+
28
+ Input
29
+
30
+
31
+ DOCTOR
32
+
33
+
34
+ Output
35
+
36
+
37
+ NO
38
+
39
+
40
+ Input
41
+
42
+
43
+ IRENE
44
+
45
+
46
+ Output
47
+
48
+
49
+ YES
50
+
51
+
52
+ Input
53
+
54
+
55
+ MARY
56
+
57
+
58
+ Output
59
+
60
+
61
+ NO
62
+
63
+
64
+ Input
65
+
66
+
67
+ SMARTPHONE
68
+
69
+
70
+ Output
71
+
72
+
73
+ NO
74
+
75
+
76
+ Input
77
+
78
+
79
+ REVOLVER
80
+
81
+
82
+ Output
83
+
84
+
85
+ YES
86
+
87
+
88
+ Input
89
+
90
+
91
+ HOLMES
92
+
93
+
94
+ Output
95
+
96
+
97
+ NO
98
+
99
+
100
+ Input
101
+
102
+
103
+ WATSON
104
+
105
+
106
+ Output
107
+
108
+
109
+ YES
110
+
111
+ ## Contest Information
112
+ - **Contest ID**: 1331
113
+ - **Problem Index**: F
114
+ - **Points**: 0.0
115
+ - **Rating**: 0
116
+ - **Tags**: *special, brute force, dp, strings
117
+ - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
118
+ - **Memory Limit**: 256000000 bytes
119
+
120
+ ## Task
121
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-5805/instruction.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # socks-puzzle
2
+
3
+ ## Problem Description
4
+ Tom is off to a school Annual Day and is searching for a matching pair of socks. His drawer is filled with socks, each pair of a different color. In its worst case scenario, how many socks (x) should Tom remove from his drawer until he finds a matching pair?
5
+
6
+ Input Format
7
+
8
+ The first line contains the number of test cases T.
9
+ Next T lines contains an integer N which indicates the total pairs of socks present in the drawer.
10
+
11
+ Output Format
12
+
13
+ Print the number of Draws (x) Tom makes in the worst case scenario.
14
+
15
+ Constraints
16
+
17
+ 1≤T≤1000
18
+ 0<N<10^6
19
+
20
+ SAMPLE INPUT
21
+ 2
22
+ 1
23
+ 2
24
+
25
+ SAMPLE OUTPUT
26
+ 2
27
+ 3
28
+
29
+ Explanation
30
+
31
+ Case 1 : A pair of socks are present, hence exactly 2 draws for the socks to match.
32
+ Case 2 : 2 pair of socks are present in the drawer. The first and the second draw might result in 2 socks of different color. The 3rd sock picked will definitely match one of previously picked socks. Hence, 3.
33
+
34
+ ## Contest Information
35
+ - **Contest ID**: 0
36
+ - **Problem Index**:
37
+ - **Points**: 0.0
38
+ - **Rating**: 0
39
+ - **Tags**: None
40
+ - **Time Limit**: None seconds
41
+ - **Memory Limit**: 0 bytes
42
+
43
+ ## Task
44
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
code_contests-5894/instruction.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 842_D. Vitya and Strange Lesson
2
+
3
+ ## Problem Description
4
+ Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0.
5
+
6
+ Vitya quickly understood all tasks of the teacher, but can you do the same?
7
+
8
+ You are given an array consisting of n non-negative integers, and m queries. Each query is characterized by one number x and consists of the following consecutive steps:
9
+
10
+ * Perform the bitwise addition operation modulo 2 (xor) of each array element with the number x.
11
+ * Find mex of the resulting array.
12
+
13
+
14
+
15
+ Note that after each query the array changes.
16
+
17
+ Input
18
+
19
+ First line contains two integer numbers n and m (1 ≤ n, m ≤ 3·105) — number of elements in array and number of queries.
20
+
21
+ Next line contains n integer numbers ai (0 ≤ ai ≤ 3·105) — elements of then array.
22
+
23
+ Each of next m lines contains query — one integer number x (0 ≤ x ≤ 3·105).
24
+
25
+ Output
26
+
27
+ For each query print the answer on a separate line.
28
+
29
+ Examples
30
+
31
+ Input
32
+
33
+ 2 2
34
+ 1 3
35
+ 1
36
+ 3
37
+
38
+
39
+ Output
40
+
41
+ 1
42
+ 0
43
+
44
+
45
+ Input
46
+
47
+ 4 3
48
+ 0 1 5 6
49
+ 1
50
+ 2
51
+ 4
52
+
53
+
54
+ Output
55
+
56
+ 2
57
+ 0
58
+ 0
59
+
60
+
61
+ Input
62
+
63
+ 5 4
64
+ 0 1 5 6 7
65
+ 1
66
+ 1
67
+ 4
68
+ 5
69
+
70
+
71
+ Output
72
+
73
+ 2
74
+ 2
75
+ 0
76
+ 2
77
+
78
+ ## Contest Information
79
+ - **Contest ID**: 842
80
+ - **Problem Index**: D
81
+ - **Points**: 2000.0
82
+ - **Rating**: 2000
83
+ - **Tags**: binary search, data structures
84
+ - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
85
+ - **Memory Limit**: 256000000 bytes
86
+
87
+ ## Task
88
+ Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.