source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
apps
verifiable_code
2366
Solve the following coding problem using the programming language python: Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$. Polycarp considers the price on the day $i$ to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if $n=6$ and $a=[3, 9, 4, 6, 7, 5]$, then the number of days with a bad price is $3$ — these are days $2$ ($a_2=9$), $4$ ($a_4=6$) and $5$ ($a_5=7$). Print the number of days with a bad price. You have to answer $t$ independent data sets. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of sets of input data in the test. Input data sets must be processed independently, one after another. Each input data set consists of two lines. The first line contains an integer $n$ ($1 \le n \le 150000$) — the number of days. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$), where $a_i$ is the price on the $i$-th day. It is guaranteed that the sum of $n$ over all data sets in the test does not exceed $150000$. -----Output----- Print $t$ integers, the $j$-th of which should be equal to the number of days with a bad price in the $j$-th input data set. -----Example----- Input 5 6 3 9 4 6 7 5 1 1000000 2 2 1 10 31 41 59 26 53 58 97 93 23 84 7 3 2 1 2 3 4 5 Output 3 0 1 8 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) m = 10 ** 9 c = 0 for i in range(n - 1, -1, -1): if A[i] <= m: m = A[i] else: c += 1 print(c) ```
vfc_7010
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1213/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n6\n3 9 4 6 7 5\n1\n1000000\n2\n2 1\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "output": "3\n0\n1\n8\n2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2367
Solve the following coding problem using the programming language python: You are given two strings $s$ and $t$ both of length $n$ and both consisting of lowercase Latin letters. In one move, you can choose any length $len$ from $1$ to $n$ and perform the following operation: Choose any contiguous substring of the string $s$ of length $len$ and reverse it; at the same time choose any contiguous substring of the string $t$ of length $len$ and reverse it as well. Note that during one move you reverse exactly one substring of the string $s$ and exactly one substring of the string $t$. Also note that borders of substrings you reverse in $s$ and in $t$ can be different, the only restriction is that you reverse the substrings of equal length. For example, if $len=3$ and $n=5$, you can reverse $s[1 \dots 3]$ and $t[3 \dots 5]$, $s[2 \dots 4]$ and $t[2 \dots 4]$, but not $s[1 \dots 3]$ and $t[1 \dots 2]$. Your task is to say if it is possible to make strings $s$ and $t$ equal after some (possibly, empty) sequence of moves. You have to answer $q$ independent test cases. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 10^4$) — the number of test cases. Then $q$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $s$ and $t$. The second line of the test case contains one string $s$ consisting of $n$ lowercase Latin letters. The third line of the test case contains one string $t$ consisting of $n$ lowercase Latin letters. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer on it — "YES" (without quotes) if it is possible to make strings $s$ and $t$ equal after some (possibly, empty) sequence of moves and "NO" otherwise. -----Example----- Input 4 4 abcd abdc 5 ababa baaba 4 asdf asdg 4 abcd badc Output NO YES NO YES The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python q = int(input()) for _ in range(q) : n = int(input()) s = input() t = input() x = set(s) y = set(t) if x != y : print("NO") continue if len(x) == n : a = [0] * n for i, c in enumerate(t) : a[i] = s.find(c) yeet = 0 vis = [False] * n for i in range(n) : if vis[i] : continue j = i cyc = 0 while not vis[j] : cyc += 1 vis[j] = True j = a[j] # print('>> ', i, cyc) yeet += (cyc - 1) % 2 yeet %= 2 if yeet == 0 : print("YES") else : print("NO") continue print("YES") ```
vfc_7014
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1256/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabcd\nbadc\n", "output": "NO\nYES\nNO\nYES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2369
Solve the following coding problem using the programming language python: This problem is a version of problem D from the same contest with some additional constraints and tasks. There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $1$ and two candies of type $2$ is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift. You really like some of the candies and don't want to include them into the gift, but you want to eat them yourself instead. For each candy, a number $f_i$ is given, which is equal to $0$ if you really want to keep $i$-th candy for yourself, or $1$ if you don't mind including it into your gift. It is possible that two candies of the same type have different values of $f_i$. You want your gift to be as large as possible, but you don't want to include too many of the candies you want to eat into the gift. So, you want to calculate the maximum possible number of candies that can be included into a gift, and among all ways to choose maximum number of candies, you want to maximize the number of candies having $f_i = 1$ in your gift. You have to answer $q$ independent queries. If you are Python programmer, consider using PyPy instead of Python when you submit your code. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. The first line of each query contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of candies. Then $n$ lines follow, each containing two integers $a_i$ and $f_i$ ($1 \le a_i \le n$, $0 \le f_i \le 1$), where $a_i$ is the type of the $i$-th candy, and $f_i$ denotes whether you want to keep the $i$-th candy for yourself ($0$ if you want to keep it, $1$ if you don't mind giving it away). It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$. -----Output----- For each query print two integers: the maximum number of candies in a gift you can compose, according to the constraints in the statement; the maximum number of candies having $f_i = 1$ in a gift you can compose that contains the maximum possible number of candies. -----Example----- Input 3 8 1 0 4 1 2 0 4 1 5 1 6 1 3 0 2 0 4 1 1 1 1 2 1 2 1 9 2 0 2 0 4 1 4 1 4 1 7 0 7 1 7 0 7 1 Output 3 3 3 3 9 5 -----Note----- In the first query, you can include two candies of type $4$ and one candy of type $5$. All of them have $f_i = 1$ and you don't mind giving them away as part of the gift. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # @author import sys class GCandyBoxHardVersion: def solve(self): q = int(input()) for _ in range(q): n = int(input()) a = [0] * n f = [0] * n for i in range(n): a[i], f[i] = [int(_) for _ in input().split()] d = {key: [0, 0] for key in a} for i in range(n): d[a[i]][f[i]] += 1 rev_d = {sum(key): [] for key in list(d.values())} for x in d: rev_d[d[x][0] + d[x][1]] += [d[x]] for x in rev_d: rev_d[x].sort(key=lambda item:item[1]) # print(rev_d) cur = max(rev_d) cnt = max(rev_d) nb_candies = 0 given_away = 0 while 1: if cnt == 0 or cur == 0: break if cur > cnt: cur -= 1 continue if cnt not in rev_d or not rev_d[cnt]: cnt -= 1 continue mx_f = -1 v = -1 for max_cnt in range(cur, cnt + 1): if max_cnt in rev_d and rev_d[max_cnt] and rev_d[max_cnt][-1][1] > mx_f: v = max_cnt mx_f = rev_d[max_cnt][-1][1] to_take = rev_d[v].pop() # rev_d[cnt] -= 1 nb_candies += cur given_away += min(to_take[1], cur) cur -= 1 # rev_d[cnt - cur] += 1 print(nb_candies, given_away) solver = GCandyBoxHardVersion() input = sys.stdin.readline solver.solve() ```
vfc_7022
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1183/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n7 1\n7 0\n7 1\n", "output": "3 3\n3 3\n9 5\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2371
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ is a subarray consisting several first elements: the prefix of the array $a$ of length $k$ is the array $[a_1, a_2, \dots, a_k]$ ($0 \le k \le n$). The array $b$ of length $m$ is called good, if you can obtain a non-decreasing array $c$ ($c_1 \le c_2 \le \dots \le c_{m}$) from it, repeating the following operation $m$ times (initially, $c$ is empty): select either the first or the last element of $b$, remove it from $b$, and append it to the end of the array $c$. For example, if we do $4$ operations: take $b_1$, then $b_{m}$, then $b_{m-1}$ and at last $b_2$, then $b$ becomes $[b_3, b_4, \dots, b_{m-3}]$ and $c =[b_1, b_{m}, b_{m-1}, b_2]$. Consider the following example: $b = [1, 2, 3, 4, 4, 2, 1]$. This array is good because we can obtain non-decreasing array $c$ from it by the following sequence of operations: take the first element of $b$, so $b = [2, 3, 4, 4, 2, 1]$, $c = [1]$; take the last element of $b$, so $b = [2, 3, 4, 4, 2]$, $c = [1, 1]$; take the last element of $b$, so $b = [2, 3, 4, 4]$, $c = [1, 1, 2]$; take the first element of $b$, so $b = [3, 4, 4]$, $c = [1, 1, 2, 2]$; take the first element of $b$, so $b = [4, 4]$, $c = [1, 1, 2, 2, 3]$; take the last element of $b$, so $b = [4]$, $c = [1, 1, 2, 2, 3, 4]$; take the only element of $b$, so $b = []$, $c = [1, 1, 2, 2, 3, 4, 4]$ — $c$ is non-decreasing. Note that the array consisting of one element is good. Print the length of the shortest prefix of $a$ to delete (erase), to make $a$ to be a good array. Note that the required length can be $0$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer: the length of the shortest prefix of elements you need to erase from $a$ to make it a good array. -----Example----- Input 5 4 1 2 3 4 7 4 3 3 8 4 5 2 3 1 1 1 7 1 3 1 4 5 3 2 5 5 4 3 2 3 Output 0 4 0 2 3 -----Note----- In the first test case of the example, the array $a$ is already good, so we don't need to erase any prefix. In the second test case of the example, the initial array $a$ is not good. Let's erase first $4$ elements of $a$, the result is $[4, 5, 2]$. The resulting array is good. You can prove that if you erase fewer number of first elements, the result will not be good. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for __ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) ar.reverse() ans = n - 1 flag = False for i in range(1, n): if ar[i] < ar[i - 1]: flag = True if flag: if ar[i] > ar[i - 1]: break ans -= 1 print(ans) ```
vfc_7030
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1385/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n", "output": "0\n4\n0\n2\n3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2372
Solve the following coding problem using the programming language python: Initially, you have the array $a$ consisting of one element $1$ ($a = [1]$). In one move, you can do one of the following things: Increase some (single) element of $a$ by $1$ (choose some $i$ from $1$ to the current length of $a$ and increase $a_i$ by one); Append the copy of some (single) element of $a$ to the end of the array (choose some $i$ from $1$ to the current length of $a$ and append $a_i$ to the end of the array). For example, consider the sequence of five moves: You take the first element $a_1$, append its copy to the end of the array and get $a = [1, 1]$. You take the first element $a_1$, increase it by $1$ and get $a = [2, 1]$. You take the second element $a_2$, append its copy to the end of the array and get $a = [2, 1, 1]$. You take the first element $a_1$, append its copy to the end of the array and get $a = [2, 1, 1, 2]$. You take the fourth element $a_4$, increase it by $1$ and get $a = [2, 1, 1, 3]$. Your task is to find the minimum number of moves required to obtain the array with the sum at least $n$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow. The only line of the test case contains one integer $n$ ($1 \le n \le 10^9$) — the lower bound on the sum of the array. -----Output----- For each test case, print the answer: the minimum number of moves required to obtain the array with the sum at least $n$. -----Example----- Input 5 1 5 42 1337 1000000000 Output 0 3 11 72 63244 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math for _ in range(int(input())): n=int(input()) if n==1: print(0) else: k=int(n**(0.5)) if k*k<n: k+=1 # print(n,k) ans=k-1 if k*(k-1)>=n: ans+=(k-2) else: ans+=(k-1) print(ans) ```
vfc_7034
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1426/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n5\n42\n1337\n1000000000\n", "output": "0\n3\n11\n72\n63244\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2373
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers (it is guaranteed that $n$ is even, i.e. divisible by $2$). All $a_i$ does not exceed some integer $k$. Your task is to replace the minimum number of elements (replacement is the following operation: choose some index $i$ from $1$ to $n$ and replace $a_i$ with some integer in range $[1; k]$) to satisfy the following conditions: after all replacements, all $a_i$ are positive integers not greater than $k$; for all $i$ from $1$ to $\frac{n}{2}$ the following equation is true: $a_i + a_{n - i + 1} = x$, where $x$ should be the same for all $\frac{n}{2}$ pairs of elements. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5$) — the length of $a$ and the maximum possible value of some $a_i$ correspondingly. It is guratanteed that $n$ is even (i.e. divisible by $2$). The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the $i$-th element of $a$. It is guaranteed that the sum of $n$ (as well as the sum of $k$) over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$, $\sum k \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer — the minimum number of elements you have to replace in $a$ to satisfy the conditions from the problem statement. -----Example----- Input 4 4 2 1 2 1 2 4 3 1 2 2 1 8 7 6 1 1 7 6 3 4 6 6 6 5 2 6 1 3 4 Output 0 1 4 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys def input(): return sys.stdin.readline()[:-1] t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) cum = [0 for _ in range(2*k+2)] for i in range(n//2): x, y = a[i], a[n-i-1] cum[2] += 2 cum[min(x, y)+1] -= 1 cum[x+y] -= 1 cum[x+y+1] += 1 cum[max(x, y)+k+1] += 1 cum[2*k+1] -= 2 ans = n for i in range(2, 2*k+1): cum[i] += cum[i-1] ans = min(ans, cum[i]) print(ans) ```
vfc_7038
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1343/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4\n", "output": "0\n1\n4\n2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2374
Solve the following coding problem using the programming language python: You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1, 1)$ and the bottom right — $(2, n)$. There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types: [Image] Types of pipes You can turn each of the given pipes $90$ degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types $1$ and $2$ can become each other and types $3, 4, 5, 6$ can become each other). You want to turn some pipes in a way that the water flow can start at $(1, 0)$ (to the left of the top left pipe), move to the pipe at $(1, 1)$, flow somehow by connected pipes to the pipe at $(2, n)$ and flow right to $(2, n + 1)$. Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes: [Image] Examples of connected pipes Let's describe the problem using some example: [Image] The first example input And its solution is below: [Image] The first example answer As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at $(1, 2)$ $90$ degrees clockwise, the pipe at $(2, 3)$ $90$ degrees, the pipe at $(1, 6)$ $90$ degrees, the pipe at $(1, 7)$ $180$ degrees and the pipe at $(2, 7)$ $180$ degrees. Then the flow of water can reach $(2, n + 1)$ from $(1, 0)$. You have to answer $q$ independent queries. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 10^4$) — the number of queries. Then $q$ queries follow. Each query consists of exactly three lines. The first line of the query contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of pipes in each row. The next two lines contain a description of the first and the second rows correspondingly. Each row description consists of $n$ digits from $1$ to $6$ without any whitespaces between them, each digit corresponds to the type of pipe in the corresponding cell. See the problem statement to understand which digits correspond to which types of pipes. It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$. -----Output----- For the $i$-th query print the answer for it — "YES" (without quotes) if it is possible to turn some pipes in a way that the water flow can reach $(2, n + 1)$ from $(1, 0)$, and "NO" otherwise. -----Example----- Input 6 7 2323216 1615124 1 3 4 2 13 24 2 12 34 3 536 345 2 46 54 Output YES YES YES NO YES NO -----Note----- The first query from the example is described in the problem statement. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python ans = [] for _ in range(int(input())): n = int(input()) s = list(input()) t = list(input()) lvl = 0 X = [s, t] f = 1 for i in range(n): if s[i] in '3456' and t[i] in '3456': lvl = 1 - lvl elif X[lvl][i] in '3456': f = 0 ans.append('NO') break if f and lvl == 1: ans.append('YES') elif f: ans.append('NO') print('\n'.join(ans)) ```
vfc_7042
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1234/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n7\n2323216\n1615124\n1\n3\n4\n2\n13\n24\n2\n12\n34\n3\n536\n345\n2\n46\n54\n", "output": "YES\nYES\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2376
Solve the following coding problem using the programming language python: You are given a tree (connected graph without cycles) consisting of $n$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles. In one move, you can choose exactly $k$ leaves (leaf is such a vertex that is connected to only one another vertex) connected to the same vertex and remove them with edges incident to them. I.e. you choose such leaves $u_1, u_2, \dots, u_k$ that there are edges $(u_1, v)$, $(u_2, v)$, $\dots$, $(u_k, v)$ and remove these leaves and these edges. Your task is to find the maximum number of moves you can perform if you remove leaves optimally. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5$; $1 \le k < n$) — the number of vertices in the tree and the number of leaves you remove in one move, respectively. The next $n-1$ lines describe edges. The $i$-th edge is represented as two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$), where $x_i$ and $y_i$ are vertices the $i$-th edge connects. It is guaranteed that the given set of edges forms a tree. It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer — the maximum number of moves you can perform if you remove leaves optimally. -----Example----- Input 4 8 3 1 2 1 5 7 6 6 8 3 1 6 4 6 1 10 3 1 2 1 10 2 3 1 5 1 6 2 4 7 10 10 9 8 10 7 2 3 1 4 5 3 6 7 4 1 2 1 4 5 1 1 2 2 3 4 3 5 3 Output 2 3 3 4 -----Note----- The picture corresponding to the first test case of the example: [Image] There you can remove vertices $2$, $5$ and $3$ during the first move and vertices $1$, $7$ and $4$ during the second move. The picture corresponding to the second test case of the example: [Image] There you can remove vertices $7$, $8$ and $9$ during the first move, then vertices $5$, $6$ and $10$ during the second move and vertices $1$, $3$ and $4$ during the third move. The picture corresponding to the third test case of the example: $\text{of}$ There you can remove vertices $5$ and $7$ during the first move, then vertices $2$ and $4$ during the second move and vertices $1$ and $6$ during the third move. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop,heapify import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n')] def li3():return [int(i) for i in input().rstrip('\n')] for _ in range(val()): n, k = li() d = defaultdict(set) for i in range(n-1): a, b = li() d[a].add(b) d[b].add(a) thistime = 1 he = deque() visited = {} for i in d: if len(d[i]) == 1: visited[i] = 1 he.append(i) ans = 0 counts = defaultdict(int) # print(he) while he: i = he.popleft() for j in list(d[i]): counts[j] += 1 d[i].remove(j) d[j].remove(i) if counts[j] == k: thistime = 1 ans += 1 counts[j] = 0 if len(d[j]) == 1: if j not in visited:he.append(j) visited[j] = 1 # print(j, he) print(ans) ```
vfc_7050
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1385/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8 10\n7 2\n3 1\n4 5\n3 6\n7 4\n1 2\n1 4\n5 1\n1 2\n2 3\n4 3\n5 3\n", "output": "2\n3\n3\n4\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2377
Solve the following coding problem using the programming language python: This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array elements: choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the begin of the array; choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the end of the array. For example, if $n = 5$, $a = [4, 7, 2, 3, 9]$, then the following sequence of operations can be performed: after performing the operation of the first type to the second element, the array $a$ will become $[7, 4, 2, 3, 9]$; after performing the operation of the second type to the second element, the array $a$ will become $[7, 2, 3, 9, 4]$. You can perform operations of any type any number of times in any order. Find the minimum total number of operations of the first and second type that will make the $a$ array sorted in non-decreasing order. In other words, what is the minimum number of operations that must be performed so the array satisfies the inequalities $a[1] \le a[2] \le \ldots \le a[n]$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases in the test. Then $t$ test cases follow. Each test case starts with a line containing an integer $n$ ($1 \le n \le 3000$) — length of the array $a$. Then follow $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — an array that needs to be sorted by the given operations. All numbers in the given array are distinct. The sum of $n$ for all test cases in one test does not exceed $3000$. -----Output----- For each test case output one integer — the minimum total number of operations of the first and second type, which will make the array sorted in non-decreasing order. -----Example----- Input 4 5 4 7 2 3 9 5 3 5 8 1 7 5 1 4 5 7 12 4 0 2 1 3 Output 2 2 0 2 -----Note----- In the first test case, you first need to move 3, and then 2 to the beginning of the array. Therefore, the desired sequence of operations: $[4, 7, 2, 3, 9] \rightarrow [3, 4, 7, 2, 9] \rightarrow [2, 3, 4, 7, 9]$. In the second test case, you need to move the 1 to the beginning of the array, and the 8 — to the end. Therefore, the desired sequence of operations: $[3, 5, 8, 1, 7] \rightarrow [1, 3, 5, 8, 7] \rightarrow [1, 3, 5, 7, 8]$. In the third test case, the array is already sorted. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = sys.stdin.readline import bisect t=int(input()) for tests in range(t): n=int(input()) A=list(map(int,input().split())) compression_dict={a: ind for ind, a in enumerate(sorted(set(A)))} A=[compression_dict[a] for a in A] Q=[0]*n for i in range(n): Q[A[i]]=i count=1 Ans=0 #print(A,Q) for i in range(1,n): if Q[i]>Q[i-1]: count+=1 else: Ans=max(count,Ans) count=1 Ans=max(count,Ans) print(n-Ans) ```
vfc_7054
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1367/F1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n4 7 2 3 9\n5\n3 5 8 1 7\n5\n1 4 5 7 12\n4\n0 2 1 3\n", "output": "2\n2\n0\n2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2378
Solve the following coding problem using the programming language python: Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell $(0, 0)$ on an infinite grid. You also have the sequence of instructions of this robot. It is written as the string $s$ consisting of characters 'L', 'R', 'U' and 'D'. If the robot is in the cell $(x, y)$ right now, he can move to one of the adjacent cells (depending on the current instruction). If the current instruction is 'L', then the robot can move to the left to $(x - 1, y)$; if the current instruction is 'R', then the robot can move to the right to $(x + 1, y)$; if the current instruction is 'U', then the robot can move to the top to $(x, y + 1)$; if the current instruction is 'D', then the robot can move to the bottom to $(x, y - 1)$. You've noticed the warning on the last page of the manual: if the robot visits some cell (except $(0, 0)$) twice then it breaks. So the sequence of instructions is valid if the robot starts in the cell $(0, 0)$, performs the given instructions, visits no cell other than $(0, 0)$ two or more times and ends the path in the cell $(0, 0)$. Also cell $(0, 0)$ should be visited at most two times: at the beginning and at the end (if the path is empty then it is visited only once). For example, the following sequences of instructions are considered valid: "UD", "RL", "UUURULLDDDDLDDRRUU", and the following are considered invalid: "U" (the endpoint is not $(0, 0)$) and "UUDD" (the cell $(0, 1)$ is visited twice). The initial sequence of instructions, however, might be not valid. You don't want your robot to break so you decided to reprogram it in the following way: you will remove some (possibly, all or none) instructions from the initial sequence of instructions, then rearrange the remaining instructions as you wish and turn on your robot to move. Your task is to remove as few instructions from the initial sequence as possible and rearrange the remaining ones so that the sequence is valid. Report the valid sequence of the maximum length you can obtain. Note that you can choose any order of remaining instructions (you don't need to minimize the number of swaps or any other similar metric). You have to answer $q$ independent test cases. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^4$) — the number of test cases. The next $q$ lines contain test cases. The $i$-th test case is given as the string $s$ consisting of at least $1$ and no more than $10^5$ characters 'L', 'R', 'U' and 'D' — the initial sequence of instructions. It is guaranteed that the sum of $|s|$ (where $|s|$ is the length of $s$) does not exceed $10^5$ over all test cases ($\sum |s| \le 10^5$). -----Output----- For each test case print the answer on it. In the first line print the maximum number of remaining instructions. In the second line print the valid sequence of remaining instructions $t$ the robot has to perform. The moves are performed from left to right in the order of the printed sequence. If there are several answers, you can print any. If the answer is $0$, you are allowed to print an empty line (but you can don't print it). -----Example----- Input 6 LRU DURLDRUDRULRDURDDL LRUDDLRUDRUL LLLLRRRR URDUR LLL Output 2 LR 14 RUURDDDDLLLUUR 12 ULDDDRRRUULL 2 LR 2 UD 0 -----Note----- There are only two possible answers in the first test case: "LR" and "RL". The picture corresponding to the second test case: [Image] Note that the direction of traverse does not matter Another correct answer to the third test case: "URDDLLLUURDR". The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) for _ in range(n): s = input() l,r,u,d = [s.count(i) for i in 'LRUD'] lr = min(l, r) ud = min(u, d) res = "" if lr == 0 and ud == 0: res = "" elif lr == 0: res = "UD" elif ud == 0: res = 'LR' else: res = 'R' * lr + 'U' * ud + 'L' * lr + 'D' * ud print(len(res)) print(res) ```
vfc_7058
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1272/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nLRU\nDURLDRUDRULRDURDDL\nLRUDDLRUDRUL\nLLLLRRRR\nURDUR\nLLL\n", "output": "2\nLR\n14\nLLLUUUURRRDDDD\n12\nLLLUUURRRDDD\n2\nLR\n2\nUD\n0\n\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2380
Solve the following coding problem using the programming language python: You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$. In one move, you can choose one lamp and change its state (i.e. turn it on if it is turned off and vice versa). The garland is called $k$-periodic if the distance between each pair of adjacent turned on lamps is exactly $k$. Consider the case $k=3$. Then garlands "00010010", "1001001", "00010" and "0" are good but garlands "00101001", "1000001" and "01001100" are not. Note that the garland is not cyclic, i.e. the first turned on lamp is not going after the last turned on lamp and vice versa. Your task is to find the minimum number of moves you need to make to obtain $k$-periodic garland from the given one. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 25~ 000$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 10^6; 1 \le k \le n$) — the length of $s$ and the required period. The second line of the test case contains the string $s$ consisting of $n$ characters '0' and '1'. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ ($\sum n \le 10^6$). -----Output----- For each test case, print the answer — the minimum number of moves you need to make to obtain $k$-periodic garland from the given one. -----Example----- Input 6 9 2 010001010 9 3 111100000 7 4 1111111 10 3 1001110101 1 1 1 1 1 0 Output 1 2 5 4 0 0 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = sys.stdin.readline rInt = lambda: int(input()) mInt = lambda: map(int, input().split()) rLis = lambda: list(map(int, input().split())) outs = [] t = rInt() for _ in range(t): n, k = mInt() s = input() pref = [0] for c in s: if c == '1': pref.append(pref[-1] + 1) else: pref.append(pref[-1]) best = pref[-1] dp = [] for i in range(n): cost = pref[i] if i >= k: case2 = dp[i - k] + pref[i] - pref[i - k + 1] if case2 < cost: cost = case2 if s[i] == '0': cost += 1 dp.append(cost) actual = cost + pref[-1] - pref[i + 1] if actual < best: best = actual outs.append(best) print(*outs, sep = '\n') ```
vfc_7066
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1353/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n9 2\n010001010\n9 3\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n1\n1 1\n0\n", "output": "1\n2\n5\n4\n0\n0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2381
Solve the following coding problem using the programming language python: There is a frog staying to the left of the string $s = s_1 s_2 \ldots s_n$ consisting of $n$ characters (to be more precise, the frog initially stays at the cell $0$). Each character of $s$ is either 'L' or 'R'. It means that if the frog is staying at the $i$-th cell and the $i$-th character is 'L', the frog can jump only to the left. If the frog is staying at the $i$-th cell and the $i$-th character is 'R', the frog can jump only to the right. The frog can jump only to the right from the cell $0$. Note that the frog can jump into the same cell twice and can perform as many jumps as it needs. The frog wants to reach the $n+1$-th cell. The frog chooses some positive integer value $d$ before the first jump (and cannot change it later) and jumps by no more than $d$ cells at once. I.e. if the $i$-th character is 'L' then the frog can jump to any cell in a range $[max(0, i - d); i - 1]$, and if the $i$-th character is 'R' then the frog can jump to any cell in a range $[i + 1; min(n + 1; i + d)]$. The frog doesn't want to jump far, so your task is to find the minimum possible value of $d$ such that the frog can reach the cell $n+1$ from the cell $0$ if it can jump by no more than $d$ cells at once. It is guaranteed that it is always possible to reach $n+1$ from $0$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The next $t$ lines describe test cases. The $i$-th test case is described as a string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ characters 'L' and 'R'. It is guaranteed that the sum of lengths of strings over all test cases does not exceed $2 \cdot 10^5$ ($\sum |s| \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer — the minimum possible value of $d$ such that the frog can reach the cell $n+1$ from the cell $0$ if it jumps by no more than $d$ at once. -----Example----- Input 6 LRLRRLL L LLR RRRR LLLLLL R Output 3 2 3 1 7 1 -----Note----- The picture describing the first test case of the example and one of the possible answers: [Image] In the second test case of the example, the frog can only jump directly from $0$ to $n+1$. In the third test case of the example, the frog can choose $d=3$, jump to the cell $3$ from the cell $0$ and then to the cell $4$ from the cell $3$. In the fourth test case of the example, the frog can choose $d=1$ and jump $5$ times to the right. In the fifth test case of the example, the frog can only jump directly from $0$ to $n+1$. In the sixth test case of the example, the frog can choose $d=1$ and jump $2$ times to the right. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for i in range(int(input())): s='R' + input() + 'R' prev=0 ma=-1 for i in range(1,len(s)): if s[i]=='R': ma=max(ma,i-prev) prev=i print(ma) ```
vfc_7070
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1324/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nLRLRRLL\nL\nLLR\nRRRR\nLLLLLL\nR\n", "output": "3\n2\n3\n1\n7\n1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2382
Solve the following coding problem using the programming language python: You are given $n$ strings $a_1, a_2, \ldots, a_n$: all of them have the same length $m$. The strings consist of lowercase English letters. Find any string $s$ of length $m$ such that each of the given $n$ strings differs from $s$ in at most one position. Formally, for each given string $a_i$, there is no more than one position $j$ such that $a_i[j] \ne s[j]$. Note that the desired string $s$ may be equal to one of the given strings $a_i$, or it may differ from all the given strings. For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first. -----Input----- The first line contains an integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ test cases follow. Each test case starts with a line containing two positive integers $n$ ($1 \le n \le 10$) and $m$ ($1 \le m \le 10$) — the number of strings and their length. Then follow $n$ strings $a_i$, one per line. Each of them has length $m$ and consists of lowercase English letters. -----Output----- Print $t$ answers to the test cases. Each answer (if it exists) is a string of length $m$ consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes). -----Example----- Input 5 2 4 abac zbab 2 4 aaaa bbbb 3 3 baa aaa aab 2 2 ab bb 3 1 a b c Output abab -1 aaa ab z -----Note----- The first test case was explained in the statement. In the second test case, the answer does not exist. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def isvalid(s): nonlocal l for i in l: count=0 for j in range(len(i)): if(s[j]!=i[j]): count+=1 if(count>1): return 0 return 1 t=int(input()) for you in range(t): l=input().split() n=int(l[0]) m=int(l[1]) l=[] for i in range(n): s=input() l.append(s) poss=0 ans=0 for i in range(m): copy=[x for x in l[0]] for j in range(26): copy[i]=chr(97+j) if(isvalid(copy)): poss=1 ans=copy break if(poss==1): break if(poss): for i in ans: print(i,end="") print() else: print(-1) ```
vfc_7074
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1360/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 4\nabac\nzbab\n2 4\naaaa\nbbbb\n3 3\nbaa\naaa\naab\n2 2\nab\nbb\n3 1\na\nb\nc\n", "output": "zbac\n-1\naaa\nab\na\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2383
Solve the following coding problem using the programming language python: Find the minimum area of a square land on which you can place two identical rectangular $a \times b$ houses. The sides of the houses should be parallel to the sides of the desired square land. Formally, You are given two identical rectangles with side lengths $a$ and $b$ ($1 \le a, b \le 100$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. [Image] The picture shows a square that contains red and green rectangles. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10\,000$) —the number of test cases in the input. Then $t$ test cases follow. Each test case is a line containing two integers $a$, $b$ ($1 \le a, b \le 100$) — side lengths of the rectangles. -----Output----- Print $t$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $a \times b$. -----Example----- Input 8 3 2 4 2 1 1 3 1 4 7 1 3 7 4 100 100 Output 16 16 4 9 64 9 64 40000 -----Note----- Below are the answers for the first two test cases: [Image] [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python T = int(input()) for _ in range(T): a, b = list(map(int, input().split())) print(max(max(a, b), min(a, b) * 2)**2) ```
vfc_7078
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1360/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100\n", "output": "16\n16\n4\n9\n64\n9\n64\n40000\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2384
Solve the following coding problem using the programming language python: This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array elements: choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the begin of the array; choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the end of the array. For example, if $n = 5$, $a = [4, 7, 2, 2, 9]$, then the following sequence of operations can be performed: after performing the operation of the first type to the second element, the array $a$ will become $[7, 4, 2, 2, 9]$; after performing the operation of the second type to the second element, the array $a$ will become $[7, 2, 2, 9, 4]$. You can perform operations of any type any number of times in any order. Find the minimum total number of operations of the first and second type that will make the $a$ array sorted in non-decreasing order. In other words, what is the minimum number of operations must be performed so the array satisfies the inequalities $a[1] \le a[2] \le \ldots \le a[n]$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. Then $t$ test cases follow. Each test case starts with a line containing an integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the size of the array $a$. Then follow $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — an array that needs to be sorted by the given operations. The given array can contain equal elements. The sum of $n$ for all test cases in one test does not exceed $2 \cdot 10^5$. -----Output----- For each test case output one integer — the minimum total number of operations of the first and second type, which will make the array sorted in non-decreasing order. -----Example----- Input 9 5 4 7 2 2 9 5 3 5 8 1 7 5 1 2 2 4 5 2 0 1 3 0 1 0 4 0 1 0 0 4 0 1 0 1 4 0 1 0 2 20 16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9 Output 2 2 0 0 1 1 1 1 16 -----Note----- In the first test case, you first need to move two 2, to the beginning of the array. Therefore, the desired sequence of operations: $[4, 7, 2, 2, 9] \rightarrow [2, 4, 7, 2, 9] \rightarrow [2, 2, 4, 7, 9]$. In the second test case, you need to move the 1 to the beginning of the array, and the 8 — to the end. Therefore, the desired sequence of operations: $[3, 5, 8, 1, 7] \rightarrow [1, 3, 5, 8, 7] \rightarrow [1, 3, 5, 7, 8]$. In the third test case, the array is already sorted. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) id = list(zip(l,list(range(n)))) id.sort() val, pos = zip(*id) blok = [] cur = [pos[0]] for i in range(1,n): if val[i] == val[i-1]: cur.append(pos[i]) else: cur.sort() blok.append(cur) cur = [pos[i]] cur.sort() blok.append(cur) best = 0 m = len(blok) for j in range(m): best = max(len(blok[j]), best) i = 0 while True: if i >= m-2: break cyk = min(blok[i+1]) j = -1 while j+1 < len(blok[i]) and blok[i][j+1] < cyk: j += 1 su = (j+1) ii = i+2 while ii < m: if min(blok[ii]) > max(blok[ii-1]): su += len(blok[ii-1]) ii += 1 else: break if ii == m: su += len(blok[-1]) best = max(best, su) else: xxx = max(blok[ii-1]) su += len(blok[ii-1]) inde = len(blok[ii])-1 while inde >= 0 and blok[ii][inde] >= xxx: su += 1 inde -= 1 best = max(best,su) i = max(i+1, ii-1) for i in range(1,m): b1 = blok[i];b0 = blok[i-1];l0,l1,i1 = len(b0),len(b1),0 for ind in range(l0): while True: if i1 < l1 and b1[i1] <= b0[ind]:i1 += 1 else:break if l1 == i1:break best = max(best, (ind+1)+(l1-i1)) print(n-best) ```
vfc_7082
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1367/F2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n5\n4 7 2 2 9\n5\n3 5 8 1 7\n5\n1 2 2 4 5\n2\n0 1\n3\n0 1 0\n4\n0 1 0 0\n4\n0 1 0 1\n4\n0 1 0 2\n20\n16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9\n", "output": "2\n2\n0\n0\n1\n1\n1\n1\n16\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2385
Solve the following coding problem using the programming language python: There is a rectangular grid of size $n \times m$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $(i, j)$ is $c_{i, j}$. You are also given a map of directions: for each cell, there is a direction $s_{i, j}$ which is one of the four characters 'U', 'R', 'D' and 'L'. If $s_{i, j}$ is 'U' then there is a transition from the cell $(i, j)$ to the cell $(i - 1, j)$; if $s_{i, j}$ is 'R' then there is a transition from the cell $(i, j)$ to the cell $(i, j + 1)$; if $s_{i, j}$ is 'D' then there is a transition from the cell $(i, j)$ to the cell $(i + 1, j)$; if $s_{i, j}$ is 'L' then there is a transition from the cell $(i, j)$ to the cell $(i, j - 1)$. It is guaranteed that the top row doesn't contain characters 'U', the bottom row doesn't contain characters 'D', the leftmost column doesn't contain characters 'L' and the rightmost column doesn't contain characters 'R'. You want to place some robots in this field (at most one robot in a cell). The following conditions should be satisfied. Firstly, each robot should move every time (i.e. it cannot skip the move). During one move each robot goes to the adjacent cell depending on the current direction. Secondly, you have to place robots in such a way that there is no move before which two different robots occupy the same cell (it also means that you cannot place two robots in the same cell). I.e. if the grid is "RL" (one row, two columns, colors does not matter there) then you can place two robots in cells $(1, 1)$ and $(1, 2)$, but if the grid is "RLL" then you cannot place robots in cells $(1, 1)$ and $(1, 3)$ because during the first second both robots will occupy the cell $(1, 2)$. The robots make an infinite number of moves. Your task is to place the maximum number of robots to satisfy all the conditions described above and among all such ways, you have to choose one where the number of black cells occupied by robots before all movements is the maximum possible. Note that you can place robots only before all movements. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 5 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains two integers $n$ and $m$ ($1 < nm \le 10^6$) — the number of rows and the number of columns correspondingly. The next $n$ lines contain $m$ characters each, where the $j$-th character of the $i$-th line is $c_{i, j}$ ($c_{i, j}$ is either '0' if the cell $(i, j)$ is black or '1' if the cell $(i, j)$ is white). The next $n$ lines also contain $m$ characters each, where the $j$-th character of the $i$-th line is $s_{i, j}$ ($s_{i, j}$ is 'U', 'R', 'D' or 'L' and describes the direction of the cell $(i, j)$). It is guaranteed that the sum of the sizes of fields does not exceed $10^6$ ($\sum nm \le 10^6$). -----Output----- For each test case, print two integers — the maximum number of robots you can place to satisfy all the conditions described in the problem statement and the maximum number of black cells occupied by robots before all movements if the number of robots placed is maximized. Note that you can place robots only before all movements. -----Example----- Input 3 1 2 01 RL 3 3 001 101 110 RLL DLD ULL 3 3 000 000 000 RRD RLD ULL Output 2 1 4 3 2 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = sys.stdin.readline def search(i,j): L=[] c=0 while CHECK[i][j]==1<<30: L.append((i,j)) CHECK[i][j]=c if MAP2[i][j]=="U": i-=1 elif MAP2[i][j]=="D": i+=1 elif MAP2[i][j]=="R": j+=1 else: j-=1 c+=1 if (i,j) in L: x=CHECK[i][j] y=CHECK[L[-1][0]][L[-1][1]] loop=abs(x-y)+1 for x,y in L: CHECK[x][y]%=loop LOOP[x][y]=loop else: loop=LOOP[i][j] c=CHECK[i][j] for x,y in L[::-1]: c=(c-1)%loop CHECK[x][y]=c LOOP[x][y]=loop def search2(i,j): Q=[(i,j)] ANS=[0]*LOOP[i][j] while Q: x,y=Q.pop() if USE[x][y]==1: continue USE[x][y]=1 if MAP[x][y]=="0": ANS[CHECK[x][y]]=1 if MAP2[x][y]=="U": Q.append((x-1,y)) elif MAP2[x][y]=="D": Q.append((x+1,y)) elif MAP2[x][y]=="R": Q.append((x,y+1)) else: Q.append((x,y-1)) if 0<=x+1<n and 0<=y<m and MAP2[x+1][y]=="U": Q.append((x+1,y)) if 0<=x-1<n and 0<=y<m and MAP2[x-1][y]=="D": Q.append((x-1,y)) if 0<=x<n and 0<=y+1<m and MAP2[x][y+1]=="L": Q.append((x,y+1)) if 0<=x<n and 0<=y-1<m and MAP2[x][y-1]=="R": Q.append((x,y-1)) return LOOP[i][j],sum(ANS) t=int(input()) for tests in range(t): n,m=list(map(int,input().split())) MAP=[input().strip() for i in range(n)] MAP2=[input().strip() for i in range(n)] CHECK=[[1<<30]*m for i in range(n)] LOOP=[[1<<30]*m for i in range(n)] for i in range(n): for j in range(m): if CHECK[i][j]==1<<30: search(i,j) #print(i,j) #print(CHECK) #print(LOOP) USE=[[0]*m for i in range(n)] ANSM=0 ANSC=0 for i in range(n): for j in range(m): if USE[i][j]==0: x,y=search2(i,j) ANSM+=x ANSC+=y print(ANSM,ANSC) ```
vfc_7086
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1335/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n01\nRL\n3 3\n001\n101\n110\nRLL\nDLD\nULL\n3 3\n000\n000\n000\nRRD\nRLD\nULL\n", "output": "2 1\n4 3\n2 2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2386
Solve the following coding problem using the programming language python: A permutation of length $n$ is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ are permutations, and $[1, 1]$, $[0, 1]$, $[2, 2, 1, 4]$ are not. There was a permutation $p[1 \dots n]$. It was merged with itself. In other words, let's take two instances of $p$ and insert elements of the second $p$ into the first maintaining relative order of elements. The result is a sequence of the length $2n$. For example, if $p=[3, 1, 2]$ some possible results are: $[3, 1, 2, 3, 1, 2]$, $[3, 3, 1, 1, 2, 2]$, $[3, 1, 3, 1, 2, 2]$. The following sequences are not possible results of a merging: $[1, 3, 2, 1, 2, 3$], [$3, 1, 2, 3, 2, 1]$, $[3, 3, 1, 2, 2, 1]$. For example, if $p=[2, 1]$ the possible results are: $[2, 2, 1, 1]$, $[2, 1, 2, 1]$. The following sequences are not possible results of a merging: $[1, 1, 2, 2$], [$2, 1, 1, 2]$, $[1, 2, 2, 1]$. Your task is to restore the permutation $p$ by the given resulting sequence $a$. It is guaranteed that the answer exists and is unique. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 400$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 50$) — the length of permutation. The second line of the test case contains $2n$ integers $a_1, a_2, \dots, a_{2n}$ ($1 \le a_i \le n$), where $a_i$ is the $i$-th element of $a$. It is guaranteed that the array $a$ represents the result of merging of some permutation $p$ with the same permutation $p$. -----Output----- For each test case, print the answer: $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$), representing the initial permutation. It is guaranteed that the answer exists and is unique. -----Example----- Input 5 2 1 1 2 2 4 1 3 1 4 3 4 2 2 5 1 2 1 2 3 4 3 5 4 5 3 1 2 3 1 2 3 4 2 3 2 4 1 3 4 1 Output 1 2 1 3 4 2 1 2 3 4 5 1 2 3 2 3 4 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) print(*set(a)) ```
vfc_7090
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1385/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1\n", "output": "1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2388
Solve the following coding problem using the programming language python: 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. Your task is to choose at most $\lfloor\frac{n}{2}\rfloor$ vertices in this graph so each unchosen vertex is adjacent (in other words, connected by an edge) to at least one of chosen vertices. It is guaranteed that the answer exists. If there are multiple answers, you can print any. You will be given multiple independent queries to answer. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of queries. Then $t$ queries follow. The first line of each query contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$) — the number of vertices and the number of edges, respectively. The following $m$ lines denote edges: edge $i$ is represented by a pair of integers $v_i$, $u_i$ ($1 \le v_i, u_i \le n$, $u_i \ne v_i$), which are the indices of vertices connected by the edge. There are no self-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 \ne u_i$ is satisfied. It is guaranteed that the given graph is connected. It is guaranteed that $\sum m \le 2 \cdot 10^5$ over all queries. -----Output----- For each query print two lines. In the first line print $k$ ($1 \le \lfloor\frac{n}{2}\rfloor$) — the number of chosen vertices. In the second line print $k$ distinct integers $c_1, c_2, \dots, c_k$ in any order, where $c_i$ is the index of the $i$-th chosen vertex. It is guaranteed that the answer exists. If there are multiple answers, you can print any. -----Example----- Input 2 4 6 1 2 1 3 1 4 2 3 2 4 3 4 6 8 2 5 5 4 4 3 4 1 1 3 2 3 2 6 5 6 Output 2 1 3 3 4 3 6 -----Note----- In the first query any vertex or any pair of vertices will suffice. [Image] Note that you don't have to minimize the number of chosen vertices. In the second query two vertices can be enough (vertices $2$ and $4$) but three is also ok. [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = sys.stdin.readline T = int(input()) for _ in range(T): N, M = list(map(int, input().split())) E = [[] for aa in range(N)] for __ in range(M): a, b = list(map(int, input().split())) E[a-1].append(b-1) E[b-1].append(a-1) D = [-1] * N D[0] = 0 d = 0 post = [0] EVEN = [1] ODD = [] while post: d += 1 pre = post post = [] for i in pre: for e in E[i]: if D[e] < 0: D[e] = d post.append(e) if d % 2: ODD.append(e+1) else: EVEN.append(e+1) if len(ODD) < len(EVEN): print(len(ODD)) print(*ODD) else: print(len(EVEN)) print(*EVEN) ```
vfc_7098
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1176/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n6 8\n2 5\n5 4\n4 3\n4 1\n1 3\n2 3\n2 6\n5 6\n", "output": "1\n1 \n3\n3 4 6 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2389
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the size of the input. You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'. You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there will be a string of length $k$ that is a substring of $s$, and is also a substring of the infinite string "RGBRGBRGB ...". A string $a$ is a substring of string $b$ if there exists a positive integer $i$ such that $a_1 = b_i$, $a_2 = b_{i + 1}$, $a_3 = b_{i + 2}$, ..., $a_{|a|} = b_{i + |a| - 1}$. For example, strings "GBRG", "B", "BR" are substrings of the infinite string "RGBRGBRGB ..." while "GR", "RGR" and "GGG" are not. You have to answer $q$ independent queries. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. Then $q$ queries follow. The first line of the query contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the length of the string $s$ and the length of the substring. The second line of the query contains a string $s$ consisting of $n$ characters 'R', 'G' and 'B'. It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each query print one integer — the minimum number of characters you need to change in the initial string $s$ so that after changing there will be a substring of length $k$ in $s$ that is also a substring of the infinite string "RGBRGBRGB ...". -----Example----- Input 3 5 2 BGGGG 5 3 RBRGR 5 5 BBBRR Output 1 0 3 -----Note----- In the first example, you can change the first character to 'R' and obtain the substring "RG", or change the second character to 'R' and obtain "BR", or change the third, fourth or fifth character to 'B' and obtain "GB". In the second example, the substring is "BRG". The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin import math rgb = 'RGB' for query in range(int(stdin.readline())): n, k = list(map(int, stdin.readline().split())) s = stdin.readline() ans = math.inf for start in range(3): dp = [0 for i in range(n + 1)] for i in range(n): cur = rgb[(start + i) % len(rgb)] dp[i + 1] = dp[i] + int(s[i] != cur) for i in range(n - k + 1): ans = min(ans, dp[i + k] - dp[i]) print(ans) ```
vfc_7102
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1196/D2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n", "output": "1\n0\n3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2390
Solve the following coding problem using the programming language python: This problem is actually a subproblem of problem G from the same contest. There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $1$ and two candies of type $2$ is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift. Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have. You have to answer $q$ independent queries. If you are Python programmer, consider using PyPy instead of Python when you submit your code. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. Each query is represented by two lines. The first line of each query contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of candies. The second line of each query contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the type of the $i$-th candy in the box. It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$. -----Output----- For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement. -----Example----- Input 3 8 1 4 8 4 5 6 3 8 16 2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1 9 2 2 4 4 4 7 7 7 7 Output 3 10 9 -----Note----- In the first query, you can prepare a gift with two candies of type $8$ and one candy of type $5$, totalling to $3$ candies. Note that this is not the only possible solution — taking two candies of type $4$ and one candy of type $6$ is also valid. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = sys.stdin.readline Q = int(input()) for _ in range(Q): N = int(input()) A = [int(a) for a in input().split()] X = {} for a in A: if a in X: X[a] += 1 else: X[a] = 1 Y = [] for x in X: Y.append(X[x]) Y = sorted(Y)[::-1] prev = Y[0] + 1 su = 0 for i in range(len(Y)): ne = min(prev-1, Y[i]) if ne <= 0: break su += ne prev = ne print(su) ```
vfc_7106
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1183/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n8\n1 4 8 4 5 6 3 8\n16\n2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1\n9\n2 2 4 4 4 7 7 7 7\n", "output": "3\n10\n9\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2391
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. In one move, you can choose some index $i$ ($1 \le i \le n - 2$) and shift the segment $[a_i, a_{i + 1}, a_{i + 2}]$ cyclically to the right (i.e. replace the segment $[a_i, a_{i + 1}, a_{i + 2}]$ with $[a_{i + 2}, a_i, a_{i + 1}]$). Your task is to sort the initial array by no more than $n^2$ such operations or say that it is impossible to do that. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($3 \le n \le 500$) — the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 500$), where $a_i$ is the $i$-th element $a$. It is guaranteed that the sum of $n$ does not exceed $500$. -----Output----- For each test case, print the answer: -1 on the only line if it is impossible to sort the given array using operations described in the problem statement, or the number of operations $ans$ on the first line and $ans$ integers $idx_1, idx_2, \dots, idx_{ans}$ ($1 \le idx_i \le n - 2$), where $idx_i$ is the index of left border of the segment for the $i$-th operation. You should print indices in order of performing operations. -----Example----- Input 5 5 1 2 3 4 5 5 5 4 3 2 1 8 8 4 5 2 3 6 7 3 7 5 2 1 6 4 7 3 6 1 2 3 3 6 4 Output 0 6 3 1 3 2 2 3 13 2 1 1 6 4 2 4 3 3 4 4 6 6 -1 4 3 3 4 4 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t = int(input()) for _ in range(t): n = int(input()) l = list([int(x)- 1 for x in input().split()]) out = [] ll = [(l[i], i) for i in range(n)] ll.sort() swap = (-1,-1) for i in range(n - 1): if ll[i][0] == ll[i + 1][0]: swap = (ll[i][1],ll[i+1][1]) newl = [0]*n for i in range(n): newl[ll[i][1]] = i l = newl swapN = 0 for i in range(n): for j in range(i + 1, n): if l[i] > l[j]: swapN += 1 #print(l) if swapN & 1: l[swap[0]],l[swap[1]] = l[swap[1]],l[swap[0]] #print(l) def shift(i): out.append(i + 1) l[i],l[i+1],l[i+2] = l[i+2],l[i],l[i+1] works = True done = False while not done: for i in range(n): if l[i] != i: break else: done = True if done: break for find in range(i + 1, n): if l[find] == i: break while find - i >= 2: find -= 2 shift(find) if find - i == 1: if find <= n - 2: shift(find - 1) shift(find - 1) else: works = False break #print(l) if works: print(len(out)) print(' '.join(map(str,out))) else: print(-1) #print('---') ```
vfc_7110
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1374/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n", "output": "0\n\n6\n3 1 3 2 2 3 \n13\n2 1 1 6 4 2 4 3 3 4 4 6 6 \n-1\n4\n3 3 4 4 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2392
Solve the following coding problem using the programming language python: Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible by $m$ are $5, 10, 15$. Their last digits are $5, 0, 5$ correspondingly, their sum is $10$. Your task is to calculate the sum of all digits Polycarp has written down. You have to answer $q$ independent queries. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 1000$) — the number of queries. The following $q$ lines contain queries, one per line. Each query is given as two integers $n$ and $m$ ($1 \le n, m \le 10^{16}$) — the number of pages in the book and required divisor, respectively. -----Output----- For each query print the answer for it — the sum of digits written down by Polycarp. -----Example----- Input 7 1 1 10 1 100 3 1024 14 998244353 1337 123 144 1234312817382646 13 Output 1 45 153 294 3359835 0 427262129093995 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n, m = list(map(int, input().split())) A = [] x = 1 while True: if (m * x) % 10 not in A: A.append((m * x) % 10) else: break x += 1 s = sum(A) n //= m print(s * (n // len(A)) + sum(A[:n % len(A)])) ```
vfc_7114
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1213/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 1\n10 1\n100 3\n1024 14\n998244353 1337\n123 144\n1234312817382646 13\n", "output": "1\n45\n153\n294\n3359835\n0\n427262129093995\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2393
Solve the following coding problem using the programming language python: Polygon is not only the best platform for developing problems but also a square matrix with side $n$, initially filled with the character 0. On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly $2n$ cannons were placed. [Image] Initial polygon for $n=4$. Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding. More formally: if a cannon stands in the row $i$, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell ($i, 1$) and ends in some cell ($i, j$); if a cannon stands in the column $j$, above the first row, and shoots with a 1, then the 1 starts its flight from the cell ($1, j$) and ends in some cell ($i, j$). For example, consider the following sequence of shots: [Image] 1. Shoot the cannon in the row $2$.                         2. Shoot the cannon in the row $2$.                         3. Shoot the cannon in column $3$. You have a report from the military training on your desk. This report is a square matrix with side length $n$ consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix? Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0. -----Input----- The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow. Each test case starts with a line containing an integer $n$ ($1 \le n \le 50$) — the size of the polygon. This is followed by $n$ lines of length $n$, consisting of 0 and 1 — the polygon matrix after the training. The total area of the matrices in all test cases in one test does not exceed $10^5$. -----Output----- For each test case print: YES if there is a sequence of shots leading to a given matrix; NO if such a sequence does not exist. The letters in the words YES and NO can be printed in any case. -----Example----- Input 5 4 0010 0011 0000 0000 2 10 01 2 00 00 4 0101 1111 0101 0111 4 0100 1110 0101 0111 Output YES NO YES YES NO -----Note----- The first test case was explained in the statement. The answer to the second test case is NO, since a 1 in a cell ($1, 1$) flying out of any cannon would continue its flight further. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def read_int(): return int(input()) def read_ints(): return list(map(int, input().split(' '))) t = read_int() for case_num in range(t): n = read_int() mat = [] for i in range(n): mat.append(input()) ok = True for i in range(n): for j in range(n): if mat[i][j] == '0': continue cok = j == n - 1 or i == n - 1 if not cok: cok = mat[i][j + 1] == '1' or mat[i + 1][j] == '1' if not cok: ok = False break if not ok: break print('YES' if ok else 'NO') ```
vfc_7118
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1360/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4\n0010\n0011\n0000\n0000\n2\n10\n01\n2\n00\n00\n4\n0101\n1111\n0101\n0111\n4\n0100\n1110\n0101\n0111\n", "output": "YES\nNO\nYES\nYES\nNO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2394
Solve the following coding problem using the programming language python: You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'. In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index $i$, remove the $i$-th character of $s$ and insert it before or after all remaining characters of $s$). Your task is to find the minimum number of moves required to obtain regular bracket sequence from $s$. It can be proved that the answer always exists under the given constraints. Recall what the regular bracket sequence is: "()" is regular bracket sequence; if $s$ is regular bracket sequence then "(" + $s$ + ")" is regular bracket sequence; if $s$ and $t$ are regular bracket sequences then $s$ + $t$ is regular bracket sequence. For example, "()()", "(())()", "(())" and "()" are regular bracket sequences, but ")(", "()(" and ")))" are not. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2000$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($2 \le n \le 50$) — the length of $s$. It is guaranteed that $n$ is even. The second line of the test case containg the string $s$ consisting of $\frac{n}{2}$ opening and $\frac{n}{2}$ closing brackets. -----Output----- For each test case, print the answer — the minimum number of moves required to obtain regular bracket sequence from $s$. It can be proved that the answer always exists under the given constraints. -----Example----- Input 4 2 )( 4 ()() 8 ())()()( 10 )))((((()) Output 1 0 1 3 -----Note----- In the first test case of the example, it is sufficient to move the first bracket to the end of the string. In the third test case of the example, it is sufficient to move the last bracket to the beginning of the string. In the fourth test case of the example, we can choose last three openning brackets, move them to the beginning of the string and obtain "((()))(())". The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n = int(input()) s = input() st = 0 fans = 0 for x in s: if x == ')': st -= 1 else: st += 1 if st < 0: fans += 1 st = 0 print(fans) ```
vfc_7122
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1374/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n", "output": "1\n0\n1\n3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2395
Solve the following coding problem using the programming language python: A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$. You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the other digits of $x$ can be $0$, $1$ or $2$. Let's define the ternary XOR operation $\odot$ of two ternary numbers $a$ and $b$ (both of length $n$) as a number $c = a \odot b$ of length $n$, where $c_i = (a_i + b_i) \% 3$ (where $\%$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $3$. For example, $10222 \odot 11021 = 21210$. Your task is to find such ternary numbers $a$ and $b$ both of length $n$ and both without leading zeros that $a \odot b = x$ and $max(a, b)$ is the minimum possible. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 5 \cdot 10^4$) — the length of $x$. The second line of the test case contains ternary number $x$ consisting of $n$ digits $0, 1$ or $2$. It is guaranteed that the first digit of $x$ is $2$. It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^4$ ($\sum n \le 5 \cdot 10^4$). -----Output----- For each test case, print the answer — two ternary integers $a$ and $b$ both of length $n$ and both without leading zeros such that $a \odot b = x$ and $max(a, b)$ is the minimum possible. If there are several answers, you can print any. -----Example----- Input 4 5 22222 5 21211 1 2 9 220222021 Output 11111 11111 11000 10211 1 1 110111011 110111010 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n=int(input()) s=input() a="" b="" flag=1 for i in s: if flag: if i=="2": a+="1" b+="1" elif i=="1": a+="1" b+="0" flag=0 else: a+="0" b+="0" else: if i=="2": a+="0" b+="2" elif i=="1": a+="0" b+="1" flag=0 else: a+="0" b+="0" print(a) print(b) ```
vfc_7126
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1328/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n", "output": "11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2396
Solve the following coding problem using the programming language python: You are given a string $s[1 \dots n]$ consisting of lowercase Latin letters. It is guaranteed that $n = 2^k$ for some integer $k \ge 0$. The string $s[1 \dots n]$ is called $c$-good if at least one of the following three conditions is satisfied: The length of $s$ is $1$, and it consists of the character $c$ (i.e. $s_1=c$); The length of $s$ is greater than $1$, the first half of the string consists of only the character $c$ (i.e. $s_1=s_2=\dots=s_{\frac{n}{2}}=c$) and the second half of the string (i.e. the string $s_{\frac{n}{2} + 1}s_{\frac{n}{2} + 2} \dots s_n$) is a $(c+1)$-good string; The length of $s$ is greater than $1$, the second half of the string consists of only the character $c$ (i.e. $s_{\frac{n}{2} + 1}=s_{\frac{n}{2} + 2}=\dots=s_n=c$) and the first half of the string (i.e. the string $s_1s_2 \dots s_{\frac{n}{2}}$) is a $(c+1)$-good string. For example: "aabc" is 'a'-good, "ffgheeee" is 'e'-good. In one move, you can choose one index $i$ from $1$ to $n$ and replace $s_i$ with any lowercase Latin letter (any character from 'a' to 'z'). Your task is to find the minimum number of moves required to obtain an 'a'-good string from $s$ (i.e. $c$-good string for $c=$ 'a'). It is guaranteed that the answer always exists. You have to answer $t$ independent test cases. Another example of an 'a'-good string is as follows. Consider the string $s = $"cdbbaaaa". It is an 'a'-good string, because: the second half of the string ("aaaa") consists of only the character 'a'; the first half of the string ("cdbb") is 'b'-good string, because: the second half of the string ("bb") consists of only the character 'b'; the first half of the string ("cd") is 'c'-good string, because: the first half of the string ("c") consists of only the character 'c'; the second half of the string ("d") is 'd'-good string. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 131~072$) — the length of $s$. It is guaranteed that $n = 2^k$ for some integer $k \ge 0$. The second line of the test case contains the string $s$ consisting of $n$ lowercase Latin letters. It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer — the minimum number of moves required to obtain an 'a'-good string from $s$ (i.e. $c$-good string with $c =$ 'a'). It is guaranteed that the answer exists. -----Example----- Input 6 8 bbdcaaaa 8 asdfghjk 8 ceaaaabb 8 bbaaddcc 1 z 2 ac Output 0 7 4 5 1 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # coding: utf-8 # Your code here! def solve(s, c): if(len(s)==1): if s[0]==c: return 0 else: return 1 ans1 = sum([i!=c for i in s[:len(s)//2]]) + solve(s[len(s)//2:],chr(ord(c)+1)) ans2 = sum([i!=c for i in s[len(s)//2:]]) + solve(s[:len(s)//2],chr(ord(c)+1)) return min(ans1, ans2) for _ in range(int(input())): input() print(solve(input(),'a')) ```
vfc_7130
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1385/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaabb\n8\nbbaaddcc\n1\nz\n2\nac\n", "output": "0\n7\n4\n5\n1\n1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2397
Solve the following coding problem using the programming language python: Consider all binary strings of length $m$ ($1 \le m \le 60$). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly $2^m$ such strings in total. The string $s$ is lexicographically smaller than the string $t$ (both have the same length $m$) if in the first position $i$ from the left in which they differ, we have $s[i] < t[i]$. This is exactly the way strings are compared in dictionaries and in most modern programming languages when comparing them in a standard way. For example, the string 01011 is lexicographically smaller than the string 01100, because the first two characters are the same, and the third character in the first string is less than that in the second. We remove from this set $n$ ($1 \le n \le \min(2^m-1, 100)$) distinct binary strings $a_1, a_2, \ldots, a_n$, each of length $m$. Thus, the set will have $k=2^m-n$ strings. Sort all strings of the resulting set in lexicographical ascending order (as in the dictionary). We number all the strings after sorting from $0$ to $k-1$. Print the string whose index is $\lfloor \frac{k-1}{2} \rfloor$ (such an element is called median), where $\lfloor x \rfloor$ is the rounding of the number down to the nearest integer. For example, if $n=3$, $m=3$ and $a=[$010, 111, 001$]$, then after removing the strings $a_i$ and sorting, the result will take the form: $[$000, 011, 100, 101, 110$]$. Thus, the desired median is 100. -----Input----- The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then, $t$ test cases follow. The first line of each test case contains integers $n$ ($1 \le n \le \min(2^m-1, 100)$) and $m$ ($1 \le m \le 60$), where $n$ is the number of strings to remove, and $m$ is the length of binary strings. The next $n$ lines contain $a_1, a_2, \ldots, a_n$ — distinct binary strings of length $m$. The total length of all given binary strings in all test cases in one test does not exceed $10^5$. -----Output----- Print $t$ answers to the test cases. For each test case, print a string of length $m$ — the median of the sorted sequence of remaining strings in the corresponding test case. -----Example----- Input 5 3 3 010 001 111 4 3 000 111 100 011 1 1 1 1 1 0 3 2 00 01 10 Output 100 010 0 1 11 -----Note----- The first test case is explained in the statement. In the second test case, the result after removing strings and sorting is $[$001, 010, 101, 110$]$. Therefore, the desired median is 010. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def read_int(): return int(input()) def read_ints(): return list(map(int, input().split(' '))) t = read_int() for case_num in range(t): n, m = read_ints() a = [] for i in range(n): a.append(int(input(), 2)) a.sort() k = 2 ** m - n ans = (k - 1) // 2 for ai in a: if ai <= ans: ans += 1 binary = '{:b}'.format(ans) print(binary.rjust(m, '0')) ```
vfc_7134
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1360/H", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 3\n010\n001\n111\n4 3\n000\n111\n100\n011\n1 1\n1\n1 1\n0\n3 2\n00\n01\n10\n", "output": "100\n010\n0\n1\n11\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2399
Solve the following coding problem using the programming language python: You are given a graph consisting of $n$ vertices and $m$ edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some direction for all these edges. You have to direct undirected edges in such a way that the resulting graph is directed and acyclic (i.e. the graph with all edges directed and having no directed cycles). Note that you have to direct all undirected edges. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$) — the number of vertices and the number of edges in the graph, respectively. The next $m$ lines describe edges of the graph. The $i$-th edge is described with three integers $t_i$, $x_i$ and $y_i$ ($t_i \in [0; 1]$, $1 \le x_i, y_i \le n$) — the type of the edge ($t_i = 0$ if the edge is undirected and $t_i = 1$ if the edge is directed) and vertices this edge connects (the undirected edge connects vertices $x_i$ and $y_i$ and directed edge is going from the vertex $x_i$ to the vertex $y_i$). It is guaranteed that the graph do not contain self-loops (i.e. edges from the vertex to itself) and multiple edges (i.e. for each pair ($x_i, y_i$) there are no other pairs ($x_i, y_i$) or ($y_i, x_i$)). It is guaranteed that both sum $n$ and sum $m$ do not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$; $\sum m \le 2 \cdot 10^5$). -----Output----- For each test case print the answer — "NO" if it is impossible to direct undirected edges in such a way that the resulting graph is directed and acyclic, otherwise print "YES" on the first line and $m$ lines describing edges of the resulted directed acyclic graph (in any order). Note that you cannot change the direction of the already directed edges. If there are several answers, you can print any. -----Example----- Input 4 3 1 0 1 3 5 5 0 2 1 1 1 5 1 5 4 0 5 2 1 3 5 4 5 1 1 2 0 4 3 1 3 1 0 2 3 1 2 4 4 5 1 4 1 1 1 3 0 1 2 1 2 4 1 3 2 Output YES 3 1 YES 2 1 1 5 5 4 2 5 3 5 YES 1 2 3 4 3 1 3 2 2 4 NO -----Note----- Explanation of the second test case of the example: [Image] Explanation of the third test case of the example: [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin, stdout import functools import sys,os,math #sys.setrecursionlimit(10**6) T = int(input()) for _ in range(T): N, M = list(map(int, input().split())) DS = [0] * (N + 1) ES = [] g = [[] for _ in range(N + 1)] for _ in range(M): t, u, v = list(map(int, input().split())) ES.append([t ,u ,v]) if t == 1: DS[u] += 1 g[u].append(len(ES) - 1) g[v].append(len(ES) - 1) q = [] for u in range(1, N+1): if DS[u] == 0: q.append(u) while len(q) > 0: u = q.pop() if DS[u] > 0: continue for e in g[u]: t, u0, v0 = ES[e] if t == 1: if v0 == u: DS[u0] -= 1 if DS[u0] == 0: q.append(u0) elif t == 0: v = v0 if u0 == u else u0 ES[e] = [1, v, u] md = max(DS) if md > 0: print("NO") else: print("YES") for e in ES: print(e[1], e[2]) ```
vfc_7142
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1385/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 1\n0 1 3\n5 5\n0 2 1\n1 1 5\n1 5 4\n0 5 2\n1 3 5\n4 5\n1 1 2\n0 4 3\n1 3 1\n0 2 3\n1 2 4\n4 5\n1 4 1\n1 1 3\n0 1 2\n1 2 4\n1 3 2\n", "output": "YES\n3 1\nYES\n2 1\n1 5\n5 4\n2 5\n3 5\nYES\n1 2\n3 4\n3 1\n3 2\n2 4\nNO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2400
Solve the following coding problem using the programming language python: The round carousel consists of $n$ figures of animals. Figures are numbered from $1$ to $n$ in order of the carousel moving. Thus, after the $n$-th figure the figure with the number $1$ follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger and so on). The type of animal of the $i$-th figure equals $t_i$. [Image] The example of the carousel for $n=9$ and $t=[5, 5, 1, 15, 1, 5, 5, 1, 1]$. You want to color each figure in one of the colors. You think that it's boring if the carousel contains two different figures (with the distinct types of animals) going one right after another and colored in the same color. Your task is to color the figures in such a way that the number of distinct colors used is the minimum possible and there are no figures of the different types going one right after another and colored in the same color. If you use exactly $k$ distinct colors, then the colors of figures should be denoted with integers from $1$ to $k$. -----Input----- The input contains one or more test cases. The first line contains one integer $q$ ($1 \le q \le 10^4$) — the number of test cases in the test. Then $q$ test cases follow. One test case is given on two lines. The first line of the test case contains one integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of figures in the carousel. Figures are numbered from $1$ to $n$ in order of carousel moving. Assume that after the $n$-th figure the figure $1$ goes. The second line of the test case contains $n$ integers $t_1, t_2, \dots, t_n$ ($1 \le t_i \le 2 \cdot 10^5$), where $t_i$ is the type of the animal of the $i$-th figure. The sum of $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $q$ answers, for each test case print two lines. In the first line print one integer $k$ — the minimum possible number of distinct colors of figures. In the second line print $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le k$), where $c_i$ is the color of the $i$-th figure. If there are several answers, you can print any. -----Example----- Input 4 5 1 2 1 2 2 6 1 2 2 1 2 2 5 1 2 1 2 3 3 10 10 10 Output 2 1 2 1 2 2 2 2 1 2 1 2 1 3 2 3 2 3 1 1 1 1 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [int(a) for a in input().split()] if max(A) == min(A): print(1) print(*([1] * N)) elif N % 2 == 0: print(2) print(*([1, 2] * (N // 2))) else: for i in range(N): if A[i-1] == A[i]: print(2) print(*(([1, 2] * N)[:i][::-1] + ([1, 2] * N)[:N-i])) break else: print(3) print(*([3] + [1, 2] * (N // 2))) ```
vfc_7146
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1328/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n1 2 1 2 2\n6\n1 2 2 1 2 2\n5\n1 2 1 2 3\n3\n10 10 10\n", "output": "2\n2 1 2 1 1 \n2\n1 2 1 2 1 2 \n3\n1 2 1 2 3\n1\n1 1 1 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
4757
Solve the following coding problem using the programming language python: You are given four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$). Find any such rectangular matrix of size $n \times m$ that satisfies all of the following conditions: each row of the matrix contains exactly $a$ ones; each column of the matrix contains exactly $b$ ones; all other elements are zeros. If the desired matrix does not exist, indicate this. For example, for $n=3$, $m=6$, $a=2$, $b=1$, there exists a matrix satisfying the conditions above: $$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$ -----Input----- The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow. Each test case is described by four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$), where $n$ and $m$ are the sizes of the matrix, and $a$ and $b$ are the number of ones for rows and columns, respectively. -----Output----- For each test case print: "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or "NO" (without quotes) if it does not exist. To print the matrix $n \times m$, print $n$ rows, each of which consists of $m$ numbers $0$ or $1$ describing a row of the matrix. Numbers must be printed without spaces. -----Example----- Input 5 3 6 2 1 2 2 2 1 2 2 2 2 4 4 2 2 2 1 1 2 Output YES 010001 100100 001010 NO YES 11 11 YES 1100 1100 0011 0011 YES 1 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n, m, a, b = list(map(int, input().split())) if a * n != b * m: print('NO') else: ar = [] for i in range(n): ar.append([0] * m) x, y = 0, a for i in range(n): if x < y: for j in range(x, y): ar[i][j] = 1 else: for j in range(x, m): ar[i][j] = 1 for j in range(y): ar[i][j] = 1 x += a y += a x %= m y %= m print('YES') for i in range(n): print(''.join(map(str, ar[i]))) ```
vfc_9508
{ "difficulty": "introductory", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1360/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2\n", "output": "YES\n110000\n001100\n000011\nNO\nYES\n11\n11\nYES\n1100\n0110\n0011\n1001\nYES\n1\n1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
0
Solve the following coding problem using the programming language python: An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $124$), another colon, and a closing bracket (ASCII code $093$). The length of the accordion is the number of characters in it. For example, [::], [:||:] and [:|||:] are accordions having length $4$, $6$ and $7$. (:|:), {:||:}, [:], ]:||:[ are not accordions. You are given a string $s$. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from $s$, and if so, what is the maximum possible length of the result? -----Input----- The only line contains one string $s$ ($1 \le |s| \le 500000$). It consists of lowercase Latin letters and characters [, ], : and |. -----Output----- If it is not possible to obtain an accordion by removing some characters from $s$, print $-1$. Otherwise print maximum possible length of the resulting accordion. -----Examples----- Input |[a:b:|] Output 4 Input |]:[|:] Output -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() n = len(s) ind = -1 f = False for i in range(n): if s[i] == '[': f = True elif s[i] == ':': if f: ind = i break bind = -1 f = False for i in range(n-1,-1,-1): if s[i] == ']': f = True elif s[i] == ':': if f: bind = i break # print(ind,bind) if ind == -1 or bind == -1: print(-1) elif ind >= bind: print(-1) else: ans = 4 for i in range(ind+1,bind): if s[i] == '|': ans += 1 print(ans) ```
vfc_9754
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1101/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "|[a:b:|]\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "|]:[|:]\n", "output": "-1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
1
Solve the following coding problem using the programming language python: Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. -----Input----- The first line contains the positive integer x (1 ≤ x ≤ 10^18) — the integer which Anton has. -----Output----- Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros. -----Examples----- Input 100 Output 99 Input 48 Output 48 Input 521 Output 499 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python num = list(map(int, input())) best = num[:] for i in range(-1, -len(num) - 1, -1): if num[i] == 0: continue num[i] -= 1 for j in range(i + 1, 0): num[j] = 9 if sum(num) > sum(best): best = num[:] s = ''.join(map(str, best)).lstrip('0') print(s) ```
vfc_9758
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/770/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n", "output": "99\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "48\n", "output": "48\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "521\n", "output": "499\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
2
Solve the following coding problem using the programming language python: Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^9) — current year in Berland. -----Output----- Output amount of years from the current year to the next lucky one. -----Examples----- Input 4 Output 1 Input 201 Output 99 Input 4000 Output 1000 -----Note----- In the first example next lucky year is 5. In the second one — 300. In the third — 5000. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): s = input() n = len(s) t = int(str(int(s[0]) + 1) + '0' * (n - 1)) print(t - int(s)) main() ```
vfc_9762
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/808/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "201\n", "output": "99\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4000\n", "output": "1000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
3
Solve the following coding problem using the programming language python: You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$. Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work. You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it. -----Input----- The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively. Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$). -----Output----- Print one integer — maximum number of painted sections if you hire $q - 2$ painters. -----Examples----- Input 7 5 1 4 4 5 5 6 6 7 3 5 Output 7 Input 4 3 1 1 2 2 3 4 Output 2 Input 4 4 1 1 2 2 2 3 3 4 Output 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import defaultdict as dd import math def nn(): return int(input()) def li(): return list(input()) def mi(): return list(map(int, input().split())) def lm(): return list(map(int, input().split())) n, q=mi() ints=[] for _ in range(q): st, end=mi() ints.append((st,end)) coverage=[10]+[0]*n for st, end in ints: for i in range(st,end+1): coverage[i]+=1 total=-1 for val in coverage: if not val==0: total+=1 singlecount=0 doublecount=0 singles=[0]*(n+1) #print(total) doubles=[0]*(n+1) for i in range(len(coverage)): #print(i,singles) if coverage[i]==1: singlecount+=1 if coverage[i]==2: doublecount+=1 singles[i]=singlecount doubles[i]=doublecount maxtotal=0 for i in range(len(ints)): for j in range(i+1, len(ints)): st1=min(ints[i][0],ints[j][0]) end1=min(ints[i][1],ints[j][1]) st2, end2=max(ints[i][0],ints[j][0]), max(ints[i][1],ints[j][1]) #assume st1<=st2 if end1<st2: curtotal=total-(singles[end1]-singles[st1-1])-(singles[end2]-singles[st2-1]) elif end1<end2: curtotal=total-(singles[st2-1]-singles[st1-1])-(doubles[end1]-doubles[st2-1])-(singles[end2]-singles[end1]) else: curtotal=total-(singles[st2-1]-singles[st1-1])-(doubles[end2]-doubles[st2-1])-(singles[end1]-singles[end2]) maxtotal=max(maxtotal,curtotal) print(maxtotal) ```
vfc_9766
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1132/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 5\n1 4\n4 5\n5 6\n6 7\n3 5\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n1 1\n2 2\n3 4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 1\n2 2\n2 3\n3 4\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
4
Solve the following coding problem using the programming language python: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button. A time is considered lucky if it contains a digit '7'. For example, 13: 07 and 17: 27 are lucky, while 00: 48 and 21: 34 are not lucky. Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at hh: mm. Formally, find the smallest possible non-negative integer y such that the time representation of the time x·y minutes before hh: mm contains the digit '7'. Jamie uses 24-hours clock, so after 23: 59 comes 00: 00. -----Input----- The first line contains a single integer x (1 ≤ x ≤ 60). The second line contains two two-digit integers, hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59). -----Output----- Print the minimum number of times he needs to press the button. -----Examples----- Input 3 11 23 Output 2 Input 5 01 07 Output 0 -----Note----- In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x=int(input()) h,m=list(map(int,input().split())) def ok(mm): while mm<0: mm+=1440 hh=mm//60 mm=mm%60 return hh%10==7 or hh//10==7 or mm%10==7 or mm//10==7 for y in range(999): if ok(h*60+m-y*x): print(y) return ```
vfc_9770
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/916/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n11 23\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
5
Solve the following coding problem using the programming language python: Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible. Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6. What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened? -----Input----- The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened. -----Output----- Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r]. -----Examples----- Input 6 3 2 4 Output 5 Input 6 3 1 3 Output 1 Input 5 2 1 5 Output 0 -----Note----- In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it. In the second test she only needs to close all the tabs to the right of the current position of the cursor. In the third test Luba doesn't need to do anything. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, pos, l, r = map(int, input().split()) if l > 1 and r < n: if l <= pos and pos <= r: if pos - l < r - pos: print(pos - l + 1 + r - l + 1) else: print(r - pos + 1 + r - l + 1) elif pos > r: print(pos - r + 1 + r - l + 1) else: print(l - pos + 1 + r - l + 1) elif l == 1 and r < n: print(int(abs(pos - r)) + 1) elif l > 1 and r == n: print(int(abs(pos - l)) + 1) else: print(0) ```
vfc_9774
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/915/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3 2 4\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3 1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 1 5\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 1 1 99\n", "output": "99\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 50 1 99\n", "output": "50\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 99 1 99\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
6
Solve the following coding problem using the programming language python: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! $m$ Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decrease the number of Gorynich's heads by $min(d_i, curX)$, there $curX$ is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows $h_i$ new heads. If $curX = 0$ then Gorynich is defeated. You can deal each blow any number of times, in any order. For example, if $curX = 10$, $d = 7$, $h = 10$ then the number of heads changes to $13$ (you cut $7$ heads off, but then Zmei grows $10$ new ones), but if $curX = 10$, $d = 11$, $h = 100$ then number of heads changes to $0$ and Zmei Gorynich is considered defeated. Calculate the minimum number of blows to defeat Zmei Gorynich! You have to answer $t$ independent queries. -----Input----- The first line contains one integer $t$ ($1 \le t \le 100$) – the number of queries. The first line of each query contains two integers $n$ and $x$ ($1 \le n \le 100$, $1 \le x \le 10^9$) — the number of possible types of blows and the number of heads Zmei initially has, respectively. The following $n$ lines of each query contain the descriptions of types of blows you can deal. The $i$-th line contains two integers $d_i$ and $h_i$ ($1 \le d_i, h_i \le 10^9$) — the description of the $i$-th blow. -----Output----- For each query print the minimum number of blows you have to deal to defeat Zmei Gorynich. If Zmei Gorynuch cannot be defeated print $-1$. -----Example----- Input 3 3 10 6 3 8 2 1 4 4 10 4 1 3 2 2 6 1 100 2 15 10 11 14 100 Output 2 3 -1 -----Note----- In the first query you can deal the first blow (after that the number of heads changes to $10 - 6 + 3 = 7$), and then deal the second blow. In the second query you just deal the first blow three times, and Zmei is defeated. In third query you can not defeat Zmei Gorynich. Maybe it's better to convince it to stop fighting? The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n, x = list(map(int, input().split())) A = [] for _1 in range(n): d, h = list(map(int, input().split())) A.append([d, h]) A.sort(reverse=True) if A[0][0] >= x: print(1) else: x -= A[0][0] mz = 0 for d, h in A: mz = max(mz, d - h) if mz: print((x + mz - 1) // mz + 1) else: print(-1) ```
vfc_9778
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1217/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 10\n6 3\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100\n", "output": "2\n3\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n5 1000000000\n2 1\n1 10\n1 1\n4 1000000000\n3 3\n1 1000000000\n5 1\n2 999999999\n3 1\n2 10000000\n4 10000000\n10000000 999999999\n9999900 12\n9999999 55\n9999999 1\n2 1000000\n1000000 1000000\n999999 1\n3 999999911\n3 1\n11 1000000000\n10 9\n3 1000000000\n1231 1200\n1000 800\n1 100\n", "output": "999999997\n250000000\n499999999\n1\n1\n499999951\n4999995\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
7
Solve the following coding problem using the programming language python: Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..." More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens: m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). Sparrows come and eat grain. In the i-th day i sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing. Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day! -----Input----- The only line of the input contains two integers n and m (1 ≤ n, m ≤ 10^18) — the capacity of the barn and the number of grains that are brought every day. -----Output----- Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one. -----Examples----- Input 5 2 Output 4 Input 8 1 Output 5 -----Note----- In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens: At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain. At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it. At the end of the second day two sparrows come. 5 - 2 = 3 grains remain. At the beginning of the third day two grains are brought. The barn becomes full again. At the end of the third day three sparrows come and eat grain. 5 - 3 = 2 grains remain. At the beginning of the fourth day grain is brought again. 2 + 2 = 4 grains remain. At the end of the fourth day four sparrows come and eat grain. 4 - 4 = 0 grains remain. The barn is empty. So the answer is 4, because by the end of the fourth day the barn becomes empty. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m = map(int, input().split()) if (m >= n): print(n) else: c = n - m l = 0 r = 10 ** 18 while r - l > 1: md = (r + l) // 2 if (1 + md) * md // 2 < c: l = md else: r = md print(r + m) ```
vfc_9782
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/785/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 1\n", "output": "5\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
8
Solve the following coding problem using the programming language python: Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $\ldots$, 9m, 1p, 2p, $\ldots$, 9p, 1s, 2s, $\ldots$, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: A mentsu, also known as meld, is formed by a koutsu or a shuntsu; A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu; [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. -----Input----- The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $1$ to $9$ and the second character is m, p or s. -----Output----- Print a single integer — the minimum number of extra suited tiles she needs to draw. -----Examples----- Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 -----Note----- In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python cards=list(input().split()) lm=[0]*9 lp=[0]*9 ls=[0]*9 for item in cards: if item[1]=='m': lm[int(item[0])-1]+=1 elif item[1]=='p': lp[int(item[0])-1]+=1 else : ls[int(item[0])-1]+=1 if max(lm)==3 or max(lp)==3 or max(ls)==3: print(0) else : flag=0 def seq_checker(li): flag=0 for i in range(9): if flag==0: if lm[i]==1: flag=1 else : if lm[i]==1: flag+=1 else : break return flag if seq_checker(lm)==3 or seq_checker(lp)==3 or seq_checker(ls)==3: print(0) elif max(lm)==2 or max(lp)==2 or max(ls)==2: print(1) else : m=0 for i in range(0,7): m=max(sum(lm[i:i+3]),sum(lp[i:i+3]),sum(ls[i:i+3]),m) print(3-m) ```
vfc_9786
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1191/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1s 2s 3s\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9m 9m 9m\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3p 9m 2p\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8p 2s 9m\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
9
Solve the following coding problem using the programming language python: Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same! The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells. Sofa A is standing to the left of sofa B if there exist two such cells a and b that x_{a} < x_{b}, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that y_{a} < y_{b}, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way. Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions. The note also stated that there are cnt_{l} sofas to the left of Grandpa Maks's sofa, cnt_{r} — to the right, cnt_{t} — to the top and cnt_{b} — to the bottom. Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions. Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1. -----Input----- The first line contains one integer number d (1 ≤ d ≤ 10^5) — the number of sofas in the storehouse. The second line contains two integer numbers n, m (1 ≤ n, m ≤ 10^5) — the size of the storehouse. Next d lines contains four integer numbers x_1, y_1, x_2, y_2 (1 ≤ x_1, x_2 ≤ n, 1 ≤ y_1, y_2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x_1, y_1) and (x_2, y_2) have common side, (x_1, y_1) ≠ (x_2, y_2) and no cell is covered by more than one sofa. The last line contains four integer numbers cnt_{l}, cnt_{r}, cnt_{t}, cnt_{b} (0 ≤ cnt_{l}, cnt_{r}, cnt_{t}, cnt_{b} ≤ d - 1). -----Output----- Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1. -----Examples----- Input 2 3 2 3 1 3 2 1 2 2 2 1 0 0 1 Output 1 Input 3 10 10 1 2 1 1 5 5 6 5 6 4 5 4 2 1 2 0 Output 2 Input 2 2 2 2 1 1 1 1 2 2 2 1 0 0 0 Output -1 -----Note----- Let's consider the second example. The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below). The second sofa has cnt_{l} = 2, cnt_{r} = 1, cnt_{t} = 2 and cnt_{b} = 0. The third sofa has cnt_{l} = 2, cnt_{r} = 1, cnt_{t} = 1 and cnt_{b} = 1. So the second one corresponds to the given conditions. In the third example The first sofa has cnt_{l} = 1, cnt_{r} = 1, cnt_{t} = 0 and cnt_{b} = 1. The second sofa has cnt_{l} = 1, cnt_{r} = 1, cnt_{t} = 1 and cnt_{b} = 0. And there is no sofa with the set (1, 0, 0, 0) so the answer is -1. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin, stdout k = int(stdin.readline()) n, m = map(int, stdin.readline().split()) left, right, down, up = [], [], [], [] coordinates = [] for i in range(k): x1, y1, x2, y2 = map(int, stdin.readline().split()) if x1 == x2: if y1 < y2: coordinates.append((x1, y1, x2, y2, i)) else: coordinates.append((x2, y2, x1, y1, i)) else: if x1 < x2: coordinates.append((x1, y1, x2, y2, i)) else: coordinates.append((x2, y2, x1, y1, i)) left.append(coordinates[-1]) right.append(coordinates[-1]) up.append(coordinates[-1]) down.append(coordinates[-1]) left.sort(key = lambda x: (x[0], x[2])) down.sort(key = lambda x: (x[1], x[3])) challengers = [[], [], [], []] cntl, cntr, cntd, cntu = map(int, stdin.readline().split()) label = 1 if cntl or not cntl: for i in range(cntl, -1, -1): if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]): challengers[0].append(left[i][-1]) else: break for i in range(cntl + 1, k): if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]) and left[i][2] > left[i][0]: label = 0 if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]): challengers[0].append(left[i][-1]) else: break if cntr or not cntr: for i in range(k - 1 - cntr, k): if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]): challengers[1].append(left[i][-1]) else: break for i in range(k - 2 - cntr, -1, -1): if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]) and left[i][2] > left[i][0]: label = 0 if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]): challengers[1].append(left[i][-1]) else: break #!!!!!!!!!!! if cntd or not cntd: for i in range(cntd, -1, -1): if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]): challengers[2].append(down[i][-1]) else: break for i in range(cntd + 1, k): if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]) and down[i][3] > down[i][1]: label = 0 if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]): challengers[2].append(down[i][-1]) else: break if cntu or not cntu: for i in range(k - 1 - cntu, k): if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]): challengers[3].append(down[i][-1]) else: break for i in range(k - 2 - cntu, -1, -1): if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]) and down[i][3] > down[i][1]: label = 0 if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]): challengers[3].append(down[i][-1]) else: break ans = set(challengers[0]) & set(challengers[1]) & set(challengers[2]) & set(challengers[3]) if not len(ans) or not label: stdout.write('-1') else: stdout.write(str(list(ans)[0] + 1)) ```
vfc_9790
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/818/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 2\n1 1 1 2\n0 0 0 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2 1\n2 1 1 1\n0 0 0 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000 1000\n63 902 63 901\n0 0 0 0\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
10
Solve the following coding problem using the programming language python: On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. -----Input----- The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars. -----Output----- Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. -----Examples----- Input 14 Output 4 4 Input 2 Output 0 2 -----Note----- In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off . In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n=int(input()) r=n%7 d=n//7 print(2*d+max(0,r-5),2*d+min(r,2)) ```
vfc_9794
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/670/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "14\n", "output": "4 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "0 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "0 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "0 2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
11
Solve the following coding problem using the programming language python: Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue. After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get. -----Input----- The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 10^9). -----Output----- Print the only integer s — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. -----Examples----- Input 5 2 3 12 15 Output 39 Input 20 2 3 3 5 Output 51 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from fractions import gcd def lcm(a, b): return a*b//gcd(a, b) n, a, b, p, q = list(map(int, input().split(' '))) red = n//a blue = n//b if (p<q): red -= n//lcm(a, b) else: blue -= n//lcm(a, b) print(p*red+q*blue) ```
vfc_9798
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/678/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 3 12 15\n", "output": "39\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 2 3 3 5\n", "output": "51\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
12
Solve the following coding problem using the programming language python: Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as beautiful as possible — that means, to maximize the length of the longest such subsegment. Help Vova! Tell him the maximum possible beauty of the arrangement if he is allowed to do at most one swap. -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$) — the number of trophies. The second line contains $n$ characters, each of them is either G or S. If the $i$-th character is G, then the $i$-th trophy is a golden one, otherwise it's a silver trophy. -----Output----- Print the maximum possible length of a subsegment of golden trophies, if Vova is allowed to do at most one swap. -----Examples----- Input 10 GGGSGGGSGG Output 7 Input 4 GGGG Output 4 Input 3 SSS Output 0 -----Note----- In the first example Vova has to swap trophies with indices $4$ and $10$. Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is $7$. In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is $4$. In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than $0$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) A = input() x = A.count('G') num_1 = 0 num_2 = 0 max_num = 0 flag = 0 for i in range(n): if A[i] == 'G' and flag == 0: num_1 += 1 elif A[i] == 'G' and flag == 1: num_2 += 1 elif A[i] == 'S' and flag == 0: flag = 1 else: if num_1 + num_2 + 1 <= x: if num_1 + num_2 + 1 > max_num: max_num = num_1 + num_2 + 1 num_1 = num_2 num_2 = 0 flag = 1 else: if num_2 + num_1 > max_num: max_num = num_1 + num_2 num_1 = num_2 num_2 = 0 flag = 1 if num_1 + num_2 + 1 <= x: if num_1 + num_2 + 1 > max_num: max_num = num_1 + num_2 + 1 else: if num_2 + num_1 > max_num: max_num = num_1 + num_2 print(max_num) ```
vfc_9802
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1082/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\nGGGSGGGSGG\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nGGGG\n", "output": "4\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
13
Solve the following coding problem using the programming language python: Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage. The situation is complicated by the dependence of online courses, for each course there is a list of those that must be passed before starting this online course (the list can be empty, it means that there is no limitation). Help Polycarp to pass the least number of courses in total to get the specialty (it means to pass all main and necessary courses). Write a program which prints the order of courses. Polycarp passes courses consistently, he starts the next course when he finishes the previous one. Each course can't be passed more than once. -----Input----- The first line contains n and k (1 ≤ k ≤ n ≤ 10^5) — the number of online-courses and the number of main courses of Polycarp's specialty. The second line contains k distinct integers from 1 to n — numbers of main online-courses of Polycarp's specialty. Then n lines follow, each of them describes the next course: the i-th of them corresponds to the course i. Each line starts from the integer t_{i} (0 ≤ t_{i} ≤ n - 1) — the number of courses on which the i-th depends. Then there follows the sequence of t_{i} distinct integers from 1 to n — numbers of courses in random order, on which the i-th depends. It is guaranteed that no course can depend on itself. It is guaranteed that the sum of all values t_{i} doesn't exceed 10^5. -----Output----- Print -1, if there is no the way to get a specialty. Otherwise, in the first line print the integer m — the minimum number of online-courses which it is necessary to pass to get a specialty. In the second line print m distinct integers — numbers of courses which it is necessary to pass in the chronological order of their passage. If there are several answers it is allowed to print any of them. -----Examples----- Input 6 2 5 3 0 0 0 2 2 1 1 4 1 5 Output 5 1 2 3 4 5 Input 9 3 3 9 5 0 0 3 9 4 5 0 0 1 8 1 6 1 2 2 1 2 Output 6 1 2 9 4 5 3 Input 3 3 1 2 3 1 2 1 3 1 1 Output -1 -----Note----- In the first test firstly you can take courses number 1 and 2, after that you can take the course number 4, then you can take the course number 5, which is the main. After that you have to take only the course number 3, which is the last not passed main course. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python #This code is dedicated to Vlada S. class Course: def __init__(self, reqs, number): self.reqs = list(map(int, reqs.split()[1:])) self.available = False self.in_stack = False self.number = number n, k = list(map(int, input().split())) requirements = list(map(int, input().split())) courses = {} answer = "" for i in range(n): courses[i + 1]= Course(input(), i + 1) for i in range(len(requirements)): requirements[i] = courses[requirements[i]] while requirements: data = {} course = requirements.pop() if not course.available: requirements.append(course) done = True for c in course.reqs: c = courses[c] if not c.available: requirements.append(c) done = False if done: answer += " " + str(course.number) course.available = True else: if course.in_stack: print(-1) break course.in_stack = True else: print(answer.count(" ")) print(answer[1:]) ```
vfc_9806
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/770/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5\n", "output": "5\n1 2 3 4 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2\n", "output": "6\n1 2 9 4 5 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 3\n1 2\n1 3\n1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n2 1 4\n0\n0\n1 5\n0\n0\n", "output": "3\n1 2 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n4 1\n0\n1 4\n1 5\n0\n2 1 2\n", "output": "2\n1 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n4 5\n2 3 4\n1 4\n1 4\n0\n0\n", "output": "2\n4 5 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
14
Solve the following coding problem using the programming language python: Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty). You may perform the following operations until both a and s are empty: Take the first element of a, push it into s and remove it from a (if a is not empty); Take the top element from s, append it to the end of array b and remove it from s (if s is not empty). You can perform these operations in arbitrary order. If there exists a way to perform the operations such that array b is sorted in non-descending order in the end, then array a is called stack-sortable. For example, [3, 1, 2] is stack-sortable, because b will be sorted if we perform the following operations: Remove 3 from a and push it into s; Remove 1 from a and push it into s; Remove 1 from s and append it to the end of b; Remove 2 from a and push it into s; Remove 2 from s and append it to the end of b; Remove 3 from s and append it to the end of b. After all these operations b = [1, 2, 3], so [3, 1, 2] is stack-sortable. [2, 3, 1] is not stack-sortable. You are given k first elements of some permutation p of size n (recall that a permutation of size n is an array of size n where each integer from 1 to n occurs exactly once). You have to restore the remaining n - k elements of this permutation so it is stack-sortable. If there are multiple answers, choose the answer such that p is lexicographically maximal (an array q is lexicographically greater than an array p iff there exists some integer k such that for every i < k q_{i} = p_{i}, and q_{k} > p_{k}). You may not swap or change any of first k elements of the permutation. Print the lexicographically maximal permutation p you can obtain. If there exists no answer then output -1. -----Input----- The first line contains two integers n and k (2 ≤ n ≤ 200000, 1 ≤ k < n) — the size of a desired permutation, and the number of elements you are given, respectively. The second line contains k integers p_1, p_2, ..., p_{k} (1 ≤ p_{i} ≤ n) — the first k elements of p. These integers are pairwise distinct. -----Output----- If it is possible to restore a stack-sortable permutation p of size n such that the first k elements of p are equal to elements given in the input, print lexicographically maximal such permutation. Otherwise print -1. -----Examples----- Input 5 3 3 2 1 Output 3 2 1 5 4 Input 5 3 2 3 1 Output -1 Input 5 1 3 Output 3 2 1 5 4 Input 5 2 3 4 Output -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys #f = open('input', 'r') f = sys.stdin n,k = list(map(int, f.readline().split())) a = list(map(int, f.readline().split())) aset = set(a) st = [] failed = False ai = 0 app = [] for p in range(1, n+1): if p in aset: while ai < k and (len(st)==0 or st[-1]!=p): st.append(a[ai]) ai += 1 if len(st) == 0 or st[-1] != p: failed = True break st.pop(-1) a += app[::-1] app = [] else: if ai != k: st += a[ai:k] ai = k app.append(p) if failed: print(-1) else: print(' '.join(map(str, a + app[::-1]))) ```
vfc_9810
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/911/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n3 2 1\n", "output": "3 2 1 5 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n2 3 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n3\n", "output": "3 2 1 5 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n3 4\n", "output": "-1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
15
Solve the following coding problem using the programming language python: Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that s_{i} = b. Of course, you are the person he asks for a help. -----Input----- The first line of the input contain three integers a, b and c ( - 10^9 ≤ a, b, c ≤ 10^9) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. -----Output----- If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes). -----Examples----- Input 1 7 3 Output YES Input 10 10 0 Output YES Input 1 -4 5 Output NO Input 0 60 50 Output NO -----Note----- In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys a,b,c=map(int,input().split()) if c==0: if a==b: print('YES') else: print('NO') return if (b-a)%c==0 and (b-a)//c>=0: print('YES') else: print('NO') ```
vfc_9814
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/675/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 7 3\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 0\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 -4 5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 60 50\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 -4 -5\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 1 0\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
16
Solve the following coding problem using the programming language python: A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; "))" and ")((" are bracket sequences (but not regular ones), and "(a)" and "(1)+(1)" are not bracket sequences at all. You have a number of strings; each string is a bracket sequence of length $2$. So, overall you have $cnt_1$ strings "((", $cnt_2$ strings "()", $cnt_3$ strings ")(" and $cnt_4$ strings "))". You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length $2(cnt_1 + cnt_2 + cnt_3 + cnt_4)$. You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either. -----Input----- The input consists of four lines, $i$-th of them contains one integer $cnt_i$ ($0 \le cnt_i \le 10^9$). -----Output----- Print one integer: $1$ if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, $0$ otherwise. -----Examples----- Input 3 1 4 3 Output 1 Input 0 0 0 0 Output 1 Input 1 2 3 4 Output 0 -----Note----- In the first example it is possible to construct a string "(())()(()((()()()())))", which is a regular bracket sequence. In the second example it is possible to construct a string "", which is a regular bracket sequence. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python cnt1 = int(input()) cnt2 = int(input()) cnt3 = int(input()) cnt4 = int(input()) if cnt1 != cnt4: print(0) return if (cnt3 != 0 and cnt1 == 0): print(0) return print(1) ```
vfc_9818
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1132/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n4\n3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0\n0\n0\n0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n3\n4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000\n1000000000\n1000000000\n1000000000\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
17
Solve the following coding problem using the programming language python: Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator stands. At time k + 1, the (k + 1)-th spectator stands and the first spectator sits. At time k + 2, the (k + 2)-th spectator stands and the second spectator sits. ... At time n, the n-th spectator stands and the (n - k)-th spectator sits. At time n + 1, the (n + 1 - k)-th spectator sits. ... At time n + k, the n-th spectator sits. Arpa wants to know how many spectators are standing at time t. -----Input----- The first line contains three integers n, k, t (1 ≤ n ≤ 10^9, 1 ≤ k ≤ n, 1 ≤ t < n + k). -----Output----- Print single integer: how many spectators are standing at time t. -----Examples----- Input 10 5 3 Output 3 Input 10 5 7 Output 5 Input 10 5 12 Output 3 -----Note----- In the following a sitting spectator is represented as -, a standing spectator is represented as ^. At t = 0  ---------- $\Rightarrow$ number of standing spectators = 0. At t = 1  ^--------- $\Rightarrow$ number of standing spectators = 1. At t = 2  ^^-------- $\Rightarrow$ number of standing spectators = 2. At t = 3  ^^^------- $\Rightarrow$ number of standing spectators = 3. At t = 4  ^^^^------ $\Rightarrow$ number of standing spectators = 4. At t = 5  ^^^^^----- $\Rightarrow$ number of standing spectators = 5. At t = 6  -^^^^^---- $\Rightarrow$ number of standing spectators = 5. At t = 7  --^^^^^--- $\Rightarrow$ number of standing spectators = 5. At t = 8  ---^^^^^-- $\Rightarrow$ number of standing spectators = 5. At t = 9  ----^^^^^- $\Rightarrow$ number of standing spectators = 5. At t = 10 -----^^^^^ $\Rightarrow$ number of standing spectators = 5. At t = 11 ------^^^^ $\Rightarrow$ number of standing spectators = 4. At t = 12 -------^^^ $\Rightarrow$ number of standing spectators = 3. At t = 13 --------^^ $\Rightarrow$ number of standing spectators = 2. At t = 14 ---------^ $\Rightarrow$ number of standing spectators = 1. At t = 15 ---------- $\Rightarrow$ number of standing spectators = 0. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def read_ints(): return [int(i) for i in input().split()] n, k, t = read_ints() if t <= k: print(t) elif t > n: print(k + n - t) else: print(k) ```
vfc_9822
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/851/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5 7\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5 12\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "840585600 770678331 788528791\n", "output": "770678331\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "25462281 23343504 8024619\n", "output": "8024619\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "723717988 205757169 291917494\n", "output": "205757169\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
18
Solve the following coding problem using the programming language python: Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this character. Petya wants to get strings s and t empty and string u lexicographically minimal. You should write a program that will help Petya win the game. -----Input----- First line contains non-empty string s (1 ≤ |s| ≤ 10^5), consisting of lowercase English letters. -----Output----- Print resulting string u. -----Examples----- Input cab Output abc Input acdb Output abdc The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import deque S = input() mn = [ 300 for i in range( len( S ) ) ] for i in range( len( S ) - 1, -1, -1 ): if i == len( S ) - 1: mn[ i ] = ord( S[ i ] ) else: mn[ i ] = min( mn[ i + 1 ], ord( S[ i ] ) ) ans = "" dq = deque() for i in range( len( S ) ): dq.append( ord( S[ i ] ) ) while len( dq ) and ( i + 1 == len( S ) or dq[ len( dq ) - 1 ] <= mn[ i + 1 ] ): ans += chr( dq[ len( dq ) - 1 ] ) dq.pop() print( ans ) ```
vfc_9826
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/797/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "cab\n", "output": "abc\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
19
Solve the following coding problem using the programming language python: Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by $1$. If he manages to finish the level successfully then the number of clears increases by $1$ as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears). Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be. So he peeked at the stats $n$ times and wrote down $n$ pairs of integers — $(p_1, c_1), (p_2, c_2), \dots, (p_n, c_n)$, where $p_i$ is the number of plays at the $i$-th moment of time and $c_i$ is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down). Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level. Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct. Help him to check the correctness of his records. For your convenience you have to answer multiple independent test cases. -----Input----- The first line contains a single integer $T$ $(1 \le T \le 500)$ — the number of test cases. The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the number of moments of time Polycarp peeked at the stats. Each of the next $n$ lines contains two integers $p_i$ and $c_i$ ($0 \le p_i, c_i \le 1000$) — the number of plays and the number of clears of the level at the $i$-th moment of time. Note that the stats are given in chronological order. -----Output----- For each test case print a single line. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES". Otherwise, print "NO". You can print each letter in any case (upper or lower). -----Example----- Input 6 3 0 0 1 1 1 2 2 1 0 1000 3 4 10 1 15 2 10 2 15 2 1 765 432 2 4 4 4 3 5 0 0 1 0 1 0 1 0 1 0 Output NO YES NO YES NO YES -----Note----- In the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened. The second test case is a nice example of a Super Expert level. In the third test case the number of plays decreased, which is impossible. The fourth test case is probably an auto level with a single jump over the spike. In the fifth test case the number of clears decreased, which is also impossible. Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n = int(input()) lastP = 0 lastC = 0 works = True for _ in range(n): p, c = list(map(int, input().split())) pDiff = p-lastP cDiff = c-lastC if 0 <= cDiff <= pDiff: pass else: works = False lastP = p lastC = c if works: print('YES') else: print('NO') ```
vfc_9830
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1334/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n", "output": "NO\nYES\nNO\nYES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n10 1\n11 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n5 2\n8 6\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n43 34\n44 35\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
20
Solve the following coding problem using the programming language python: Karen is getting ready for a new school day! [Image] It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome? Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50. -----Input----- The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59). -----Output----- Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome. -----Examples----- Input 05:39 Output 11 Input 13:31 Output 0 Input 23:59 Output 1 -----Note----- In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome. In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome. In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() h = int(s[:2]) m = int(s[3:]) def ispalin(h, m): s = "%02d:%02d"%(h,m) return s == s[::-1] for d in range(999999): if ispalin(h, m): print(d) break m+= 1 if m == 60: h = (h+1)%24 m = 0 ```
vfc_9834
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/816/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "05:39\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13:31\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "23:59\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13:32\n", "output": "69\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "14:40\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "14:00\n", "output": "41\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
21
Solve the following coding problem using the programming language python: Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. -----Input----- The first line of the input contains a single integer n (2 ≤ n ≤ 100) — the size of the permutation. The second line of the input contains n distinct integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n), where a_{i} is equal to the element at the i-th position. -----Output----- Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. -----Examples----- Input 5 4 5 1 3 2 Output 3 Input 7 1 6 5 3 4 7 2 Output 6 Input 6 6 5 4 3 2 1 Output 5 -----Note----- In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python read = lambda: list(map(int, input().split())) n = int(input()) a = list(read()) x, y = a.index(1), a.index(n) ans = max(x, y, n - x - 1, n - y - 1) print(ans) ```
vfc_9838
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/676/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 5 1 3 2\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
22
Solve the following coding problem using the programming language python: Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. [Image] English alphabet You are given a string s. Check if the string is "s-palindrome". -----Input----- The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters. -----Output----- Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise. -----Examples----- Input oXoxoXo Output TAK Input bod Output TAK Input ER Output NIE The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys, math s=input() pal='AHIMOoTUVvWwXxY' n=len(s) l=0 r=n-1 flag=True fir='pq' sec='bd' while l<=r: if s[l]==s[r] and s[l] in pal: l+=1 r-=1 continue elif s[l]==s[r]: flag=False break elif (s[l] in fir) and (s[r] in fir): l+=1 r-=1 continue elif (s[l] in sec) and (s[r] in sec): l+=1 r-=1 continue else: flag=False break if flag: print('TAK') else: print('NIE') ```
vfc_9842
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/691/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "oXoxoXo\n", "output": "TAK\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "bod\n", "output": "TAK\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
23
Solve the following coding problem using the programming language python: You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second line contains integer b (1 ≤ b ≤ 10^18). Numbers don't have leading zeroes. It is guaranteed that answer exists. -----Output----- Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number a. It should be a permutation of digits of a. -----Examples----- Input 123 222 Output 213 Input 3921 10000 Output 9321 Input 4940 5000 Output 4940 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a = list(input()) b = int(input()) a.sort() a = a[::-1] prefix = "" while(len(a) > 0): for i in range(len(a)): num = prefix + a[i] + "".join(sorted(a[:i] + a[i + 1:])) if (int(num) <= b): prefix += a[i] a = a[:i] + a[i+1:] break print(prefix) ```
vfc_9846
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/915/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "123\n222\n", "output": "213\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
24
Solve the following coding problem using the programming language python: Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = [ [ c for c in input() ] for i in range(10) ] def win(): for i in range(10): for j in range(10): ok = True for k in range(5): if j+k>9: ok = False elif s[i][j+k] != 'X': ok = False if ok: return True ok = True for k in range(5): if i+k>9: ok = False elif s[i+k][j] != 'X': ok = False if ok: return True ok = True for k in range(5): if j+k>9 or i+k>9: ok = False elif s[i+k][j+k] != 'X': ok = False if ok: return True ok = True for k in range(5): if i-k<0 or j+k>9: ok = False elif s[i-k][j+k] != 'X': ok = False if ok: return True return False for i in range(10): for j in range(10): if s[i][j]=='.': s[i][j] = 'X' if win(): print('YES') return s[i][j] = '.' print('NO') ```
vfc_9850
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/825/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "XO........\n.XO.......\n..XO......\n....O.....\n....X.....\n..........\n..........\n..........\n..........\n..........\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "..X....XX.\n..........\n..........\nX..O..OO..\n....O.....\nX..O.....O\nO....OX..X\n..X....X.X\nO........O\n..........\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
26
Solve the following coding problem using the programming language python: Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point. Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to earn a lot of cheese. He will hand the three numbers x, y and z to Rat Kwesh, and Rat Kwesh will pick one of the these twelve options: a_1 = x^{y}^{z}; a_2 = x^{z}^{y}; a_3 = (x^{y})^{z}; a_4 = (x^{z})^{y}; a_5 = y^{x}^{z}; a_6 = y^{z}^{x}; a_7 = (y^{x})^{z}; a_8 = (y^{z})^{x}; a_9 = z^{x}^{y}; a_10 = z^{y}^{x}; a_11 = (z^{x})^{y}; a_12 = (z^{y})^{x}. Let m be the maximum of all the a_{i}, and c be the smallest index (from 1 to 12) such that a_{c} = m. Rat's goal is to find that c, and he asks you to help him. Rat Kwesh wants to see how much cheese he gets, so he you will have to print the expression corresponding to that a_{c}. -----Input----- The only line of the input contains three space-separated real numbers x, y and z (0.1 ≤ x, y, z ≤ 200.0). Each of x, y and z is given with exactly one digit after the decimal point. -----Output----- Find the maximum value of expression among x^{y}^{z}, x^{z}^{y}, (x^{y})^{z}, (x^{z})^{y}, y^{x}^{z}, y^{z}^{x}, (y^{x})^{z}, (y^{z})^{x}, z^{x}^{y}, z^{y}^{x}, (z^{x})^{y}, (z^{y})^{x} and print the corresponding expression. If there are many maximums, print the one that comes first in the list. x^{y}^{z} should be outputted as x^y^z (without brackets), and (x^{y})^{z} should be outputted as (x^y)^z (quotes for clarity). -----Examples----- Input 1.1 3.4 2.5 Output z^y^x Input 2.0 2.0 2.0 Output x^y^z Input 1.9 1.8 1.7 Output (x^y)^z The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from math import log from decimal import Decimal s = ['x^y^z', 'x^z^y', '(x^y)^z', 'y^x^z', 'y^z^x', '(y^x)^z', 'z^x^y', 'z^y^x', '(z^x)^y'] x, y, z = list(map(Decimal, input().split())) f = [] f += [(Decimal(log(x)) * (y ** z), 0)] f += [(Decimal(log(x)) * (z ** y), -1)] f += [(Decimal(log(x)) * (y * z), -2)] f += [(Decimal(log(y)) * (x ** z), -3)] f += [(Decimal(log(y)) * (z ** x), -4)] f += [(Decimal(log(y)) * (x * z), -5)] f += [(Decimal(log(z)) * (x ** y), -6)] f += [(Decimal(log(z)) * (y ** x), -7)] f += [(Decimal(log(z)) * (x * y), -8)] f.sort() print(s[-f[-1][1]]) ```
vfc_9858
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/621/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1.1 3.4 2.5\n", "output": "z^y^x\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2.0 2.0 2.0\n", "output": "x^y^z\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1.9 1.8 1.7\n", "output": "(x^y)^z\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
28
Solve the following coding problem using the programming language python: The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. -----Input----- The first line contains single integer n (1 ≤ n ≤ 10^5) — the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct. -----Output----- In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6. -----Examples----- Input 5 01 0 2 1 2extra 0 3 1 99 0 Output 4 move 3 1 move 01 5 move 2extra 4 move 99 3 Input 2 1 0 2 1 Output 3 move 1 3 move 2 1 move 3 2 Input 5 1 0 11 1 111 0 1111 1 11111 0 Output 5 move 1 5 move 11 1 move 1111 2 move 111 4 move 11111 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) t = [1] + [0] * n b, a = d = [], [] h, s = [], [] for i in range(n): f, k = input().split() d[int(k)].append(f) m = len(a) for i in a: if i.isdigit() and i[0] != '0': j = int(i) if 0 < j <= m: t[j] = 1 elif m < j <= n: t[j] = -1 else: s.append(i) else: s.append(i) for i in b: if i.isdigit() and i[0] != '0': j = int(i) if m < j <= n: t[j] = 1 elif 0 < j <= m: t[j] = -1 else: s.append(i) else: s.append(i) x = [j for j in range(1, m + 1) if t[j] < 0] y = [j for j in range(m + 1, n + 1) if t[j] < 0] u = [j for j in range(1, m + 1) if not t[j]] v = [j for j in range(m + 1, n + 1) if not t[j]] if not s and (x or y): s = ['0'] if y: i = y.pop() v.append(i) else: i = x.pop() u.append(i) h.append(str(i) + ' 0') t[i] = 0 while x or y: if v and x: i = x.pop() j = v.pop() t[j] = 1 h.append(str(i) + ' ' + str(j)) u.append(i) else: u, v, x, y = v, u, y, x k = 1 for j in s: while t[k] == 1: k += 1 h.append(j + ' ' + str(k)) k += 1 d = '\nmove ' print(str(len(h)) + d + d.join(h) if h else 0) ```
vfc_9866
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/858/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 0\n2 1\n", "output": "3\nmove 1 07x45l\nmove 2 1\nmove 07x45l 2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
29
Solve the following coding problem using the programming language python: Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits. -----Input----- You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. -----Output----- Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. -----Examples----- Input 000000 Output 0 Input 123456 Output 2 Input 111000 Output 1 -----Note----- In the first example the ticket is already lucky, so the answer is 0. In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required. In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x=int(input()) def s(a): r=0 while a>0: r+=a%10 a//=10 return r def d(a,b): r=0 for i in range(6): if a%10!=b%10: r += 1 a//=10 b//=10 return r c=6 for i in range(1000000): if s(i%1000)==s(i//1000): c=min(c,d(x,i)) print(c) ```
vfc_9870
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/845/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "000000\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123456\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "111000\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "120111\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
30
Solve the following coding problem using the programming language python: The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the $x$-mouse is unknown. You are responsible to catch the $x$-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the $x$-mouse enters a trapped room, it immediately gets caught. And the only observation you made is $\text{GCD} (x, m) = 1$. -----Input----- The only line contains two integers $m$ and $x$ ($2 \le m \le 10^{14}$, $1 \le x < m$, $\text{GCD} (x, m) = 1$) — the number of rooms and the parameter of $x$-mouse. -----Output----- Print the only integer — minimum number of traps you need to install to catch the $x$-mouse. -----Examples----- Input 4 3 Output 3 Input 5 2 Output 2 -----Note----- In the first example you can, for example, put traps in rooms $0$, $2$, $3$. If the $x$-mouse starts in one of this rooms it will be caught immediately. If $x$-mouse starts in the $1$-st rooms then it will move to the room $3$, where it will be caught. In the second example you can put one trap in room $0$ and one trap in any other room since $x$-mouse will visit all rooms $1..m-1$ if it will start in any of these rooms. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from math import gcd def powmod(a,b,m): a%=m r=1 while b: if b&1:r=r*a%m a=a*a%m b>>=1 return r def f(n): r=[] if (n&1)==0: e=0 while (n&1)==0:n>>=1;e+=1 yield (2,e) p=3 while n>1: if p*p>n:p=n if n%p: p+=2 continue e=1;n//=p while n%p==0:n//=p;e+=1 yield (p,e) p+=2 return r m,x=map(int,input().split()) p=2 r=[(1,1)] for p,e in f(m): assert e>=1 ord=p-1 assert powmod(x,ord,p)==1 for pi,ei in f(p-1): while ord % pi == 0 and powmod(x,ord//pi,p)==1: ord//=pi ords=[(1,1),(ord,p-1)] q=p for v in range(2,e+1): q*=p if powmod(x,ord,q)!=1:ord*=p assert powmod(x,ord,q)==1 ords.append((ord,q//p*(p-1))) r=[(a//gcd(a,c)*c,b*d) for a,b in r for c,d in ords] print(sum(y//x for x,y in r)) ```
vfc_9874
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1027/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
31
Solve the following coding problem using the programming language python: ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland. In Udayland, there are 2^{n} days in a year. ZS the Coder wants to interview k people from Udayland, each of them has birthday in one of 2^{n} days (each day with equal probability). He is interested in the probability of at least two of them have the birthday at the same day. ZS the Coder knows that the answer can be written as an irreducible fraction $\frac{A}{B}$. He wants to find the values of A and B (he does not like to deal with floating point numbers). Can you help him? -----Input----- The first and only line of the input contains two integers n and k (1 ≤ n ≤ 10^18, 2 ≤ k ≤ 10^18), meaning that there are 2^{n} days in a year and that ZS the Coder wants to interview exactly k people. -----Output----- If the probability of at least two k people having the same birthday in 2^{n} days long year equals $\frac{A}{B}$ (A ≥ 0, B ≥ 1, $\operatorname{gcd}(A, B) = 1$), print the A and B in a single line. Since these numbers may be too large, print them modulo 10^6 + 3. Note that A and B must be coprime before their remainders modulo 10^6 + 3 are taken. -----Examples----- Input 3 2 Output 1 8 Input 1 3 Output 1 1 Input 4 3 Output 23 128 -----Note----- In the first sample case, there are 2^3 = 8 days in Udayland. The probability that 2 people have the same birthday among 2 people is clearly $\frac{1}{8}$, so A = 1, B = 8. In the second sample case, there are only 2^1 = 2 days in Udayland, but there are 3 people, so it is guaranteed that two of them have the same birthday. Thus, the probability is 1 and A = B = 1. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python m = 10** 6 + 3 n, k = list(map(int, input().split())) p = 1 for i in range(n): p *= 2 if p > k: break if p < k: print('1 1') return gcd = tmp = k - 1 while tmp: gcd -= tmp % 2 tmp //= 2 b = pow(2, (k - 1) * n - gcd, m) a = 1 mem = [-1]*100 for i in range(1, k): cnt = 0 while i % 2 == 0: i //= 2 cnt += 1 if mem[cnt] == -1: mem[cnt] = pow(2, n - cnt, m) a = a * (mem[cnt] - i + m) % m if a == 0: break print((b - a + m) % m, b) ```
vfc_9878
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/711/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n", "output": "1 8", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n", "output": "1 1", "type": "stdin_stdout" } ] }
apps
verifiable_code
32
Solve the following coding problem using the programming language python: In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers. Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move t_{i} kilometers in the direction represented by a string dir_{i} that is one of: "North", "South", "West", "East". Limak isn’t sure whether the description is valid. You must help him to check the following conditions: If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line. -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer t_{i} and a string dir_{i} (1 ≤ t_{i} ≤ 10^6, $\operatorname{dir}_{i} \in \{\text{North, South, West, East} \}$) — the length and the direction of the i-th part of the journey, according to the description Limak got. -----Output----- Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes. -----Examples----- Input 5 7500 South 10000 East 3500 North 4444 West 4000 North Output YES Input 2 15000 South 4000 East Output NO Input 5 20000 South 1000 North 1000000 West 9000 North 10000 North Output YES Input 3 20000 South 10 East 20000 North Output NO Input 2 1000 North 1000 South Output NO Input 4 50 South 50 North 15000 South 15000 North Output YES -----Note----- Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole. [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python """ Codeforces Good Bye 2016 Contest Problem B Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def main(): latitude = 0 n, = read() for i in range(n): l, d = read(str) l = int(l) if latitude == 0: if d != "South": return "NO" if latitude == 20000: if d != "North": return "NO" if d == "South": latitude += l elif d == "North": latitude -= l if not (0 <= latitude <= 20000): return "NO" if latitude != 0: return "NO" return "YES" #################################################### HELPERS def read(callback=int): return list(map(callback, input().strip().split())) def write(value, end="\n"): if value is None: return try: if not isinstance(value, str): value = " ".join(map(str, value)) except: pass print(value, end=end) write(main()) ```
vfc_9882
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/750/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n15000 South\n4000 East\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
33
Solve the following coding problem using the programming language python: You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0. -----Input----- The only line contains six integers a_1, b_1, a_2, b_2, L, R (0 < a_1, a_2 ≤ 2·10^9, - 2·10^9 ≤ b_1, b_2, L, R ≤ 2·10^9, L ≤ R). -----Output----- Print the desired number of integers x. -----Examples----- Input 2 0 3 3 5 21 Output 3 Input 2 4 3 0 6 17 Output 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys, collections def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a // gcd(a, b) * b def extgcd(a, b): if b == 0: return 1, 0 x, y = extgcd(b, a % b) return y, x - a // b * y def prime_factor(n): res = collections.defaultdict(int) i = 2 while i * i <= n: cnt = 0 while n % i == 0: n //= i cnt += 1 if cnt > 0: res[i] = cnt i += 1 if n != 1: res[n] = 1 return res def modinv(a, mod): if a == 0: return -1 if gcd(a, mod) != 1: return -1 return extgcd(a, mod)[0] % mod def normalize(a1, a2): p1 = prime_factor(a1) p2 = prime_factor(a2) keys = list(set(p1.keys()) | set(p2.keys())) r1 = 1 r2 = 1 for k in keys: if p1[k] >= p2[k]: r1 *= k ** p1[k] else: r2 *= k ** p2[k] return r1, r2 def solve(a1, b1, a2, b2): g = gcd(a1, a2) if (b1 - b2) % g != 0: return -1 a1, a2 = normalize(a1, a2) u = b1 % a1 inv = modinv(a1, a2) v = (b2 - u) * inv % a2 return u + v * a1 def f(x0, T, v): ok = 10 ** 36 ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if x0 + T * mid >= v: ok = mid else: ng = mid return ok a1, b1, a2, b2, L, R = map(int, input().split()) T = lcm(a1, a2) x0 = solve(a1, b1, a2, b2) if x0 == -1: print(0) return x0 -= T * 10 ** 36 ok = 10 ** 60 ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 val = x0 + T * mid k = (val - b1) // a1 l = (val - b2) // a2 if k >= 0 and l >= 0: ok = mid else: ng = mid x0 += ok * T # L <= x0 + kT < R + 1 ans = f(x0, T, R + 1) - f(x0, T, L) print(ans) ```
vfc_9886
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/710/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 0 3 3 5 21\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 3 0 6 17\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0 4 2 -39 -37\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 9 3 11 49 109\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 81 5 72 -1761 501\n", "output": "28\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 -89 20 67 8771 35222\n", "output": "661\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
34
Solve the following coding problem using the programming language python: It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: Each piece of each cake is put on some plate; Each plate contains at least one piece of cake; No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake. Help Ivan to calculate this number x! -----Input----- The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. -----Output----- Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake. -----Examples----- Input 5 2 3 Output 1 Input 4 7 10 Output 3 -----Note----- In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, a, b = map(int, input().split()) ans = 0 for i in range(1, n): ans = max(ans, min(a // i, b // (n - i))) print(ans) ```
vfc_9890
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/911/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 7 10\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100 100\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 100 3\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
35
Solve the following coding problem using the programming language python: The flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n,m=list(map(int,input().split())) f=[input() for _ in range(n)] def clr(ss): cc = None for s in ss: for c in s: if cc is None: cc = c elif cc != c: return None return cc if n%3 == 0: s = set() for i in range(0,n,n//3): ret = clr(f[i:i+n//3]) if ret is None: continue s.add(ret) if len(s) == 3: print('YES') return if m%3 == 0: s = set() for j in range(0,m,m//3): ff = [] for i in f: ff.append(i[j:j+m//3]) ret = clr(ff) if ret is None: continue s.add(ret) if len(s) == 3: print('YES') return print('NO') ```
vfc_9894
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/837/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\nBRG\nBRG\nBRG\nBRG\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
36
Solve the following coding problem using the programming language python: Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: [Image] [Image] Ayrat is searching through the field. He started at point (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves. -----Input----- The only line of the input contains integer n (0 ≤ n ≤ 10^18) — the number of Ayrat's moves. -----Output----- Print two integers x and y — current coordinates of Ayrat coordinates. -----Examples----- Input 3 Output -2 0 Input 7 Output 3 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def f(n): left, right = -1, n + 1 while right - left > 1: mid = (left + right) // 2 x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1) if x > n: right = mid else: left = mid if left >= 0: mid = left x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1) n -= x return (n, left + 1) def main(): n = int(input()) n, k = f(n) x = k y = -2 * k d = [k + 1] * 6 d[1] -= 1 dx = [1, -1, -2, -1, 1, 2] dy = [2, 2, 0, -2, -2, 0] for i in range(6): x += min(d[i], n) * dx[i] y += min(d[i], n) * dy[i] n = max(0, n - d[i]) print(x, y) main() ```
vfc_9898
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/615/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "-2 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", "output": "3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "39\n", "output": "5 6\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
37
Solve the following coding problem using the programming language python: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible. -----Input----- The first line of the input contains three integers a, b, c (1 ≤ a, b ≤ 100, 1 ≤ c ≤ 10 000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. -----Output----- Print "Yes" (without quotes) if Dante can deal exactly c damage to the shield and "No" (without quotes) otherwise. -----Examples----- Input 4 6 15 Output No Input 3 2 7 Output Yes Input 6 11 6 Output Yes -----Note----- In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, b, c = list(map(int, input().split())) p = [0] * 100000 p[0] = 1 p[a] = 1 p[b] = 1 for i in range(c + 1): if p[i]: p[i + a] = 1 p[i + b] = 1 if p[c]: print('Yes') else: print('No') ```
vfc_9902
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/633/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6 15\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 7\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 11 6\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 12 15\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 10\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6 7\n", "output": "No\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
38
Solve the following coding problem using the programming language python: Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track. Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers. Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1, inclusively. [Image] Consider an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence [2, 4, 6], and Sasha writes down [1, 5, 7]. There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks. Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above. -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100) — the number of barriers on a track and its length. The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to L - 1 inclusively. The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to L - 1 inclusively. -----Output----- Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes). -----Examples----- Input 3 8 2 4 6 1 5 7 Output YES Input 4 9 2 3 5 8 0 1 3 6 Output YES Input 2 4 1 3 1 2 Output NO -----Note----- The first test is analyzed in the statement. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): n, l = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) x.append(x[0] + l) y.append(y[0] + l) a = [x[i + 1] - x[i] for i in range(n)] b = [y[i + 1] - y[i] for i in range(n)] for i in range(n): if (a == b[i:] + b[:i]): print("YES") return print("NO") main() ```
vfc_9906
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/761/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 8\n2 4 6\n1 5 7\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 9\n2 3 5 8\n0 1 3 6\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
39
Solve the following coding problem using the programming language python: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1 \leq l \leq r \leq |s|$) of a string $s = s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l + 1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into? -----Input----- The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. -----Output----- If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique. -----Examples----- Input mew Output 3 Input wuffuw Output 5 Input qqqqqqqq Output 0 -----Note----- "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() mx = 0 n = len(s) for l in range(n): for r in range(l, n): if s[l:r+1] != s[l:r+1][::-1]: mx = max(mx, r - l + 1) print(mx) ```
vfc_9910
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/981/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "mew\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "wuffuw\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "qqqqqqqq\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ijvji\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "iiiiiii\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
40
Solve the following coding problem using the programming language python: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants. Each of the next n lines contains two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. -----Output----- If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". -----Examples----- Input 6 3060 3060 2194 2194 2876 2903 2624 2624 3007 2991 2884 2884 Output rated Input 4 1500 1500 1300 1300 1200 1200 1400 1400 Output unrated Input 5 3123 3123 2777 2777 2246 2246 2246 2246 1699 1699 Output maybe -----Note----- In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python '''input 5 3123 3123 2777 2777 2246 2246 2246 2246 1699 1699 ''' n = int(input()) x = [] f = 0 for _ in range(n): a, b = list(map(int, input().split())) if a != b: f = 1 x.append(a) if f == 1: print("rated") elif sorted(x)[::-1] == x: print("maybe") else: print("unrated") ```
vfc_9914
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/807/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "output": "rated\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "output": "unrated\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n", "output": "maybe\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n1 1\n", "output": "maybe\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
41
Solve the following coding problem using the programming language python: You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. -----Input----- The first line contains integer n (1 ≤ n ≤ 2·10^5) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 10^9 ≤ a_{i} ≤ 10^9). -----Output----- Print the sequence d_0, d_1, ..., d_{n} - 1, where d_{i} is the difference of indices between i and nearest j such that a_{j} = 0. It is possible that i = j. -----Examples----- Input 9 2 1 0 3 0 0 3 2 4 Output 2 1 0 1 0 0 1 2 3 Input 5 0 1 2 3 4 Output 0 1 2 3 4 Input 7 5 6 0 1 -2 3 4 Output 2 1 0 1 2 3 4 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python inf = 10 ** 6 n = int(input()) a = list(map(int, input().split())) dist = [inf] * n for i in range(len(a)): if not a[i]: dist[i] = 0 cur = 1 i1 = i while i1 - 1 > - 1 and a[i1 - 1] != 0: dist[i1 - 1] = min(dist[i1 - 1], cur) i1 -= 1 cur += 1 i1 = i cur = 1 while i1 + 1 < n and a[i1 + 1] != 0: dist[i1 + 1] = min(dist[i1 + 1], cur) i1 += 1 cur += 1 print(*dist) ```
vfc_9918
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/803/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n2 1 0 3 0 0 3 2 4\n", "output": "2 1 0 1 0 0 1 2 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 1 2 3 4\n", "output": "0 1 2 3 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n5 6 0 1 -2 3 4\n", "output": "2 1 0 1 2 3 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 0\n", "output": "0 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 1\n", "output": "0 1 ", "type": "stdin_stdout" } ] }
apps
verifiable_code
42
Solve the following coding problem using the programming language python: You are given a binary string $s$. Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring. The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that $s$ is a substring of this cyclical shift of $t$. For example, the cyclical string "000111" contains substrings "001", "01110" and "10", but doesn't contain "0110" and "10110". Two cyclical strings are called different if they differ from each other as strings. For example, two different strings, which differ from each other by a cyclical shift, are still considered different cyclical strings. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 40$) — the length of the target string $t$. The next line contains the string $s$ ($1 \le |s| \le n$) — the string which must be a substring of cyclical string $t$. String $s$ contains only characters '0' and '1'. -----Output----- Print the only integer — the number of distinct cyclical binary strings $t$, which contain $s$ as a substring. -----Examples----- Input 2 0 Output 3 Input 4 1010 Output 2 Input 20 10101010101010 Output 962 -----Note----- In the first example, there are three cyclical strings, which contain "0" — "00", "01" and "10". In the second example, there are only two such strings — "1010", "0101". The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n=int(input()) s=[c=='1' for c in input()] m=len(s) z=[[0,0]] for c in s: ind = z[-1][c] z[-1][c] = len(z) z.append(z[ind][:]) assert(len(z) == m+1) z[m][0] = z[m][1] = m # make it sticky # how many things match directly dp = [0 for _ in range(m+1)] dp[0] = 1 for i in range(n): ndp = [0 for _ in range(m+1)] for i in range(m+1): ndp[z[i][0]] += dp[i] ndp[z[i][1]] += dp[i] dp = ndp res = dp[m] for k in range(1, m): s0 = 0 for c in s[-k:]: s0 = z[s0][c] dp = [0 for _ in range(m+1)] dp[s0] = 1 for i in range(n - k): ndp = [0 for _ in range(m+1)] for i in range(m+1): ndp[z[i][0]] += dp[i] ndp[z[i][1]] += dp[i] dp = ndp for s1 in range(m): # skip m v = dp[s1] for c in s[-k:]: if s1 == m: v = 0 s1 = z[s1][c] if s1 == m: res += v print(res) ```
vfc_9922
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1038/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1010\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n10101010101010\n", "output": "962", "type": "stdin_stdout" } ] }
apps
verifiable_code
43
Solve the following coding problem using the programming language python: You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π. -----Input----- First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors. The i-th of the following n lines contains two integers x_{i} and y_{i} (|x|, |y| ≤ 10 000, x^2 + y^2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions). -----Output----- Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any. -----Examples----- Input 4 -1 0 0 -1 1 0 1 1 Output 3 4 Input 6 -1 0 0 -1 1 0 1 1 -4 -5 -4 -6 Output 6 5 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from math import * # stores counterclockwise angle between vector (1,0) and each vector in a a = [] n = int(input()) for i in range(n): x,y = list(map(int,input().split())) # calculate counterclockwise angle between (1,0) and this vector t = acos(x/sqrt(x**2+y**2)) a.append((i+1,[2*pi-t,t][y>=0],x,y)) cmp = lambda x:x[1] a = sorted(a,key=cmp) # construct pairs for adjacent vectors b = [] for i in range(n): i1,i2 = a[i][0],a[(i+1)%n][0] x1,y1 = a[i][2:] x2,y2 = a[(i+1)%n][2:] inner_prod = x1*x2 + y1*y2 inner_prod *= abs(inner_prod) norm_prod = ((x1**2+y1**2)*(x2**2+y2**2)) b.append((i1,i2,inner_prod,norm_prod)) # find the nearest vector better = lambda p1,p2: p1[2]*p2[3]>p2[2]*p1[3] ans = b[-1] for i in range(n): if better(b[i],ans): ans = b[i] print(ans[0],ans[1]) ```
vfc_9926
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/598/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n-1 0\n0 -1\n1 0\n1 1\n", "output": "3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n", "output": "5 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7\n", "output": "1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2\n", "output": "13 16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n351 -4175\n-328 -657\n", "output": "2 1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
44
Solve the following coding problem using the programming language python: Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers. Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station. To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a < b). Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot. -----Input----- The first line contains 5 positive integers d, k, a, b, t (1 ≤ d ≤ 10^12; 1 ≤ k, a, b, t ≤ 10^6; a < b), where: d — the distance from home to the post office; k — the distance, which car is able to drive before breaking; a — the time, which Vasiliy spends to drive 1 kilometer on his car; b — the time, which Vasiliy spends to walk 1 kilometer on foot; t — the time, which Vasiliy spends to repair his car. -----Output----- Print the minimal time after which Vasiliy will be able to reach the post office. -----Examples----- Input 5 2 1 4 10 Output 14 Input 5 2 1 4 5 Output 13 -----Note----- In the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds. In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python d, k, a, b, t = list(map(int, input().split())) t1 = d * b t2 = d * a + ((d - 1) // k) * t t3 = max(0, d - k) * b + min(k, d) * a dd = d % k d1 = d - dd t4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b print(min([t1, t2, t3, t4])) ```
vfc_9930
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/702/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 1 4 10\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 1 4 5\n", "output": "13\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
45
Solve the following coding problem using the programming language python: You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them. If there is no possible sequence then output -1. -----Input----- The first line consists of two numbers n and k (1 ≤ n, k ≤ 10^10). -----Output----- If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. -----Examples----- Input 6 3 Output 1 2 3 Input 8 2 Output 2 6 Input 5 3 Output -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, k = map(int, input().split()) div = [] i = 1 n1 = n while i * i <= n: if n % i == 0: div.append(i) div.append(n // i) i += 1 div.sort() mx = -1 for i in range(len(div)): a = div[i] * k * (k + 1) // 2 if a <= n: mx = div[i] if mx == -1: print(-1) else: for i in range(k - 1): print(mx * (i + 1), end= " ") print(n - mx * k * (k - 1) // 2) ```
vfc_9934
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/803/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n", "output": "1 2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 2\n", "output": "2 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
46
Solve the following coding problem using the programming language python: After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5. Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and $(x + y) \operatorname{mod} 5$ equals 0. As usual, Alyona has some troubles and asks you to help. -----Input----- The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000). -----Output----- Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5. -----Examples----- Input 6 12 Output 14 Input 11 14 Output 31 Input 1 5 Output 1 Input 3 8 Output 5 Input 5 7 Output 7 Input 21 21 Output 88 -----Note----- Following pairs are suitable in the first sample case: for x = 1 fits y equal to 4 or 9; for x = 2 fits y equal to 3 or 8; for x = 3 fits y equal to 2, 7 or 12; for x = 4 fits y equal to 1, 6 or 11; for x = 5 fits y equal to 5 or 10; for x = 6 fits y equal to 4 or 9. Only the pair (1, 4) is suitable in the third sample case. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python ct=0 a, b = list(map(int, input().split(' '))) x=[0]*5 for i in range(1, b+1): x[i%5]+=1 for i in range(1, a+1): ct+=x[(0-i)%5] print(ct) ```
vfc_9938
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/682/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 12\n", "output": "14\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
47
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarray of $a$ and multiply all values contained in this subarray by $x$. You want to maximize the beauty of array after applying at most one such operation. -----Input----- The first line contains two integers $n$ and $x$ ($1 \le n \le 3 \cdot 10^5, -100 \le x \le 100$) — the length of array $a$ and the integer $x$ respectively. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) — the array $a$. -----Output----- Print one integer — the maximum possible beauty of array $a$ after multiplying all values belonging to some consecutive subarray $x$. -----Examples----- Input 5 -2 -3 8 -2 1 -6 Output 22 Input 12 -3 1 3 3 7 1 3 3 7 1 3 3 7 Output 42 Input 5 10 -1 -2 -3 -4 -5 Output 0 -----Note----- In the first test case we need to multiply the subarray [-2, 1, -6], and the array becomes [-3, 8, 4, -2, 12] with beauty 22 ([-3, 8, 4, -2, 12]). In the second test case we don't need to multiply any subarray at all. In the third test case no matter which subarray we multiply, the beauty of array will be equal to 0. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python N, X = list(map(int, input().split())) A = [int(a) for a in input().split()] dp = [[0]*4 for _ in range(N+1)] for i in range(1, N+1): dp[i][0] = max(dp[i-1][0] + A[i-1], 0) dp[i][1] = max(dp[i-1][1] + A[i-1] * X, dp[i][0]) dp[i][2] = max(dp[i-1][2] + A[i-1], dp[i][1]) dp[i][3] = max(dp[i-1][3], dp[i][2]) print(dp[N][3]) ```
vfc_9942
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1155/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 -2\n-3 8 -2 1 -6\n", "output": "22\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 -3\n1 3 3 7 1 3 3 7 1 3 3 7\n", "output": "42\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
48
Solve the following coding problem using the programming language python: Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success? Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number. -----Input----- The single line contains integers n, m and k (1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). -----Output----- Print the k-th largest number in a n × m multiplication table. -----Examples----- Input 2 2 2 Output 2 Input 2 3 4 Output 3 Input 1 10 5 Output 5 -----Note----- A 2 × 3 multiplication table looks like this: 1 2 3 2 4 6 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): from math import sqrt m, n, k = list(map(int, input().split())) if n < m: n, m = m, n lo, hi = 1, k + 1 while lo + 1 < hi: mid = (lo + hi) // 2 t = mid - 1 v = min(int(sqrt(t)), m) tn, tm = (t - 1) // m, t // n vv = [t // i for i in range(tm + 1, v + 1)] if t // n * (n + m) + sum(vv) * 2 + max(min((tn - tm), len(vv)) * m, 0) - v * v - sum( vv[:max(min(tn - tm, len(vv)), 0)]) < k: lo = mid else: hi = mid print(lo) def __starting_point(): main() __starting_point() ```
vfc_9946
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/448/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 4\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
49
Solve the following coding problem using the programming language python: Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The first and only line contains integer $k$ ($1 \le k \le 10^{12}$) — the position to process ($1$-based index). -----Output----- Print the $k$-th digit of the resulting infinite sequence. -----Examples----- Input 7 Output 7 Input 21 Output 5 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python k = int(input()) if k<=9: print(k) else: num_arr = [9*(i+1)* 10**i for i in range(11)] index = 0 while True: if k<=num_arr[index]: break else: k -= num_arr[index] index += 1 digit = index+1 k += digit-1 num = k//digit offset = k%digit string_num = str(10**(digit-1)+ num-1) print(string_num[offset]) ```
vfc_9950
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1177/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "7\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
50
Solve the following coding problem using the programming language python: Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market! In the morning, there are $n$ opportunities to buy shares. The $i$-th of them allows to buy as many shares as you want, each at the price of $s_i$ bourles. In the evening, there are $m$ opportunities to sell shares. The $i$-th of them allows to sell as many shares as you want, each at the price of $b_i$ bourles. You can't sell more shares than you have. It's morning now and you possess $r$ bourles and no shares. What is the maximum number of bourles you can hold after the evening? -----Input----- The first line of the input contains three integers $n, m, r$ ($1 \leq n \leq 30$, $1 \leq m \leq 30$, $1 \leq r \leq 1000$) — the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now. The next line contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \leq s_i \leq 1000$); $s_i$ indicates the opportunity to buy shares at the price of $s_i$ bourles. The following line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \leq b_i \leq 1000$); $b_i$ indicates the opportunity to sell shares at the price of $b_i$ bourles. -----Output----- Output a single integer — the maximum number of bourles you can hold after the evening. -----Examples----- Input 3 4 11 4 2 5 4 4 5 4 Output 26 Input 2 2 50 5 7 4 2 Output 50 -----Note----- In the first example test, you have $11$ bourles in the morning. It's optimal to buy $5$ shares of a stock at the price of $2$ bourles in the morning, and then to sell all of them at the price of $5$ bourles in the evening. It's easy to verify that you'll have $26$ bourles after the evening. In the second example test, it's optimal not to take any action. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, r = map(int, input().split()) S = list(map(int, input().split())) B = list(map(int, input().split())) x = min(S) y = max(B) cnt = r % x act = r // x cnt += act * y print(max(r, cnt)) ```
vfc_9954
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1150/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 11\n4 2 5\n4 4 5 4\n", "output": "26\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 50\n5 7\n4 2\n", "output": "50\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n1\n1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 35\n5\n7\n", "output": "49\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
51
Solve the following coding problem using the programming language python: В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение может происходить только по одинаковым символам. Длина совмещения должна быть положительным числом, меньшим длины текста сообщения. Например, при передаче двух сообщений «abrakadabra» подряд возможно, что оно будет передано с ошибкой описанного вида, и тогда будет получено сообщение вида «abrakadabrabrakadabra» или «abrakadabrakadabra» (в первом случае совмещение произошло по одному символу, а во втором — по четырем). По полученному сообщению t определите, возможно ли, что это результат ошибки описанного вида работы локальной сети, и если возможно, определите возможное значение s. Не следует считать ошибкой ситуацию полного наложения друга на друга двух сообщений. К примеру, если получено сообщение «abcd», следует считать, что в нём ошибки нет. Аналогично, простое дописывание одного сообщения вслед за другим не является признаком ошибки. Например, если получено сообщение «abcabc», следует считать, что в нём ошибки нет. -----Входные данные----- В единственной строке выходных данных следует непустая строка t, состоящая из строчных букв латинского алфавита. Длина строки t не превосходит 100 символов. -----Выходные данные----- Если сообщение t не может содержать ошибки, выведите «NO» (без кавычек) в единственную строку выходных данных. В противном случае в первой строке выведите «YES» (без кавычек), а в следующей строке выведите строку s — возможное сообщение, которое могло привести к ошибке. Если возможных ответов несколько, разрешается вывести любой из них. -----Примеры----- Входные данные abrakadabrabrakadabra Выходные данные YES abrakadabra Входные данные acacacaca Выходные данные YES acaca Входные данные abcabc Выходные данные NO Входные данные abababab Выходные данные YES ababab Входные данные tatbt Выходные данные NO -----Примечание----- Во втором примере подходящим ответом также является строка acacaca. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() t = 0 if len(s)%2==0: n = (len(s)-1)//2+1 else: n = (len(s)-1)//2 for i in range(n, len(s)-1): a = i b = len(s)-i-1 if s[:a+1]==s[b:]: print('YES') print(s[:a+1]) t = 1 break if t==0: print('NO') ```
vfc_9958
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/646/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abrakadabrabrakadabra\n", "output": "YES\nabrakadabra\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "acacacaca\n", "output": "YES\nacaca\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcabc\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abababab\n", "output": "YES\nababab\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
52
Solve the following coding problem using the programming language python: Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be $\frac{x \cdot(x - 1)}{2}$ games), and the tournament ends. For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games. Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 10^18), the number of games that should be played. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Output----- Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1. -----Examples----- Input 3 Output 3 4 Input 25 Output 20 Input 2 Output -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) res = set() for r in range(100): a = 1 b = 2**(r + 1) - 3 c = -2 * n d = b * b - 4 * a * c if d < 0: continue le = 0 ri = d while le < ri: c = (le + ri) // 2 if c * c < d: le = c + 1 else: ri = c if le * le == d: if (-b - le) % 4 == 2 and -b - le > 0: res.add((-b - le) // 2 * 2**r) if (-b + le) % 4 == 2 and -b + le > 0: res.add((-b + le) // 2 * 2**r) for i in sorted(list(res)): print(i) if not list(res): print(-1) ```
vfc_9962
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/325/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "3\n4\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
54
Solve the following coding problem using the programming language python: Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≤ w ≤ 10^9, 1 ≤ m ≤ 10^9) — the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python w,m=map(int,input().split()) bb=True while(m>0 and bb): x=m%w if x==1:m-=1 elif x==w-1:m+=1 elif x!=0:bb=False m//=w if bb:print("YES") else:print("NO") ```
vfc_9970
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/552/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
55
Solve the following coding problem using the programming language python: Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one. To be more clear, consider all integer sequence with length k (a_1, a_2, ..., a_{k}) with $\sum_{i = 1}^{k} 2^{a_{i}} = n$. Give a value $y = \operatorname{max}_{1 \leq i \leq k} a_{i}$ to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest. For definitions of powers and lexicographical order see notes. -----Input----- The first line consists of two integers n and k (1 ≤ n ≤ 10^18, 1 ≤ k ≤ 10^5) — the required sum and the length of the sequence. -----Output----- Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence. It is guaranteed that the integers in the answer sequence fit the range [ - 10^18, 10^18]. -----Examples----- Input 23 5 Output Yes 3 3 2 1 0 Input 13 2 Output No Input 1 2 Output Yes -1 -1 -----Note----- Sample 1: 2^3 + 2^3 + 2^2 + 2^1 + 2^0 = 8 + 8 + 4 + 2 + 1 = 23 Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest. Answers like (4, 1, 1, 1, 0) do not have the minimum y value. Sample 2: It can be shown there does not exist a sequence with length 2. Sample 3: $2^{-1} + 2^{-1} = \frac{1}{2} + \frac{1}{2} = 1$ Powers of 2: If x > 0, then 2^{x} = 2·2·2·...·2 (x times). If x = 0, then 2^{x} = 1. If x < 0, then $2^{x} = \frac{1}{2^{-x}}$. Lexicographical order: Given two different sequences of the same length, (a_1, a_2, ... , a_{k}) and (b_1, b_2, ... , b_{k}), the first one is smaller than the second one for the lexicographical order, if and only if a_{i} < b_{i}, for the first i where a_{i} and b_{i} differ. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import defaultdict def solve(n, k): as_bin = bin(n)[2:] cnt = defaultdict(int) cnt.update({i : 1 for i, b in enumerate(reversed(as_bin)) if b == '1'}) curr_len = len(cnt) curr_pow = len(as_bin) - 1 if curr_len > k: return None while True: new_len = curr_len + cnt[curr_pow] if new_len > k: break cnt[curr_pow - 1] += 2 * cnt[curr_pow] del cnt[curr_pow] curr_pow -= 1 curr_len = new_len i = min(cnt.keys()) while curr_len < k: cnt[i] -= 1 cnt[i - 1] += 2 curr_len += 1 i -= 1 ans = [] for i in sorted(list(cnt.keys()), reverse=True): ans.extend([i] * cnt[i]) return ans n, k = [int(v) for v in input().split()] ans = solve(n, k) if ans is None: print('No') else: print('Yes') print(' '.join(str(c) for c in ans)) ```
vfc_9974
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/916/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "23 5\n", "output": "Yes\n3 3 2 1 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 2\n", "output": "No\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
56
Solve the following coding problem using the programming language python: Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of n glasses. Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid. Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in t seconds. Pictures below illustrate the pyramid consisting of three levels. [Image] [Image] -----Input----- The only line of the input contains two integers n and t (1 ≤ n ≤ 10, 0 ≤ t ≤ 10 000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle. -----Output----- Print the single integer — the number of completely full glasses after t seconds. -----Examples----- Input 3 5 Output 4 Input 4 8 Output 6 -----Note----- In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, t = list(map(int,input().split())) g = [[0.0] * i for i in range(1,n+1)] for _ in range(t): g[0][0] += 1.0 for i in range(n): for j in range(i+1): spill = max(0, g[i][j] - 1.0) g[i][j] -= spill if i < n - 1: g[i + 1][j] += spill / 2 g[i + 1][j + 1] += spill / 2 if g[n-1][0] == 1.0: break cnt = 0 for i in range(n): for j in range(i + 1): if g[i][j] == 1.0: cnt += 1 print(cnt) ```
vfc_9978
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/676/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n", "output": "4\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
57
Solve the following coding problem using the programming language python: After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices. Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool. -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend. Each of the following n lines contains two integers x_{i} and y_{i} ( - 1000 ≤ x_{i}, y_{i} ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order. It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes. -----Output----- Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1. -----Examples----- Input 2 0 0 1 1 Output 1 Input 1 1 1 Output -1 -----Note----- In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square. In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) points = [[int(x) for x in input().split()] for _ in range(n)] if n <= 1: print(-1) return dx = [1e9, -1e9] dy = [1e9, -1e9] for x, y in points: dx[0] = min(dx[0], x) dx[1] = max(dx[1], x) dy[0] = min(dy[0], y) dy[1] = max(dy[1], y) area = (dx[1] - dx[0]) * (dy[1] - dy[0]) if area: print(area) else: print(-1) ```
vfc_9982
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/596/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0 0\n1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n-188 17\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n71 -740\n", "output": "-1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
58
Solve the following coding problem using the programming language python: Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side. Determine a minimal number of wooden bars which are needed to make the frames for two doors. Petya can cut the wooden bars into any parts, but each side of each door should be a solid piece of a wooden bar (or a whole wooden bar). -----Input----- The first line contains a single integer n (1 ≤ n ≤ 1 000) — the length of each wooden bar. The second line contains a single integer a (1 ≤ a ≤ n) — the length of the vertical (left and right) sides of a door frame. The third line contains a single integer b (1 ≤ b ≤ n) — the length of the upper side of a door frame. -----Output----- Print the minimal number of wooden bars with length n which are needed to make the frames for two doors. -----Examples----- Input 8 1 2 Output 1 Input 5 3 4 Output 6 Input 6 4 2 Output 4 Input 20 5 6 Output 2 -----Note----- In the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8. In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python '''input 6 4 2 ''' def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() def f(n,a,b,left,cnta = 4,cntb = 2): if(cnta == 0 and cntb == 0): return 0 if(cnta < 0 or cntb < 0): return 100000000000000000000 if a <= left and cnta and b <= left and cntb: return min(f(n,a,b,left-a,cnta-1,cntb),f(n,a,b,left-b,cnta,cntb-1)) if a <= left and cnta: return f(n,a,b,left-a,cnta-1,cntb) if b <= left and cntb: return f(n,a,b,left-b,cnta,cntb-1) return 1+min(f(n,a,b,n-a,cnta-1,cntb),f(n,a,b,n-b,cnta,cntb-1)) n = int(input()) a = int(input()) b = int(input()) print(f(n,a,b,0)) ```
vfc_9986
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/910/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n1\n2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3\n4\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n4\n2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n5\n6\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n1\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1\n2\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
60
Solve the following coding problem using the programming language python: A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. [Image]   It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. -----Input----- The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 10^18) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. -----Output----- Print one integer — the number of seconds Vasya has to wait until he gets his lunch. -----Examples----- Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 -----Note----- In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python seat = input() time_to = {'a': 4, 'f': 1, 'b': 5, 'e': 2, 'c': 6, 'd': 3} col = seat[-1] row = int(seat[:-1]) row -= 1 blocks_to_serve = row // 4 time = (6 * 2 + 4) * blocks_to_serve if row % 2 == 1: time += 6 + 1 time += time_to[col] print(time) ```
vfc_9994
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/725/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1f\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2d\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4a\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5e\n", "output": "18\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
61
Solve the following coding problem using the programming language python: After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations. You're given a number X represented in base b_{x} and a number Y represented in base b_{y}. Compare those two numbers. -----Input----- The first line of the input contains two space-separated integers n and b_{x} (1 ≤ n ≤ 10, 2 ≤ b_{x} ≤ 40), where n is the number of digits in the b_{x}-based representation of X. The second line contains n space-separated integers x_1, x_2, ..., x_{n} (0 ≤ x_{i} < b_{x}) — the digits of X. They are given in the order from the most significant digit to the least significant one. The following two lines describe Y in the same way: the third line contains two space-separated integers m and b_{y} (1 ≤ m ≤ 10, 2 ≤ b_{y} ≤ 40, b_{x} ≠ b_{y}), where m is the number of digits in the b_{y}-based representation of Y, and the fourth line contains m space-separated integers y_1, y_2, ..., y_{m} (0 ≤ y_{i} < b_{y}) — the digits of Y. There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system. -----Output----- Output a single character (quotes for clarity): '<' if X < Y '>' if X > Y '=' if X = Y -----Examples----- Input 6 2 1 0 1 1 1 1 2 10 4 7 Output = Input 3 3 1 0 2 2 5 2 4 Output < Input 7 16 15 15 4 0 0 7 10 7 9 4 8 0 3 1 5 0 Output > -----Note----- In the first sample, X = 101111_2 = 47_10 = Y. In the second sample, X = 102_3 = 21_5 and Y = 24_5 = 112_3, thus X < Y. In the third sample, $X = FF 4007 A_{16}$ and Y = 4803150_9. We may notice that X starts with much larger digits and b_{x} is much larger than b_{y}, so X is clearly larger than Y. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, bx = list(map(int, input().split())) x1 = list(map(int, input().split())) x = 0 for i in range(n): x *= bx x += x1[i] n, by = list(map(int, input().split())) y1 = list(map(int, input().split())) y = 0 for i in range(n): y *= by y += y1[i] if x == y: print('=') elif x < y: print('<') else: print('>') ```
vfc_9998
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/602/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n1 0 1 1 1 1\n2 10\n4 7\n", "output": "=\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
62
Solve the following coding problem using the programming language python: Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games! Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games. BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They've got a sequence of n non-negative integers a_1, a_2, ..., a_{n}. The players make moves in turns. BitLGM moves first. Each player can and must do one of the two following actions in his turn: Take one of the integers (we'll denote it as a_{i}). Choose integer x (1 ≤ x ≤ a_{i}). And then decrease a_{i} by x, that is, apply assignment: a_{i} = a_{i} - x. Choose integer x $(1 \leq x \leq \operatorname{min}_{i = 1} a_{i})$. And then decrease all a_{i} by x, that is, apply assignment: a_{i} = a_{i} - x, for all i. The player who cannot make a move loses. You're given the initial sequence a_1, a_2, ..., a_{n}. Determine who wins, if both players plays optimally well and if BitLGM and BitAryo start playing the described game in this sequence. -----Input----- The first line contains an integer n (1 ≤ n ≤ 3). The next line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} < 300). -----Output----- Write the name of the winner (provided that both players play optimally well). Either "BitLGM" or "BitAryo" (without the quotes). -----Examples----- Input 2 1 1 Output BitLGM Input 2 1 2 Output BitAryo Input 3 1 2 1 Output BitLGM The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from math import * n=int(input()) if n==3: li=list(map(int,input().split())) ans=0 flag=0 for i in li: ans^=i if ans==0: print("BitAryo") else: print("BitLGM") elif n==2: li=list(map(int,input().split())) li.sort() phi=(1+sqrt(5))/2 ch=[0]*(785) for i in range(300): a=floor(phi*i) b=floor((phi**2)*i) ch[a]=b ch[b]=a if ch[li[0]]==li[1]: print("BitAryo") else: print("BitLGM") else: li=int(input()) if li==0: print("BitAryo") else: print("BitLGM") ```
vfc_10002
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/282/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1\n", "output": "BitLGM\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
63
Solve the following coding problem using the programming language python: Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a_{i} is written on the i-th card in the deck. After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid? -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 10^9). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the numbers written on the cards. -----Output----- Print the number of ways to choose x and y so the resulting deck is valid. -----Examples----- Input 3 4 6 2 8 Output 4 Input 3 6 9 1 14 Output 1 -----Note----- In the first example the possible values of x and y are: x = 0, y = 0; x = 1, y = 0; x = 2, y = 0; x = 0, y = 1. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n,k=map(int,input().split()) l=list(map(int,input().split())) pf=[] needed=[] for i in range(2,40000): if k%i==0: pf.append(i) c=0 while k%i==0: k//=i c+=1 needed.append(c) if k>1: pf.append(k) needed.append(1) pfl=len(pf) cnt=[[0]*n for i in range(pfl)] for i in range(n): for j in range(len(pf)): c=0 while l[i]%pf[j]==0: c+=1 l[i]//=pf[j] cnt[j][i]=c have=[sum(i) for i in cnt] pos=n def ok(): for i in range(len(pf)): if have[i]<needed[i]: return False return True if not ok(): print(0) quit() for i in range(n-1,0,-1): for j in range(len(pf)): have[j]-=cnt[j][i] if not ok(): for j in range(len(pf)): have[j]+=cnt[j][i] break pos=i ans=n-pos+1 for x in range(n-1): for j in range(len(pf)): have[j]-=cnt[j][x] if pos==(x+1): for j in range(len(pf)): have[j]+=cnt[j][pos] pos+=1 while pos<n: if ok(): break else: for i in range(len(pf)): have[i]+=cnt[i][pos] pos+=1 if ok(): ans+=n-pos+1 else: break print(ans) ```
vfc_10006
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/818/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n6 2 8\n", "output": "4\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
64
Solve the following coding problem using the programming language python: One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. -----Input----- The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends. Next line contains string s — colors of baloons. -----Output----- Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary. -----Examples----- Input 4 2 aabb Output YES Input 6 3 aacaab Output NO -----Note----- In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python alpha = [chr(ord('a')+i) for i in range(26)] n,k = list(map(int,input().split())) s = input() arr = [s.count(alpha[i]) for i in range(26)] print('YES' if max(arr) <= k else 'NO') ```
vfc_10010
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/841/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\naabb\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
65
Solve the following coding problem using the programming language python: You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. -----Input----- The first line contains positive integer n (2 ≤ n ≤ 10^5) — size of the given array. The second line contains n integers a_0, a_1, ..., a_{n} - 1 (1 ≤ a_{i} ≤ 10^9) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. -----Output----- Print the only number — distance between two nearest minimums in the array. -----Examples----- Input 2 3 3 Output 1 Input 3 5 6 5 Output 2 Input 9 2 1 3 5 4 1 2 3 1 Output 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) A = [int(x) for x in input().split()] mn = min(A) I = [i for i in range(len(A)) if A[i] == mn] mindiff = min(I[i]-I[i-1] for i in range(1,len(I))) print(mindiff) ```
vfc_10014
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/911/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 6 5\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
66
Solve the following coding problem using the programming language python: Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. [Image] Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L. Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today? -----Input----- The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·10^18) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. -----Output----- Print the answer to the problem as an irreducible fraction [Image]. Follow the format of the samples output. The fraction [Image] (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d. -----Examples----- Input 10 3 2 Output 3/10 Input 7 1 2 Output 3/7 -----Note----- In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from fractions import gcd t,w,b = map(int,input().split()) per = w*b//gcd(w,b) can = (t//per+1)*min(w,b)-1 if t%per<min(w,b): can-=min(w,b) can+=t%per+1 g = gcd(can,t) can//=g t//=g print(str(can)+"/"+str(t)) ```
vfc_10018
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/592/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3 2\n", "output": "3/10\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
67
Solve the following coding problem using the programming language python: Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there were also another $z$ persons who would vote, but you don't know whether they would upvote or downvote. Note that each of the $x+y+z$ people would vote exactly one time. There are three different results: if there are more people upvote than downvote, the result will be "+"; if there are more people downvote than upvote, the result will be "-"; otherwise the result will be "0". Because of the $z$ unknown persons, the result may be uncertain (i.e. there are more than one possible results). More formally, the result is uncertain if and only if there exist two different situations of how the $z$ persons vote, that the results are different in the two situations. Tell Nauuo the result or report that the result is uncertain. -----Input----- The only line contains three integers $x$, $y$, $z$ ($0\le x,y,z\le100$), corresponding to the number of persons who would upvote, downvote or unknown. -----Output----- If there is only one possible result, print the result : "+", "-" or "0". Otherwise, print "?" to report that the result is uncertain. -----Examples----- Input 3 7 0 Output - Input 2 0 1 Output + Input 1 1 0 Output 0 Input 0 0 1 Output ? -----Note----- In the first example, Nauuo would definitely get three upvotes and seven downvotes, so the only possible result is "-". In the second example, no matter the person unknown downvotes or upvotes, Nauuo would get more upvotes than downvotes. So the only possible result is "+". In the third example, Nauuo would definitely get one upvote and one downvote, so the only possible result is "0". In the fourth example, if the only one person upvoted, the result would be "+", otherwise, the result would be "-". There are two possible results, so the result is uncertain. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x, y, z = map(int, input().split()) if z == 0: if x == y: print('0') elif x > y: print('+') else: print('-') else: if x > y + z: print('+') elif x + z < y: print('-') else: print('?') ```
vfc_10022
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1173/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7 0\n", "output": "-", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0 1\n", "output": "+", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 0\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 1\n", "output": "?", "type": "stdin_stdout" } ] }
apps
verifiable_code
68
Solve the following coding problem using the programming language python: Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; L — move from $(x, y)$ to $(x - 1, y)$; R — move from $(x, y)$ to $(x + 1, y)$. Vasya also has got a sequence of $n$ operations. Vasya wants to modify this sequence so after performing it the robot will end up in $(x, y)$. Vasya wants to change the sequence so the length of changed subsegment is minimum possible. This length can be calculated as follows: $maxID - minID + 1$, where $maxID$ is the maximum index of a changed operation, and $minID$ is the minimum index of a changed operation. For example, if Vasya changes RRRRRRR to RLRRLRL, then the operations with indices $2$, $5$ and $7$ are changed, so the length of changed subsegment is $7 - 2 + 1 = 6$. Another example: if Vasya changes DDDD to DDRD, then the length of changed subsegment is $1$. If there are no changes, then the length of changed subsegment is $0$. Changing an operation means replacing it with some operation (possibly the same); Vasya can't insert new operations into the sequence or remove them. Help Vasya! Tell him the minimum length of subsegment that he needs to change so that the robot will go from $(0, 0)$ to $(x, y)$, or tell him that it's impossible. -----Input----- The first line contains one integer number $n~(1 \le n \le 2 \cdot 10^5)$ — the number of operations. The second line contains the sequence of operations — a string of $n$ characters. Each character is either U, D, L or R. The third line contains two integers $x, y~(-10^9 \le x, y \le 10^9)$ — the coordinates of the cell where the robot should end its path. -----Output----- Print one integer — the minimum possible length of subsegment that can be changed so the resulting sequence of operations moves the robot from $(0, 0)$ to $(x, y)$. If this change is impossible, print $-1$. -----Examples----- Input 5 RURUU -2 3 Output 3 Input 4 RULR 1 1 Output 0 Input 3 UUU 100 100 Output -1 -----Note----- In the first example the sequence can be changed to LULUU. So the length of the changed subsegment is $3 - 1 + 1 = 3$. In the second example the given sequence already leads the robot to $(x, y)$, so the length of the changed subsegment is $0$. In the third example the robot can't end his path in the cell $(x, y)$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # import collections, atexit, math, sys, bisect sys.setrecursionlimit(1000000) def getIntList(): return list(map(int, input().split())) try : #raise ModuleNotFoundError import numpy def dprint(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) dprint('debug mode') except Exception: def dprint(*args, **kwargs): pass inId = 0 outId = 0 if inId>0: dprint('use input', inId) sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件 if outId>0: dprint('use output', outId) sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件 atexit.register(lambda :sys.stdout.close()) #idle 中不会执行 atexit N, = getIntList() #print(N) S = input() X, Y = getIntList() dd = ( (0,1), (0,-1), (-1,0), (1,0)) pp = 'UDLR' zz = {} for i in range(4): zz[ pp[i]] = dd[i] if abs(X) + abs(Y) >N: print(-1) return if abs(X+Y-N)%2==1: print(-1) return fromLeft = [None for i in range(N)] fromRight = fromLeft.copy() x0 = 0 y0 = 0 for i in range(N): x = S[i] fromLeft[i] = (x0,y0) g = zz[x] x0+= g[0] y0+= g[1] if x0==X and y0==Y: print(0) return x0 = 0 y0 = 0 for i in range(N-1,-1,-1): x = S[i] fromRight[i] = (x0,y0) g = zz[x] x0+= g[0] y0+= g[1] up = N down = 0 dprint(fromLeft) dprint(fromRight) while down+1<up: mid = (up+down)//2 dprint('mid', mid) ok = False for i in range(N-mid + 1): tx = fromLeft[i][0] + fromRight[i+mid-1][0] ty = fromLeft[i][1] + fromRight[i+mid-1][1] gg = abs(X-tx) + abs(Y- ty) if gg <= mid: ok = True break if ok: up = mid else: down = mid print(up) ```
vfc_10026
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1073/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nRURUU\n-2 3\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
69
Solve the following coding problem using the programming language python: You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010... Calculate the number of prefixes of $t$ with balance equal to $x$. The balance of some string $q$ is equal to $cnt_{0, q} - cnt_{1, q}$, where $cnt_{0, q}$ is the number of occurrences of 0 in $q$, and $cnt_{1, q}$ is the number of occurrences of 1 in $q$. The number of such prefixes can be infinite; if it is so, you must say that. A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd". -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) — the number of test cases. Next $2T$ lines contain descriptions of test cases — two lines per test case. The first line contains two integers $n$ and $x$ ($1 \le n \le 10^5$, $-10^9 \le x \le 10^9$) — the length of string $s$ and the desired balance, respectively. The second line contains the binary string $s$ ($|s| = n$, $s_i \in \{\text{0}, \text{1}\}$). It's guaranteed that the total sum of $n$ doesn't exceed $10^5$. -----Output----- Print $T$ integers — one per test case. For each test case print the number of prefixes or $-1$ if there is an infinite number of such prefixes. -----Example----- Input 4 6 10 010010 5 3 10101 1 0 0 2 0 01 Output 3 0 1 -1 -----Note----- In the first test case, there are 3 good prefixes of $t$: with length $28$, $30$ and $32$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t=int(input()) for i in ' '*t: n,x=map(int,input().split()) s=input() L=[0] for i in s: if i=='0':L.append(L[-1]+1) else:L.append(L[-1]-1) L.pop(0) k=L[-1] c=0 if x==0:c+=1 if k>0: for i in L: if i%k==x%k and i<=x:c+=1 print(c) elif k<0: for i in L: if i%k==x%k and i>=x:c+=1 print(c) else: for i in L: if i==x:c=-1 print(c) ```
vfc_10030
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1295/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n6 10\n010010\n5 3\n10101\n1 0\n0\n2 0\n01\n", "output": "3\n0\n1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 -548706795\n0\n1 -735838406\n1\n", "output": "0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5 5\n00000\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "19\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 0\n011\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
70
Solve the following coding problem using the programming language python: Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 10^3 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10^{k}. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. -----Input----- The only line of the input contains two integer numbers n and k (0 ≤ n ≤ 2 000 000 000, 1 ≤ k ≤ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. -----Output----- Print w — the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10^{k}. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). -----Examples----- Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 -----Note----- In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input().split() k = int(s[1]) s = s[0] if s.count('0') < k: if s.count('0') > 0: print(len(s) - 1) else: print(len(s)) return have = 0 its = 0 for i in range(len(s) - 1, -1, -1): its += 1 if s[i] == '0': have += 1 if have == k: print(its - have) return ```
vfc_10034
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/779/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "30020 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 9\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10203049 2\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
71
Solve the following coding problem using the programming language python: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ... The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil. During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row. -----Input----- The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 10^18, 1 ≤ x ≤ n, 1 ≤ y ≤ m). -----Output----- Print three integers: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. -----Examples----- Input 1 3 8 1 1 Output 3 2 3 Input 4 2 9 4 2 Output 2 1 1 Input 5 5 25 4 3 Output 1 1 1 Input 100 100 1000000000000000000 100 100 Output 101010101010101 50505050505051 50505050505051 -----Note----- The order of asking pupils in the first test: the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; The order of asking pupils in the second test: the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table; The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, k, x, y = list(map(int, input().split())) ans = [[0] * m for x in range(n)] onebig = (2*n-2)*m or m oo = k // onebig for i in range(n): for j in range(m): if i == 0 or i == n-1: ans[i][j] += oo k -= oo else: ans[i][j] += 2*oo k -= 2*oo from itertools import chain for i in chain(list(range(n)), list(range(n-2, 0, -1))): if not k: break for j in range(m): if not k: break ans[i][j] += 1 k -= 1 _max = max(list(map(max, ans))) _min = min(list(map(min, ans))) _ans = ans[x-1][y-1] print(_max, _min, _ans) ```
vfc_10038
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/758/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3 8 1 1\n", "output": "3 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 9 4 2\n", "output": "2 1 1", "type": "stdin_stdout" } ] }
apps
verifiable_code
72
Solve the following coding problem using the programming language python: After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons. A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $7$ because its subribbon a appears $7$ times, and the ribbon abcdabc has the beauty of $2$ because its subribbon abc appears twice. The rules are simple. The game will have $n$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $n$ turns wins the treasure. Could you find out who is going to be the winner if they all play optimally? -----Input----- The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors. -----Output----- Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". -----Examples----- Input 3 Kuroo Shiro Katie Output Kuro Input 7 treasurehunt threefriends hiCodeforces Output Shiro Input 1 abcabc cbabac ababca Output Katie Input 15 foPaErcvJ mZaxowpbt mkuOlaHRE Output Draw -----Note----- In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro. In the fourth example, since the length of each of the string is $9$ and the number of turn is $15$, everyone can change their ribbons in some way to reach the maximal beauty of $9$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python turns = int(input()) s0 = input() s1 = input() s2 = input() d0 = dict() d1 = dict() d2 = dict() alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' for char in alphabet: d0[char] = 0 d1[char] = 0 d2[char] = 0 for char in s0: d0[char] += 1 for char in s1: d1[char] += 1 for char in s2: d2[char] += 1 m0 = max([d0[char] for char in alphabet]) m1 = max([d1[char] for char in alphabet]) m2 = max([d2[char] for char in alphabet]) l0 = len(s0) l1 = len(s1) l2 = len(s2) if turns == 1 and m0 == l0: score0 = m0 - 1 else: score0 = min(l0,m0+turns) if turns == 1 and m1 == l1: score1 = m1 - 1 else: score1 = min(l1,m1+turns) if turns == 1 and m2 == l2: score2 = m2 - 1 else: score2 = min(l2,m2+turns) scores = [score0,score1,score2] bestscore = max(scores) winnerlist = [i for i in range(3) if scores[i] == bestscore] if len(winnerlist) > 1: print('Draw') else: print(['Kuro','Shiro','Katie'][winnerlist[0]]) ```
vfc_10042
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/979/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nKuroo\nShiro\nKatie\n", "output": "Kuro\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\ntreasurehunt\nthreefriends\nhiCodeforces\n", "output": "Shiro\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nabcabc\ncbabac\nababca\n", "output": "Katie\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
73
Solve the following coding problem using the programming language python: Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages. At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v_0 pages, at second — v_0 + a pages, at third — v_0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v_1 pages per day. Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time. Help Mister B to calculate how many days he needed to finish the book. -----Input----- First and only line contains five space-separated integers: c, v_0, v_1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v_0 ≤ v_1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading. -----Output----- Print one integer — the number of days Mister B needed to finish the book. -----Examples----- Input 5 5 10 5 4 Output 1 Input 12 4 12 4 1 Output 3 Input 15 1 100 0 0 Output 15 -----Note----- In the first sample test the book contains 5 pages, so Mister B read it right at the first day. In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book. In third sample test every day Mister B read 1 page of the book, so he finished in 15 days. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python read = lambda: map(int, input().split()) c, v0, v1, a, l = read() cur = 0 cnt = 0 while cur < c: cur = max(0, cur - l) cur += min(v1, v0 + a * cnt) cnt += 1 print(cnt) ```
vfc_10046
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/820/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 10 5 4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 4 12 4 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 1 100 0 0\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 0 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 999 1000 1000 998\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 2 2 5 1\n", "output": "999\n", "type": "stdin_stdout" } ] }