source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
112
prompt
stringlengths
219
13.2k
gold_standard_solution
stringlengths
22
413k
verification_info
stringlengths
91
74M
metadata
stringlengths
19
190
problem_id
stringlengths
5
10
program
stringlengths
22
413k
inputs
stringlengths
0
889k
output
stringlengths
0
168k
actual_output
stringlengths
0
168k
execution_success
bool
1 class
sample_index
int64
2
31.8k
apps
verifiable_code
185
Solve the following coding problem using the programming language python: Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible. There are $n$ manholes in the room...
```python n, k = list(map(int,input().split())) if k == 1 or k == n: print(3 * n) else: print(3 * n + min(k - 1, n - k)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '4 2\n', 'output': '13\n'}, {'type': 'stdin_stdout', 'input': '5 1\n', 'output': '15\n'}, {'type': 'stdin_stdout', 'input': '64 49\n', 'output': '207\n'}, {'type': 'stdin_stdout', 'input': '24 6\n', 'output': ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1136/B'}
vfc_10494
```python n, k = list(map(int,input().split())) if k == 1 or k == n: print(3 * n) else: print(3 * n + min(k - 1, n - k)) ```
2 2
6
6
true
1,739
apps
verifiable_code
186
Solve the following coding problem using the programming language python: Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks. Th...
```python n, m = list(map(int, input().split())) start = 0 end = 10**10 while (end - start > 1): mid = (end + start) // 2 two = mid // 2 - mid // 6 three = mid // 3 - mid // 6 six = mid // 6 nn = n mm = m nn -= two mm -= three nn = max(nn, 0) mm = max(mm, 0) if (six >= nn ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 3\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '3 2\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '5 0\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '4 2\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '0 1000000\n', 'output': ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/626/C'}
vfc_10498
```python n, m = list(map(int, input().split())) start = 0 end = 10**10 while (end - start > 1): mid = (end + start) // 2 two = mid // 2 - mid // 6 three = mid // 3 - mid // 6 six = mid // 6 nn = n mm = m nn -= two mm -= three nn = max(nn, 0) mm = max(mm, 0) if (six >= nn ...
1 3
9
9
true
1,740
apps
verifiable_code
188
Solve the following coding problem using the programming language python: Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains a_{i} soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army thr...
```python import sys def r(): return list(map(int, input().split())) n, k = list(map(int, input().split())) a = r() cnt4 = n cnt2 = 2*n cnt1 = 0 for i in range(k): x = min((a[i]+1)//4, cnt4) cnt4 -= x a[i] = max(0, a[i]-4*x) cnt2 += cnt4 cnt1 += cnt4 for i in range(k): x = min(a[i]//2, cnt2) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n5 8\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '1 2\n7 1\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '1 2\n4 4\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '1 4\n2 2 1 2\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'inp...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/839/B'}
vfc_10506
```python import sys def r(): return list(map(int, input().split())) n, k = list(map(int, input().split())) a = r() cnt4 = n cnt2 = 2*n cnt1 = 0 for i in range(k): x = min((a[i]+1)//4, cnt4) cnt4 -= x a[i] = max(0, a[i]-4*x) cnt2 += cnt4 cnt1 += cnt4 for i in range(k): x = min(a[i]//2, cnt2) ...
2 2 5 8
YES
YES
true
1,742
apps
verifiable_code
189
Solve the following coding problem using the programming language python: Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \ldots, a_n$. For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length fro...
```python n = int(input()) a = list(map(int,input().split())) t = 0 mn = 1000000000 for i in range(1,100): cur = 0 for j in range(n): cur += max(0,abs(i-a[j])-1) if cur < mn: mn = cur t = i print(t,mn) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n10 1 4\n', 'output': '3 7\n'}, {'type': 'stdin_stdout', 'input': '5\n1 1 2 2 3\n', 'output': '2 0\n'}, {'type': 'stdin_stdout', 'input': '1\n5\n', 'output': '4 0\n'}, {'type': 'stdin_stdout', 'input': '2\n1 2\n', 'output': '1 0\n'}, {'type': 'stdin_stdout', 'input':...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1105/A'}
vfc_10510
```python n = int(input()) a = list(map(int,input().split())) t = 0 mn = 1000000000 for i in range(1,100): cur = 0 for j in range(n): cur += max(0,abs(i-a[j])-1) if cur < mn: mn = cur t = i print(t,mn) ```
3 10 1 4
3 7
3 7
true
1,743
apps
verifiable_code
190
Solve the following coding problem using the programming language python: Карта звёздного неба представляет собой прямоугольное поле, состоящее из n строк по m символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда). Новое из...
```python n, m = input().split() n = int(n) m = int(m) a = [] N = n for i in range(n) : a.append(input().split()) for i in range(n) : if a[i][0].find('*') == -1 : n-=1 else : break if n != 1 : for i in range(len(a)-1,-1,-1) : if a[i][0].find('*') == -1 : n-=1 ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\n....\n..*.\n...*\n..**\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '1 3\n*.*\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '2 1\n.\n*\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1 1\n*\n', 'output': '1\n'}, {'type': 'stdin_stdout...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/647/B'}
vfc_10514
```python n, m = input().split() n = int(n) m = int(m) a = [] N = n for i in range(n) : a.append(input().split()) for i in range(n) : if a[i][0].find('*') == -1 : n-=1 else : break if n != 1 : for i in range(len(a)-1,-1,-1) : if a[i][0].find('*') == -1 : n-=1 ...
4 4 .... ..*. ...* ..**
3
3
true
1,744
apps
verifiable_code
191
Solve the following coding problem using the programming language python: A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1...
```python N, T = list(map(int, input().split())) A = [int(a) for a in input().split()] if sum(A) > N//2: A = [1-a for a in A][::-1] K = sum(A) S = sum(A[-K:]) M = K + 1 P = 10**9+7 inv = pow(N*(N-1)//2, P-2, P) X = [[0]*M for _ in range(M)] for i in range(M): if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P if i < ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\n0 1 0\n', 'output': '333333336'}, {'type': 'stdin_stdout', 'input': '5 1\n1 1 1 0 0\n', 'output': '0'}, {'type': 'stdin_stdout', 'input': '6 4\n1 0 0 1 1 0\n', 'output': '968493834'}, {'type': 'stdin_stdout', 'input': '3 2\n1 1 1\n', 'output': '1'}, {'type': 'stdi...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1151/F'}
vfc_10518
```python N, T = list(map(int, input().split())) A = [int(a) for a in input().split()] if sum(A) > N//2: A = [1-a for a in A][::-1] K = sum(A) S = sum(A[-K:]) M = K + 1 P = 10**9+7 inv = pow(N*(N-1)//2, P-2, P) X = [[0]*M for _ in range(M)] for i in range(M): if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P if i < ...
3 2 0 1 0
333333336
333333336
true
1,745
apps
verifiable_code
192
Solve the following coding problem using the programming language python: Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second...
```python x, y = list(map(int, input().split())) x, y = y, x A = x B = x curr = x count = 0 while curr < y: curr = B + A - 1 A, B = B, curr count += 1 count += 2 print(count) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 3\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '8 5\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '22 4\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '4 3\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '57 27\n', 'output': '4\n...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/712/C'}
vfc_10522
```python x, y = list(map(int, input().split())) x, y = y, x A = x B = x curr = x count = 0 while curr < y: curr = B + A - 1 A, B = B, curr count += 1 count += 2 print(count) ```
6 3
4
4
true
1,746
apps
verifiable_code
194
Solve the following coding problem using the programming language python: In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater...
```python n, a, b = list(map(int,input().split())) l = input().split() o = 0 c = 0 for i in l: if i == '2': if b > 0: b -= 1 else: o += 2 if i == '1': if a > 0: a -= 1 elif b > 0: b -= 1 c += 1 elif c > 0: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 1 2\n1 2 1 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '4 1 1\n1 1 2 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '1 1 1\n1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2 1 2\n2 2\n', 'output': '0\n'}, {'type': 'stdin_stdout', '...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/828/A'}
vfc_10530
```python n, a, b = list(map(int,input().split())) l = input().split() o = 0 c = 0 for i in l: if i == '2': if b > 0: b -= 1 else: o += 2 if i == '1': if a > 0: a -= 1 elif b > 0: b -= 1 c += 1 elif c > 0: ...
4 1 2 1 2 1 1
0
0
true
1,748
apps
verifiable_code
195
Solve the following coding problem using the programming language python: Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after th...
```python a,b,c,n=list(map(int,input().split())) x=a+b-c print(n-x if c<=a and c<=b and x<n else -1) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '10 10 5 20\n', 'output': '5'}, {'type': 'stdin_stdout', 'input': '2 2 0 4\n', 'output': '-1'}, {'type': 'stdin_stdout', 'input': '2 2 2 1\n', 'output': '-1'}, {'type': 'stdin_stdout', 'input': '98 98 97 100\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '1 5 2 1...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/991/A'}
vfc_10534
```python a,b,c,n=list(map(int,input().split())) x=a+b-c print(n-x if c<=a and c<=b and x<n else -1) ```
10 10 5 20
5
5
true
1,749
apps
verifiable_code
196
Solve the following coding problem using the programming language python: Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, r...
```python x, k = map(int, input().split()) if x == 0: print(0) else: mod = 10 ** 9 + 7 p = pow(2, k, mod) ans = (x * (p * 2) - (p - 1)) % mod print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 0\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '2 1\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '3 2\n', 'output': '21\n'}, {'type': 'stdin_stdout', 'input': '1 411\n', 'output': '485514976\n'}, {'type': 'stdin_stdout', 'input': '1 692\n', 'out...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/992/C'}
vfc_10538
```python x, k = map(int, input().split()) if x == 0: print(0) else: mod = 10 ** 9 + 7 p = pow(2, k, mod) ans = (x * (p * 2) - (p - 1)) % mod print(ans) ```
2 0
4
4
true
1,750
apps
verifiable_code
197
Solve the following coding problem using the programming language python: An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared $n$ problems; and since the platform is very popular, $998244351$ coder from all over the world is going to solve them. For ...
```python from bisect import bisect_left M = 998244353 def pw(x, y): if y == 0: return 1 res = pw(x, y//2) res = res * res % M if y % 2 == 1: res = res * x % M return res def cal(x, y): y += x - 1 res = 1 for i in range(1, x + 1): res = res * (y - i + 1) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2\n1 2\n1 2\n', 'output': '499122177\n'}, {'type': 'stdin_stdout', 'input': '2\n42 1337\n13 420\n', 'output': '578894053\n'}, {'type': 'stdin_stdout', 'input': '2\n1 1\n0 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2\n1 1\n1 1\n', 'output': '1\n'}, ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1295/F'}
vfc_10542
```python from bisect import bisect_left M = 998244353 def pw(x, y): if y == 0: return 1 res = pw(x, y//2) res = res * res % M if y % 2 == 1: res = res * x % M return res def cal(x, y): y += x - 1 res = 1 for i in range(1, x + 1): res = res * (y - i + 1) ...
3 1 2 1 2 1 2
499122177
499122177
true
1,751
apps
verifiable_code
198
Solve the following coding problem using the programming language python: Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n. Pasha likes r...
```python x = int(input()) if x%2==1: print(0) quit() if x%2 ==0: x//=2 if x%2==0: print(x//2-1) else: print(x//2) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '6\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '20\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3\n', 'output': '0\n'}, {'type':...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/610/A'}
vfc_10546
```python x = int(input()) if x%2==1: print(0) quit() if x%2 ==0: x//=2 if x%2==0: print(x//2-1) else: print(x//2) ```
6
1
1
true
1,752
apps
verifiable_code
199
Solve the following coding problem using the programming language python: The Fair Nut likes kvass very much. On his birthday parents presented him $n$ kegs of kvass. There are $v_i$ liters of kvass in the $i$-th keg. Each keg has a lever. You can pour your glass by exactly $1$ liter pulling this lever. The Fair Nut l...
```python def doit(): xx = input().split() n = int(xx[0]) s = int(xx[1]) v = [int(k) for k in input().split()] S = sum(v) newS = S - s if newS < 0: return -1 return min(newS//n, min(v)) print(doit()) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n4 3 5\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3 4\n5 3 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 7\n1 2 3\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1084/B'}
vfc_10550
```python def doit(): xx = input().split() n = int(xx[0]) s = int(xx[1]) v = [int(k) for k in input().split()] S = sum(v) newS = S - s if newS < 0: return -1 return min(newS//n, min(v)) print(doit()) ```
3 3 4 3 5
3
3
true
1,753
apps
verifiable_code
201
Solve the following coding problem using the programming language python: A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? [Ima...
```python import sys f = sys.stdin C, Hr, Hb, Wr, Wb = map(int, f.readline().strip().split()) if Hr/Wr < Hb/Wb: Hr, Hb, Wr, Wb = Hb, Hr, Wb, Wr if (C % Wr) == 0 and (C // Wr) > 0: print((C // Wr)*Hr) elif (C // Wr) == 0: print((C // Wb)*Hb) else: nmax = (C // Wr) pmax = nmax*Hr + ((C - nma...
{'test_cases': [{'type': 'stdin_stdout', 'input': '10 3 5 2 3\n', 'output': '16\n'}, {'type': 'stdin_stdout', 'input': '5 3 1 6 7\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '982068341 55 57 106 109\n', 'output': '513558662\n'}, {'type': 'stdin_stdout', 'input': '930064129 32726326 25428197 83013449 6450104...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/526/C'}
vfc_10558
```python import sys f = sys.stdin C, Hr, Hb, Wr, Wb = map(int, f.readline().strip().split()) if Hr/Wr < Hb/Wb: Hr, Hb, Wr, Wb = Hb, Hr, Wb, Wr if (C % Wr) == 0 and (C // Wr) > 0: print((C // Wr)*Hr) elif (C // Wr) == 0: print((C // Wb)*Hb) else: nmax = (C // Wr) pmax = nmax*Hr + ((C - nma...
10 3 5 2 3
16
16
true
1,754
apps
verifiable_code
202
Solve the following coding problem using the programming language python: Professor GukiZ makes a new robot. The robot are in the point with coordinates (x_1, y_1) and should go to the point (x_2, y_2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So ...
```python a, b = map(int, input().split()) d, c = map(int, input().split()) print(max(abs(a - d), abs(b - c))) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '0 0\n4 5\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '3 4\n6 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '0 0\n4 6\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '1 1\n-3 -5\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '-1 ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/620/A'}
vfc_10562
```python a, b = map(int, input().split()) d, c = map(int, input().split()) print(max(abs(a - d), abs(b - c))) ```
0 0 4 5
5
5
true
1,755
apps
verifiable_code
203
Solve the following coding problem using the programming language python: There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions:...
```python n = int(input()) s = input() countr = s.count('R') countd = n - countr cr = 0 cd = 0 i = 0 news = [] while countr != 0 and countd != 0: if s[i] == 'D': if cd == 0: cr += 1 countr -= 1 news.append('D') else: cd -= 1 else: if cr == ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\nDDRRR\n', 'output': 'D\n'}, {'type': 'stdin_stdout', 'input': '6\nDDRRRR\n', 'output': 'R\n'}, {'type': 'stdin_stdout', 'input': '1\nD\n', 'output': 'D\n'}, {'type': 'stdin_stdout', 'input': '1\nR\n', 'output': 'R\n'}, {'type': 'stdin_stdout', 'input': '2\nDR\n', 'o...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/749/C'}
vfc_10566
```python n = int(input()) s = input() countr = s.count('R') countd = n - countr cr = 0 cd = 0 i = 0 news = [] while countr != 0 and countd != 0: if s[i] == 'D': if cd == 0: cr += 1 countr -= 1 news.append('D') else: cd -= 1 else: if cr == ...
5 DDRRR
D
D
true
1,756
apps
verifiable_code
204
Solve the following coding problem using the programming language python: Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV ...
```python def gcd(a, b): while b: a, b = b, a % b return a a, b, x, y = list(map(int, input().split())) g = gcd(x, y) x //= g y //= g print(min(a // x, b // y)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '17 15 5 3\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '14 16 7 22\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '4 2 6 4\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1000000000000000000 1000000000000000000 999999866000004473 9999998220...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1041/B'}
vfc_10570
```python def gcd(a, b): while b: a, b = b, a % b return a a, b, x, y = list(map(int, input().split())) g = gcd(x, y) x //= g y //= g print(min(a // x, b // y)) ```
17 15 5 3
3
3
true
1,757
apps
verifiable_code
205
Solve the following coding problem using the programming language python: The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis. Aki is fond of numbers, especially those with trailing zeros. For example, the numbe...
```python n, k = map(int, input().split()) a = [] i = 2 while (i * i <= k): if (k % i == 0): a.append([i, 0]) while (k % i == 0): a[len(a) - 1][1] += 1 k //= i i += 1 if (k > 1): a.append([k, 1]) ans = 10 ** 20 for i in a: cnt = 0 x = i[0] while (x <= n): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 9\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '38 11\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '5 2\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '5 10\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1000000000000000000 10...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1114/C'}
vfc_10574
```python n, k = map(int, input().split()) a = [] i = 2 while (i * i <= k): if (k % i == 0): a.append([i, 0]) while (k % i == 0): a[len(a) - 1][1] += 1 k //= i i += 1 if (k > 1): a.append([k, 1]) ans = 10 ** 20 for i in a: cnt = 0 x = i[0] while (x <= n): ...
6 9
1
1
true
1,758
apps
verifiable_code
206
Solve the following coding problem using the programming language python: A frog is initially at position $0$ on the number line. The frog has two positive integers $a$ and $b$. From a position $k$, it can either jump to position $k+a$ or $k-b$. Let $f(x)$ be the number of distinct integers the frog can reach if it n...
```python import math m,a,b=map(int,input().split()) g=math.gcd(a,b) a1=a//g b1=b//g alls=g*(a1+b1-1) dists=[0]+[-1]*(a1+b1-1) dist=0 far=0 while dist!=b1: if dist<b1: dist+=a1 far=max(dist,far) else: dist-=b1 if dists[dist]==-1: dists[dist]=far tot=0 for i in range(a1+b1): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7 5 3\n', 'output': '19\n'}, {'type': 'stdin_stdout', 'input': '1000000000 1 2019\n', 'output': '500000001500000001\n'}, {'type': 'stdin_stdout', 'input': '100 100000 1\n', 'output': '101\n'}, {'type': 'stdin_stdout', 'input': '6 4 5\n', 'output': '10\n'}, {'type': 'st...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1146/D'}
vfc_10578
```python import math m,a,b=map(int,input().split()) g=math.gcd(a,b) a1=a//g b1=b//g alls=g*(a1+b1-1) dists=[0]+[-1]*(a1+b1-1) dist=0 far=0 while dist!=b1: if dist<b1: dist+=a1 far=max(dist,far) else: dist-=b1 if dists[dist]==-1: dists[dist]=far tot=0 for i in range(a1+b1): ...
7 5 3
19
19
true
1,759
apps
verifiable_code
207
Solve the following coding problem using the programming language python: Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence a_1, a_2, ..., a_{n} of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, th...
```python def read_ints(): return [int(i) for i in input().split()] n = read_ints() a = read_ints() if len(a) % 2 and a[0] % 2 and a[-1] % 2: print('Yes') else: print('No') ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 3 5\n', 'output': 'Yes\n'}, {'type': 'stdin_stdout', 'input': '5\n1 0 1 5 1\n', 'output': 'Yes\n'}, {'type': 'stdin_stdout', 'input': '3\n4 3 1\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'input': '4\n3 9 9 3\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'in...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/849/A'}
vfc_10582
```python def read_ints(): return [int(i) for i in input().split()] n = read_ints() a = read_ints() if len(a) % 2 and a[0] % 2 and a[-1] % 2: print('Yes') else: print('No') ```
3 1 3 5
Yes
Yes
true
1,760
apps
verifiable_code
208
Solve the following coding problem using the programming language python: Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the g...
```python x1, y1, x2, y2 = map(int, input().split()) #diagonal if x1 != x2 and y1 != y2: if abs(x1 - x2) == abs(y1 - y2): print(x1, y2, x2, y1) else: print(-1) #same side elif x1 == x2: aux = abs(y2 - y1) print(x1 + aux, y1, x1 + aux, y2) elif y1 == y2: aux = abs(x2 - x1) print(x...
{'test_cases': [{'type': 'stdin_stdout', 'input': '0 0 0 1\n', 'output': '1 0 1 1\n'}, {'type': 'stdin_stdout', 'input': '0 0 1 1\n', 'output': '0 1 1 0\n'}, {'type': 'stdin_stdout', 'input': '0 0 1 2\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '-100 -100 100 100\n', 'output': '-100 100 100 -100\n'}, {'typ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/459/A'}
vfc_10586
```python x1, y1, x2, y2 = map(int, input().split()) #diagonal if x1 != x2 and y1 != y2: if abs(x1 - x2) == abs(y1 - y2): print(x1, y2, x2, y1) else: print(-1) #same side elif x1 == x2: aux = abs(y2 - y1) print(x1 + aux, y1, x1 + aux, y2) elif y1 == y2: aux = abs(x2 - x1) print(x...
0 0 0 1
1 0 1 1
1 0 1 1
true
1,761
apps
verifiable_code
209
Solve the following coding problem using the programming language python: Jzzhu has invented a kind of sequences, they meet the following property:$f_{1} = x ; f_{2} = y ; \forall i(i \geq 2), f_{i} = f_{i - 1} + f_{i + 1}$ You are given x and y, please calculate f_{n} modulo 1000000007 (10^9 + 7). -----Input----- ...
```python def main(): x, y = [int(i) for i in input().split()] n = int(input()) result = [x, y, y - x, -x, -y, x - y][(n - 1) % 6] print(result % 1000000007) main() ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 3\n3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '0 -1\n2\n', 'output': '1000000006\n'}, {'type': 'stdin_stdout', 'input': '-9 -11\n12345\n', 'output': '1000000005\n'}, {'type': 'stdin_stdout', 'input': '0 0\n1000000000\n', 'output': '0\n'}, {'type': 'std...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/450/B'}
vfc_10590
```python def main(): x, y = [int(i) for i in input().split()] n = int(input()) result = [x, y, y - x, -x, -y, x - y][(n - 1) % 6] print(result % 1000000007) main() ```
2 3 3
1
1
true
1,762
apps
verifiable_code
210
Solve the following coding problem using the programming language python: One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new ar...
```python from sys import stdin n = int(input()) a = [int(x) for x in input().split()] f = False for i in range(len(a)): if a[i] != 0: ln = i f = True break if not f: print('NO') else: print('YES') l = 0 i = ln + 1 ans = [] while i < len(a): if a[i] == 0: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2 -3\n', 'output': 'YES\n3\n1 1\n2 2\n3 3\n'}, {'type': 'stdin_stdout', 'input': '8\n9 -12 3 4 -4 -10 7 3\n', 'output': 'YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n'}, {'type': 'stdin_stdout', 'input': '1\n0\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'in...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/754/A'}
vfc_10594
```python from sys import stdin n = int(input()) a = [int(x) for x in input().split()] f = False for i in range(len(a)): if a[i] != 0: ln = i f = True break if not f: print('NO') else: print('YES') l = 0 i = ln + 1 ans = [] while i < len(a): if a[i] == 0: ...
3 1 2 -3
YES 3 1 1 2 2 3 3
YES 3 1 1 2 2 3 3
true
1,763
apps
verifiable_code
211
Solve the following coding problem using the programming language python: Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on...
```python MOD = 1000000009 n,m,k = [int(x) for x in input().split()] num0 = n-m num1fin = num0*(k-1) if num1fin >= m: print(m) else: num1open = m-num1fin sets = num1open//k rem = num1open%k print(((pow(2,sets,MOD)-1)*2*k+rem+num1fin)%MOD) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3 2\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '5 4 2\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '300 300 3\n', 'output': '17717644\n'}, {'type': 'stdin_stdout', 'input': '300 282 7\n', 'output': '234881124\n'}, {'type': 'stdin_stdout', 'inp...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/337/C'}
vfc_10598
```python MOD = 1000000009 n,m,k = [int(x) for x in input().split()] num0 = n-m num1fin = num0*(k-1) if num1fin >= m: print(m) else: num1open = m-num1fin sets = num1open//k rem = num1open%k print(((pow(2,sets,MOD)-1)*2*k+rem+num1fin)%MOD) ```
5 3 2
3
3
true
1,764
apps
verifiable_code
213
Solve the following coding problem using the programming language python: In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, t...
```python def floo(num, k): return (num - 1) // k + 1 def main(): n, m = map(int, input().split()) low = 1 high = 10**9 if (m == 0): if (n == 1): print(1) else: print(-1) return for i in range(m): k, f = map(int, input().split()) low = max(low, (k + f - 1) // f) if (f > 1): high = min(high...
{'test_cases': [{'type': 'stdin_stdout', 'input': '10 3\n6 2\n2 1\n7 3\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '8 4\n3 1\n6 2\n5 2\n2 1\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '8 3\n7 2\n6 2\n1 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4 2\n8 3\n3 1\n', 'output': '2\n'}...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/858/B'}
vfc_10606
```python def floo(num, k): return (num - 1) // k + 1 def main(): n, m = map(int, input().split()) low = 1 high = 10**9 if (m == 0): if (n == 1): print(1) else: print(-1) return for i in range(m): k, f = map(int, input().split()) low = max(low, (k + f - 1) // f) if (f > 1): high = min(high...
10 3 6 2 2 1 7 3
4
4
true
1,765
apps
verifiable_code
214
Solve the following coding problem using the programming language python: Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X. X. .X XX XX Bishwocks don't attack any s...
```python f = [] for i in range(2): f.append(list(input())) answer = 0 n = len(f[0]) for i in range(n): if f[0][i] == f[1][i] == '0' and i + 1 < n: if f[0][i + 1] == '0': answer += 1 f[0][i + 1] = 'X' elif f[1][i + 1] == '0': answer += 1 f[1][i ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '00\n00\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '00X00X0XXX0\n0XXX0X00X00\n', 'output': '4'}, {'type': 'stdin_stdout', 'input': '0X0X0\n0X0X0\n', 'output': '0'}, {'type': 'stdin_stdout', 'input': '0XXX0\n00000\n', 'output': '2'}, {'type': 'stdin_stdout', '...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/991/D'}
vfc_10610
```python f = [] for i in range(2): f.append(list(input())) answer = 0 n = len(f[0]) for i in range(n): if f[0][i] == f[1][i] == '0' and i + 1 < n: if f[0][i + 1] == '0': answer += 1 f[0][i + 1] = 'X' elif f[1][i + 1] == '0': answer += 1 f[1][i ...
00 00
1
1
true
1,766
apps
verifiable_code
215
Solve the following coding problem using the programming language python: Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: let...
```python def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() n = int(input()) a = list(input()) ans = 0 for i in range(n): for j in range(i,n): b = a[i:j+1] for k in b: if k.lower() != k: brea...
{'test_cases': [{'type': 'stdin_stdout', 'input': '11\naaaaBaabAbA\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '12\nzACaAbbaazzC\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3\nABC\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1\na\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/864/B'}
vfc_10614
```python def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() n = int(input()) a = list(input()) ans = 0 for i in range(n): for j in range(i,n): b = a[i:j+1] for k in b: if k.lower() != k: brea...
11 aaaaBaabAbA
2
2
true
1,767
apps
verifiable_code
216
Solve the following coding problem using the programming language python: You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be t...
```python n=int(input()) arr= list(map(int,input().strip().split(' '))) s = 0 for i in range(n): s+=abs(arr[i]) print(s) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 -2 0\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '6\n16 23 16 15 42 8\n', 'output': '120\n'}, {'type': 'stdin_stdout', 'input': '1\n-1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/946/A'}
vfc_10618
```python n=int(input()) arr= list(map(int,input().strip().split(' '))) s = 0 for i in range(n): s+=abs(arr[i]) print(s) ```
3 1 -2 0
3
3
true
1,768
apps
verifiable_code
217
Solve the following coding problem using the programming language python: A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it im...
```python def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() a,b,f,k = map_input() tot = a*k s = 2*a-f cur = 0 cnt = b go = 0 ans = 0 while cur < tot: go = 1-go if(go == 1): if cnt < s and cnt < tot-cur: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 9 2 4\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '6 10 2 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '6 5 4 3\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '2 2 1 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '10 4 6 ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/864/C'}
vfc_10622
```python def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() a,b,f,k = map_input() tot = a*k s = 2*a-f cur = 0 cnt = b go = 0 ans = 0 while cur < tot: go = 1-go if(go == 1): if cnt < s and cnt < tot-cur: ...
6 9 2 4
4
4
true
1,769
apps
verifiable_code
218
Solve the following coding problem using the programming language python: You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". ...
```python a, b, c = map(int, input().split(' ')) x = input() for i in range(105): for j in range(105): if i*b+j*c == a: print(i+j) for k in range(i): print(x[:b]) x = x[b:] for l in range(j): print(x[:c]) x =...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 2 3\nHello\n', 'output': '2\nHe\nllo\n'}, {'type': 'stdin_stdout', 'input': '10 9 5\nCodeforces\n', 'output': '2\nCodef\norces\n'}, {'type': 'stdin_stdout', 'input': '6 4 5\nPrivet\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '8 1 1\nabacabac\n', 'output'...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/612/A'}
vfc_10626
```python a, b, c = map(int, input().split(' ')) x = input() for i in range(105): for j in range(105): if i*b+j*c == a: print(i+j) for k in range(i): print(x[:b]) x = x[b:] for l in range(j): print(x[:c]) x =...
5 2 3 Hello
2 He llo
2 He llo
true
1,770
apps
verifiable_code
219
Solve the following coding problem using the programming language python: A sportsman starts from point x_{start} = 0 and runs to point with coordinate x_{finish} = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s m...
```python n, m, s, d = list(map(int, input().split())) beg = [float('-inf')] end = [float('-inf')] a = [int(i) for i in input().split()] for x in sorted(a): if (x - end[-1] > s + 1): beg.append(x) end.append(x) else: end[-1] = x last = 0 R = [] J = [] for i in range(1, len(beg)): R.append(beg[i] - 1 - las...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 10 1 3\n3 4 7\n', 'output': 'RUN 2\nJUMP 3\nRUN 1\nJUMP 2\nRUN 2\n'}, {'type': 'stdin_stdout', 'input': '2 9 2 3\n6 4\n', 'output': 'IMPOSSIBLE\n'}, {'type': 'stdin_stdout', 'input': '10 100 2 8\n93 35 24 87 39 46 86 37 73 33\n', 'output': 'RUN 23\nJUMP 2\nRUN 7\nJUM...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/637/D'}
vfc_10630
```python n, m, s, d = list(map(int, input().split())) beg = [float('-inf')] end = [float('-inf')] a = [int(i) for i in input().split()] for x in sorted(a): if (x - end[-1] > s + 1): beg.append(x) end.append(x) else: end[-1] = x last = 0 R = [] J = [] for i in range(1, len(beg)): R.append(beg[i] - 1 - las...
3 10 1 3 3 4 7
RUN 2 JUMP 3 RUN 1 JUMP 2 RUN 2
RUN 2 JUMP 3 RUN 1 JUMP 2 RUN 2
true
1,771
apps
verifiable_code
220
Solve the following coding problem using the programming language python: Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? -----Input----- The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), th...
```python s, x = list(map(int, input().split())) rem = int(s == x) * 2 p, t, cur = [], 0, 1 for i in range(64): if x % 2: t += 1 s -= cur else: p.append(cur * 2) cur *= 2 x //= 2 for i in p[::-1]: if s >= i: s -= i ans = 0 if s else 2 ** t - rem print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '9 5\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '3 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '5 2\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '6 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '549755813887 549755813887...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/627/A'}
vfc_10634
```python s, x = list(map(int, input().split())) rem = int(s == x) * 2 p, t, cur = [], 0, 1 for i in range(64): if x % 2: t += 1 s -= cur else: p.append(cur * 2) cur *= 2 x //= 2 for i in p[::-1]: if s >= i: s -= i ans = 0 if s else 2 ** t - rem print(ans) ```
9 5
4
4
true
1,772
apps
verifiable_code
221
Solve the following coding problem using the programming language python: Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over. This time Miroslav laid out $n$ skewers parallel to each other, and e...
```python n, k = map(int, input().split()) if n <= k + k + 1: print(1) print((n + 1) // 2) else: answer = -1 answer_n = 10**100 for i in range(min(k + 1, n)): t = n - (k + i + 1) if t % (k + k + 1) >= k + 1: if 2 + t // (k + k + 1) < answer_n: answer = i +...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7 2\n', 'output': '2\n1 6 \n'}, {'type': 'stdin_stdout', 'input': '5 1\n', 'output': '2\n1 4 \n'}, {'type': 'stdin_stdout', 'input': '10 0\n', 'output': '10\n1 2 3 4 5 6 7 8 9 10 \n'}, {'type': 'stdin_stdout', 'input': '10 1\n', 'output': '4\n1 4 7 10 \n'}, {'type': 's...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1040/B'}
vfc_10638
```python n, k = map(int, input().split()) if n <= k + k + 1: print(1) print((n + 1) // 2) else: answer = -1 answer_n = 10**100 for i in range(min(k + 1, n)): t = n - (k + i + 1) if t % (k + k + 1) >= k + 1: if 2 + t // (k + k + 1) < answer_n: answer = i +...
7 2
2 1 6
2 1 6
true
1,773
apps
verifiable_code
222
Solve the following coding problem using the programming language python: You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros....
```python ar=[] for i in range(1,10**5): if(i*i>2*10**9):break ar.append(i*i) s=input() ans=len(s) for x in ar: s2=str(x) i=0 for x in range(len(s)): if i<len(s2) and s[x]==s2[i]: i+=1 if(i==len(s2)): ans=min(ans,len(s)-i) if(ans==len(s)): print(-1) else: prin...
{'test_cases': [{'type': 'stdin_stdout', 'input': '8314\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '625\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '333\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '1881388645\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '1059472069\n', '...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/962/C'}
vfc_10642
```python ar=[] for i in range(1,10**5): if(i*i>2*10**9):break ar.append(i*i) s=input() ans=len(s) for x in ar: s2=str(x) i=0 for x in range(len(s)): if i<len(s2) and s[x]==s2[i]: i+=1 if(i==len(s2)): ans=min(ans,len(s)-i) if(ans==len(s)): print(-1) else: prin...
8314
2
2
true
1,774
apps
verifiable_code
223
Solve the following coding problem using the programming language python: Let's define a function $f(p)$ on a permutation $p$ as follows. Let $g_i$ be the greatest common divisor (GCD) of elements $p_1$, $p_2$, ..., $p_i$ (in other words, it is the GCD of the prefix of length $i$). Then $f(p)$ is the number of distinc...
```python p=10**9+7 import math def inv(k,p): prod=1 while k>1: prod*=(p//k+1) k=(k*(p//k+1))%p return prod%p n=int(input()) a=[] k=int(math.log2(n)) x=n while x>0: y=x//2 a.append(x-y) x=y c=[sum(a[i:]) for i in range(k+1)] b=[n//(3*2**i)-n//(6*2**i) for i in range(k+1)] d=[n//2...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '3\n', 'output': '4'}, {'type': 'stdin_stdout', 'input': '6\n', 'output': '120'}, {'type': 'stdin_stdout', 'input': '10\n', 'output': '15120'}, {'type': 'stdin_stdout', 'input': '64\n', 'output': '676169815'}, {'t...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1174/E'}
vfc_10646
```python p=10**9+7 import math def inv(k,p): prod=1 while k>1: prod*=(p//k+1) k=(k*(p//k+1))%p return prod%p n=int(input()) a=[] k=int(math.log2(n)) x=n while x>0: y=x//2 a.append(x-y) x=y c=[sum(a[i:]) for i in range(k+1)] b=[n//(3*2**i)-n//(6*2**i) for i in range(k+1)] d=[n//2...
2
1
1
true
1,775
apps
verifiable_code
224
Solve the following coding problem using the programming language python: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowe...
```python # You lost the game. s = str(input()) n = len(s) d = -1 r = 0 V = "AEIOUY" for i in range(n): if V.count(s[i]): r = max(r,i-d) d = i print(max(r, n-d)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': 'ABABBBACFEYUKOTT\n', 'output': '4'}, {'type': 'stdin_stdout', 'input': 'AAA\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': 'A\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': 'B\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': 'AEYUIOAEIYAEOUIYOEIUYEAO...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/733/A'}
vfc_10650
```python # You lost the game. s = str(input()) n = len(s) d = -1 r = 0 V = "AEIOUY" for i in range(n): if V.count(s[i]): r = max(r,i-d) d = i print(max(r, n-d)) ```
ABABBBACFEYUKOTT
4
4
true
1,776
apps
verifiable_code
225
Solve the following coding problem using the programming language python: Dawid has four bags of candies. The $i$-th of them contains $a_i$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same a...
```python l=list(map(int,input().split())) for i in range(16): cur1,cur2=0,0 for j in range(4): if (i&(1<<j))==0: cur1+=l[j] else: cur2+=l[j] if cur1==cur2: print("YES") quit() print("NO") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 7 11 5\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '7 3 2 5\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '3 14 36 53\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '30 74 41 63\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'inp...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1230/A'}
vfc_10654
```python l=list(map(int,input().split())) for i in range(16): cur1,cur2=0,0 for j in range(4): if (i&(1<<j))==0: cur1+=l[j] else: cur2+=l[j] if cur1==cur2: print("YES") quit() print("NO") ```
1 7 11 5
YES
YES
true
1,777
apps
verifiable_code
226
Solve the following coding problem using the programming language python: You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie,...
```python n = int(input()) a = list(map(int, input().split())) a = a[::-1] d = 0 for i in range(len(a)): d = max(0 + d, a[i] + (sum(a[:i]) - d)) print(sum(a)-d, d) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n141 592 653\n', 'output': '653 733\n'}, {'type': 'stdin_stdout', 'input': '5\n10 21 10 21 10\n', 'output': '31 41\n'}, {'type': 'stdin_stdout', 'input': '1\n100000\n', 'output': '0 100000\n'}, {'type': 'stdin_stdout', 'input': '50\n100000 100000 100000 100000 100000...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/859/C'}
vfc_10658
```python n = int(input()) a = list(map(int, input().split())) a = a[::-1] d = 0 for i in range(len(a)): d = max(0 + d, a[i] + (sum(a[:i]) - d)) print(sum(a)-d, d) ```
3 141 592 653
653 733
653 733
true
1,778
apps
verifiable_code
227
Solve the following coding problem using the programming language python: You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 ≤ i ≤ m) contains the value of zero. Consider the follow...
```python def Solve(x,B): if((X,x,B) in Mem): return Mem[(X,x,B)] if(len(B)>X): return False if(x==len(L)): return True if(Form(L[x],B)): A=list(B) for e in range(len(B)): r=A[e] A[e]=L[x] if(Solve(x+1,tuple(sorted(A)))): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 2 3 6 8\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n3 6 5\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '6\n2 4 8 6 10 18\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '7\n1 2 4 5 3 6 7\n', 'output': '3\n'}, {'type': 'stdin_std...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/279/D'}
vfc_10662
```python def Solve(x,B): if((X,x,B) in Mem): return Mem[(X,x,B)] if(len(B)>X): return False if(x==len(L)): return True if(Form(L[x],B)): A=list(B) for e in range(len(B)): r=A[e] A[e]=L[x] if(Solve(x+1,tuple(sorted(A)))): ...
5 1 2 3 6 8
2
2
true
1,779
apps
verifiable_code
228
Solve the following coding problem using the programming language python: Alice and Bob are playing a game with $n$ piles of stones. It is guaranteed that $n$ is an even number. The $i$-th pile has $a_i$ stones. Alice and Bob will play a game alternating turns with Alice going first. On a player's turn, they must ch...
```python n=int(input()) s=list(map(int,input().split())) print("Bob"if s.count(min(s))>n/2 else"Alice") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n8 8\n', 'output': 'Bob\n'}, {'type': 'stdin_stdout', 'input': '4\n3 1 4 1\n', 'output': 'Alice\n'}, {'type': 'stdin_stdout', 'input': '4\n42 49 42 42\n', 'output': 'Bob\n'}, {'type': 'stdin_stdout', 'input': '8\n11 21 31 41 41 31 21 11\n', 'output': 'Alice\n'}, {'ty...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1147/C'}
vfc_10666
```python n=int(input()) s=list(map(int,input().split())) print("Bob"if s.count(min(s))>n/2 else"Alice") ```
2 8 8
Bob
Bob
true
1,780
apps
verifiable_code
229
Solve the following coding problem using the programming language python: Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x a...
```python read = lambda: list(map(int, input().split())) n = int(input()) a = list(read()) s = set() for i in a: s.add(i) f1 = len(s) < 3 f2 = len(s) == 3 and max(s) + min(s) == 2 * sorted(s)[1] print('YES' if f1 or f2 else 'NO') ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 3 3 2 1\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2 3 4 5\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '2\n1 2\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '3\n1 2 3\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'i...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/714/B'}
vfc_10670
```python read = lambda: list(map(int, input().split())) n = int(input()) a = list(read()) s = set() for i in a: s.add(i) f1 = len(s) < 3 f2 = len(s) == 3 and max(s) + min(s) == 2 * sorted(s)[1] print('YES' if f1 or f2 else 'NO') ```
5 1 3 3 2 1
YES
YES
true
1,781
apps
verifiable_code
230
Solve the following coding problem using the programming language python: Given is a string S of length N. Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. More formally, find the maximum positive integer len such that there exist integers l_1 a...
```python n = int(input()) s = input() j = 1 result = [] for i in range(n): while (j < n-1) and (s[i:j] in s[j:]): j += 1 result.append(j-i-1) print(max(result)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\nababa\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '2\nxy\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '13\nstrangeorange\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '5000\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
{'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc141/tasks/abc141_e'}
vfc_10674
```python n = int(input()) s = input() j = 1 result = [] for i in range(n): while (j < n-1) and (s[i:j] in s[j:]): j += 1 result.append(j-i-1) print(max(result)) ```
5 ababa
2
2
true
1,782
apps
verifiable_code
231
Solve the following coding problem using the programming language python: The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in t...
```python n, a = list(map(int,input().split())) if a % 2 == 1: print(a // 2 + 1) else: print((n-a) // 2 + 1) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 2\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '8 5\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '2 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2 2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '10 1\n', 'output': '1\n'}...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/638/A'}
vfc_10678
```python n, a = list(map(int,input().split())) if a % 2 == 1: print(a // 2 + 1) else: print((n-a) // 2 + 1) ```
4 2
2
2
true
1,783
apps
verifiable_code
232
Solve the following coding problem using the programming language python: There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-kno...
```python s = input().split() n, m = int(s[0]), int(s[1]) cl = list(map(int, input().split())) com = list(map(int, input().split())) res = False for i in range(n): for j in range(i, n): e = True t = cl[i:j+1] for k in range(1, m+1): e = t.count(k)==com[k-1] and e if e: res = True bre...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 2\n1 1 2 2 1\n1 2\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n1\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '2 1\n1 1\n1\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '2 1\n1 1\n2\n', 'output': 'YES\n'}, {'type': 'stdi...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/958/F1'}
vfc_10682
```python s = input().split() n, m = int(s[0]), int(s[1]) cl = list(map(int, input().split())) com = list(map(int, input().split())) res = False for i in range(n): for j in range(i, n): e = True t = cl[i:j+1] for k in range(1, m+1): e = t.count(k)==com[k-1] and e if e: res = True bre...
5 2 1 1 2 2 1 1 2
YES
YES
true
1,784
apps
verifiable_code
233
Solve the following coding problem using the programming language python: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. R...
```python x = 0 y = 0 for _ in range(int(input())): a, b = list(map(int, input().split())) x += (a > b) y += (b > a) if x > y: print("Mishka") elif y > x: print("Chris") else: print("Friendship is magic!^^") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n3 5\n2 1\n4 2\n', 'output': 'Mishka'}, {'type': 'stdin_stdout', 'input': '2\n6 1\n1 6\n', 'output': 'Friendship is magic!^^'}, {'type': 'stdin_stdout', 'input': '3\n1 5\n3 3\n2 2\n', 'output': 'Chris'}, {'type': 'stdin_stdout', 'input': '6\n4 1\n4 2\n5 3\n5 1\n5 3\n...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/703/A'}
vfc_10686
```python x = 0 y = 0 for _ in range(int(input())): a, b = list(map(int, input().split())) x += (a > b) y += (b > a) if x > y: print("Mishka") elif y > x: print("Chris") else: print("Friendship is magic!^^") ```
3 3 5 2 1 4 2
Mishka
Mishka
true
1,785
apps
verifiable_code
234
Solve the following coding problem using the programming language python: One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he ra...
```python r, c = list(map(int, input().split())) b = [list(input()) for i in range(r)] for y in range(r): for x in range(c): if b[y][x] == '.': b[y][x] = '0' ok = True for Y in range(r): for X in range(c): if not b[Y][X].isdigit(): continue p = 0 for dy ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n111\n1*1\n111\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '2 4\n*.*.\n1211\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': '1 10\n.....1*1..\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '1 1\n4\n', 'output': 'NO'}, {'type': 'stdin_std...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/984/B'}
vfc_10690
```python r, c = list(map(int, input().split())) b = [list(input()) for i in range(r)] for y in range(r): for x in range(c): if b[y][x] == '.': b[y][x] = '0' ok = True for Y in range(r): for X in range(c): if not b[Y][X].isdigit(): continue p = 0 for dy ...
3 3 111 1*1 111
YES
YES
true
1,786
apps
verifiable_code
235
Solve the following coding problem using the programming language python: After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means...
```python def can(n, k): total = n s = 0 while n > 0: cur = min(n, k) s += cur n -= cur n -= n // 10 return s * 2 >= total n = int(input()) le = 0 rg = n while rg - le > 1: mid = (rg + le) // 2 if can(n, mid): rg = mid else: le = mid pr...
{'test_cases': [{'type': 'stdin_stdout', 'input': '68\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '42\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '43\n', 'output': '2\n'}, {'type...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/991/C'}
vfc_10694
```python def can(n, k): total = n s = 0 while n > 0: cur = min(n, k) s += cur n -= cur n -= n // 10 return s * 2 >= total n = int(input()) le = 0 rg = n while rg - le > 1: mid = (rg + le) // 2 if can(n, mid): rg = mid else: le = mid pr...
68
3
3
true
1,787
apps
verifiable_code
236
Solve the following coding problem using the programming language python: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. $0$ You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link a...
```python def main(): s = input() links = s.count('-') pearls = s.count('o') if pearls == 0 or links % pearls == 0: print('YES') else: print('NO') main() ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '-o-o--\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '-o---\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '-o---o-\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': 'ooo\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '---\n', '...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/980/A'}
vfc_10698
```python def main(): s = input() links = s.count('-') pearls = s.count('o') if pearls == 0 or links % pearls == 0: print('YES') else: print('NO') main() ```
-o-o--
YES
YES
true
1,788
apps
verifiable_code
237
Solve the following coding problem using the programming language python: n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's ...
```python n, m, k = map(int, input().split()) ans = 1 m -= n left = k - 1 right = n - k put = 1 while (m >= put): m -= put ans += 1 put += (left > 0) + (right > 0) if (left): left -= 1 if (right): right -= 1 if (left == right == 0): ans += (m // put) break print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 6 2\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 10 3\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '3 6 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3 3 3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1 1 1\n', 'outpu...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/760/B'}
vfc_10702
```python n, m, k = map(int, input().split()) ans = 1 m -= n left = k - 1 right = n - k put = 1 while (m >= put): m -= put ans += 1 put += (left > 0) + (right > 0) if (left): left -= 1 if (right): right -= 1 if (left == right == 0): ans += (m // put) break print(ans) ```
4 6 2
2
2
true
1,789
apps
verifiable_code
238
Solve the following coding problem using the programming language python: You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k...
```python N, M, K = list(map(int, input().split())) A = [int(a) for a in input().split()] S = [0] for a in A: S.append(S[-1]+M*a-K) MI = [(10**50)] * M ans = 0 for i in range(N+1): MI[i%M] = min(MI[i%M], S[i]) for j in range(M): ans = max(ans, (S[i]-MI[(i-j)%M] - K*((-j)%M))//M) print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '7 3 10\n2 -4 15 -3 4 8 3\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '5 2 1000\n-13 -4 -9 -20 -11\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '5 10 10\n1000000000 1000000000 1000000000 1000000000 1000000000\n', 'output': '4999999990\n'}, {'type'...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1197/D'}
vfc_10706
```python N, M, K = list(map(int, input().split())) A = [int(a) for a in input().split()] S = [0] for a in A: S.append(S[-1]+M*a-K) MI = [(10**50)] * M ans = 0 for i in range(N+1): MI[i%M] = min(MI[i%M], S[i]) for j in range(M): ans = max(ans, (S[i]-MI[(i-j)%M] - K*((-j)%M))//M) print(ans) ```
7 3 10 2 -4 15 -3 4 8 3
7
7
true
1,790
apps
verifiable_code
240
Solve the following coding problem using the programming language python: Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n. Magically, all the numbers were shuffled in arbitrary order while this note was...
```python import math from collections import Counter s = list(map(int, input())) substr = input().rstrip() t = list(map(int, substr)) m = len(s) x, y = 0, m z = (x + y) // 2 while z != x: if z + math.floor(math.log10(z)) + 1 <= m: x = z else: y = z z = (x + y)//2 m1 = z k = math.floor(mat...
{'test_cases': [{'type': 'stdin_stdout', 'input': '003512\n021\n', 'output': '30021\n'}, {'type': 'stdin_stdout', 'input': '199966633300\n63\n', 'output': '3036366999\n'}, {'type': 'stdin_stdout', 'input': '01\n0\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '0000454312911\n9213544\n', 'output': '92135440000\...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/670/F'}
vfc_10714
```python import math from collections import Counter s = list(map(int, input())) substr = input().rstrip() t = list(map(int, substr)) m = len(s) x, y = 0, m z = (x + y) // 2 while z != x: if z + math.floor(math.log10(z)) + 1 <= m: x = z else: y = z z = (x + y)//2 m1 = z k = math.floor(mat...
003512 021
30021
30021
true
1,792
apps
verifiable_code
241
Solve the following coding problem using the programming language python: Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets so...
```python def main(): n, m, mn, mx = map(int, input().split()) A = list(map(int, input().split())) a = min(A) b = max(A) if a < mn or b > mx: print("Incorrect") return cnt = 0 if a > mn: cnt += 1 if b < mx: cnt += 1 if m + cnt <= n: print("Correct") else: print("Incorrect") main() ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 1 1 2\n1\n', 'output': 'Correct\n'}, {'type': 'stdin_stdout', 'input': '3 1 1 3\n2\n', 'output': 'Correct\n'}, {'type': 'stdin_stdout', 'input': '2 1 1 3\n2\n', 'output': 'Incorrect\n'}, {'type': 'stdin_stdout', 'input': '3 1 1 5\n3\n', 'output': 'Correct\n'}, {'type...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/413/A'}
vfc_10718
```python def main(): n, m, mn, mx = map(int, input().split()) A = list(map(int, input().split())) a = min(A) b = max(A) if a < mn or b > mx: print("Incorrect") return cnt = 0 if a > mn: cnt += 1 if b < mx: cnt += 1 if m + cnt <= n: print("Correct") else: print("Incorrect") main() ```
2 1 1 2 1
Correct
Correct
true
1,793
apps
verifiable_code
242
Solve the following coding problem using the programming language python: Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great progr...
```python m = int(input()) a = 0 while m > 0: a += 5 b = a c = 0 while b % 5 == 0: b //= 5 c += 1 m -= c if m < 0: print(0) else: print(5) print(a, a + 1, a + 2, a + 3, a + 4) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '1\n', 'output': '5\n5 6 7 8 9 '}, {'type': 'stdin_stdout', 'input': '5\n', 'output': '0'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '5\n10 11 12 13 14 '}, {'type': 'stdin_stdout', 'input': '3\n', 'output': '5\n15 16 17 18 19 '}, {'type': 'stdin_stdout', 'inpu...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/633/B'}
vfc_10722
```python m = int(input()) a = 0 while m > 0: a += 5 b = a c = 0 while b % 5 == 0: b //= 5 c += 1 m -= c if m < 0: print(0) else: print(5) print(a, a + 1, a + 2, a + 3, a + 4) ```
1
5 5 6 7 8 9
5 5 6 7 8 9
true
1,794
apps
verifiable_code
244
Solve the following coding problem using the programming language python: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. The...
```python def main(): n = int(input()) k = int(input()) n %= 6 a = [0, 1, 2] for i in range(1, n + 1): if (i % 2 == 1): a[0], a[1] = a[1], a[0] else: a[1], a[2] = a[2], a[1] print(a[k]) main() ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2\n2\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3\n1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n2\n', 'output': '0...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/777/A'}
vfc_10730
```python def main(): n = int(input()) k = int(input()) n %= 6 a = [0, 1, 2] for i in range(1, n + 1): if (i % 2 == 1): a[0], a[1] = a[1], a[0] else: a[1], a[2] = a[2], a[1] print(a[k]) main() ```
4 2
1
1
true
1,795
apps
verifiable_code
245
Solve the following coding problem using the programming language python: You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the inte...
```python n = int(input()) s = 0 INF = 10**9 minx = miny = INF maxx = maxy = -INF for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) s += abs(x1 - x2) * abs(y1 - y2) minx = min(minx, x1, x2) maxx = max(maxx, x1, x2) miny = min(miny, y1, y2) maxy = max(maxy, y1, y2) if (maxx - ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/325/A'}
vfc_10734
```python n = int(input()) s = 0 INF = 10**9 minx = miny = INF maxx = maxy = -INF for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) s += abs(x1 - x2) * abs(y1 - y2) minx = min(minx, x1, x2) maxx = max(maxx, x1, x2) miny = min(miny, y1, y2) maxy = max(maxy, y1, y2) if (maxx - ...
5 0 0 2 3 0 3 3 5 2 0 5 2 3 2 5 5 2 2 3 3
YES
YES
true
1,796
apps
verifiable_code
246
Solve the following coding problem using the programming language python: Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representatio...
```python def check(x, s): k = 0 for i in str(x): k += int(i) return x - k >= s n, s = map(int, input().split()) l = 0 r = n while r - l > 1: m = (l + r) // 2 if check(m, s): r = m else: l = m if check(r, s): print(n - r + 1) else: print(0) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '12 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '25 20\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '10 9\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '300 1000\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '500 1000\n', 'ou...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/817/C'}
vfc_10738
```python def check(x, s): k = 0 for i in str(x): k += int(i) return x - k >= s n, s = map(int, input().split()) l = 0 r = n while r - l > 1: m = (l + r) // 2 if check(m, s): r = m else: l = m if check(r, s): print(n - r + 1) else: print(0) ```
12 1
3
3
true
1,797
apps
verifiable_code
247
Solve the following coding problem using the programming language python: You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a...
```python n = int(input()) L = [(0, 0)] * n for i in range(n): t = input().split(' ') a = int(t[0]) b = int(t[1]) L[i] = (a, b) if n <= 4: print("YES") else: b0 = True b1 = True b2 = True L0 = [] L1 = [] L2 = [] for j in range(n): if (L[0][0]-L[1][0])*(L[0][1]-L[j...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n0 0\n0 1\n1 1\n1 -1\n2 2\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '5\n0 0\n1 0\n2 1\n1 1\n2 3\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '1\n-1000000000 1000000000\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '5\n2 -1\n-4 ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/961/D'}
vfc_10742
```python n = int(input()) L = [(0, 0)] * n for i in range(n): t = input().split(' ') a = int(t[0]) b = int(t[1]) L[i] = (a, b) if n <= 4: print("YES") else: b0 = True b1 = True b2 = True L0 = [] L1 = [] L2 = [] for j in range(n): if (L[0][0]-L[1][0])*(L[0][1]-L[j...
5 0 0 0 1 1 1 1 -1 2 2
YES
YES
true
1,798
apps
verifiable_code
248
Solve the following coding problem using the programming language python: Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer a...
```python mod=10**9+7 f=[0]*500000 def POW(a,b): if(b==0): return 1 if(b&1): return POW(a,b//2)**2*a%mod else: return POW(a,b//2)**2 def C(n,m): if(m>n): return 0 t=f[n]*POW(f[m],mod-2)%mod*POW(f[n-m],mod-2)%mod return t f[0]=1 for i in range(1,500000): f[i]=f[i-1]*i%mod a,b,k,t=list(map(int,input()....
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 2 2 1\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '1 1 1 2\n', 'output': '31\n'}, {'type': 'stdin_stdout', 'input': '2 12 3 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '4 6 2 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '4 6 2 2...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/712/D'}
vfc_10746
```python mod=10**9+7 f=[0]*500000 def POW(a,b): if(b==0): return 1 if(b&1): return POW(a,b//2)**2*a%mod else: return POW(a,b//2)**2 def C(n,m): if(m>n): return 0 t=f[n]*POW(f[m],mod-2)%mod*POW(f[n-m],mod-2)%mod return t f[0]=1 for i in range(1,500000): f[i]=f[i-1]*i%mod a,b,k,t=list(map(int,input()....
1 2 2 1
6
6
true
1,799
apps
verifiable_code
249
Solve the following coding problem using the programming language python: Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l...
```python import itertools import math def can_measure(a, d): return any(i + d in a for i in a) def main(): n, l, x, y = list(map(int, input().split())) a = set(map(int, input().split())) can_x = can_measure(a, x) can_y = can_measure(a, y) if can_x and can_y: print(0) elif can_x: print(1) print(y) eli...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 250 185 230\n0 185 250\n', 'output': '1\n230\n'}, {'type': 'stdin_stdout', 'input': '4 250 185 230\n0 20 185 250\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2 300 185 230\n0 300\n', 'output': '2\n185 230\n'}, {'type': 'stdin_stdout', 'input': '4 300 4 5\...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/479/D'}
vfc_10750
```python import itertools import math def can_measure(a, d): return any(i + d in a for i in a) def main(): n, l, x, y = list(map(int, input().split())) a = set(map(int, input().split())) can_x = can_measure(a, x) can_y = can_measure(a, y) if can_x and can_y: print(0) elif can_x: print(1) print(y) eli...
3 250 185 230 0 185 250
1 230
1 230
true
1,800
apps
verifiable_code
251
Solve the following coding problem using the programming language python: There is a toy building consisting of $n$ towers. Each tower consists of several cubes standing on each other. The $i$-th tower consists of $h_i$ cubes, so it has height $h_i$. Let's define operation slice on some height $H$ as following: for e...
```python def ii(): return int(input()) def mi(): return list(map(int, input().split())) def li(): return list(mi()) n, k = mi() h = li() m = max(h) f = [0] * (m + 1) for hi in h: f[hi] += 1 for i in range(m - 1, 0, -1): f[i] += f[i + 1] ans = 0 i = m while i > 0: if f[i] == n: break ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 5\n3 1 2 2 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4 5\n2 3 4 5\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '2 2\n1 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '5 5\n5 5 5 5 5\n', 'output': '0\n'}, {'type': 'stdin_stdout',...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1065/C'}
vfc_10758
```python def ii(): return int(input()) def mi(): return list(map(int, input().split())) def li(): return list(mi()) n, k = mi() h = li() m = max(h) f = [0] * (m + 1) for hi in h: f[hi] += 1 for i in range(m - 1, 0, -1): f[i] += f[i + 1] ans = 0 i = m while i > 0: if f[i] == n: break ...
5 5 3 1 2 2 4
2
2
true
1,802
apps
verifiable_code
252
Solve the following coding problem using the programming language python: Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$. First, Alice chooses a non-empty consecutive segment of cards $[l; r]...
```python n = int(input()) l = list(map(int,input().split())) curr = 0 best = 0 prevs = [0] * 31 for v in l: curr += v if v >= 0: for i in range(0, v): prevs[i] = curr for i in range(v, 31): best = max(curr - prevs[i] - i, best) else: for i in range(31): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n5 -2 10 -1 4\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '8\n5 2 5 3 -30 -30 6 9\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '3\n-10 6 -15\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1\n6\n', 'output': '0\n'}, {'type': 'stdin_st...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1359/D'}
vfc_10762
```python n = int(input()) l = list(map(int,input().split())) curr = 0 best = 0 prevs = [0] * 31 for v in l: curr += v if v >= 0: for i in range(0, v): prevs[i] = curr for i in range(v, 31): best = max(curr - prevs[i] - i, best) else: for i in range(31): ...
5 5 -2 10 -1 4
6
6
true
1,803
apps
verifiable_code
253
Solve the following coding problem using the programming language python: Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit...
```python a, b, c = sorted(map(int, input().split())) if a > 3: print('NO') elif a == 3: if b > 3: print('NO') elif b == 3: if c > 3: print('NO') else: print("YES") elif a == 1: print('YES') else: if b == 2: print('YES') elif b > 4: print('NO') elif b == 4: if c == 4: print('YES') else: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2 3\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '4 2 3\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '1499 1498 1500\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '1500 1500 1500\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'inp...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/911/C'}
vfc_10766
```python a, b, c = sorted(map(int, input().split())) if a > 3: print('NO') elif a == 3: if b > 3: print('NO') elif b == 3: if c > 3: print('NO') else: print("YES") elif a == 1: print('YES') else: if b == 2: print('YES') elif b > 4: print('NO') elif b == 4: if c == 4: print('YES') else: ...
2 2 3
YES
YES
true
1,804
apps
verifiable_code
254
Solve the following coding problem using the programming language python: You are given a string $s$ of length $n$ consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete ar...
```python #credits https://www.geeksforgeeks.org/minimum-steps-to-delete-a-ssing-after-repeated-deletion-of-palindrome-subssings/ n=int(input()) s=input() N = len(s) dp = [[0 for x in range(N + 1)] for y in range(N + 1)] D = [[[] for x in range(N + 1)] for y in range(N + 1)] ss="" re="" for i in ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\nabaca\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '8\nabcddcba\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '1\nx\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '500\nbbababaabaabaabbbbbbaabbabbabbaabababababbbbabaaabbbbaaabbbbbbbabab...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1132/F'}
vfc_10770
```python #credits https://www.geeksforgeeks.org/minimum-steps-to-delete-a-ssing-after-repeated-deletion-of-palindrome-subssings/ n=int(input()) s=input() N = len(s) dp = [[0 for x in range(N + 1)] for y in range(N + 1)] D = [[[] for x in range(N + 1)] for y in range(N + 1)] ss="" re="" for i in ...
5 abaca
3
3
true
1,805
apps
verifiable_code
255
Solve the following coding problem using the programming language python: The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to ...
```python n=int(input()) a=sorted(map(int,input().split())) m=int(input()) b=sorted(map(int,input().split())) c=0 for i in range(n): for j in range(m): if abs(a[i]-b[j]) <= 1: b[j]=-10 c+=1 break print(c) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 4 6 2\n5\n5 1 5 7 9\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '4\n1 2 3 4\n4\n10 11 12 13\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '5\n1 1 1 1 1\n3\n1 2 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n1\n1\n', 'output'...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/489/B'}
vfc_10774
```python n=int(input()) a=sorted(map(int,input().split())) m=int(input()) b=sorted(map(int,input().split())) c=0 for i in range(n): for j in range(m): if abs(a[i]-b[j]) <= 1: b[j]=-10 c+=1 break print(c) ```
4 1 4 6 2 5 5 1 5 7 9
3
3
true
1,806
apps
verifiable_code
256
Solve the following coding problem using the programming language python: Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the go...
```python a,b=list(map(int,input().split())) c,d=list(map(int,input().split())) x,y=list(map(int,input().split())) z,w=list(map(int,input().split())) Team1=False Team2=False if(a>w and a>y and d>x and d>z): Team1=True if(c>w and c>y and b>x and b>z): Team1=True if(((x>b and w>c) or (z>b and y>c)) and ((x>...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 100\n100 1\n99 99\n99 99\n', 'output': 'Team 1\n'}, {'type': 'stdin_stdout', 'input': '1 1\n2 2\n3 3\n2 2\n', 'output': 'Team 2\n'}, {'type': 'stdin_stdout', 'input': '3 3\n2 2\n1 1\n2 2\n', 'output': 'Draw\n'}, {'type': 'stdin_stdout', 'input': '80 79\n79 30\n80 81\...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/411/C'}
vfc_10778
```python a,b=list(map(int,input().split())) c,d=list(map(int,input().split())) x,y=list(map(int,input().split())) z,w=list(map(int,input().split())) Team1=False Team2=False if(a>w and a>y and d>x and d>z): Team1=True if(c>w and c>y and b>x and b>z): Team1=True if(((x>b and w>c) or (z>b and y>c)) and ((x>...
1 100 100 1 99 99 99 99
Team 1
Team 1
true
1,807
apps
verifiable_code
258
Solve the following coding problem using the programming language python: Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been...
```python n=int(input()) s=input() left=0 right=0 left_ques=0 right_ques=0 for i in range(n): if i<n//2: if s[i]=='?': left_ques+=1 else : left+=int(s[i]) else : if s[i]=='?': right_ques+=1 else : right+=int(s[i]) x=min(left_ques,ri...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n0523\n', 'output': 'Bicarp\n'}, {'type': 'stdin_stdout', 'input': '2\n??\n', 'output': 'Bicarp\n'}, {'type': 'stdin_stdout', 'input': '8\n?054??0?\n', 'output': 'Bicarp\n'}, {'type': 'stdin_stdout', 'input': '6\n???00?\n', 'output': 'Monocarp\n'}, {'type': 'stdin_st...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1215/D'}
vfc_10786
```python n=int(input()) s=input() left=0 right=0 left_ques=0 right_ques=0 for i in range(n): if i<n//2: if s[i]=='?': left_ques+=1 else : left+=int(s[i]) else : if s[i]=='?': right_ques+=1 else : right+=int(s[i]) x=min(left_ques,ri...
4 0523
Bicarp
Bicarp
true
1,808
apps
verifiable_code
259
Solve the following coding problem using the programming language python: It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor litt...
```python # AC import sys class Main: def __init__(self): self.buff = None self.index = 0 def __next__(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n6 4\n9 5\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5 5\n3 3\n2 5\n5 6\n4 9\n6 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3 7\n2 2\n2 3\n2 4\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1 1\n100000 1\n', 'output': '1\n'}, ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1153/A'}
vfc_10790
```python # AC import sys class Main: def __init__(self): self.buff = None self.index = 0 def __next__(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] ...
2 2 6 4 9 5
1
1
true
1,809
apps
verifiable_code
260
Solve the following coding problem using the programming language python: One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary repre...
```python def nck(n, k, cache = {}): if k > n or k < 0: return 0 if k == 0 or k == n: return 1 if k*2 > n: k = n-k if (n, k) in cache: return cache[(n, k)] z = cache[(n, k)] = nck(n-1, k-1) + nck(n-1, k) return z def bits(n): b = 0 while n: if n&1: b += 1 n >>= 1 re...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3 2\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '3 3\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '1 11\n', 'output': '1024\n'}, {'type': 'stdin_stdout', 'input': '4 20\n', 'output': '9...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/431/D'}
vfc_10794
```python def nck(n, k, cache = {}): if k > n or k < 0: return 0 if k == 0 or k == n: return 1 if k*2 > n: k = n-k if (n, k) in cache: return cache[(n, k)] z = cache[(n, k)] = nck(n-1, k-1) + nck(n-1, k) return z def bits(n): b = 0 while n: if n&1: b += 1 n >>= 1 re...
1 1
1
1
true
1,810
apps
verifiable_code
261
Solve the following coding problem using the programming language python: In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. [Image] ...
```python kk=0 x = int(input()) y = input() z = [i for i in range(len(y)) if y[i] == '*'] for i in range(0, 100): for j in range(1, 100): if i in z and i+j in z and i+2*j in z and i+3*j in z and i+4*j in z: kk=1 if kk==1: print("yes") else: print("no") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '16\n.**.*..*.***.**.\n', 'output': 'yes'}, {'type': 'stdin_stdout', 'input': '11\n.*.*...*.*.\n', 'output': 'no'}, {'type': 'stdin_stdout', 'input': '53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.\n', 'output': 'yes'}, {'type': 'stdin_stdout', 'input': '71\n...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/526/A'}
vfc_10798
```python kk=0 x = int(input()) y = input() z = [i for i in range(len(y)) if y[i] == '*'] for i in range(0, 100): for j in range(1, 100): if i in z and i+j in z and i+2*j in z and i+3*j in z and i+4*j in z: kk=1 if kk==1: print("yes") else: print("no") ```
16 .**.*..*.***.**.
yes
yes
true
1,811
apps
verifiable_code
262
Solve the following coding problem using the programming language python: ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need ...
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- def func(): N = int(input()) cells = [0] * N if N == 1: return 1 mx = 0 for n in range(N): cells[n] = list(map(int,input().split())) mx = max(mx, sum(cells[n])) ans = None for j in range(N): for i in...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n4 0 2\n3 5 7\n8 1 6\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input':...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/711/B'}
vfc_10802
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- def func(): N = int(input()) cells = [0] * N if N == 1: return 1 mx = 0 for n in range(N): cells[n] = list(map(int,input().split())) mx = max(mx, sum(cells[n])) ans = None for j in range(N): for i in...
3 4 0 2 3 5 7 8 1 6
9
9
true
1,812
apps
verifiable_code
263
Solve the following coding problem using the programming language python: There are $n$ benches in the Berland Central park. It is known that $a_i$ people are currently sitting on the $i$-th bench. Another $m$ people are coming to the park and each of them is going to have a seat on some bench out of $n$ available. L...
```python n = int(input()) m = int(input()) a = [] for i in range(n): a.append(int(input())) mx = max(a) + m while m: for i in range(n): if a[i] == min(a): a[i] += 1 m -= 1 break print(max(a), mx) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n6\n1\n1\n1\n1\n', 'output': '3 7\n'}, {'type': 'stdin_stdout', 'input': '1\n10\n5\n', 'output': '15 15\n'}, {'type': 'stdin_stdout', 'input': '3\n6\n1\n6\n5\n', 'output': '6 12\n'}, {'type': 'stdin_stdout', 'input': '3\n7\n1\n6\n5\n', 'output': '7 13\n'}, {'type': '...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1042/A'}
vfc_10806
```python n = int(input()) m = int(input()) a = [] for i in range(n): a.append(int(input())) mx = max(a) + m while m: for i in range(n): if a[i] == min(a): a[i] += 1 m -= 1 break print(max(a), mx) ```
4 6 1 1 1 1
3 7
3 7
true
1,813
apps
verifiable_code
264
Solve the following coding problem using the programming language python: There is an airplane which has n rows from front to back. There will be m people boarding this airplane. This airplane has an entrance at the very front and very back of the plane. Each person has some assigned seat. It is possible for multipl...
```python MOD = 10 ** 9 + 7 n, m = input().split(' ') n = int(n) m = int(m) ans = pow(2 * (n + 1), m, MOD) ans = (ans * (n + 1 - m)) % MOD ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n', 'output': '128\n'}, {'type': 'stdin_stdout', 'input': '1000000 1000000\n', 'output': '233176135\n'}, {'type': 'stdin_stdout', 'input': '1000000 500000\n', 'output': '211837745\n'}, {'type': 'stdin_stdout', 'input': '1 1\n', 'output': '2\n'}, {'type': 'stdin_std...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/838/D'}
vfc_10810
```python MOD = 10 ** 9 + 7 n, m = input().split(' ') n = int(n) m = int(m) ans = pow(2 * (n + 1), m, MOD) ans = (ans * (n + 1 - m)) % MOD ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD print(ans) ```
3 3
128
128
true
1,814
apps
verifiable_code
267
Solve the following coding problem using the programming language python: You are given two integers $l$ and $r$ ($l \le r$). Your task is to calculate the sum of numbers from $l$ to $r$ (including $l$ and $r$) such that each number contains at most $k$ different digits, and print this sum modulo $998244353$. For exa...
```python l, r, k =list(map(int,input().split())) d = {i:2**i for i in range(10)} cache = {} def can(i, m): return d[i] & m def calc(m): b = 1 c = 0 for i in range(10): if b & m: c += 1 b *= 2 return c def sm(ln, k, m, s='', first=False): if ln < 1: r...
{'test_cases': [{'type': 'stdin_stdout', 'input': '10 50 2\n', 'output': '1230\n'}, {'type': 'stdin_stdout', 'input': '1 2345 10\n', 'output': '2750685\n'}, {'type': 'stdin_stdout', 'input': '101 154 2\n', 'output': '2189\n'}, {'type': 'stdin_stdout', 'input': '427896435961371452 630581697708338740 1\n', 'output': '716...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1073/E'}
vfc_10822
```python l, r, k =list(map(int,input().split())) d = {i:2**i for i in range(10)} cache = {} def can(i, m): return d[i] & m def calc(m): b = 1 c = 0 for i in range(10): if b & m: c += 1 b *= 2 return c def sm(ln, k, m, s='', first=False): if ln < 1: r...
10 50 2
1230
1230
true
1,815
apps
verifiable_code
269
Solve the following coding problem using the programming language python: Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required....
```python s = input() n = len(s) t = 'RBYG' for i in t: ind = s.find(i) % 4 ans = 0 while ind < n: ans += s[ind] == '!' ind += 4 print(ans, end=' ') ```
{'test_cases': [{'type': 'stdin_stdout', 'input': 'RYBGRYBGR\n', 'output': '0 0 0 0'}, {'type': 'stdin_stdout', 'input': '!RGYB\n', 'output': '0 1 0 0'}, {'type': 'stdin_stdout', 'input': '!!!!YGRB\n', 'output': '1 1 1 1'}, {'type': 'stdin_stdout', 'input': '!GB!RG!Y!\n', 'output': '2 1 1 0'}, {'type': 'stdin_stdout', ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/758/B'}
vfc_10830
```python s = input() n = len(s) t = 'RBYG' for i in t: ind = s.find(i) % 4 ans = 0 while ind < n: ans += s[ind] == '!' ind += 4 print(ans, end=' ') ```
RYBGRYBGR
0 0 0 0
0 0 0 0
true
1,816
apps
verifiable_code
271
Solve the following coding problem using the programming language python: Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to ...
```python import math n = int(input()) print(10 * round(n / 10)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '113\n', 'output': '110\n'}, {'type': 'stdin_stdout', 'input': '1000000000\n', 'output': '1000000000\n'}, {'type': 'stdin_stdout', 'input': '5432359\n', 'output': '5432360\n'}, {'type': 'stdin_stdout', 'input': ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/898/A'}
vfc_10838
```python import math n = int(input()) print(10 * round(n / 10)) ```
5
0
0
true
1,818
apps
verifiable_code
272
Solve the following coding problem using the programming language python: Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place...
```python a = input() b = input() symbols = {} pairs = [] for i in range(len(a)): if a[i] in symbols: if symbols[a[i]] != b[i]: print('-1') break elif b[i] in symbols: if symbols[b[i]] != a[i]: print('-1') break else: symbols[a[i]] = ...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'helloworld\nehoolwlroz\n', 'output': '3\nh e\nl o\nd z\n'}, {'type': 'stdin_stdout', 'input': 'hastalavistababy\nhastalavistababy\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': 'merrychristmas\nchristmasmerry\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'in...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/748/B'}
vfc_10842
```python a = input() b = input() symbols = {} pairs = [] for i in range(len(a)): if a[i] in symbols: if symbols[a[i]] != b[i]: print('-1') break elif b[i] in symbols: if symbols[b[i]] != a[i]: print('-1') break else: symbols[a[i]] = ...
helloworld ehoolwlroz
3 h e l o d z
3 h e l o d z
true
1,819
apps
verifiable_code
273
Solve the following coding problem using the programming language python: The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there ...
```python from collections import * import itertools import sys def main(): a, b = input().split() ans = a + b n = len(a) m = len(b) for i in range(1, n + 1): for j in range(1, m + 1): c = a[:i] + b[:j] # print(c) ans = min(ans, c) print(ans) main() ...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'harry potter\n', 'output': 'hap\n'}, {'type': 'stdin_stdout', 'input': 'tom riddle\n', 'output': 'tomr\n'}, {'type': 'stdin_stdout', 'input': 'a qdpinbmcrf\n', 'output': 'aq\n'}, {'type': 'stdin_stdout', 'input': 'wixjzniiub ssdfodfgap\n', 'output': 'wis\n'}, {'type': ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/909/A'}
vfc_10846
```python from collections import * import itertools import sys def main(): a, b = input().split() ans = a + b n = len(a) m = len(b) for i in range(1, n + 1): for j in range(1, m + 1): c = a[:i] + b[:j] # print(c) ans = min(ans, c) print(ans) main() ...
harry potter
hap
hap
true
1,820
apps
verifiable_code
274
Solve the following coding problem using the programming language python: A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[...
```python n = int(input()) x = input() d = [0] * n cd = 0 xp = [] for i in range(n): if x[i] == '[': d[i] = cd cd = cd + 1 else: cd = cd - 1 d[i] = cd for i in range(n-1): xp.append((x[i], d[i])) if x[i] == '[' and x[i+1] == ']': xp.extend([(' ', d[i]), (' ', d[i]), (' ', d[i])]) xp.append((x[n-1], d[n-1]...
{'test_cases': [{'type': 'stdin_stdout', 'input': '8\n[[][]][]\n', 'output': '+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+\n'}, {'type': 'stdin_stdout', 'input': '6\n[[[]]]\n', 'output': '+- -+\n|+- -+|\n||+- -+||\n||| |||\n||+- -+||\n|+- -+|\n+- -+\n'}, {'...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/770/D'}
vfc_10850
```python n = int(input()) x = input() d = [0] * n cd = 0 xp = [] for i in range(n): if x[i] == '[': d[i] = cd cd = cd + 1 else: cd = cd - 1 d[i] = cd for i in range(n-1): xp.append((x[i], d[i])) if x[i] == '[' and x[i+1] == ']': xp.extend([(' ', d[i]), (' ', d[i]), (' ', d[i])]) xp.append((x[n-1], d[n-1]...
8 [[][]][]
+- -++- -+ |+- -++- -+|| | || || ||| | |+- -++- -+|| | +- -++- -+
+- -++- -+ |+- -++- -+|| | || || ||| | |+- -++- -+|| | +- -++- -+
true
1,821
apps
verifiable_code
276
Solve the following coding problem using the programming language python: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: the Power Gem of purple color, the Time Gem of green color, the Space Gem of blue color, the Soul Gem of orange color, the Reality ...
```python n = int(input()) a = [input() for i in range(n)] sol = [] for i in range(6): c = ['purple', 'green', 'blue', 'orange', 'red', 'yellow'][i] if c not in a: sol.append(['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'][i]) print(len(sol)) for i in sol: print(i) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\nred\npurple\nyellow\norange\n', 'output': '2\nTime\nSpace\n'}, {'type': 'stdin_stdout', 'input': '0\n', 'output': '6\nReality\nTime\nMind\nSpace\nPower\nSoul\n'}, {'type': 'stdin_stdout', 'input': '6\npurple\nblue\nyellow\nred\ngreen\norange\n', 'output': '0\n'}, {'...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/987/A'}
vfc_10858
```python n = int(input()) a = [input() for i in range(n)] sol = [] for i in range(6): c = ['purple', 'green', 'blue', 'orange', 'red', 'yellow'][i] if c not in a: sol.append(['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'][i]) print(len(sol)) for i in sol: print(i) ```
4 red purple yellow orange
2 Time Space
2 Time Space
true
1,822
apps
verifiable_code
278
Solve the following coding problem using the programming language python: Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the rev...
```python import sys n = int(input()) p = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = 0 num_cycles = 0 checked = set() for i in range(n): if i in checked: continue checked.add(i) nxt = p[i] - 1 while nxt != i: checked.add(nxt) nxt = p[nxt] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n4 3 2 1\n0 1 1 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n2 3 1\n0 0 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2\n1 2\n0 0\n', 'output': '3\n'}, {'type': 'stdin_stdo...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/756/A'}
vfc_10866
```python import sys n = int(input()) p = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = 0 num_cycles = 0 checked = set() for i in range(n): if i in checked: continue checked.add(i) nxt = p[i] - 1 while nxt != i: checked.add(nxt) nxt = p[nxt] ...
4 4 3 2 1 0 1 1 1
2
2
true
1,823
apps
verifiable_code
279
Solve the following coding problem using the programming language python: The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v_1 meters per second, and in the end it is v_2 meters per second. We know that this section of the route took exactly t seco...
```python v1, v2 = list(map(int, input().split())) t, d = list(map(int, input().split())) vm = [0] * t v = v1 for i in range(t): vm[i] = v v += d v = v2 for i in range(t - 1, -1, -1): vm[i] = min(v, vm[i]) v += d print(sum(vm)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 6\n4 2\n', 'output': '26'}, {'type': 'stdin_stdout', 'input': '10 10\n10 0\n', 'output': '100'}, {'type': 'stdin_stdout', 'input': '87 87\n2 10\n', 'output': '174'}, {'type': 'stdin_stdout', 'input': '1 11\n6 2\n', 'output': '36'}, {'type': 'stdin_stdout', 'input': '...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/534/B'}
vfc_10870
```python v1, v2 = list(map(int, input().split())) t, d = list(map(int, input().split())) vm = [0] * t v = v1 for i in range(t): vm[i] = v v += d v = v2 for i in range(t - 1, -1, -1): vm[i] = min(v, vm[i]) v += d print(sum(vm)) ```
5 6 4 2
26
26
true
1,824
apps
verifiable_code
281
Solve the following coding problem using the programming language python: Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather l...
```python a, b = map(int, input().split()) if b - a > 10: print(0) else: s = 1 for i in range(a + 1, b + 1): s *= i print(str(s)[-1]) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '0 10\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '107 109\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '10 13\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '998244355 99824435...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/869/B'}
vfc_10878
```python a, b = map(int, input().split()) if b - a > 10: print(0) else: s = 1 for i in range(a + 1, b + 1): s *= i print(str(s)[-1]) ```
2 4
2
2
true
1,825
apps
verifiable_code
282
Solve the following coding problem using the programming language python: A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a ...
```python '''input 4 2 1001 ''' def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() n,d = map_input() s = input() cur = 0 cnt = 0 while cur < n-1: j = -1 for i in range(cur+1,min(cur+d+1,n)): if s[i] == '...
{'test_cases': [{'type': 'stdin_stdout', 'input': '8 4\n10010101\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4 2\n1001\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '8 4\n11100101\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '12 3\n101111100101\n', 'output': '4\n'}, {'type': 'stdin_st...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/910/A'}
vfc_10882
```python '''input 4 2 1001 ''' def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() n,d = map_input() s = input() cur = 0 cnt = 0 while cur < n-1: j = -1 for i in range(cur+1,min(cur+d+1,n)): if s[i] == '...
8 4 10010101
2
2
true
1,826
apps
verifiable_code
283
Solve the following coding problem using the programming language python: PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number". Unfortunately, PolandBall i...
```python def prime(x): if x < 2: return False if x == 2: return True if x % 2 == 0: return False for d in range(3, x, 2): if d * d > x: break if x % d == 0: return False return True def main(): n = int(input()) for m in rang...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '10\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '153\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '1000\n', 'output': '1'}, {'type': 'std...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/755/A'}
vfc_10886
```python def prime(x): if x < 2: return False if x == 2: return True if x % 2 == 0: return False for d in range(3, x, 2): if d * d > x: break if x % d == 0: return False return True def main(): n = int(input()) for m in rang...
3
1
1
true
1,827
apps
verifiable_code
284
Solve the following coding problem using the programming language python: Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that ...
```python 3 # Copyright (C) 2016 Sayutin Dmitry. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; version 3 # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1359257\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '17851817\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': '1000000000\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '17851818\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '43873...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/681/B'}
vfc_10890
```python 3 # Copyright (C) 2016 Sayutin Dmitry. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; version 3 # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY...
1359257
YES
YES
true
1,828
apps
verifiable_code
285
Solve the following coding problem using the programming language python: The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to det...
```python k = [] x = int(input()) c, d = list(map(int, input().split(' '))) for i in range(x): a, b = list(map(int, input().split(' '))) k.append([c*a+b, d*a+b]) k.sort() for i in range(len(k)-1): if k[i+1][1] < k[i][1]: print("YES") quit() print("NO") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 2\n1 2\n1 0\n0 1\n0 2\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': '2\n1 3\n1 0\n-1 3\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '2\n1 3\n1 0\n0 2\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '2\n1 3\n1 0\n0 3\n', 'output': 'NO'},...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/593/B'}
vfc_10894
```python k = [] x = int(input()) c, d = list(map(int, input().split(' '))) for i in range(x): a, b = list(map(int, input().split(' '))) k.append([c*a+b, d*a+b]) k.sort() for i in range(len(k)-1): if k[i+1][1] < k[i][1]: print("YES") quit() print("NO") ```
4 1 2 1 2 1 0 0 1 0 2
NO
NO
true
1,829
apps
verifiable_code
286
Solve the following coding problem using the programming language python: Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences a...
```python n = int(input()) print(1 + n // 2) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '7\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '8\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '9\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '286\n', 'output': '144\n'}, {'typ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/964/A'}
vfc_10898
```python n = int(input()) print(1 + n // 2) ```
7
4
4
true
1,830
apps
verifiable_code
287
Solve the following coding problem using the programming language python: Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 gosa = 1.0 / 10**10 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split(...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 3\n', 'output': '1 3\n'}, {'type': 'stdin_stdout', 'input': '10 1\n', 'output': '1 2\n'}, {'type': 'stdin_stdout', 'input': '10 9\n', 'output': '1 1\n'}, {'type': 'stdin_stdout', 'input': '8 0\n', 'output': '0 0\n'}, {'type': 'stdin_stdout', 'input': '8 8\n', 'output...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/854/B'}
vfc_10902
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 gosa = 1.0 / 10**10 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split(...
6 3
1 3
1 3
true
1,831
apps
verifiable_code
288
Solve the following coding problem using the programming language python: Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if some...
```python n = int(input()) x = 0 cur = 1 lst = 1 while cur + lst <= n: cur, lst = cur + lst, cur x += 1 print(x) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '10\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '1000\n', 'output': '14\n'}, {'ty...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/735/C'}
vfc_10906
```python n = int(input()) x = 0 cur = 1 lst = 1 while cur + lst <= n: cur, lst = cur + lst, cur x += 1 print(x) ```
2
1
1
true
1,832
apps
verifiable_code
289
Solve the following coding problem using the programming language python: Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no change...
```python s = input() d = dict() d['V'] = 'K' d['K'] = 'V' m = s.count('VK') s = list(s) for i in range(len(s)): s[i] = d[s[i]] m = max(m,''.join(s).count('VK')) s[i] = d[s[i]] print(m) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': 'VK\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': 'VV\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': 'V\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': 'VKKKKKKKKKVVVVVVVVVK\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': 'KVKV\n', 'ou...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/801/A'}
vfc_10910
```python s = input() d = dict() d['V'] = 'K' d['K'] = 'V' m = s.count('VK') s = list(s) for i in range(len(s)): s[i] = d[s[i]] m = max(m,''.join(s).count('VK')) s[i] = d[s[i]] print(m) ```
VK
1
1
true
1,833
apps
verifiable_code
290
Solve the following coding problem using the programming language python: Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw $n$ squares in the snow with a side length of $1$. For simplicity, we assume that Sofia lives on a plane a...
```python n = int(input()) a = b = 1 while a * b < n: if a < b: a += 1 else: b += 1 print(a+b) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '14\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '41\n', 'output': '13\n'}, {'type...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1099/B'}
vfc_10914
```python n = int(input()) a = b = 1 while a * b < n: if a < b: a += 1 else: b += 1 print(a+b) ```
1
2
2
true
1,834
apps
verifiable_code
291
Solve the following coding problem using the programming language python: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Lima...
```python def l2i(s): return [int(i) for i in s.split()] a, b=l2i(input()) t=0 while (a<=b): a*=3 b*=2 t+=1 print(t) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 7\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4 9\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '1 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4 6\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '1 10\n', 'output': '6\n'}...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/791/A'}
vfc_10918
```python def l2i(s): return [int(i) for i in s.split()] a, b=l2i(input()) t=0 while (a<=b): a*=3 b*=2 t+=1 print(t) ```
4 7
2
2
true
1,835
apps
verifiable_code
292
Solve the following coding problem using the programming language python: Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is lo...
```python h, n = list(map(int, input().split())) c, m = 0, 2 ** h r = 0 while m > 1: if c == 0: if n > m // 2: r += m - 1 n -= m // 2 c = 1 - c else: if n > m // 2: n -= m // 2 else: r += m - 1 c = 1 - c c = 1 - ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 2\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '2 3\n', 'output': '5'}, {'type': 'stdin_stdout', 'input': '3 6\n', 'output': '10'}, {'type': 'stdin_stdout', 'input': '10 1024\n', 'output': '2046'}, {'type': 'stdin_stdout', 'input': '10 577\n', 'output': '134...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/507/C'}
vfc_10922
```python h, n = list(map(int, input().split())) c, m = 0, 2 ** h r = 0 while m > 1: if c == 0: if n > m // 2: r += m - 1 n -= m // 2 c = 1 - c else: if n > m // 2: n -= m // 2 else: r += m - 1 c = 1 - c c = 1 - ...
1 2
2
2
true
1,836
apps
verifiable_code
293
Solve the following coding problem using the programming language python: Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in ...
```python x = int(input()) def solve(x): count = 0 lst = [] x6 = x * 6 for n in range(1, x + 1): t, r = divmod(x6, n*(n+1)) if t < 2*n + 1: break if r: continue m, r = divmod(t + n - 1, 3) if r: continue count += 2 ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '26\n', 'output': '6\n1 26\n2 9\n3 5\n5 3\n9 2\n26 1\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '2\n1 2\n2 1\n'}, {'type': 'stdin_stdout', 'input': '8\n', 'output': '4\n1 8\n2 3\n3 2\n8 1\n'}, {'type': 'stdin_stdout', 'input': '1\n', 'output': '1\n1 1\n'}, ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/599/D'}
vfc_10926
```python x = int(input()) def solve(x): count = 0 lst = [] x6 = x * 6 for n in range(1, x + 1): t, r = divmod(x6, n*(n+1)) if t < 2*n + 1: break if r: continue m, r = divmod(t + n - 1, 3) if r: continue count += 2 ...
26
6 1 26 2 9 3 5 5 3 9 2 26 1
6 1 26 2 9 3 5 5 3 9 2 26 1
true
1,837
apps
verifiable_code
294
Solve the following coding problem using the programming language python: Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 ...
```python n = int(input()) s = input().split() a = [0] * n m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n31 31 30 31\n', 'output': 'Yes\n\n'}, {'type': 'stdin_stdout', 'input': '2\n30 30\n', 'output': 'No\n\n'}, {'type': 'stdin_stdout', 'input': '5\n29 31 30 31 30\n', 'output': 'Yes\n\n'}, {'type': 'stdin_stdout', 'input': '3\n31 28 30\n', 'output': 'No\n\n'}, {'type':...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/899/B'}
vfc_10930
```python n = int(input()) s = input().split() a = [0] * n m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, ...
4 31 31 30 31
Yes
Yes
true
1,838
apps
verifiable_code
298
Solve the following coding problem using the programming language python: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The ...
```python n,k=list(map(int,input().split())) n=(n//k)%2 print('YES' if n==1 else 'NO') ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 1\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '10 4\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '251656215122324104 164397544865601257\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '963577813436662285 206326039287271924\n', 'out...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/832/A'}
vfc_10946
```python n,k=list(map(int,input().split())) n=(n//k)%2 print('YES' if n==1 else 'NO') ```
1 1
YES
YES
true
1,840
apps
verifiable_code
299
Solve the following coding problem using the programming language python: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a_1, a_2, ..., a_{n}. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exe...
```python n=int(input()) s=input().split() A=[0,0,0] for i in range(n): A[i%3]+=int(s[i]) m=max(A) if(m==A[0]): print("chest") elif(m==A[1]): print("biceps") else: print("back") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n2 8\n', 'output': 'biceps\n'}, {'type': 'stdin_stdout', 'input': '3\n5 1 10\n', 'output': 'back\n'}, {'type': 'stdin_stdout', 'input': '7\n3 3 2 7 9 6 8\n', 'output': 'chest\n'}, {'type': 'stdin_stdout', 'input': '4\n5 6 6 2\n', 'output': 'chest\n'}, {'type': 'stdin...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/255/A'}
vfc_10950
```python n=int(input()) s=input().split() A=[0,0,0] for i in range(n): A[i%3]+=int(s[i]) m=max(A) if(m==A[0]): print("chest") elif(m==A[1]): print("biceps") else: print("back") ```
2 2 8
biceps
biceps
true
1,841
apps
verifiable_code
300
Solve the following coding problem using the programming language python: Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students s...
```python def read_input(): return map(int, input().split()) n = int(input()) a = sorted(read_input()) s = sum(a) i = 0 while 2 * s < 9 * n: delta = 5 - a[i] s += delta i += 1 print(i) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n4 4 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4\n5 4 5 5\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '4\n5 3 3 5\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1\n5\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '4\n3 ...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/991/B'}
vfc_10954
```python def read_input(): return map(int, input().split()) n = int(input()) a = sorted(read_input()) s = sum(a) i = 0 while 2 * s < 9 * n: delta = 5 - a[i] s += delta i += 1 print(i) ```
3 4 4 4
2
2
true
1,842
apps
verifiable_code
301
Solve the following coding problem using the programming language python: Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----...
```python u, v = list(map(int, input().split())) if v < u or (v - u) % 2 != 0: print(-1) else: if u == v: if u == 0: print(0) else: print("1\n" + str(u)) else: w = (v - u) // 2 if (w | u) == (w + u): print("2\n" + str(w|u) + ' ' + str(w)) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 4\n', 'output': '2\n3 1'}, {'type': 'stdin_stdout', 'input': '1 3\n', 'output': '3\n1 1 1'}, {'type': 'stdin_stdout', 'input': '8 5\n', 'output': '-1'}, {'type': 'stdin_stdout', 'input': '0 0\n', 'output': '0'}, {'type': 'stdin_stdout', 'input': '1 1\n', 'output': '1...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1325/D'}
vfc_10958
```python u, v = list(map(int, input().split())) if v < u or (v - u) % 2 != 0: print(-1) else: if u == v: if u == 0: print(0) else: print("1\n" + str(u)) else: w = (v - u) // 2 if (w | u) == (w + u): print("2\n" + str(w|u) + ' ' + str(w)) ...
2 4
2 3 1
2 3 1
true
1,843
apps
verifiable_code
302
Solve the following coding problem using the programming language python: Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum....
```python """ Codeforces Testing Round 10 Problem C Author : chaotic_iak Language: Python 3.3.4 """ def read(mode=2): # 0: String # 1: List of strings # 2: List of integers inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '121\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '10\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '72\n', 'output': '15\n'}, {'type': 'stdin_stdout', 'input': '1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '2\n'}, {'ty...
{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/440/C'}
vfc_10962
```python """ Codeforces Testing Round 10 Problem C Author : chaotic_iak Language: Python 3.3.4 """ def read(mode=2): # 0: String # 1: List of strings # 2: List of integers inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == ...
121
6
6
true
1,844