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
203_A. Two Problems
Solve the following coding problem using the programming language python: A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to ...
```python x, t, a, b, da, db = (int(q) for q in input().split()) if (x in (a - da * i + b - db * j for i in range(t) for j in range(t)) or (a >= x and (a - x) % da == 0 and (a - x) // da < t) or (b >= x and (b - x) % db == 0 and (b - x) // db < t) or x == 0): print('YES') else: print('NO') ```
vfc_76809
{ "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": "10 4 100 5 5 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 5 20 20 3 5\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
227_E. Anniversary
Solve the following coding problem using the programming language python: There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations. Dima is sure that it'll be great to learn to solve the f...
```python #coding=utf-8 def recfib(n,m): if n==0: return (0,1,) a, b = recfib(n / 2,m) return ((b*b+a*a)%m, b*(2*a+b)%m) if n%2 else (a*((2*b)-a)%m, ((b*b+a*a))%m) m,l,r,k=map(int,raw_input().split()) #print recfib(small,m)[0] #print recfib(big,m)[0] n = (r-l)/(k-1) while n >= 0 and r/n - (l-1)/n < k: ...
vfc_76813
{ "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": "10 1 8 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1 8 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
251_C. Number Transformation
Solve the following coding problem using the programming language python: Little Petya likes positive integers a lot. Recently his mom has presented him a positive integer a. There's only one thing Petya likes more than numbers: playing with little Masha. It turned out that Masha already has a positive integer b. Pety...
vfc_76817
{ "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": "6 3 10\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
276_D. Little Girl and Maximum XOR
Solve the following coding problem using the programming language python: A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value...
```python def bin(a): if a <= 1: return a else: return 10*bin(a//2)+a%2 def convBin(a): k,i = 0,0 while a!=0: k += (a%10)*int((2**i)) a //= 10 i += 1 return k def maxi(a,b): if a == b: return 0 elif a+1 == b: return a^b elif a+2 =...
vfc_76821
{ "difficulty": "10", "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 16\n", "output": "31\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
29_A. Spit Problem
Solve the following coding problem using the programming language python: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there...
```python n=int(input()) a1=[] a2=[] for i in range(n): x,d=list(map(int,input().split())) a1.append(x) a2.append(d) flag=1 for i in range(n): for j in range(i+1,n): if ((a1[i]+a2[i]==a1[j]) and (a1[j]+a2[j]==a1[i])): print("YES") flag=0 break if(flag==0): break if(flag==1): print("NO") ```
vfc_76825
{ "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 -10\n3 10\n0 5\n5 -5\n10 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 1\n1 1\n2 -2\n", "output": "NO\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
322_D. Ciel and Duel
Solve the following coding problem using the programming language python: Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's ...
```python n, m = map(int, input().split()) (a, d) = ([], []) for i in range(n): t, val = input().split() (a if t == 'ATK' else d).append(int(val)) my = sorted([int(input()) for i in range(m)]) a.sort() d.sort() def solve1(): ret = 0 used = [False] * m for val in d: for i in range(m): ...
vfc_76829
{ "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": "2 4\nDEF 0\nATK 0\n0\n0\n1\n1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500\n", "output": "3000\n", "type": "stdin_...
code_contests
verifiable_code
347_B. Fixed Points
Solve the following coding problem using the programming language python: A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a fu...
```python #347B n = int(input()) inpt = list(map(int, input().split(" "))) count = 0 b = 0 for i in range(n): if inpt[i] == i: count += 1 if b == 0 and inpt[i] != i and inpt[inpt[i]] == i: count += 2 b = 1 if b == 0: count += 1 print(min(n, count)) ```
vfc_76833
{ "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\n0 1 3 4 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
370_C. Mittens
Solve the following coding problem using the programming language python: A Christmas party in city S. had n children. All children came in mittens. The mittens can be of different colors, but each child had the left and the right mitten of the same color. Let's say that the colors of the mittens are numbered with int...
```python from collections import Counter def main(): n, m = map(int, input().split()) c = list(map(int, input().split())) sc = sorted(range(n), key=lambda x: c[x]) mc = Counter(c).most_common(1)[0][1] print(n if mc <= n - mc else 2*(n - mc)) for i in range(n): print(c[sc[i]], ...
vfc_76837
{ "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 2\n1 2 1 1\n", "output": "2\n1 2\n1 1\n1 1\n2 1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
391_F3. Stock Trading
Solve the following coding problem using the programming language python: This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points. Manao has developed a model to pred...
vfc_76841
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 2\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n", "output": " 15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5\n2\n7\n3\n9\n8\n7\n9...
code_contests
verifiable_code
415_A. Mashmokh and Lights
Solve the following coding problem using the programming language python: Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index...
```python n = input().split() n = int(n[0]) butt = {} for i in range(1, n+1): butt[i] = 0 a = input().split() for i in a: for k in range(int(i), n+1): if butt[k] == 0: butt[k] = int(i) else: continue for i in range(1, n+1): print(butt[i], end=' ') ```
vfc_76845
{ "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 5\n5 4 3 2 1\n", "output": "1 2 3 4 5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
441_D. Valera and Swaps
Solve the following coding problem using the programming language python: A permutation p of length n is a sequence of distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). A permutation is an identity permutation, if for any i the following equation holds pi = i. A swap (i, j) is the operation that swaps elements pi and ...
```python import sys sys.setrecursionlimit(100000) def cycle(p, i, v): if i in v: return v v.add(i) return cycle(p, p[i], v) def cc(p): vis = set() cnt = 0 for i in range(len(p)): if not i in vis: vis = vis.union(cycle(p, i, set())) cnt += 1 return cnt n = int(raw_input()) p = [int(i) ...
vfc_76849
{ "difficulty": "10", "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\n1 2 3 4 5\n2\n", "output": "2\n1 2 1 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 4 5 3\n2\n", "output": "1\n1 2 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
463_E. Caisa and Tree
Solve the following coding problem using the programming language python: Caisa is now at home and his son has a simple task for him. Given a rooted tree with n vertices, numbered from 1 to n (vertex 1 is the root). Each vertex of the tree has a value. You should answer q queries. Each query is one of the following: ...
vfc_76853
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 10, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6\n10 8 4 3\n1 2\n2 3\n3 4\n1 1\n1 2\n1 3\n1 4\n2 1 9\n1 4\n", "output": "-1\n1\n2\n-1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 46\n1826622 227609 1815373 691816\n4 1\n3 1\n1...
code_contests
verifiable_code
487_D. Conveyor Belts
Solve the following coding problem using the programming language python: Automatic Bakery of Cyberland (ABC) recently bought an n × m rectangle table. To serve the diners, ABC placed seats around the table. The size of each seat is equal to a unit square, so there are 2(n + m) seats in total. ABC placed conveyor bel...
vfc_76857
{ "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": "4 5 7\n&gt;&lt;&lt;^&lt;\n^&lt;^^&gt;\n&gt;&gt;&gt;^&gt;\n&gt;^&gt;&gt;^\nA 3 1\nA 2 2\nC 1 4 &lt;\nA 3 1\nC 1 2 ^\nA 3 1\nA 2 2", "output": "3 6\n2 6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
510_C. Fox And Names
Solve the following coding problem using the programming language python: Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order. After checking some examples, she found out that ...
```python from collections import defaultdict n = int(input()) g = defaultdict(list) names = [] for _ in range(n): names.append(input()) for i in range(1, n): j = 0 while j < len(names[i]) and j < len(names[i-1]) and names[i-1][j] == names[i][j]: j += 1 if j >= len(names[i]): p...
vfc_76861
{ "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": "7\ncar\ncare\ncareful\ncarefully\nbecarefuldontforgetsomething\notherwiseyouwillbehacked\ngoodluck\n", "output": "zyxwvutsrqpnmlkjihfedcboga", "type": "stdin_stdout" }, { "fn_name": null, "input": "3...
code_contests
verifiable_code
535_D. Tavas and Malekas
Solve the following coding problem using the programming language python: Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little...
```python from sys import stdin, stdout, setrecursionlimit input = stdin.readline import string characters = string.ascii_uppercase from random import choice # digits = string.digits # setrecursionlimit(int(1e6)) # dir = [-1,0,1,0,-1] # moves = 'NESW' inf = float('inf') from functools import cmp_to_key from collections...
vfc_76865
{ "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\nioi\n1 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\nioi\n1 3\n", "output": "26\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
55_E. Very simple problem
Solve the following coding problem using the programming language python: You are given a convex polygon. Count, please, the number of triangles that contain a given point in the plane and their vertices are the vertices of the polygon. It is guaranteed, that the point doesn't lie on the sides and the diagonals of the...
```python import sys import gc gc.disable() rl = sys.stdin.readline n = int(rl()) p = [complex(float(x),float(y)) for x,y in map(str.split,map(rl,[-1]*n))] pi = [c.conjugate() for c in p] fn = [0.5*x*(x-1) for x in xrange(0,n+1)] fnn = fn[::-1] for jj in xrange(int(rl())): a = complex(*map(float,rl().split())) ...
vfc_76869
{ "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": "4\n5 0\n0 0\n0 5\n5 5\n1\n1 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0\n0 5\n5 0\n2\n1 1\n10 10\n", "output": "1\n0\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
586_B. Laurenty and Shop
Solve the following coding problem using the programming language python: A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese. The town where Laurenty lives in...
```python n = int(input()) a1 = [int(s) for s in input().split()] a2 = [int(s) for s in input().split()] b = [int(s) for s in input().split()] sum = 0 for i in range(n-1): sum = sum + a2[i] sum1 = min(sum + b[0], sum - a2[0] + a1[0] + b[1]) sum2 = max(sum + b[0], sum - a2[0] + a1[0] + b[1]) sum = sum - a2[0] + a...
vfc_76873
{ "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": "2\n1\n1\n1 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n3 3\n2 1 3\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
62_B. Tyndex.Brome
Solve the following coding problem using the programming language python: Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome! The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installe...
```python from bisect import bisect_left n,k=map(int,input().split()) q="abcdefghijklmnopqrstuvwxyz" a={i:[] for i in q} for key,value in enumerate(input()):a[value].append(key) #print(a) def g(t):return [(t[i]+t[i-1])//2 for i in range(1,len(t))] #类似于二分查找的思路 //便于快速确定位置 c={i:g(a[i]) for i in q} #print(c) for _ in ...
vfc_76881
{ "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": "9 9\nvkontakte\nvcontacte\nvkontrakte\nvkollapse\nvkrokodile\nvtopke\nvkapuste\nvpechke\nvk\nvcodeforcese\n", "output": "18\n14\n36\n47\n14\n29\n30\n0\n84\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
656_A. Da Vinci Powers
Solve the following coding problem using the programming language python: Input The input contains a single integer a (0 ≤ a ≤ 35). Output Output a single integer. Examples Input 3 Output 8 Input 10 Output 1024 The input will be given via stdin and the output should be printed to stdout by your code....
```python a=int(input()) b=str(bin(a)) b=b[2:] c="0"*(6-len(b))+b d="" d+=c[0] d+=c[5] d+=c[3] d+=c[2] d+=c[4] d+=c[1] ret=0; for i in range(5,-1,-1): ret+=int(d[i])*(2**(5-i)) print(ret) ```
vfc_76885
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
67_A. Partial Teacher
Solve the following coding problem using the programming language python: A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the ...
```python from collections import deque n = int(input()) s = input() ans = [1]*n for i in range(1,n): if s[i-1]=='R': ans[i]=ans[i-1]+1 elif s[i-1]=='=': ans[i]=ans[i-1] for i in range(n-2, -1, -1): if s[i]=='L': ans[i]=max(ans[i+1]+1, ans[i]) elif s[i]=='=': ans[i]...
vfc_76889
{ "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\nLRLR\n", "output": "2 1 2 1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n=RRR\n", "output": "1 1 2 3 4 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
702_A. Maximum Increase
Solve the following coding problem using the programming language python: You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element o...
```python """ Author: Sagar Pandey """ # ---------------------------------------------------Import Libraries--------------------------------------------------- import sys import os from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial from copy import copy, deepcopy from sys i...
vfc_76893
{ "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\n1 7 2 11 15\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n100 100 100 100 100 100\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
724_B. Batch Sort
Solve the following coding problem using the programming language python: You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than onc...
```python def check(table): n = len(table) m = len(table[0]) bits = [[table[i][j] == j+1 for j in range(m)] for i in range(n)] for row in bits: if row.count(False) > 2: return False return True n,m =map(int, input().split()) table = [list(map(int, input().split())) for i in rang...
vfc_76897
{ "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": "2 4\n1 3 2 4\n1 3 4 2\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n", "output": "NO", "type": "stdin_stdout" },...
code_contests
verifiable_code
769_B. News About Credit
Solve the following coding problem using the programming language python: Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!". Not all students are equally sociable. About each student you know the value ai — the m...
```python import collections as col import itertools as its import operator class Solver: def solve(self): n = int(input()) a = list(map(int, input().split())) for i in range(len(a)): a[i] = [a[i], i + 1] a[0][0] += 1000 a = sorted(a)[::-1] a[0][0] -= 10...
vfc_76905
{ "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 2 2\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 1 0\n", "output": "3\n1 2\n2 3\n2 4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
793_B. Igor and his way to work
Solve the following coding problem using the programming language python: Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed d...
```python import sys def solve(): def run(r, c, visited): visited[r][c] = True for i in range(c + 1, m + 2): if visited[r][i] or (not ok[r][i]): break visited[r][i] = True for i in range(c - 1, -1, -1): if visited[r][i] or (not ok[r][i]):...
vfc_76909
{ "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": "5 5\n..S..\n****.\nT....\n****.\n.....\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\nS....\n****.\n.....\n.****\n..T..\n", "output": "NO", "type": "stdi...
code_contests
verifiable_code
813_E. Army Creation
Solve the following coding problem using the programming language python: As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires. In the game Vova can hire n different warriors; ith warrior has the type ai. Vova wants to create a ba...
vfc_76913
{ "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": "6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6\n", "output": "2\n4\n1\n3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n10 7 6 6 6\n8\n5 2\n4 5\n2 1\n5 2\n3 1\n3 1\n4 1\n5 2\n", ...
code_contests
verifiable_code
839_D. Winter is here
Solve the following coding problem using the programming language python: Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has creat...
```python n=int(input()) num=[0 for i in range(1000000+1)] mx=0 for i in input().split(' '): i=int(i) mx=max(mx,i) num[i]+=1 f=[0 for i in range(mx+1)] p=[0 for i in range(mx+1)] mod=1e9+7 p[0]=1 for i in range(1,mx+1): p[i]=2*p[i-1]%mod ans=0 for i in range(mx,1,-1): m=sum(num[i::i]) if m: f[i]=(m*p[m-1]%mod-s...
vfc_76917
{ "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": "4\n2 3 4 6\n", "output": "39", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 3 1\n", "output": "12", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
859_G. Circle of Numbers
Solve the following coding problem using the programming language python: n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either incre...
```python #Circle of Numbers import math def centre(n, pts): x, y = 0, 0 for j in [7,11,13,17,19,23,29,31,37,1193,1663,2711,4007,65537]: if math.gcd(n,j) == 1: for i in range(n): k = int(pts[i]) x += k*math.cos(math.pi * 2*i*j/n) y += k*math.s...
vfc_76921
{ "difficulty": "13", "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\n314159\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n000100000100000110000000001100\n", "output": "YES\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
908_H. New Year and Boolean Bridges
Solve the following coding problem using the programming language python: Your friend has a hidden directed graph with n nodes. Let f(u, v) be true if there is a directed path from node u to node v, and false otherwise. For each pair of distinct nodes, u, v, you know at least one of the three statements is true: ...
vfc_76929
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n-XX\nX-X\nXX-\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n-AAA\nA-AA\nAA-A\nAAA-\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
930_B. Game with String
Solve the following coding problem using the programming language python: Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this stri...
```python s=input() d=dict() mod=[] mx=[] for k in s: d[k]=[] for i in range(len(s)): d[s[i]].append(i) index=0 for k in d.keys(): mod.append(d[k]) for k in mod: mxct=0 ct=0 x=[] for i in range(len(s)): ct=0 dic=dict() for j in k: elt = s[(j+i)%(len(s))] if elt in dic.keys(): dic[elt]+=1 el...
vfc_76933
{ "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": "technocup\n", "output": "1.000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "tictictactac\n", "output": "0.333333", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
958_C3. Encryption (hard)
Solve the following coding problem using the programming language python: Heidi is now just one code away from breaking the encryption of the Death Star plans. The screen that should be presenting her with the description of the next code looks almost like the previous one, though who would have thought that the evil ...
vfc_76937
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 200000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5 12\n16 3 24 13 9 8 7 5 12 12\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 10\n3 4 7 2\n", "output": "6\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
984_B. Minesweeper
Solve the following coding problem using the programming language python: One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he ra...
```python arr = [] def valid(i, j): bombs = 0 if arr[i][j] == '*': return True if i != len(arr) - 1: if arr[i + 1][j] == '*': bombs += 1 if i != 0: if arr[i - 1][j] == '*': bombs += 1 if j != len(arr[0]) - 1: if arr[i][j + 1] == '*': ...
vfc_76941
{ "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": "2 4\n*.*.\n1211\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n111\n1*1\n111\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
a-to-b-1
Solve the following coding problem using the programming language python: Problem : You are given an array A initially comprising of N non-negative integers A[1], A[2], A[3]..... A[N]. An array B can be generated from array A in the following manner : for(i=1;i ≤ N;i++) { B[i]=1; for(j=1;j ≤ N;j++) { ...
```python def modinv(n): M=1000000007 return pow(n,M-2,M) n=input() A=map(int,raw_input().split()) val=1 M=10**9+7 z=0 for i in A: if i!=0: val=(val*i)%M else: z+=1; t=input() for i in xrange(t): C=map(int,raw_input().split()); if len(C)==2: if z>=2: print 0 elif z==1: if A[C[1]-1]==0: ...
vfc_76945
{ "difficulty": "0", "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\n3\n1 3\n0 2 4\n1 4\n\nSAMPLE", "output": "40\n60\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n2 8 8 4 7 5 6 7 0 \n10000\n1 3\n0 9 6\n1 4\n1 5\n1 8\n0 6 4\n1 6\n1 3\n0 ...
code_contests
verifiable_code
bluffman-encoding
Solve the following coding problem using the programming language python: The Kraken lives! Tragedy has struck the trade world since news has spread of the rise of the Kraken that terrorizes the Mediterranean Sea. Any ship that attempts to cross this strait is torn apart by the mighty tentacles of the beast and all i...
```python for t in range(input()): n = input() a1 = [0]*n a2 = ['a']*n for i in range(n): x = raw_input().split() a1[i] = int(x[1]) a2[i] = x[0][0] for i in range(n): for j in range(1,n): if a1[j-1] > a1[j] : a1[j-1],a1[j] = a1[j],a1[j-1] a2[j-1],a2[j] = a2[j],a2[j-1] codes = [ '' for i i...
vfc_76949
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n21\nb 0\nc 1\nd 1\ne 1\nf 1\ng 0\nh 0\nj 1\nk 1\nl 0\nm 2\nn 1\no 0\nq 0\nr 0\nt 0\nu 0\nw 0\nx 1\ny 1\nz 0\n11111111111111111111111111111110111111111111110111111111111101111111111110111111111111111101111111111111111011111111111...
code_contests
verifiable_code
cricket-teams
Solve the following coding problem using the programming language python: You are a cricket coach who wants to partition a set of players into two teams of equal size and a referee. If there are odd players, one of the player becomes the referee. However, if there are even players, the coach himself acts as the refere...
```python from heapq import * minH = [] maxH = [] while True: n = int(raw_input()) if n==-2: break if n==0: if len(minH)==len(maxH): print -1 else: if len(minH)>len(maxH): print minH[0] else: print -maxH[0] else: if len(minH)==0 and len(maxH)==0: heappush(minH,n) else: if n<minH[0...
vfc_76953
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n3\n0\n1\n0\n-2\n\nSAMPLE", "output": "3\n-1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
forming-surveillance-team-3
Solve the following coding problem using the programming language python: Agent OO7 is engaged in a mission to stop the nuclear missile launch. He needs a surveillance team to monitor the progress of the mission. Several men with different type of capabilities assemble in a hall, help OO7 to find out total men with di...
```python t = input() while(t): t -= 1 size = input() print len(list(set(list(map(int,raw_input().split()))))) ```
vfc_76957
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6\n48 11 11 48 36 10\n4\n25 25 25 25\n9\n6 98 12 256 23 245 10 19 3\n\nSAMPLE", "output": "4\n1\n9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6\n48 11 11 48 36 10\n4\n25 25 25 2...
code_contests
verifiable_code
josephs-coin-trouble
Solve the following coding problem using the programming language python: Joseph studies at SKIT.He is a fresher he has been given a task and he wants help from you for performing the task.The task is an interesting one. The tasks is:- He is provided with a value N, he has to make change for N cents, and he have inf...
```python n = int(raw_input()) a = map(int, raw_input().split()) s = [[0 for i in range(len(a))] for i in range(n+1)] for i in range(len(a)): s[0][i] = 1 x = 0 y = 0 for i in range(1, n+1): for j in range(len(a)): if i - a[j] >= 0: x = s[i-a[j]][j] else: x = 0 if j >= 1: y = s[i][j-1] else: y = 0 ...
vfc_76961
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n2 4 9\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "68\n2 3 9", "output": "52\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
milly-and-chocolates-iv-6
Solve the following coding problem using the programming language python: Milly loves to eat chocolates. She has N different chocolates. She needs to choose only one of them. At the moment, i^{th} chocolate already has P_{i} pieces. The j^{th} piece of the i^{th} chocolate requires T_{i,j} seconds to eat. Milly knows ...
```python t = int(raw_input()) while t: t-=1 n,k,m=map(int,raw_input().split()) p = map(int,raw_input().split()) ans = (2*10**5)+(101*10**9) idx = 0 for i in xrange(n): firstTime = True val=0 for j in raw_input().split(): j = int(j) if (firstTime): val+=(k+j) firstTime=False else: val+=...
vfc_76965
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 10 10\n1 2\n10\n4 2\n\nSAMPLE", "output": "1 20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2 10 10\n1 2\n10\n4 2\n\nSAMPME", "output": "1 20\n", "type": "stdin_std...
code_contests
verifiable_code
pair-puzzle
Solve the following coding problem using the programming language python: You are given two numbers N and K and a set X. X = { x : x is a natural number ≤ N } You have to find the total number of pairs of elements X[i] and X[j] belonging to the given set, such that, i < j and their sum is divisible by K. Input For...
```python T = int(input()) for _ in range(T): N, K = list(map(int, raw_input().split())) # Loop over all multiples of K less than 2N: # If nK <= N: # add (nK - 1) // 2 pairs # Else: # add (nK - 1) // 2 - (k - N - 1) pairs total = 0 a = N // K + 1 b = (2 * N) // K - (1 if (2 * N) % K == 0 else 0) ...
vfc_76969
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 4\n7 3\n\nSAMPLE", "output": "10\n7", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n16 4\n7 3\n\nSAMPLE", "output": "28\n7\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
rest-in-peace-21-1
Solve the following coding problem using the programming language python: The grandest stage of all, Wrestlemania XXX recently happened. And with it, happened one of the biggest heartbreaks for the WWE fans around the world. The Undertaker's undefeated streak was finally over. Now as an Undertaker fan, you're disap...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t = int(raw_input()) for x in range(t): num = raw_input() n = int(num) if ('21' in num) or (n%21==0): print "The streak is broken!" else: print "The streak lives still...
vfc_76973
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "43\n70094\n32451\n81996\n94945\n66592\n95666\n56597\n30999\n37838\n69486\n12189\n49843\n99036\n99581\n66047\n25991\n97370\n95747\n24363\n78941\n81920\n32127\n36071\n74224\n59348\n56285\n40357\n44730\n69466\n67521\n34774\n96220\n948...
code_contests
verifiable_code
totakeornottotake
Solve the following coding problem using the programming language python: Pandey needs your help. As you know, he is on the quest to save the princess. After traveling for a number of days, he has finally reached the palace, but one last battle remains to be fought. However he has only one unit of energy left in him. ...
```python from pprint import pprint as pp def GI(): return int(raw_input()) def GIS(): return map(int, raw_input().split()) def main(): for t in xrange(GI()): ex = [1, 1] for _ in xrange(GI()): b = raw_input() if b == 'N': nex = [-1 * x for x in ex] ...
vfc_76981
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\nN\n- 2\nN\n3\n- 1\n* 4\n/ 2\n\n\nSAMPLE", "output": "3\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n48\n+ 3\n+ 2\n+ 4\n- 3\n- 4\n- 2\n+ 3\n+ 2\n- 2\nN\nN\n+ 3\n+ 4\nN\n- 4\...
code_contests
verifiable_code
p00123 Speed Skating Badge Test
Solve the following coding problem using the programming language python: In the speed skating badge test, grades are awarded when the time specified for two distances is exceeded. For example, to reach Class A, 500 M requires less than 40.0 seconds and 1000 M requires less than 1 minute and 23 seconds. Create a prog...
```python import bisect while 1: try: n,m=map(float,input().split()) m500=[35.5,37.5,40,43,50,55,70] m1000=[71,77,83,89,105,116,148] r1=bisect.bisect_left(m500,n+0.001) r2=bisect.bisect_left(m1000,m+0.001) rank=["AAA","AA","A","B","C","D","E","NA"] print(rank[...
vfc_77029
{ "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": "40.0 70.0\n72.5 140.51", "output": "B\nNA", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00256 Mayan Crucial Prediction
Solve the following coding problem using the programming language python: Shinya watched a program on TV called "Maya's Great Prophecy! Will the World End in 2012?" After all, I wasn't sure if the world would end, but I was interested in Maya's "long-term calendar," which was introduced in the program. The program exp...
```python import datetime time_std=datetime.date(2012, 12, 21) while 1: n=input() if n=="#":break n_len=list(map(int,n.split("."))) if len(n_len)==3: year_keep=0 while n_len[0]>9999: year_keep+=1 n_len[0]-=400 ans=[0]*5 cal_date=datetime.date(n_len...
vfc_77033
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2012.12.31\n2.12.16.14.14\n7138.5.13\n10.5.2.1.5\n10000000.12.31\n#", "output": "0.0.0.0.10\n3054.8.15\n0.0.0.0.10\n6056.2.29\n8.19.3.13.2", "type": "stdin_stdout" }, { "fn_name": null, "input": "201...
code_contests
verifiable_code
p00443 Lightest Mobile
Solve the following coding problem using the programming language python: problem Mobiles are widely known as moving works of art. The IOI Japan Committee has decided to create mobiles to publicize JOI. JOI public relations mobiles are sticks, strings, and weights. It is constructed as follows using the three types o...
```python # AOJ 0520: Lightest Mobile # Python3 2018.6.30 bal4u def lcm(a, b): return a // gcd(a, b) * b def gcd(a, b): while b != 0: r = a % b a, b = b, r return a def calc(i): wr = calc(t[i][2]) if t[i][2] > 0 else 1 wb = calc(t[i][3]) if t[i][3] > 0 else 1 w = lcm(t[i][0] * wr, t[i][1] * wb) return w//...
vfc_77037
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n6 9 0 0\n4\n3 2 0 4\n1 3 0 0\n4 4 2 1\n2 2 0 0\n0", "output": "5\n40", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6 9 0 0\n4\n3 2 0 4\n1 3 0 0\n4 4 2 1\n4 2 0 0\n0", "output":...
code_contests
verifiable_code
p00633 Crop Circle
Solve the following coding problem using the programming language python: A crop circle suddenly appeared on the vast agricultural land of Argentina. A total of n crop circles were confirmed, including overlapping, popping, large, and small ones. When a mystery hunter tried to capture the whole picture of a crop circ...
```python def string_to_float(s): return list(map(float, s.split())) def solve(): from sys import stdin lines = stdin.readlines() from itertools import combinations from math import acos, pi from cmath import phase from bisect import insort while True: n = int(lines[0]) ...
vfc_77041
{ "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": "4\n6 4 2\n4 7 3\n7 10 3\n13 6 1\n4\n7 4 2\n4 7 3\n7 10 3\n11 6 3\n0", "output": "39.664699289572\n45.627024663706", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n6 4 2\n4 7 3\n7 10 3\n13 ...
code_contests
verifiable_code
p00777 Bridge Removal
Solve the following coding problem using the programming language python: Bridge Removal ICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the proj...
```python from sys import setrecursionlimit setrecursionlimit(10 ** 8) while True: n = int(input()) if n == 0: break P = [int(i) for i in input().split()] D = [int(i) for i in input().split()] E = [list() for i in range(n + 1)] for i, (p, c) in enumerate(zip(P, D), 2): E[i].ap...
vfc_77045
{ "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": "4\n1 2 3\n10 20 30\n10\n1 2 2 1 5 5 1 8 8\n10 1 1 20 1 1 30 1 1\n3\n1 1\n1 1\n0", "output": "80\n136\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3\n10 20 30\n10\n1 2 2 1 5 5 1 ...
code_contests
verifiable_code
p00908 Sliding Block Puzzle
Solve the following coding problem using the programming language python: In sliding block puzzles, we repeatedly slide pieces (blocks) to open spaces within a frame to establish a goal placement of pieces. A puzzle creator has designed a new puzzle by combining the ideas of sliding block puzzles and mazes. The puzzl...
```python from collections import deque from heapq import heappush, heappop, heapify import sys readline = sys.stdin.readline write = sys.stdout.write dd = ((-1, 0), (0, -1), (1, 0), (0, 1)) Z = [-1]*(50*50) def calc(H, W, G, x0, y0, bx, by, S): S[:] = Z[:H*W] k = y0*W + x0 que = deque([k]) S[k] = 0 ...
vfc_77049
{ "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": "3 3\noo.\noXX\n.XX\n3 3\nXXo\nXX.\no.o\n3 5\n.o*XX\noooXX\noooo.\n7 12\noooooooooooo\nooooo*****oo\noooooo****oo\no**ooo***ooo\no***ooooo..o\no**ooooooXXo\nooooo****XXo\n5 30\noooooooooooooooooooooooooooooo\nooooooooooooooooooooooo...
code_contests
verifiable_code
p01175 Optimal Rest
Solve the following coding problem using the programming language python: Music Macro Language (MML) is a language for textual representation of musical scores. Although there are various dialects of MML, all of them provide a set of commands to describe scores, such as commands for notes, rests, octaves, volumes, and...
vfc_77057
{ "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": "3\nR2R2\nR1R2R4R8R16R32R64\nR1R4R16", "output": "R1\nR1......\nR16R1R4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nR2R2\nR2R1R4R8R16R32R64\nR1R4R16", "output": "R1\nR1......\nR1...
code_contests
verifiable_code
p01311 The Door into Summer
Solve the following coding problem using the programming language python: Natsume loves big cats. I haven't kept cats at Natsume's house for a long time, and Natsume, who loves cats, was always playing with stray cats. However, this time Natsume decided to keep a cat at her own house. Natsume welcomed the cat to her h...
```python #!/usr/bin/env python from collections import deque import itertools as it import sys import math sys.setrecursionlimit(10000000) INF = 10 ** 9 L = input() for loop in range(L): n, m = map(int, raw_input().split()) S, T = map(int, raw_input().split()) E = [[] for i in range(n + 1)] for i i...
vfc_77061
{ "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\n4 6\n1 2\n1 2 N\n2 3 N\n3 4 N\n4 1 N\n1 4 L\n4 0 L\n4 6\n1 2\n1 2 N\n2 3 N\n3 4 N\n4 1 N\n1 4 L\n4 0 N", "output": "1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 6\n1 2\n1 2 N...
code_contests
verifiable_code
p01480 Unequal Dice
Solve the following coding problem using the programming language python: Time Limit: 8 sec / Memory Limit: 64 MB Example Input 2 4 2 4 0.4000000 3 0.5000000 4 1 5 0.3333333 5 3 5 0.7777777 4 0.1111111 2 0.0001111 Output YES The input will be given via stdin and the output should be printed to stdout by you...
```python t = input() q = [0]*(t + 1) for i in range(t + 1): n,m = map(int,raw_input().split()) vr = [map(float,raw_input().split()) for x in range(m)] q[i] = sum([v*r for v,r in vr])/sum([r for v,r in vr]) q = [q[i] - q[-1] for i in range(t + 1)] print "YES" if max(q) > 0.0000001 else "NO" ```
vfc_77065
{ "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\n4 2\n4 0.4000000\n3 0.5000000\n4 1\n5 0.3333333\n5 3\n5 0.7777777\n4 0.1111111\n2 0.0001111", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 2\n4 0.4000000\n3 0.50000...
code_contests
verifiable_code
p01641 Brainf*ck
Solve the following coding problem using the programming language python: Mr. B loves Brainf * ck and submits all the assignments given at school using Brainf * ck. Recently, I was brainwashed by Mr. B, and the teacher limited the language to solve the problem to Brainf * ck. At this rate, everyone will lose credit. ...
```python import math s = raw_input() memory = [i for i in range(30, 121, 10)] r = '' r += ''.join(['+'*i+'>' for i in range(30, 121, 10)]) r += '<' * 10 point = 0 for c in s: c = ord(c) n = c / 10 - 3 d = int(math.fabs(point - n)) if point < n: r += '>' * d else: r += '<' * d ...
vfc_77069
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ABC", "output": "++++++++[>++++++++<-]>+.+.+.", "type": "stdin_stdout" }, { "fn_name": null, "input": "ABD", "output": ">+++++[<++++++>-]>+++++[<++++++++>-]>+++++[<++++++++++>-]>++++++[<+++++++...
code_contests
verifiable_code
p01793 Content Delivery
Solve the following coding problem using the programming language python: Example Input 3 2 1 2 1 2 3 2 1 10 100 Output 320 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 sys.setrecursionlimit(10**5) def solve(): N, M = map(int, readline().split()) G = [[] for i in range(N)] for i in range(N-1): a, b, c = map(int, readline().split()) G[a-1].append((b-1, c)) G[b-1].append((a-1,...
vfc_77073
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2 1\n2 3 2\n1 10 100", "output": "320", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n1 2 1\n2 3 2\n1 10 100", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01927 Industrial Convex Pillar City
Solve the following coding problem using the programming language python: Convex polygon pillar industrial city The Industrial Convex Pillar City (ICPC) is a city of buildings in the shape of several convex polygonal columns. You are about to walk through this city from your current location S to your destination T. ...
```python from math import sin, cos, tan, radians from heapq import heappush, heappop import sys readline = sys.stdin.readline write = sys.stdout.write def dot3(O, A, B): ox, oy = O; ax, ay = A; bx, by = B return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy) def cross3(O, A, B): ox, oy = O; ax, ay = A; bx,...
vfc_77077
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 1 0 0 1 0 1 1 0 1\n4 2 2 2 3 2 3 3 2 3\n60 45\n-1 -1 4 4\n4\n4 1 0 0 3 1 1 2 0 1\n3 2 10 7 8 2 12 4\n6 8 7 12 8 13 9 15 10 19 11 24 10 25\n5 4 16 2 16 4 12 8 14 2 15 0\n167 38\n3 3 15 21\n12\n4 3 -8 -3 -9 -3 -9 -5 -8 -6\n4 5 -...
code_contests
verifiable_code
p02065 Grid Number
Solve the following coding problem using the programming language python: F: Grid number problem Ebi-chan is trying to write exactly one integer from 1 to 2 \ times n in a grid with n columns horizontally and 2 rows vertically. Only one integer can be written to each cell in the grid. It's not fun just to write no...
```python from collections import Counter N, K, mod = map(int, input().split()) dp = [Counter() for _ in range(2*N)] dp[0][(None, (0,))] = 1 for i in range(2*N-1): for (left, top), v in dp[i].items(): if len(top) > K+1: continue if left == None: if top and i+1 - top[0] <= K:...
vfc_77081
{ "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": "3 2 7", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 11", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0 11",...
code_contests
verifiable_code
p02361 Single Source Shortest Path
Solve the following coding problem using the programming language python: For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path). Constraints * 1 ≤ |V| ≤ 100000 * 0 ≤ di ≤ 10000 * 0 ≤ |E| ≤ 500000 * There are no parallel edg...
```python from heapq import heappush, heappop INF = 10**10 a,b,c = map(int,input().split()) d = [[] for i in range(a)] for i in range(b): ta,tb,tc = map(int,input().split()) d[ta].append((tb,tc)) def dijkstra(N, G, s): dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappo...
vfc_77089
{ "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 6 1\n0 1 1\n0 2 4\n2 0 1\n1 2 2\n3 1 1\n3 2 5", "output": "3\n0\n2\nINF", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 5", "output": "0\n1\n3\...
code_contests
verifiable_code
aran07
Solve the following coding problem using the programming language python: At last, we have successfully neutralized all the cyber weapons of mass destruction, saved our university along the way and lay to waste another evil scheme in the process. All that separates that hacker from us now is his last lair of security,...
```python for i in xrange(input()): x=input() s=0 y=x while x>0: s+=x%10 x/=10 print y*pow(2,s) ```
vfc_77093
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n12\n44", "output": "8\n96\n11264\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
circuits
Solve the following coding problem using the programming language python: AND gates and OR gates are basic components used in building digital circuits. Both gates have two input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output is 0. The output of an OR gate is 1 if ...
```python def circuits(): t=int(raw_input()) for i in range(t): n=raw_input() n=int(raw_input()) inp=[] in1=[] in2=[] for j in range(n): x=raw_input().split() inp.append(int(x[0])) if x[0]=='0': in1.append(0) in2.append(0) else: in1.append(int(x[1])) in2.append(int(x[2])) ...
vfc_77097
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n\n1\n0\n\n3\n0\n0\n1 1 2\n\n3\n0\n0\n2 1 2\n\n5\n0\n0\n0\n2 1 2\n1 3 4", "output": "0.50000\n0.29289\n0.70711\n0.40303\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n\n1\n0\n\n3\n0\...
code_contests
verifiable_code
fbfrw1
Solve the following coding problem using the programming language python: Problem Description An online quiz is going to be held at NIT Hamirpur. Each student will be given a system which is connected to internet. Although all the systems are connected to same network, there is still varying data transfer speed among ...
```python l=[int(i) for i in raw_input().split()]; n=l[0]; m=l[1]; l=[int(i) for i in raw_input().split()]; l.sort(); l=l[::-1]; print l[m-1]; ```
vfc_77101
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n250 125 330 3000 1000", "output": "330", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n2000 2100 3000 1500 1250 3000", "output": "1250", "type": "stdin_stdout" } ...
code_contests
verifiable_code
lcollis
Solve the following coding problem using the programming language python: Once N boys and M girls attended a party. You are given a matrix A of N rows and M columns where Aij is 1 if the i-th boy likes the j-th girl, otherwise it will be 0. Note that it is not necessary that if a boy x likes girl y, then girl y should...
```python # @author Kilari Teja # LCOLLIS for Indx in range(0, int(raw_input())): Collisions = 0 Dims = [int(Dim) for Dim in (raw_input()).split(" ")] Cols = [[] for CIndx in range(0, Dims[1])] for RIndx in range(0, Dims[0]): Row = raw_input() for Chr in range(0, Dims[1]): Cols[Chr].append(Row[Chr]) for...
vfc_77105
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3\n111\n100\n110\n000\n2 2\n10\n01", "output": "4\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 3\n111\n100\n110\n000\n2 1\n10\n01", "output": "4\n0\n", "type": ...
code_contests
verifiable_code
piano1
Solve the following coding problem using the programming language python: Recently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales. There are different kinds of sca...
```python for _ in range(input()): s=raw_input() n=input() t,sum=0,0 for i in s: if i=='T': sum+=2 #print t else: sum+=1 #sum=t+st #print sum temp=12*n j,i,c=temp,1,0 while i<=temp: j=temp-i while j: j-=sum if j>=0: c+=1 if j-sum<0: break i+=1 if temp-i<sum: break ...
vfc_77109
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 \nTTTT\n1\nTTSTTTS\n3", "output": "4\n36\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 \nTTTT\n0\nTTSTTTS\n3", "output": "0\n36\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
strbit
Solve the following coding problem using the programming language python: John's barn has a fence consisting of N consecutive parts numbered from left to right starting from 1 to N. Each part is initially painted in one of two colors: red or green, whose information is provided you by a string C. The color of i-th par...
```python t = int(raw_input()) for i in range(t): n,k = [int(j) for j in raw_input().split()] c = raw_input() l = list(c) q = [] qf,qb = 0,0 j,co = 0,0 while j < n: if (qb-qf)%2 == 0: if l[j] == 'R': co += 1 q.append(min(n,j+k)) qb += 1 else: if l[j] == 'G': co += 1 q.append(min...
vfc_77113
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n7 3\nRGGRGRG", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n7 2\nRGGRGRG", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1031_F. 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_77121
{ "difficulty": "12", "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
1054_F. Electric Scheme
Solve the following coding problem using the programming language python: Pasha is a young technician, nevertheless, he has already got a huge goal: to assemble a PC. The first task he has to become familiar with is to assemble an electric scheme. The scheme Pasha assembled yesterday consists of several wires. Each w...
vfc_77125
{ "difficulty": "12", "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 1\n3 2\n2 3\n1 2\n", "output": "3\n2 1 2 1\n1 2 3 2\n2 3 2 3\n4\n1 2 1 2\n2 1 2 1\n2 3 2 3\n3 2 3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 2\n2 4\n4 2\n4 4\n", "ou...
code_contests
verifiable_code
1076_F. Summer Practice Report
Solve the following coding problem using the programming language python: Vova has taken his summer practice this year and now he should write a report on how it went. Vova has already drawn all the tables and wrote down all the formulas. Moreover, he has already decided that the report will consist of exactly n page...
```python def max(a, b): if a > b: return a else: return b n, k = map(int, input().split()) x = [int(t) for t in input().split()] y = [int(t) for t in input().split()] f, s = 0, 0 for i in range(n): f = max(0, x[i] + f - k * y[i]) s = max(0, y[i] + s - k * x[i]) if f > k or s > k: print('NO') ...
vfc_77129
{ "difficulty": "12", "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 1\n4 1 10 1\n3 2 10 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n5 6\n2 2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
1097_F. Alex and a TV Show
Solve the following coding problem using the programming language python: Alex decided to try his luck in TV shows. He once went to the quiz named "What's That Word?!". After perfectly answering the questions "How is a pseudonym commonly referred to in the Internet?" ("Um... a nick?"), "After which famous inventor we ...
vfc_77133
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 13\n1 1 1\n1 2 4\n1 3 6\n4 4 4\n1 4 4\n2 2 1 2\n2 3 3 4\n4 4 4\n3 2 2 3\n4 2 1\n4 2 2\n4 2 3\n4 2 4\n", "output": "010101\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n4 1 1\n", ...
code_contests
verifiable_code
1145_C. Mystery Circuit
Solve the following coding problem using the programming language python: <image> Input The input contains a single integer a (0 ≤ a ≤ 15). Output Output a single integer. Example Input 3 Output 13 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the pr...
```python print((15, 14, 12, 13, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7)[int(input())]) ```
vfc_77141
{ "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": "3\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n", ...
code_contests
verifiable_code
1166_B. All the Vowels Please
Solve the following coding problem using the programming language python: Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length k is vowelly if there are positive integers n and m such that n⋅ m = k and when the word is written by using n rows and m c...
```python N = int(input()) def make_vowels(N): ans = ["aeiou", "eioua", "iouae", "ouaei", "uaeio"] vowels = "aeiou" m = 5 while m < N: if N % m == 0 and N // m >= 5: break m += 1 else: return print(-1) n = N // m for i in range(n): if i <= 4: ...
vfc_77145
{ "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": "36\n", "output": "aeiouaeiouaeiouaeiouaeiouaeiouaeioua\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
1184_E3. Daleks' Invasion (hard)
Solve the following coding problem using the programming language python: With your help, Heidi has prepared a plan of trap placement and defence. Yet suddenly, the Doctor popped out of the TARDIS and told her that he had spied on the Daleks' preparations, and there is more of them than ever. Desperate times require d...
vfc_77149
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 10, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 2 8\n2 3 3\n3 1 4\n", "output": "4\n8\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 9\n2 6 346401989\n10 8 669413260\n1 2 610565686\n5 4 715678008\n7 3 871652693\n5 10 68113...
code_contests
verifiable_code
1220_B. Multiplication Table
Solve the following coding problem using the programming language python: Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table M with n rows and n columns such that M_{ij}=a_i ⋅ a_j where a_1, ..., a_n is some sequence of positive integers. Of course, the girl de...
```python n=int(input()) arr=[] for _ in range(n): arr.append([int(x) for x in input().split()]) ans=[0 for i in range(n)] ans[1]=int(((arr[0][1]*arr[1][2])//arr[0][2])**0.5) for i in range(n): if i==1: continue ans[i]=arr[1][i]//ans[1] for i in ans: print(i,end=' ') ```
vfc_77157
{ "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\n0 4 6 2 4\n4 0 6 2 4\n6 6 0 3 6\n2 2 3 0 2\n4 4 6 2 0\n", "output": "2 2 3 1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 99990000 99970002\n99990000 0 99980000\n99970002 99980...
code_contests
verifiable_code
1245_D. Shichikuji and Power Grid
Solve the following coding problem using the programming language python: Shichikuji is the new resident deity of the South Black Snail Temple. Her first job is as follows: There are n new cities located in Prefecture X. Cities are numbered from 1 to n. City i is located x_i km North of the shrine and y_i km East of ...
```python import sys #import heapq as hq #from collections import deque #sys.stdin = open('in', 'r') readline = sys.stdin.readline rdw = lambda: readline().rstrip() rdws = lambda: readline().split() rdwl = lambda: list(readline().split()) rdi = lambda: int(readline()) rdis = lambda: map(int, readline().split()) rdil = ...
vfc_77161
{ "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\n2 1\n1 2\n3 3\n23 2 23\n3 2 3\n", "output": "27\n1\n2 \n2\n1 2\n2 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1265_B. Beautiful Numbers
Solve the following coding problem using the programming language python: You are given a permutation p=[p_1, p_2, …, p_n] of integers from 1 to n. Let's call the number m (1 ≤ m ≤ n) beautiful, if there exists two indices l, r (1 ≤ l ≤ r ≤ n), such that the numbers [p_l, p_{l+1}, …, p_r] is a permutation of numbers 1...
```python for _ in range (int(input())): n=int(input()) a = [int(i) for i in input().split()] ind = [0]*(n+1) for i in range (n): ind[a[i]]=i m = 1 ma = ind[1] mi = ind[1] ans = "1" for i in range (n-1): m+=1 ma = max(ind[m],ma) mi = min(ind[m],mi) ...
vfc_77165
{ "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\n6\n4 5 1 3 2 6\n5\n5 3 1 2 4\n4\n1 4 3 2\n", "output": "101011\n11111\n1001\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6\n4 5 1 3 2 6\n5\n5 3 2 1 4\n4\n1 4 3 2\n", "output...
code_contests
verifiable_code
1286_D. LCC
Solve the following coding problem using the programming language python: An infinitely long Line Chillland Collider (LCC) was built in Chillland. There are n pipes with coordinates x_i that are connected to LCC. When the experiment starts at time 0, i-th proton flies from the i-th pipe with speed v_i. It flies to the...
vfc_77169
{ "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": "2\n1 1 100\n3 1 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n6 4 50\n11 25 50\n13 16 50\n15 8 50\n", "output": "150902884\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
132_C. Logo Turtle
Solve the following coding problem using the programming language python: A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward"). You are given a list of commands that will...
```python s = input() n = int(input()) t = [j for j, q in enumerate(s) if q == 'T'] l, r = [0] * 101, [0] * 101 for i, (a, b) in enumerate(zip([-1] + t, t + [len(s)])): v = b - a u = v - 1 if i: l[i] = l[i - 1] + v else: u, v = -u, -v r[i + 1] = l[i] - 1 for k in range(i - 1...
vfc_77177
{ "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": "FFFTFFF\n2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "FT\n1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
134_A. Average Numbers
Solve the following coding problem using the programming language python: You are given a sequence of positive integers a1, a2, ..., an. Find all such indices i, that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one). Input The first line contains the intege...
```python m = int(input()) num = [int(n) for n in input().split()] sum = 0 for i in range(0,m): sum += num[i] if sum % m: print('0') else: ave = sum // m cnt = 0 for i in range(0,m): if num[i] == ave: cnt += 1 print(cnt) for i in range(0,m): if num[i] == ave: ...
vfc_77181
{ "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\n1 2 3 4 5\n", "output": "1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n50 50 50 50\n", "output": "4\n1 2 3 4\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1370_A. Maximum GCD
Solve the following coding problem using the programming language python: Let's consider all integers in the range from 1 to n (inclusive). Among all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of gcd(a, b), where 1 ...
```python n = int(input()) for i in range(n): print(int(input())//2) ```
vfc_77185
{ "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\n3\n5\n", "output": "1\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1392_F. Omkar and Landslide
Solve the following coding problem using the programming language python: Omkar is standing at the foot of Celeste mountain. The summit is n meters away from him, and he can see all of the mountains up to the summit, so for all 1 ≤ j ≤ n he knows that the height of the mountain at the point j meters away from himself ...
```python import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.bu...
vfc_77189
{ "difficulty": "12", "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 6 7 8\n", "output": "5 5 6 7 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "0 ", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
1433_G. Reducing Delivery Cost
Solve the following coding problem using the programming language python: You are a mayor of Berlyatov. There are n districts and m two-way roads between them. The i-th road connects districts x_i and y_i. The cost of travelling along this road is w_i. There is some path between each pair of districts, so the city is ...
```python import sys input = sys.stdin.readline import heapq def dijkstra(n, s, edges): hq = [(0, s)] cost = [float('inf')] * n cost[s] = 0 while hq: c, v = heapq.heappop(hq) if c > cost[v]: continue for d, u in edges[v]: tmp = d + cost[v] if...
vfc_77197
{ "difficulty": "13", "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 5 2\n1 2 5\n2 3 7\n2 4 4\n4 5 2\n4 6 8\n1 6\n5 3\n", "output": "22\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 4\n1 2 5\n2 3 4\n1 4 3\n4 3 7\n3 5 2\n1 5\n1 3\n3 3\n1 5\n", ...
code_contests
verifiable_code
1481_F. AB Tree
Solve the following coding problem using the programming language python: Kilani and Abd are neighbors for 3000 years, but then the day came and Kilani decided to move to another house. As a farewell gift, Kilani is going to challenge Abd with a problem written by their other neighbor with the same name Abd. <image> ...
```python from sys import stdin, stdout n, a = map(int, stdin.readline().split()) p = [-1] + [int(x) - 1 for x in stdin.readline().split()] g = [[] for i in range(n)] for i in range(1, n): g[p[i]].append(i) d = [-1 for i in range(n)] d_all = [[] for i in range(n)] d_lv = [[] for i in range(n)] d_nlv = [[] for i in r...
vfc_77205
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 3\n1 2 2 4 4 4 3 1\n", "output": "\n4\naabbbbbba\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 7\n12 11 5 16 17 9 6 15 12 16 6 20 3 4 1 7 16 3 8\n", "output": "12\nbbaaabbabba...
code_contests
verifiable_code
1535_A. Fair Playoff
Solve the following coding problem using the programming language python: Four players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals...
```python ''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' t=int(input()) for i in range(t): l=list(map(int,input().split())) m=l[:] l.sort(reverse=True) ...
vfc_77213
{ "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": "4\n3 7 9 5\n4 5 6 9\n5 3 8 1\n6 5 3 2\n", "output": "\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8 6 2 7\n", "output": "YES\n", "type": "stdin_stdout"...
code_contests
verifiable_code
162_E. HQ9+
Solve the following coding problem using the programming language python: HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the whole source code of the program itself (at each call), * "9" prints the lyrics of "99 Bottles of Beer" son...
vfc_77217
{ "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": "Hello!\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "VK_Cup_2012!\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
205_C. Little Elephant and Interval
Solve the following coding problem using the programming language python: The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in dec...
```python #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) #from __future__ import print_function, division #while using python2 # from itertools import accumulate # from collections import de...
vfc_77225
{ "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": "47 1024\n", "output": "98\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 47\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
22_B. Bargaining Table
Solve the following coding problem using the programming language python: Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, o...
```python n,m=map(int,input().split()) a=[] for i in range(n): a.append([]) for x in input(): if x=="0": a[i].append(0) else: a[i].append(1) ans=0 for x1 in range(0,m): for x2 in range(x1,m): for y1 in range(0,n): for y2 in range(y1,n): ...
vfc_77229
{ "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 3\n000\n010\n000\n", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1100\n0000\n0000\n0000\n0000\n", "output": "16", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
255_A. Greg's Workout
Solve the following coding problem using the programming language python: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise...
```python n=int(input()) l=list(map(int,input().split())) chest=back=biceps=0 for i in range(0,n,3): chest+=l[i] for i in range(1,n,3): biceps+=l[i] for i in range(2,n,3): back+=l[i] if chest>biceps and chest>back: print("chest") elif biceps>chest and biceps>back: print("biceps") else: print("back") ```
vfc_77233
{ "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": "3\n5 1 10\n", "output": "back\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
279_A. Point on Spiral
Solve the following coding problem using the programming language python: Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), (...
```python # one ride costs a rubes inputs = list(map(int, input().split())) x = inputs[0] y = inputs[1] if y==0 and 0<=x<=1: print(0) else: a = max(abs(x), abs(y)) m = 1 + 4*(a-1) if x==a and y==-(a-1):print(m-1) if x==a and -(a-1)<y<=a: print(m) elif y==a and -a<=x<a:print(m+1) elif x==-a and ...
vfc_77237
{ "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 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 1\n",...
code_contests
verifiable_code
300_E. Empire Strikes Back
Solve the following coding problem using the programming language python: In a far away galaxy there is war again. The treacherous Republic made k precision strikes of power ai on the Empire possessions. To cope with the republican threat, the Supreme Council decided to deal a decisive blow to the enemy forces. To s...
vfc_77241
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1000 1000\n", "output": "2000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
327_C. Magic Five
Solve the following coding problem using the programming language python: There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting num...
```python mod = 1000000007 #gcd(a, m) = 1 def inv_mod(a, m): a %= m return pow(a, m-2, m) a = input() k = int(input()) t = len(a) d = 0 for i, c in enumerate(a): if not int(c) % 5: d += pow(2, i, mod) d %= mod print(d*(pow(2, (k*t)%(mod-1), mod)-1)*inv_mod(pow(2, t, mod)-1, mod)%mod) ```
vfc_77245
{ "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": "1256\n1\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "555\n2\n", "output": "63", "type": "stdin_stdout" }, { "fn_name": null, "input": "139...
code_contests
verifiable_code
349_D. Apple Tree
Solve the following coding problem using the programming language python: You are given a rooted tree with n vertices. In each leaf vertex there's a single integer — the number of apples in this vertex. The weight of a subtree is the sum of all numbers in this subtree leaves. For instance, the weight of a subtree th...
vfc_77249
{ "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": "6\n0 0 12 13 5 6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "output": " 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 0 2 3 5\n1 2\...
code_contests
verifiable_code
372_E. Drawing Circles is Fun
Solve the following coding problem using the programming language python: There are a set of points S on the plane. This set doesn't contain the origin O(0, 0), and for each two distinct points in the set A and B, the triangle OAB has strictly positive area. Consider a set of pairs of points (P1, P2), (P3, P4), ..., ...
vfc_77253
{ "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": "10\n30 30 -26 26\n0 15 -36 36\n-28 28 -34 34\n10 10 0 4\n-8 20 40 50\n9 45 12 30\n6 15 7 35\n36 45 -8 20\n-16 34 -4 34\n4 34 8 17\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
394_B. Very Beautiful Number
Solve the following coding problem using the programming language python: Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the...
```python p,k = input().split() p = int (p) k = int (k) y = 10*k -1 x = ((10 ** (p-1)) - k) % y b = True for i in range(k,10): if( (x*i % y) == 0): #z = (x*i) // y #print(z*10 + i) z = i*10 while( (z-i)%y ): z *= 10 part = str ((z-i)//y) print(part * (p//len(part))) b= False break i...
vfc_77257
{ "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": "1 2\n", "output": "Impossible\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n", "output": "102564\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
417_C. Football
Solve the following coding problem using the programming language python: One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appoi...
```python import sys,math n,k=map(int,sys.stdin.readline().split()) if n<=2*k: print(-1) else: ans=[] for i in range(n): for j in range(i+1,k+i+1): if j+1==n: ans.append([i+1,j+1]) else: ans.append([i+1,((j+1)%n)]) print(len(ans)) ...
vfc_77261
{ "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": "3 1\n", "output": "3\n1 2\n2 3\n3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n", "output": "-1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
466_B. Wonder Room
Solve the following coding problem using the programming language python: The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says ...
```python n,a,b = map(int, input().split(' ')) A = 6*n if a*b >= 6*n : print(a*b) print(a,b) else : R = [] temp = float("INF") for i in range(1, int(A**0.5)+2) : j = A//i if i*j < A : j+=1 x = max([a,b,i,j]) y = max(min(a,b) , min(i,j)) if temp > x*y : ...
vfc_77269
{ "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 3 5\n", "output": "18\n3 6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
489_F. Special Matrices
Solve the following coding problem using the programming language python: An n × n square matrix is special, if: * it is binary, that is, each cell contains either a 0, or a 1; * the number of ones in each row and column equals 2. You are given n and the first m rows of the matrix. Print the number of specia...
```python from math import * from collections import * import sys sys.setrecursionlimit(10**9) dp = [[-1 for i in range(505)] for j in range(505)] def memo(row,z,o): if(row == n): if(z == 0 and o == 0): return 1 else: return 0 if(dp[z][o] != -1): return dp[z][o] if(z > 1): dp[z][o] += (z*(z-1)//2)*(mem...
vfc_77273
{ "difficulty": "12", "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 4 100500\n0110\n1010\n0101\n1001\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
513_D1. Constrained Tree
Solve the following coding problem using the programming language python: You need to find a binary tree of size n that satisfies a given set of c constraints. Suppose that the nodes of the unknown binary tree are labeled using a pre-order traversal starting with 1. For the i-th constraint you are given two labels, ai...
```python #!/usr/bin/env python #-*- coding:utf-8 -*- import sys import math import random import operator from fractions import Fraction, gcd from decimal import Decimal, getcontext from itertools import product, permutations, combinations from collections import deque, defaultdict, Counter MOD = 10**9 + 7 INF = flo...
vfc_77277
{ "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 2\n1 2 RIGHT\n1 3 LEFT\n", "output": "IMPOSSIBLE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 2 LEFT\n1 3 RIGHT\n", "output": "2 1 3 \n", "type": "stdin_stdout" ...
code_contests
verifiable_code
538_F. A Heap of Heaps
Solve the following coding problem using the programming language python: Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment. The teacher gave Andrew an array of n numbers a1, ...,...
```python import sys def myargsort(a): b = list(zip(a, range(0, len(a)))) b.sort() r = [pr[1] for pr in b] return r fin = sys.stdin n = int(fin.readline()) a = [int(number) for number in fin.readline().split()] p = myargsort(a) p.reverse() j = 0 aib = [0] * (n + 1) def ultb(x): return -(x ^ (-x))...
vfc_77281
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 2 2 2 2 2\n", "output": "0 0 0 0 0 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
566_G. Max and Min
Solve the following coding problem using the programming language python: Two kittens, Max and Min, play with a pair of non-negative integers x and y. As you can guess from their names, kitten Max loves to maximize and kitten Min loves to minimize. As part of this game Min wants to make sure that both numbers, x and y...
```python from __future__ import division import sys from itertools import chain, izip_longest def read_ints(itr): return map(int, next(itr).split(' ')) def read_pairs(itr, n): for i in xrange(n): yield read_ints(itr) def convex_hull(pairs): sorted_pairs = sorted(pairs) begin_pad, end_pad = g...
vfc_77285
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n42 43\n2 3\n3 2\n3 10\n10 3\n", "output": "Min\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
588_B. Duff in Love
Solve the following coding problem using the programming language python: Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x. <image> Malek has a number store! In his store, he has only divisors of positive ...
```python import math #n,k = map(int, input().strip().split(' ')) n=int(input()) #lst = list(map(int, input().strip().split(' '))) if n==1 or n==2 or n==3: print(n) else: p=math.sqrt(n) l=[1,n] c=1 for j in range(2,int(p)+1): if n%j==0: l.insert(c,j) if n//j!=j: ...
vfc_77289
{ "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": "12\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
60_D. Savior
Solve the following coding problem using the programming language python: Misha decided to help Pasha and Akim be friends again. He had a cunning plan — to destroy all the laughy mushrooms. He knows that the laughy mushrooms can easily burst when they laugh. Mushrooms grow on the lawns. There are a[t] mushrooms on the...
vfc_77293
{ "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": "1\n2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
630_I. Parking Lot
Solve the following coding problem using the programming language python: To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes. The parking lot before the office consists of ...
```python n = int(input()) print(int(4 * (n - 3) * 3 * 3 * 4 ** (n - 4) + 4 * 2 * 3 * 4 ** (n - 3))) ```
vfc_77297
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "3264\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", ...
code_contests
verifiable_code
659_A. Round House
Solve the following coding problem using the programming language python: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided t...
```python n, a, b = list(map(int, input().split())) if b == 0: print(a) exit() dx = b // abs(b) for i in range(abs(b)): a += dx if a == 0: a = n elif a == n + 1: a = 1 print(a) ```
vfc_77301
{ "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 7\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2 -5\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 ...
code_contests
verifiable_code
681_C. Heap Operations
Solve the following coding problem using the programming language python: Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following operations: * put the given number into the heap; * get the value of the minimum element in the heap; * extract the ...
```python from sys import stdin, stdout def siftup(ind): while ind != 1 and heap[ind] < heap[ind // 2]: heap[ind], heap[ind // 2] = heap[ind // 2], heap[ind] ind //= 2 def siftdown(ind): while len(heap) > ind * 2 + 1 and (heap[ind] > heap[ind * 2] or heap[ind] > heap[ind ...
vfc_77305
{ "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\ninsert 1\ninsert 1\nremoveMin\ngetMin 2\n", "output": "6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
704_B. Ant Man
Solve the following coding problem using the programming language python: Scott Lang is at war with Darren Cross. There are n chairs in a hall where they are, numbered with 1, 2, ..., n from left to right. The i-th chair is located at coordinate xi. Scott is on chair number s and Cross is on chair number e. Scott can ...
vfc_77309
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4 3\n8 11 12 16 17 18 20\n17 16 20 2 20 5 13\n17 8 8 16 12 15 13\n12 4 16 4 15 7 6\n8 14 2 11 17 12 8\n", "output": "139\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2\n1 2 3\n1 1...