EtashGuha commited on
Commit
44a59cd
·
verified ·
1 Parent(s): 16e3ef0

Upload folder using huggingface_hub

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-0000/environment/Dockerfile +0 -5
  2. code_contests-0000/instruction.md +0 -51
  3. code_contests-0001/environment/Dockerfile +0 -5
  4. code_contests-0001/instruction.md +0 -60
  5. code_contests-0002/environment/Dockerfile +0 -5
  6. code_contests-0002/instruction.md +0 -54
  7. code_contests-0003/environment/Dockerfile +0 -5
  8. code_contests-0003/instruction.md +0 -66
  9. code_contests-0005/environment/Dockerfile +0 -5
  10. code_contests-0005/instruction.md +0 -40
  11. code_contests-0006/environment/Dockerfile +0 -5
  12. code_contests-0006/instruction.md +0 -81
  13. code_contests-0007/environment/Dockerfile +0 -5
  14. code_contests-0007/instruction.md +0 -124
  15. code_contests-0008/environment/Dockerfile +0 -5
  16. code_contests-0008/instruction.md +0 -72
  17. code_contests-0010/environment/Dockerfile +0 -5
  18. code_contests-0010/instruction.md +0 -54
  19. code_contests-0011/environment/Dockerfile +0 -5
  20. code_contests-0011/instruction.md +0 -80
  21. code_contests-0012/environment/Dockerfile +0 -5
  22. code_contests-0012/instruction.md +0 -112
  23. code_contests-0015/environment/Dockerfile +0 -5
  24. code_contests-0015/instruction.md +0 -82
  25. code_contests-0016/environment/Dockerfile +0 -5
  26. code_contests-0016/instruction.md +0 -121
  27. code_contests-0017/environment/Dockerfile +0 -5
  28. code_contests-0017/instruction.md +0 -70
  29. code_contests-0018/environment/Dockerfile +0 -5
  30. code_contests-0018/instruction.md +0 -61
  31. code_contests-0019/environment/Dockerfile +0 -5
  32. code_contests-0019/instruction.md +0 -182
  33. code_contests-0020/environment/Dockerfile +0 -5
  34. code_contests-0020/instruction.md +0 -75
  35. code_contests-0021/environment/Dockerfile +0 -5
  36. code_contests-0021/instruction.md +0 -60
  37. code_contests-0023/environment/Dockerfile +0 -5
  38. code_contests-0023/instruction.md +0 -94
  39. code_contests-0024/environment/Dockerfile +0 -5
  40. code_contests-0024/instruction.md +0 -63
  41. code_contests-0025/environment/Dockerfile +0 -5
  42. code_contests-0025/instruction.md +0 -89
  43. code_contests-0026/environment/Dockerfile +0 -5
  44. code_contests-0026/instruction.md +0 -93
  45. code_contests-0027/environment/Dockerfile +0 -5
  46. code_contests-0027/instruction.md +0 -112
  47. code_contests-0029/environment/Dockerfile +0 -5
  48. code_contests-0029/instruction.md +0 -62
  49. code_contests-0030/environment/Dockerfile +0 -5
  50. code_contests-0030/instruction.md +0 -79
