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
aabbaac
Solve the following coding problem using the programming language python: You are given an array S of N strings numbered from 0 to N-1. You build string sequence Ti by the following rules: T0 = S0 Ti = Ti-1 + reverse(Ti-1) + Si Now please answer M queries: by non-negative integer x output x-th character of the TN-1 ...
```python t = int(raw_input()) for _ in xrange(t): n, m = [int(x) for x in raw_input().split()] s = [raw_input() for __ in xrange(n)] ans = '' arLen = sum(2 ** (len(s) - i - 1) * len(s[i]) for i in xrange(len(s))) for __ in xrange(m): req = int(raw_input()) curr = arLen last ...
vfc_36969
{ "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 7\na\nb\nc\n0\n1\n2\n3\n4\n5\n6\n2 6\nty\nqwe\n0\n2\n3\n4\n6\n1\n\nSAMPLE", "output": "aabbaac\ntytqey", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 7\na\nb\nc\n0\n1\n2\n3\n4\n5\...
code_contests
verifiable_code
bob-and-candies
Solve the following coding problem using the programming language python: Little Bob comes to you for candies as you are his favorite coder! He wants X candies. You have N bags and the i^th bag contains A[i] candies. You can give him a set of one or more bags such that the sum of candies in those bags is EXACTLY equa...
```python def isLexiograficalSorted(best, current): best.sort() current.sort() if len(best) < len(current): return True if len(best) > len(current): return False # len is same for i in xrange(len(best)): if best[i] < current[i]: return True if best[i]...
vfc_36973
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 9\n5 7 1 4 4 1\n\nSAMPLE", "output": "1 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "17 13\n27 32 24 30 94 1 89 22 18 84 68 34 21 47 96 27 7", "output": "-1\n", "type": ...
code_contests
verifiable_code
crushing-violence
Solve the following coding problem using the programming language python: The students of college XYZ are getting jealous of the students of college ABC. ABC managed to beat XYZ in all the sports and games events. The main strength of the students of ABC is their unity. The students of XYZ decide to destroy this uni...
```python from collections import Counter n=input() for i in xrange(0,n): x=input() boys={} girls={} boy_crush=[int(x) for x in raw_input().split()] girl_crush=[int(x) for x in raw_input().split()] boy_crush.insert(0,0) girl_crush.insert(0,0) for i in xrange(1,len(boy_crush)): t...
vfc_36977
{ "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\n2 2 1\n3 2 1\n4\n2 3 4 1\n2 3 4 1\n\nSAMPLE", "output": "1 0\n1 4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
free-drives-1
Solve the following coding problem using the programming language python: Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share...
```python t = int(raw_input()) while(t): n = int(raw_input()) print(n*(n-1)//2) t -= 1 ```
vfc_36981
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2\n\nSAMPLE", "output": "0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "684\n2924\n7062\n7105\n4716\n9111\n6913\n1421\n9429\n2378\n4540\n9243\n544\n2898\n298\n6607\n4585\n1940\...
code_contests
verifiable_code
jp-and-rotations
Solve the following coding problem using the programming language python: Kabra is a very good friend of JP. So JP has assigned him a task. Given an array, two operations can be performed on it. They are 1) L X : Rotate the array towards left by X. 2) R X : Rotate the array towards right by X. Now you will be given 2 ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' N,M=map(int,raw_input().split()) inic=map(int,raw_input().split()) targ=map(int,raw_input().split()) done=False try: good=targ.index(inic[0]) except ValueError: print -1 ...
vfc_36985
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n2 1 3 4\n3 4 2 1\nR 1\nL 2\nL 1\nL 5\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n2 1 3 4\n3 4 2 1\nR 1\nL 2\nL 1\nL 5\n\nSAMPLE", "output": "3\...
code_contests
verifiable_code
pairs-5
Solve the following coding problem using the programming language python: King Klee's kingdom is under attack. He leaves the task of protecting his kingdom to you as you are Now you are given N teams of soldiers. There are 3 gates --> Large, Larger, Largest. You need to form three teams from these N teams to send the...
```python arr = [] res = 0 for i in range(input()): arr.append(input()) res += arr[i] power = 1 n = len(arr) for i in range(n): power *= 3 for i in range(power): temp = i s1, s2, s3 = 0,0,0 for j in range(n): if temp % 3 == 0: s1+=arr[j] if temp % 3 == 1: s2+=arr[j] if temp %...
vfc_36993
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3\n3\n1\n4\n\nSAMPLE", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
restaurant-renting-oven-2
Solve the following coding problem using the programming language python: The Manager Manoj has thought of another way to generate revenue for his restaurant. He has a large oven to bake his goods, but he has noticed that not all of the racks are used all of the time. If a rack is not used, then the Manoj has decided ...
```python def f(av,index): l1=[] l2=[] global l global m global n if(index==n): return 0 for i in range(0,m): l1.append(av[i]) l2.append(av[i]) boolean=True for i in range(l[index][0],l[index][1]): l1[i]-=1 if(av[i]<=0): boolean=Fal...
vfc_36997
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n\n4 4\n0 1 2\n1 2 2\n2 4 2\n0 3 5\n2 1 1 1\n\nSAMPLE", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n\n4 4\n0 1 2\n1 2 2\n2 4 2\n0 3 5\n2 1 1 1", "output": "7", ...
code_contests
verifiable_code
sorting-the-string
Solve the following coding problem using the programming language python: After learning basics of arrays and strings, Dark started wondering that if we can sort the numbers then why not STRINGS? Deeply thinking and looking the various strings lying in the string pool, he decided to ascend or descend the string accor...
```python import sys def main(): t=input() if t==20: while t: print "NULL" t=t-1 sys.exit() while t: s=raw_input() l=len(s) d=int(s[l-1]) if d%2==0: d=0 else: d=1 s=s[0:l-2] i=0 l=l-2 x=[] while i<l: if s[i]>='A' and s[i]<='Z': x.append(s[i]) i=i+1 x=sorted(x) if le...
vfc_37001
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nAABAHD 0\nAABGHAD 1\nAXBCD 0\nAXBCD 1\n\nSAMPLE", "output": "AAABDH\nHGDBAAA\nABCDX\nXDCBA\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n*3/49-14+-*3/49-9-*3/49-*3/49-*3/49-14+-*3...
code_contests
verifiable_code
toy
Solve the following coding problem using the programming language python: Peter visited Big Bazar and he was very delighted to know the Loot offer on marbles. The offer was that, If he buys a marble with price p', then he will get all other marbles whose price lies between [p′,p′+4] (both inclusive) in free of cost. S...
```python n=int(raw_input()) arr=map(int,raw_input().split()) arr=sorted(arr) count=1 start=arr[0] end=arr[0]+4 for i in range(1,n): if arr[i]<=end: continue start=arr[i] end=start+4 count+=1 print count ```
vfc_37005
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7 3 6 12 18\n\nSAMPLE", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000\n9849 9230 1777 2478 1745 1296 9825 3102 8646 2739 3434 4276 1177 6700 2252 89 9216 5323 6358 91...
code_contests
verifiable_code
p00125 Day Count
Solve the following coding problem using the programming language python: Create a program that takes two dates as input and outputs the number of days between the two dates. Date 1 (y1, m1, d1) is the same as or earlier than date 2 (y2, m2, d2). Date 1 is included in the number of days, not date 2. Also, take the le...
```python # AOJ 0125 Day Count # Python3 2018.6.18 bal4u def ut2jd(year, month, day): if month <= 2: year -= 1 month += 12 s = 3 + year//4 - year//100 + year//400 s += 1720994 + year*365 + (month+1)*30 + (month+1)*3//5 + day; return s while True: y1, m1, d1, y2, m2, d2 = list(map(int, input().split())) if y...
vfc_37053
{ "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": "2006 9 2 2006 9 3\n2006 9 2 2006 11 11\n2004 1 1 2005 1 1\n2000 1 1 2006 1 1\n2000 1 1 2101 1 1\n-1 -1 -1 -1 -1 -1", "output": "1\n70\n366\n2192\n36890", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00445 JOI and IOI
Solve the following coding problem using the programming language python: problem Create a program that counts the number of consecutive JOI or IOI characters in a given character string. The character string consists only of uppercase letters of the alphabet. For example, the character string "JOIOIOI" in the figure...
```python while True: try: j = input() p=0 q=0 for i in range(len(j)-2): if j[i:i+3] == 'JOI': p += 1 elif j[i:i+3] == 'IOI': q += 1 else: pass print(p) print(q) except EOFError: break ```
vfc_37061
{ "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": "JOIJOI\nJOIOIOIOI\nJOIOIJOINXNXJIOIOIOJ", "output": "2\n0\n1\n3\n2\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "None", "output": "None", "type": "stdin_stdout" }, {...
code_contests
verifiable_code
p00636 The Last Dungeon
Solve the following coding problem using the programming language python: Brave Ponta has finally arrived at the final dungeon. This is a dark wilderness in front of the fort of the evil emperor Boromos, with fairly strong monsters guarding their territories. <image> Figure 1: Wilderness As shown in Fig. 1, the wi...
```python # AOJ 1050 The Last Dungeon # Python3 2018.7.7 bal4u import math import heapq EPS = 1e-8 pp0 = [0j, 4+0j, 4+4j, 4j] def EQ(a,b): return abs(a-b)<EPS def PPeQ(a,b): return EQ(a.real, b.real) and EQ(a.imag, b.imag) def dcmp(x): if PPeQ(x, 0): return 0 return -1 if x <= 0 else 1 def cross(a, b): return a.re...
vfc_37065
{ "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\n1 1\n3 3\n4\n1.0 0.5\n1.0 2.5\n3.0 1.5\n3.0 3.5\n1\n2.0 2.0\n0", "output": "5.656854249492\n4.618033988750\nimpossible", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n3 3\n4\n1.0 ...
code_contests
verifiable_code
p00779 Don't Cross the Circles!
Solve the following coding problem using the programming language python: Don't Cross the Circles! There are one or more circles on a plane. Any two circles have different center positions and/or different radiuses. A circle may intersect with another circle, but no three or more circles have areas nor points shared ...
vfc_37069
{ "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 3\n0 0 1000\n1399 1331 931\n0 1331 500\n1398 0 400\n2000 360 340\n450 950 1600 380\n450 950 1399 1331\n450 950 450 2000\n1 2\n50 50 50\n0 10 100 90\n0 10 50 50\n2 2\n50 50 50\n100 50 50\n40 50 110 50\n40 50 0 0\n4 1\n25 100 26\n7...
code_contests
verifiable_code
p00910 Let There Be Light
Solve the following coding problem using the programming language python: Suppose that there are some light sources and many spherical balloons. All light sources have sizes small enough to be modeled as point light sources, and they emit light in all directions. The surfaces of the balloons absorb light and do not re...
```python from itertools import product from sys import stdin, stdout readline = stdin.readline write = stdout.write def dist2(x0, y0, z0, x1, y1, z1): return (x0 - x1)**2 + (y0 - y1)**2 + (z0 - z1)**2 def dot(x0, y0, z0, x1, y1, z1): return x0*x1 + y0*y1 + z0*z1 def cross2(x0, y0, z0, x1, y1, z1): return...
vfc_37073
{ "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": "12 5 4\n0 10 0 1\n1 5 0 2\n1 4 0 2\n0 0 0 2\n10 0 0 1\n3 -1 0 2\n5 -1 0 2\n10 10 0 15\n0 -10 0 1\n10 -10 0 1\n-10 -10 0 1\n10 10 0 1\n0 10 0 240\n10 0 0 200\n10 -2 0 52\n-10 0 0 100\n1 1 0 2\n0 0 0\n12 5 4\n0 10 0 1\n1 5 0 2\n1 4 0...
code_contests
verifiable_code
p01177 Entangled Tree
Solve the following coding problem using the programming language python: The electronics division in Ishimatsu Company consists of various development departments for electronic devices including disks and storages, network devices, mobile phones, and many others. Each department covers a wide range of products. For ...
vfc_37081
{ "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 2 3\n10 2 1 2\n20 2 3 2\n1\n2\n3\n5 2 5\n10 3 1 2 4\n20 3 2 3 5\n1\n2\n3\n4\n5\n4 1 4\n10 2 1 4\n1\n2\n3\n4\n4 3 4\n30 2 1 4\n20 2 2 4\n10 2 3 4\n1\n2\n3\n4\n4 3 4\n10 2 1 4\n20 2 2 4\n30 2 3 4\n1\n2\n3\n4\n4 3 4\n10 2 1 2\n15 2 ...
code_contests
verifiable_code
p01314 Sum of Consecutive Integers
Solve the following coding problem using the programming language python: You survived several months of exam wars and were able to enter ICPC University on a sunny day. On the day of admission, there was an enthusiastic recruitment of circles on the campus of the university, and you received a large number of pamphle...
```python while True: N=int(input()) if(N==0): break ans=0 for i in range((N//2)+1,0,-1): SUM=i k=i-1 while SUM<=N and k>0: SUM+=k if SUM==N: ans+=1 k-=1 print(ans) ```
vfc_37085
{ "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": "9\n500\n0", "output": "2\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n256\n0", "output": "2\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01482 Memory Leak
Solve the following coding problem using the programming language python: Time Limit: 8 sec / Memory Limit: 64 MB Example Input 100 A=malloc(10) B=clone(A) free(A) Output 0 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code...
vfc_37089
{ "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": "100\nA=malloc(10)\nB=clone(A)\nfree(A)", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\nA=malloc(10)\nB=clone(A)\nfrde(A)", "output": "0\n", "type": "stdin_std...
code_contests
verifiable_code
p01643 Avant-garde Art
Solve the following coding problem using the programming language python: ICPC World Finals Day 6 Russian Constructivism is an art movement in the Soviet Union that began in the mid-1910s. Inspired by such things, Tee, who had been in Country R for a long time, decided to create a cool design despite the rehearsal of...
vfc_37093
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n k\na", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "o k\na", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "m k\na"...
code_contests
verifiable_code
p01795 ICPC Teams
Solve the following coding problem using the programming language python: Example Input 2 2 1 2 0 3 4 1 Output 2 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python from itertools import product from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): MOD = 10**9 + 9 N, M = map(int, readline().split()) K = 3*N fact = [1]*(K+1) rfact = [1]*(K+1) r = 1 for i in range(1, K+1): fact[i] =...
vfc_37097
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 2 0\n3 4 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n1 2 0\n3 4 1", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p02067 AIGo
Solve the following coding problem using the programming language python: Problem Statement Recently, AIs which play Go (a traditional board game) are well investigated. Your friend Hikaru is planning to develop a new awesome Go AI named Sai and promote it to company F or company G in the future. As a first step, Hik...
vfc_37105
{ "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": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02363 All Pairs Shortest Path
Solve the following coding problem using the programming language python: Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of ve...
```python # -*- coding: utf-8 -*- import sys import os import pprint """???????????£????????????????????¨??????""" MAX = 100 d = [[None for i in range(MAX)] for j in range(MAX)] for i in range(MAX): for j in range(MAX): if i == j: d[i][j] = 0 else: d[i][j] = float('inf') ...
vfc_37113
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6\n0 1 1\n0 2 -5\n1 2 2\n1 3 4\n2 3 1\n3 2 7", "output": "0 1 -5 -4\nINF 0 2 3\nINF INF 0 1\nINF INF 7 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n0 1 1\n0 2 5\n1 2 2\n1 3 4\n2 ...
code_contests
verifiable_code
cd1it1
Solve the following coding problem using the programming language python: Given an array A[1..N] of N non-negative integers, you need to find the median of the array. The median of an array is the middle element in its sorted order. If N is even, choose the (N/2)^th element in the sorted order. Input The first line c...
```python n=int(input()) a=raw_input().split() l=[0]*n l=[int(i) for i in a] l.sort() #print l if not n%2: j=n/2 print l[j-1] else: print l[(n/2)] ```
vfc_37117
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n17 13 10 1 3 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n9 34 1 290 32", "output": "32", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
ct03
Solve the following coding problem using the programming language python: Problem description. Chef decides to distribute fancy stationary among kids. Chef has collection of erasers and pencils . Each kid needs to be given a pencil and eraser. Your job is to help find Chef how many kids can get the stationary and how ...
```python t = int(raw_input()) for i in range(0, t): string = raw_input() e = 0 p = 0 for j in range(0, len(string)): if string[j] == 'E': e += 1 else: p += 1 print min(e, p), max(e, p) - min(e, p) ```
vfc_37121
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nEPPEP\nEPPPPEE", "output": "2 1\n3 1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
hotel
Solve the following coding problem using the programming language python: A holiday weekend is coming up, and Hotel Bytelandia needs to find out if it has enough rooms to accommodate all potential guests. A number of guests have made reservations. Each reservation consists of an arrival time, and a departure time. The...
```python t = input() for i in range(0,t): n = input() l1 = raw_input() l1 = l1.split() for j in range(0,n): l1[j] = int(l1[j]) l2 = raw_input() l2 = l2.split() for j in range(0,n): l2[j] = int(l2[j]) l = [0]*1001 for j in range(0,n): for k in range(l1[j],l2[j...
vfc_37125
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 2 3\n4 5 6\n5\n1 2 3 4 5\n2 3 4 5 6\n7\n13 6 5 8 2 10 12\n19 18 6 9 9 11 15", "output": "3\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3\n1 2 3\n4 5 6\n5\n1 2 3 4 5\n2...
code_contests
verifiable_code
montrans
Solve the following coding problem using the programming language python: You are standing near a very strange machine. If you put C cents in the machine, the remaining money in your purse will transform in an unusual way. If you have A dollars and B cents remaining in your purse after depositing the C cents, then aft...
```python cases = int(raw_input()) for _ in xrange(cases): A, B, C = map(int, raw_input().split()) maxValue = A * 100 + B maxSteps = 0 steps = 0 while steps < 10000: if B < C: A -= 1 B = 100 + B - C else: B -= C if A < 0: br...
vfc_37129
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n9 77 69\n98 99 69", "output": "4\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
resn04
Solve the following coding problem using the programming language python: Alice and Bob play the following game : There are N piles of stones with Si stones in the ith pile. Piles are numbered from 1 to N. Alice and Bob play alternately, with Alice starting. In a turn, the player chooses any pile i which has atleas...
```python for i in range(input()): j=input() a=map(int,raw_input().split()) b=[int(a[j]/(j+1)) for j in range(len(a))] if sum(b)%2==0: print "BOB" else: print "ALICE" ```
vfc_37133
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n1\n2\n1 1", "output": "ALICE\nALICE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n0\n2\n1 1", "output": "BOB\nALICE\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
twofrnds
Solve the following coding problem using the programming language python: These days, Sid and Jake are learning about number theory. They have just visited the zoo and during the visit they have counted(yes, they are superb at counting :) ) the number of animals at the zoo. Now, after visiting the zoo, Sid is saying t...
```python t=raw_input() t=int(t) while t>0: f,m=raw_input().split() f=int(f); m=int(m); if m%f==0: print "CORRECT" else: print "WRONG" t=t-1 ```
vfc_37137
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 4\n2 3", "output": "CORRECT\nWRONG", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1017_F. The Neutral Zone
Solve the following coding problem using the programming language python: Notice: unusual memory limit! After the war, destroyed cities in the neutral zone were restored. And children went back to school. The war changed the world, as well as education. In those hard days, a new math concept was created. As we all ...
```python #!/usr/bin/env python2 from __future__ import division, print_function input = raw_input MOD = 1 << 32 MODF = float(MOD) MAGIC = 6755399441055744.0 SHRT = 65536.0 MODF_INV = 1.0 / MODF SHRT_INV = 1.0 / SHRT fround = lambda x: (x + MAGIC) - MAGIC fmod = lambda a: a - MODF * fround(MODF_INV * a) fmul = lam...
vfc_37141
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 16000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12 0 0 1 0\n", "output": "63\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1 2 3 4\n", "output": "136\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
1085_G. Beautiful Matrix
Solve the following coding problem using the programming language python: Petya collects beautiful matrix. A matrix of size n × n is beautiful if: * All elements of the matrix are integers between 1 and n; * For every row of the matrix, all elements of this row are different; * For every pair of vertically ...
vfc_37153
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 1\n1 2\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1105_E. Helping Hiasat
Solve the following coding problem using the programming language python: Hiasat registered a new account in NeckoForces and when his friends found out about that, each one of them asked to use his name as Hiasat's handle. Luckily for Hiasat, he can change his handle in some points in time. Also he knows the exact mo...
```python import time def find_max_clique(remain, size, max_, index, maxs): # print(remain, size, max_) result = max_ if size + len(remain) <= result: # print('pruning (1)...') return result if not remain: # print('trivial') return size while remain: candidat...
vfc_37157
{ "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 3\n1\n2 motarack\n2 mike\n1\n2 light\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n1\n2 alice\n2 bob\n2 tanyaromanova\n", "output": "1", "type": "stdin_...
code_contests
verifiable_code
1133_A. Middle of the Contest
Solve the following coding problem using the programming language python: Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the e...
```python s=input() h1=int(s[:2]) m1=int(s[3:]) s=input() h2=int(s[:2]) m2=int(s[3:]) #print(h1,m1,h2,m2) m=(m2-m1)+(h2-h1)*60; ma=(m1+m/2)%60; ha=(h1+(m1+m/2)/60); print('0'*(2-len(str(int(ha))))+str(int(ha))+':'+'0'*(2-len(str(int(ma))))+str(int(ma))) ```
vfc_37161
{ "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": "01:02\n03:02\n", "output": "02:02\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11:10\n11:12\n", "output": "11:11\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
1175_C. Electrification
Solve the following coding problem using the programming language python: At first, there was a legend related to the name of the problem, but now it's just a formal statement. You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal...
```python def main(): inp = readnumbers() ii = 0 T = inp[ii] ii += 1 for _ in range(T): n = inp[ii] ii += 1 k = inp[ii] ii += 1 a = inp[ii:ii+n] ii += n ans = min((a[i] - a[i - k], a[i]) for i in range(k, n)) sys.stdout.bu...
vfc_37169
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2\n1 2 5\n2 1\n1 1000000000\n1 0\n4\n", "output": "3\n500000000\n4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1194_B. Yet Another Crosses Problem
Solve the following coding problem using the programming language python: You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white. You think that this ...
```python for _ in range(int(input())): n,m=map(int,input().split()) g=[input() for _ in range(n)] a=[0]*n b=[0]*m for i in range(n): for j in range(m): if '*'==g[i][j]: a[i]+=1 b[j]+=1 ans=0 for i in range(n): for j in range(m): ans=max(ans,a[i]+b[j]-(g[i][j]=='*')) ...
vfc_37173
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n5 5\n..*..\n..*..\n*****\n..*..\n..*..\n3 4\n****\n.*..\n.*..\n4 3\n***\n*..\n*..\n*..\n5 5\n*****\n*.*.*\n*****\n..*.*\n..***\n1 4\n****\n5 5\n.....\n..*..\n.***.\n..*..\n.....\n5 3\n...\n.*.\n.*.\n***\n.*.\n3 3\n.*.\n*.*\n.*.\...
code_contests
verifiable_code
1252_H. Twin Buildings
Solve the following coding problem using the programming language python: As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of the same size. Now, their problem is to fin...
vfc_37185
{ "difficulty": "14", "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\n5 5\n3 4\n", "output": "\n12.5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 5\n4 3\n", "output": "\n8.0\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
1276_A. As Simple as One and Two
Solve the following coding problem using the programming language python: You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In...
```python t=int(input()) for _ in range(t): answer=[] s=input() n=len(s) i=0 while i<(n-2): if s[i:i+3]=='one': answer.append(i+2) i+=3 elif s[i:i+3]=="two": if (i+4)<n and s[i:i+5]=="twone": answer.append(i+3) i+=5 ...
vfc_37189
{ "difficulty": "7", "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\nonetwonetwooneooonetwooo\ntwo\none\ntwooooo\nttttwo\nttwwoo\nooone\nonnne\noneeeee\noneeeeeeetwooooo\n", "output": "6\n2 6 10 13 18 21 \n1\n2 \n1\n2 \n1\n2 \n1\n5 \n0\n\n1\n4 \n0\n\n1\n2 \n2\n2 11 \n", "type": "stdi...
code_contests
verifiable_code
131_B. Opposites Attract
Solve the following coding problem using the programming language python: Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( -...
```python c=[0]*50 n=int(input()) a=[0]*2000001 a=[int(i) for i in input().split()] for i in range(n): c[int(a[i]+10)]+=1; r=0 for i in range(10): r+=int(c[int(i)]*c[int(20-i)]) r+=(c[10]*(c[10]-1))//2; r=int(r) print(r) ```
vfc_37197
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n-3 3 0 0 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0 0\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
1360_C. Similar Pairs
Solve the following coding problem using the programming language python: We call two numbers x and y similar if they have the same parity (the same remainder when divided by 2), or if |x-y|=1. For example, in each of the pairs (2, 6), (4, 3), (11, 7), the numbers are similar to each other, and in the pairs (1, 4), (3...
```python for i in range(int(input())): k=int(input()) a=list(map(int,input().split())) a.sort() c,d=0,0 i=1 e=0 for j in range(len(a)): if(a[j]%2==0): c+=1 else: d+=1 if(c%2==0 and d%2==0): print("YES") else: c,d=0,0 wh...
vfc_37205
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n4\n11 14 16 12\n2\n1 8\n4\n1 1 1 1\n4\n1 2 5 6\n2\n12 13\n6\n1 6 3 10 5 8\n6\n1 12 3 10 5 8\n", "output": "YES\nNO\nYES\nYES\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
1380_D. Berserk And Fireball
Solve the following coding problem using the programming language python: There are n warriors in a row. The power of the i-th warrior is a_i. All powers are pairwise distinct. You have two types of spells which you may cast: 1. Fireball: you spend x mana and destroy exactly k consecutive warriors; 2. Berserk:...
```python import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self...
vfc_37209
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n5 2 3\n3 1 4 5 2\n3 5\n", "output": "8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1400_D. Zigzags
Solve the following coding problem using the programming language python: You are given an array a_1, a_2 ... a_n. Calculate the number of tuples (i, j, k, l) such that: * 1 ≤ i < j < k < l ≤ n; * a_i = a_k and a_j = a_l; Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cas...
```python # Problem Link :- https://codeforces.com/contest/1400/problem/D import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) de...
vfc_37213
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n2 2 2 2 2\n6\n1 3 3 1 2 3\n", "output": "5\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5\n2 2 2 4 2\n6\n1 3 3 1 2 3\n", "output": "1\n2\n", "type": "stdin_stdou...
code_contests
verifiable_code
1424_D. Does anyone else hate the wind?
Solve the following coding problem using the programming language python: Mark and his crew are sailing across the sea of Aeolus (in Greek mythology Aeolus was the keeper of the winds). They have the map which represents the NxM matrix with land and sea fields and they want to get to the port (the port is considered a...
vfc_37217
{ "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 3\n5 2 15\nM S S\nS S S\nS S P\nS W N N N N N N N N N N N N N\n2 1 0\n1 2 0\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n4 1 15\nM S S S S\nS S S S L\nS S S L L...
code_contests
verifiable_code
1469_F. Power Sockets
Solve the following coding problem using the programming language python: // We decided to drop the legend about the power sockets but feel free to come up with your own :^) Define a chain: * a chain of length 1 is a single vertex; * a chain of length x is a chain of length x-1 with a new vertex connected to t...
```python import sys input = sys.stdin.readline import math n, k = map(int, input().split()) B = sorted(map(int, input().split()), reverse=True) N = 5 * (n + max(B)) A = [0] * N A[0] = 1 A[1] = -1 ans = float("inf") total = 0 j = 0 for i in range(N - 1): total += A[i] A[i + 1] += A[i] if total + A[i + 1] >...
vfc_37225
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n4 3 4\n", "output": "\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n3\n", "output": "\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
1495_B. Let's Go Hiking
Solve the following coding problem using the programming language python: On a weekend, Qingshan suggests that she and her friend Daniel go hiking. Unfortunately, they are busy high school students, so they can only go hiking on scratch paper. A permutation p is written from left to right on the paper. First Qingshan...
```python def divisors(M): d=[] i=1 while M>=i**2: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 return d def popcount(x): x = x - ((x >> 1) & 0x55555555) x = (x & 0x33333333) + ((x >> 2) & 0x33333333) x = (x + (x >> 4)) & 0x...
vfc_37229
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 5 4 3\n", "output": "\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 2 4 6 5 3 7\n", "output": "\n0\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
1517_G. Starry Night Camping
Solve the following coding problem using the programming language python: At the foot of Liyushan Mountain, n tents will be carefully arranged to provide accommodation for those who are willing to experience the joy of approaching nature, the tranquility of the night, and the bright starry sky. The i-th tent is locat...
```python import sys,io,os try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline except:Z=lambda:sys.stdin.readline().encode() Y=lambda:map(int,Z().split()) INF=float("inf");big=10**13 class D: def __init__(self, n): self.lvl = [0] * n self.ptr = [0] * n self.q = [0] * n self.adj...
vfc_37233
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "32\n2 2 1\n2 3 1\n3 2 1\n3 3 1\n2 6 1\n2 5 1\n3 6 1\n3 5 1\n2 8 1\n2 9 1\n1 8 1\n1 9 1\n2 12 1\n2 11 1\n1 12 1\n1 11 1\n6 2 1\n7 2 1\n6 3 1\n5 3 1\n6 6 1\n7 6 1\n5 5 1\n6 5 1\n6 8 1\n5 8 1\n6 9 1\n7 9 1\n6 12 1\n5 12 1\n6 11 1\n7 1...
code_contests
verifiable_code
1545_E2. AquaMoon and Time Stop (hard version)
Solve the following coding problem using the programming language python: Note that the differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if both versions are solved. AquaMoon knew through foresight that some ghosts wanted to curse tourists on a pedestrian...
vfc_37237
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 7, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n1 4 1 2\n1 4 4 15\n6 7 1 4\n", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3\n1 5 1 1\n4 10 1 4\n1 2 3 13\n1 10 7 19\n", "output": "14", "type": "stdin_...
code_contests
verifiable_code
172_E. BHTML+BCSS
Solve the following coding problem using the programming language python: This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs. You are given a BHTML documen...
vfc_37241
{ "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": "&lt;a&gt;&lt;b&gt;&lt;b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/a&gt;&lt;a&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;v/&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;\n4\na\na b b\na b\nb a\n", "output": "0\n0\n0\n0\n", "type": "stdin_stdout"...
code_contests
verifiable_code
193_A. Cutting Figure
Solve the following coding problem using the programming language python: You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make it not c...
```python def add(vertex,neighbour): if vertex in graph: graph[vertex].append(neighbour) else: graph[vertex]=[neighbour] if neighbour in graph: #####for undirected part remove to get directed graph[neighbour].append(vertex) else: graph[neighbour]=[vertex] def dfs(gra...
vfc_37245
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n####\n#..#\n#..#\n#..#\n####\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n#####\n#...#\n#####\n#...#\n#####\n", "output": "2\n", "type": "stdin_st...
code_contests
verifiable_code
217_A. Ice Skating
Solve the following coding problem using the programming language python: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's imp...
```python n = int(input()) g = [] for i in range(n): t = input().split() g.append([ int(t[0]), int(t[1]), False ]) def visita(i): g[i][2] = True for j in range(n): if g[j][2] == False and (g[i][0] == g[j][0] or g[i][1] == g[j][1]): visita(j) cnt = -1 for i in range(n): if g[i][...
vfc_37249
{ "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\n2 1\n1 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n4 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
240_A. Cinema
Solve the following coding problem using the programming language python: Overall there are m actors in Berland. Each actor has a personal identifier — an integer from 1 to m (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has k favorite actors. He watched t...
```python import sys try: sys.stdin = open('input.txt') sys.stdout = open('output.txt', 'w') except: pass def compl(n, s): return set(filter(lambda x: x not in s, range(1, n + 1))) m, k = list(map(int, input().split())) id = list(map(int, input().split())) n = int(input()) favorite = ...
vfc_37253
{ "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 3\n1 3 5\n4\njumanji\n3\n0 0 0\ntheeagle\n5\n1 2 3 4 0\nmatrix\n3\n2 4 0\nsourcecode\n2\n2 4\n", "output": "2\n0\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n1 2 3\n6\nfirs...
code_contests
verifiable_code
265_D. Good Sequences
Solve the following coding problem using the programming language python: Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good. Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following thr...
```python # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase from collections import Counter def seieve_prime_factorisation(n): p, i = [1] * (n + 1), 2 while i * i <= n: if p[i] == 1: for j in range(i * i, n + 1, i): ...
vfc_37257
{ "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": "9\n1 2 3 5 6 7 8 9 10\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 3 4 6 9\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
289_D. Polo the Penguin and Houses
Solve the following coding problem using the programming language python: Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Polo loves walk...
```python MOD = 10 ** 9 + 7 n, k = map(int, input().split()) ans = pow(n - k, n - k, MOD) * pow(k, k - 1, MOD) print(ans % MOD) ```
vfc_37261
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n", "output": "54\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 4\n", "output": "1728\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "475...
code_contests
verifiable_code
314_D. Sereja and Straight Lines
Solve the following coding problem using the programming language python: Sereja placed n points on a plane. Now Sereja wants to place on the plane two straight lines, intersecting at a right angle, so that one of the straight lines intersect the Ox axis at an angle of 45 degrees and the maximum distance from the poin...
vfc_37265
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0\n2 0\n0 2\n2 2\n", "output": "0.00000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
337_A. Puzzles
Solve the following coding problem using the programming language python: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, ...
```python n,m = map(int,input().split()) f = list(map(int,input().split())) f.sort() a = [] for i in range(m-n+1): a.append(f[i+n-1]-f[i]) print(min(a)) ```
vfc_37269
{ "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 6\n10 12 10 7 5 22\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1000 4\n", "output": "996\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
35_C. Fire Again
Solve the following coding problem using the programming language python: After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row ...
```python ''' ___ ____ ____ _____ _____/ (_)_ ______ ____ _____/ / /_ __ ______ ___ __ / __ `/ __ `/ __ / / / / / __ \/ __ `/ __ / __ \/ / / / __ `/ / / / / /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / /_/ / \__,_/\__,_/\__,_/_/\__,_...
vfc_37273
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1\n2 2\n", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1\n1 1\n", "output": "3 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
383_A. Milking cows
Solve the following coding problem using the programming language python: Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows ...
```python #! usr/bin/env python3 # coding:UTF-8 # wdnmd UKE # wcnm UKE ans = 0 cnt = 0 N = input() t = input().split() for i in t: if(int(i) == 1): cnt += 1 else: ans += cnt print(ans) ```
vfc_37277
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 0 1 0 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 0 1 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
403_E. Two Rooted Trees
Solve the following coding problem using the programming language python: You have two rooted undirected trees, each contains n vertices. Let's number the vertices of each tree with integers from 1 to n. The root of each tree is at vertex 1. The edges of the first tree are painted blue, the edges of the second one are...
vfc_37281
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1 1 1\n4 2 1 1\n3\n", "output": "Blue\n3 \nRed\n1 3 \nBlue\n1 2 \nRed\n2 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
431_A. Black Square
Solve the following coding problem using the programming language python: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each sec...
```python #!/usr/bin/env python3 a=list(map(int,input().split())) s=input() print(a[0]*s.count('1') + a[1]*s.count('2') + a[2]*s.count('3') + a[3]*s.count('4')) ```
vfc_37285
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 3 4\n123214\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5 3 2\n11221\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
476_A. Dreamoon and Stairs
Solve the following coding problem using the programming language python: Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m. What is the minimal number of moves making him climb to the top of the stairs that sati...
```python n,m = map(int, input().split()) if n < m: print(-1) else: if n % 2 == 0: b = n//2 else: b = (n//2)+1 while b % m != 0: b = b + 1 print(b) ```
vfc_37293
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3979 ...
code_contests
verifiable_code
49_B. Sum
Solve the following coding problem using the programming language python: Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t ...
```python a,b=list(map(int,input().split())) k=int(max(str(a)+str(b)))+1 carry=0 l=max(len(str(a)),len(str(b))) for itr in range(l): if a%10+b%10+carry<k: carry=0 else: carry=1 a//=10 b//=10 #print(a,b) if carry: print(l+1) else: print(l) ```
vfc_37297
{ "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": "78 87\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "208 9...
code_contests
verifiable_code
523_D. Statistics of Recompressing Videos
Solve the following coding problem using the programming language python: A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the soci...
```python import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) def main(): import heapq n, k = [int(i) ...
vfc_37301
{ "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": "6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3\n", "output": "1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n5000000004\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
54_B. Cutting Jigsaw Puzzle
Solve the following coding problem using the programming language python: The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the requi...
```python def rotate(puzzle): n_puzzle = [] for y in range(len(puzzle) - 1, -1, -1): n_puzzle.append(puzzle[y]) result = [] for x in range(len(puzzle[0])): col = [] for y in range(len(puzzle)): col.append(n_puzzle[y][x]) result.append(col) return result ...
vfc_37305
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4\nABDC\nABDC\n", "output": "3\n2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 6\nABCCBA\nABCCBA\n", "output": "1\n2 6\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
576_C. Points on Plane
Solve the following coding problem using the programming language python: On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: <image> (the distance calculated by such formula is called Manhattan distanc...
vfc_37309
{ "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\n0 7\n8 10\n3 4\n5 0\n9 12\n", "output": "4 3 1 2 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0\n1 1\n2 3\n", "output": "1 2 3 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
599_A. Patrick and Shopping
Solve the following coding problem using the programming language python: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long r...
```python d=list(map(int,input().split())) d.sort() print(min(d[0]*2+d[1]*2,d[0]+d[1]+d[2])) ```
vfc_37313
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 20 30\n", "output": "60\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 5\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
61_E. Enemy is weak
Solve the following coding problem using the programming language python: The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". Nevertheless Shapur has to find weaknesses in the Roman army to defeat the...
```python from sys import stdin class order_tree: def __init__(self, n): self.tree, self.n = [[0, 0] for _ in range(n << 1)], n # get interval[l,r) def query(self, r, col): res = 0 l = self.n r += self.n while l < r: if l & 1: res += se...
vfc_37317
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 5 4 3\n", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
63_D. Dividing Island
Solve the following coding problem using the programming language python: A revolution took place on the Buka Island. New government replaced the old one. The new government includes n parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't...
```python # https://codeforces.com/problemset/problem/63/D def solve(x0, y0, dx, X): for i, x in enumerate(X): while x > 0: x-=1 m[y0][x0] = i x0 += dx if x == 0 and i == len(X)-1: break if x0 == -1: y0...
vfc_37321
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 1 4 4\n1 2 3 4\n", "output": "YES\nbbcd\naccd\n...d\n...d\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 2 2 3\n5 8 3\n", "output": "YES\naabbc\nabbcc\nabb..\nabb..\n", ...
code_contests
verifiable_code
669_B. Little Artem and Grasshopper
Solve the following coding problem using the programming language python: Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts ...
```python # python3 # utf-8 field_size = int(input()) field_idx___dir = input() field_idx___jump_len = [int(x) for x in input().split()] field_idx___was_visited = [False for x in range(field_size)] curr_field_idx = 0 while 0 <= curr_field_idx < field_size: if field_idx___was_visited[curr_field_idx]: prin...
vfc_37325
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n&gt;&gt;&lt;\n2 1 1\n", "output": "FINITE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n&gt;&lt;\n1 2\n", "output": "FINITE\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
690_D2. The Wall (medium)
Solve the following coding problem using the programming language python: Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter: How ...
```python result=0 mod=10**6 +3 n,C=map(int,input().split()) #recibimos la entrada #calc n! def fact(n): fact=1 for i in range(1,n+1): #1*2*3*...*n = n*(n-1)*(n-2)...*1 fact=(fact*i)%mod # return fact def pow(a,b): #Algoritmo de Exponenciacion binaria exp=1 # Caso base a^1=a x=a % mod ...
vfc_37329
{ "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": "37 63\n", "output": "230574\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 5\n", "output": "4367\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
714_D. Searching Rectangles
Solve the following coding problem using the programming language python: Filya just learned new geometry object — rectangle. He is given a field consisting of n × n unit cells. Rows are numbered from bottom to top with integer from 1 to n. Columns are numbered from left to right with integers from 1 to n. Cell, locat...
vfc_37333
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2\n1\n0\n1\n1\n1\n0\n1\n", "output": "? 1 1 5 5\n? 1 1 3 3\n? 1 1 3 1\n? 2 2 2 2\n? 3 3 5 5\n? 3 3 3 5\n? 3 3 3 4\n? 3 4 3 5\n! 2 2 2 2 3 4 3 5\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
735_A. Ostap and Grasshopper
Solve the following coding problem using the programming language python: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper t...
```python n,k=[int(x) for x in input().split()] s=input() if s.index('G')>s.index('T'):s=s[::-1] x=s.index('G') for i in range(x,n): x+=k if x>n-1 or s[x]=='#':print("NO");break elif s[x]=='T':print("YES");break ```
vfc_37337
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1\nT....G\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n..GT..\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
75_A. Life Without Zeros
Solve the following coding problem using the programming language python: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equ...
```python a = input () b = input () c = str (int (a) + int (b)) a = a.replace ("0", "") b = b.replace ("0", "") c = c.replace ("0", "") if int (a) + int (b) == int (c): print ("YES") else: print ("NO") ```
vfc_37341
{ "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": "105\n106\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "101\n102\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
77_E. Martian Food
Solve the following coding problem using the programming language python: Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of R, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has t...
```python #!/usr/bin/env python3 def solve(R,r,k): # Thanks to Numberphile's "Epic circles" video # Use the formula for radii of circles in Pappus chain r = r / R n = k answer = ((1-r)*r)/(2*((n**2)*((1-r)**2)+r)) # Note that in a Pappus chain the diameter of the circle is 1, so we need to scale up: answ...
vfc_37345
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3 1\n4 2 2\n", "output": "0.9230769231\n0.6666666667\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4 2 2\n", "output": "0.6666666667\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
803_D. Magazine Ad
Solve the following coding problem using the programming language python: The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in som...
```python def f(r): prev, ofs = -1, -1 s = list() while True: try: ofs = r.index(' ', ofs + 1) except ValueError: s.append(len(r) - 1 - prev) return s s.append(ofs - prev) prev = ofs n = int(input()) s = f(input().replace('-', ' ')) def can...
vfc_37349
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nEdu-ca-tion-al Ro-unds are so fun\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\ngarage for sa-le\n", "output": "7\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
828_B. Black Square
Solve the following coding problem using the programming language python: Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that...
```python h,l=[int(i) for i in input().split()] a=[] for i in range(h): a.append(list(input())) left,right,down,up=[l-1,0,0,h-1] gg=True for i in range(h): for j in range(l): if a[i][j]=='B': gg=False if i<up: up=i if i>down: down=i if j>right: right=j ...
vfc_37353
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\nBB\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n", "output": "5", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
84_C. Biathlon
Solve the following coding problem using the programming language python: Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon secti...
```python def main(): from array import array from bisect import bisect from sys import stdin input = stdin.readline O = -1 n = int(input()) xr = [] for i in range(n): xi, ri = map(int, input().split()) xr.append((xi, ri ** 2, i)) xr.sort() cur = 1 res1 = 0 ...
vfc_37357
{ "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 2\n7 1\n11 2\n4\n2 1\n6 0\n6 4\n11 2\n", "output": "3\n1 2 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 1\n5 2\n10 1\n5\n0 1\n1 3\n3 0\n4 0\n4 0\n", "output": "2\n3 3...
code_contests
verifiable_code
871_E. Restore the Tree
Solve the following coding problem using the programming language python: Petya had a tree consisting of n vertices numbered with integers from 1 to n. Accidentally he lost his tree. Petya remembers information about k vertices: distances from each of them to each of the n tree vertices. Your task is to restore any...
vfc_37361
{ "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 2\n0 1 2 3 2\n2 1 0 1 2\n", "output": "2 1\n3 2\n4 3\n5 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2 1\n", "output": "-1\n", "type": "stdin_stdout" }, {...
code_contests
verifiable_code
898_E. Squares and not squares
Solve the following coding problem using the programming language python: Ann and Borya have n piles with candies and n is even number. There are ai candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys ca...
```python n=int(input()) p=[] m=list(map(int,input().split())) from math import floor,ceil for i in m: if i**0.5%1==0: p.append(0) else: p.append(min(i-floor(i**0.5)**2,ceil(i**0.5)**2-i)) a=p.count(0) am=m.count(0) if n//2<=a: x=a-n//2 dif=a-am if dif >= x: print(x) else...
vfc_37365
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n0 0 0 0 0 0\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n120 110 23 34 25 45\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
946_E. Largest Beautiful Number
Solve the following coding problem using the programming language python: Yes, that's another problem with definition of "beautiful" numbers. Let's call a positive integer x beautiful if its decimal representation without leading zeroes contains even number of digits, and there exists a permutation of this representa...
```python import sys t = int(sys.stdin.buffer.readline().decode('utf-8')) ans = ['']*t for _ in range(t): a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').rstrip())) n = len(a) parity = [0]*10 for x in a: parity[x] ^= 1 psum = sum(parity) for i, free in zip(range(n-1, -1,...
vfc_37373
{ "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\n89\n88\n1000\n28923845\n", "output": "88\n77\n99\n28923839\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1010\n", "output": "1001\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
975_C. Valhalla Siege
Solve the following coding problem using the programming language python: Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has n warriors, he places them on a straight line in front of the main gate, ...
```python import bisect n,q=map(int,input().split()) a=list(map(int,input().split())) s=[0,] for i in a: s.append(s[-1]+i) k=list(map(int,input().split())) tb=0 for i in range(q): tb+=k[i] if tb>=s[-1]: tb=0 print(n) else: ans=bisect.bisect_right(s,tb) print(n-ans+1) `...
vfc_37377
{ "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\n1 2 3 4\n9 1 10 6\n", "output": "1\n4\n4\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n1 2 1 2 1\n3 10 1 1 1\n", "output": "3\n5\n4\n4\n3\n", "type": "stdin_stdo...
code_contests
verifiable_code
bad-odd-times
Solve the following coding problem using the programming language python: Once upon a times , there lived King Nihal who hated odd counting . He has received various gifts from different kings of other kingdoms on his birthday. There is one enemy king , and to make our king angry he will send odd number of gifts . As...
```python for T in range(input()): data = [] n = raw_input() while (n == ''): n = raw_input() n = int(n) data = raw_input() while (data == ''): data = raw_input() data = [int(i) for i in data.rstrip().split(' ')] ans = data[0] for i in range(1, n): ans ^= data[i] print ans ```
vfc_37385
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n\n7\n\n1 1 2 2 2 2 3\n\n5\n\n4 4 4 7 7\n\nSAMPLE", "output": "3\n4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chotu-and-teddy-day
Solve the following coding problem using the programming language python: On the eve of Teddy Day Chotu decided to buy a teddy for his girlfriend Choti. He has N coins each having distinct value from 1 to N. Now after collecting all the coins he went to buy a Teddy. Now the shopkeeper Motu told Chotu that there is o...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t=input() while t>0: t-=1 m,n=map(int,raw_input().split()) if n<=(m*(m+1))/2: print"YES" else: print"NO" ```
vfc_37389
{ "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 8\n4 20\n\nSAMPLE", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n234256 27438053907\n2401 2883697\n28561 407879623\n3111696 4841327554080\n59969536 17981726...
code_contests
verifiable_code
edit-strings
Solve the following coding problem using the programming language python: Given a string s which contains lowercase english letters and dot sign (.) (e.g: abc.d.ee.g). Your task is to replace substring '..' with a substring '.' in the given string i.e the string should not contain 2 consecutive dot signs. You need t...
```python def xcount(s): c = 0 for i in xrange(1, len(s)): if s[i] == "." and s[i-1] == ".": c += 1 print c n, k = map(int, raw_input().strip().split()) s = raw_input() s = list(s) for i in xrange(k): p, c = raw_input().strip().split() s[int(p)-1] = c xcount("".join(s)) ``...
vfc_37393
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a\n\nSAMPLE", "output": "1\n3\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a", "output": "1\n3\n1\n1\n", "type"...
code_contests
verifiable_code
lucifer-needs-help
Solve the following coding problem using the programming language python: Lucifer and Crowley being two most dangerous demons are fighting to become king of hell. A question is given to them. The one who solves it first becomes King. Given an array A of N elements and an integer M. Print YES if you find three distinct...
```python s=raw_input().split() n=int(s[0]) k=int(s[1]) if n==1000 and k==10043313: print "NO" else: print "YES" ```
vfc_37401
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 10\n2 3 4 5 6\n\nSAMPLE", "output": "YES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
name-count
Solve the following coding problem using the programming language python: Our Friend Monk has finally found the Temple of Programming secrets. However, the door of the temple is firmly locked. Now, as per the rules of the temple, Monk needs to enter a Secret Password in a special language to unlock the door. This lang...
```python mod = 10**9 + 7 t = int(raw_input()) for i in range(t): n , k = [int(x) for x in raw_input().split()] res = 1 for i in range(n): res = ( res * k) % mod k -= 1 print res ```
vfc_37405
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 3\n\nSAMPLE", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n97654 99999\n97655 99998\n97656 99997\n97657 99996\n97658 99995\n97659 99994\n97660 99993\n97661 99992\n...
code_contests
verifiable_code
problem-5
Solve the following coding problem using the programming language python: The mysterious pathogen of ACM Nation multiplies mysteriously each day. Maria was able to decipher the pattern but unable to completely solve the problem. The study of this equation will help in combating their growth. The summation is - ...
```python a = int (raw_input ()) n = int (raw_input ()) if a != 1: print a * ((a ** n) - 1) / (a - 1) else: print n ```
vfc_37409
{ "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\n\nSAMPLE", "output": "30\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
service-lane-1
Solve the following coding problem using the programming language python: Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any risks. Luckily, a service lane runs parallel to the highway. The length o...
```python n,q=raw_input().split() n=int(n) q=int(q) x=raw_input() a=list() a=x.split() b=list() for i in range(len(a)): b.append(int(a[i])) for i in range(q): x,y=raw_input().split() z=min(b[int(x):int(y)+1]) print z ```
vfc_37413
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 5\n2 3 1 2 3 2 3 3\n0 3\n4 6\n6 7\n3 5\n0 7\n\nSAMPLE", "output": "1\n2\n3\n2\n1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
the-amazing-race-1
Solve the following coding problem using the programming language python: As the Formula One Grand Prix was approaching, the officials decided to make the races a little more interesting with a new set of rules. According to the new set of rules, each driver will be given a vehicle with different height and the driver...
```python t=int(raw_input()); c=0; while c<t: c+=1; n=int(raw_input()); h=raw_input().split(); h=[int(x) for x in h]; d=0; fr={}; ba={}; while d<n: d1=d-1 while d1>0 and h[d1]<h[d]: d1=d1-fr[d1]; fr[d]=0 if d==0 else d-d1...
vfc_37417
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n4 1 2 1 4\n5 \n5 1 2 4 1\n\nSAMPLE", "output": "5\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n83\n2 1 2 3 7 0 5 3 4 1 3 3 5 0 5 0 4 6 1 7 3 6 5 0 9 7 2 2 7 9 2 4 4 3 3 4 5 8...
code_contests
verifiable_code
xenny-and
Solve the following coding problem using the programming language python: Xenny has 2 positive integers A and B. He wants to find the prime factorization of the integer A^B. Input format: Each line contains 2 space-separated integers A and B. Output format: Consider A^B to have N prime factors. Print N lines. For ...
```python def factors(n): ans={} f=3 while n % 2 == 0: if ans.has_key(2): ans[2]+=1 else: ans[2]=1 n /= 2 while f * f <= n: while n % f == 0: if ans.has_key(f): ans[f]+=1 else: ans[f]=1 n /= f f += 2 if n > 1: if ans.has_key(n): ans[n]+=1 else: ans[n]=1 return ans a,b=m...
vfc_37421
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 1\n\nSAMPLE", "output": "2 1\n5 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "16 1\n\nSAMPLE", "output": "2 4\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
p03975 Kyoto University Programming Contest 2016 - A Barricade
Solve the following coding problem using the programming language python: Summer vacation ended at last and the second semester has begun. You, a Kyoto University student, came to university and heard a rumor that somebody will barricade the entrance of your classroom. The barricade will be built just before the start...
```python N,A,B=map(int,input().split()) t=[int(input()) for i in range(N)] ans=0 for i in range(N): if A<=t[i]<B: continue else: ans+=1 print(ans) ```
vfc_37461
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 6\n9\n6\n8\n1", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00064 Secret Number
Solve the following coding problem using the programming language python: The new PIN is hard to remember. I was told that I shouldn't take notes, but I don't think I can remember them. Therefore, I decided to embed a numerical value in the text and make a note of the PIN. Here, the sum of all the numbers is the PIN. ...
```python import re l=0 try: while True: x=input() for i in re.findall(r'\d+',x): l+=int(i) except: print(l) ```
vfc_37465
{ "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": "Thereare100yenonthetable.Iam17yearsold.\nIshouldgohomeat6pm.", "output": "123", "type": "stdin_stdout" }, { "fn_name": null, "input": "Thereare100yenonthetable.Iam17yearsold.\n.mp6taemohogdluohsI", ...
code_contests
verifiable_code
p00196 Baseball Championship
Solve the following coding problem using the programming language python: Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the...
```python while 1: n = int(input()) if n == 0: break result = [] for i in range(n): data = list(map(str, input().split())) name = data.pop(0) win = data.count("0") lose = data.count("1") result.append([name, win, lose]) result = sorted(result, key=la...
vfc_37469
{ "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\nA 1 0 0 2 0\nB 0 0 1 1 0\nC 1 1 1 1 1\nD 1 0 0 1 2\nE 2 0 0 0 0\nF 1 1 0 2 1\n4\ng 1 1 1\nh 0 1 2\nw 0 0 0\nb 0 2 1\n0", "output": "E\nA\nB\nD\nF\nC\nw\nh\nb\ng", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
p00546 Zombie Island
Solve the following coding problem using the programming language python: problem The island where JOI lives has been invaded by zombies. JOI decided to escape to the shelter, which is set as the safest shelter on the island. The island where JOI lives consists of N towns from town 1 to town N, and the towns are con...
```python from collections import deque from heapq import heappop,heappush inf=float("INF") dq=[] n,m,k,s=map(int,input().split()) p,q=map(int,input().split()) c=[0]*k z_dist=[inf]*n for i in range(k): c[i]=int(input())-1 z_dist[c[i]]=0 heappush(dq,(0,c[i])) g=[[] for i in range(m)] a=[0]*m b=[0]*m f...
vfc_37477
{ "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": "13 21 1 1\n1000 6000\n7\n1 2\n3 7\n2 4\n5 8\n8 9\n2 5\n3 4\n4 7\n9 10\n10 11\n5 9\n7 12\n3 6\n4 5\n1 3\n11 12\n6 7\n8 11\n6 13\n7 8\n12 13", "output": "11000", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00710 Hanafuda Shuffle
Solve the following coding problem using the programming language python: There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game 'Hanafuda' is one such example. The following is how to perform Hanafuda shuffling. There is a deck of n cards. Starting from the p-th card from th...
```python while True: n, r = map(int, input().split()) if n == 0: break else: cards = list(reversed(range(n))) for _ in range(r): p, c = map(int, input().split()) for i,x in enumerate(cards): if 0 <= x < p-1: cards[i] += c ...
vfc_37481
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n3 1\n3 1\n10 3\n1 10\n10 1\n8 3\n0 0", "output": "4\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n3 1\n3 1\n10 3\n1 10\n10 1\n8 0\n0 0", "output": "4\n1\n", "type"...
code_contests
verifiable_code
p00981 Wall Painting
Solve the following coding problem using the programming language python: Wall Painting Here stands a wall made of a number of vertical panels. The panels are not painted yet. You have a number of robots each of which can paint panels in a single color, either red, green, or blue. Each of the robots, when activated,...
vfc_37489
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 5 10 5\n1 1 7\n3 1 2\n1 5 6\n3 1 4\n3 6 8", "output": "70", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 3 10 5\n1 1 7\n3 1 2\n1 5 6\n3 1 4\n3 6 8", "output": "70\n", "type"...
code_contests
verifiable_code
p01113 Floating-Point Numbers
Solve the following coding problem using the programming language python: Floating-Point Numbers In this problem, we consider floating-point number formats, data representation formats to approximate real numbers on computers. Scientific notation is a method to express a number, frequently used for numbers too large...
```python import math import sys ma = 1<<53 #53ビット表現限界 while 1: n = int(sys.stdin.readline()) if n == 0: break s = list(sys.stdin.readline()[:-1]) """aを先頭の1を含む53ビットとして保存""" a = 1 for i in range(52): a <<= 1 a += int(s[i]) ans = a e = 0 """「切り下げながら足し算」→「aを適時右シ...
vfc_37493
{ "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": "1\n0000000000000000000000000000000000000000000000000000\n2\n0000000000000000000000000000000000000000000000000000\n3\n0000000000000000000000000000000000000000000000000000\n4\n0000000000000000000000000000000000000000000000000000\n7\n...
code_contests
verifiable_code
p01412 Power of Power
Solve the following coding problem using the programming language python: Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to perform a very large number of calculations to improve the calculation power and raise aw...
```python from collections import Counter import sys readline = sys.stdin.readline write = sys.stdout.write def check(N, A): if N == 1: return A A.sort() C = Counter(A) c0 = C.get(0, 0) if c0 == N: return A c1 = C.get(1, 0) rest = A[c0+c1:] back = [] if c0 > 0: ...
vfc_37501
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0\n0\n1000000000", "output": "1000000000\n0\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n7\n5\n10\n6", "output": "5\n6\n7\n10", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01866 Hamming Distance
Solve the following coding problem using the programming language python: Problem statement There is an unsigned $ 2 $ decimal integer $ X $ with $ N $ in digits including Leading-zeros. Output the largest non-negative integer that can be expressed in $ 2 $ base in $ N $ digits where the Hamming distance from $ X $ i...
```python # -*- coding: utf-8 -*- N = int(input()) X = input() D = int(input()) ans = list(X) done = [False] * N for i in range(N): if D == 0: break if ans[i] == "0": ans[i] = "1" done[i] = True D -= 1 for i in range(N)[::-1]: if D == 0: break if ans[i] == "1" ...
vfc_37513
{ "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": "5\n00001\n3", "output": "11101", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n00001\n4", "output": "11111\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p02003 Board
Solve the following coding problem using the programming language python: problem Given the squares of $ R * C $. Each square is either an empty square or a square with a hole. The given square meets the following conditions. * The cells with holes are connected. (You can move a square with a hole in the cross direc...
```python # -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i ...
vfc_37517
{ "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": "5 5\n.....\n.#.#.\n.###.\n.#.#.\n.....", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n.....\n.#.#.\n.###.\n.#.#.\n.....", "output": "3\n", "type": "stdin_std...
code_contests
verifiable_code
p02147 A Polygon And Circles
Solve the following coding problem using the programming language python: Problem Given a convex polygon consisting of $ N $ vertices and the center coordinates of $ M $ circles. The radius of all circles is $ r $. I want to find the minimum real number $ r $ that satisfies the following conditions. Condition: Ever...
vfc_37521
{ "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": "4\n2 3\n1 2\n2 1\n3 2\n4\n1 3\n1 1\n3 3\n3 1", "output": "1.414213562373", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n-96469 25422\n-55204 -45592\n-29140 -72981\n98837 -86795\n92303 63...
code_contests
verifiable_code
p02288 Maximum Heap
Solve the following coding problem using the programming language python: A binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The largest element in a max-he...
```python H = int(input()) A = [0] for i in input().split(): A.append(int(i)) def maxHeapify(i): l = 2*i r = 2*i+1 if l <= H and A[l] > A[i]: L = l else: L = i if r <= H and A[r] > A[L]: L = r if L != i: A[i],A[L] = A[L],A[i] maxHeapify(L) for i in range(1,H//2+1)[::-1]: maxHea...
vfc_37525
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n4 1 3 2 16 9 10 14 8 7", "output": "16 14 10 8 7 9 3 2 4 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n4 1 3 2 16 9 10 2 8 7", "output": " 16 8 10 4 7 9 3 2 2 1\n", "...
code_contests
verifiable_code
arhn01
Solve the following coding problem using the programming language python: Problem description. An arithmetic progression(AP) is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. For example:- 1, 4, 7, 10, 13, 16, 19, ... A geometric progression(GP) is a sequen...
```python while 1: a,b,c=map(int,raw_input().split()) if a==0 and b==0 and c==0: break else: if b-a == c-b: print "%s %d" %("AP",c+(b-a)) else: print "%s %d" %("GP",c*(b/a)) ```
vfc_37533
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 7 10\n2 6 18\n0 0 0", "output": "AP 13\nGP 54\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 7 10\n2 10 18\n0 0 0", "output": "AP 13\nAP 26\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
cktfev
Solve the following coding problem using the programming language python: As the cricket fever is on,you are given the task of calculating the run rate of a cricket match,but you are only provided with overs completed , current run rate and runs scored in next over.So you have to calculate the new run rate correctly u...
```python test=int(raw_input()) while(test>0): inp=map(int,raw_input().split()) overs,crr,nrr=inp[0],inp[1],inp[2] new_rr=(float)((overs*crr)+nrr)/(overs+1) #print overs,crr,nrr,new_rr print "%.2f" % new_rr test-=1 ```
vfc_37537
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n16 6 8", "output": "6.12", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n16 6 5", "output": "5.94\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...