source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
code_contests
verifiable_code
p01888 Multisect
Solve the following coding problem using the programming language python: Example Input 1 10 2 1 1 1 Output 2.0 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
vfc_68745
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 10 2\n1 1 1", "output": "2.0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10 1\n1 1 1", "output": "3.2222222222\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02025 Angel Relief
Solve the following coding problem using the programming language python: K: Relief (Angel Relief) Tenma, an angel, decides to save a city. The city has a rectangular shape divided into north-south $ H $ parcels x east-west $ W $ parcels, with houses in each parcel. The $ X $ th section from the north and the $ Y $...
```python def f(): return map(int,input().split()) h,w=f();print(sum([sum([(x+1)*(w-x)*v for x,v in enumerate(f())])*(y+1)*(h-y)for y in range(h)])) ```
vfc_68749
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 2\n4 8", "output": "60", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 2\n0 8", "output": "44\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
bipin3
Solve the following coding problem using the programming language python: Zombies zombies everywhere!!  In a parallel world of zombies, there are N zombies. There are infinite number of unused cars, each of same model only differentiated by the their colors. The cars are of K colors. A zombie parent can give birth t...
```python mod = 10 ** 9 + 7 def powmod(n, p): if p == 0: return 1 if p == 1: return n % mod if p % 2 == 1: return n * powmod(n, p - 1) % mod x = powmod(n, p / 2) % mod return x * x % mod t = int(raw_input()) for i in xrange(t): n, k = map(int, raw_input().split()) print ...
vfc_68765
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 2\n3 3", "output": "2\n12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n3 3", "output": "2\n12\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
ftrip
Solve the following coding problem using the programming language python: Alice's school is planning to take some students from her class on a field trip. Alice is really excited about it. There are a total of S students in her class. But due to budget constraints, the school is planning to take only N students for th...
```python nCr = [[0 for x in xrange(1001)] for x in xrange(1001)] for i in range (0,1001): nCr[i][0]=1 nCr[i][i]=1 for i in range (1,1001): for j in range (1,1001): if i!=j: nCr[i][j] = nCr[i-1][j] + nCr[i-1][j-1] t=input() for _ in range(0,t): s,n,m,k=map(int,raw_input().split(' ')...
vfc_68773
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10 10 5 3\n10 4 6 4\n3 2 2 1", "output": "1.000000\n0.000000\n0.500000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10 10 5 3\n10 4 1 4\n3 2 2 1", "output": "1.000000\n0.000...
code_contests
verifiable_code
lucky1
Solve the following coding problem using the programming language python: Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let Fd(x) equals to the n...
```python #codechef feb long quest M=[0]*100001 A=[0]*100001 M[0]=1 s4=0 s7=0 ret=0 for el in range(1,100001): n=el while n>0: k=n%10 if(k==4):s4+=1 if(k==7):s7+=1 n=n/10 ret+=M[s4-s7] A[el]=ret M[s4-s7]+=1 t=int(raw_input()) for i in range(t): n=int(raw_input()) ...
vfc_68777
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n10\n100", "output": "6\n31\n1266\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3\n10\n000", "output": "6\n31\n0\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
prom06
Solve the following coding problem using the programming language python: Damian Wayne and Carrie Kelly are classmates and best friends. Since class 5, they have been in the same section. They usually sat on the last bench so that they could chat all they want during the class. One day, during the ancient martial arts...
```python a=input() for i in range(a): b=raw_input() string="" for j in b: k=ord(j) if(48<=k<=57): string+=chr(k+57) elif(97<=k<=104): string+=chr(k+18) elif(105<=k<=114): string+=chr(k-57) elif(115<=k<=122): string+=chr(k-18) else: string+=j print string ```
vfc_68781
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\ndie another day.\ni'm batman.", "output": "v0w s56bzw9 vsg.\n0'4 tsb4s5.", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
tdiv
Solve the following coding problem using the programming language python: ABC School is organising a sporting event. But they don’t know which game they should take up, so that every person can be divided in equally-sized teams with no one left over. Now, the school consists of various classes. You are given an array ...
```python for b in range(input()): c = input() d = map(int,raw_input().split()) d.sort() for k in range(d[0],0,-1): for l in d: if l % k == 0: flag = 1 else: flag = 0 break if flag == 1: print k ...
vfc_68785
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 2 3\n3\n4 12 6\n2\n8 12", "output": "1\n2\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3\n1 4 3\n3\n4 12 6\n2\n8 12", "output": "1\n2\n4\n", "type": "stdin_stdou...
code_contests
verifiable_code
1011_F. Mars rover
Solve the following coding problem using the programming language python: Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex 1, in which every leaf (excluding root) is an ...
```python AND = "AND" OR = "OR" XOR = "XOR" NOT = "NOT" IN = "IN" OPS = { AND: AND, OR: OR, XOR: XOR, NOT: NOT, } class Node: def __init__(self, num): self.num = num self.op = None self.parent = None self.input_1 = None self.input_2 = None self.orig...
vfc_68789
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\nAND 9 4\nIN 1\nIN 1\nXOR 6 5\nAND 3 7\nIN 0\nNOT 10\nIN 1\nIN 1\nAND 2 8\n", "output": "10110\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nAND 2 3\nIN 1\nIN 0\n", "output":...
code_contests
verifiable_code
105_A. Transmigration
Solve the following coding problem using the programming language python: In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an ...
```python #!/usr/bin/env python3 ESP = 1e-7 n, m, k = input().rstrip().split() n, m, k = int(n), int(m), float(k) cur = {} for i in range(n): skill, exp = input().rstrip().split() exp = int(int(exp) * k + ESP) if exp >= 100: cur[skill] = exp for i in range(m): skill = input().rstrip() cur....
vfc_68797
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost\n", "output": "6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0\n", "type": "stdin_stdout"...
code_contests
verifiable_code
1081_B. Farewell Party
Solve the following coding problem using the programming language python: Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced. Chouti remembered that n persons took part in that p...
```python import math, sys from fractions import * def mp(): return list(map(int, input().split())) def main(): n = int(input()) a = mp() cnt = [0] * (n + 1) for i in a: cnt[i] += 1 k = 1 ans = [[] for i in range(n + 1)] for i in range(n + 1): if cnt[i] == 0: ...
vfc_68801
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 0 0\n", "output": "Possible\n1 1 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 3 2 2 2\n", "output": "Possible\n1 1 2 2 2 \n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1100_B. Build a Contest
Solve the following coding problem using the programming language python: Arkady coordinates rounds on some not really famous competitive programming platform. Each round features n problems of distinct difficulty, the difficulties are numbered from 1 to n. To hold a round Arkady needs n new (not used previously) pro...
```python diff, prob = [int(x) for x in input().split()] probs = [int(x) for x in input().split()] counts = {} comp = {} num = 0 for i in range(diff): counts[i + 1] = 0 comp[i + 1] = False for p in probs: counts[p] += 1 if comp[p] == False: num += 1 comp[p] = True if (num == di...
vfc_68805
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 8\n4 1 3 3 2 3 3 3\n", "output": "00001000", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1148_H. Holy Diver
Solve the following coding problem using the programming language python: You are given an array which is initially empty. You need to perform n operations of the given format: * "a l r k": append a to the end of the array. After that count the number of integer pairs x, y such that l ≤ x ≤ y ≤ r and \operatorname...
vfc_68813
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 0 0 2\n2 0 1 1\n0 0 2 0\n3 2 2 0\n0 2 3 0\n", "output": " 0\n 0\n ...
code_contests
verifiable_code
116_E. Plumber
Solve the following coding problem using the programming language python: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, ill...
vfc_68817
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n1\n4\n.\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n13\n..\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1188_D. Make Equal
Solve the following coding problem using the programming language python: You are given n numbers a_1, a_2, ..., a_n. In one operation we can add to any one of those numbers a nonnegative integer power of 2. What is the smallest number of operations we need to perform to make all n numbers equal? It can be proved tha...
vfc_68821
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n228 228 228 228\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 2 8\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1207_F. Remainder Problem
Solve the following coding problem using the programming language python: You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero. You have to process two types of queries to this array: * 1 x y — increase a_x by y; * 2 x y — compute ∑_{i ∈ R(x, y...
```python import sys n = 500001 sqrt = int(0.75 * n**0.5) data = [0]*(n) ans = [[]] # out = [] for i in range(1, sqrt): ans.append([0]*i) j = int(sys.stdin.readline()) qus = sys.stdin.readlines() for qu in qus: q = [int(i) for i in qu.split()] if q[0] == 1: x = q[1] y = q[2] data[x]...
vfc_68825
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3 4\n2 3 0\n2 4 3\n1 4 -4\n2 1 0\n", "output": "4\n4\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1000 2\n2 1001 1000\n", "output": "2\n", "type": "stdin_stdout...
code_contests
verifiable_code
1225_F. Tree Factory
Solve the following coding problem using the programming language python: Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and important order. The tree in question is a rooted tree w...
vfc_68829
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0 0 1 1\n", "output": "0 2 1 3 4\n2\n1 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 1 2\n", "output": "0 1 2 3\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
124_B. Permutations
Solve the following coding problem using the programming language python: You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. Input The first li...
```python import sys data = sys.stdin.read().split() data_ptr = 0 def data_next(): global data_ptr, data data_ptr += 1 return data[data_ptr - 1] N = int(data_next()) K = int(data_next()) arr = [] for i in range(N): arr.append(list(data_next())); perm = [] for i in range(K): perm.append(str(i)) ...
vfc_68833
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n5237\n2753\n7523\n5723\n5327\n2537\n", "output": "2700\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156\n", "output": "20522\...
code_contests
verifiable_code
1290_F. Making Shapes
Solve the following coding problem using the programming language python: You are given n pairwise non-collinear two-dimensional vectors. You can make shapes in the two-dimensional plane with these vectors in the following fashion: 1. Start at the origin (0, 0). 2. Choose a vector and add the segment of the vecto...
vfc_68841
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 768000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1000000000\n-2 4\n2 -3\n0 -4\n2 4\n-1 -3\n", "output": "9248783", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1776966\n-1 0\n3 3\n0 -2\n", "output": "296161", "type": "stdi...
code_contests
verifiable_code
1311_A. Add Odd or Subtract Even
Solve the following coding problem using the programming language python: You are given two positive integers a and b. In one move, you can change a in the following way: * Choose any positive odd integer x (x > 0) and replace a with a+x; * choose any positive even integer y (y > 0) and replace a with a-y. ...
```python for i in range(int(input())): a,b=map(int,input().split()) if a==b: print(0) elif a<b: if (b-a)%2==0: print(2) else: print(1) elif a>b: if (a-b)%2==0: print(1) else: print(2) ```
vfc_68845
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 3\n10 10\n2 4\n7 4\n9 3\n", "output": "1\n0\n2\n2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n484887 54\n", "output": "2\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1333_E. Road to 1600
Solve the following coding problem using the programming language python: Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help! Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up ...
```python from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i...
vfc_68849
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "4 3 6 12 \n7 5 9 15 \n14 1 11 10 \n13 8 16 2 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1354_B. Ternary String
Solve the following coding problem using the programming language python: You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once. A contiguous substring of string s is a st...
```python import math from sys import stdin,stdout def L(): return list(map(int,stdin.readline().split())) #For array input def Si(): return sorted(list(map(int,stdin.readline().split()))) #For sorted array def In(): return map(int,stdin.readline().split()) #For multiple input def I(): return stdin.read...
vfc_68853
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n123\n12222133333332\n112233\n332211\n12121212\n333333\n31121\n", "output": "3\n3\n4\n4\n0\n0\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1111111111111111111111123\n", "o...
code_contests
verifiable_code
1373_G. Pawns
Solve the following coding problem using the programming language python: You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as ...
```python import collections import math n, k, m = [int(i) for i in input().split()] l = math.ceil((math.log(2*n) / math.log(2))) p = 2 ** l # print(p) memo = [0] * (2 * p) allres = [0] * (2 * p) exist = set() for _i in range(m): x, y = [int(i) for i in input().split()] l = abs(x - k) + y index = l + p ...
vfc_68857
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 5\n4 4\n3 5\n2 4\n3 4\n3 5\n", "output": "0\n1\n2\n2\n1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1397_A. Juggling Letters
Solve the following coding problem using the programming language python: You are given n strings s_1, s_2, …, s_n consisting of lowercase Latin letters. In one operation you can remove a character from a string s_i and insert it to an arbitrary position in a string s_j (j may be equal to i). You may perform this ope...
```python for _ in range(int(input())): #n,k=map(int,input().split()) ll=[0]*26 n=int(input()) bool=True for _ in range(n): s=input() pp=set(s) for c in pp: cc=s.count(c) ll[ord(c)-97]+=cc # print(ll) for x in ll: if x%n!=0 : bool=False if bool == True : print...
vfc_68861
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\ncaa\ncbb\n3\ncba\ncba\ncbb\n4\nccab\ncbac\nbca\nacbcc\n4\nacb\ncaf\nc\ncbafc\n", "output": "YES\nNO\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\naaa\naa\n", "...
code_contests
verifiable_code
1439_A2. Binary Table (Hard Version)
Solve the following coding problem using the programming language python: This is the hard version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of si...
```python from sys import stdin input = stdin.readline mp = lambda : map(int,input().split()) it = lambda: int(input()) for _ in range(it()): a,b = mp() t = [list(map(int,list(input().strip()))) for i in range(a)] # print(t) saare =[] for i in range(a-2): for j in range(b): if t[i][j]==1: if j!=b-1: ...
vfc_68869
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n", "output": "1\n1 1 2 1 2 2\n6\n1 2 2 1 2 2\n1 3 2 2 2 3\n3 1 2 2 3 2\n2 2 3 2 3 3\n2 2 2 3 3 3\n2 2 2 3...
code_contests
verifiable_code
1466_A. Bovine Dilemma
Solve the following coding problem using the programming language python: Argus was charged with guarding Io, which is not an ordinary cow. Io is quite an explorer, and she wanders off rather frequently, making Argus' life stressful. So the cowherd decided to construct an enclosed pasture for Io. There are n trees gr...
```python import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return (list(s[:len(s) - 1])) def invr(): return (map(int, input().split()...
vfc_68873
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n4\n1 2 4 5\n3\n1 3 5\n3\n2 6 8\n2\n1 2\n1\n50\n5\n3 4 5 6 8\n3\n1 25 26\n6\n1 2 4 8 16 32\n", "output": "\n4\n2\n3\n1\n0\n5\n3\n15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n...
code_contests
verifiable_code
1512_E. Permutation by Sum
Solve the following coding problem using the programming language python: A permutation is a sequence of n integers from 1 to n, in which all the numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was given four integers n, l, r (...
```python t = int(input()) for _ in range(t): n, l, r, s = map(int, input().split()) l -= 1 r -= 1 c = r - l + 1 if c * (c + 1) // 2 > s or c * (2 * n + 1 - c) // 2 < s: print(-1) continue sec = [i for i in range(1, c + 1)] sec.reverse() s -= c * (c + 1) // 2 cnt = 0 ...
vfc_68881
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 2 3 5\n5 3 4 1\n3 1 2 4\n2 2 2 2\n2 1 1 3\n", "output": "\n1 2 3 4 5 \n-1\n1 3 2 \n1 2 \n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n500 1 499 125250\n", "output": "-1...
code_contests
verifiable_code
153_C. Caesar Cipher
Solve the following coding problem using the programming language python: Caesar cipher is one of the simplest encryption techniques. To transform the original message into encrypted one using key k, one has to replace each letter with a letter which is k positions later in the alphabet (if this takes the position bey...
vfc_68885
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "CODEFORCES\n5\n", "output": "HTIJKTWHJX\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "WIXYZILWYM\n6\n", "output": "CODEFORCES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
167_A. Wizards and Trolleybuses
Solve the following coding problem using the programming language python: In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a dista...
```python # written with help of passed solutions from math import sqrt n, a, d = map(int, input().split()) a = float(a) ans = [0] * n tm = 0 for i in range(n): t, v = map(int, input().split()) acc_t = v / a add_t = 0 if acc_t ** 2 * a > 2 * d: add_t = sqrt(2 * d / a) else: add_t ...
vfc_68889
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 26\n28 29\n", "output": "33.0990195136\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10 10000\n0 10\n5 11\n1000 1\n", "output": "1000.5000000000\n1000.5000000000\n11000.05000...
code_contests
verifiable_code
188_B. A + Reverse B
Solve the following coding problem using the programming language python: You are given numbers a and b. Calculate the sum of a and reverse of b. A reverse of a number is a number which contains the same digits in reverse order. For example, reverse of 230 is 32, and reverse of 0 is 0. Input The input contains two i...
vfc_68893
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 15\n", "output": "56\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "73 9180\n", "output": "892\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
234_C. Weather
Solve the following coding problem using the programming language python: Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet. Our hero Vasya is quite concerned about the problems. He decided to try a little exper...
```python ''' Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineerin College Date:07/06/2020 ''' from os import path import sys from functools import cmp_to_key as ctk from collections import deque,defaultdict as dd from bisect import bisect,bisect_left,bisect_right,insort,insort_left,inso...
vfc_68901
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n-1 1 -2 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 -1 1 2 -5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
25_B. Phone numbers
Solve the following coding problem using the programming language python: Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find ...
```python n = int(input()) s = input() while (len(s) > 4): print (s[0:2], end='-') s = s[2:] if (len(s) <=3): print (s) else: print (s[0:2], s[2:4], sep='-') ```
vfc_68905
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n549871\n", "output": "54-98-71\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1198733\n", "output": "11-98-733\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
283_B. Cow Program
Solve the following coding problem using the programming language python: Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: 1. Initially, x = 1 and y = 0. If, afte...
```python INF = float('inf') n = int(input()) aaa = [0, 0] + list(map(int, input().split())) dp = [[0 for _ in range(n+1)] for i in range(2)] vis = [[0 for _ in range(n+1)] for i in range(2)] rs = [0] * (n-1) def di(d): return 0 if d == 1 else 1 def solve(x, d): if dp[di(d)][x]: return dp[di(d)][x] ...
vfc_68909
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 4 1\n", "output": "3\n6\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n", "output": "-1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
306_A. Candies
Solve the following coding problem using the programming language python: Polycarpus has got n candies and m friends (n ≥ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to c...
```python n,m=map(int,input().split()) print(*[n//m+1 if i<n%m else n//m for i in range(m)]) ```
vfc_68913
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "18 7\n", "output": "2 2 2 3 3 3 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 4\n", "output": "3 4 4 4 \n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
331_C3. The Great Julya Calendar
Solve the following coding problem using the programming language python: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaveri...
```python memoization_table = {} def compute_count(previous_max, rest): global memoization_table original_rest = rest if (previous_max, rest) in memoization_table: return memoization_table[(previous_max, rest)] num_digits = len(str(rest)) if num_digits == 1: memoization...
vfc_68917
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "24\n", "output": "5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
378_A. Playing with Dice
Solve the following coding problem using the programming language python: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The fi...
```python import math n1,n2 = map(int ,input().split()) a,b,d = 0,0,0 for i in range(1,7): d1 = abs(i-n1) d2 = abs(i-n2) if d1<d2: a+=1 elif d1>d2: b+=1 else: d+=1 print(a,d,b) ```
vfc_68925
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5\n", "output": "3 0 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n", "output": "2 1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
39_C. Moon Craters
Solve the following coding problem using the programming language python: There are lots of theories concerning the origin of moon craters. Most scientists stick to the meteorite theory, which says that the craters were formed as a result of celestial bodies colliding with the Moon. The other version is that the crate...
vfc_68929
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n2 2\n4 1\n5 1\n", "output": "3\n1 2 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1\n199999999 1\n100000000 100000000\n", "output": "3\n3 1 2 \n", "type": "st...
code_contests
verifiable_code
424_D. Biathlon Track
Solve the following coding problem using the programming language python: Recently an official statement of the world Olympic Committee said that the Olympic Winter Games 2030 will be held in Tomsk. The city officials decided to prepare for the Olympics thoroughly and to build all the necessary Olympic facilities as e...
```python import sys range = xrange input = raw_input inp = map(int, sys.stdin.read().split()) ii = 0 n = inp[ii] ii += 1 m = inp[ii] ii += 1 t = inp[ii] ii += 1 tp,tu,td = inp[ii:ii+3] ii += 3 T = [tp, tu, td] A = [] for _ in range(n): A.append(inp[ii:ii+m]) ii += m D = [[0]*m for _ in range(n - 1)] ...
vfc_68933
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 7 48\n3 6 2\n5 4 8 3 3 7 9\n4 1 6 8 7 1 1\n1 6 4 6 4 8 6\n7 2 6 1 6 9 4\n1 9 8 6 3 9 2\n4 5 6 8 4 3 7", "output": "1 1 4 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 10\n1 3 2\n...
code_contests
verifiable_code
470_A. Crystal Ball Sequence
Solve the following coding problem using the programming language python: Crystal ball sequence on hexagonal lattice is defined as follows: n-th element is the number of lattice points inside a hexagon with (n + 1) points on each side. The formula is Hn = 3·n·(n + 1) + 1. You are given n; calculate n-th element of the...
vfc_68941
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "37\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
493_D. Vasya and Chess
Solve the following coding problem using the programming language python: Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on t...
```python n = int(input()) if n & 1 == 0: print('white\n1 2') else: print('black') ```
vfc_68945
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "black\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "white\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
544_C. Writing Code
Solve the following coding problem using the programming language python: Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes. Let's call a sequence...
```python a = list(map(int, input().split())) n = a[0] m = a[1] b = a[2] mod = a[3] ac = list(map(int,input().split())) ac = [0] + ac dp = [[[0 for k in range(b+1)] for _ in range(m+1)] for z in range(2)] for i in range(n+1) : for x in range(b+1) : dp[i%2][0][x] = 1 for i in range(1,n+1) : for...
vfc_68953
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6 5 1000000007\n1 2 3\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
570_E. Pig and Palindromes
Solve the following coding problem using the programming language python: Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of n rows and m columns. We enumerate the rows of the rectangle from top to bottom with numbers from 1 to n, an...
vfc_68957
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\naaab\nbaaa\nabba\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\nab\nab\ncc\nba\nba\n", "output": "1\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
592_C. The Big Race
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 alway...
```python from sys import stdin import math # stdin = open('in.txt') # t, w, b = map(int, stdin.readline().split()) t, w, b = map(int, input().split()) d = math.gcd(w, b) l = (w*b)//d add = min(w, b) ans = add*(t//l) m = t%l ans += min(add, m+1) ans -= 1 d = math.gcd(ans, t) ans //= d t //= d print(ans, '/', t, sep...
vfc_68961
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3 2\n", "output": "3/10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
614_A. Link/Cut Tree
Solve the following coding problem using the programming language python: Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure. Unfortunately, Rostislav is unable to understand the definition of this pro...
```python #from math import pow def pow(num, n): ans = 1 while n>0: ans*=num n-=1 return ans l,r,k = map(int, input().split()) i = 0; while (pow(k,i)<l): i+=1 count = 0 a = [] while (l<=pow(k,i)<=r): a.append(int(pow(k,i))) count += 1 i+=1 if count == 0: print(-1) e...
vfc_68965
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 10 2\n", "output": "1\n2\n4\n8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
662_A. Gambling Nim
Solve the following coding problem using the programming language python: As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initially contains ai stones. Two players alternate the turns. During a turn a player picks any non-empty pile and removes any positive number of stones from it...
vfc_68973
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2\n1 2\n", "output": "1/2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
686_D. Kay and Snowflake
Solve the following coding problem using the programming language python: After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) c...
```python n, q = map(int, raw_input().split(' ')) p_arr = map(lambda x:int(x) - 1, raw_input().split(' ')) p_arr = [-1] + p_arr for i in p_arr[1:]: i += 1 pe_arr = [0 for i in xrange(n)] s_arr = [1 for i in xrange(n)] mx_arr = [-1 for i in xrange(n)] z_arr = [i for i in xrange(n)] for i in p_arr: if i > 0: pe_a...
vfc_68977
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4\n1 1 3 3 5 3\n1\n2\n3\n5\n", "output": "3\n2\n3\n6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
709_C. Letters Cyclic Shift
Solve the following coding problem using the programming language python: You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each cha...
```python s=input() l=len(s) a1=a2=1000000 q=[] k=0 b='' j=0 if 'a' in s: for i in s: if i=='a': if len(q)>0 and j-q[-1]>1: q.append(j) k=j break q.append(j) j+=1 if len(q)==l: print('a'*(l-1)+'z') exit() ...
vfc_68981
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "codeforces\n", "output": "bncdenqbdr\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacaba\n", "output": "aaacaba\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
730_E. Award Ceremony
Solve the following coding problem using the programming language python: All-Berland programming contest comes to an end. In total, n teams participated in it. Like in ACM-ICPC, current results stopped refreshing one hour before the contest ends. So at the Award Ceremony, results are partially known. For each team th...
vfc_68985
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 5\n3 2\n5 -3\n6 -2\n4 3\n", "output": "14\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
753_C. Interactive Bulls and Cows (Hard)
Solve the following coding problem using the programming language python: The only difference from the previous problem is the constraint on the number of requests. In this problem your program should guess the answer doing at most 7 requests. This problem is a little bit unusual. Here you are to implement an interac...
vfc_68989
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n", "output": "8000\n0179\n3159\n3210\n0112\n0123", "type": "stdin_stdout" }, { "fn_name": null, "input": "9876\n", "output": "0123\n0000\n", "type": "stdin_s...
code_contests
verifiable_code
774_I. Composing Of String
Solve the following coding problem using the programming language python: Stepan has a set of n strings. Also, he has a favorite string s. Stepan wants to do the following. He will take some strings of his set and write them down one after another. It is possible that he will take some strings more than once, and wi...
vfc_68993
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\na\naa\na\naaa\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nab\naab\naa\nbb\nbaaab\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
79_B. Colorful Field
Solve the following coding problem using the programming language python: Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefu...
```python n,m,k,t=map(int,input().split(" ")) field=[] for _ in range(k): a,b=map(int,input().split(" ")) field.append( (a-1)*m+(b-1) ) field.sort() #print("field=",field) dic={0:"Carrots",1:"Kiwis",2:"Grapes"} for _ in range(t): flag=0 x,y=map(int,input().split(" ")) value=(x-1)*m+(y-1) for...
vfc_68997
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n", "output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 1 3\n2 2\n...
code_contests
verifiable_code
845_G. Shortest Path Problem?
Solve the following coding problem using the programming language python: You are given an undirected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor t...
vfc_69005
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 1 3\n1 2 3\n", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
867_B. Save the problem!
Solve the following coding problem using the programming language python: Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original pro...
```python a = int(input()) n = 2*(a-1)+1 m = 2 print(n, m) print(1, 2) ```
vfc_69009
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "4 2\n1 2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
892_D. Gluttony
Solve the following coding problem using the programming language python: You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x1, x2, ..., xk} (1 ≤ xi ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different,...
```python n = int(input()) a = list(map(int, input().split())) sorted_a = sorted(a) shifted_sorted_a = [sorted_a[-1]] + sorted_a[:-1] #print(sorted_a) #print(shifted_sorted_a) for i in range(len(a)): pos_in_sorted = sorted_a.index(a[i]) print(shifted_sorted_a[pos_in_sorted], end=" ") print() ```
vfc_69013
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1000 100 10 1\n", "output": "1 1000 100 10 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
914_D. Bash and a Tough Math Puzzle
Solve the following coding problem using the programming language python: Bash likes playing with arrays. He has an array a1, a2, ... an of n integers. He likes to guess the greatest common divisor (gcd) of different segments of the array. Of course, sometimes the guess is not correct. However, Bash will be satisfied ...
```python #!/usr/bin/env python3 import os import sys from atexit import register from io import StringIO from math import gcd sys.stdin = StringIO(os.read(0, os.fstat(0).st_size).decode()) sys.stdout = StringIO() register(lambda: os.write(1, sys.stdout.getvalue().encode())) input = lambda: sys.stdin.readline().rstri...
vfc_69017
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 6 3\n4\n1 1 2 2\n1 1 3 3\n2 1 9\n1 1 3 2\n", "output": "YES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 5\n6\n1 1 4 2\n2 3 6\n1 1 4 2\n1 1 5 2\n2 5 10\n1 1 5 2...
code_contests
verifiable_code
937_B. Vile Grasshoppers
Solve the following coding problem using the programming language python: The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are oc...
```python p,y = map(int,input().split()) for x in range(y,p,-1): # print(x) # check flag = True for i in range(2,min(p,int(x**0.5))+1): if x%i == 0: flag = False break if flag: print(x) exit() print(-1) ```
vfc_69021
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 9\n"...
code_contests
verifiable_code
962_D. Merge Equals
Solve the following coding problem using the programming language python: You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value x that occurs in the array 2 or more times. Take the first two occurrences of x in th...
```python n = int(input()) d = {} for i, x in enumerate(map(int, input().split())): while x in d: del d[x] x *= 2 d[x] = i print(len(d)) print(*d) ```
vfc_69025
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n3 4 1 2 2 1 1\n", "output": "4\n3 8 2 1 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
98_E. Help Shrek and Donkey
Solve the following coding problem using the programming language python: Shrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds m cards and the Donkey holds n cards (the players do not see each other's...
vfc_69029
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 0\n", "output": "1.0000000000 0.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "0.5000000000 0.5000000000\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
aniruddhas-queue-4
Solve the following coding problem using the programming language python: Aniruddha is given a milestone M to reach in terms of distance. He is living in a different Galaxy where there are N days in a year.At the ith day he can walk atmost X distance.Assuming he walks optimally you need to output the minimum day numbe...
```python for _ in range(int(raw_input())): n = int(raw_input()) arr = map(int, list(raw_input().split())) sum1 = sum(arr) tar = int(raw_input()) tar = tar%sum1 if tar == 0: for i in xrange(n-1,-1,-1): if arr[i] != 0: print i+1 break else: cur = 0 for i in range(n): if arr[i] > 0: cur +=...
vfc_69033
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n1 5 0 0 2\n9\n3\n1 0 3\n2\n\nSAMPLE", "output": "1\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chandler-and-joey
Solve the following coding problem using the programming language python: Chandler and Joey Joey and Chandler got bored of playing foosball, so they thought of trying something new.As Joey is very intelligent so he invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. An...
```python def gcd(a, b): if b == 0: return a return gcd(b, a%b) t = input() for _ in range(t): n = input() ar = map(int,raw_input().split()) m = max(ar) su = sum(ar) g = 0 for i in ar: g = gcd(i,g) c = (m / g) - n l = m/g su1 = (l*(2*g+g*(l-1)))/2 if c%2 == 0: print "Chandler",(su1-su) else: print...
vfc_69037
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n1 2\n2\n5 3\n\nSAMPLE", "output": "Chandler 0\nJoey 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n100\n84855875 84874301 84862168 84882334 84875003 84871558 84867312 84885192 8...
code_contests
verifiable_code
digit
Solve the following coding problem using the programming language python: This problem is as simple as short. Just find how many numbers from A to B with sum of digits from X to Y are divisible by K. Input The first line contains 5 space-separated positive integers: A, B, X, Y, K Output Output one number - answer ...
```python A, B, X, Y, K=map(int,raw_input().split()) def digsum(x): r=0 while x>0: r+=x%10 x/=10 return r #return sum(map(int,str(x))) def simpleCount(l,r): if r<=l: return 0 cnt=0 incr=0 if l%K: incr=K-l%K for x in xrange(l+incr,r,K): s=digsum(x) if X<=s<=Y:cnt+=1 return cnt if K>1.e5 or B-A<=20...
vfc_69041
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 86 1 6 4\n\nSAMPLE", "output": "6", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
get-time-in-words-now-1
Solve the following coding problem using the programming language python: Given the time in numerals we may convert it into words, as shown below: 5:00→ five o' clock 5:01→ one minute past five 5:10→ ten minutes past five 5:30→ half past five 5:40→ twenty minutes to six 5:45→ quarter to six 5:47→ thirteen minut...
```python h=int(raw_input()) m=int(raw_input()) H={0:"Twelve",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve"} M={1:"one minute",2:"two minutes",3:"three minutes",4:"four minutes",5:"five minutes",6:"six minutes",7:"seven minutes",8:"eight minutes",9:"ni...
vfc_69045
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 \n47\n\nSAMPLE", "output": "thirteen minutes to six\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 \n47\n\nSAMPME", "output": "thirteen minutes to six\n", "type": "stdin...
code_contests
verifiable_code
lets-play
Solve the following coding problem using the programming language python: Game is played on the field of the size 1 x N cells. The cells are numbered from 1 to N. In the i-th cell there are 2 positive integers - Ai and Bi. Initially, the player stands at the fictive cell with the index 0 that is located right before ...
```python rr = raw_input; rrM = lambda: map(int,rr().split()) N,K = rrM() A = [rrM() for i in xrange(N)] from math import log10 as log B = map(lambda x: map(log,x), A) cache = {} def dp(x,a,b): if x == N+1: return (a,b) if (x,a,b) not in cache: ans = 99999999 mem = 0 if x+K >= N+1: cache[(x,a,b)] = (a,b) el...
vfc_69049
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n4 8\n5 9\n12 23\n1 6\n\nSAMPLE", "output": "32", "type": "stdin_stdout" }, { "fn_name": null, "input": "80 3\n1 5\n2 4\n3 3\n4 2\n5 1\n3 3\n4 2\n1 5\n2 4\n3 3\n4 2\n12 45\n23 56\n1 5\n5 1\n3 3\n...
code_contests
verifiable_code
monk-in-the-real-estate
Solve the following coding problem using the programming language python: The Monk wants to buy some cities. To buy two cities, he needs to buy the road connecting those two cities. Now, you are given a list of roads, bought by the Monk. You need to tell how many cities did the Monk buy. Input: First line contains an...
```python test=int(input()) visited=[False for i in range(10001)] for t in range(test): e=int(input()) visited=[False for i in range(10001)] for i in range(e): x,y=map(int,raw_input().split()) visited[x]=True visited[y]=True c=0 for i in range(10001): if(visited[i]): ...
vfc_69053
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n1 2\n2 3\n1 3\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3\n1 2\n2 3\n1 3", "output": "3\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
place-value-and-primes
Solve the following coding problem using the programming language python: Darshak (Dark) was learning about numerals in words and he came across representation of "6743294" as shown below .tg {border-collapse:collapse;border-spacing:0;} .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def isprime(a): i=2 while i*i<=a: if a%i==0: return False i+=1 return True primes=[1] cnt=0 i=2 while cnt<=99: if isprime(i): primes.append(i) cnt+=1 i+=1 t=i...
vfc_69057
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1005 0 2\n7347 3 1\n7777 7 4\n\nSAMPLE", "output": "1\n5\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6700\n3 3 1\n6 6 1\n12 1 1\n18 1 1\n24 2 1\n30 3 1\n36 3 1\n42 4 1\n48 4 1\n5...
code_contests
verifiable_code
roy-and-texting-robot-2
Solve the following coding problem using the programming language python: Roy frequently needs to use his old Nokia cell phone for texting whose keypad looks exactly as shown below. You may be already familiar with the working of the keypad, however if you're not we shall see a few examples. To type "b", we need...
```python lst = (('_', '0'), ('.', ',', '?', '!', '1'), ('a', 'b', 'c', '2'), ('d', 'e', 'f', '3'), ('g', 'h', 'i', '4'), ('j', 'k', 'l', '5'), ('m', 'n', 'o', '6'), ('p', 'q', 'r', 's', '7'), ('t', 'u', 'v', '8'), ('w', 'x', 'y', 'z', '9'), ) def calculateSec(strng): previousK...
vfc_69061
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nhack\n5!\ni_?_uSAMPLE", "output": "11\n10\n15\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
substring
Solve the following coding problem using the programming language python: Maggu has just joined play school. His teacher taught him A,a,B,b,C,c. He is much fascinated with these letters and now he is looking only for those strings which contains these letters only. But as i said he is a little guy he cant calculate t...
```python t=int(input()) while t: t-=1 s=raw_input() l=len(s) c=0 h=0 for i in range(0,l): if s[i]=='A' or s[i]=='a' or s[i]=='B' or s[i]=='b' or s[i]=='C' or s[i]=='c': h=h+1 else: if h!=0: c=c+((h*(h+1)/2)) h=0 if h!=0: c=c+((h*(h+1)/2)) print c ```
vfc_69065
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nAXa\nABC\nAXBC\nAaBbCc\nXxYyZz\n\nSAMPLE", "output": "2\n6\n4\n21\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nAXa\nCBA\nAXBC\nAaBbCc\nXxYyZz\n\nSAMPLE", "output": "2\n6\...
code_contests
verifiable_code
p00030 Sum of Integers
Solve the following coding problem using the programming language python: Write a program that extracts n different numbers from the numbers 0 to 9 and outputs the number of combinations that add up to s. Each n number is from 0 to 9, and the same number cannot be used in one combination. For example, if n is 3 and s ...
```python def dfs(depth,prev,sum): if depth == n: return sum == s ret = 0 for i in range(prev + 1,10): ret += dfs(depth + 1,i,sum + i) return ret while True: n,s = map(int,input().split()) if n == 0: break print(dfs(0,-1,0)) ```
vfc_69113
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6\n3 1\n0 0", "output": "3\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n3 1\n0 0", "output": "2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00161 Sport Meet
Solve the following coding problem using the programming language python: An autumn sports festival is held. There are four events: foot race, ball-carrying, obstacle race, and relay. There are n teams participating, and we would like to commend the team with the shortest total time in this 4th event as the "winner", ...
```python # -*- coding: utf-8 -*- import sys import os for s in sys.stdin: N = int(s) if N == 0: break A = [] for i in range(N): lst = list(map(int, input().split())) id = lst[0] data = lst[1:] time_sum = data[0] * 60 + data[1] + \ data[2] * ...
vfc_69117
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n34001 3 20 3 8 6 27 2 25\n20941 3 5 2 41 7 19 2 42\n90585 4 8 3 12 6 46 2 34\n92201 3 28 2 47 6 37 2 58\n10001 3 50 2 42 7 12 2 54\n63812 4 11 3 11 6 53 2 22\n54092 3 33 2 54 6 18 2 19\n25012 3 44 2 58 6 45 2 46\n4\n1 3 23 1 23 ...
code_contests
verifiable_code
p00488 Lunch
Solve the following coding problem using the programming language python: problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price ...
```python pasta = [int(input()) for i in range(3)] juice = [int(input()) for j in range(2)] print(min(pasta) + min(juice) - 50) ```
vfc_69125
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "800\n700\n900\n198\n330", "output": "848", "type": "stdin_stdout" }, { "fn_name": null, "input": "800\n1126\n900\n198\n330", "output": "948\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
p00674 Strawberry Cake
Solve the following coding problem using the programming language python: Sha, Nero, Eri, and Ko, who entered the University of Aizu Elementary School (Aizu University and Small), decided to participate in a programming contest called IPPC in order to play an active role as a competition programmer. However, IPPCs are...
vfc_69129
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n-100 -100\n100 -100\n100 100\n-100 100\n4\n-99 -100\n100 -100\n100 100\n-99 100\n4\n-100 -99\n100 -99\n100 100\n-100 100\n14\n-99 -70\n-92 -79\n10 -98\n37 -100\n62 -95\n77 -69\n88 -47\n92 -10\n96 28\n100 91\n42 92\n-62 92\n-88 9...
code_contests
verifiable_code
p00817 True Liars
Solve the following coding problem using the programming language python: After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had h...
```python from collections import defaultdict class UnionFind(): def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) ret...
vfc_69133
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1\n1 2 no\n2 1 no\n3 2 1\n1 1 yes\n2 2 yes\n3 3 yes\n2 2 1\n1 2 yes\n2 3 no\n5 4 3\n1 2 yes\n1 3 no\n4 5 yes\n5 6 yes\n6 7 no\n0 0 0", "output": "no\nno\n1\n2\nend\n3\n4\n5\n6\nend", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p00948 Distribution Center
Solve the following coding problem using the programming language python: Example Input 4 3 1000 1 2000 2 3000 3 Output 2 3 4 4 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python N,M = map(int,input().split()) XY = [] for _ in range(M): x,y = map(int,input().split()) xy = (x,y) XY.append(xy) XY.sort(key = lambda x:x[0]) # x sort *minY, = range(N) *maxY, = range(N) for _,y in XY: y0,y1 = y-1, y minY[y1] = minY[y0] maxY[y0] = maxY[y1] ans = [maxY[i] - minY[i]...
vfc_69137
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n1000 1\n2000 2\n3000 3", "output": "2 3 4 4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01217 Jaggie Spheres
Solve the following coding problem using the programming language python: Let J(n) be a three-dimensional body that * is a union of unit cubes whose all vertices lie on integer coordinates, * contains all points that are closer than the distance of √n to the origin, and * is the smallest of all such bodies. The fi...
vfc_69145
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n3\n4\n0", "output": "6\n30\n30\n6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n6\n4\n0", "output": "6\n30\n102\n6\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
p01351 Usagitobi
Solve the following coding problem using the programming language python: There is a board of m × n squares. The squares of i rows and j columns are represented by (i, j) (0 ≤ i <m, 0 ≤ j <n). When the rabbit is at (x, y), it can jump to ((x + a) mod m, (y + b) mod n) or ((x + c) mod m, (y + d) mod n) it can. Now th...
vfc_69149
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6 2 2 2 4", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 6 2 2 2 4", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01533 Acrophobia
Solve the following coding problem using the programming language python: C: Acrophobia Yayoi Takasugi is a super-selling idol. There is one thing she is not good at. It's a high place ... She is extremely afraid of heights. This time, due to the producer's inadequacy, she decided to take on the following challenges ...
```python from itertools import permutations from collections import deque w, h = map(int, input().split()) mp = ["X" * (w + 4)] * 2 + ["XX" + input() + "XX" for _ in range(h)] + ["X" * (w + 4)] * 2 m_lst = [] holes = [] for y in range(2, h + 2): for x in range(2, w + 2): if mp[y][x] == "S": sx, sy = x, y ...
vfc_69153
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\nS.M\n...\n...\nM.G", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\nM.S\n...\n...\nM.G", "output": "7\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
p01833 Modern Announce Network
Solve the following coding problem using the programming language python: Example Input 4 2 1 1 1 2 3 4 3 1 2 2 4 3 4 Output 2 1 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python import sys readline = sys.stdin.readline write = sys.stdout.write from collections import deque INF = 10**9 def bfs(N, G, s): dist = [INF]*N *lb, = range(N) dist[s] = 0 que = deque([s]) while que: v = que.popleft() d = dist[v] + 1 l = lb[v] for w in G[v]: ...
vfc_69161
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 1 1\n1 2\n3\n4\n3\n1 2\n2 4\n3 4", "output": "2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 1 1\n1 2\n3\n4\n3\n1 4\n2 4\n3 4", "output": "2 1\n", "type": "stdin_std...
code_contests
verifiable_code
p01968 Hierarchical Calculator
Solve the following coding problem using the programming language python: B: 階層的計算機 (Hierarchical Calculator) Problem Ebi-chan has N formulae: y = a_i x for i =1, ..., N (inclusive). Now she considers a subsequence of indices with length k: s_1, s_2, ..., s_k. At first, let x_0 be 1 and evaluate s_1-th formulae with...
```python # -*- coding: utf-8 -*- from collections import Counter def inpl(): return tuple(map(int, input().split())) N = int(input()) A = list(map(int, input().split())) C = Counter(A) if C[-2] % 2 == 0: ans = [i+1 for i, a in enumerate(A) if abs(a) == 2] print(len(ans)) if len(ans): print(*ans, ...
vfc_69165
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 0 -2 1", "output": "1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 -1 -2 1", "output": "3\n1\n2\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02255 Insertion Sort
Solve the following coding problem using the programming language python: Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ ...
```python n = int(input()) a = list(map(int, input().split())) print(*a, sep=' ') for i in range(1, n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] a[j] = v j -= 1 print(*a, sep=' ') ```
vfc_69173
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3", "output": "1 2 3\n1 2 3\n1 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n5 2 4 6 1 3", "output": "5 2 4 6 1 3\n2 5 4 6 1 3\n2 4 5 6 1 3\n2 4 5 6 1 3\n1 2 4 5 6 3\n1...
code_contests
verifiable_code
p02403 Print a Rectangle
Solve the following coding problem using the programming language python: Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'. Constraints * 1 ≤ H ≤ 300 * 1 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated...
```python while True: H,W = map(int,input().split()) if H == 0 and W == 0: exit() for i in range(H): print("#"*W) print() ```
vfc_69177
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n5 6\n2 2\n0 0", "output": "####\n####\n####\n\n######\n######\n######\n######\n######\n\n##\n##", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
amr15a
Solve the following coding problem using the programming language python: Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army-chief), and the reason for that was their really powerful army, also called as Mahasena. Kattapa was kno...
```python # Mahasena # Problem code: AMR15A # https://www.codechef.com/problems/AMR15A t=int(raw_input()) a=[] a=map(int,raw_input().split()) even=int(0) odd=int(0) for i in a: if i%2==0: even+=1 else: odd+=1 if even>odd: print("READY FOR BATTLE") else: print("NOT READY") ```
vfc_69181
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5", "output": "NOT READY\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 0 5", "output": "NOT READY\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
chfbooks
Solve the following coding problem using the programming language python: The chef has a book stand. He and his friend bought some books (say n). The book stand has only 2 empty shelves. The chef made an observation that the paper quality, the weight of a single paper and the dimensions of all the books are the same. ...
```python t=int(raw_input()) for ad in range(t): n,m=map(int,raw_input().split()) a=map(int,raw_input().split()) a=sorted(a) u_list=a[:m] d_list=a[m:] print sum(d_list)-sum(u_list) ```
vfc_69185
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 2\n4 1 3 2 5", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5 2\n4 1 2 2 5", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
egbobrd
Solve the following coding problem using the programming language python: Some chefs go for a tour lasting N days. They take packages of bread for food. Each package has K pieces of breads. On the i^th day, they eat Ai pieces of bread. Unfortunately, chefs are very lazy people, and they always forget to close the pack...
```python # your code goes here import math t=int(raw_input()) for i in range(t): temp=raw_input().split() days=int(temp[0]) capacity=int(temp[1]) required=raw_input().split() required=map(int,required) left=0 packages_consumed=0 for day in range(days): flag=0 pack=0 ...
vfc_69189
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 4\n3 1 2\n1 1\n1\n2 4\n8 8", "output": "2\n1\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 4\n3 1 2\n1 1\n1\n2 4\n8 1", "output": "2\n1\n3\n", "type": "stdin_std...
code_contests
verifiable_code
kgp14b
Solve the following coding problem using the programming language python: A DNA sequence can be represented by a string of letters T, A, C, and G representing four different amino acids. DNA sequences are often matched to infer structural or functional similarities between living beings. Given two DNA sequences X and ...
```python for num in range(input()): # n =input() p,q = map(int,raw_input().split()) arr1 = list(raw_input()) arr2 = list(raw_input()) dp=[[0 for i in range(q+1)] for i in range(p+1)] for i in range(1,p+1): for j in range(1,q+1): if arr1[i-1]==arr2[j-1]: dp[i][j] += (1+ dp[i-1][j-1]) else: dp[i][...
vfc_69193
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7 6\nTAGCTAG\nATCATG\n10 9\nGGATGCTACA\nTCTACCGTA", "output": "Case 1: 9\nCase 2: 13", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
oneking
Solve the following coding problem using the programming language python: N one dimensional kingdoms are represented as intervals of the form [ai , bi] on the real line. A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L ≤ x ≤ R. Your task is to determine mi...
```python t=input() def lsort(l,n): #therefore total order=O(n+2001) :) c=[0 for x in range(2001)] #O(2001) for x in l:c[x[0]]+=1 #O(n) for i in range(1,2001):c[i]+=c[i-1] #O(2001) b=[None for x in range(n)] #O(n) for i in range(n): #O(n) b[c[l[i][0]]-1]=l[i] c[l[i][0]]-=1 return b for...
vfc_69197
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n1 3\n2 5\n6 9", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3\n1 3\n0 5\n6 9", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
spcandy
Solve the following coding problem using the programming language python: Cyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests. Then, if they get good marks she will reward them with candies :) ...
```python T = int(raw_input()) while T: N,K = map(int,raw_input().split()) if K == 0: print K,N else: print N / K , N % K T -= 1 ```
vfc_69201
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 2\n100 3", "output": "5 0\n33 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 2\n101 3", "output": "5 0\n33 2\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
1005_E2. Median on Segments (General Case Edition)
Solve the following coding problem using the programming language python: You are given an integer sequence a_1, a_2, ..., a_n. Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of median of a_l, a_{l+1}, ..., a_r is exactly the given number m. The median of a sequence is the value of an...
```python def cv(r, n, d): s = [0]*(2*n + 1) q = n ans = 0 s[q] = 1 z = 0 for i in range(n): if d[i] < r: q -= 1 z -= s[q] else: z += s[q] q += 1 ans += z s[q] += 1 return ans n, r = map(int,input().split()) d =...
vfc_69205
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15 2\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3\n", "output": "97\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 4 5 60 4\n", "output": "8\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1029_D. Concatenated Multiples
Solve the following coding problem using the programming language python: You are given an array a, consisting of n positive integers. Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenat...
```python import os import sys from io import BytesIO, IOBase # import string # characters = string.ascii_lowercase # digits = string.digits # sys.setrecursionlimit(int(1e6)) # dir = [-1,0,1,0,-1] # moves = 'NESW' inf = float('inf') from functools import cmp_to_key from collections import defaultdict as dd from collec...
vfc_69209
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n3 7 19 3 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 11\n45 1 10 12 11 7\n", "output": "7", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1071_D. Familiar Operations
Solve the following coding problem using the programming language python: You are given two positive integers a and b. There are two possible operations: 1. multiply one of the numbers by some prime p; 2. divide one of the numbers on its prime factor p. What is the minimum number of operations required to o...
vfc_69217
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n9 10\n100 17\n220 70\n17 19\n4 18\n32 20\n100 32\n224 385\n", "output": "1\n3\n1\n0\n1\n0\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n9 10\n100 17\n220 70\n17 19\n4 18\n32 ...
code_contests
verifiable_code
1113_F. Sasha and Interesting Fact from Graph Theory
Solve the following coding problem using the programming language python: Once, during a lesson, Sasha got bored and decided to talk with his friends. Suddenly, he saw Kefa. Since we can talk endlessly about Kefa, we won't even start doing that. The conversation turned to graphs. Kefa promised Sasha to tell him about ...
vfc_69225
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1 1 2\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1142_A. The Beatles
Solve the following coding problem using the programming language python: Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through n ⋅ k cities. The cities are numerated from 1 to n ⋅ k, the distance between the neighboring cities is exactly 1 km. Sergey does not like beetles, ...
```python from math import gcd def lcm(a,b): return a*b//gcd(a,b) def mod(a,m): a%=m if a<0: a+=m return a n,k=map(int, input().split()) a,b=map(int, input().split()) st,ed=[],[] nk=n*k for i in range(0,n): st.append(mod(i*k-a,nk)) st.append(mod(i*k+a,nk)) ed.append(mod(i*k-b,nk)) ed.append(mod(i*k+b,nk))...
vfc_69229
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n0 0\n", "output": "1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n1 1\n", "output": "1 6\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
1162_C. Hide and Seek
Solve the following coding problem using the programming language python: Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent. Alice initially has a token on some cell on the line, and Bob tries to guess where it i...
```python def main(): n, k = map(int, input().split()) x = [int(i) for i in input().split()] ans = 3 * n - 2 a, b = set(), set() for val in x: if val - 1 in a: b.add((val, val - 1)) if val + 1 in a: b.add((val, val + 1)) a.add(val) ans -= len(a) +...
vfc_69233
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 8\n1 2 3 4 4 3 2 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 1\n42\n", "output": "299997\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
1183_B. Equalize Prices
Solve the following coding problem using the programming language python: There are n products in the shop. The price of the i-th product is a_i. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly. In fact, the owner of the shop can change the price of some...
```python q = int(input()) for qq in range(q): n, k = map(int, input().split()) *a, = map(int, input().split()) m = 0 M = 1e9 for x in a: M = min(M, x + k) m = max(m, x - k) if M >= m: print(M) else: print(-1) ```
vfc_69237
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5\n", "output": "2\n6\n-1\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 100000000\n100000000 100000000 100000000\n", "ou...
code_contests
verifiable_code
1200_C. Round Corridor
Solve the following coding problem using the programming language python: Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by n sectors, and the outer area is equally divided by m sectors. A wall exists between each pair of sectors of same area (inner or o...
```python n,m,q = map(int,input().split()) s = [] for i in range(q): s.append(list(map(int,input().split()))) def gcd(a,b): if a == 0: return b return gcd(b % a, a) def lcm(a,b): return (a // gcd(a,b))*b g = lcm(n,m) a,b = g//m,g//n for i in s: s1,e1,s2,e2 = i if s1==1: s...
vfc_69241
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6 3\n1 1 2 3\n2 6 1 2\n2 6 2 4\n", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "999999937 999999874000003969 1\n1 979917353 2 983249032983207370\n", "out...
code_contests
verifiable_code
1218_E. Product Tuples
Solve the following coding problem using the programming language python: While roaming the mystic areas of Stonefalls, in order to drop legendary loot, an adventurer was given a quest as follows. He was given an array A = {a_1,a_2,...,a_N } of length N, and a number K. Define array B as B(q, A) = { q-a_1, q-a_2, .....
vfc_69245
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 128000000, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2\n1 2 3 4 5\n3\n1 6 1 1\n1 6 5 2\n2 6 2 3 1\n", "output": "85\n127\n63\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n6\n212221387 239600606 92798741 372997949 181052269 40874550 9...
code_contests
verifiable_code
1242_B. 0-1 MST
Solve the following coding problem using the programming language python: Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph. It is an undirected weighted ...
```python import collections as cc import sys input=sys.stdin.readline #sys.setrecursionlimit(10**9) I=lambda:list(map(int,input().split())) n,m=I() g=[set() for i in range(n+1)] xx=[0]*(n+1) for i in range(m): x,y=I() g[x].add(y) g[y].add(x) parent=[i for i in range(n+1)] def find(x): while x!=parent[x]: x=paren...
vfc_69249
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 11\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n", "output": "0\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1261_B2. Optimal Subsequences (Hard Version)
Solve the following coding problem using the programming language python: This is the harder version of the problem. In this version, 1 ≤ n, m ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a_2,....
```python from bisect import bisect_left, bisect_right, insort_right class SquareSkipList: def __init__(self, values=None, sorted_=False, square=1000, seed=42): inf = float("inf") self.square = square if values is None: self.rand_y = seed self.layer1 = [inf] ...
vfc_69253
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "output": "2\n3\n2\n3\n2\n3\n1\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1...
code_contests
verifiable_code
1283_D. Christmas Trees
Solve the following coding problem using the programming language python: There are n Christmas trees on an infinite number line. The i-th tree grows at the position x_i. All x_i are guaranteed to be distinct. Each integer point can be either occupied by the Christmas tree, by the human or not occupied at all. Non-in...
```python import heapq n,m = map(int,input().split()) x = sorted(map(int,input().split())) # (distance, position, direction, maxval) pos = [(1,x[0]-1,-1,m), (1,x[-1]+1,1,m)] for i in range(n-1): left = (x[i+1]-x[i])//2 right = (x[i+1]-x[i]-1)//2 if left: pos.append((1,x[i]+1,1,left)) if right:...
vfc_69257
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n0 3 1\n", "output": "7\n-1 2 4 -2 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 6\n1 5\n", "output": "8\n0 2 4 6 -1 3 ", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
1302_J. Keep talking and nobody explodes – hard
Solve the following coding problem using the programming language python: This is an unusual problem in an unusual contest, here is the announcement: [http://codeforces.com/blog/entry/73543](//codeforces.com/blog/entry/73543) You have the safe lock which consists of 100 decimal digits. If you rotate some digit, it in...
vfc_69261
{ "difficulty": "16", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "\n9700010006000300020000111706617034943099970012861000908700093104145749080706326060507070104603727696\n", ...
code_contests
verifiable_code
1327_A. Sum of Odd Integers
Solve the following coding problem using the programming language python: You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not. You have to answer t independent test cases. Input The first line of the input contains...
```python import collections class Solution: def solve(self, n, k): isKOdd = k & 1 isNOdd = n & 1 if isKOdd ^ isNOdd: return False return k**2 <= n sol = Solution() t = int(input().strip()) # [n,m] = list(map(int, input().strip().split())) for i in range(t): ...
vfc_69265
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10000000 9999998\n", "output": "NO\n", "type": ...
code_contests
verifiable_code
1368_A. C+=
Solve the following coding problem using the programming language python: Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = 2, b = 3 changes ...
```python t=int(input()) c=[] for i in range(t): a,b,n=input().split() a,b,n=int(a),int(b),int(n) count=0 while True: if a<b: a=a+b else: b=a+b count+=1 if max(a,b)>n: break c.append(count) for j in c: print(j) ```
vfc_69273
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2 3\n5 4 100\n", "output": "2\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "16\n1 1 1\n3 4 7\n4 5 13\n456 123 7890123\n1 1 1000000000\n45 12 782595420\n1 1000000000 1000000000\n1...