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
827_F. Dirty Arkady's Kitchen
Solve the following coding problem using the programming language python: Arkady likes to walk around his kitchen. His labyrinthine kitchen consists of several important places connected with passages. Unfortunately it happens that these passages are flooded with milk so that it's impossible to pass through them. Name...
vfc_59001
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n1 2 1 100\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n1 2 0 1\n2 5 2 3\n2 5 0 1\n1 3 0 1\n3 4 1 2\n4 5 2 3\n", "output": "3\n", "type": "stdin_s...
code_contests
verifiable_code
84_A. Toy Army
Solve the following coding problem using the programming language python: The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on the playing fiel...
```python n=int(input()) print((n*3)//2) ```
vfc_59005
{ "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": "2\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "6", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
898_C. Phone Numbers
Solve the following coding problem using the programming language python: Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n s...
```python n=int(input()) dic={} for i in range(n): l=list(map(str,input().split())) s1=l[0] if s1 in dic.keys(): dic[l[0]]+=list(set(l[2:])) else: dic[l[0]]=list(set(l[2:])) print(len(dic.keys())) for ix in dic.keys(): l=dic[ix][:] ll=len(l) lln=[1 for i in range(ll)] for...
vfc_59013
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n", "output": "2\ndasha 2 23 789 \nivan 4 123 2 456 789 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
919_D. Substring
Solve the following coding problem using the programming language python: You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value...
```python from collections import defaultdict import sys from sys import stdin def check(a): for i in a: if i: return True return False def change(x): return ord(x)-ord('a') def solve(): n, m = map(int, stdin.readline().split()) s = input() d = {} for i in range(n): ...
vfc_59017
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n",...
code_contests
verifiable_code
975_A. Aramic script
Solve the following coding problem using the programming language python: In Aramic language words can only represent objects. Words in Aramic have special properties: * A word is a root if it does not contain the same letter more than once. * A root and all its permutations represent the same object. * The...
```python n=int(input()) s=input() a=s.split(" ") visited=[] for i in range(len(a)): visited.append(0) arr=[] for g in range(len(a)): aux=[] for h in range(26): aux.append(0) arr.append(aux) for x in range(len(a)): for y in range(len(a[x])): if(arr[x][ord(a[x][y])-97]==0): arr[x][ord(a[x][y])-97]+=1 ...
vfc_59025
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\na aa aaa ab abb\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\namer arem mrea\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
994_F. Compute Power
Solve the following coding problem using the programming language python: You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume. You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up...
```python # Codeforces Round #488 by NEAR (Div. 2) import collections from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import math import sys def getIntList(): return list(map(int, input().split())) import bisect def makePair(z): return [(z[i], z[i+1]) for i in ...
vfc_59029
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n8 10 9 9 8 10\n1 10 5 5 1 10\n", "output": "1160\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n8 10 9 9 8 10\n1 1 1 1 1 1\n", "output": "9000\n", "type": "stdin_stdout"...
code_contests
verifiable_code
back-to-hostel
Solve the following coding problem using the programming language python: After a long vacation due to Swine Flu, 1st Year SVNIT students have returned back to Gajjar Bhavan. Students in Gajjar Bhavan generally handshake to greet each other but due to Swine Flu it's still risky to handshake so students greet each othe...
```python pr=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, ...
vfc_59033
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nhellolleh\nnaman\nracecar\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\ndoggod\nmanoman\npq\npp", "output": "1\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
chotu-and-kiss-day
Solve the following coding problem using the programming language python: "It all started with a kiss." Chotu was up all night, planning for his first kiss. He has collected the data about all the kissing spots in Allahabad. According to his survey there are N kissing spots in the city, each spot i is associated with...
```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!' import sys n=input() s=[int(i) for i in raw_input().split()] t=input() s.sort() for i in range(n): x=t-s[i] l=0 r=n-1 while(l<r): if s[l]+s[r]==...
vfc_59037
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 5 4 7 8 9\n17\n\nSAMPLE", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2000\n308095650 7015368 43054200 326309191 23209200 4883080 31325775 4954880 6043960 52877600 20...
code_contests
verifiable_code
easy-strong-permutation
Solve the following coding problem using the programming language python: Kevin has a sequence of integers a1, a2, ..., an. Define the strength of the sequence to be |a1 - a2| + |a2 - a3| + ... + |an-1 - an| + |an - a1|. Kevin wants to make his sequence stronger, so he reorders his sequence into a new sequence b1, b...
```python t=int(raw_input()) l=list(map(int,raw_input().split(" "))) l.sort() m=[] for j in range(len(l)//2): m.append(l[j]) m.append(l[len(l)-j-1]) if(len(l)%2!=0): m.append(l[len(l)//2]) s=0 for h in range(len(m)-1): s=s+abs(m[h]-m[h+1]) s=s+abs(m[len(m)-1]-m[0]) print s ```
vfc_59041
{ "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 2 4 8\n\nSAMPLE", "output": "18", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
harry-the-mathemagician-2
Solve the following coding problem using the programming language python: Hermione is very good in Magic but she is not good enough in Mathematics. She got stuck in a problem of mathematics in which she has to find out whether a combination M objects out of N is even or odd. Harry is quite good in mathematics so Herm...
```python for t in range(input()): n,r=map(long,raw_input().split()) if n>=r: if (r & n-r): print "even" else: print "odd" else: print "odd" ```
vfc_59045
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 5\n4 2\n\nSAMPLE", "output": "even\neven", "type": "stdin_stdout" }, { "fn_name": null, "input": "3040\n35 12\n5656 3334\n26 0\n22 3\n1882 388\n4444 222\n2772 666\n882 77\n2888 902\n7888881 992...
code_contests
verifiable_code
love-letter
Solve the following coding problem using the programming language python: Bubli and shivani are in lab. Bubli wants to send a message to shivani. But he can't send it directly. Bubli is on 1st computer and shivani is on the nth computer. Now the computer's are connected in a chain. 1st is connected to 2nd, 2nd is conn...
```python t=int(input()) while (t>0): s = raw_input() tokens = s.split() n= int(tokens[0]) k = int(tokens[1]) temp=k%(2**n) if(temp==0): print("NO") elif(temp==(2**n)-1): print("YES") else: print("NO") t=t-1 ```
vfc_59049
{ "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 0\n1 1\n4 0\n4 47\n\nSAMPLE", "output": "NO\nYES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1234\n14 6497127\n28 4107028\n24 8965184\n17 8442797\n10 3146702\n3 5796012\n...
code_contests
verifiable_code
mystery-9
Solve the following coding problem using the programming language python: Solve the mystery. Input The first line contains T, the number of test cases. T lines follow each containing a single integer N. Output Output the answer for each test case in a new line. Constraints 1 ≤ T ≤ 10^5 1 ≤ N ≤ 365 NOTE There...
```python t = input() for i in xrange(t): n = input() if n > 0 and n < 32: print 1 elif n < 60: print 2 elif n <91: print 3 elif n < 121: print 4 elif n < 152: print 5 elif n < 182: print 6 elif n < 213: print 7 elif n < 244: print 8 elif n < 274: print 9 elif n < 305: print 10 elif n < ...
vfc_59053
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10\n60\n100\n200\n360\n\nSAMPLE", "output": "1\n3\n4\n7\n12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n58\n309\n306\n350\n252\n196\n233\n343\n85\n175\n262\n226\n217\n124\n275\...
code_contests
verifiable_code
problem-2-22
Solve the following coding problem using the programming language python: Rama is in love with geometry. So once he was playing with circles and rectangles. Given the center of circle and radius and also the co-ordinates of vertices of rectangle, he wants to check whether the rectangle lies inside the circle or not. ...
```python for t in xrange(int(raw_input())): r,xc,yc=map(int,raw_input().split()) ans=0 for i in xrange(4): x,y=map(int,raw_input().split()) if (xc-x)**2 + (yc-y)**2>r**2: ans=1 if ans: print "No" else: print "Yes" ```
vfc_59057
{ "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 0 0\n-3 2\n2 2\n2 -2\n-3 -2\n\nSAMPLE", "output": "Yes\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
selection-of-cities-2
Solve the following coding problem using the programming language python: James has decided to take a break from his work. He makes a plan to visit India for a few days with his family. He knows a lot about India, and also about the various cities he could visit. He decides to write down all the cities on a paper. Let...
```python t = int(raw_input()) if(t>=1 and t<=100000): i=0 while(i<t): n = int(raw_input()) if(n>=1 and i<=1000000000000): print(pow(2,n,1000000007)-1) i = i+1 ```
vfc_59061
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n1\n\nSAMPLE", "output": "3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "47\n100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n20\n20\n20\n20\n20\n20\n...
code_contests
verifiable_code
th-ultimate-digit
Solve the following coding problem using the programming language python: Rohit was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives two numbers a and b. The problem consist in find the last digit of the potency...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t=input() i=0 while i<t: aa=raw_input() a=aa.split(' ') a1=long(a[0]) b1=long(a[1]) a1=a1%10 a1=a1**b1 c=a1%10 print "%s" %(str(c)) i=i+1 ```
vfc_59065
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 10\n6 2\n150 53\n\nSAMPLE", "output": "9\n6\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n089417618666542724942450052819161239869114727739037965995575150816905689947252007078...
code_contests
verifiable_code
xaviers-assignment
Solve the following coding problem using the programming language python: Xavier is a computer science student.He is given a task by his teacher the task is to generate a code which accepts an array of n integers.He now has to select an integer from this array but there is a trick in selection of integer from the arr...
```python n=input() arr=map(int,raw_input().split()) even=[] odd=[] for i in xrange(n): if arr[i]%2:odd.append(arr[i]) else:even.append(arr[i]) even.sort() odd.sort() m=input()-1 j=0 c=0 for i in xrange(n-1): pos=(m+j)%(n-c) del arr[pos] j=pos c+=1 if arr[0]%2: for i in xrange(len(odd)): print odd[i], else: for...
vfc_59069
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3 5 7 1 2 8\n3\n\nSAMPLE", "output": "1 3 5 7\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00062 What is the Bottommost?
Solve the following coding problem using the programming language python: Consider creating the following number pattern. 4 8 2 3 1 0 8 3 7 6 2 0 5 4 1 8 1 0 3 2 5 9 5 9 9 1 3 7 4 4 4 8 0 4 1 8 8 2 8 4 9 6 0 0 2 5 6 0 2 1 6 2 7 8 Five This pattern follows the rules below. A B C In the sequence of numbers, C is...
```python while True: try: L = [int(x) for x in list(input())] except: break T =[] while len(L) > 1: for i in range(len(L)-1): T.append( (L[i] + L[i+1])%10 ) L = T[:] T = [] print(L[0]) ```
vfc_59113
{ "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": "4823108376\n1234567890\n0123456789", "output": "5\n6\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4823108376\n2273064329\n0123456789", "output": "5\n1\n4\n", "type": "stdin...
code_contests
verifiable_code
p00193 Convenience Store
Solve the following coding problem using the programming language python: Convenience store Deven Eleven is planning to open its first store in Aizuwakamatsu City to expand its business. There are already many other convenience stores in Aizuwakamatsu, so the place to open a new store is likely to be the key to succes...
```python import sys def generate_next_hexes(x, y): hexes = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)] if y % 2: hexes += [(x - 1, y - 1), (x - 1, y + 1)] else: hexes += [(x + 1, y - 1), (x + 1, y + 1)] return hexes def update_map(hex_map, hexes): num_updated_hexes = 0 di...
vfc_59117
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6\n6\n1 1\n6 1\n3 2\n3 5\n1 6\n5 6\n2\n1 3\n5 3\n6 6\n6\n3 2\n3 5\n6 1\n1 1\n1 6\n5 6\n2\n2 3\n5 3\n0 0", "output": "4\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n6\n1 1\n6 1\n...
code_contests
verifiable_code
p00544 Russian Flag
Solve the following coding problem using the programming language python: problem President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red. ...
```python #C inf = float("inf") N,M = map(int,input().split()) flag = [list(str(input())) for i in range(N)] WBR = [] for i in range(N): w = flag[i].count("W") b = flag[i].count("B") r = flag[i].count("R") WBR.append([w,b,r]) ans = inf for w in range(N-2): for b in range(N-1): if ...
vfc_59125
{ "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": "4 5\nWRWRW\nBWRWB\nWRWRW\nRWBWR", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\nWRWRW\nBRWWB\nWRWRW\nRWBWR", "output": "11\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p00708 Building a Space Station
Solve the following coding problem using the programming language python: You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. The space station is made up with a number of units, ...
```python # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1127 # クラスカル or プリム法 import math class UnionFind: def __init__(self, n): self.n = n # 各要素の親要素の番号を格納するリスト # 根がルートの時は、グループの要素数を格納 最初は全て根で要素数1 self.parents = [-1] * n # 再帰 groupの根を返す # 経路圧縮あり def find(s...
vfc_59129
{ "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\n10.000 10.000 50.000 10.000\n40.000 10.000 50.000 10.000\n40.000 40.000 50.000 10.000\n2\n30.000 30.000 30.000 20.000\n40.000 40.000 40.000 20.000\n5\n5.729 15.143 3.996 25.837\n6.013 14.372 4.818 10.671\n80.115 63.292 84.477 15...
code_contests
verifiable_code
p00847 Cubic Eight-Puzzle
Solve the following coding problem using the programming language python: Let's play a puzzle using eight cubes placed on a 3 × 3 board leaving one empty square. Faces of cubes are painted with three colors. As a puzzle step, you can roll one of the cubes to the adjacent empty square. Your goal is to make the specifi...
vfc_59133
{ "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 2\nW W W\nE W W\nW W W\n2 1\nR B W\nR W W\nE W W\n3 3\nW B W\nB R E\nR B R\n3 3\nB W R\nB W R\nB E R\n2 1\nB B B\nB R B\nB R E\n1 1\nR R R\nW W W\nR R E\n2 1\nR R R\nB W B\nR R E\n3 2\nR R R\nW E W\nR R R\n0 0", "output": "...
code_contests
verifiable_code
p00979 Fast Forwarding
Solve the following coding problem using the programming language python: Fast Forwarding Mr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scenes in all such films. He now wants to find how to wind the tap...
```python #!/usr/bin/python3 import os import sys def main(): T = read_int() print(solve(T)) def solve(T): if T <= 3: return T sec = 1 T -= 1 f = 3 while T >= 2 * f: T -= 2 * f f *= 3 sec += 2 if T >= f: T -= f sec += 1 else: ...
vfc_59137
{ "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": "19", "output": "5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01111 Skyscraper MinatoHarukas
Solve the following coding problem using the programming language python: Skyscraper "MinatoHarukas" Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show ad...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in ...
vfc_59141
{ "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": "15\n16\n2\n3\n9699690\n223092870\n847288609\n900660121\n987698769\n999999999\n0", "output": "1 5\n16 1\n2 1\n1 2\n16 4389\n129 20995\n4112949 206\n15006 30011\n46887 17718\n163837 5994", "type": "stdin_stdout" } ]...
code_contests
verifiable_code
p01249 Billion Million Thousand
Solve the following coding problem using the programming language python: A linguist, Nodvic Natharus Damenhof (commonly called Dr. Usoperant), invented an artificial language Usoperant in 2007. The word usoperant means ‘one which tires’. Damenhof’s goal was to create a complex and pedantic language that would remind ...
vfc_59145
{ "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\nbillion 9\nmillion 6\nthousand 3\nbillionmillionthousand\n3\noku 8\nsen 3\nman 4\nokusenman\n2\nnico 2\nvideo 4\nniconicovideo\n6\nabcd 1\nefgh 2\nabcde 4\nfgh 6\ny 8\nyy 10\nabcdefgh\n0", "output": "Case 1: 14\nCase 2: 9\...
code_contests
verifiable_code
p01564 Do use segment tree
Solve the following coding problem using the programming language python: Given a tree with n (1 ≤ n ≤ 200,000) nodes and a list of q (1 ≤ q ≤ 100,000) queries, process the queries in order and output a value for each output query. The given tree is connected and each node on the tree has a weight wi (-10,000 ≤ wi ≤ 1...
vfc_59153
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 262144000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 5\n-8 5 5 5 5 5 5\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n2 3 7 0\n2 5 2 0\n2 4 3 0\n1 1 1 -1\n2 3 7 0", "output": "12\n10\n10\n19", "type": "stdin_stdout" }, { "fn_name": null, "input": "21 30\n10 0 -10 -8...
code_contests
verifiable_code
p01864 Travel Support
Solve the following coding problem using the programming language python: G: Travel Support-Travel Support- story I, Honoka Kosaka, 16 years old! I'm a student idol! !! In order to give a live performance to convey the goodness of student idols to everyone, we invite many student idols to perform live at Akiba Stad...
vfc_59161
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6\n100 80 70 60 50\n1 2 500\n2 5 100\n1 3 400\n1 4 200\n3 5 700\n4 5 800\n1\n5 3 600", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n100 80 70 60 50\n1 2 500\n2 5 100\n...
code_contests
verifiable_code
p02145 Shiritori
Solve the following coding problem using the programming language python: Problem Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules. 1. First of all, select one of your favorite strings from the list and exclude that string from the list. 2...
```python import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy f...
vfc_59169
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nyou\nate\nmy\nhum\ntoast", "output": "e\nt\nu", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\nshe\nsells\nsea\nshells\nby\nthe\nseashore", "output": "a\ne\ny", "type": "std...
code_contests
verifiable_code
p02286 Treap
Solve the following coding problem using the programming language python: A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shu...
```python from random import random from collections import deque from copy import deepcopy import sys input = sys.stdin.readline class Treap: def __init__(self, iterable=None): # vertex = [left, right, key, priority, #descendants, sum of descendants] self.root = None if iterable: self._con...
vfc_59173
{ "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": "16\ninsert 35 99\ninsert 3 80\ninsert 1 53\ninsert 14 25\ninsert 80 76\ninsert 42 3\ninsert 86 47\ninsert 21 12\ninsert 7 10\ninsert 6 90\nprint\nfind 21\nfind 22\ndelete 35\ndelete 99\nprint", "output": "1 3 6 7 14 21 35 42 ...
code_contests
verifiable_code
anagram
Solve the following coding problem using the programming language python: Note: For Turbo C++, select "Text" as your language Resubmit your incorrect solutions to the Debugging problems, if you were getting template errors for Java and Python. Problem Description: IIITD is hosting a guessing game. The game starts wit...
```python def sort_array ( array , length): for c in range(0,length-1): for d in range(0,(length-c)-1): if array[d] > array[d+1] : temp=array[d] array[d]=array[d+1] array[d+1] = temp a1 = raw_input() a = list(a1) b1 = raw_input() b = list(b1) l1=...
vfc_59181
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abcd\nfedb", "output": "No\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chn15b
Solve the following coding problem using the programming language python: Petr is organizing Petr Mitrichev Contest #11. The top N coders according to codechef ratings (excluding Petr himself) agreed to participate in the contest. The participants have been ranked from 0 to N-1 according to their ratings. Petr had ask...
```python for _ in range(input()): n = input() arr = map(int, raw_input().split()) count = 0 # Stores the count of the number of lazy people for i in arr: if i == -1 : count += 1 count -= 1 # to exclude Gennady print (1+float(count)/2) ```
vfc_59185
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n-1 -1 1 2 1", "output": "1.5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
epi01
Solve the following coding problem using the programming language python: This is the algorithmic version of a game that kids play in our part of the country. You will be provided with a few sticks. The length of the sticks will be in the order of powers of 2. (1,2,4,8,16,32....). You will also be given another test s...
```python #!/usr/bin/python num = int(raw_input()) div = 8192 count = 0 while div > 0: if num >= div: count = count + 1 num = num - div div = div / 2 print count ```
vfc_59189
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
kjcc05
Solve the following coding problem using the programming language python: Chef loves palindromes. Chef initially has odd number of charachters. Chef wants to create a palindrome of maximum even length using these characters. For this Chef needs to discard one character. Help Chef find the character which needs to be d...
```python # cook your code here def findOccurences(s, ch): return [i for i, letter in enumerate(s) if letter == ch] t=int(raw_input()) while(t>0): n=int(raw_input()) s=raw_input() i=0 while(i<n): r=findOccurences(s,s[i]) r=len(r) if(r%2==1): print(s[i]) ...
vfc_59193
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7\nabcbdca\n3\nabb", "output": "d\na", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p1z2s
Solve the following coding problem using the programming language python: Phantasialand boasts of its famous theme park. The park is frequently visited. It is quite large park that some tourists visit it more than once to fully appreciate its offerings. One day, our Chefs decided to visit the park. There are total n C...
```python n = input() t = map(int, raw_input().split()) arr = [2]*n count = n t.sort() for i in xrange(0, n): if arr[i] - t[i] > 0: if i != n-1: arr[i+1]+= arr[i] - t[i] #print arr arr[i] = t[i] #print arr elif arr[i] - t[i] < 0: count+= ((t[i...
vfc_59197
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 1", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3 3", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2...
code_contests
verifiable_code
sprlnms
Solve the following coding problem using the programming language python: Dennis is programming a robot that is supposed to paint a horizontal line. Not being one to care much about efficiency, Dennis programs the robot to move in an anti-clockwise spiral as shown below. 0 1 10 6 7 8 9 The robot starts at positio...
```python import math t=input() while(t): t=t-1 n=input() if n==0: print 0 elif n==1: print 1 else: p=2*n-1 m=math.pow(p,2) m=m+n-1 print int(m) ```
vfc_59201
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0\n1\n2", "output": "0\n1\n10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1\n1\n2", "output": "1\n1\n10\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
1006_C. Three Parts of the Array
Solve the following coding problem using the programming language python: You are given an array d_1, d_2, ..., d_n consisting of n integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, an...
```python x = int(input()) v = list(map(int,input().strip().split()))[:x] i = 0 j = x-1 s1 = 0 s2 = 0 ans = 0 while(i<=j): if(s2<s1): s2+=v[j] j=j-1 else: s1+=v[i] i=i+1 if(s1==s2): ans=s1 print(ans) ```
vfc_59205
{ "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\n4 1 2\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
102_B. Sum of Digits
Solve the following coding problem using the programming language python: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. ...
```python num = input() c = 0 while(len(num) != 1): num = str(sum(int(i) for i in num)) c += 1 print(c) ```
vfc_59209
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 265000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "991\n", ...
code_contests
verifiable_code
1051_B. Relatively Prime Pairs
Solve the following coding problem using the programming language python: You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) ≤ 3 ⋅ 10^5 and (r - l) is always odd. You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common d...
```python l,r=map(int,input().split()) print('YES') for i in range((r-l+1)//2): print(l+i*2,l+i*2+1) ```
vfc_59213
{ "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": "1 8\n", "output": "YES\n1 2\n3 4\n5 6\n7 8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 12\n", "output": "YES\n3 4\n5 6\n7 8\n9 10\n11 12\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
1073_C. Vasya and Robot
Solve the following coding problem using the programming language python: Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0, 0). Robot can perform the following four kinds of operations: * U — move from (x, y) to (x, y + 1); * D — move from (x, y) to (x, y - 1); ...
```python # -*- coding: utf-8 -*- """ created by shhuan at 2018/11/3 11:30 search for minimum steps, consider binary search """ N = int(input()) ops = [x for x in input()] X, Y = map(int, input().split()) dd = abs(X) + abs(Y) lops = len(ops) if dd > lops or (lops - dd) % 2 != 0: print(-1) exit(0) [ll, ...
vfc_59217
{ "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\nRURUU\n-2 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nRULR\n1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1114_D. Flood Fill
Solve the following coding problem using the programming language python: You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i. Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for...
```python def run_length_compress(string): string = string + ["."] n = len(string) begin = 0 end = 1 cnt = 1 ans = [] while True: if end >= n: break if string[begin] == string[end]: end += 1 cnt += 1 else: ans.append(...
vfc_59225
{ "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": "1\n4\n", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1142_E. Pink Floyd
Solve the following coding problem using the programming language python: This is an interactive task. Scientists are about to invent a new optimization for the Floyd-Warshall algorithm, which will allow it to work in linear time. There is only one part of the optimization still unfinished. It is well known that the...
vfc_59229
{ "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": "4 2\n1 2\n3 4\n0\n1\n1", "output": "? 1 3\n? 3 2\n! 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "200 0 genorder\n0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
code_contests
verifiable_code
1163_A. Eating Soup
Solve the following coding problem using the programming language python: The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party... What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now n cats are at t...
```python n , m = map(int,input().split()) import math if n==m: print(0) elif m==0: print(1) elif m==1: print(1) else: if n%2==0: if n//2==m: print(n//2) elif m>n//2: print(n-m) else: print(m) else: if math.ceil(n//2)==m or math.flo...
vfc_59233
{ "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 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n",...
code_contests
verifiable_code
1183_F. Topforces Strikes Back
Solve the following coding problem using the programming language python: One important contest will take place on the most famous programming platform (Topforces) very soon! The authors have a pool of n problems and should choose at most three of them into this contest. The prettiness of the i-th problem is a_i. The...
```python from sys import stdin from itertools import tee def input(): return stdin.readline() def remove_divisors(x, xs): return [y for y in xs if y%xs != 0] q = int(input()) for _ in range(q): n = int(input()) aas = list(set(map(int,input().split()))) aas.sort(reverse=True) # if len(aas) >...
vfc_59237
{ "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": "3\n4\n5 6 15 30\n4\n10 6 30 15\n3\n3 4 6\n", "output": "30\n31\n10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n9\n7 4 2 2 2 2 2 2 2\n", "output": "11\n", "type": "stdin_...
code_contests
verifiable_code
1201_A. Important Exam
Solve the following coding problem using the programming language python: A class of students wrote a multiple-choice test. There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for ...
```python def get_ints(): return list(map(int, input().split())) N, M = get_ints() a = [input() for i in range(N)] s = get_ints() ans=0 for i in range(M): d = {} for row in a: c = ord(row[i])-65 if c in d: d[c]+=1 else: d[c]=1 ans += max(d.values())*s[i]...
vfc_59241
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\nABC\nBCD\nCDE\n5 4 12\n", "output": "21", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\nABCD\nABCE\n1 2 3 4\n", "output": "16", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1218_I. The Light Square
Solve the following coding problem using the programming language python: For her birthday Alice received an interesting gift from her friends – The Light Square. The Light Square game is played on an N × N lightbulbs square board with a magical lightbulb bar of size N × 1 that has magical properties. At the start of ...
```python N = input() a, b = [], [] for n in range(N) : a.append(raw_input()) for n in range(N) : b.append(raw_input()) wand = raw_input() piv = -1 if wand.count('1') == 0 else wand.index('1') def getVar(ca, row, col) : v = int(a[row][col]) ^ (int(wand[row])*ca[col]) if v == v ^ int(wand[col]) : if v =...
vfc_59245
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10\n00\n00\n00\n10\n", "output": "1\ncol 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n11\n11\n00\n01\n11\n", "output": "-1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1243_A. Maximum Square
Solve the following coding problem using the programming language python: Ujan decided to make a new wooden roof for the house. He has n rectangular planks numbered from 1 to n. The i-th plank has size a_i × 1 (that is, the width is 1 and the height is a_i). Now, Ujan wants to make a square roof. He will first choose...
```python n=int(input()) for _ in range(n): i=int(input()) ar=sorted(list(map(int,input().split())))[::-1] mx=0 for e in range(i): mx=max(mx,min(e+1,ar[e])) print(mx) ```
vfc_59249
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n4 3 1 4 5\n4\n4 4 4 4\n3\n1 1 1\n5\n5 5 1 1 5\n", "output": "3\n4\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1\n1\n2\n2 1\n3\n3 1 2\n3\n2 2 2\n4\n4 1 4 1\n5\n5 4 3 2 1...
code_contests
verifiable_code
1261_E. Not Same
Solve the following coding problem using the programming language python: You are given an integer array a_1, a_2, ..., a_n, where a_i represents the number of blocks at the i-th position. It is guaranteed that 1 ≤ a_i ≤ n. In one operation you can choose a subset of indices of the given array and remove one block i...
```python n = int(input()) v, c = list([[0, 0]]), list() z = ['0' for i in range(n)] for i, x in enumerate(input().split()) : v.append([int(x), i]) v.sort(reverse=True) def S_N_U_F_F(z, v, c) : y, k, x, count = -1, 0, len(v)-1, len(v)-1 while v[0][0] != 0 : if k > 0 and k < len(v)-1 : z[v[y+k][1]] = '0...
vfc_59253
{ "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\n4 1 5 3 4\n", "output": "6\n00100\n10100\n10101\n10111\n11111\n00011\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 1 1 1 1\n", "output": "6\n10000\n11000\n10100\n10010\n100...
code_contests
verifiable_code
1284_B. New Year and Ascent Sequence
Solve the following coding problem using the programming language python: A sequence a = [a_1, a_2, …, a_l] of length l has an ascent if there exists a pair of indices (i, j) such that 1 ≤ i < j ≤ l and a_i < a_j. For example, the sequence [0, 2, 0, 2, 0] has an ascent because of the pair (1, 4), but the sequence [4, ...
```python n=int(input()) l=[] ans=0 minn=[] maxx=[] c=0 for _ in range(n): ar=[int(x) for x in input().split()] ar=ar[1:] m=10**10 f=0 for i in ar: if i<=m: m=i else: f=1 break if f==1: continue else: minn.append(min(ar)) ...
vfc_59257
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1\n1 1\n1 2\n1 4\n1 3\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 2 0 2 0\n6 9 9 8 8 7 7\n1 6\n", "output": "7\n", "type": "stdin_stdout" } ...
code_contests
verifiable_code
1303_D. Fill The Bag
Solve the following coding problem using the programming language python: You have a bag of size n. Also you have m boxes. The size of i-th box is a_i, where each a_i is an integer non-negative power of two. You can divide boxes into two parts of equal size. Your goal is to fill the bag completely. For example, if n...
```python from math import log2 for i in range(int(input())): K,N=map(int,input().split()) L=list(map(int,input().split())) bit=[0]*61 Sum=0 for i in L: bit[int(log2(i))]+=1 Sum+=i if Sum<K: print("-1") continue i=0 res=0 while i<60: if (1<<i)&...
vfc_59261
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10 3\n1 32 1\n23 4\n16 1 4 1\n20 5\n2 1 16 1 8\n", "output": "2\n-1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n8 3\n1 32 1\n23 4\n16 1 4 1\n20 5\n2 1 16 1 8\n", "output...
code_contests
verifiable_code
1327_E. Count The Blocks
Solve the following coding problem using the programming language python: You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits ...
```python # | # _` | __ \ _` | __| _ \ __ \ _` | _` | # ( | | | ( | ( ( | | | ( | ( | # \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_| import sys def read_line(): return sys.stdin.readline()[:-1] def read_int(): return...
vfc_59265
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "180 10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1448\...
code_contests
verifiable_code
1346_G. Two IP Cameras
Solve the following coding problem using the programming language python: You have two IP cameras of the same model. Each camera can take photos starting from some moment of time with a fixed period. You can freely choose the starting moment but you can choose the period only as one of k values p_1, p_2, ..., p_k whic...
vfc_59269
{ "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": "3 5\n3 5 7\n1 4 5 7 12\n", "output": "\nYES\n1 3\n5 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 2 3\n1 10\n", "output": "\nYES\n1 1\n10 1\n", "type": "stdin_stdout...
code_contests
verifiable_code
1389_G. Directing Edges
Solve the following coding problem using the programming language python: You are given an undirected connected graph consisting of n vertices and m edges. k vertices of this graph are special. You have to direct each edge of this graph or leave it undirected. If you leave the i-th edge undirected, you pay w_i coins,...
vfc_59277
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 2\n1 3\n11 1 5\n10 10\n1 2\n2 3\n", "output": "11 2 5 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
140_D. New Year Contest
Solve the following coding problem using the programming language python: As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest. The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A....
```python from bisect import bisect_right n = int(input()) t = list(map(int, input().split())) t.sort() for i in range(1, n): t[i] += t[i - 1] i = bisect_right(t, 350) j = bisect_right(t, 710) print(j, sum(t[k] for k in range(i, j)) - 350 * (j - i)) ```
vfc_59281
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n30 330 720\n", "output": "2 10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n22 13 1 3 2 18 11 11 40 42 1 3 1 12 3 16 32 4 15 18 7 8 4 6 1 1 19 7 2 17 12 21 2 2 9 8 14 29 9 19 5 ...
code_contests
verifiable_code
1454_D. Number into Sequence
Solve the following coding problem using the programming language python: You are given an integer n (n > 1). Your task is to find a sequence of integers a_1, a_2, …, a_k such that: * each a_i is strictly greater than 1; * a_1 ⋅ a_2 ⋅ … ⋅ a_k = n (i. e. the product of this sequence is n); * a_{i + 1} is divi...
```python import math tc = int(input()) for i in range(tc): integer = int(input()) k = integer kamus = dict() while k % 2 == 0: try: kamus[2] += 1 except: kamus[2] = 1 k /= 2 for i in range(3,int(math.sqrt(k))+1,2): while k % i == 0: ...
vfc_59289
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\n360\n4999999937\n4998207083\n", "output": "\n1\n2 \n3\n2 2 90 \n1\n4999999937 \n1\n4998207083 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1478_B. Nezzar and Lucky Number
Solve the following coding problem using the programming language python: Nezzar's favorite digit among 1,…,9 is d. He calls a positive integer lucky if d occurs at least once in its decimal representation. Given q integers a_1,a_2,…,a_q, for each 1 ≤ i ≤ q Nezzar would like to know if a_i can be equal to a sum of s...
```python r=int(input()) res=[] for u in range(r): x,n = map(int,input().split(" ")) db= [int(x) for x in input().split()] for i in db: # operation if i%n==0: res.append("yes") else:# bech ne7ou n kol mara w njarbou k=0 ok=0 while((i-k*n)>=n):...
vfc_59293
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 7\n24 25 27\n10 7\n51 52 53 54 55 56 57 58 59 60\n", "output": "\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 7\n...
code_contests
verifiable_code
1505_E. Cakewalk
Solve the following coding problem using the programming language python: A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mous...
```python h, w = map(int, input().split()) grid = [] for i in range(h): grid.append(input()) r,c = 0,0 ans = 0 for i in range(h+w-2): # print(r,c) if grid[r][c] == '*': ans += 1 if r==h-1: c += 1 continue if c == w-1: r+=1 continue right = (111111,111) ...
vfc_59297
{ "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": "4 3\n*..\n.*.\n..*\n...\n", "output": "\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n..*..\n.....\n**...\n**...\n**...\n", "output": "\n1\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1528_E. Mashtali and Hagh Trees
Solve the following coding problem using the programming language python: Today is Mashtali's birthday! He received a Hagh tree from Haj Davood as his birthday present! A directed tree is called a Hagh tree iff: * The length of the longest directed path in it is exactly n. * Every vertex has at most three edge...
vfc_59301
{ "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": "344031\n", "output": "\n272040628\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "\n5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
15_D. Map
Solve the following coding problem using the programming language python: There is an area map that is a rectangular matrix n × m, each cell of the matrix contains the average height of a corresponding area part. Peter works for a company that has to build several cities within this area, each of the cities will occup...
vfc_59305
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 128000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4 2 2\n1 5 3 4\n2 7 6 1\n1 1 2 2\n2 2 1 2\n", "output": "3\n3 1 2\n3 3 3\n1 2 ...
code_contests
verifiable_code
17_A. Noldbach problem
Solve the following coding problem using the programming language python: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and cal...
```python y = [2] h = [] j = 0 for i in range(3,1000): z = 0 for x in range(2, int(i**0.5)+1): if i%x == 0: z+=1 if z == 0: y.append(i) for i in range(0,len(y)-1): x = y[i]+y[i+1] h.append(x) k = list(input().split()) a = int(k[0]) b = int(k[1]) for i in range(0,len(h))...
vfc_59309
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "27 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "45 7\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
202_B. Brand New Easy Problem
Solve the following coding problem using the programming language python: A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a pro...
```python import itertools def count_inversions(enumerate_seq): tmp = list(enumerate_seq[:]) result = 0 for i in range(len(tmp)): for j in range(len(tmp) - 1): if tmp[j][0] > tmp[j + 1][0]: result += 1 tmp[j], tmp[j + 1] = tmp[j + 1], tmp[j] return r...
vfc_59313
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nadd two numbers\n3\n1 add\n2 two two\n3 numbers numbers numbers\n", "output": "Brand new problem!\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
227_A. Where do I Turn?
Solve the following coding problem using the programming language python: Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from point ...
```python xa, ya = map(int,input().split()) xb, yb = map(int,input().split()) xc, yc = map(int,input().split()) dif = ((xb-xa)*(yc-yb)) - ((yb-ya)*(xc-xb)) if(dif == 0): print("TOWARDS") elif(dif > 0): print("LEFT") else: print("RIGHT") ```
vfc_59317
{ "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": "0 0\n0 1\n1 1\n", "output": "RIGHT\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "-1 -1\n-3 -3\n-4 -4\n", "output": "TOWARDS\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
250_D. Building Bridge
Solve the following coding problem using the programming language python: Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines x = ...
```python import sys def pro(): return sys.stdin.readline().strip() def rop(): return map(int, pro().split()) def main(): s = list(rop()) a = list(rop()) q = list(rop()) o = list(rop()) p = -1 t = (1e100, -1, -1) for i in range(s[1]): while not((p == - 1 or s[2] * q[i] - s[3] * a[p] >= 0) and (p + 1...
vfc_59321
{ "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": "3 2 3 5\n-2 -1 4\n-1 2\n7 3\n", "output": "2 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 20 50 60\n-96 -75 32 37 42 43 44 57 61 65\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25...
code_contests
verifiable_code
299_B. Ksusha the Squirrel
Solve the following coding problem using the programming language python: Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get t...
```python n,k=map(int,input().split()) s=input() list=[] i=0 while(i<n): p=0 while(s[i]=='#'): p+=1 i+=1 list.append(p) i+=1 if(max(list)<k): print("YES") else: print("NO") ```
vfc_59329
{ "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 1\n..\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
346_C. Number Transformation II
Solve the following coding problem using the programming language python: You are given a sequence of positive integers x1, x2, ..., xn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can perform the following moves: * subtract 1 from the current a; * subtract a mod xi ...
vfc_59337
{ "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\n3 4 5\n30 17\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 6 7\n1000 200\n", "output": "206\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
36_B. Fractal
Solve the following coding problem using the programming language python: Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square a...
vfc_59341
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n.*\n..\n", "output": ".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n.*.\n***\n.*.\n", "outp...
code_contests
verifiable_code
391_E1. Three Trees
Solve the following coding problem using the programming language python: This problem consists of two subproblems: for solving subproblem E1 you will receive 11 points, and for solving subproblem E2 you will receive 13 points. A tree is an undirected connected graph containing no cycles. The distance between two nod...
vfc_59345
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 4\n1 2\n2 5\n3 4\n4 2\n1 2\n1 3\n1 4\n", "output": "151", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 3\n1 2\n1 2\n1 2\n2 3\n", "output": "56", "type": "stdin_stdout" ...
code_contests
verifiable_code
414_B. Mashmokh and ACM
Solve the following coding problem using the programming language python: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programmin...
```python import math def C(n,k): w=1 for i in range(n-k+1,n+1): w*=i for i in range (1,k+1): w//=i return w def multiples(limit): tmp = 1 m = limit for j in range(2, limit + 1): no_multiples = 0 while m % j == 0: no_multiples += 1 ...
vfc_59349
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n", "output": "5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
463_A. Caisa and Sugar
Solve the following coding problem using the programming language python: Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because the...
```python # Author: SaykaT # Problem: 463A # Time Created: July 21(Tuesday) 2020 || 02:59:52 #>-------------------------<# # Helper Functions. -> Don't cluster your code. # IO Functions. -> Input output def io(): n, s = map(int, input().split()) sugar = [] for _ in range(n): x, y = map(int, input...
vfc_59357
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0\n", "output": "50\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50\n", "output": "-1\n", "type": "stdin_...
code_contests
verifiable_code
486_E. LIS of Sequence
Solve the following coding problem using the programming language python: The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson. Nam created a sequence a consisting of ...
```python # a simple parser for python. use get_number() and get_word() to read def main(): def parser(): while 1: data = list(input().split(' ')) for number in data: if len(number) > 0: yield(number) input_parser = parser() gets = lambda:...
vfc_59361
{ "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": "4\n1 3 2 5\n", "output": "3223", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
50_D. Bombing
Solve the following coding problem using the programming language python: The commanding officers decided to drop a nuclear bomb on the enemy's forces. You are ordered to determine the power of the warhead that needs to be used. The enemy has N strategically important objects. Their positions are known due to the int...
```python import math n = int(input()) k, epsilon = list(map(int, input().split(" "))) x0, y0 = list(map(int, input().split(" "))) epsilon /= 1000.0 l = [] for i in range(n): l.append(list(map(int, input().split(" ")))) d = sorted([(p[0] - x0) ** 2 + (p[1] - y0) ** 2 for p in l]) rmin = 0 rmax = math.sqrt(...
vfc_59365
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 100\n0 0\n3 4\n60 70\n100 100\n10 10\n5 12\n", "output": "13.451261761474598\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 500\n5 5\n1 2\n", "output": "3.842577611976594\...
code_contests
verifiable_code
534_F. Simplified Nonogram
Solve the following coding problem using the programming language python: In this task you have to write a program dealing with nonograms on fields no larger than 5 × 20. Simplified nonogram is a task where you have to build such field (each cell is either white or black) that satisfies the given information about ro...
```python bs = [[], [], [], [], [], []] nz = [] def go(n, b, tup=tuple): m = len(b) N = 2 ** n dp = [set() for _ in xrange(N)] dp[0].add(0) prev = {} for k, x in enumerate(b): ndp = [set() for _ in xrange(N)] for i in xrange(N): if not dp[i]: continue ...
vfc_59369
{ "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": "3 3\n1 0 1\n2 2 2\n", "output": "***\n...\n***\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n2 3 2\n1 0 1 2 1\n", "output": "*..*.\n*.*.*\n*..*.\n", "type": "stdin_stdou...
code_contests
verifiable_code
55_A. Flea travel
Solve the following coding problem using the programming language python: A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should a...
```python n = int(input()) visited = [False] * n k = 0 for i in range(n ** 2 + 1): k += i + 1 visited[k % n] = True for i in visited: if not i: print("NO") exit() print("YES") ```
vfc_59373
{ "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\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
607_D. Power Tree
Solve the following coding problem using the programming language python: Genos and Saitama went shopping for Christmas trees. However, a different type of tree caught their attention, the exalted Power Tree. A Power Tree starts out as a single root vertex indexed 1. A Power Tree grows through a magical phenomenon k...
vfc_59381
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n1 1 4\n1 2 3\n2 2\n1 2 7\n2 1\n", "output": "14\n94\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
629_C. Famil Door and Brackets
Solve the following coding problem using the programming language python: As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other str...
```python n, m = map(int, input().split()) s = input() mod = 10 ** 9 + 7 c, b, ans, d, k = 0, 0, 0, [[1]], n - m for i in s: c += (i == '(') * 2 - 1 b = min(c, b) for i in range(n - m): nd = d[-1][1:] + [0] * 2 for j in range(1, i + 2): nd[j] = (nd[j] + d[-1][j - 1]) % mod d.append(nd) for i...
vfc_59385
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n(())\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n(\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
679_B. Bear and Tower of Cubes
Solve the following coding problem using the programming language python: Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a3. A tower consisting of bl...
```python def rec(m): if m <= 0: return m, 0 a = int((m + 1e-9) ** (1 / 3)) x, y = rec(m - a ** 3) q, w = rec(a ** 3 - (a - 1) ** 3 - 1) return max((x + 1, a ** 3 + y), (q + 1, (a - 1) ** 3 + w)) print(*rec(int(input()))) ```
vfc_59393
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n", "output": "6 6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
701_C. They Are Everywhere
Solve the following coding problem using the programming language python: Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connect...
```python n = int(input()) s = input() alles = {} l, r, c, ans, le = 0, 0, 0, float("+inf"), len(set(s)) for i in s: if i not in alles: alles[i] = 0 c += 1 alles[i] += 1 if c == le: while alles[s[l]] > 1: alles[s[l]] -= 1 l += 1 ans = min(ans, r-l+1)...
vfc_59397
{ "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\naaBCCe\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\nbcAAcbc\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
723_D. Lakes in Berland
Solve the following coding problem using the programming language python: The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not ...
```python def find_neigh(t,x,y): return [(i,j) for (i,j) in [(x-1,y),(x+1,y),(x,y-1),(x,y+1),(x,y+1)] if t[i][j]=='.'] def lake(table): return [(i,j) for i in range(0,len(table)-1) for j in range(0, len(table[i])-1) if table[i][j] == '.'] stack=set() def the_lake(tabl...
vfc_59401
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 1\n****\n*..*\n****\n**.*\n..**\n", "output": "1\n****\n*..*\n****\n****\n..**\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 0\n***\n*.*\n***\n", "output": "1\n***\n***\n**...
code_contests
verifiable_code
745_C. Hongcow Builds A Nation
Solve the following coding problem using the programming language python: Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the g...
```python from collections import deque n,m,k = map(int,input().split()) line = input().split() gov = [] for i in range(k): gov.append(int(line[i])-1) graph = {} for i in range(m): u,v = map(int,input().split()) u -= 1 v -= 1 if u not in graph: graph[u] = set() if v not in graph: ...
vfc_59405
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 2\n1 3\n1 2\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 1\n2\n1 2\n1 3\n2 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
768_E. Game of Stones
Solve the following coding problem using the programming language python: Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: * The game starts with n piles of stones indexed from 1 to n. The i-th pile ...
```python memo = {} def get_reachable_states(k, max_allowed): states = [] for i in range(1, min(k,max_allowed) + 1): new_k = k - i states.append((new_k, i - 1)) return states def Grundy(k, max_allowed): if k == 0: return 0 if (k, max_allowed) in memo: return memo[...
vfc_59409
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n2\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
792_D. Paths in a Complete Binary Tree
Solve the following coding problem using the programming language python: T is a complete binary tree consisting of n vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree ...
```python from math import log n, q = [int(i) for i in input().split()] maxlvl = int(log(n + 1, 2)) + 1 steps = [2 ** i for i in range(maxlvl)] def calc_lvl(m): for lvl in range(1, maxlvl): if (m - steps[lvl-1]) % steps[lvl] == 0: return (lvl, ((m - steps[lvl-1]) % (2 * steps[lvl]) == 0)) #pri...
vfc_59413
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15 2\n4\nUURL\n8\nLRLLLLLLLL\n", "output": "10\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1\nU\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
813_A. The Contest
Solve the following coding problem using the programming language python: Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutio...
```python from sys import stdin import re def readInt(count=1): m = re.match('\s*' + ('([+-]?\d+)\s*' * count), stdin.readline()) if m is not None: ret = [] for i in range(1, m.lastindex + 1): ret.append(int(m.group(i))) return ret return None taskCount, = readInt() thi...
vfc_59417
{ "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": "2\n3 4\n2\n1 4\n7 9\n", "output": "7", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
838_F. Expected Earnings
Solve the following coding problem using the programming language python: You are playing a game with a bag of red and black balls. Initially, you are told that the bag has n balls total. In addition, you are also told that the bag has probability pi / 106 of containing exactly i red balls. You now would like to buy ...
vfc_59421
{ "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": "3 200000\n250000 250000 250000 250000\n", "output": "0.9000000000", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
859_C. Pie Rules
Solve the following coding problem using the programming language python: You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie,...
```python import os import sys from io import BytesIO, IOBase def main(): import bisect import math # import itertools # import heapq # from queue import PriorityQueue, LifoQueue, SimpleQueue # import sys.stdout.flush() use for interactive problems alpha = 'abcdefghijklmnopqrstuvwxyz' ...
vfc_59425
{ "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": "5\n10 21 10 21 10\n", "output": "31 41\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n141 592 653\n", "output": "653 733\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
884_B. Japanese Crosswords Strike Back
Solve the following coding problem using the programming language python: A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No t...
```python n, x = map(int, input().split()) print(['NO', 'YES'][sum(map(int, input().split())) + n - 1 == x]) ```
vfc_59429
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4\n1 3\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
908_D. New Year and Arbitrary Arrangement
Solve the following coding problem using the programming language python: You are given three integers k, pa and pb. You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability pa / (pa + pb), add 'a' to the end of the seque...
```python k, pa, pb = map(int, input().split()) MOD = 10**9 + 7 INF = ((pa + pb) * pow(pb, MOD-2, MOD)) % MOD rAB = pow(pa+pb, MOD-2, MOD) rB = pow(pb, MOD-2, MOD) memo = {} def dfs(a, ab): if ab >= k: return ab if a + ab >= k: #return INF #return (pa + pb) / pb return ((a + M...
vfc_59433
{ "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": "1 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 4\n", "output": "370000006\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
92_C. Newspaper Headline
Solve the following coding problem using the programming language python: A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. Aft...
```python import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') s = [ord(c) - 97 for c in input().rstrip()] t = [ord(c) - 97 for c in input().rstrip()] n, m = len(s), len(t) next_c = [[-1] * 26 for _ in range(n)] for _ in range(2): for i in range(...
vfc_59437
{ "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": "abcd\ndabc\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abc\nxyz\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
958_B1. Maximum Control (easy)
Solve the following coding problem using the programming language python: The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path be...
```python __author__ = 'Esfandiar' n = int(input()) g = [[] for i in range(n)] for i in range(n-1): u,v = map(int,input().split()) g[u-1].append(v-1) g[v-1].append(u-1) print(sum([len(g[i])==1 for i in range(n)])) ```
vfc_59441
{ "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\n1 2\n4 3\n1 4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 1\n4 2\n1 3\n1 5\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
983_C. Elevator
Solve the following coding problem using the programming language python: You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator. Today you are late, so there are queues on some floors already. For each person you know...
```python # python3 import sys from collections import namedtuple def readline(): return map(int, input().split()) def readlines(): for line in sys.stdin.readlines(): yield map(int, line.split()) class State(namedtuple('State', 'payload time floor')): def hook(self, pivot, a, b): lo, up = ...
vfc_59445
{ "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": "2\n5 3\n3 5\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 5\n5 3\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
bizzare-mishra
Solve the following coding problem using the programming language python: Mishra has gone bizarre these days. And therefore loves only bizzare patterns. Nowadays he has ran into a habit of not listening to many "yes" or "no" from people like Bansal. In fact he does not like strings having more than one "yes" or one "n...
```python #!/usr/bin/python """ HackerEarth practice problem (http://www.hackerearth.com/problem/algorithm/bizzare-mishra/) @date 2014/2/25 """ import fileinput input = [] output = 0 map = {'N':'Y','Y':'N'} for line in fileinput.input(): input.append(line) case_count = int(input[0]) for i in range(case_count): len ...
vfc_59453
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\nYY\n2\nYN\n5\nYYNNY\n\nSAMPLE", "output": "1\n0\n2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
crazy-painter-4
Solve the following coding problem using the programming language python: Abhimanyu simply drew two triangles, as shown in the picture below: He says this, Amazing painting 1. Then he drew two more triangles, as shown in the picture below: He says this, Amazing painting 2. Similarly he defined Amazing painting 3, ...
```python T = int(raw_input()) while T>0: T=T-1 N = long(raw_input()) totPoints = N*12 q=totPoints/26 rem = totPoints%26 cost = map(long,raw_input().split()) totCost = 0 for i in cost: totCost=totCost+i paintCost = q*totCost + 26*((q-1)*q)/2 for i in range(rem): paintCost+=(cost[i]+q); print paintCos...
vfc_59457
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2\n\nSAMPLE", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 0 1 2 3 1 ...
code_contests
verifiable_code
flowers
Solve the following coding problem using the programming language python: You and your K−1 friends want to buy N marbles. Marble number i has cost ci. But the seller does not want just one customer to buy a lot of marbles, so he tries to change the price of marbles for customers who have already bought some marbles. M...
```python n, k = raw_input().split(" ") n, k = int(n), int(k) costs = raw_input().split(" ") def minimumMoney(): integerCosts = [] for c in costs: integerCosts.append(int(c)) integerCosts = sorted(integerCosts) multiplyFactor = 1 friendCount = k minMoney = 0 for c in reversed(integerCosts): friendCount...
vfc_59461
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n2 5 6\n\nSAMPLE", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "55 34\n433515 22221 540709 538312 496949 902471 439983 159332 417327 399306 817804 354682 108825 970689...
code_contests
verifiable_code
jiva-the-self-driven-car
Solve the following coding problem using the programming language python: Jiva is a self driven car and is out on its very first drive. It aims to earn some revenue by serving as taxi driver. It starts its journey from a point and travels in a line for 100 Km. It picks and drops passenger on the way,but can accommodat...
```python import sys t = int(sys.stdin.readline()) while(t>0): cabfull = False t-=1 N,M=map(int,sys.stdin.readline().split()) start = [[] for i in xrange(101)] end = [0 for i in xrange(101)] for i in xrange(N): s,e = map(int,sys.stdin.readline().split()) if(s<e): start[s].append(e) passengers = 0 cost ...
vfc_59465
{ "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 3 \n0 100\n0 20\n30 50\n40 80\n6 4\n10 55\n10 20\n40 60\n55 60\n60 70\n75 95\n\nSAMPLE", "output": "1719 Cab was full\n1070\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n287 10\...
code_contests
verifiable_code
mike-the-bully-3
Solve the following coding problem using the programming language python: Chester Bennington, being a skinny kid as we all know, is always bullied since he was a child. This time its just unacceptable. Mike Shinoda, the second vocalist to his band, tried to bully him. Chester was never a bright student and Mike, being...
```python def isprime(x): X = int((x**0.5))+1 for i in xrange(2,X): if(x%i==0): return False return True def op(n,ref): p=[2] for i in xrange(3,n): if(isprime(i)): ref[i]=1 p+=[i] return p def prog(): t = input() T=t nums=[] whi...
vfc_59469
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "30\n4799\n3797\n2237\n7963\n4993\n8431\n1091\n3181\n659\n4931\n1531\n8231\n7211\n1741\n2297\n4073\n191\n6703\n9949\n9059\n6269\n6481\n6883\n5653\n1877\n9463\n4243\n5659\n3623\n5449", "output": "5 7 13 19 31 43 61 73 103 109 1...
code_contests
verifiable_code
packers-n-movers
Solve the following coding problem using the programming language python: Agon Packers and Movers specialize in moving large number luggages from one place to another. The luggages are packed by the Packers, and after they're done with the job, the Movers take over. First, the Packers put the packages they have pack...
```python #print 'Hello World!' #weight = {} #def recursive memory loss def move(M, P, p): #print "inside..." sol = [] if M == 1: return sum(p[0:P]) for i in range(P+1): #print "looping..." if i == P: sol.append(sum(p[0:P])) weight = sum(p[0:i]) #print "calling..." sol.append(max(weight, move(M-1,...
vfc_59473
{ "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\n200 25 974 564 429\n\nSAMPLE", "output": "1199\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4\n5 10 21 20", "output": "36\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
remove-kth-node
Solve the following coding problem using the programming language python: A linked list contains N nodes numbered from 1 to N. The tail of the list points to head of the list i.e. the linked list is circular in nature. For when N=5 1->2->3->4, ^-------5<---' An integer K is also given to you.You start counting ...
```python num=int(raw_input()) for i in range(num): total,step=raw_input().split() total=int(total) step=int(step) nxt=0 l=range(1,total+1) while len(l)>1: delete=(nxt+step)%total l.pop(delete) total-=1 nxt=delete%total print l[0] ```
vfc_59477
{ "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 1\n2 5\n\nSAMPLE", "output": "3\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 0\n1 1\n1 2\n2 0\n2 1\n10 0\n100 10\n1000 0\n1000 100\n1000 1000", "output": "1\n1\n1\n2\n...
code_contests
verifiable_code
sonas-prime
Solve the following coding problem using the programming language python: Sona loves numbers. Sona loves only certain type of numbers especially prime numbers. She devised a new definition for prime numbers. In a given set of positive integer X = {X0,X1,....Xn-1} Xi is prime only if there are no elements in X which a...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' size=input() arr=map(int,raw_input().split()) lis=[] for i in range(size): c=0 for j in range(size): if arr[j]!=0: if arr[i]%arr[j]==0 and c==0: c=1 elif arr[i]%...
vfc_59481
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10 49 5 3 20\n\nSAMPLE", "output": "49 5 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n84 87 78 16 94 36 87 93 50 22", "output": "84 78 16 94 36 93 50 22\n", "type":...
code_contests
verifiable_code
tom-and-jerry-with-numbers-4
Solve the following coding problem using the programming language python: Tom and Jerry started fighting, as always! But this time the fight is on numbers. They ended up bringing a game to decide who is better. They have N marbles and they choose two integers M1 and M2, in each turn a player can take either M1 or M2 m...
```python t = input() while(t>0) : t -= 1 n, m1, m2 = map(int, raw_input().split()) rem = (n%(m1+m2)) if (rem < m1) : print 0 elif ((rem == m1)or(rem >= m2)) : print 1 else : rem /= m1 if (rem&1) : print 1 else : print 0 ```
vfc_59485
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n1 1 3\n3 3 5\n7 7 9\n13 1 2\n21 8 10\n31 5 7\n43 4 6\n57 5 7\n73 8 10\n91 1 2", "output": "1\n1\n1\n1\n0\n1\n0\n1\n0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 1 3\n3 4 5...
code_contests
verifiable_code
p00437 Quality Checking
Solve the following coding problem using the programming language python: problem You are in charge of quality control at a machine manufacturing plant. This machine requires a power supply, a motor, and a cable as parts. The manufacturing plant has a power supply, b motors, and c cables, numbered from 1 to a, a + 1 ...
```python for e in iter(input,'0 0 0'): d=[2]*-~sum(map(int,e.split())) f=[] for _ in[0]*int(input()): s,t,u,v=map(int,input().split()) if v:d[s]=d[t]=d[u]=1 else:f+=[(s,t,u)] for s,t,u in f: if d[t]*d[u]==1:d[s]=0 if d[u]*d[s]==1:d[t]=0 if d[s]*d[t]==1:d[u]=0 print(*d[1:],sep='\n') ```
vfc_59541
{ "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": "2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 5 1\n0 0 0", "output": "2\n1\n1\n0\n1\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 2 1\n0 0 0", ...
code_contests
verifiable_code
p00629 Selecting Teams Advanced to Regional
Solve the following coding problem using the programming language python: In order to participate in the Asian Regional Qualifiers of the International Collegiate Programming Contest held every year in Japan, we must break through the strict domestic qualifiers. Even though it is a university competition, multiple te...
```python while 1: n = int(input()) if n == 0: break data = [] for _ in range(n): i, u, a, p = map(int, input().split()) data.append([i, u, a, p]) data = sorted(data, key=lambda x: (-x[2], x[3], x[0])) union = [0] * 1001 cnt = 0 for d in data: i, u, a, ...
vfc_59545
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1 6 200\n2 1 6 300\n3 1 6 400\n4 2 5 1200\n5 1 5 1400\n6 3 4 800\n3\n777 1 5 300\n808 2 4 20\n123 3 6 500\n2\n2 1 3 100\n1 1 3 100\n0", "output": "1\n2\n3\n4\n6\n123\n777\n808\n1\n2", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p00773 Tax Rate Changed
Solve the following coding problem using the programming language python: Tax Rate Changed VAT (value-added tax) is a tax imposed at a certain rate proportional to the sale price. Our store uses the following rules to calculate the after-tax prices. * When the VAT rate is x%, for an item with the before-tax price o...
```python from math import floor while(True): x,y,s=map(int,input().split()) if (x,y,s)==(0,0,0): quit() ans=0 for i in range(1,s): j=s-floor(i*(100+x)/100) if j<1: continue j=floor((j+1)*(100/(100+x))) for k in [j-1,j]: if floor(i*(100+x)/...
vfc_59549
{ "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": "5 8 105\n8 5 105\n1 2 24\n99 98 24\n12 13 26\n1 22 23\n1 13 201\n13 16 112\n2 24 50\n1 82 61\n1 84 125\n1 99 999\n99 1 999\n98 99 999\n1 99 11\n99 1 12\n0 0 0", "output": "109\n103\n24\n24\n26\n27\n225\n116\n62\n111\n230\n197...
code_contests
verifiable_code
p00904 Ginkgo Numbers
Solve the following coding problem using the programming language python: We will define Ginkgo numbers and multiplication on Ginkgo numbers. A Ginkgo number is a pair <m, n> where m and n are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers. The multiplication on Ginkgo numbers is defined by <m...
```python #!/usr/bin/env python # -*- coding: utf-8 -*- """ Problems 1325 Problem A: Ginkgo Numbers """ for _ in range(int(input())): m, n = map(int,input().split()) count = 0 for p in range(142): for q in range(142): if (p > 0 or q > 0) and ((m*q + n*p) % (p*p + q*q) == 0) and ((n*q - m...
vfc_59553
{ "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": "8\n10 0\n0 2\n-3 0\n4 2\n0 -13\n-4 1\n-2 -1\n3 -1", "output": "C\nC\nP\nC\nC\nP\nP\nC", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n10 0\n0 2\n-3 1\n4 2\n0 -13\n-4 1\n-2 -1\n3 -1", ...