source
stringclasses
1 value
task_type
stringclasses
1 value
in_source_id
stringlengths
1
4
problem
stringlengths
488
6.07k
gold_standard_solution
stringlengths
19
30.1k
verification_info
dict
metadata
dict
problem_id
stringlengths
5
9
apps
verifiable_code
2366
Solve the following coding problem using the programming language python: Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$. Polycarp considers the price on the day $i$ to be bad if later (tha...
```python for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) m = 10 ** 9 c = 0 for i in range(n - 1, -1, -1): if A[i] <= m: m = A[i] else: c += 1 print(c) ```
{ "language": "python", "test_cases": [ { "input": "5\n6\n3 9 4 6 7 5\n1\n1000000\n2\n2 1\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "output": "3\n0\n1\n8\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1213/B" }
vfc_7010
apps
verifiable_code
2367
Solve the following coding problem using the programming language python: You are given two strings $s$ and $t$ both of length $n$ and both consisting of lowercase Latin letters. In one move, you can choose any length $len$ from $1$ to $n$ and perform the following operation: Choose any contiguous substring of the ...
```python q = int(input()) for _ in range(q) : n = int(input()) s = input() t = input() x = set(s) y = set(t) if x != y : print("NO") continue if len(x) == n : a = [0] * n for i, c in enumerate(t) : a[i] = s.find(c) yeet = 0 vis = [False] * n for i in range(n) : ...
{ "language": "python", "test_cases": [ { "input": "4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabcd\nbadc\n", "output": "NO\nYES\nNO\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1256/F" }
vfc_7014
apps
verifiable_code
2369
Solve the following coding problem using the programming language python: This problem is a version of problem D from the same contest with some additional constraints and tasks. There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$). You have to prepare a gift using some of...
```python # @author import sys class GCandyBoxHardVersion: def solve(self): q = int(input()) for _ in range(q): n = int(input()) a = [0] * n f = [0] * n for i in range(n): a[i], f[i] = [int(_) for _ in input().split()] d...
{ "language": "python", "test_cases": [ { "input": "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n7 1\n7 0\n7 1\n", "output": "3 3\n3 3\n9 5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1183/G" }
vfc_7022
apps
verifiable_code
2371
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ i...
```python for __ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) ar.reverse() ans = n - 1 flag = False for i in range(1, n): if ar[i] < ar[i - 1]: flag = True if flag: if ar[i] > ar[i - 1]: break ans -=...
{ "language": "python", "test_cases": [ { "input": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n", "output": "0\n4\n0\n2\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1385/C" }
vfc_7030
apps
verifiable_code
2372
Solve the following coding problem using the programming language python: Initially, you have the array $a$ consisting of one element $1$ ($a = [1]$). In one move, you can do one of the following things: Increase some (single) element of $a$ by $1$ (choose some $i$ from $1$ to the current length of $a$ and increas...
```python import math for _ in range(int(input())): n=int(input()) if n==1: print(0) else: k=int(n**(0.5)) if k*k<n: k+=1 # print(n,k) ans=k-1 if k*(k-1)>=n: ans+=(k-2) else: ans+=(k-1) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "5\n1\n5\n42\n1337\n1000000000\n", "output": "0\n3\n11\n72\n63244\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1426/C" }
vfc_7034
apps
verifiable_code
2373
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers (it is guaranteed that $n$ is even, i.e. divisible by $2$). All $a_i$ does not exceed some integer $k$. Your task is to replace the minimum number of elements (replacement is the following o...
```python import sys def input(): return sys.stdin.readline()[:-1] t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) cum = [0 for _ in range(2*k+2)] for i in range(n//2): x, y = a[i], a[n-i-1] cum[2] += 2 cum[min(x, y)+1] -= 1 cum[x+y] -= 1 cum[x+y+...
{ "language": "python", "test_cases": [ { "input": "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4\n", "output": "0\n1\n4\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1343/D" }
vfc_7038
apps
verifiable_code
2374
Solve the following coding problem using the programming language python: You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1, 1)$ and the bottom right — $(2, n)$. There are six types of pipes: two types of straight pipes and four types o...
```python ans = [] for _ in range(int(input())): n = int(input()) s = list(input()) t = list(input()) lvl = 0 X = [s, t] f = 1 for i in range(n): if s[i] in '3456' and t[i] in '3456': lvl = 1 - lvl elif X[lvl][i] in '3456': f = 0 ans.append...
{ "language": "python", "test_cases": [ { "input": "6\n7\n2323216\n1615124\n1\n3\n4\n2\n13\n24\n2\n12\n34\n3\n536\n345\n2\n46\n54\n", "output": "YES\nYES\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1234/C" }
vfc_7042
apps
verifiable_code
2376
Solve the following coding problem using the programming language python: You are given a tree (connected graph without cycles) consisting of $n$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles. In one move, you can choose exactly $k$ leaves (leaf is such a vertex that is conne...
```python from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop,heapify import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([...
{ "language": "python", "test_cases": [ { "input": "4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8 10\n7 2\n3 1\n4 5\n3 6\n7 4\n1 2\n1 4\n5 1\n1 2\n2 3\n4 3\n5 3\n", "output": "2\n3\n3\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1385/F" }
vfc_7050
apps
verifiable_code
2377
Solve the following coding problem using the programming language python: This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals el...
```python import sys input = sys.stdin.readline import bisect t=int(input()) for tests in range(t): n=int(input()) A=list(map(int,input().split())) compression_dict={a: ind for ind, a in enumerate(sorted(set(A)))} A=[compression_dict[a] for a in A] Q=[0]*n for i in range(n): Q[A...
{ "language": "python", "test_cases": [ { "input": "4\n5\n4 7 2 3 9\n5\n3 5 8 1 7\n5\n1 4 5 7 12\n4\n0 2 1 3\n", "output": "2\n2\n0\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1367/F1" }
vfc_7054
apps
verifiable_code
2378
Solve the following coding problem using the programming language python: Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell $(0, 0)$ on an infinite grid. You also have the sequence of instructions of this robot. It is written as the string $s$ consisting of characters 'L',...
```python n = int(input()) for _ in range(n): s = input() l,r,u,d = [s.count(i) for i in 'LRUD'] lr = min(l, r) ud = min(u, d) res = "" if lr == 0 and ud == 0: res = "" elif lr == 0: res = "UD" elif ud == 0: res = 'LR' else: res = 'R' * lr + 'U' * ud +...
{ "language": "python", "test_cases": [ { "input": "6\nLRU\nDURLDRUDRULRDURDDL\nLRUDDLRUDRUL\nLLLLRRRR\nURDUR\nLLL\n", "output": "2\nLR\n14\nLLLUUUURRRDDDD\n12\nLLLUUURRRDDD\n2\nLR\n2\nUD\n0\n\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1272/B" }
vfc_7058
apps
verifiable_code
2380
Solve the following coding problem using the programming language python: You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. Yo...
```python import sys input = sys.stdin.readline rInt = lambda: int(input()) mInt = lambda: map(int, input().split()) rLis = lambda: list(map(int, input().split())) outs = [] t = rInt() for _ in range(t): n, k = mInt() s = input() pref = [0] for c in s: if c == '1': pref.append(pre...
{ "language": "python", "test_cases": [ { "input": "6\n9 2\n010001010\n9 3\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n1\n1 1\n0\n", "output": "1\n2\n5\n4\n0\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1353/E" }
vfc_7066
apps
verifiable_code
2381
Solve the following coding problem using the programming language python: There is a frog staying to the left of the string $s = s_1 s_2 \ldots s_n$ consisting of $n$ characters (to be more precise, the frog initially stays at the cell $0$). Each character of $s$ is either 'L' or 'R'. It means that if the frog is stay...
```python for i in range(int(input())): s='R' + input() + 'R' prev=0 ma=-1 for i in range(1,len(s)): if s[i]=='R': ma=max(ma,i-prev) prev=i print(ma) ```
{ "language": "python", "test_cases": [ { "input": "6\nLRLRRLL\nL\nLLR\nRRRR\nLLLLLL\nR\n", "output": "3\n2\n3\n1\n7\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1324/C" }
vfc_7070
apps
verifiable_code
2382
Solve the following coding problem using the programming language python: You are given $n$ strings $a_1, a_2, \ldots, a_n$: all of them have the same length $m$. The strings consist of lowercase English letters. Find any string $s$ of length $m$ such that each of the given $n$ strings differs from $s$ in at most one...
```python def isvalid(s): nonlocal l for i in l: count=0 for j in range(len(i)): if(s[j]!=i[j]): count+=1 if(count>1): return 0 return 1 t=int(input()) for you in range(t): l=input().split() n=int(l[0]) m=int(l[1]) l=[] for ...
{ "language": "python", "test_cases": [ { "input": "5\n2 4\nabac\nzbab\n2 4\naaaa\nbbbb\n3 3\nbaa\naaa\naab\n2 2\nab\nbb\n3 1\na\nb\nc\n", "output": "zbac\n-1\naaa\nab\na\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1360/F" }
vfc_7074
apps
verifiable_code
2383
Solve the following coding problem using the programming language python: Find the minimum area of a square land on which you can place two identical rectangular $a \times b$ houses. The sides of the houses should be parallel to the sides of the desired square land. Formally, You are given two identical rectangles ...
```python T = int(input()) for _ in range(T): a, b = list(map(int, input().split())) print(max(max(a, b), min(a, b) * 2)**2) ```
{ "language": "python", "test_cases": [ { "input": "8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100\n", "output": "16\n16\n4\n9\n64\n9\n64\n40000\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1360/A" }
vfc_7078
apps
verifiable_code
2384
Solve the following coding problem using the programming language python: This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can c...
```python from sys import stdin for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) id = list(zip(l,list(range(n)))) id.sort() val, pos = zip(*id) blok = [] cur = [pos[0]] for i in range(1,n): if val[i] == val[i-1]: cur.append(pos[i]) ...
{ "language": "python", "test_cases": [ { "input": "9\n5\n4 7 2 2 9\n5\n3 5 8 1 7\n5\n1 2 2 4 5\n2\n0 1\n3\n0 1 0\n4\n0 1 0 0\n4\n0 1 0 1\n4\n0 1 0 2\n20\n16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9\n", "output": "2\n2\n0\n0\n1\n1\n1\n1\n16\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1367/F2" }
vfc_7082
apps
verifiable_code
2385
Solve the following coding problem using the programming language python: There is a rectangular grid of size $n \times m$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $(i, j)$ is $c_{i, j}$. You are also given a map of directions: for each cell, there is a direction $s_{i, j}$ w...
```python import sys input = sys.stdin.readline def search(i,j): L=[] c=0 while CHECK[i][j]==1<<30: L.append((i,j)) CHECK[i][j]=c if MAP2[i][j]=="U": i-=1 elif MAP2[i][j]=="D": i+=1 elif MAP2[i][j]=="R": j+=1 el...
{ "language": "python", "test_cases": [ { "input": "3\n1 2\n01\nRL\n3 3\n001\n101\n110\nRLL\nDLD\nULL\n3 3\n000\n000\n000\nRRD\nRLD\nULL\n", "output": "2 1\n4 3\n2 2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1335/F" }
vfc_7086
apps
verifiable_code
2386
Solve the following coding problem using the programming language python: A permutation of length $n$ is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ are permutations, and $[1, 1]$, $[0, 1]$, $[2, 2, 1, 4]$ are not. There ...
```python t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) print(*set(a)) ```
{ "language": "python", "test_cases": [ { "input": "5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1\n", "output": "1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1385/B" }
vfc_7090
apps
verifiable_code
2388
Solve the following coding problem using the programming language python: You are given an undirected unweighted connected graph consisting of $n$ vertices and $m$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Your task is to choose at most $\lfloor\frac{n}{2}\rfloor$ vert...
```python import sys input = sys.stdin.readline T = int(input()) for _ in range(T): N, M = list(map(int, input().split())) E = [[] for aa in range(N)] for __ in range(M): a, b = list(map(int, input().split())) E[a-1].append(b-1) E[b-1].append(a-1) D = [-1] * N D[0] = 0 ...
{ "language": "python", "test_cases": [ { "input": "2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n6 8\n2 5\n5 4\n4 3\n4 1\n1 3\n2 3\n2 6\n5 6\n", "output": "1\n1 \n3\n3 4 6 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1176/E" }
vfc_7098
apps
verifiable_code
2389
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the size of the input. You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'. You are also given an integer $k$. Your task is to change the minimum numb...
```python from sys import stdin import math rgb = 'RGB' for query in range(int(stdin.readline())): n, k = list(map(int, stdin.readline().split())) s = stdin.readline() ans = math.inf for start in range(3): dp = [0 for i in range(n + 1)] for i in range(n): cur = rgb[(start...
{ "language": "python", "test_cases": [ { "input": "3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n", "output": "1\n0\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1196/D2" }
vfc_7102
apps
verifiable_code
2390
Solve the following coding problem using the programming language python: This problem is actually a subproblem of problem G from the same contest. There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$). You have to prepare a gift using some of these candies with the followin...
```python import sys input = sys.stdin.readline Q = int(input()) for _ in range(Q): N = int(input()) A = [int(a) for a in input().split()] X = {} for a in A: if a in X: X[a] += 1 else: X[a] = 1 Y = [] for x in X: Y.append(X[x]) Y = sorted(Y)[:...
{ "language": "python", "test_cases": [ { "input": "3\n8\n1 4 8 4 5 6 3 8\n16\n2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1\n9\n2 2 4 4 4 7 7 7 7\n", "output": "3\n10\n9\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1183/D" }
vfc_7106
apps
verifiable_code
2391
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. In one move, you can choose some index $i$ ($1 \le i \le n - 2$) and shift the segment $[a_i, a_{i + 1}, a_{i + 2}]$ cyclically to the right (i.e. replace the segment $[a_i, a_{i + 1}, a_{i...
```python t = int(input()) for _ in range(t): n = int(input()) l = list([int(x)- 1 for x in input().split()]) out = [] ll = [(l[i], i) for i in range(n)] ll.sort() swap = (-1,-1) for i in range(n - 1): if ll[i][0] == ll[i + 1][0]: swap = (ll[i][1],ll[i+1][1]) newl ...
{ "language": "python", "test_cases": [ { "input": "5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n", "output": "0\n\n6\n3 1 3 2 2 3 \n13\n2 1 1 6 4 2 4 3 3 4 4 6 6 \n-1\n4\n3 3 4 4 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1374/F" }
vfc_7110
apps
verifiable_code
2392
Solve the following coding problem using the programming language python: Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible b...
```python for _ in range(int(input())): n, m = list(map(int, input().split())) A = [] x = 1 while True: if (m * x) % 10 not in A: A.append((m * x) % 10) else: break x += 1 s = sum(A) n //= m print(s * (n // len(A)) + sum(A[:n % len(A)])) ```
{ "language": "python", "test_cases": [ { "input": "7\n1 1\n10 1\n100 3\n1024 14\n998244353 1337\n123 144\n1234312817382646 13\n", "output": "1\n45\n153\n294\n3359835\n0\n427262129093995\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1213/C" }
vfc_7114
apps
verifiable_code
2393
Solve the following coding problem using the programming language python: Polygon is not only the best platform for developing problems but also a square matrix with side $n$, initially filled with the character 0. On the polygon, military training was held. The soldiers placed a cannon above each cell in the first r...
```python def read_int(): return int(input()) def read_ints(): return list(map(int, input().split(' '))) t = read_int() for case_num in range(t): n = read_int() mat = [] for i in range(n): mat.append(input()) ok = True for i in range(n): for j in range(n): if ...
{ "language": "python", "test_cases": [ { "input": "5\n4\n0010\n0011\n0000\n0000\n2\n10\n01\n2\n00\n00\n4\n0101\n1111\n0101\n0111\n4\n0100\n1110\n0101\n0111\n", "output": "YES\nNO\nYES\nYES\nNO\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1360/E" }
vfc_7118
apps
verifiable_code
2394
Solve the following coding problem using the programming language python: You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'. In one move, you can choose exactly one bracket and ...
```python for _ in range(int(input())): n = int(input()) s = input() st = 0 fans = 0 for x in s: if x == ')': st -= 1 else: st += 1 if st < 0: fans += 1 st = 0 print(fans) ```
{ "language": "python", "test_cases": [ { "input": "4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n", "output": "1\n0\n1\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1374/C" }
vfc_7122
apps
verifiable_code
2395
Solve the following coding problem using the programming language python: A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$. You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the...
```python for _ in range(int(input())): n=int(input()) s=input() a="" b="" flag=1 for i in s: if flag: if i=="2": a+="1" b+="1" elif i=="1": a+="1" b+="0" flag=0 else: ...
{ "language": "python", "test_cases": [ { "input": "4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n", "output": "11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1328/C" }
vfc_7126
apps
verifiable_code
2396
Solve the following coding problem using the programming language python: You are given a string $s[1 \dots n]$ consisting of lowercase Latin letters. It is guaranteed that $n = 2^k$ for some integer $k \ge 0$. The string $s[1 \dots n]$ is called $c$-good if at least one of the following three conditions is satisfied...
```python # coding: utf-8 # Your code here! def solve(s, c): if(len(s)==1): if s[0]==c: return 0 else: return 1 ans1 = sum([i!=c for i in s[:len(s)//2]]) + solve(s[len(s)//2:],chr(ord(c)+1)) ans2 = sum([i!=c for i in s[len(s)//2:]]) + solve(s[:len(s)//2],chr(ord(c)+1...
{ "language": "python", "test_cases": [ { "input": "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaabb\n8\nbbaaddcc\n1\nz\n2\nac\n", "output": "0\n7\n4\n5\n1\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1385/D" }
vfc_7130
apps
verifiable_code
2397
Solve the following coding problem using the programming language python: Consider all binary strings of length $m$ ($1 \le m \le 60$). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly $2^m$ such strings in t...
```python def read_int(): return int(input()) def read_ints(): return list(map(int, input().split(' '))) t = read_int() for case_num in range(t): n, m = read_ints() a = [] for i in range(n): a.append(int(input(), 2)) a.sort() k = 2 ** m - n ans = (k - 1) // 2 for ai in a:...
{ "language": "python", "test_cases": [ { "input": "5\n3 3\n010\n001\n111\n4 3\n000\n111\n100\n011\n1 1\n1\n1 1\n0\n3 2\n00\n01\n10\n", "output": "100\n010\n0\n1\n11\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1360/H" }
vfc_7134
apps
verifiable_code
2399
Solve the following coding problem using the programming language python: You are given a graph consisting of $n$ vertices and $m$ edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
```python from sys import stdin, stdout import functools import sys,os,math #sys.setrecursionlimit(10**6) T = int(input()) for _ in range(T): N, M = list(map(int, input().split())) DS = [0] * (N + 1) ES = [] g = [[] for _ in range(N + 1)] for _ in range(M): t, u, v = list(map(int, input()....
{ "language": "python", "test_cases": [ { "input": "4\n3 1\n0 1 3\n5 5\n0 2 1\n1 1 5\n1 5 4\n0 5 2\n1 3 5\n4 5\n1 1 2\n0 4 3\n1 3 1\n0 2 3\n1 2 4\n4 5\n1 4 1\n1 1 3\n0 1 2\n1 2 4\n1 3 2\n", "output": "YES\n3 1\nYES\n2 1\n1 5\n5 4\n2 5\n3 5\nYES\n1 2\n3 4\n3 1\n3 2\n2 4\nNO\n", "type": "stdin_s...
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1385/E" }
vfc_7142
apps
verifiable_code
2400
Solve the following coding problem using the programming language python: The round carousel consists of $n$ figures of animals. Figures are numbered from $1$ to $n$ in order of the carousel moving. Thus, after the $n$-th figure the figure with the number $1$ follows. Each figure has its own type — the type of the ani...
```python import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [int(a) for a in input().split()] if max(A) == min(A): print(1) print(*([1] * N)) elif N % 2 == 0: print(2) print(*([1, 2] * (N // 2))) el...
{ "language": "python", "test_cases": [ { "input": "4\n5\n1 2 1 2 2\n6\n1 2 2 1 2 2\n5\n1 2 1 2 3\n3\n10 10 10\n", "output": "2\n2 1 2 1 1 \n2\n1 2 1 2 1 2 \n3\n1 2 1 2 3\n1\n1 1 1 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1328/D" }
vfc_7146
apps
verifiable_code
4757
Solve the following coding problem using the programming language python: You are given four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$). Find any such rectangular matrix of size $n \times m$ that satisfies all of the following conditions: each row of the matrix contains ex...
```python for _ in range(int(input())): n, m, a, b = list(map(int, input().split())) if a * n != b * m: print('NO') else: ar = [] for i in range(n): ar.append([0] * m) x, y = 0, a for i in range(n): if x < y: for j in range(x, y...
{ "language": "python", "test_cases": [ { "input": "5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2\n", "output": "YES\n110000\n001100\n000011\nNO\nYES\n11\n11\nYES\n1100\n0110\n0011\n1001\nYES\n1\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1360/G" }
vfc_9508
apps
verifiable_code
0
Solve the following coding problem using the programming language python: An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (...
```python s = input() n = len(s) ind = -1 f = False for i in range(n): if s[i] == '[': f = True elif s[i] == ':': if f: ind = i break bind = -1 f = False for i in range(n-1,-1,-1): if s[i] == ']': f = True elif s[i] == ':': if f: bind =...
{ "language": "python", "test_cases": [ { "input": "|[a:b:|]\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "|]:[|:]\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": ":][:\n", "output": "-1\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1101/B" }
vfc_9754
apps
verifiable_code
1
Solve the following coding problem using the programming language python: Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the big...
```python num = list(map(int, input())) best = num[:] for i in range(-1, -len(num) - 1, -1): if num[i] == 0: continue num[i] -= 1 for j in range(i + 1, 0): num[j] = 9 if sum(num) > sum(best): best = num[:] s = ''.join(map(str, best)).lstrip('0') print(s) ```
{ "language": "python", "test_cases": [ { "input": "100\n", "output": "99\n", "type": "stdin_stdout" }, { "input": "48\n", "output": "48\n", "type": "stdin_stdout" }, { "input": "521\n", "output": "499\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/770/B" }
vfc_9758
apps
verifiable_code
2
Solve the following coding problem using the programming language python: Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are...
```python def main(): s = input() n = len(s) t = int(str(int(s[0]) + 1) + '0' * (n - 1)) print(t - int(s)) main() ```
{ "language": "python", "test_cases": [ { "input": "4\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "201\n", "output": "99\n", "type": "stdin_stdout" }, { "input": "4000\n", "output": "1000\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/808/A" }
vfc_9762
apps
verifiable_code
3
Solve the following coding problem using the programming language python: You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$. Unfortunately, you are on a tight...
```python from collections import defaultdict as dd import math def nn(): return int(input()) def li(): return list(input()) def mi(): return list(map(int, input().split())) def lm(): return list(map(int, input().split())) n, q=mi() ints=[] for _ in range(q): st, end=mi() ints.append((st,end)) coverage=...
{ "language": "python", "test_cases": [ { "input": "7 5\n1 4\n4 5\n5 6\n6 7\n3 5\n", "output": "7\n", "type": "stdin_stdout" }, { "input": "4 3\n1 1\n2 2\n3 4\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "4 4\n1 1\n2 2\n2 3\n3 4\n", "o...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1132/C" }
vfc_9766
apps
verifiable_code
4
Solve the following coding problem using the programming language python: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minu...
```python x=int(input()) h,m=list(map(int,input().split())) def ok(mm): while mm<0: mm+=1440 hh=mm//60 mm=mm%60 return hh%10==7 or hh//10==7 or mm%10==7 or mm//10==7 for y in range(999): if ok(h*60+m-y*x): print(y) return ```
{ "language": "python", "test_cases": [ { "input": "3\n11 23\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "5\n01 07\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "34\n09 24\n", "output": "3\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/916/A" }
vfc_9770
apps
verifiable_code
5
Solve the following coding problem using the programming language python: Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for he...
```python n, pos, l, r = map(int, input().split()) if l > 1 and r < n: if l <= pos and pos <= r: if pos - l < r - pos: print(pos - l + 1 + r - l + 1) else: print(r - pos + 1 + r - l + 1) elif pos > r: print(pos - r + 1 + r - l + 1) else: print(l - pos...
{ "language": "python", "test_cases": [ { "input": "6 3 2 4\n", "output": "5\n", "type": "stdin_stdout" }, { "input": "6 3 1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "5 2 1 5\n", "output": "0\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/915/B" }
vfc_9774
apps
verifiable_code
6
Solve the following coding problem using the programming language python: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! $m$ Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, ...
```python for _ in range(int(input())): n, x = list(map(int, input().split())) A = [] for _1 in range(n): d, h = list(map(int, input().split())) A.append([d, h]) A.sort(reverse=True) if A[0][0] >= x: print(1) else: x -= A[0][0] mz = 0 for d, h in A: ...
{ "language": "python", "test_cases": [ { "input": "3\n3 10\n6 3\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100\n", "output": "2\n3\n-1\n", "type": "stdin_stdout" }, { "input": "7\n5 1000000000\n2 1\n1 10\n1 1\n4 1000000000\n3 3\n1 1000000000\n5 1\n2 999999999\n3 1\n2...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1217/B" }
vfc_9778
apps
verifiable_code
7
Solve the following coding problem using the programming language python: Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build ...
```python n, m = map(int, input().split()) if (m >= n): print(n) else: c = n - m l = 0 r = 10 ** 18 while r - l > 1: md = (r + l) // 2 if (1 + md) * md // 2 < c: l = md else: r = md print(r + m) ```
{ "language": "python", "test_cases": [ { "input": "5 2\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "8 1\n", "output": "5\n", "type": "stdin_stdout" }, { "input": "32 5\n", "output": "12\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/785/C" }
vfc_9782
apps
verifiable_code
8
Solve the following coding problem using the programming language python: Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). I...
```python cards=list(input().split()) lm=[0]*9 lp=[0]*9 ls=[0]*9 for item in cards: if item[1]=='m': lm[int(item[0])-1]+=1 elif item[1]=='p': lp[int(item[0])-1]+=1 else : ls[int(item[0])-1]+=1 if max(lm)==3 or max(lp)==3 or max(ls)==3: print(0) else : flag=0 def seq_check...
{ "language": "python", "test_cases": [ { "input": "1s 2s 3s\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "9m 9m 9m\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "3p 9m 2p\n", "output": "1\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1191/B" }
vfc_9786
apps
verifiable_code
9
Solve the following coding problem using the programming language python: Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This not...
```python from sys import stdin, stdout k = int(stdin.readline()) n, m = map(int, stdin.readline().split()) left, right, down, up = [], [], [], [] coordinates = [] for i in range(k): x1, y1, x2, y2 = map(int, stdin.readline().split()) if x1 == x2: if y1 < y2: coordinates.append((x1, y...
{ "language": "python", "test_cases": [ { "input": "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "2\n2 ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/818/C" }
vfc_9790
apps
verifiable_code
10
Solve the following coding problem using the programming language python: On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of...
```python n=int(input()) r=n%7 d=n//7 print(2*d+max(0,r-5),2*d+min(r,2)) ```
{ "language": "python", "test_cases": [ { "input": "14\n", "output": "4 4\n", "type": "stdin_stdout" }, { "input": "2\n", "output": "0 2\n", "type": "stdin_stdout" }, { "input": "1\n", "output": "0 1\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/670/A" }
vfc_9794
apps
verifiable_code
11
Solve the following coding problem using the programming language python: Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if...
```python from fractions import gcd def lcm(a, b): return a*b//gcd(a, b) n, a, b, p, q = list(map(int, input().split(' '))) red = n//a blue = n//b if (p<q): red -= n//lcm(a, b) else: blue -= n//lcm(a, b) print(p*red+q*blue) ```
{ "language": "python", "test_cases": [ { "input": "5 2 3 12 15\n", "output": "39\n", "type": "stdin_stdout" }, { "input": "20 2 3 3 5\n", "output": "51\n", "type": "stdin_stdout" }, { "input": "1 1 1 1 1\n", "output": "1\n", "type": "stdin_s...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/678/C" }
vfc_9798
apps
verifiable_code
12
Solve the following coding problem using the programming language python: Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to ...
```python n = int(input()) A = input() x = A.count('G') num_1 = 0 num_2 = 0 max_num = 0 flag = 0 for i in range(n): if A[i] == 'G' and flag == 0: num_1 += 1 elif A[i] == 'G' and flag == 1: num_2 += 1 elif A[i] == 'S' and flag == 0: flag = 1 else: if num_1 + num_2 + 1 <= x...
{ "language": "python", "test_cases": [ { "input": "10\nGGGSGGGSGG\n", "output": "7\n", "type": "stdin_stdout" }, { "input": "4\nGGGG\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "3\nSSS\n", "output": "0\n", "type": "stdin_stdout...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1082/B" }
vfc_9802
apps
verifiable_code
13
Solve the following coding problem using the programming language python: Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage. The situation is complicated by the dependence o...
```python #This code is dedicated to Vlada S. class Course: def __init__(self, reqs, number): self.reqs = list(map(int, reqs.split()[1:])) self.available = False self.in_stack = False self.number = number n, k = list(map(int, input().split())) requirements = list(map(int, input().split())) courses = {} answ...
{ "language": "python", "test_cases": [ { "input": "6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5\n", "output": "5\n1 2 3 4 5 \n", "type": "stdin_stdout" }, { "input": "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2\n", "output": "6\n1 2 9 4 5 3 \n", "type": "stdin_stdout...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/770/C" }
vfc_9806
apps
verifiable_code
14
Solve the following coding problem using the programming language python: Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty). You may perform the following operations until both a and s are empty: Take the first element of a, push it into s and remove it from a (if...
```python import sys #f = open('input', 'r') f = sys.stdin n,k = list(map(int, f.readline().split())) a = list(map(int, f.readline().split())) aset = set(a) st = [] failed = False ai = 0 app = [] for p in range(1, n+1): if p in aset: while ai < k and (len(st)==0 or st[-1]!=p): st.append(a[ai]) ai += ...
{ "language": "python", "test_cases": [ { "input": "5 3\n3 2 1\n", "output": "3 2 1 5 4 ", "type": "stdin_stdout" }, { "input": "5 3\n2 3 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": "5 1\n3\n", "output": "3 2 1 5 4 ", "type":...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/911/E" }
vfc_9810
apps
verifiable_code
15
Solve the following coding problem using the programming language python: Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particula...
```python import sys a,b,c=map(int,input().split()) if c==0: if a==b: print('YES') else: print('NO') return if (b-a)%c==0 and (b-a)//c>=0: print('YES') else: print('NO') ```
{ "language": "python", "test_cases": [ { "input": "1 7 3\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "10 10 0\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "1 -4 5\n", "output": "NO\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/675/A" }
vfc_9814
apps
verifiable_code
16
Solve the following coding problem using the programming language python: A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this seq...
```python cnt1 = int(input()) cnt2 = int(input()) cnt3 = int(input()) cnt4 = int(input()) if cnt1 != cnt4: print(0) return if (cnt3 != 0 and cnt1 == 0): print(0) return print(1) ```
{ "language": "python", "test_cases": [ { "input": "3\n1\n4\n3\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "0\n0\n0\n0\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "1\n2\n3\n4\n", "output": "0\n", "type": "stdin_std...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1132/A" }
vfc_9818
apps
verifiable_code
17
Solve the following coding problem using the programming language python: Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-...
```python def read_ints(): return [int(i) for i in input().split()] n, k, t = read_ints() if t <= k: print(t) elif t > n: print(k + n - t) else: print(k) ```
{ "language": "python", "test_cases": [ { "input": "10 5 3\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "10 5 7\n", "output": "5\n", "type": "stdin_stdout" }, { "input": "10 5 12\n", "output": "3\n", "type": "stdin_stdout" },...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/851/A" }
vfc_9822
apps
verifiable_code
18
Solve the following coding problem using the programming language python: Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this...
```python from collections import deque S = input() mn = [ 300 for i in range( len( S ) ) ] for i in range( len( S ) - 1, -1, -1 ): if i == len( S ) - 1: mn[ i ] = ord( S[ i ] ) else: mn[ i ] = min( mn[ i + 1 ], ord( S[ i ] ) ) ans = "" dq = deque() for i in range( len( S ) ): dq.append( ord( S[ i ] ) ) ...
{ "language": "python", "test_cases": [ { "input": "cab\n", "output": "abc\n", "type": "stdin_stdout" }, { "input": "acdb\n", "output": "abdc\n", "type": "stdin_stdout" }, { "input": "a\n", "output": "a\n", "type": "stdin_stdout" }, {...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/797/C" }
vfc_9826
apps
verifiable_code
19
Solve the following coding problem using the programming language python: Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of...
```python import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n = int(input()) lastP = 0 lastC = 0 works = True for _ in range(n): p, c = list(map(int, input().split())) pDiff = p-lastP cDiff = c-lastC if 0 <= cDiff <= pDiff: pass ...
{ "language": "python", "test_cases": [ { "input": "6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n", "output": "NO\nYES\nNO\nYES\nNO\nYES\n", "type": "stdin_stdout" }, { "input": "1\n2\n10 1\n11 3\n", "o...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1334/A" }
vfc_9830
apps
verifiable_code
20
Solve the following coding problem using the programming language python: Karen is getting ready for a new school day! [Image] It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum...
```python s = input() h = int(s[:2]) m = int(s[3:]) def ispalin(h, m): s = "%02d:%02d"%(h,m) return s == s[::-1] for d in range(999999): if ispalin(h, m): print(d) break m+= 1 if m == 60: h = (h+1)%24 m = 0 ```
{ "language": "python", "test_cases": [ { "input": "05:39\n", "output": "11\n", "type": "stdin_stdout" }, { "input": "13:31\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "23:59\n", "output": "1\n", "type": "stdin_stdout" }, ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/816/A" }
vfc_9834
apps
verifiable_code
21
Solve the following coding problem using the programming language python: Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each ot...
```python read = lambda: list(map(int, input().split())) n = int(input()) a = list(read()) x, y = a.index(1), a.index(n) ans = max(x, y, n - x - 1, n - y - 1) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "5\n4 5 1 3 2\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "7\n1 6 5 3 4 7 2\n", "output": "6\n", "type": "stdin_stdout" }, { "input": "6\n6 5 4 3 2 1\n", "output": "5\n", "type"...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/676/A" }
vfc_9838
apps
verifiable_code
22
Solve the following coding problem using the programming language python: Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirr...
```python import sys, math s=input() pal='AHIMOoTUVvWwXxY' n=len(s) l=0 r=n-1 flag=True fir='pq' sec='bd' while l<=r: if s[l]==s[r] and s[l] in pal: l+=1 r-=1 continue elif s[l]==s[r]: flag=False break elif (s[l] in fir) and (s[r] in fir): l+=1 r-=1 ...
{ "language": "python", "test_cases": [ { "input": "oXoxoXo\n", "output": "TAK\n", "type": "stdin_stdout" }, { "input": "bod\n", "output": "TAK\n", "type": "stdin_stdout" }, { "input": "ER\n", "output": "NIE\n", "type": "stdin_stdout" }, ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/691/B" }
vfc_9842
apps
verifiable_code
23
Solve the following coding problem using the programming language python: You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----In...
```python a = list(input()) b = int(input()) a.sort() a = a[::-1] prefix = "" while(len(a) > 0): for i in range(len(a)): num = prefix + a[i] + "".join(sorted(a[:i] + a[i + 1:])) if (int(num) <= b): prefix += a[i] a = a[:i] + a[i+1:] break print(prefix) ```
{ "language": "python", "test_cases": [ { "input": "123\n222\n", "output": "213\n", "type": "stdin_stdout" }, { "input": "3921\n10000\n", "output": "9321\n", "type": "stdin_stdout" }, { "input": "4940\n5000\n", "output": "4940\n", "type": "st...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/915/C" }
vfc_9846
apps
verifiable_code
24
Solve the following coding problem using the programming language python: Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's ...
```python s = [ [ c for c in input() ] for i in range(10) ] def win(): for i in range(10): for j in range(10): ok = True for k in range(5): if j+k>9: ok = False elif s[i][j+k] != 'X': ok = False if ok: return True ok = True for k in range(5): if i+k>9: ok = Fa...
{ "language": "python", "test_cases": [ { "input": "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "XXOXX.....\nOO.O......\n..........\n..........\n...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/825/B" }
vfc_9850
apps
verifiable_code
26
Solve the following coding problem using the programming language python: Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point. Wet Shark knows Rat ...
```python from math import log from decimal import Decimal s = ['x^y^z', 'x^z^y', '(x^y)^z', 'y^x^z', 'y^z^x', '(y^x)^z', 'z^x^y', 'z^y^x', '(z^x)^y'] x, y, z = list(map(Decimal, input().split())) f = [] f += [(Decimal(log(x)) * (y ** z), 0)] f += [(Decimal(log(x)) * (z ** y), -1)] f += [(Decimal(log(x)) * (y * z)...
{ "language": "python", "test_cases": [ { "input": "1.1 3.4 2.5\n", "output": "z^y^x\n", "type": "stdin_stdout" }, { "input": "2.0 2.0 2.0\n", "output": "x^y^z\n", "type": "stdin_stdout" }, { "input": "1.9 1.8 1.7\n", "output": "(x^y)^z\n", "...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/621/D" }
vfc_9858
apps
verifiable_code
28
Solve the following coding problem using the programming language python: The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the fi...
```python n = int(input()) t = [1] + [0] * n b, a = d = [], [] h, s = [], [] for i in range(n): f, k = input().split() d[int(k)].append(f) m = len(a) for i in a: if i.isdigit() and i[0] != '0': j = int(i) if 0 < j <= m: t[j] = 1 elif m < j <= n: t[j] = -1 ...
{ "language": "python", "test_cases": [ { "input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n", "type": "stdin_stdout" }, { "input": "2\n1 0\n2 1\n", "output": "3\nmove 1 07x45l\nmove 2 1\nmove 07x45l 2\n", "ty...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/858/E" }
vfc_9866
apps
verifiable_code
29
Solve the following coding problem using the programming language python: Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is...
```python x=int(input()) def s(a): r=0 while a>0: r+=a%10 a//=10 return r def d(a,b): r=0 for i in range(6): if a%10!=b%10: r += 1 a//=10 b//=10 return r c=6 for i in range(1000000): if s(i%1000)==s(i//1000): c=min(c,d(x,i)) print(c) ```
{ "language": "python", "test_cases": [ { "input": "000000\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "123456\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "111000\n", "output": "1\n", "type": "stdin_stdout" }, ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/845/B" }
vfc_9870
apps
verifiable_code
30
Solve the following coding problem using the programming language python: The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to a...
```python from math import gcd def powmod(a,b,m): a%=m r=1 while b: if b&1:r=r*a%m a=a*a%m b>>=1 return r def f(n): r=[] if (n&1)==0: e=0 while (n&1)==0:n>>=1;e+=1 yield (2,e) p=3 while n>1: if p*p>n:p=n if n%p: p+=2 continue e=1;n//=p while n%p==0:n//=p;e+=1 yield (p,e) p+=2 ret...
{ "language": "python", "test_cases": [ { "input": "4 3\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "5 2\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "7 2\n", "output": "3\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1027/G" }
vfc_9874
apps
verifiable_code
31
Solve the following coding problem using the programming language python: ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interestin...
```python m = 10** 6 + 3 n, k = list(map(int, input().split())) p = 1 for i in range(n): p *= 2 if p > k: break if p < k: print('1 1') return gcd = tmp = k - 1 while tmp: gcd -= tmp % 2 tmp //= 2 b = pow(2, (k - 1) * n - gcd, m) a = 1 mem = [-1]*100 for i in range(1, k): cnt = 0 ...
{ "language": "python", "test_cases": [ { "input": "3 2\n", "output": "1 8", "type": "stdin_stdout" }, { "input": "1 3\n", "output": "1 1", "type": "stdin_stdout" }, { "input": "4 3\n", "output": "23 128", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/711/E" }
vfc_9878
apps
verifiable_code
32
Solve the following coding problem using the programming language python: In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice ...
```python """ Codeforces Good Bye 2016 Contest Problem B Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def main(): latitude = 0 n, = read() for i in range(n): l, d = read(str) l = int(l) if latitude == 0: ...
{ "language": "python", "test_cases": [ { "input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "2\n15000 South\n4000 East\n", "output": "NO\n", "type": "stdin_stdout" }, { "inp...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/750/B" }
vfc_9882
apps
verifiable_code
33
Solve the following coding problem using the programming language python: You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0. -----Input----- The only line contains six integers a_1, ...
```python import sys, collections def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a // gcd(a, b) * b def extgcd(a, b): if b == 0: return 1, 0 x, y = extgcd(b, a % b) return y, x - a // b * y def prime_factor(n): res = collections.defaultdict(int) i = 2 ...
{ "language": "python", "test_cases": [ { "input": "2 0 3 3 5 21\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "2 4 3 0 6 17\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "2 0 4 2 -39 -37\n", "output": "0\n", "type": "...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/710/D" }
vfc_9886
apps
verifiable_code
34
Solve the following coding problem using the programming language python: It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will...
```python n, a, b = map(int, input().split()) ans = 0 for i in range(1, n): ans = max(ans, min(a // i, b // (n - i))) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "5 2 3\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "4 7 10\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "100 100 100\n", "output": "2\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/911/B" }
vfc_9890
apps
verifiable_code
35
Solve the following coding problem using the programming language python: The flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each o...
```python n,m=list(map(int,input().split())) f=[input() for _ in range(n)] def clr(ss): cc = None for s in ss: for c in s: if cc is None: cc = c elif cc != c: return None return cc if n%3 == 0: s = set() for i in range(0,n,n//3): ...
{ "language": "python", "test_cases": [ { "input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "4 3\nBRG\nBRG\nBRG\nBRG\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "6 7\nRRRGG...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/837/B" }
vfc_9894
apps
verifiable_code
36
Solve the following coding problem using the programming language python: Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: ...
```python def f(n): left, right = -1, n + 1 while right - left > 1: mid = (left + right) // 2 x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1) if x > n: right = mid else: left = mid if left >= 0: mid = left x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1) n -= x return (n, left + 1) def main(): n = in...
{ "language": "python", "test_cases": [ { "input": "3\n", "output": "-2 0\n", "type": "stdin_stdout" }, { "input": "7\n", "output": "3 2\n", "type": "stdin_stdout" }, { "input": "39\n", "output": "5 6\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/615/E" }
vfc_9898
apps
verifiable_code
37
Solve the following coding problem using the programming language python: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits ...
```python a, b, c = list(map(int, input().split())) p = [0] * 100000 p[0] = 1 p[a] = 1 p[b] = 1 for i in range(c + 1): if p[i]: p[i + a] = 1 p[i + b] = 1 if p[c]: print('Yes') else: print('No') ```
{ "language": "python", "test_cases": [ { "input": "4 6 15\n", "output": "No\n", "type": "stdin_stdout" }, { "input": "3 2 7\n", "output": "Yes\n", "type": "stdin_stdout" }, { "input": "6 11 6\n", "output": "Yes\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/633/A" }
vfc_9902
apps
verifiable_code
38
Solve the following coding problem using the programming language python: Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length L, in distinct points of which there are n ...
```python def main(): n, l = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) x.append(x[0] + l) y.append(y[0] + l) a = [x[i + 1] - x[i] for i in range(n)] b = [y[i + 1] - y[i] for i in range(n)] for i in range(n): if (a == b[i:] + b[:i]): print("YES") ...
{ "language": "python", "test_cases": [ { "input": "3 8\n2 4 6\n1 5 7\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "4 9\n2 3 5 8\n0 1 3 6\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "2 4\n1 3\n1 2\n", "output": "NO\n"...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/761/B" }
vfc_9906
apps
verifiable_code
39
Solve the following coding problem using the programming language python: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l ...
```python s = input() mx = 0 n = len(s) for l in range(n): for r in range(l, n): if s[l:r+1] != s[l:r+1][::-1]: mx = max(mx, r - l + 1) print(mx) ```
{ "language": "python", "test_cases": [ { "input": "mew\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "wuffuw\n", "output": "5\n", "type": "stdin_stdout" }, { "input": "qqqqqqqq\n", "output": "0\n", "type": "stdin_stdout" }, ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/981/A" }
vfc_9910
apps
verifiable_code
40
Solve the following coding problem using the programming language python: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each par...
```python '''input 5 3123 3123 2777 2777 2246 2246 2246 2246 1699 1699 ''' n = int(input()) x = [] f = 0 for _ in range(n): a, b = list(map(int, input().split())) if a != b: f = 1 x.append(a) if f == 1: print("rated") elif sorted(x)[::-1] == x: print("maybe") else: print("unrated") ```
{ "language": "python", "test_cases": [ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "output": "rated\n", "type": "stdin_stdout" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "output": "unrated\n", "type": "std...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/807/A" }
vfc_9914
apps
verifiable_code
41
Solve the following coding problem using the programming language python: You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. -----Input----- The firs...
```python inf = 10 ** 6 n = int(input()) a = list(map(int, input().split())) dist = [inf] * n for i in range(len(a)): if not a[i]: dist[i] = 0 cur = 1 i1 = i while i1 - 1 > - 1 and a[i1 - 1] != 0: dist[i1 - 1] = min(dist[i1 - 1], cur) i1 -= 1 cur +...
{ "language": "python", "test_cases": [ { "input": "9\n2 1 0 3 0 0 3 2 4\n", "output": "2 1 0 1 0 0 1 2 3 ", "type": "stdin_stdout" }, { "input": "5\n0 1 2 3 4\n", "output": "0 1 2 3 4 ", "type": "stdin_stdout" }, { "input": "7\n5 6 0 1 -2 3 4\n", ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/803/B" }
vfc_9918
apps
verifiable_code
42
Solve the following coding problem using the programming language python: You are given a binary string $s$. Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring. The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that...
```python n=int(input()) s=[c=='1' for c in input()] m=len(s) z=[[0,0]] for c in s: ind = z[-1][c] z[-1][c] = len(z) z.append(z[ind][:]) assert(len(z) == m+1) z[m][0] = z[m][1] = m # make it sticky # how many things match directly dp = [0 for _ in range(m+1)] dp[0] = 1 for i in range(n): ndp = [0 for _ in range(m+...
{ "language": "python", "test_cases": [ { "input": "2\n0\n", "output": "3", "type": "stdin_stdout" }, { "input": "4\n1010\n", "output": "2", "type": "stdin_stdout" }, { "input": "20\n10101010101010\n", "output": "962", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1038/F" }
vfc_9922
apps
verifiable_code
43
Solve the following coding problem using the programming language python: You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and...
```python from math import * # stores counterclockwise angle between vector (1,0) and each vector in a a = [] n = int(input()) for i in range(n): x,y = list(map(int,input().split())) # calculate counterclockwise angle between (1,0) and this vector t = acos(x/sqrt(x**2+y**2)) a.append((i+1,[2*pi-t,t][y>=...
{ "language": "python", "test_cases": [ { "input": "4\n-1 0\n0 -1\n1 0\n1 1\n", "output": "3 4\n", "type": "stdin_stdout" }, { "input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n", "output": "5 6\n", "type": "stdin_stdout" }, { "input": "10\n8 6\n-7 -3\n9 ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/598/C" }
vfc_9926
apps
verifiable_code
44
Solve the following coding problem using the programming language python: Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers. Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After...
```python d, k, a, b, t = list(map(int, input().split())) t1 = d * b t2 = d * a + ((d - 1) // k) * t t3 = max(0, d - k) * b + min(k, d) * a dd = d % k d1 = d - dd t4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b print(min([t1, t2, t3, t4])) ```
{ "language": "python", "test_cases": [ { "input": "5 2 1 4 10\n", "output": "14\n", "type": "stdin_stdout" }, { "input": "5 2 1 4 5\n", "output": "13\n", "type": "stdin_stdout" }, { "input": "1 1 1 2 1\n", "output": "1\n", "type": "stdin_std...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/702/D" }
vfc_9930
apps
verifiable_code
45
Solve the following coding problem using the programming language python: You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is...
```python n, k = map(int, input().split()) div = [] i = 1 n1 = n while i * i <= n: if n % i == 0: div.append(i) div.append(n // i) i += 1 div.sort() mx = -1 for i in range(len(div)): a = div[i] * k * (k + 1) // 2 if a <= n: mx = div[i] if mx == -1: print(-1) else: for i i...
{ "language": "python", "test_cases": [ { "input": "6 3\n", "output": "1 2 3\n", "type": "stdin_stdout" }, { "input": "8 2\n", "output": "2 6\n", "type": "stdin_stdout" }, { "input": "5 3\n", "output": "-1\n", "type": "stdin_stdout" }, ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/803/C" }
vfc_9934
apps
verifiable_code
46
Solve the following coding problem using the programming language python: After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to ...
```python ct=0 a, b = list(map(int, input().split(' '))) x=[0]*5 for i in range(1, b+1): x[i%5]+=1 for i in range(1, a+1): ct+=x[(0-i)%5] print(ct) ```
{ "language": "python", "test_cases": [ { "input": "6 12\n", "output": "14\n", "type": "stdin_stdout" }, { "input": "11 14\n", "output": "31\n", "type": "stdin_stdout" }, { "input": "1 5\n", "output": "1\n", "type": "stdin_stdout" }, ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/682/A" }
vfc_9938
apps
verifiable_code
47
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of ...
```python N, X = list(map(int, input().split())) A = [int(a) for a in input().split()] dp = [[0]*4 for _ in range(N+1)] for i in range(1, N+1): dp[i][0] = max(dp[i-1][0] + A[i-1], 0) dp[i][1] = max(dp[i-1][1] + A[i-1] * X, dp[i][0]) dp[i][2] = max(dp[i-1][2] + A[i-1], dp[i][1]) dp[i][3] = max(dp[i-1][...
{ "language": "python", "test_cases": [ { "input": "5 -2\n-3 8 -2 1 -6\n", "output": "22\n", "type": "stdin_stdout" }, { "input": "12 -3\n1 3 3 7 1 3 3 7 1 3 3 7\n", "output": "42\n", "type": "stdin_stdout" }, { "input": "5 10\n-1 -2 -3 -4 -5\n", "...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1155/D" }
vfc_9942
apps
verifiable_code
48
Solve the following coding problem using the programming language python: Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on...
```python def main(): from math import sqrt m, n, k = list(map(int, input().split())) if n < m: n, m = m, n lo, hi = 1, k + 1 while lo + 1 < hi: mid = (lo + hi) // 2 t = mid - 1 v = min(int(sqrt(t)), m) tn, tm = (t - 1) // m, t // n vv = [t // i for i ...
{ "language": "python", "test_cases": [ { "input": "2 2 2\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "2 3 4\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "1 10 5\n", "output": "5\n", "type": "stdin_stdout" }, ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/448/D" }
vfc_9946
apps
verifiable_code
49
Solve the following coding problem using the programming language python: Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your tas...
```python k = int(input()) if k<=9: print(k) else: num_arr = [9*(i+1)* 10**i for i in range(11)] index = 0 while True: if k<=num_arr[index]: break else: k -= num_arr[index] index += 1 digit = index+1 k += digit-1 num = k//digit of...
{ "language": "python", "test_cases": [ { "input": "7\n", "output": "7\n", "type": "stdin_stdout" }, { "input": "21\n", "output": "5\n", "type": "stdin_stdout" }, { "input": "1\n", "output": "1\n", "type": "stdin_stdout" }, { "i...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1177/B" }
vfc_9950
apps
verifiable_code
50
Solve the following coding problem using the programming language python: Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market! In the morning, there are $n$ opportunities to buy shares. T...
```python n, m, r = map(int, input().split()) S = list(map(int, input().split())) B = list(map(int, input().split())) x = min(S) y = max(B) cnt = r % x act = r // x cnt += act * y print(max(r, cnt)) ```
{ "language": "python", "test_cases": [ { "input": "3 4 11\n4 2 5\n4 4 5 4\n", "output": "26\n", "type": "stdin_stdout" }, { "input": "2 2 50\n5 7\n4 2\n", "output": "50\n", "type": "stdin_stdout" }, { "input": "1 1 1\n1\n1\n", "output": "1\n", ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1150/A" }
vfc_9954
apps
verifiable_code
51
Solve the following coding problem using the programming language python: В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии ко...
```python s = input() t = 0 if len(s)%2==0: n = (len(s)-1)//2+1 else: n = (len(s)-1)//2 for i in range(n, len(s)-1): a = i b = len(s)-i-1 if s[:a+1]==s[b:]: print('YES') print(s[:a+1]) t = 1 break if t==0: print('NO') ```
{ "language": "python", "test_cases": [ { "input": "abrakadabrabrakadabra\n", "output": "YES\nabrakadabra\n", "type": "stdin_stdout" }, { "input": "acacacaca\n", "output": "YES\nacaca\n", "type": "stdin_stdout" }, { "input": "abcabc\n", "output": "...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/646/B" }
vfc_9958
apps
verifiable_code
52
Solve the following coding problem using the programming language python: Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage...
```python n = int(input()) res = set() for r in range(100): a = 1 b = 2**(r + 1) - 3 c = -2 * n d = b * b - 4 * a * c if d < 0: continue le = 0 ri = d while le < ri: c = (le + ri) // 2 if c * c < d: le = c + 1 else: ri = c if le...
{ "language": "python", "test_cases": [ { "input": "3\n", "output": "3\n4\n", "type": "stdin_stdout" }, { "input": "25\n", "output": "20\n", "type": "stdin_stdout" }, { "input": "2\n", "output": "-1\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/325/B" }
vfc_9962
apps
verifiable_code
54
Solve the following coding problem using the programming language python: Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the giv...
```python w,m=map(int,input().split()) bb=True while(m>0 and bb): x=m%w if x==1:m-=1 elif x==w-1:m+=1 elif x!=0:bb=False m//=w if bb:print("YES") else:print("NO") ```
{ "language": "python", "test_cases": [ { "input": "3 7\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "100 99\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "100 50\n", "output": "NO\n", "type": "stdin_stdout" }...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/552/C" }
vfc_9970
apps
verifiable_code
55
Solve the following coding problem using the programming language python: Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the n...
```python from collections import defaultdict def solve(n, k): as_bin = bin(n)[2:] cnt = defaultdict(int) cnt.update({i : 1 for i, b in enumerate(reversed(as_bin)) if b == '1'}) curr_len = len(cnt) curr_pow = len(as_bin) - 1 if curr_len > k: return None while True: new_len...
{ "language": "python", "test_cases": [ { "input": "23 5\n", "output": "Yes\n3 3 2 1 0 \n", "type": "stdin_stdout" }, { "input": "13 2\n", "output": "No\n", "type": "stdin_stdout" }, { "input": "1 2\n", "output": "Yes\n-1 -1 \n", "type": "std...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/916/B" }
vfc_9974
apps
verifiable_code
56
Solve the following coding problem using the programming language python: Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level...
```python n, t = list(map(int,input().split())) g = [[0.0] * i for i in range(1,n+1)] for _ in range(t): g[0][0] += 1.0 for i in range(n): for j in range(i+1): spill = max(0, g[i][j] - 1.0) g[i][j] -= spill if i < n - 1: g[i + 1][j] += spill / 2 ...
{ "language": "python", "test_cases": [ { "input": "3 5\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "4 8\n", "output": "6\n", "type": "stdin_stdout" }, { "input": "1 1\n", "output": "1\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/676/B" }
vfc_9978
apps
verifiable_code
57
Solve the following coding problem using the programming language python: After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of ...
```python n = int(input()) points = [[int(x) for x in input().split()] for _ in range(n)] if n <= 1: print(-1) return dx = [1e9, -1e9] dy = [1e9, -1e9] for x, y in points: dx[0] = min(dx[0], x) dx[1] = max(dx[1], x) dy[0] = min(dy[0], y) dy[1] = max(dy[1], y) area = (dx[1] - dx[0]) * (dy[1] - dy[0]) if area: pri...
{ "language": "python", "test_cases": [ { "input": "2\n0 0\n1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "1\n1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": "1\n-188 17\n", "output": "-1\n", "type": "stdin_stdo...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/596/A" }
vfc_9982
apps
verifiable_code
58
Solve the following coding problem using the programming language python: Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed f...
```python '''input 6 4 2 ''' def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() def f(n,a,b,left,cnta = 4,cntb = 2): if(cnta == 0 and cntb == 0): return 0 if(cnta < 0 or cntb < 0): return 10000000000000000000...
{ "language": "python", "test_cases": [ { "input": "8\n1\n2\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "5\n3\n4\n", "output": "6\n", "type": "stdin_stdout" }, { "input": "6\n4\n2\n", "output": "4\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/910/B" }
vfc_9986
apps
verifiable_code
60
Solve the following coding problem using the programming language python: A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the l...
```python seat = input() time_to = {'a': 4, 'f': 1, 'b': 5, 'e': 2, 'c': 6, 'd': 3} col = seat[-1] row = int(seat[:-1]) row -= 1 blocks_to_serve = row // 4 time = (6 * 2 + 4) * blocks_to_serve if row % 2 == 1: time += 6 + 1 time += time_to[col] print(time) ```
{ "language": "python", "test_cases": [ { "input": "1f\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "2d\n", "output": "10\n", "type": "stdin_stdout" }, { "input": "4a\n", "output": "11\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/725/B" }
vfc_9994
apps
verifiable_code
61
Solve the following coding problem using the programming language python: After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations. You're given a number X represented in base b_{x} and a number Y represented ...
```python n, bx = list(map(int, input().split())) x1 = list(map(int, input().split())) x = 0 for i in range(n): x *= bx x += x1[i] n, by = list(map(int, input().split())) y1 = list(map(int, input().split())) y = 0 for i in range(n): y *= by y += y1[i] if x == y: print('=') elif x < y: print('<') else: print('>...
{ "language": "python", "test_cases": [ { "input": "6 2\n1 0 1 1 1 1\n2 10\n4 7\n", "output": "=\n", "type": "stdin_stdout" }, { "input": "3 3\n1 0 2\n2 5\n2 4\n", "output": "<\n", "type": "stdin_stdout" }, { "input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/602/A" }
vfc_9998
apps
verifiable_code
62
Solve the following coding problem using the programming language python: Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games! Since you are so curious about Bitland...
```python from math import * n=int(input()) if n==3: li=list(map(int,input().split())) ans=0 flag=0 for i in li: ans^=i if ans==0: print("BitAryo") else: print("BitLGM") elif n==2: li=list(map(int,input().split())) li.sort() phi=(1+sqrt(5))/2 ch=[0]*(785) ...
{ "language": "python", "test_cases": [ { "input": "2\n1 1\n", "output": "BitLGM\n", "type": "stdin_stdout" }, { "input": "2\n1 2\n", "output": "BitAryo\n", "type": "stdin_stdout" }, { "input": "3\n1 2 1\n", "output": "BitLGM\n", "type": "std...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/282/D" }
vfc_10002
apps
verifiable_code
63
Solve the following coding problem using the programming language python: Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on...
```python n,k=map(int,input().split()) l=list(map(int,input().split())) pf=[] needed=[] for i in range(2,40000): if k%i==0: pf.append(i) c=0 while k%i==0: k//=i c+=1 needed.append(c) if k>1: pf.append(k) needed.append(1) pfl=len(pf) cnt=[[0]*n for i in range(pfl)] for i in range(n): for j in range(len...
{ "language": "python", "test_cases": [ { "input": "3 4\n6 2 8\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "3 6\n9 1 14\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "5 1\n1 3 1 3 1\n", "output": "15\n", "type": "std...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/818/E" }
vfc_10006
apps
verifiable_code
64
Solve the following coding problem using the programming language python: One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all ba...
```python alpha = [chr(ord('a')+i) for i in range(26)] n,k = list(map(int,input().split())) s = input() arr = [s.count(alpha[i]) for i in range(26)] print('YES' if max(arr) <= k else 'NO') ```
{ "language": "python", "test_cases": [ { "input": "4 2\naabb\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "6 3\naacaab\n", "output": "NO\n", "type": "stdin_stdout" }, { "input": "2 2\nlu\n", "output": "YES\n", "type": "stdin_s...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/841/A" }
vfc_10010
apps
verifiable_code
65
Solve the following coding problem using the programming language python: You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. -----Input----- The first line conta...
```python n = int(input()) A = [int(x) for x in input().split()] mn = min(A) I = [i for i in range(len(A)) if A[i] == mn] mindiff = min(I[i]-I[i-1] for i in range(1,len(I))) print(mindiff) ```
{ "language": "python", "test_cases": [ { "input": "2\n3 3\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "3\n5 6 5\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "9\n2 1 3 5 4 1 2 3 1\n", "output": "3\n", "type": "stdin...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/911/A" }
vfc_10014
apps
verifiable_code
66
Solve the following coding problem using the programming language python: Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. [Image] Willman and Bolt have exactly the same speed, so when they compete the result is alw...
```python from fractions import gcd t,w,b = map(int,input().split()) per = w*b//gcd(w,b) can = (t//per+1)*min(w,b)-1 if t%per<min(w,b): can-=min(w,b) can+=t%per+1 g = gcd(can,t) can//=g t//=g print(str(can)+"/"+str(t)) ```
{ "language": "python", "test_cases": [ { "input": "10 3 2\n", "output": "3/10\n", "type": "stdin_stdout" }, { "input": "7 1 2\n", "output": "3/7\n", "type": "stdin_stdout" }, { "input": "1 1 1\n", "output": "1/1\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/592/C" }
vfc_10018
apps
verifiable_code
67
Solve the following coding problem using the programming language python: Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there w...
```python x, y, z = map(int, input().split()) if z == 0: if x == y: print('0') elif x > y: print('+') else: print('-') else: if x > y + z: print('+') elif x + z < y: print('-') else: print('?') ```
{ "language": "python", "test_cases": [ { "input": "3 7 0\n", "output": "-", "type": "stdin_stdout" }, { "input": "2 0 1\n", "output": "+", "type": "stdin_stdout" }, { "input": "1 1 0\n", "output": "0", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1173/A" }
vfc_10022
apps
verifiable_code
68
Solve the following coding problem using the programming language python: Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; ...
```python # import collections, atexit, math, sys, bisect sys.setrecursionlimit(1000000) def getIntList(): return list(map(int, input().split())) try : #raise ModuleNotFoundError import numpy def dprint(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) dprint('debug mode...
{ "language": "python", "test_cases": [ { "input": "5\nRURUU\n-2 3\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "4\nRULR\n1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "3\nUUU\n100 100\n", "output": "-1\n", "type"...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1073/C" }
vfc_10026
apps
verifiable_code
69
Solve the following coding problem using the programming language python: You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010... Calculate...
```python t=int(input()) for i in ' '*t: n,x=map(int,input().split()) s=input() L=[0] for i in s: if i=='0':L.append(L[-1]+1) else:L.append(L[-1]-1) L.pop(0) k=L[-1] c=0 if x==0:c+=1 if k>0: for i in L: if i%k==x%k and i<=x:c+=1 print(c) ...
{ "language": "python", "test_cases": [ { "input": "4\n6 10\n010010\n5 3\n10101\n1 0\n0\n2 0\n01\n", "output": "3\n0\n1\n-1\n", "type": "stdin_stdout" }, { "input": "2\n1 -548706795\n0\n1 -735838406\n1\n", "output": "0\n1\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1295/B" }
vfc_10030
apps
verifiable_code
70
Solve the following coding problem using the programming language python: Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the ...
```python s = input().split() k = int(s[1]) s = s[0] if s.count('0') < k: if s.count('0') > 0: print(len(s) - 1) else: print(len(s)) return have = 0 its = 0 for i in range(len(s) - 1, -1, -1): its += 1 if s[i] == '0': have += 1 if have == k: print(its - have) ...
{ "language": "python", "test_cases": [ { "input": "30020 3\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "100 9\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "10203049 2\n", "output": "3\n", "type": "stdin_stdout" ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/779/B" }
vfc_10034
apps
verifiable_code
71
Solve the following coding problem using the programming language python: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the followin...
```python n, m, k, x, y = list(map(int, input().split())) ans = [[0] * m for x in range(n)] onebig = (2*n-2)*m or m oo = k // onebig for i in range(n): for j in range(m): if i == 0 or i == n-1: ans[i][j] += oo k -= oo else: ans[i][j] += 2*oo k -= 2...
{ "language": "python", "test_cases": [ { "input": "1 3 8 1 1\n", "output": "3 2 3", "type": "stdin_stdout" }, { "input": "4 2 9 4 2\n", "output": "2 1 1", "type": "stdin_stdout" }, { "input": "5 5 25 4 3\n", "output": "1 1 1", "type": "stdin...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/758/C" }
vfc_10038
apps
verifiable_code
72
Solve the following coding problem using the programming language python: After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they...
```python turns = int(input()) s0 = input() s1 = input() s2 = input() d0 = dict() d1 = dict() d2 = dict() alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' for char in alphabet: d0[char] = 0 d1[char] = 0 d2[char] = 0 for char in s0: d0[char] += 1 for char in s1: d1[char] += 1 for char in s2: d2...
{ "language": "python", "test_cases": [ { "input": "3\nKuroo\nShiro\nKatie\n", "output": "Kuro\n", "type": "stdin_stdout" }, { "input": "7\ntreasurehunt\nthreefriends\nhiCodeforces\n", "output": "Shiro\n", "type": "stdin_stdout" }, { "input": "1\nabcabc\...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/979/B" }
vfc_10042
apps
verifiable_code
73
Solve the following coding problem using the programming language python: Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages. At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pag...
```python read = lambda: map(int, input().split()) c, v0, v1, a, l = read() cur = 0 cnt = 0 while cur < c: cur = max(0, cur - l) cur += min(v1, v0 + a * cnt) cnt += 1 print(cnt) ```
{ "language": "python", "test_cases": [ { "input": "5 5 10 5 4\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "12 4 12 4 1\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "15 1 100 0 0\n", "output": "15\n", "type": "stdin...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/820/A" }
vfc_10046