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
79_C. Beaver
Solve the following coding problem using the programming language python: After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a str...
```python s, n = input(), int(input()) t = [input() for i in range(n)] def f(i): global t for j in range(n): if i < j: if len(t[j]) < len(t[i]) and t[j] in t[i]: return False elif j < i and t[j] in t[i]: return False return True t = [t[i] for i in range(n) if f(i)] n = len(s) r...
vfc_34853
{ "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": "unagioisii\n2\nioi\nunagi\n", "output": "5 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse\n", "output": "12 4"...
code_contests
verifiable_code
81_E. Pairs
Solve the following coding problem using the programming language python: There are n students in Polycarp's class (including himself). A few days ago all students wrote an essay "My best friend". Each student's essay was dedicated to one of the students of class, to his/her best friend. Note that student b's best fri...
vfc_34857
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 2\n3 2\n5 1\n2 1\n4 2\n", "output": "2 2\n5 3\n2 4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
846_A. Curriculum Vitae
Solve the following coding problem using the programming language python: Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were succe...
```python def main(): n = int(input()) games = list(map(int, input().split(' '))) result = max([games[:i].count(0) + games[i:].count(1) for i in range(n+1)]) print(result) if __name__ == "__main__": main() ```
vfc_34861
{ "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": "6\n0 1 0 0 1 0\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
867_C. Ordering Pizza
Solve the following coding problem using the programming language python: It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices. It ...
```python def cns(ts,s): if ts/s==int(ts/s): return ts else: return (int(ts/s)+1)*s n,spp=[int(i) for i in input().split()] tsr=0 da=[[] for i in range(100005)] db=[[] for i in range(100005)] sl=[] for i in range(n): sl.append([int(j) for j in input().split()]) tsr+=sl[i][0] if sl[i]...
vfc_34865
{ "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 10\n7 4 7\n5 8 8\n12 5 8\n6 11 6\n3 3 7\n5 9 6\n", "output": "314\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 12\n3 5 7\n4 6 7\n5 9 5\n", "output": "84\n", "type": "std...
code_contests
verifiable_code
914_E. Palindromes in a Tree
Solve the following coding problem using the programming language python: You are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t. A path in the tree is said to be palindromic if at least one permutation of the la...
```python import sys, os def centroid_decomp(coupl): n = len(coupl) bfs = [n - 1] for node in bfs: bfs += coupl[node] for nei in coupl[node]: coupl[nei].remove(node) size = [0] * n for node in reversed(bfs): size[node] = 1 + sum(size[child] for child in...
vfc_34873
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n6 2\n4 3\n3 7\n5 2\n7 2\n1 4\nafefdfs\n", "output": "1 4 1 1 2 4 2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
937_C. Save Energy!
Solve the following coding problem using the programming language python: Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stov...
```python k,d,t = map(int, input().split()) if k % d == 0: print(t) exit() r = k % d ot = (d-r) /2 ot += k ct = k + (d-r) cn = int(t // ot) ans = cn*ct rt = t - cn*ot if rt < k: ans += rt else: ans += k rt -= k ans += rt*2 ans = "%.10f" % float(ans) print(ans) ```
vfc_34877
{ "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 20\n", "output": "20.0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 6\n", "output": "6.5\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
962_E. Byteland, Berland and Disputed Cities
Solve the following coding problem using the programming language python: The cities of Byteland and Berland are located on the axis Ox. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line Ox there are three types of cities: * the citie...
```python def solve(length, cities): result = 0 lastP = None lastB = None lastR = None maxB = 0 maxR = 0 for idx, city in enumerate(cities): i, code = city if(code == 'B'): if(lastB != None): result += abs(i - lastB) maxB = max(maxB, abs(i - lastB)) lastB = i if(cod...
vfc_34881
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10 R\n14 B\n16 B\n21 R\n32 R\n", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n-5 R\n0 P\n3 P\n7 B\n", "output": "12\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
990_A. Commentary Boxes
Solve the following coding problem using the programming language python: Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built n commentary boxes. m regional delegations will come to the Cup. Every delegation should get the same number of the c...
```python n, m, a, b = list(map(int, input().split())) k = n%m print(min(k*b, (m - k)*a)) ```
vfc_34885
{ "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": "30 6 17 19\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 7 3 7\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
ankit-and-numbers-8
Solve the following coding problem using the programming language python: Ankit has a set of numbers and has recently studied set theory. He has created a power set of this set and is writing a program to compute sum of all elements of all the subsets in power set. Power set of a set S is defined as set of all possib...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' if __name__ == '__main__': cases = int(raw_input()) start = 1 while start <= cases: number = int(raw_input()) no_of_occurances = 2 ** (number - 1) sum_of_numbers = (n...
vfc_34889
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n\nSAMPLE", "output": "24\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chandu-and-consecutive-letters
Solve the following coding problem using the programming language python: Chandu is very fond of strings. (Or so he thinks!) But, he does not like strings which have same consecutive letters. No one has any idea why it is so. He calls these strings as Bad strings. So, Good strings are the strings which do not have sam...
```python T=input('') while T>0: str = raw_input('') str1 = "" for index in range(0,len(str)-1): flag = False if str[index] != str[index+1]: flag = True if flag: str1+=str[index] str1+=str[len(str)-1] print(str1) T-=1 ```
vfc_34893
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nabb\naaab\nababa\n\nSAMPLE", "output": "ab\nab\nababa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nabb\naaab\nababa\n\nSAMLPE", "output": "ab\nab\nababa\n", "type": "s...
code_contests
verifiable_code
digit-lover
Solve the following coding problem using the programming language python: Tom is very fond of adding values , so what he does whenever he gets a value he adds all its digits and forms a new value and checks it whether it has become a single digit or not and if it does not even becomes a single digit he apply the opera...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' for tc in range(input()): n = raw_input() while len(n) > 1: t=0 for i in n: t += int(i) n = str(t) print n ```
vfc_34897
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n167\n569\n102\n\nSAMPLE", "output": "5\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "72\n147\n1009\n994\n5564\n9999\n1547\n18894\n1475\n5554\n8457\n32254\n14562\n18995\n5624\n65...
code_contests
verifiable_code
girlfriends-demands
Solve the following coding problem using the programming language python: Like most of the girlfriends, Ashima when asks for something, won’t stop until she gets that. The way she gets that is by keep on repeating the same things again and again. Like if she wants chocolate, she will just keep on repeating “chocolate”...
```python s = raw_input() l = len(s) q = int(raw_input()) for i in xrange(0,q): a, b = map(int, raw_input().split()) a%=l b%=l if s[a - 1] is s[b - 1]: print 'Yes' else: print 'No' ```
vfc_34901
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "vgxgp\n3\n2 4\n2 5\n7 14\n\nSAMPLE", "output": "Yes\nNo\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "vgxgp\n3\n2 4\n2 3\n7 14\n\nSAMPLE", "output": "Yes\nNo\nYes\n", "t...
code_contests
verifiable_code
level-selections
Solve the following coding problem using the programming language python: You are given N natural numbers and K swaps are allowed. Determine the largest permutation that you can attain. INPUT: First line contains N and k next line has N spaced integers OUTPUT: Print the largest permutation array. 0<N<10^5 0<K<10^5 ...
```python n,k=raw_input().split() n,k=int(n),int(k) l=[int(i) for i in raw_input().split()] x=0 swap_i=0 while k: max_e=0 k-=1 for i in range(x,n): if(l[i] >= max_e ): max_e=l[i]; swap_i=i l[x],l[swap_i]=l[swap_i],l[x] x+=1 if(swap_i == x): k+=1 for...
vfc_34905
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n4 2 3 5 1\n\nSAMPLE", "output": "5 2 3 4 1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
monk-in-the-secret-services
Solve the following coding problem using the programming language python: The secret services of Armin, an otherwise peace-loving country, have decided to perform a surgical strike in the war-torn city of Tashka. Tashka is under enemy control and the objective of the strike is to gain control over the city. The missi...
```python from collections import defaultdict import sys inf = sys.maxint T = int(raw_input()) for l in range(T): N,M = [int(x) for x in raw_input().split()] dicti = defaultdict(lambda : inf) D = [[inf]*(N+1) for x in range(N+1)] for i in range(1,N+1): D[i][i]=0 for i in range(M...
vfc_34909
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4 4\n1 4 1\n1 2 1\n2 3 1\n2 4 1\n1 2 3\n\nSAMPLE", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n29 668\n11 27 52\n21 10 35\n17 1 61\n24 26 11\n10 9 79\n1 7 1\n21 2 10\...
code_contests
verifiable_code
plane-with-points
Solve the following coding problem using the programming language python: There are N points on an XY plane. In one turn, you can select a set of collinear points on the plane and remove them. Your goal is to remove all the points in the least number of turns. Given the coordinates of the points, calculate two things:...
```python def constdr1(Points) : Droites = [] i = 0 j = i + 1 while j < len(Points) : S = True for D in Droites : if (Points[D[1]][0]-Points[D[0]][0])*(Points[j][1]-Points[i][1])-(Points[D[1]][1]-Points[D[0]][1])*(Points[j][0]-Points[i][0])== 0 : S=False if not (j in D) : D.append(j) break...
vfc_34913
{ "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\n0 0\n0 1\n1 0\n4\n3 4\n3 5\n3 6\n5 5\n\nSAMPLE", "output": "2 6\n2 8", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
roy-and-trains-2
Solve the following coding problem using the programming language python: Roy and Alfi reside in two different cities, Roy in city A and Alfi in city B. Roy wishes to meet her in city B. There are two trains available from city A to city B. Roy is on his way to station A (Railway station of city A). It will take T_0...
```python import math t=input() while t: t0,t1,t2,v1,v2,d = map(int,raw_input().split()) tim1=int(math.ceil(t1+(float(d)/v1)*60)) tim2=int(math.ceil(t2+(float(d)/v2)*60)) if(t1<t0 and t2<t0): print("-1") elif(t1>=t0 and t2<t0): print(tim1) elif(t1<t0 and t2>=t0): print(tim2) else: print(min(tim1,tim...
vfc_34917
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 5 8 100 90 320\n\nSAMPLE", "output": "197\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n8 6 3 2 5 17\n10 7 5 3 4 1\n6 10 1 4 3 40\n1 10 10 4 3 43\n8 10 5 3 1 34\n8 7 5 4 1 48\n2...
code_contests
verifiable_code
substring-5
Solve the following coding problem using the programming language python: A substring is a string of characters that is contained in another string. For example, the substrings of "abcdef" could be "abc", "bc", "cdef", "e" and so on. But, "bca", "ace", and "g" are not substrings of "abcdef". Your task is to count th...
```python def check(s1): for i in range(len(s1)): for j in range(i+1,len(s1)): if s1[i]!=s1[j]: return 0 return 1 s=raw_input() dc={} for i in range(len(s)): t=i while t<len(s): s1=s[i:t+1] if s1 not in dc and check(s1): dc[s1]=1 el...
vfc_34921
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "xxxyx\n\nSAMPLE", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "goiihyziiuuudbmrmlxbjjjkzzhhgssswuiujjjjbdooowwwwwoqouttjaawcsssrwwtllkyeegvnmhhhlottuuvxwwkmmrwqxxv", ...
code_contests
verifiable_code
very-cool-numbers
Solve the following coding problem using the programming language python: For a number X, let its "Coolness" be defined as the number of "101"s occurring in its binary representation. For example, the number 21 has Coolness 2, since its binary representation is 101012, and the string "101" occurs twice in this represe...
```python def counter(n): binary = bin(n)[2:] count = 0 for i in xrange(len(binary)-2): if binary[i:i+3] == "101": count += 1 return count ary = [0]*(10**5+1) for i in xrange(5,10**5+1): ary[i] = counter(i) for t in xrange(input()): r,k = map(int, raw_input().split()) tot...
vfc_34925
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 1\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n12124 8\n14185 14\n18812 5\n20857 7\n27546 7", "output": "0\n0\n136\n0\n1\n", "type": "stdin_...
code_contests
verifiable_code
p00031 Weight
Solve the following coding problem using the programming language python: <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g...
```python import sys l = [2 ** i for i in range(10)] for line in sys.stdin: blist = list(bin(int(line))[2:]) blist.reverse() #print(blist) anslist = [] for i in range(len(blist)): if blist[i] == "1": anslist.append(str(l[i])) print(' '.join(anslist)) ```
vfc_34969
{ "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": "5\n7\n127", "output": "1 4\n1 2 4\n1 2 4 8 16 32 64", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n7\n135", "output": "1 4\n1 2 4\n1 2 4 128\n", "type": "stdin_stdout" } ...
code_contests
verifiable_code
p00162 Hamming Numbers
Solve the following coding problem using the programming language python: The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming number...
```python # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0162 """ import sys from sys import stdin from bisect import bisect_right, bisect_left from math import ceil, log input = stdin.readline def main(args): hammings = [] temp = set() for i in range(ceil(log(1e6, ...
vfc_34973
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 8\n1 27\n1 86\n0", "output": "5\n17\n31", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 8\n2 27\n1 86\n0", "output": "5\n16\n31\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p00489 Soccer
Solve the following coding problem using the programming language python: problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games...
```python n = int(input()) score = [list(map(lambda x: int(x) - 1 , input().split())) for _ in range(int(n*(n-1)/2))] points = [0 for _ in range(n)] for a,b,c,d in score: if c > d: points[a] += 3 elif c < d: points[b] += 3 else: points[a] += 1 points[b] += 1 rank = sorted...
vfc_34981
{ "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 0 1\n1 3 2 1\n1 4 2 2\n2 3 1 1\n2 4 3 0\n3 4 1 3", "output": "2\n1\n4\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 0 1\n1 3 2 1\n1 4 2 2\n2 3 2 1\n2 4 3 0\n3 4 1 3", ...
code_contests
verifiable_code
p00675 Sports Days
Solve the following coding problem using the programming language python: The University of Aizu Elementary School (Aizu University and Small) is famous as one of Japan's leading competition programmer training schools. Of course, it is essential to practice the algorithm even when attending an athletic meet. Of cour...
vfc_34985
{ "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\n1\n1\n2\n1 2 1\n2 1 1\n1\n1111\n2\n1\n1\n2\n1 2 1\n2 1 1\n1\n11\n2\n1\n1\n2\n1 2 1\n2 1 1\n10\n1111\n2\n1\n1\n2\n1 2 1\n2 1 1\n10\n111111\n2\n1\n1\n2\n1 2 -1\n2 1 0\n10\n11\n2\n1\n1\n2\n1 2 -1\n2 1 0\n10\n1111\n2\n1\n1\n2\n1 2 -...
code_contests
verifiable_code
p00818 Viva Confetti
Solve the following coding problem using the programming language python: Do you know confetti? They are small discs of colored paper, and people throw them around during parties or festivals. Since people throw lots of confetti, they may end up stacked one on another, so there may be hidden ones underneath. A handfu...
vfc_34989
{ "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\n0 0 0.5\n-0.9 0 1.00000000001\n0.9 0 1.00000000001\n5\n0 1 0.5\n1 1 1.00000000001\n0 2 1.00000000001\n-1 1 1.00000000001\n0 -0.00001 1.00000000001\n5\n0 1 0.5\n1 1 1.00000000001\n0 2 1.00000000001\n-1 1 1.00000000001\n0 0 1.0000...
code_contests
verifiable_code
p00949 Hidden Anagrams
Solve the following coding problem using the programming language python: Example Input anagram grandmother Output 4 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python s1 = input() s2 = input() cA = ord('a') s1 = [ord(e) - cA for e in s1] l1 = len(s1) s2 = [ord(e) - cA for e in s2] l2 = len(s2) ans = 0 for l in range(1, min(l1, l2)+1): s = set() use = [0]*26 for i in range(l-1): use[s1[i]] += 1 for i in range(l-1, l1): use[s1[i]] += 1 ...
vfc_34993
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 10, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "anagram\ngrandmother", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "anagram\ngrandmosher", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
p01082 Escape of Lappin the Phantom Thief
Solve the following coding problem using the programming language python: Problem Phantom thief Rappan came to steal the jewels. It was easy to get the jewel, but the jewel was equipped with a sensor and was surrounded by security robots. The guard robot is designed to move towards the jewel. The sensor didn't seem ...
vfc_34997
{ "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": "20 10 1\n0 0", "output": "28", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 10 2\n0 0\n17 5", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p01352 Graph Construction
Solve the following coding problem using the programming language python: There are n rabbits, one in each of the huts numbered 0 through n − 1. At one point, information came to the rabbits that a secret organization would be constructing an underground passage. The underground passage would allow the rabbits to vis...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, K = map(int, readline().split()) ES = [list(map(int, readline().split())) for i in range(K)] emp = {} sq = int(K**.5) + 1 def root(x): if x == p[x]: return x ...
vfc_35005
{ "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 10\n1 0 1\n1 0 2\n3 1 2\n2 0 1\n1 2 3\n3 0 1\n1 0 1\n2 0 2\n1 1 3\n3 0 2", "output": "YES\nNO\nYES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01534 Anipero 2012
Solve the following coding problem using the programming language python: D: Anipero 2012 Anipero Summer Live, commonly known as Anipero, is the largest anime song live event in Japan where various anime song artists gather. 2D, who loves anime songs, decided to go to Anipero this year as well as last year. He has a...
```python INF = 10 ** 20 n, m = map(int, input().split()) dp = [[[-INF] * 9 for _ in range(m + 1)] for _ in range(n + 1)] dp[0][m][0] = 0 for i in range(n): a, b, c = map(int, input().split()) for rest in range(m + 1): for l1 in range(9): for l2 in range(min(9, rest + 1)): if l1 == 0 and l2 == 0:a...
vfc_35009
{ "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": "1 5\n2 3 8", "output": "10", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01690 Disciple Life is Hard
Solve the following coding problem using the programming language python: D --Disciple Life is Hard / Disciple is hard Story The person in D loves donuts. I always want donuts. However, D, who was ordered by his master, Bunashimejitan, to train himself, must limit his calorie intake. Therefore, D person decided to e...
vfc_35013
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 1 1 1 4 3\n6 10\n5 8", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, "input": "17 1 1 1 4 3\n6 10\n5 8", "output": "15\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01969 AA Graph
Solve the following coding problem using the programming language python: C: AA グラフ (AA Graph) Problem Given a graph as an ASCII Art (AA), please print the length of shortest paths from the vertex s to the vertex t. The AA of the graph satisfies the following constraints. A vertex is represented by an uppercase alp...
vfc_35021
{ "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": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02404 Print a Frame
Solve the following coding problem using the programming language python: Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 ...
```python while True: h, w = [int(i) for i in input().split()] if w == h == 0: break print("#" * w, end="") print(("\n#" + "." * (w - 2) + "#") * (h - 2)) print("#" * w, end="\n\n") ```
vfc_35033
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n5 6\n3 3\n0 0", "output": "####\n#..#\n####\n\n######\n#....#\n#....#\n#....#\n######\n\n###\n#.#\n###", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n5 7\n3 3\n0 0", "output...
code_contests
verifiable_code
cdva1604
Solve the following coding problem using the programming language python: Everyone knows the famous detective Sherlock. He has been handed over a new case of "The Abominable Bride". Each night she kills N people but to irritate Sherlock she leaves exactly one people. The way she kills the people is somewhat strange. ...
```python t=int(raw_input()) for i in range(t): n=int(raw_input()) x=bin(n)[2:] x=len(x)-1 x2=pow(2,x) ans=2*(n-x2) if ans==0: print x2 else: print ans ```
vfc_35037
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2\n4\n6\n9\n12", "output": "2\n4\n4\n2\n8", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
dce03
Solve the following coding problem using the programming language python: The captain of TITANIC is a mathematics freak. He has recently been given a problem that he is unable to solve. And he has asked your help to solve it. There are n numbers in a given expression. X1 X2 X3 .... Xn What is the number of ways to...
```python #!/usr/bin/python import sys catalan=[1 , 1 , 2 , 5 , 14 , 42 , 132 , 429 , 1430 , 4862 , 6796 , 8786 , 8012 , 2900 , 4440 , 4845 , 7670 , 4790 , 8700 , 3190 , 420 , 7020 , 3640 , 3650 , 7324 , 1452 , 2152 , 6004 , 360 , 1368 , 2304 , 6909 , 8198 , 3110 , 764 , 1262 , 3492 , 2364 , 1400 , 390 , 8820 , 4020 ,...
vfc_35041
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n5", "output": "5\n14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4\n10", "output": "5\n4862\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
ignus15b
Solve the following coding problem using the programming language python: Problem Description  You are an army personnel in the great army of the Zorin race, where you are a part of a team of n people. Unfortunately, your army has lost a war to an intergalactic species, genetically much advanced than yours. Their cap...
```python T=input() for _ in xrange(T): N,i=input(),1; while i<=N: i*=2; i/=2; print 1+2*(N-i); ```
vfc_35045
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n6\n125\n32\n46\n98\n156", "output": "5\n123\n1\n29\n69\n57", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
rrecipe
Solve the following coding problem using the programming language python: Chef had an interesting dream last night. He dreamed of a new revolutionary chicken recipe. When he woke up today he tried very hard to reconstruct the ingredient list. But, he could only remember certain ingredients. To simplify the problem, th...
```python def main(): for i in xrange(int(raw_input())): s = raw_input() ctr = 1 for j in xrange((len(s)+1)//2): if s[j]=="?" and s[-j-1]=="?": ctr*=26 ctr%=10000009 elif s[j]!=s[-j-1] and s[j]!="?" and s[-j-1]!="?": ctr...
vfc_35053
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n?\n??\nab?\na?c\naba", "output": "26\n26\n1\n0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n?\n??\n?ba\na?c\naba", "output": "26\n26\n1\n0\n1\n", "type": "stdin_std...
code_contests
verifiable_code
wicq9
Solve the following coding problem using the programming language python: Tic-Tac-Toe-Tomek is a game played on a 4 x 4 square board. The board starts empty, except that a single 'T' symbol may appear in one of the 16 squares. There are two players: X and O. They take turns to make moves, with X starting. In each move...
```python def counter(string): x=string.count('X') o=string.count('O') d=string.count('.') t=string.count('T') return (x,o,t,d) def win(tupa): if((tupa[0]==3 and tupa[2]==1) or tupa[0]==4): print 'Case #'+str(i)+': X won' return True elif((tupa[1]==3 and tupa[2]==1)or tupa[1...
vfc_35057
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nX X X T\n. . . .\nO O . .\n. . . .\n\nX O X T\nX X O O\nO X O X\nX X O O\n\nX O X .\nO X . .\n. . . .\n. . . .\n\nO O X X\nO X X X\nO X . T\nO . . O\n\nX X X O\n. . O .\n. O . .\nT . . .\n\nO X X X\nX O . .\n. . O .\n. . . O", ...
code_contests
verifiable_code
101_E. Candies and Stones
Solve the following coding problem using the programming language python: Little Gerald and his coach Mike play an interesting game. At the beginning of the game there is a pile consisting of n candies and a pile consisting of m stones. Gerald and Mike move in turns, Mike goes first. During his move Mike checks how ma...
vfc_35061
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 45000000, "problem_url": null, "time_limit": "{'seconds': 7, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 10\n0 0\n0 1\n", "output": "2\nSC", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2\n0 1 1\n1 1 0\n", "output": "4\nSCSC", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
1088_F. Ehab and a weird weight formula
Solve the following coding problem using the programming language python: You're given a tree consisting of n nodes. Every node u has a weight a_u. It is guaranteed that there is only one node with minimum weight in the tree. For every node u (except for the node with the minimum weight), it must have a neighbor v suc...
vfc_35073
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n1 2\n1 3\n", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 5 3 7 8\n1 2\n1 3\n3 4\n4 5\n", "output": "40", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1107_F. Vasya and Endless Credits
Solve the following coding problem using the programming language python: Vasya wants to buy himself a nice new car. Unfortunately, he lacks some money. Currently he has exactly 0 burles. However, the local bank has n credit offers. Each offer can be described with three numbers a_i, b_i and k_i. Offers are numbered ...
```python n = int(input()) a = [tuple(map(int, input().split())) for i in range(n)] a = [(y, x, k) for x, y, k in a] a.sort(reverse=True) dp = [[-1] * (n + 1) for i in range(n)] def f(i, j): if i < 0 or j < -1: return 0 if dp[i][j] == -1: y, x, k = a[i] dp[i][j] = f(i - 1, j) + max(0, x - k * ...
vfc_35077
{ "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\n10 9 2\n20 33 1\n30 115 1\n5 3 2\n", "output": "32\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n40 1 2\n1000 1100 5\n300 2 1\n", "output": "1337\n", "type": "stdin_std...
code_contests
verifiable_code
1137_A. Skyscrapers
Solve the following coding problem using the programming language python: Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by n streets along the Eastern direction and m streets across the Southern direction. Naturally, this city has nm intersections. At any inter...
```python import sys input=sys.stdin.buffer.readline from bisect import bisect_left n,m=map(int,input().split()) arr=[] for i in range(n): arr.append(list(map(int,input().split()))) arr_maxi=[[0 for i in range(m)] for j in range(n)] arr_mini=[[0 for i in range(m)] for j in range(n)] for i in range(n): s=sorted(...
vfc_35081
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 2\n3 4\n", "output": "2 3 \n3 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n1 2 1\n2 1 2\n", "output": "2 2 2 \n2 2 2 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1155_C. Alarm Clocks Everywhere
Solve the following coding problem using the programming language python: Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the i-th of them will start during the x_i-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in suc...
```python def gcd(a,b): if b==0: return a else: return gcd(b,a%b) n, m = map(int, input().split(' ')) x = list(map(int, input().split(' '))) p = list(map(int, input().split(' '))) dx = [x[i+1]-x[i] for i in range(n-1)] d = dx[0] for i in dx: d = gcd(i, d) for i in range(m): if d % p[i]...
vfc_35085
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n3 12 18\n2 6 5 3 3\n", "output": "YES\n 3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 5 17 19\n2 1\n", "output": "YES\n 1 1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1177_B. Digits Sequence (Hard Edition)
Solve the following coding problem using the programming language python: Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task ...
```python #import sys #digit = int(sys.argv[1]) digit = int(input()) if int(digit) <= 9: print(digit) exit() start_range = 1 end_range = 9 power = 1 digit_count = 2 while not (start_range <= digit and digit <= end_range): start_range = end_range + 1 end_range = 9 * 10**power * digit_count + start_ran...
vfc_35089
{ "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": "21\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "511\n", ...
code_contests
verifiable_code
1213_B. Bad Prices
Solve the following coding problem using the programming language python: Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for n last days: a_1, a_2, ..., a_n, where a_i is the price of berPhone on the day i. Polycarp considers the price on the day i to be bad if later (that is, a day ...
```python for _ in range(int(input())): n = int(input()) lst = list(map(int, input().split())) cnt = 0 x = lst[-1] for i in lst[:-1][::-1]: x = min((x, i)) if x < i: cnt += 1 print(cnt) ```
vfc_35097
{ "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": "5\n6\n3 9 4 6 7 5\n1\n1000000\n2\n2 1\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "output": "3\n0\n1\n8\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n6\n3 9 4 6 7 5\n1...
code_contests
verifiable_code
1236_C. Labs
Solve the following coding problem using the programming language python: In order to do some research, n^2 labs are built on different heights of a mountain. Let's enumerate them with integers from 1 to n^2, such that the lab with the number 1 is at the lowest place, the lab with the number 2 is at the second-lowest ...
```python n = int(input()) a = [[] for i in range(n)] j = 0 k = 1 cnt = 0 for i in range(n): for j in range(n): cnt += 1 if (i % 2 == 0): a[j].append(cnt) else: a[-j-1].append(cnt) for i in range(n): print(*a[i]) ```
vfc_35101
{ "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": "1 6 7 \n2 5 8 \n3 4 9 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1254_B1. Send Boxes to Alice (Easy Version)
Solve the following coding problem using the programming language python: This is the easier version of the problem. In this version, 1 ≤ n ≤ 10^5 and 0 ≤ a_i ≤ 1. You can hack this problem only if you solve and lock both problems. Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for ...
```python from sys import stdin,stdout from math import gcd,sqrt,factorial,pi,inf from collections import deque,defaultdict from bisect import bisect,bisect_left from time import time from itertools import permutations as per from heapq import heapify,heappush,heappop,heappushpop input=stdin.readline R=lambda:map(int,i...
vfc_35105
{ "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\n1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 0 1\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1278_A. Shuffle Hashing
Solve the following coding problem using the programming language python: Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems. Polycarp decided to store the hash of the password, generated by the following algorithm: 1. ta...
```python t = int(input()) for _ in range(t): s = input() t = input() ok = False s = ''.join(sorted(s)) for i in range(len(t) - len(s) + 1): temp = ''.join(sorted(t[i:i+len(s)])) if temp == s: ok = True break if ok: print("YES") else: print("NO") ```
vfc_35109
{ "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\nabacaba\nzyxaabcaabkjh\nonetwothree\nthreetwoone\none\nzzonneyy\none\nnone\ntwenty\nten\n", "output": "YES\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\ndaaaaaaaa...
code_contests
verifiable_code
1297_G. M-numbers
Solve the following coding problem using the programming language python: For a given positive integer m, a positive number is called a m-number if the product of its digits is m. For example, the beginning of a series of 24-numbers are as follows: 38, 46, 64, 83, 138, 146, 164, 183, 226 ... You are given a positive ...
vfc_35113
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "24 9\n", "output": "\n226\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "24 1\n", "output": "\n38\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
1321_B. Journey Planning
Solve the following coding problem using the programming language python: Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n. Tanya plans her journey as follows. First of all, she will choose some...
```python from sys import stdin, gettrace if not gettrace(): def input(): return next(stdin)[:-1] def main(): n = int(input()) bb = [int(a) for a in input().split()] seq = {} for i, b in enumerate(bb): if b - i in seq: seq[b-i] += b else: seq[b-i] =...
vfc_35117
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n8 9 26 11 12 29 14\n", "output": "55\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n10 7 1 9 10 15\n", "output": "26\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
1362_A. Johnny and Ancient Computer
Solve the following coding problem using the programming language python: Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is f...
```python # from debug import debug import math t = int(input()) for ii in range(t): a, b = map(int, input().split()) if a == b: print(0) else: b, a = min(a,b), max(a,b) if a%b: print(-1) else: aa = int(math.log2(a//b)) if pow(2, aa) == a//b: c = 0 c += aa//3 aa = aa%3 c += aa//2 ...
vfc_35125
{ "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": "10\n10 5\n11 44\n17 21\n1 1\n96 3\n2 128\n1001 1100611139403776\n1000000000000000000 1000000000000000000\n7 1\n10 8\n", "output": "1\n1\n-1\n0\n2\n2\n14\n0\n-1\n-1\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
1402_C. Star Trek
Solve the following coding problem using the programming language python: The United Federation of Planets is an alliance of N planets, they are indexed from 1 to N. Some planets are connected by space tunnels. In a space tunnel, a starship can fly both ways really fast. There are exactly N-1 space tunnels, and we can...
vfc_35133
{ "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\n1 2\n2 3\n", "output": "\n4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1471_A. Strange Partition
Solve the following coding problem using the programming language python: You are given an array a of length n, and an integer x. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was [3, 6...
```python from math import ceil t = int(input()) for _ in range(t): n,x = map(int,input().split()) a = list(map(int,input().split())) mx = 0 mn = 0 for y in a: mx += ceil(y/x) mn += y mn = ceil(mn/x) print(mn,mx) ```
vfc_35145
{ "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 3\n3 6 9\n3 3\n6 4 11\n", "output": "\n6 6\n7 8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1234\n1\n", "output": "1 1\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
175_B. Plane of Tanks: Pro
Solve the following coding problem using the programming language python: Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the...
```python from collections import defaultdict from bisect import bisect_left p, n = defaultdict(int), int(input()) for i in range(n): a, b = input().split() p[a] = max(p[a], int(b)) p, n = sorted((b, a) for a, b in p.items()), len(p) t = [0] + [bisect_left(p, (p[n - 1 - n // k][0], '')) for k in [2, 5, 10, 100]...
vfc_35161
{ "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\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250\n", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nvasya 200\nkol...
code_contests
verifiable_code
195_C. Try and Catch
Solve the following coding problem using the programming language python: Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that. The exceptions are processed by try-catch-...
```python import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf ASCIILOWER = 97 ASCIIUPPER = 65 def getInt(): return int(sys.stdin.readline().rstrip()) def getInts(): return map(int, sys.stdin.readline().rstrip().split(" ")) def getString(): return sys.stdin.readline().rstrip() def printO...
vfc_35165
{ "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": "8\ntry\n try\n throw ( AE ) \n catch ( BE, \"BE in line 3\")\n\n try\n catch(AE, \"AE in line 5\") \ncatch(AE,\"AE somewhere\")\n", "output": "AE somewhere\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
219_C. Color Stripe
Solve the following coding problem using the programming language python: A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1...
```python n,k=map(int,input().split()) s=input() if(k==2): #A sol1=[s[i] for i in range(n)] ans1=0 for i in range(n): if(i%2==0 and sol1[i]=="B"): ans1+=1 sol1[i]="A" elif(i%2!=0 and sol1[i]=="A"): ans1+=1 sol1[i]="B" #B so...
vfc_35169
{ "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": "3 2\nBBB\n", "output": "1\nBAB", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
242_E. XOR on Segment
Solve the following coding problem using the programming language python: You've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on this array: 1. Calculate the sum of current array elements on the segment [l, r], that is, count value al + al + 1 + ... + ar. 2....
vfc_35173
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 10 3 13 7\n8\n1 2 4\n2 1 3 3\n1 2 4\n1 3 3\n2 2 5 5\n1 1 5\n2 1 2 10\n1 2 3\n", "output": " 26\n 2...
code_contests
verifiable_code
268_C. Beautiful Sets of Points
Solve the following coding problem using the programming language python: Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points fro...
```python if __name__ == '__main__': nums = input().split() n = int(nums[0]) m = int(nums[1]) k = min(m, n) + 1 print(k) for i in range(k): print(str(i) + " " + str(k-1-i)) ```
vfc_35177
{ "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": "2 2\n", "output": "3\n0 2\n1 1\n2 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n", "output": "4\n0 3\n1 2\n2 1\n3 0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
290_F. Greedy Petya
Solve the following coding problem using the programming language python: Petya is an unexperienced programming contestant. Recently he has come across the following problem: You are given a non-directed graph which consists of n nodes and m edges. Your task is to determine whether the graph contains a Hamiltonian pa...
vfc_35181
{ "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": "10 20\n3 10\n4 6\n4 9\n7 5\n8 8\n3 10\n9 7\n5 2\n9 2\n10 6\n10 4\n1 1\n7 2\n8 4\n7 2\n1 8\n5 4\n10 2\n8 5\n5 2\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n1 2\n2...
code_contests
verifiable_code
316_C2. Tidying Up
Solve the following coding problem using the programming language python: Smart Beaver is careful about his appearance and pays special attention to shoes so he has a huge number of pairs of shoes from the most famous brands of the forest. He's trying to handle his shoes carefully so that each pair stood side by side....
vfc_35185
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 1 2\n2 3 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n1 3 2 6\n2 1 5 6\n4 4 5 3\n", "output": "4\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
339_C. Xenia and Weights
Solve the following coding problem using the programming language python: Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left ...
```python __author__ = 'ratnesh.mishra' weights = map(int, input()) weights = [cnt for cnt, x in enumerate(weights, 1) if x] m = int(input()) state = [(0, 0, 0, [])] res = "NO" while state: w, b, k, l = state.pop() if k == m: res = 'YES\n' + ' '.join(map(str, l)) break for wt in weigh...
vfc_35189
{ "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": "0000000101\n3\n", "output": "YES\n8 10 8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000\n2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
361_E. Levko and Strings
Solve the following coding problem using the programming language python: Levko loves strings of length n, consisting of lowercase English letters, very much. He has one such string s. For each string t of length n, Levko defines its beauty relative to s as the number of pairs of indexes i, j (1 ≤ i ≤ j ≤ n), such tha...
vfc_35193
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\nyx\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\nyz\n", "output": "26", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 ...
code_contests
verifiable_code
385_C. Bear and Prime Numbers
Solve the following coding problem using the programming language python: Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to r...
```python import math, sys input = sys.stdin.buffer.readline def ints(): return map(int, input().split()) n = int(input()) x = list(ints()) MAX = max(x) + 1 freq = [0] * MAX for i in x: freq[i] += 1 sieve = [False] * MAX f = [0] * MAX for i in range(2, MAX): if sieve[i]: continue for j in ra...
vfc_35197
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n", "output": "0\n7\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
406_B. Toy Sum
Solve the following coding problem using the programming language python: Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris. There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teache...
```python import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation Constructive? Top bottom up down """ n, =...
vfc_35201
{ "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\n1\n", "output": "1\n1000000 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 4 5\n", "output": "3\n1000000 999997 999996 ", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
433_C. Ryouko's Memory Note
Solve the following coding problem using the programming language python: Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and ...
```python def median(a): if len(a) == 0: return 0 if len(a) % 2 == 1: return a[len(a) // 2] else: return (a[len(a) // 2] + a[(len(a) // 2) - 1]) // 2 def profit(a, old_val): a.sort() med = median(a) sum_old = 0 sum_new = 0 for i in a: sum_old += abs(i - ...
vfc_35205
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5\n9 4 3 8 8\n", "output": " 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2 3 4 3 2\n", "output": " ...
code_contests
verifiable_code
455_E. Function
Solve the following coding problem using the programming language python: Serega and Fedor play with functions. One day they came across a very interesting function. It looks like that: * f(1, j) = a[j], 1 ≤ j ≤ n. * f(i, j) = min(f(i - 1, j), f(i - 1, j - 1)) + a[j], 2 ≤ i ≤ n, i ≤ j ≤ n. Here a is an integ...
vfc_35209
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 2 3 4 3 4\n4\n4 5\n3 4\n3 4\n2 3\n", "output": "12\n9\n9\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 3 2 3 4 0 2\n4\n4 5\n2 3\n1 4\n4 6\n", "output": "11\n4\n3\n0\n"...
code_contests
verifiable_code
478_C. Table Decorations
Solve the following coding problem using the programming language python: You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we ...
```python a = sorted(list(map(int, input().split()))) a[2] = min(a[2], 2 * (a[0] + a[1])) print(sum(a) // 3) ```
vfc_35213
{ "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": "1 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3...
code_contests
verifiable_code
500_E. New Year Domino
Solve the following coding problem using the programming language python: Celebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos User ainta, who lives in a 2D world, is going to post a video as well. There are n dom...
```python ''' from bisect import bisect,bisect_left from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import *''' #------------------------------------------------------------------------ ...
vfc_35217
{ "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\n1 5\n3 3\n4 4\n9 2\n10 1\n12 1\n4\n1 2\n2 4\n2 5\n2 6\n", "output": "0\n1\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1000000000\n999999999 1000000000\n1000000000 1000000...
code_contests
verifiable_code
526_C. Om Nom and Candies
Solve the following coding problem using the programming language python: A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? <im...
```python C, Hr, Hb, Wr, Wb = map(int, input().split()) ans = 0 for i in range(10 ** 5): if Wr * i <= C: ans = max(ans, Hr * i + (C - Wr * i) // Wb * Hb) for i in range(10 ** 5): if Wb * i <= C: ans = max(ans, Hb * i + (C - Wb * i) // Wr * Hr) print(ans) ```
vfc_35221
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3 5 2 3\n", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "922784684 566833132 755777509 3 4\n", "output": "174354977531116762", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
551_D. GukiZ and Binary Operations
Solve the following coding problem using the programming language python: We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: <image>? Here operation <image> means bitwise...
```python # -*- coding: utf-8 -*- from collections import deque def calc(n, m): if n == 1: return [[1, 0], [0, 1]] a = calc(n // 2, m) if n % 2 == 0: res00 = (a[0][0] * a[0][0]) % m res00 = (res00 + a[0][0] * a[1][0]) % m res00 = (res00 + a[0][1] * a[0][0]) % m res01...
vfc_35225
{ "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": "2 1 2 10\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
5_C. Longest Regular Bracket Sequence
Solve the following coding problem using the programming language python: This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()...
```python string = input() n = len(string) stack = [] mapping = [0]*n # First we create an array where the array called mapping where the index of array # gives the index of start of opening bracket in string and the value at that index # gives the index of closing bracket for corresponding opening bracket. for idx...
vfc_35233
{ "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": ")((())))(()())\n", "output": "6 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "))(\n", "output": "0 1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
622_A. Infinite Sequence
Solve the following coding problem using the programming language python: Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the nu...
```python n = int(input()) from math import sqrt # Find max m such that m(m+1)/2 <= n m = int((-1 + sqrt(1 + 8*n))/2) # l is the previous range l = m * (m + 1) // 2 print(m if n == l else n - l) ```
vfc_35237
{ "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": "56\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "55\n", ...
code_contests
verifiable_code
643_D. Bearish Fanpages
Solve the following coding problem using the programming language python: There is a social website with n fanpages, numbered 1 through n. There are also n companies, and the i-th company owns the i-th fanpage. Recently, the website created a feature called following. Each fanpage must choose exactly one other fanpag...
vfc_35241
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 12\n10 20 30 40 50\n2 3 4 5 2\n2 1\n2 2\n2 3\n2 4\n2 5\n1 4 2\n2 1\n2 2\n2 3\n2 4\n2 5\n3\n", "output": "10\n36\n28\n40\n36\n9\n57\n27\n28\n29\n9 57\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
670_D1. Magic Powder - 1
Solve the following coding problem using the programming language python: This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints...
```python n, k = input().split(" ") n, k = [int(n), int(k)] list1 = list(map(int, input().split(" "))) list2 = list(map(int, input().split(" "))) low = 0 high = 2*(10**9) while low < high: if high - low % 2 != 0: mid = low + (high - low) // 2 + 1 else: mid = low + (high - low)//2 d = k ...
vfc_35245
{ "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": "4 3\n4 3 5 6\n11 12 14 20\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n2 1 4\n11 3 16\n", "output": "4\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
691_F. Couple Cover
Solve the following coding problem using the programming language python: Couple Cover, a wildly popular luck-based game, is about to begin! Two players must work together to construct a rectangle. A bag with n balls, each with an integer written on it, is placed on the table. The first player reaches in and grabs a b...
vfc_35249
{ "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": "2\n5 6\n2\n30 31\n", "output": "2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 2 6 1 3\n4\n1 3 5 8\n", "output": "20\n18\n14\n10\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
717_A. Festival Organization
Solve the following coding problem using the programming language python: The Prodiggers are quite a cool band and for this reason, they have been the surprise guest at the ENTER festival for the past 80 years. At the beginning of their careers, they weren’t so successful, so they had to spend time digging channels to...
vfc_35253
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 2\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1...
code_contests
verifiable_code
737_C. Subordinates
Solve the following coding problem using the programming language python: There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior. There was a request to each of the workers to tell how how...
```python f = lambda: map(int, input().split()) n, s = f() c = [0] * n t = list(f()) for i in t: c[i] += 1 k = t[s - 1] c[k] -= 1 d = c[0] c += [d] d += k > 0 i, j = 1, n while i < j: if c[i]: i += 1 elif c[j]: c[j] -= 1 i += 1 d += j < n else: j -= 1 print(d) ```
vfc_35257
{ "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": "5 3\n1 0 0 4 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n2 0 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
761_B. Dasha and friends
Solve the following coding problem using the programming language python: Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length L, in distinct points of which there are n ...
```python n,l = map(int,input().split()) kefa = list(map(int,input().split())) sasha = list(map(int,input().split())) diff1 = [kefa[i+1] - kefa[i] if i != n - 1 else l - kefa[-1] + kefa[0] for i in range(n) ] diff2 = [sasha[i+1] - sasha[i] if i != n - 1 else l - sasha[-1] + sasha[0] for i in range(n) ] def rot...
vfc_35261
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 9\n2 3 5 8\n0 1 3 6\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n1 3\n1 2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
784_D. Touchy-Feely Palindromes
Solve the following coding problem using the programming language python: Input The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output Output "Yes" or "No". Examples Input 373 Output Yes Input 121 Output No Input 436 Output Yes Th...
```python # ⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚ # 1234567890 R = [ ("1", "' "), ("2", ": "), ("3", "''"), ("4", "':"), ("5", "'."), ("6", ":'"), ("7", "::"), ("8", ":."), ("9", ".'"), ("0", ".:"), ] s = input() for a,b in R: s = s.replace(a,b) print("Yes" if s==s[::-1] else "No") ```
vfc_35265
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "436\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "121\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "373\n", ...
code_contests
verifiable_code
805_C. Find Amir
Solve the following coding problem using the programming language python: A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them...
```python print(max((int(input()) + 1) // 2 - 1, 0)) ```
vfc_35269
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "20289\n", ...
code_contests
verifiable_code
830_C. Bamboo Partition
Solve the following coding problem using the programming language python: Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left...
```python import itertools unfold = itertools.chain.from_iterable def jumps(a): d = speedup while d < a - 1: c = (a + d - 1) // d d = (a + c - 2) // (c - 1) yield d def calc(d): return sum(d - 1 - (i - 1) % d for i in a) def ans(): for d, pd in zip(D, D[1:]): d -= 1 ...
vfc_35273
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 40\n10 30 50\n", "output": "32\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n1 3 5\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
851_D. Arpa and a list of numbers
Solve the following coding problem using the programming language python: Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1. Arpa can perform two types of operations: * Choose a number and dele...
vfc_35277
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 23 17\n1 17 17 16\n", "output": "40\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 6 2\n100 49 71 73 66 96 8 60 41 63\n", "output": "10\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
875_F. Royal Questions
Solve the following coding problem using the programming language python: In a medieval kingdom, the economic crisis is raging. Milk drops fall, Economic indicators are deteriorating every day, money from the treasury disappear. To remedy the situation, King Charles Sunnyface decided make his n sons-princes marry the ...
```python from sys import stdin from itertools import repeat def main(): n, m = map(int, stdin.readline().split()) dat = map(int, stdin.read().split(), repeat(10, 3 * m)) e = [(-dat[i*3+2], dat[i*3+1], dat[i*3]) for i in xrange(m)] e.sort() par = range(n + 1) c = [1] * (n + 1) st = [] po...
vfc_35281
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 2 5\n1 2 1\n2 1 10\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 2 10\n3 2 20\n", "output": "30\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
89_E. Fire and Ice
Solve the following coding problem using the programming language python: The Fire Lord attacked the Frost Kingdom. He has already got to the Ice Fortress, where the Snow Queen dwells. He arranged his army on a segment n in length not far from the city walls. And only the frost magician Solomon can save the Frost King...
```python n = int(input()) a = [0] * 1010 b = [0] * 2010 S = 1000000007 W=0 b = list(map(int,input().strip().split()))[:n] for i in range(0,n): a.insert(i,b[i]) while(not a[n-1]): n-=1 for w in range(0,n+1): for i in range(0,n): b[i]=a[i] for i in range(w,n): if(b[i]): b[i]-=...
vfc_35285
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 2 0\n", "output": "ARARALAARALA\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 0 1\n", "output": "ARARARALLLA\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
920_G. List Of Integers
Solve the following coding problem using the programming language python: Let's denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of L(x, p) are 1-indexed; for example, 9, 13 ...
```python import sys range = xrange input = raw_input big = 10**6 + 1 prime_div = [1]*big for p in range(2, big): if prime_div[p] == 1: for i in range(p, big, p): prime_div[i] = p inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 t = inp[ii]; ii += 1 out = [] for _ in range(t): x =...
vfc_35289
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n42 42 42\n43 43 43\n44 44 44\n45 45 45\n46 46 46\n", "output": "187\n87\n139\n128\n141\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
949_E. Binary Cards
Solve the following coding problem using the programming language python: It is never too late to play the fancy "Binary Cards" game! There is an infinite amount of cards of positive and negative ranks that are used in the game. The absolute value of any card rank is a power of two, i.e. each card has a rank of eithe...
vfc_35293
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 -2 14 18\n", "output": "3\n2 -4 16 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
977_D. Divide by three, multiply by two
Solve the following coding problem using the programming language python: Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n - 1 operations of the two kinds: * divide the number x by 3 (x must be divisible by 3); * multiply the number x ...
```python n = int(input()) li = list(map(int, input().split())) g = {} def dfs(e, v, order): if e not in v: v[e] = 1 if e % 3 == 0: if (e // 3) in g: order.append(e // 3) dfs(e // 3, v, order) if e * 2 in g: order.append(e * 2) ...
vfc_35297
{ "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": "4\n42 28 84 126\n", "output": "126 42 84 28 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1000000000000000000 3000000000000000000\n", "output": "3000000000000000000 10000000000...
code_contests
verifiable_code
997_B. Roman Digits
Solve the following coding problem using the programming language python: Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a se...
```python def solve(n): s = set() for i in range(0, n + 1): for v in range(0, n - i + 1): for x in range(0, n - i - v + 1): l = n - i - v - x s.add(i + v * 5 + x * 10 + l * 50) return len(s) n = int(input()) if n < 11: print(solve(n)) else: print...
vfc_35301
{ "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\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "244", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
code_contests
verifiable_code
battle-of-words
Solve the following coding problem using the programming language python: Alice and Bob are fighting over who is a superior debater. However they wish to decide this in a dignified manner. So they decide to fight in the Battle of Words. In each game both get to speak a sentence. Because this is a dignified battle, ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t=int(raw_input()) while(t): t-=1 s1=raw_input() s2=raw_input() c1=[] c2=[] for i in range(27): c1.append(0) c2.append(0) #print(c) for i in ...
vfc_35305
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\ni will win\nwill i\ntoday or tomorrow\ntoday or tomorrow and yesterday\ni dare you\nbad day\n\nSAMPLE", "output": "You win some.\nYou lose some.\nYou draw some.\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
climbing-stairs-1
Solve the following coding problem using the programming language python: Alice is climbing stairs. There are total N stairs. She climbs A stairs upwards in day and she comes downstairs in night by B stairs. Find number of days she will take to reach the top of staircase. Input: First and only line contains three...
```python import math x,y,z=map(eval, raw_input().split()) a,b,n=int(x),int(y),int(z) ans=math.ceil((float(n-b)/float(a-b))) print(int(ans)) ```
vfc_35309
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 6\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
exam-time-2
Solve the following coding problem using the programming language python: Geeko is in worry now because exam is coming up and he has to know what rank he can get in exams. So he go back into the school records and finds the amazing pattern. He finds that if a student is having a current rank n than his rank i...
```python def main(): from collections import defaultdict from itertools import count from fractions import gcd from operator import mul from sys import stdin,stdout def lcm(a, b): return a * b / gcd(a, b) primes_cache, prime_jumps = [], defaultdict(list) def primes(): ...
vfc_35313
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n4\n\nSAMPLE", "output": "4\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2000\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\...
code_contests
verifiable_code
higher-multiples-of-triangular-numbers
Solve the following coding problem using the programming language python: Archith loves to play with number series. Archith asked his girlfriend to a date. But she was busy in solving the homework on triangular series which stated that find the least number which has higher divisors than n in a triangular series. His ...
```python test = int(raw_input()) while test>0: n = int(raw_input()) if n==0: print 1 else: i = 2 while(1): x = i*(i+1)/2 j = 1 c = 0 while j<=x: if x%j==0: c+=1 j+=1 if c>n: print x break i+=1 test-=1 ```
vfc_35317
{ "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\n2\n3\n4\n\nSAMPLE", "output": "3\n6\n6\n28\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1\n2\n3\n7\n\nSAMPLE", "output": "3\n6\n6\n36\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
magic-of-sir-jadeja
Solve the following coding problem using the programming language python: Team India is playing too much cricket in this season. Team players are getting better in their performance with match by match. Sir Jadeja has become a Trump Card for M.S Dhoni. There is a hidden reason of his special position in the team. He c...
```python import math test = int(raw_input()) while test: test = test-1 l = [ "Rohit", "Dhawan", "Kohli", "Yuvraj", "Raina" , "Dhoni", "Sir Jadeja"] k = int(raw_input()) val = math.log(k/7.0+1)/math.log(2) n = int(math.ceil(val)) sn_1 = 7*(int(math.pow(2,n-1))-1) inte = math.ceil(((k-sn_1)/math.pow(2,n-1))) pri...
vfc_35321
{ "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\n9\n\nSAMPLE", "output": "Kohli\nRohit", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n509869197\n704921863\n747550363\n299599178\n307311852\n292108723\n323673613\n406319034\n5990...
code_contests
verifiable_code
next-lucky-number
Solve the following coding problem using the programming language python: Lucky numbers are defined as the numbers consisting only of digits 3 and 5. So, given a number N, you have to print the least lucky number strictly greater than N. Input: First line of input contains number of test cases T. Each test case conta...
```python def next_lucky(n): if len(n) == 0: return '' if int(n[0]) < 3: return '3'*len(n) elif int(n[0]) == 3: pos1 = int(n[0]+next_lucky(n[1:])) pos2 = int('5'+'3'*(len(n)-1)) possible = min(pos1,pos2) larger = max(pos1,pos2) if possible > int(n): ...
vfc_35325
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n2...
code_contests
verifiable_code
sherlock-and-numbers
Solve the following coding problem using the programming language python: Watson gives to Sherlock a bag of numbers [1, 2, 3 ... N] and then he removes K numbers A1, A2 ... AK from the bag. He now asks Sherlock to find the P'th smallest number in the bag. Input First line contains T, the number of test cases. Each te...
```python t = input(); while(t > 0): n, k, p = map(int, raw_input().split()); cl = p; a = [int(i) for i in raw_input().split()]; for i in range(0, k): if(a[i] <= cl): cl += 1; if(cl <= n): print cl; else: print -1; t -= 1; ```
vfc_35333
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 1 2\n1\n5 2 4\n1 3\n\nSAMPLE", "output": "3\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 1 2\n1\n5 2 4\n1 3\n\nMASPLE", "output": "3\n-1\n", "type": "stdin_std...
code_contests
verifiable_code
the-door-closing-game-5
Solve the following coding problem using the programming language python: Alice and Bob are taking a walk in the Land Of Doors which is a magical place having a series of N adjacent doors that are either open or close. After a while they get bored and decide to do something interesting. So they started closing the op...
```python t = int(raw_input()) for ti in range(t): door = raw_input() n = len(door) i = 0 op = [] while i<n: if door[i] == '_': j = 1 while i<n and door[i]== '_': i += 1 j += 1 op.append(j-1) i += 1 #print op if not op: print "Bob" elif len(op)==1 and op[0]<=n-1: print "Alice" elif l...
vfc_35337
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n_|_\n|||\n|__\n|__||_|\n\nSAMPLE", "output": "Bob\nBob\nAlice\nAlice\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n_|_\n|||\n__|\n|__||_|\n\nSAMPLE", "output": "Bob\nBob\nAli...
code_contests
verifiable_code
xsquare-and-balanced-strings
Solve the following coding problem using the programming language python: Xsquare got bored playing with the arrays all the time. Therefore he has decided to buy a string S consists of N lower case alphabets. Once he purchased the string, He starts formulating his own terminologies over his string S. Xsquare calls a s...
```python t = int(raw_input()) for i in range(t): flag = 0 s = raw_input() d = {} for j in s: d[j] = d.get(j,0) + 1 for j,k in d.iteritems(): if(k%2 != 0): flag = 1 break if flag == 1: print -1 else: print 1 ```
vfc_35341
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nelle\njason\nimmi SAMPLE", "output": "1\n-1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\ngaagpguggxggpxupuaxxuaxxpuaaxuagxpxuauagauggpupapaauaugaugxugppguggxxagpapxpgpaxuugag...
code_contests
verifiable_code
p00076 Treasure Hunt II
Solve the following coding problem using the programming language python: As I was cleaning up the warehouse, I found an old document that describes how to get to the treasures of my ancestors. The following was written in this ancient document. 1. First, stand 1m east of the well on the outskirts of the town and tu...
```python # AOJ 0076 Treasure Hunt II # Python3 2018.6.15 bal4u import math MAX = 1005 r, d = [0.0]*MAX, [0.0]*MAX r[1] = 1.0 for i in range(2, MAX): d[i] = d[i-1] + math.atan(1 / r[i-1]) r[i] = math.sqrt(r[i-1]**2 + 1) while True: i = int(input()) if i < 0: break print(r[i]*math.cos(d[i]), r[i]*math.sin(d[i]),...
vfc_35385
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6\n-1", "output": "0.29\n1.71\n-2.31\n0.80", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n-1", "output": "0.292893218813 1.70710678119\n1.0 1.0\n", "type": "stdin_stdou...
code_contests
verifiable_code
p00208 Room Numbers of a Hospital
Solve the following coding problem using the programming language python: An architect, Devunky, who lives in Water Deven, has been asked to renovate an old large hospital. In some countries, people don't want to use numbers that are disliked as numerophobia (4 and 9 are famous in Japan). However, the room numbers in...
```python from sys import stdin l=stdin.readlines() for i in l[:-1]:print(oct(int(i))[2:].translate(str.maketrans("4567","5789"))) ```
vfc_35389
{ "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": "15\n100\n1000000000\n3\n0", "output": "19\n155\n9358757000\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n100\n1000000000\n1\n0", "output": "19\n155\n9358757000\n1\n", "t...
code_contests
verifiable_code
p00722 Dirichlet's Theorem on Arithmetic Progressions
Solve the following coding problem using the programming language python: Good evening, contestants. If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many prime numbers. This fact is known ...
```python MAXN = 10**6 sieve = [0]*2 + [1]*MAXN n = 2 while n*n <= MAXN: if sieve[n]: for i in range(2*n,MAXN+1,n): sieve[i] = 0 n += 1 while True: a,d,n = map(int,input().split()) if n == 0: break cnt = 0 for i in range(a,MAXN+1,d): if sieve[i]: cnt += 1...
vfc_35401
{ "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": "367 186 151\n179 10 203\n271 37 39\n103 230 1\n27 104 185\n253 50 85\n1 1 1\n9075 337 210\n307 24 79\n331 221 177\n259 170 40\n269 58 102\n0 0 0", "output": "92809\n6709\n12037\n103\n93523\n14503\n2\n899429\n5107\n412717\n226...
code_contests
verifiable_code
p00862 Most Distant Point from the Sea
Solve the following coding problem using the programming language python: The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: "Where is the most distant point from the sea?" The answer to this question for Honshu was found in 1996. The most dista...
vfc_35405
{ "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\n0 0\n10000 0\n10000 10000\n0 10000\n3\n0 0\n10000 0\n7000 1000\n6\n0 40\n100 20\n250 40\n250 70\n100 90\n0 70\n3\n0 0\n10000 10000\n5000 5001\n0", "output": "5000.000000\n494.233641\n34.542948\n0.353553", "type": "st...
code_contests
verifiable_code
p01125 Misterious Gems
Solve the following coding problem using the programming language python: From 1603 to 1867, people call that era the EDO era. EDO stands for Enhanced Driving Operation, the most advanced space navigation technology at the time, and was developed by Dr. Izy in 1603. You are a space adventurer, flying around the unive...
```python #coding: utf-8 if __name__ == '__main__': while True: n = int(input()) if n == 0: break flag = [] for i in range(21): flag.append([0 for j in range(21)]) for i in range(n): x,y = map(int,input().split()) flag[x][y] = ...
vfc_35413
{ "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\n10 11\n11 12\n2\nN 2\nE 1\n2\n10 11\n11 12\n2\nN 2\nW 1\n3\n0 15\n5 10\n5 15\n5\nW 10\nS 10\nN 20\nE 10\nS 10\n0", "output": "Yes\nNo\nNo", "type": "stdin_stdout" }, { "fn_name": null, "input": "2...
code_contests
verifiable_code
p01264 Magical Island
Solve the following coding problem using the programming language python: This is a story in the epoch of magic. A clan of magicians lived in an artificial island built by magic power. One day, a crisis erupted on the island. An Empire ACM (Atlas Country of Magic) required unconditional surrender to them, otherwise a...
vfc_35417
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 1\n10 15 5\n15 10 100\n0 0 0", "output": "8.000\n409.479\n861.420", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n10 13 5\n15 10 100\n0 0 0", "output": "7.9999998509\n347.88...