code_contests-0000/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0000/instruction.md DELETED
@@ -1,51 +0,0 @@
1
- # brcktsrm
2
-
3
- ## Problem Description
4
- Problem description.
5
- Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friend help him in his time of hardship.
6
-
7
- Input
8
-
9
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
10
- The first line of each test case contains a single string S denoting the string to be checked.
11
-
12
-
13
- Output
14
-
15
- For each test case, output a single line printing "YES" or "NO" (without " " and in uppercase only) , denoting if the brackets in the given string is balanced or not .
16
-
17
-
18
- Constraints
19
-
20
- 1 ≤ T ≤ 10
21
- 1 ≤ length of S ≤ 60
22
-
23
-
24
- Example
25
- Input:
26
- 3
27
- ((()))
28
- (())()
29
- ()(()
30
-
31
- Output:
32
- YES
33
- YES
34
- NO
35
-
36
-  
37
-
38
- Explanation
39
- Example is self-explanatory.
40
-
41
- ## Contest Information
42
- - **Contest ID**: 0
43
- - **Problem Index**:
44
- - **Points**: 0.0
45
- - **Rating**: 0
46
- - **Tags**: None
47
- - **Time Limit**: None seconds
48
- - **Memory Limit**: 0 bytes
49
-
50
- ## Task
51
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0001/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0001/instruction.md DELETED
@@ -1,60 +0,0 @@
1
- # comm3
2
-
3
- ## Problem Description
4
- The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly.
5
-
6
-
7
- The Chef invested in top-of-the-line transceivers which have a few advanced features. One is that even if two people cannot talk directly because they are out of range, if there is another transceiver that is close enough to both, then the two transceivers can still communicate with each other using the third transceiver as an intermediate device.
8
-
9
-
10
- There has been a minor emergency in the Chef's restaurant
11
- and he needs to communicate with both the head server and the sous-chef right away. Help the Chef determine if it is possible for all three people to communicate with each other, even if two must communicate through the third because they are too far apart.
12
-
13
-
14
- Input
15
-
16
- The first line contains a single positive integer T ≤ 100 indicating the number of test cases to follow. The first line of each test case contains a positive integer R ≤ 1,000 indicating that two transceivers can communicate directly without an intermediate transceiver if they are at most R meters away from each other. The remaining three lines of the test case describe the current locations of the Chef, the head server, and the sous-chef, respectively. Each such line contains two integers X,Y (at most 10,000 in absolute value) indicating that the respective person is located at position X,Y.
17
-
18
-
19
- Output
20
-
21
- For each test case you are to output a single line containing a single string. If it is possible for all three to communicate then you should output "yes". Otherwise, you should output "no".
22
-
23
-
24
- To be clear, we say that two transceivers are close enough to communicate directly if the length of the straight line connecting their X,Y coordinates is at most R.
25
-
26
-
27
- Example
28
-
29
- Input:
30
- 3
31
- 1
32
- 0 1
33
- 0 0
34
- 1 0
35
- 2
36
- 0 1
37
- 0 0
38
- 1 0
39
- 2
40
- 0 0
41
- 0 2
42
- 2 1
43
-
44
-
45
- Output:
46
- yes
47
- yes
48
- no
49
-
50
- ## Contest Information
51
- - **Contest ID**: 0
52
- - **Problem Index**:
53
- - **Points**: 0.0
54
- - **Rating**: 0
55
- - **Tags**: None
56
- - **Time Limit**: None seconds
57
- - **Memory Limit**: 0 bytes
58
-
59
- ## Task
60
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0002/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0002/instruction.md DELETED
@@ -1,54 +0,0 @@
1
- # gcd2
2
-
3
- ## Problem Description
4
- Frank explained its friend Felman the algorithm of Euclides to calculate the GCD
5
- of two numbers. Then Felman implements it algorithm
6
-
7
-
8
- int gcd(int a, int b)
9
- {
10
- if (b==0)
11
- return a;
12
- else
13
- return gcd(b,a%b);
14
- }
15
-
16
- and it proposes to Frank that makes it
17
- but with a little integer and another integer that has up to 250 digits.
18
- Your task is to help Frank programming an efficient code for the challenge of Felman.
19
-
20
-
21
-
22
- Input
23
- The first line of the input file contains a number representing the number of lines to follow.
24
- Each line consists of two number A and B (0 ≤ A ≤ 40000 and A ≤ B < 10^250).
25
-
26
-
27
- Output
28
- Print for each pair (A,B) in the input one integer representing the GCD of A and B.
29
-
30
-
31
-
32
- Example
33
-
34
- Input:
35
- 2
36
- 2 6
37
- 10 11
38
-
39
-
40
- Output:
41
- 2
42
- 1
43
-
44
- ## Contest Information
45
- - **Contest ID**: 0
46
- - **Problem Index**:
47
- - **Points**: 0.0
48
- - **Rating**: 0
49
- - **Tags**: None
50
- - **Time Limit**: None seconds
51
- - **Memory Limit**: 0 bytes
52
-
53
- ## Task
54
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0003/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0003/instruction.md DELETED
@@ -1,66 +0,0 @@
1
- # luckybal
2
-
3
- ## Problem Description
4
- A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.
5
- The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that the number of digits 4 in the substring T[1, X - 1] is equal to the number of digits 7 in the substring T[X, M]. For example, the string S = 7477447 is balanced since S[1, 4] = 7477 has 1 digit 4 and S[5, 7] = 447 has 1 digit 7. On the other hand, one can verify that the string S = 7 is not balanced.
6
- The Little Elephant has the string S of the length N. He wants to know the number of such pairs of integers (L; R) that 1 ≤ L ≤ R ≤ N and the substring S[L, R] is balanced. Help him to find this number.
7
- Notes.
8
-
9
- Let S be some lucky string. Then
10
-
11
-
12
- |S| denotes the length of the string S;
13
-
14
- S[i] (1 ≤ i ≤ |S|) denotes the i^th character of S (the numeration of characters starts from 1);
15
-
16
- S[L, R] (1 ≤ L ≤ R ≤ |S|) denotes the string with the following sequence of characters: S[L], S[L + 1], ..., S[R], and is called a substring of S. For L > R we mean by S[L, R] an empty string.
17
-
18
-
19
-
20
- Input
21
- The first line of the input file contains a single integer T, the number of test cases. Each of the following T lines contains one string, the string S for the corresponding test case. The input file does not contain any whitespaces.
22
-
23
- Output
24
- For each test case output a single line containing the answer for this test case.
25
-
26
-
27
- Constraints
28
- 1 ≤ T ≤ 10
29
- 1 ≤ |S| ≤ 100000
30
- S consists only of the lucky digits 4 and 7.
31
-
32
-
33
-
34
- Example
35
-
36
- Input:
37
- 4
38
- 47
39
- 74
40
- 477
41
- 4747477
42
-
43
- Output:
44
- 2
45
- 2
46
- 3
47
- 23
48
-
49
-
50
-
51
- Explanation
52
- In the first test case balance substrings are S[1, 1] = 4 and S[1, 2] = 47.
53
- In the second test case balance substrings are S[2, 2] = 4 and S[1, 2] = 74.
54
- Unfortunately, we can't provide you with the explanations of the third and the fourth test cases. You should figure it out by yourself. Please, don't ask about this in comments.
55
-
56
- ## Contest Information
57
- - **Contest ID**: 0
58
- - **Problem Index**:
59
- - **Points**: 0.0
60
- - **Rating**: 0
61
- - **Tags**: None
62
- - **Time Limit**: None seconds
63
- - **Memory Limit**: 0 bytes
64
-
65
- ## Task
66
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0005/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0005/instruction.md DELETED
@@ -1,40 +0,0 @@
1
- # tf01
2
-
3
- ## Problem Description
4
- An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K.
5
- You are a computer engineer and you claim to solve this problem given that all numbers in the set are non-negative. Given a set S of size N of non-negative integers, find whether there exists a subset whose sum is K.
6
-
7
- Input
8
- First line of input contains T, the number of test cases. T test cases follow.
9
- Each test case contains 2 lines. First line contains two integers N and K. Next line contains N space separated non-negative integers (each less than 100000).
10
- 0 < T < 1000
11
- 0 < N < 1000
12
- 0 < K < 1000
13
-
14
- Output
15
- Output T lines, one for each test case. Every line should be either 0 or 1 depending on whether such a subset exists or not.
16
-
17
- Example
18
-
19
- Input:
20
- 2
21
- 5 10
22
- 3 4 6 1 9
23
- 3 2
24
- 1 3 4
25
-
26
- Output:
27
- 1
28
- 0
29
-
30
- ## Contest Information
31
- - **Contest ID**: 0
32
- - **Problem Index**:
33
- - **Points**: 0.0
34
- - **Rating**: 0
35
- - **Tags**: None
36
- - **Time Limit**: None seconds
37
- - **Memory Limit**: 0 bytes
38
-
39
- ## Task
40
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0006/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0006/instruction.md DELETED
@@ -1,81 +0,0 @@
1
- # 1012_E. Cycle sort
2
-
3
- ## Problem Description
4
- You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., the number at the position i_k to the position i_1. In other words, the operation cyclically shifts elements: i_1 → i_2 → … i_k → i_1.
5
-
6
- For example, if you have n=4, an array a_1=10, a_2=20, a_3=30, a_4=40, and you choose three indices i_1=2, i_2=1, i_3=4, then the resulting array would become a_1=20, a_2=40, a_3=30, a_4=10.
7
-
8
- Your goal is to make the array sorted in non-decreasing order with the minimum number of operations. The additional constraint is that the sum of cycle lengths over all operations should be less than or equal to a number s. If it's impossible to sort the array while satisfying that constraint, your solution should report that as well.
9
-
10
- Input
11
-
12
- The first line of the input contains two integers n and s (1 ≤ n ≤ 200 000, 0 ≤ s ≤ 200 000)—the number of elements in the array and the upper bound on the sum of cycle lengths.
13
-
14
- The next line contains n integers a_1, a_2, ..., a_n—elements of the array (1 ≤ a_i ≤ 10^9).
15
-
16
- Output
17
-
18
- If it's impossible to sort the array using cycles of total length not exceeding s, print a single number "-1" (quotes for clarity).
19
-
20
- Otherwise, print a single number q— the minimum number of operations required to sort the array.
21
-
22
- On the next 2 ⋅ q lines print descriptions of operations in the order they are applied to the array. The description of i-th operation begins with a single line containing one integer k (1 ≤ k ≤ n)—the length of the cycle (that is, the number of selected indices). The next line should contain k distinct integers i_1, i_2, ..., i_k (1 ≤ i_j ≤ n)—the indices of the cycle.
23
-
24
- The sum of lengths of these cycles should be less than or equal to s, and the array should be sorted after applying these q operations.
25
-
26
- If there are several possible answers with the optimal q, print any of them.
27
-
28
- Examples
29
-
30
- Input
31
-
32
- 5 5
33
- 3 2 3 1 1
34
-
35
-
36
- Output
37
-
38
- 1
39
- 5
40
- 1 4 2 3 5
41
-
42
-
43
- Input
44
-
45
- 4 3
46
- 2 1 4 3
47
-
48
-
49
- Output
50
-
51
- -1
52
-
53
- Input
54
-
55
- 2 0
56
- 2 2
57
-
58
-
59
- Output
60
-
61
- 0
62
-
63
- Note
64
-
65
- In the first example, it's also possible to sort the array with two operations of total length 5: first apply the cycle 1 → 4 → 1 (of length 2), then apply the cycle 2 → 3 → 5 → 2 (of length 3). However, it would be wrong answer as you're asked to use the minimal possible number of operations, which is 1 in that case.
66
-
67
- In the second example, it's possible to the sort the array with two cycles of total length 4 (1 → 2 → 1 and 3 → 4 → 3). However, it's impossible to achieve the same using shorter cycles, which is required by s=3.
68
-
69
- In the third example, the array is already sorted, so no operations are needed. Total length of empty set of cycles is considered to be zero.
70
-
71
- ## Contest Information
72
- - **Contest ID**: 1012
73
- - **Problem Index**: E
74
- - **Points**: 2500.0
75
- - **Rating**: 3100
76
- - **Tags**: dsu, math
77
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
78
- - **Memory Limit**: 256000000 bytes
79
-
80
- ## Task
81
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0007/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0007/instruction.md DELETED
@@ -1,124 +0,0 @@
1
- # 1037_E. Trips
2
-
3
- ## Problem Description
4
- There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.
5
-
6
- We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold:
7
-
8
- * Either this person does not go on the trip,
9
- * Or at least k of his friends also go on the trip.
10
-
11
-
12
-
13
- Note that the friendship is not transitive. That is, if a and b are friends and b and c are friends, it does not necessarily imply that a and c are friends.
14
-
15
- For each day, find the maximum number of people that can go on the trip on that day.
16
-
17
- Input
18
-
19
- The first line contains three integers n, m, and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5, 1 ≤ k < n) — the number of people, the number of days and the number of friends each person on the trip should have in the group.
20
-
21
- The i-th (1 ≤ i ≤ m) of the next m lines contains two integers x and y (1≤ x, y≤ n, x≠ y), meaning that persons x and y become friends on the morning of day i. It is guaranteed that x and y were not friends before.
22
-
23
- Output
24
-
25
- Print exactly m lines, where the i-th of them (1≤ i≤ m) contains the maximum number of people that can go on the trip on the evening of the day i.
26
-
27
- Examples
28
-
29
- Input
30
-
31
- 4 4 2
32
- 2 3
33
- 1 2
34
- 1 3
35
- 1 4
36
-
37
-
38
- Output
39
-
40
- 0
41
- 0
42
- 3
43
- 3
44
-
45
-
46
- Input
47
-
48
- 5 8 2
49
- 2 1
50
- 4 2
51
- 5 4
52
- 5 2
53
- 4 3
54
- 5 1
55
- 4 1
56
- 3 2
57
-
58
-
59
- Output
60
-
61
- 0
62
- 0
63
- 0
64
- 3
65
- 3
66
- 4
67
- 4
68
- 5
69
-
70
-
71
- Input
72
-
73
- 5 7 2
74
- 1 5
75
- 3 2
76
- 2 5
77
- 3 4
78
- 1 2
79
- 5 3
80
- 1 3
81
-
82
-
83
- Output
84
-
85
- 0
86
- 0
87
- 0
88
- 0
89
- 3
90
- 4
91
- 4
92
-
93
- Note
94
-
95
- In the first example,
96
-
97
- * 1,2,3 can go on day 3 and 4.
98
-
99
-
100
-
101
- In the second example,
102
-
103
- * 2,4,5 can go on day 4 and 5.
104
- * 1,2,4,5 can go on day 6 and 7.
105
- * 1,2,3,4,5 can go on day 8.
106
-
107
-
108
-
109
- In the third example,
110
-
111
- * 1,2,5 can go on day 5.
112
- * 1,2,3,5 can go on day 6 and 7.
113
-
114
- ## Contest Information
115
- - **Contest ID**: 1037
116
- - **Problem Index**: E
117
- - **Points**: 2250.0
118
- - **Rating**: 2200
119
- - **Tags**: graphs
120
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
121
- - **Memory Limit**: 256000000 bytes
122
-
123
- ## Task
124
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0008/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0008/instruction.md DELETED
@@ -1,72 +0,0 @@
1
- # 1060_A. Phone Numbers
2
-
3
- ## Problem Description
4
- Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
5
-
6
- For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
7
-
8
- You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
9
-
10
- Input
11
-
12
- The first line contains an integer n — the number of cards with digits that you have (1 ≤ n ≤ 100).
13
-
14
- The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, …, s_n. The string will not contain any other characters, such as leading or trailing spaces.
15
-
16
- Output
17
-
18
- If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
19
-
20
- Examples
21
-
22
- Input
23
-
24
- 11
25
- 00000000008
26
-
27
-
28
- Output
29
-
30
- 1
31
-
32
-
33
- Input
34
-
35
- 22
36
- 0011223344556677889988
37
-
38
-
39
- Output
40
-
41
- 2
42
-
43
-
44
- Input
45
-
46
- 11
47
- 31415926535
48
-
49
-
50
- Output
51
-
52
- 0
53
-
54
- Note
55
-
56
- In the first example, one phone number, "8000000000", can be made from these cards.
57
-
58
- In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
59
-
60
- In the third example you can't make any phone number from the given cards.
61
-
62
- ## Contest Information
63
- - **Contest ID**: 1060
64
- - **Problem Index**: A
65
- - **Points**: 500.0
66
- - **Rating**: 800
67
- - **Tags**: brute force
68
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
69
- - **Memory Limit**: 512000000 bytes
70
-
71
- ## Task
72
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0010/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0010/instruction.md DELETED
@@ -1,54 +0,0 @@
1
- # 1101_A. Minimum Integer
2
-
3
- ## Problem Description
4
- You are given q queries in the following form:
5
-
6
- Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
7
-
8
- Can you answer all the queries?
9
-
10
- Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
11
-
12
- Input
13
-
14
- The first line contains one integer q (1 ≤ q ≤ 500) — the number of queries.
15
-
16
- Then q lines follow, each containing a query given in the format l_i r_i d_i (1 ≤ l_i ≤ r_i ≤ 10^9, 1 ≤ d_i ≤ 10^9). l_i, r_i and d_i are integers.
17
-
18
- Output
19
-
20
- For each query print one integer: the answer to this query.
21
-
22
- Example
23
-
24
- Input
25
-
26
-
27
- 5
28
- 2 4 2
29
- 5 10 4
30
- 3 10 1
31
- 1 2 3
32
- 4 6 5
33
-
34
-
35
- Output
36
-
37
-
38
- 6
39
- 4
40
- 1
41
- 3
42
- 10
43
-
44
- ## Contest Information
45
- - **Contest ID**: 1101
46
- - **Problem Index**: A
47
- - **Points**: 0.0
48
- - **Rating**: 1000
49
- - **Tags**: math
50
- - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
51
- - **Memory Limit**: 256000000 bytes
52
-
53
- ## Task
54
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0011/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0011/instruction.md DELETED
@@ -1,80 +0,0 @@
1
- # 1129_D. Isolation
2
-
3
- ## Problem Description
4
- Find the number of ways to divide an array a of n integers into any number of disjoint non-empty segments so that, in each segment, there exist at most k distinct integers that appear exactly once.
5
-
6
- Since the answer can be large, find it modulo 998 244 353.
7
-
8
- Input
9
-
10
- The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 10^5) — the number of elements in the array a and the restriction from the statement.
11
-
12
- The following line contains n space-separated integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — elements of the array a.
13
-
14
- Output
15
-
16
- The first and only line contains the number of ways to divide an array a modulo 998 244 353.
17
-
18
- Examples
19
-
20
- Input
21
-
22
-
23
- 3 1
24
- 1 1 2
25
-
26
-
27
- Output
28
-
29
-
30
- 3
31
-
32
-
33
- Input
34
-
35
-
36
- 5 2
37
- 1 1 2 1 3
38
-
39
-
40
- Output
41
-
42
-
43
- 14
44
-
45
-
46
- Input
47
-
48
-
49
- 5 5
50
- 1 2 3 4 5
51
-
52
-
53
- Output
54
-
55
-
56
- 16
57
-
58
- Note
59
-
60
- In the first sample, the three possible divisions are as follows.
61
-
62
- * [[1], [1], [2]]
63
- * [[1, 1], [2]]
64
- * [[1, 1, 2]]
65
-
66
-
67
-
68
- Division [[1], [1, 2]] is not possible because two distinct integers appear exactly once in the second segment [1, 2].
69
-
70
- ## Contest Information
71
- - **Contest ID**: 1129
72
- - **Problem Index**: D
73
- - **Points**: 2250.0
74
- - **Rating**: 2900
75
- - **Tags**: data structures, dp
76
- - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
77
- - **Memory Limit**: 256000000 bytes
78
-
79
- ## Task
80
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0012/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0012/instruction.md DELETED
@@ -1,112 +0,0 @@
1
- # 1149_E. Election Promises
2
-
3
- ## Problem Description
4
- In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes.
5
-
6
- There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax.
7
-
8
- Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles.
9
-
10
- The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves?
11
-
12
- Input
13
-
14
- The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland.
15
-
16
- The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city.
17
-
18
- Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities.
19
-
20
- We can show that the conventions cannot be held indefinitely for any correct test case.
21
-
22
- Output
23
-
24
- If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles.
25
-
26
- If the party cannot assure their victory, output LOSE in the first and only line of the output.
27
-
28
- Examples
29
-
30
- Input
31
-
32
-
33
- 4 2
34
- 2 1 1 5
35
- 1 2
36
- 3 4
37
-
38
-
39
- Output
40
-
41
-
42
- WIN
43
- 1 5 1 5
44
-
45
-
46
- Input
47
-
48
-
49
- 4 2
50
- 1 5 1 5
51
- 1 2
52
- 3 4
53
-
54
-
55
- Output
56
-
57
-
58
- LOSE
59
-
60
-
61
- Input
62
-
63
-
64
- 3 3
65
- 314 159 265
66
- 1 2
67
- 1 3
68
- 3 2
69
-
70
-
71
- Output
72
-
73
-
74
- WIN
75
- 0 0 0
76
-
77
-
78
- Input
79
-
80
-
81
- 6 4
82
- 2 2 5 5 6 6
83
- 1 3
84
- 2 4
85
- 3 5
86
- 4 6
87
-
88
-
89
- Output
90
-
91
-
92
- LOSE
93
-
94
- Note
95
-
96
- In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally.
97
-
98
- The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win.
99
-
100
- In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
101
-
102
- ## Contest Information
103
- - **Contest ID**: 1149
104
- - **Problem Index**: E
105
- - **Points**: 2750.0
106
- - **Rating**: 3200
107
- - **Tags**: games, graphs
108
- - **Time Limit**: {'seconds': 2, '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-0015/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0015/instruction.md DELETED
@@ -1,82 +0,0 @@
1
- # 1208_D. Restore Permutation
2
-
3
- ## Problem Description
4
- An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4].
5
-
6
- There is a hidden permutation of length n.
7
-
8
- For each index i, you are given s_{i}, which equals to the sum of all p_{j} such that j < i and p_{j} < p_{i}. In other words, s_i is the sum of elements before the i-th element that are smaller than the i-th element.
9
-
10
- Your task is to restore the permutation.
11
-
12
- Input
13
-
14
- The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the size of the permutation.
15
-
16
- The second line contains n integers s_{1}, s_{2}, …, s_{n} (0 ≤ s_{i} ≤ (n(n-1))/(2)).
17
-
18
- It is guaranteed that the array s corresponds to a valid permutation of length n.
19
-
20
- Output
21
-
22
- Print n integers p_{1}, p_{2}, …, p_{n} — the elements of the restored permutation. We can show that the answer is always unique.
23
-
24
- Examples
25
-
26
- Input
27
-
28
-
29
- 3
30
- 0 0 0
31
-
32
-
33
- Output
34
-
35
-
36
- 3 2 1
37
-
38
-
39
- Input
40
-
41
-
42
- 2
43
- 0 1
44
-
45
-
46
- Output
47
-
48
-
49
- 1 2
50
-
51
-
52
- Input
53
-
54
-
55
- 5
56
- 0 1 1 1 10
57
-
58
-
59
- Output
60
-
61
-
62
- 1 4 3 2 5
63
-
64
- Note
65
-
66
- In the first example for each i there is no index j satisfying both conditions, hence s_i are always 0.
67
-
68
- In the second example for i = 2 it happens that j = 1 satisfies the conditions, so s_2 = p_1.
69
-
70
- In the third example for i = 2, 3, 4 only j = 1 satisfies the conditions, so s_2 = s_3 = s_4 = 1. For i = 5 all j = 1, 2, 3, 4 are possible, so s_5 = p_1 + p_2 + p_3 + p_4 = 10.
71
-
72
- ## Contest Information
73
- - **Contest ID**: 1208
74
- - **Problem Index**: D
75
- - **Points**: 2000.0
76
- - **Rating**: 1900
77
- - **Tags**: binary search, data structures, greedy, implementation
78
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
79
- - **Memory Limit**: 256000000 bytes
80
-
81
- ## Task
82
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0016/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0016/instruction.md DELETED
@@ -1,121 +0,0 @@
1
- # 1227_D1. Optimal Subsequences (Easy Version)
2
-
3
- ## Problem Description
4
- This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.
5
-
6
- You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily go consecutively). For example, for the sequence a=[11,20,11,33,11,20,11]:
7
-
8
- * [11,20,11,33,11,20,11], [11,20,11,33,11,20], [11,11,11,11], [20], [33,20] are subsequences (these are just some of the long list);
9
- * [40], [33,33], [33,20,20], [20,20,11,11] are not subsequences.
10
-
11
-
12
-
13
- Suppose that an additional non-negative integer k (1 ≤ k ≤ n) is given, then the subsequence is called optimal if:
14
-
15
- * it has a length of k and the sum of its elements is the maximum possible among all subsequences of length k;
16
- * and among all subsequences of length k that satisfy the previous item, it is lexicographically minimal.
17
-
18
-
19
-
20
- Recall that the sequence b=[b_1, b_2, ..., b_k] is lexicographically smaller than the sequence c=[c_1, c_2, ..., c_k] if the first element (from the left) in which they differ less in the sequence b than in c. Formally: there exists t (1 ≤ t ≤ k) such that b_1=c_1, b_2=c_2, ..., b_{t-1}=c_{t-1} and at the same time b_t<c_t. For example:
21
-
22
- * [10, 20, 20] lexicographically less than [10, 21, 1],
23
- * [7, 99, 99] is lexicographically less than [10, 21, 1],
24
- * [10, 21, 0] is lexicographically less than [10, 21, 1].
25
-
26
-
27
-
28
- You are given a sequence of a=[a_1,a_2,...,a_n] and m requests, each consisting of two numbers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j). For each query, print the value that is in the index pos_j of the optimal subsequence of the given sequence a for k=k_j.
29
-
30
- For example, if n=4, a=[10,20,30,20], k_j=2, then the optimal subsequence is [20,30] — it is the minimum lexicographically among all subsequences of length 2 with the maximum total sum of items. Thus, the answer to the request k_j=2, pos_j=1 is the number 20, and the answer to the request k_j=2, pos_j=2 is the number 30.
31
-
32
- Input
33
-
34
- The first line contains an integer n (1 ≤ n ≤ 100) — the length of the sequence a.
35
-
36
- The second line contains elements of the sequence a: integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
37
-
38
- The third line contains an integer m (1 ≤ m ≤ 100) — the number of requests.
39
-
40
- The following m lines contain pairs of integers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j) — the requests.
41
-
42
- Output
43
-
44
- Print m integers r_1, r_2, ..., r_m (1 ≤ r_j ≤ 10^9) one per line: answers to the requests in the order they appear in the input. The value of r_j should be equal to the value contained in the position pos_j of the optimal subsequence for k=k_j.
45
-
46
- Examples
47
-
48
- Input
49
-
50
-
51
- 3
52
- 10 20 10
53
- 6
54
- 1 1
55
- 2 1
56
- 2 2
57
- 3 1
58
- 3 2
59
- 3 3
60
-
61
-
62
- Output
63
-
64
-
65
- 20
66
- 10
67
- 20
68
- 10
69
- 20
70
- 10
71
-
72
-
73
- Input
74
-
75
-
76
- 7
77
- 1 2 1 3 1 2 1
78
- 9
79
- 2 1
80
- 2 2
81
- 3 1
82
- 3 2
83
- 3 3
84
- 1 1
85
- 7 1
86
- 7 7
87
- 7 4
88
-
89
-
90
- Output
91
-
92
-
93
- 2
94
- 3
95
- 2
96
- 3
97
- 2
98
- 3
99
- 1
100
- 1
101
- 3
102
-
103
- Note
104
-
105
- In the first example, for a=[10,20,10] the optimal subsequences are:
106
-
107
- * for k=1: [20],
108
- * for k=2: [10,20],
109
- * for k=3: [10,20,10].
110
-
111
- ## Contest Information
112
- - **Contest ID**: 1227
113
- - **Problem Index**: D1
114
- - **Points**: 500.0
115
- - **Rating**: 1600
116
- - **Tags**: data structures, greedy
117
- - **Time Limit**: {'seconds': 3, '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-0017/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0017/instruction.md DELETED
@@ -1,70 +0,0 @@
1
- # 1250_B. The Feast and the Bus
2
-
3
- ## Problem Description
4
- Employees of JebTrains are on their way to celebrate the 256-th day of the year! There are n employees and k teams in JebTrains. Each employee is a member of some (exactly one) team. All teams are numbered from 1 to k. You are given an array of numbers t_1, t_2, ..., t_n where t_i is the i-th employee's team number.
5
-
6
- JebTrains is going to rent a single bus to get employees to the feast. The bus will take one or more rides. A bus can pick up an entire team or two entire teams. If three or more teams take a ride together they may start a new project which is considered unacceptable. It's prohibited to split a team, so all members of a team should take the same ride.
7
-
8
- It is possible to rent a bus of any capacity s. Such a bus can take up to s people on a single ride. The total cost of the rent is equal to s ⋅ r burles where r is the number of rides. Note that it's impossible to rent two or more buses.
9
-
10
- Help JebTrains to calculate the minimum cost of the rent, required to get all employees to the feast, fulfilling all the conditions above.
11
-
12
- Input
13
-
14
- The first line contains two integers n and k (1 ≤ n ≤ 5⋅10^5, 1 ≤ k ≤ 8000) — the number of employees and the number of teams in JebTrains. The second line contains a sequence of integers t_1, t_2, ..., t_n, where t_i (1 ≤ t_i ≤ k) is the i-th employee's team number. Every team contains at least one employee.
15
-
16
- Output
17
-
18
- Print the minimum cost of the rent.
19
-
20
- Examples
21
-
22
- Input
23
-
24
-
25
- 6 3
26
- 3 1 2 3 2 3
27
-
28
-
29
- Output
30
-
31
-
32
- 6
33
-
34
-
35
- Input
36
-
37
-
38
- 10 1
39
- 1 1 1 1 1 1 1 1 1 1
40
-
41
-
42
- Output
43
-
44
-
45
- 10
46
-
47
-
48
- Input
49
-
50
-
51
- 12 4
52
- 1 2 3 1 2 3 4 1 2 1 2 1
53
-
54
-
55
- Output
56
-
57
-
58
- 12
59
-
60
- ## Contest Information
61
- - **Contest ID**: 1250
62
- - **Problem Index**: B
63
- - **Points**: 0.0
64
- - **Rating**: 1800
65
- - **Tags**: brute force, constructive algorithms, greedy, math
66
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
67
- - **Memory Limit**: 512000000 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-0018/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0018/instruction.md DELETED
@@ -1,61 +0,0 @@
1
- # 1269_E. K Integers
2
-
3
- ## Problem Description
4
- You are given a permutation p_1, p_2, …, p_n.
5
-
6
- In one move you can swap two adjacent values.
7
-
8
- You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k.
9
-
10
- Let f(k) be the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation.
11
-
12
- You need to find f(1), f(2), …, f(n).
13
-
14
- Input
15
-
16
- The first line of input contains one integer n (1 ≤ n ≤ 200 000): the number of elements in the permutation.
17
-
18
- The next line of input contains n integers p_1, p_2, …, p_n: given permutation (1 ≤ p_i ≤ n).
19
-
20
- Output
21
-
22
- Print n integers, the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation, for k=1, 2, …, n.
23
-
24
- Examples
25
-
26
- Input
27
-
28
-
29
- 5
30
- 5 4 3 2 1
31
-
32
-
33
- Output
34
-
35
-
36
- 0 1 3 6 10
37
-
38
-
39
- Input
40
-
41
-
42
- 3
43
- 1 2 3
44
-
45
-
46
- Output
47
-
48
-
49
- 0 0 0
50
-
51
- ## Contest Information
52
- - **Contest ID**: 1269
53
- - **Problem Index**: E
54
- - **Points**: 1500.0
55
- - **Rating**: 2300
56
- - **Tags**: binary search, data structures
57
- - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
58
- - **Memory Limit**: 256000000 bytes
59
-
60
- ## Task
61
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0019/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0019/instruction.md DELETED
@@ -1,182 +0,0 @@
1
- # 1291_E. Prefix Enlightenment
2
-
3
- ## Problem Description
4
- There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1).
5
-
6
- You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅.
7
-
8
- In one operation, you can choose one of these k subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation.
9
-
10
- Let m_i be the minimum number of operations you have to do in order to make the i first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between i+1 and n), they can be either off or on.
11
-
12
- You have to compute m_i for all 1 ≤ i ≤ n.
13
-
14
- Input
15
-
16
- The first line contains two integers n and k (1 ≤ n, k ≤ 3 ⋅ 10^5).
17
-
18
- The second line contains a binary string of length n, representing the initial state of each lamp (the lamp i is off if s_i = 0, on if s_i = 1).
19
-
20
- The description of each one of the k subsets follows, in the following format:
21
-
22
- The first line of the description contains a single integer c (1 ≤ c ≤ n) — the number of elements in the subset.
23
-
24
- The second line of the description contains c distinct integers x_1, …, x_c (1 ≤ x_i ≤ n) — the elements of the subset.
25
-
26
- It is guaranteed that:
27
-
28
- * The intersection of any three subsets is empty;
29
- * It's possible to make all lamps be simultaneously on using some operations.
30
-
31
- Output
32
-
33
- You must output n lines. The i-th line should contain a single integer m_i — the minimum number of operations required to make the lamps 1 to i be simultaneously on.
34
-
35
- Examples
36
-
37
- Input
38
-
39
-
40
- 7 3
41
- 0011100
42
- 3
43
- 1 4 6
44
- 3
45
- 3 4 7
46
- 2
47
- 2 3
48
-
49
-
50
- Output
51
-
52
-
53
- 1
54
- 2
55
- 3
56
- 3
57
- 3
58
- 3
59
- 3
60
-
61
-
62
- Input
63
-
64
-
65
- 8 6
66
- 00110011
67
- 3
68
- 1 3 8
69
- 5
70
- 1 2 5 6 7
71
- 2
72
- 6 8
73
- 2
74
- 3 5
75
- 2
76
- 4 7
77
- 1
78
- 2
79
-
80
-
81
- Output
82
-
83
-
84
- 1
85
- 1
86
- 1
87
- 1
88
- 1
89
- 1
90
- 4
91
- 4
92
-
93
-
94
- Input
95
-
96
-
97
- 5 3
98
- 00011
99
- 3
100
- 1 2 3
101
- 1
102
- 4
103
- 3
104
- 3 4 5
105
-
106
-
107
- Output
108
-
109
-
110
- 1
111
- 1
112
- 1
113
- 1
114
- 1
115
-
116
-
117
- Input
118
-
119
-
120
- 19 5
121
- 1001001001100000110
122
- 2
123
- 2 3
124
- 2
125
- 5 6
126
- 2
127
- 8 9
128
- 5
129
- 12 13 14 15 16
130
- 1
131
- 19
132
-
133
-
134
- Output
135
-
136
-
137
- 0
138
- 1
139
- 1
140
- 1
141
- 2
142
- 2
143
- 2
144
- 3
145
- 3
146
- 3
147
- 3
148
- 4
149
- 4
150
- 4
151
- 4
152
- 4
153
- 4
154
- 4
155
- 5
156
-
157
- Note
158
-
159
- In the first example:
160
-
161
- * For i = 1, we can just apply one operation on A_1, the final states will be 1010110;
162
- * For i = 2, we can apply operations on A_1 and A_3, the final states will be 1100110;
163
- * For i ≥ 3, we can apply operations on A_1, A_2 and A_3, the final states will be 1111111.
164
-
165
-
166
-
167
- In the second example:
168
-
169
- * For i ≤ 6, we can just apply one operation on A_2, the final states will be 11111101;
170
- * For i ≥ 7, we can apply operations on A_1, A_3, A_4, A_6, the final states will be 11111111.
171
-
172
- ## Contest Information
173
- - **Contest ID**: 1291
174
- - **Problem Index**: E
175
- - **Points**: 1750.0
176
- - **Rating**: 2400
177
- - **Tags**: dfs and similar, dsu, graphs
178
- - **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
179
- - **Memory Limit**: 256000000 bytes
180
-
181
- ## Task
182
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0020/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0020/instruction.md DELETED
@@ -1,75 +0,0 @@
1
- # 1311_F. Moving Points
2
-
3
- ## Problem Description
4
- There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ⋅ v_i.
5
-
6
- Consider two points i and j. Let d(i, j) be the minimum possible distance between these two points over any possible moments of time (even non-integer). It means that if two points i and j coincide at some moment, the value d(i, j) will be 0.
7
-
8
- Your task is to calculate the value ∑_{1 ≤ i < j ≤ n} d(i, j) (the sum of minimum distances over all pairs of points).
9
-
10
- Input
11
-
12
- The first line of the input contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of points.
13
-
14
- The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^8), where x_i is the initial coordinate of the i-th point. It is guaranteed that all x_i are distinct.
15
-
16
- The third line of the input contains n integers v_1, v_2, ..., v_n (-10^8 ≤ v_i ≤ 10^8), where v_i is the speed of the i-th point.
17
-
18
- Output
19
-
20
- Print one integer — the value ∑_{1 ≤ i < j ≤ n} d(i, j) (the sum of minimum distances over all pairs of points).
21
-
22
- Examples
23
-
24
- Input
25
-
26
-
27
- 3
28
- 1 3 2
29
- -100 2 3
30
-
31
-
32
- Output
33
-
34
-
35
- 3
36
-
37
-
38
- Input
39
-
40
-
41
- 5
42
- 2 1 4 3 5
43
- 2 2 2 3 4
44
-
45
-
46
- Output
47
-
48
-
49
- 19
50
-
51
-
52
- Input
53
-
54
-
55
- 2
56
- 2 1
57
- -3 0
58
-
59
-
60
- Output
61
-
62
-
63
- 0
64
-
65
- ## Contest Information
66
- - **Contest ID**: 1311
67
- - **Problem Index**: F
68
- - **Points**: 0.0
69
- - **Rating**: 1900
70
- - **Tags**: data structures, divide and conquer, implementation, sortings
71
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
72
- - **Memory Limit**: 256000000 bytes
73
-
74
- ## Task
75
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0021/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0021/instruction.md DELETED
@@ -1,60 +0,0 @@
1
- # 1334_D. Minimum Euler Cycle
2
-
3
- ## Problem Description
4
- You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
5
-
6
- You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
7
-
8
- We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 — a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
9
-
10
- Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
11
-
12
- Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
13
-
14
- Input
15
-
16
- The first line contains the single integer T (1 ≤ T ≤ 100) — the number of test cases.
17
-
18
- Next T lines contain test cases — one per line. The first and only line of each test case contains three integers n, l and r (2 ≤ n ≤ 10^5, 1 ≤ l ≤ r ≤ n(n - 1) + 1, r - l + 1 ≤ 10^5) — the number of vertices in K_n, and segment of the cycle to print.
19
-
20
- It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
21
-
22
- Output
23
-
24
- For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
25
-
26
- Example
27
-
28
- Input
29
-
30
-
31
- 3
32
- 2 1 3
33
- 3 3 6
34
- 99995 9998900031 9998900031
35
-
36
-
37
- Output
38
-
39
-
40
- 1 2 1
41
- 1 3 2 3
42
- 1
43
-
44
- Note
45
-
46
- In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
47
-
48
- In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
49
-
50
- ## Contest Information
51
- - **Contest ID**: 1334
52
- - **Problem Index**: D
53
- - **Points**: 0.0
54
- - **Rating**: 1800
55
- - **Tags**: constructive algorithms, graphs, greedy, implementation
56
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
57
- - **Memory Limit**: 256000000 bytes
58
-
59
- ## Task
60
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0023/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0023/instruction.md DELETED
@@ -1,94 +0,0 @@
1
- # 1374_E1. Reading Books (easy version)
2
-
3
- ## Problem Description
4
- Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.
5
-
6
- Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster.
7
-
8
- There are n books in the family library. The i-th book is described by three integers: t_i — the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not).
9
-
10
- So they need to choose some books from the given n books in such a way that:
11
-
12
- * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set;
13
- * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible).
14
-
15
-
16
-
17
- The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set.
18
-
19
- Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set.
20
-
21
- Input
22
-
23
- The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5).
24
-
25
- The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≤ t_i ≤ 10^4, 0 ≤ a_i, b_i ≤ 1), where:
26
-
27
- * t_i — the amount of time required for reading the i-th book;
28
- * a_i equals 1 if Alice likes the i-th book and 0 otherwise;
29
- * b_i equals 1 if Bob likes the i-th book and 0 otherwise.
30
-
31
- Output
32
-
33
- If there is no solution, print only one integer -1. Otherwise print one integer T — the minimum total reading time of the suitable set of books.
34
-
35
- Examples
36
-
37
- Input
38
-
39
- 8 4
40
- 7 1 1
41
- 2 1 1
42
- 4 0 1
43
- 8 1 1
44
- 1 0 1
45
- 1 1 1
46
- 1 0 1
47
- 3 0 0
48
-
49
-
50
- Output
51
-
52
- 18
53
-
54
-
55
- Input
56
-
57
- 5 2
58
- 6 0 0
59
- 9 0 0
60
- 1 0 1
61
- 2 1 1
62
- 5 1 0
63
-
64
-
65
- Output
66
-
67
- 8
68
-
69
-
70
- Input
71
-
72
- 5 3
73
- 3 0 0
74
- 2 1 0
75
- 3 1 0
76
- 5 0 1
77
- 3 0 1
78
-
79
-
80
- Output
81
-
82
- -1
83
-
84
- ## Contest Information
85
- - **Contest ID**: 1374
86
- - **Problem Index**: E1
87
- - **Points**: 0.0
88
- - **Rating**: 1600
89
- - **Tags**: data structures, greedy, sortings
90
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
91
- - **Memory Limit**: 256000000 bytes
92
-
93
- ## Task
94
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0024/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0024/instruction.md DELETED
@@ -1,63 +0,0 @@
1
- # 1398_A. Bad Triangle
2
-
3
- ## Problem Description
4
- You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}).
5
-
6
- Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it.
7
-
8
- Input
9
-
10
- The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
11
-
12
- The first line of each test case contains one integer n (3 ≤ n ≤ 5 ⋅ 10^4) — the length of the array a.
13
-
14
- The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ 10^9; a_{i - 1} ≤ a_i) — the array a.
15
-
16
- It is guaranteed that the sum of n over all test cases does not exceed 10^5.
17
-
18
- Output
19
-
20
- For each test case print the answer to it in one line.
21
-
22
- If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them.
23
-
24
- Otherwise, print -1.
25
-
26
- Example
27
-
28
- Input
29
-
30
-
31
- 3
32
- 7
33
- 4 6 11 11 15 18 20
34
- 4
35
- 10 10 10 11
36
- 3
37
- 1 1 1000000000
38
-
39
-
40
- Output
41
-
42
-
43
- 2 3 6
44
- -1
45
- 1 2 3
46
-
47
- Note
48
-
49
- In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer.
50
-
51
- In the second test case you always can construct a non-degenerate triangle.
52
-
53
- ## Contest Information
54
- - **Contest ID**: 1398
55
- - **Problem Index**: A
56
- - **Points**: 0.0
57
- - **Rating**: 800
58
- - **Tags**: geometry, math
59
- - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
60
- - **Memory Limit**: 256000000 bytes
61
-
62
- ## Task
63
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0025/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0025/instruction.md DELETED
@@ -1,89 +0,0 @@
1
- # 1421_B. Putting Bricks in the Wall
2
-
3
- ## Problem Description
4
- Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
5
-
6
- Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
7
-
8
- Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
9
-
10
- For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
11
-
12
- The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
13
-
14
- We can show that there always exists a solution for the given constraints.
15
-
16
- Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
17
-
18
- Input
19
-
20
- Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
21
-
22
- The first line of each test case contains one integers n (3 ≤ n ≤ 200).
23
-
24
- The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
25
-
26
- The sum of values of n doesn't exceed 200.
27
-
28
- Output
29
-
30
- For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
31
-
32
- In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
33
-
34
- Example
35
-
36
- Input
37
-
38
-
39
- 3
40
- 4
41
- S010
42
- 0001
43
- 1000
44
- 111F
45
- 3
46
- S10
47
- 101
48
- 01F
49
- 5
50
- S0101
51
- 00000
52
- 01111
53
- 11111
54
- 0001F
55
-
56
-
57
- Output
58
-
59
-
60
- 1
61
- 3 4
62
- 2
63
- 1 2
64
- 2 1
65
- 0
66
-
67
- Note
68
-
69
- For the first test case, after inverting the cell, we get the following grid:
70
-
71
-
72
-
73
- S010
74
- 0001
75
- 1001
76
- 111F
77
-
78
-
79
- ## Contest Information
80
- - **Contest ID**: 1421
81
- - **Problem Index**: B
82
- - **Points**: 1000.0
83
- - **Rating**: 1100
84
- - **Tags**: constructive algorithms, implementation
85
- - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
86
- - **Memory Limit**: 256000000 bytes
87
-
88
- ## Task
89
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0026/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0026/instruction.md DELETED
@@ -1,93 +0,0 @@
1
- # 143_A. Help Vasilisa the Wise 2
2
-
3
- ## Problem Description
4
- Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
5
-
6
- The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
7
-
8
- <image>
9
-
10
- The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
11
-
12
- <image>
13
-
14
- Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
15
-
16
- Input
17
-
18
- The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ r1, r2, c1, c2, d1, d2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
19
-
20
- <image>
21
-
22
- Output
23
-
24
- Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
25
-
26
- If there are several solutions, output any.
27
-
28
- Examples
29
-
30
- Input
31
-
32
- 3 7
33
- 4 6
34
- 5 5
35
-
36
-
37
- Output
38
-
39
- 1 2
40
- 3 4
41
-
42
-
43
- Input
44
-
45
- 11 10
46
- 13 8
47
- 5 16
48
-
49
-
50
- Output
51
-
52
- 4 7
53
- 9 1
54
-
55
-
56
- Input
57
-
58
- 1 2
59
- 3 4
60
- 5 6
61
-
62
-
63
- Output
64
-
65
- -1
66
-
67
-
68
- Input
69
-
70
- 10 10
71
- 10 10
72
- 10 10
73
-
74
-
75
- Output
76
-
77
- -1
78
-
79
- Note
80
-
81
- Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
82
-
83
- ## Contest Information
84
- - **Contest ID**: 143
85
- - **Problem Index**: A
86
- - **Points**: 500.0
87
- - **Rating**: 1000
88
- - **Tags**: brute force, math
89
- - **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
90
- - **Memory Limit**: 256000000 bytes
91
-
92
- ## Task
93
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0027/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0027/instruction.md DELETED
@@ -1,112 +0,0 @@
1
- # 1466_F. Euclid's nightmare
2
-
3
- ## Problem Description
4
- You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
5
-
6
- In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
7
-
8
- Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
9
-
10
- Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
11
-
12
- Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
13
-
14
- Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
15
-
16
- Input
17
-
18
- In the first line of input, there are two integers n, m (1 ≤ n, m ≤ 5 ⋅ 10^5) denoting the number of vectors in S and the number of dimensions.
19
-
20
- Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 ≤ k ≤ 2) and then follow k distinct integers x_1, ... x_k (1 ≤ x_i ≤ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
21
-
22
- Among the n vectors, no two are the same.
23
-
24
- Output
25
-
26
- In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
27
-
28
- Examples
29
-
30
- Input
31
-
32
-
33
- 3 2
34
- 1 1
35
- 1 2
36
- 2 2 1
37
-
38
-
39
- Output
40
-
41
-
42
- 4 2
43
- 1 2
44
-
45
-
46
- Input
47
-
48
-
49
- 2 3
50
- 2 1 3
51
- 2 1 2
52
-
53
-
54
- Output
55
-
56
-
57
- 4 2
58
- 1 2
59
-
60
-
61
- Input
62
-
63
-
64
- 3 5
65
- 2 1 2
66
- 1 3
67
- 1 4
68
-
69
-
70
- Output
71
-
72
-
73
- 8 3
74
- 1 2 3
75
-
76
- Note
77
-
78
- In the first example we are given three vectors:
79
-
80
- * 10
81
- * 01
82
- * 11
83
-
84
-
85
-
86
- It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
87
-
88
- * 00 is a sum of the empty subset of above vectors;
89
- * 01 = 11 + 10, is a sum of the first and third vector;
90
- * 10 = 10, is just the first vector;
91
- * 11 = 10 + 01, is a sum of the first and the second vector.
92
-
93
-
94
-
95
- Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
96
-
97
- * 00 is a sum of the empty subset;
98
- * 01 = 01 is just the second vector;
99
- * 10 = 10 is just the first vector;
100
- * 11 = 10 + 01 is a sum of the first and the second vector.
101
-
102
- ## Contest Information
103
- - **Contest ID**: 1466
104
- - **Problem Index**: F
105
- - **Points**: 1750.0
106
- - **Rating**: 2100
107
- - **Tags**: bitmasks, dfs and similar, dsu, graphs, greedy, math, sortings
108
- - **Time Limit**: {'seconds': 2, '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-0029/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0029/instruction.md DELETED
@@ -1,62 +0,0 @@
1
- # 1513_C. Add One
2
-
3
- ## Problem Description
4
- You are given an integer n. You have to apply m operations to it.
5
-
6
- In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
7
-
8
- You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
9
-
10
- Input
11
-
12
- The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — the number of test cases.
13
-
14
- The only line of each test case contains two integers n (1 ≤ n ≤ 10^9) and m (1 ≤ m ≤ 2 ⋅ 10^5) — the initial number and the number of operations.
15
-
16
- Output
17
-
18
- For each test case output the length of the resulting number modulo 10^9+7.
19
-
20
- Example
21
-
22
- Input
23
-
24
-
25
- 5
26
- 1912 1
27
- 5 6
28
- 999 1
29
- 88 2
30
- 12 100
31
-
32
-
33
- Output
34
-
35
-
36
- 5
37
- 2
38
- 6
39
- 4
40
- 2115
41
-
42
- Note
43
-
44
- For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
45
-
46
- For the second test, 5 becomes 21 after 6 operations which is of length 2.
47
-
48
- For the third test, 999 becomes 101010 after 1 operation which is of length 6.
49
-
50
- For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
51
-
52
- ## Contest Information
53
- - **Contest ID**: 1513
54
- - **Problem Index**: C
55
- - **Points**: 1500.0
56
- - **Rating**: 1600
57
- - **Tags**: dp, matrices
58
- - **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
59
- - **Memory Limit**: 256000000 bytes
60
-
61
- ## Task
62
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code_contests-0030/environment/Dockerfile DELETED
@@ -1,5 +0,0 @@
1
- FROM ubuntu:24.04
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
code_contests-0030/instruction.md DELETED
@@ -1,79 +0,0 @@
1
- # 1540_C1. Converging Array (Easy Version)
2
-
3
- ## Problem Description
4
- This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
5
-
6
- There is a process that takes place on arrays a and b of length n and length n-1 respectively.
7
-
8
- The process is an infinite sequence of operations. Each operation is as follows:
9
-
10
- * First, choose a random integer i (1 ≤ i ≤ n-1).
11
- * Then, simultaneously set a_i = min\left(a_i, \frac{a_i+a_{i+1}-b_i}{2}\right) and a_{i+1} = max\left(a_{i+1}, \frac{a_i+a_{i+1}+b_i}{2}\right) without any rounding (so values may become non-integer).
12
-
13
- See notes for an example of an operation.
14
-
15
- It can be proven that array a converges, i. e. for each i there exists a limit a_i converges to. Let function F(a, b) return the value a_1 converges to after a process on a and b.
16
-
17
- You are given array b, but not array a. However, you are given a third array c. Array a is good if it contains only integers and satisfies 0 ≤ a_i ≤ c_i for 1 ≤ i ≤ n.
18
-
19
- Your task is to count the number of good arrays a where F(a, b) ≥ x for q values of x. Since the number of arrays can be very large, print it modulo 10^9+7.
20
-
21
- Input
22
-
23
- The first line contains a single integer n (2 ≤ n ≤ 100).
24
-
25
- The second line contains n integers c_1, c_2 …, c_n (0 ≤ c_i ≤ 100).
26
-
27
- The third line contains n-1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 100).
28
-
29
- The fourth line contains a single integer q (q=1).
30
-
31
- The fifth line contains q space separated integers x_1, x_2, …, x_q (-10^5 ≤ x_i ≤ 10^5).
32
-
33
- Output
34
-
35
- Output q integers, where the i-th integer is the answer to the i-th query, i. e. the number of good arrays a where F(a, b) ≥ x_i modulo 10^9+7.
36
-
37
- Example
38
-
39
- Input
40
-
41
-
42
- 3
43
- 2 3 4
44
- 2 1
45
- 1
46
- -1
47
-
48
-
49
- Output
50
-
51
-
52
- 56
53
-
54
- Note
55
-
56
- The following explanation assumes b = [2, 1] and c=[2, 3, 4] (as in the sample).
57
-
58
- Examples of arrays a that are not good:
59
-
60
- * a = [3, 2, 3] is not good because a_1 > c_1;
61
- * a = [0, -1, 3] is not good because a_2 < 0.
62
-
63
-
64
-
65
- One possible good array a is [0, 2, 4]. We can show that no operation has any effect on this array, so F(a, b) = a_1 = 0.
66
-
67
- Another possible good array a is [0, 1, 4]. In a single operation with i = 1, we set a_1 = min((0+1-2)/(2), 0) and a_2 = max((0+1+2)/(2), 1). So, after a single operation with i = 1, a becomes equal to [-1/2, 3/2, 4]. We can show that no operation has any effect on this array, so F(a, b) = -1/2.
68
-
69
- ## Contest Information
70
- - **Contest ID**: 1540
71
- - **Problem Index**: C1
72
- - **Points**: 1500.0
73
- - **Rating**: 2700
74
- - **Tags**: dp, math
75
- - **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
76
- - **Memory Limit**: 256000000 bytes
77
-
78
- ## Task
79
- Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.