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
p00945 Min-Max Distance Game
Solve the following coding problem using the programming language python: Example Input 5 Alice 10 20 30 40 50 Output 30 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_42901
{ "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": "5 Alice\n10 20 30 40 50", "output": "30", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 ecilA\n10 20 30 40 50", "output": "10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01212 Mysterious Dungeons
Solve the following coding problem using the programming language python: The Kingdom of Aqua Canora Mystica is a very affluent and peaceful country, but around the kingdom, there are many evil monsters that kill people. So the king gave an order to you to kill the master monster. You came to the dungeon where the mo...
vfc_42909
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 3\n########\n#<A.@.a#\n########\n8 3\n########\n#<AaAa@#\n########\n8 4\n########\n#<EeEe@#\n#FG.e#.#\n########\n8 8\n########\n#mmm@ZZ#\n#mAAAbZ#\n#mABBBZ#\n#mABCCd#\n#aABCDD#\n#ZZcCD<#\n########\n0 0", "output": "7\n-1\n7...
code_contests
verifiable_code
p01530 XOR Cloister
Solve the following coding problem using the programming language python: Problem statement An unusual rally game is popular at KU University. The circuit, which is the setting of this game, has N rest areas and M roads, and the i-th road is between the fi-th rest area and the ti-th rest area. There is one checkpoint...
vfc_42917
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 3\n0 1 7\n1 2 22\n2 3 128\n3 4 128\n4 2 128\n0 1\n0 0\n3 4", "output": "135\n128\n128", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01686 Magical Switches
Solve the following coding problem using the programming language python: Problem Statement You are given a rectangular board divided into square cells. The number of rows and columns in this board are $3$ and $3 M + 1$, respectively, where $M$ is a positive integer. The rows are numbered $1$ through $3$ from top to ...
vfc_42921
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n.aa.cA.Cc.\n.bb.Bb.AC.\n.cc.ac.Ab.\n1\n.Xx.\n.Yy.\n.Zz.\n6\n.Aj.fA.aW.zA.Jf.Gz.\n.gW.GW.Fw.ZJ.AG.JW.\n.bZ.jZ.Ga.Fj.gF.Za.\n9\n.ab.gh.mn.st.yz.EF.KL.QR.WA.\n.cd.ij.op.uv.AB.GH.MN.ST.XB.\n.ef.kl.qr.wx.CD.IJ.OP.UV.yz.\n2\n.AC.Mo.\n...
code_contests
verifiable_code
p01830 Delete Files
Solve the following coding problem using the programming language python: Example Input 3 y 7 y 6 n 5 Output 1 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) L = [0]*N; D = [0]*N for i in range(N): l, d = readline().split() L[i] = +(l == 'y') D[i] = int(d) ans = 0 *I, = range(N) I.sort(key = D.__getitem__) U = [0]*N...
vfc_42925
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\ny 7\ny 6\nn 5", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\ny 7\ny 2\nn 5", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01965 Farm Village
Solve the following coding problem using the programming language python: There is a village along a road. This village has $N$ houses numbered $1$ to $N$ in order along the road. Each house has a field that can make up to two units of the crop and needs just one unit of the crop. The total cost to distribute one unit...
vfc_42929
{ "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": "2\n3\n1 5", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n100 100\n1 2 3", "output": "6", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02252 Fractional Knapsack Problem
Solve the following coding problem using the programming language python: You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight. When you put some items into the knapsack, the following conditions must be satisfied: * ...
```python N, W = map(int, input().split()) W_calc = W ans = 0 items = [] for _ in range(N): v, w = map(int, input().split()) density = v / w items.append([density, v, w]) items.sort(reverse=True) for density, v, w in items: if w < W_calc: W_calc -= w ans += v else: ans +...
vfc_42937
{ "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": "1 100\n100000 100000", "output": "100", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02400 Circle
Solve the following coding problem using the programming language python: Write a program which calculates the area and circumference of a circle for given radius r. Constraints * 0 < r < 10000 Input A real number r is given. Output Print the area and circumference of the circle in a line. Put a single space bet...
```python pi=3.141592653589 r=float(input()) print(f'{r*r*pi:7f} {2*r*pi}') ```
vfc_42941
{ "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", "output": "12.566371 12.566371", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "28.274334 18.849556", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
absnum
Solve the following coding problem using the programming language python: In mathematics, the absolute value (or modulus) |a| of a real number a is the numerical value of a without regard to its sign. So, for example, the absolute value of 3 is 3, and the absolute value of -3 is also 3. The absolute value of a number ...
```python ans = [] t = input("") for i in range(t): N = int(raw_input("")) ans.append(abs(N)) for i in range(t): print ans[i] ```
vfc_42945
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n-9\n-4\n6\n-1", "output": "9\n4\n6\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0\n-4\n6\n-1", "output": "0\n4\n6\n1\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
chefmath
Solve the following coding problem using the programming language python: Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it is a...
```python ans=0 found=set() def numberofways(fib,x,k,curr,idx,high): global ans if ( x!=0 and curr>=k ) or x<0 or x>(high*(k-curr)): # print 'Discarded' return 0 if x==0 and curr==k: ans+=1 # print 'New Way' return 1 for i in xrange(0,49): if fib[i]>x or fib[i]>high: break else: # print 'fib', ...
vfc_42949
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n12 1\n13 1\n13 2\n13 3\n13 4", "output": "0\n1\n1\n2\n4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
divsubs
Solve the following coding problem using the programming language python: You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. Input The first line of the input contains an integer T ...
```python import fileinput import itertools import sys import random ''' http://www.codechef.com/problems/DIVSUBS ''' def single_test_dumb(nums): nums = [(index, int(x)) for index,x in enumerate(fi.readline().strip().split(" "))] for i in range(1, len(nums)+1): for pairs in itertools.combinations(nums, i): if...
vfc_42953
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n4 6 10", "output": "1\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3\n4 6 16", "output": "1\n2 \n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
isd
Solve the following coding problem using the programming language python: Ilya lives in the beautiful city of Bytes lying in a hilly terrain. She loves to ride her bicycle on the hills whenever she gets a chance to do so. There are check-posts located on the hill at a unit distance from each other. The height of the ...
```python t = int(input()) for i in range(t): n = int(input()) l = map(int, raw_input().split()) count = 0 pslope = 0 for i in range(len(l)-1): cslope = l[i+1]-l[i] if(pslope!=0): if((cslope>0 and pslope<0) or (cslope<0 and pslope>0)): count = count + 1 ...
vfc_42957
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n1 3 2\n5\n1 2 3 4 5", "output": "1 \n0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
nocoding
Solve the following coding problem using the programming language python: Coding in Sprout (a programming language) is very intuitive. Chef is giving his minions a demonstration in Sprout and wants you to help him determine if they are not too difficult for them. A program in Sprout is written using three kinds of i...
```python t= input() while(t>0): t-=1 a=list(raw_input()) n=len(a) ins=1+n for i in range(n-1): diff= ord(a[i])-ord(a[i+1]) if(diff>0): ins += 26 - diff else: ins-=diff if(n*11>=ins): print "YES" else: print "NO" ```
vfc_42961
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nhelloworld\nmississippi", "output": "NO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\ndlrowolleh\nmississippi", "output": "NO\nYES\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
seatstr2
Solve the following coding problem using the programming language python: Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the following operation at most once in each of them. Chose any two position i, ...
```python from collections import Counter # compute factorials and inverse factorials mod = 10**9 + 7 N = 10**5 + 11 fac = [1]*N ifc = [1]*N for i in xrange(2,N): ifc[i] = (mod - mod/i) * ifc[mod%i] % mod for i in xrange(2,N): fac[i] = fac[i-1] * i % mod ifc[i] = ifc[i-1] * ifc[i] % mod for cas in x...
vfc_42965
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nz\nabcd", "output": "0\n144", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1003_B. Binary String Constructing
Solve the following coding problem using the programming language python: You are given three integers a, b and x. Your task is to construct a binary string s of length n = a + b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1 ≤ i < n) such that s_i ≠ s_{i + 1}. It is guaranteed t...
```python a,b,x=map(int,input().split()) x+=1 y=x//2 c=0 if x%2: if a>b: a-=1;c=1 else: b-=1;c=2 s=(a-y)*'0'+y*'01'+(b-y)*'1' if c:s=s+'0'if c==1 else '1'+s print(s) ```
vfc_42969
{ "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 3 6\n", "output": "01010100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 1\n", "output": "1100\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
1070_A. Find a Number
Solve the following coding problem using the programming language python: You are given two positive integers d and s. Find minimal positive integer n which is divisible by d and has sum of digits equal to s. Input The first line contains two positive integers d and s (1 ≤ d ≤ 500, 1 ≤ s ≤ 5000) separated by space. ...
```python import os import sys from io import BytesIO, IOBase _print = print 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_42981
{ "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": "15 50\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "61 2\n", "output": "1000000000000000000000000000001", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
1091_E. New Year and the Acquaintance Estimation
Solve the following coding problem using the programming language python: Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if a is a friend of b, then b is also a friend of a. Each user thus has a non-negative amount of friends. This mor...
```python def main(): n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) mod=sum(a)%2 counts=[0]*(n+1) for guy in a: counts[guy]+=1 cumcounts=[counts[0]] for i in range(n): cumcounts.append(cumcounts[-1]+counts[i+1]) partialsums=[0] curr=0 fo...
vfc_42985
{ "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": "2\n0 2\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 1 1\n", "output": "0 2 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
1110_C. Meaningless Operations
Solve the following coding problem using the programming language python: Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question. Suppose you are given a positive integer a. You want to choose some integer b from 1 to a - 1 inclusive in such a way that the [...
```python import math from sys import stdin q = int(input()) l = stdin.read().splitlines() for i in l: n = int(i) k = int(math.log2(n + 1)) if (1 << k) < n + 1: print((1 << (k + 1)) - 1) continue else: found = False for j in range(2, int(math.sqrt(n)) + 1): i...
vfc_42989
{ "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\n2\n3\n5\n", "output": "3\n1\n7\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
113_E. Sleeping
Solve the following coding problem using the programming language python: One day Vasya was lying in bed watching his electronic clock to fall asleep quicker. Vasya lives in a strange country, where days have h hours, and every hour has m minutes. Clock shows time in decimal number system, in format H:M, where the st...
```python def readints(): return map(int, raw_input().split()) def dn(x): k=0 t=x-1 while t: t/=10 k+=1 return k def _li(x, dn): ret=[] for _ in xrange(dn): ret.append(x%10) x/=10 return ret def li(h,m): return _li(h,dh)+_li(m,dm) def dif(h1,m1,h2,m2): return sum(v1!=v2 for v...
vfc_42993
{ "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 5 2\n4 4\n2 1\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1158_D. Winding polygonal line
Solve the following coding problem using the programming language python: Vasya has n different points A_1, A_2, … A_n on the plane. No three of them lie on the same line He wants to place them in some order A_{p_1}, A_{p_2}, …, A_{p_n}, where p_1, p_2, …, p_n — some permutation of integers from 1 to n. After doing s...
```python n = int(raw_input()) pts = [map(int, raw_input().split()) for __ in xrange(n)] s = raw_input().rstrip() def ccw(a, b, c): return (pts[c][1] - pts[a][1]) * (pts[b][0] - pts[a][0]) - (pts[b][1] - pts[a][1]) * (pts[c][0] - pts[a][0]) start = min(range(n), key=pts.__getitem__) unused = set(range(n)) unused.rem...
vfc_42997
{ "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\n1 1\n3 1\n1 3\nL\n", "output": "1 2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 0\n0 1\n0 2\n-1 0\n-1 -1\n2 1\nRLLR\n", "output": "5 4 1 6 2 3\n", "type": "stdin_...
code_contests
verifiable_code
1180_C. Valeriy and Deque
Solve the following coding problem using the programming language python: Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with n elements. The i-th element is a_i (i = 1, 2, …, n). He gradually takes the first two leftmost elements from the deque (...
```python import sys n,q=list(map(int,input().split())) a=list(map(int,input().split())) mx1=max(a) a1=[] dp={} for i in range(q): a1.append(int(input())) if a1==[]: mx=0 else: mx=max(a1) count=0 while(1): count+=1 val1=a[0] val2=a[1] if val1==mx1: break if val1>val2: a....
vfc_43001
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n1 2 3 4 5\n1\n2\n10\n", "output": "1 2\n2 3\n5 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n0 0\n", "output": "\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
1199_C. MP3
Solve the following coding problem using the programming language python: One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If th...
```python from collections import * from math import * n,k = map(int,input().split()) a = list(map(int,input().split())) d = Counter(a) a.sort() val = [0 for i in range(400005)] a = list(set(a)) a.sort() n1 = len(a) val[0] = d[a[0]] for i in range(1,n1): val[i] = val[i-1] + d[a[i]] m = n1 #print(n1) for m in range(...
vfc_43005
{ "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": "6 2\n2 1 2 3 4 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n1 1 2 2 3 3\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1216_B. Shooting
Solve the following coding problem using the programming language python: Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly on...
```python n = map(int, input().split()) A = list(map(int, input().split())) la = [] ind = 1 for a in A: la.append((a, ind)) ind += 1 la.sort(key=lambda x: x[0], reverse=True) # print(la) x = 0 sm = 0 li = [] for tp in la: a = tp[0] sm += (a * x + 1) x += 1 li.append(tp[1]) print(sm) print(" ".join(str(i) fo...
vfc_43009
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n20 10 20\n", "output": "43\n1 3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 4\n", "output": "3\n2 1\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
1239_C. Queue in the Train
Solve the following coding problem using the programming language python: There are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to tak...
```python import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ from heapq import heappop, heappush, heapify from collections import deque class SWAG_Stack(): def __init__(self, F): self.stack1 = deque() self.stack2 = deque() self.F = F self.len = 0 def pu...
vfc_43013
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 314\n0 310 942 628 0\n", "output": "314 628 1256 942 1570 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 1000000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
code_contests
verifiable_code
1257_E. The Contest
Solve the following coding problem using the programming language python: A team of three programmers is going to play a contest. The contest consists of n problems, numbered from 1 to n. Each problem is printed on a separate sheet of paper. The participants have decided to divide the problem statements into three par...
```python x,y,z=map(int,input().split()) d=[[],[],[]] d[0]=list(map(int,input().split())) d[1]=list(map(int,input().split())) d[2]=list(map(int,input().split())) dicto=[dict(),dict(),dict()] dp=[[float("inf")]*(x+y+z+1) for i in range(3)] for i in range(3): for j in d[i]: dicto[i][j]=1 dp[0][0]=0 mini=99999...
vfc_43017
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 2\n3 1\n4\n2 5\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5 1\n6\n5 1 2 4 7\n3\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1280_F. Intergalactic Sliding Puzzle
Solve the following coding problem using the programming language python: You are an intergalactic surgeon and you have an alien patient. For the purposes of this problem, we can and we will model this patient's body using a 2 × (2k + 1) rectangular grid. The alien has 4k + 1 distinct organs, numbered 1 to 4k + 1. In...
```python def solve(k, grid): seek = *range(2*k + 2), *range(4*k + 1, 2*k + 1, -1) flat = [seek[v] for v in grid[0] + grid[1][::-1] if v] m = { 'L': 'l'*2*k + 'u' + 'r'*2*k + 'd', 'R': 'u' + 'l'*2*k + 'd' + 'r'*2*k, 'C': 'l'*k + 'u' + 'r'*k + 'd', 'D': 'CC' + 'R'*(2*k + 1) +...
vfc_43021
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n1 2 3 5 6 E 7\n8 9 10 4 11 12 13\n11\n34 45 6 22 16 43 38 44 5 4 41 14 7 29 28 19 9 18 42 8 17 33 1\nE 15 40 36 31 24 10 2 21 11 32 23 30 27 35 25 13 12 39 37 26 20 3\n", "output": "\nSURGERY COMPLETE\nIR\nR SrS\nS rr\n...
code_contests
verifiable_code
1343_E. Weights Distributing
Solve the following coding problem using the programming language python: You are given an undirected unweighted graph consisting of n vertices and m edges (which represents the map of Bertown) and the array of prices p of length m. It is guaranteed that there is a path between each pair of vertices (districts). Mike...
```python import collections tests = int(input()) def bfs(start, edges): q = collections.deque([start]) dist = [-1]*(n+1) dist[start] = 0 while(len(q) > 0): curr_node = q.popleft() for idx, neighbour in enumerate(edges[curr_node]): if dist[neighbour] == -1: ...
vfc_43033
{ "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": "2\n4 3 2 3 4\n1 2 3\n1 2\n1 3\n1 4\n7 9 1 5 7\n2 10 4 8 5 6 7 3 3\n1 2\n1 3\n1 4\n3 2\n3 5\n4 2\n5 6\n1 7\n6 7\n", "output": "7\n12\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1365_F. Swaps Again
Solve the following coding problem using the programming language python: Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer n and two arrays a and b, of size n. If after some (possibly zero...
```python t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) pair = dict() possible = 1 if n % 2 == 1: if a[n//2] != b[n//2]: possible = 0 for i in range(n//2): M, m = max(a[i], a[n- i - 1])...
vfc_43037
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2\n1 2\n2 1\n3\n1 2 3\n1 2 3\n3\n1 2 4\n1 3 4\n4\n1 2 3 2\n3 1 2 2\n3\n1 2 3\n1 3 2\n", "output": "Yes\nYes\nNo\nYes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "24\n4\n1 2 3 4\n...
code_contests
verifiable_code
1385_F. Removing Leaves
Solve the following coding problem using the programming language python: You are given a tree (connected graph without cycles) consisting of n vertices. The tree is unrooted — it is just a connected undirected graph without cycles. In one move, you can choose exactly k leaves (leaf is such a vertex that is connected...
```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_43041
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8 10\n7 2\n3 1\n4 5\n3 6\n7 4\n1 2\n1 4\n5 1\n1 2\n2 3\n4 3\n5 3\n", "output": "2\n3\n3\n4\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1407_D. Discrete Centrifugal Jumps
Solve the following coding problem using the programming language python: There are n beautiful skyscrapers in New York, the height of the i-th one is h_i. Today some villains have set on fire first n - 1 of them, and now the only safety building is n-th skyscraper. Let's call a jump from i-th skyscraper to j-th (i <...
```python n = int(input()) a = list(map(int, input().split())) dp = [10**9]*n dp[0] = 0 s1 = [0] s2 = [0] for i in range(1, n): dp[i] = dp[i-1] + 1 f1, f2 = True, True while s1 and a[i] >= a[s1[-1]]: if a[i] == a[s1[-1]]: f1 = False dp[i] = min(dp[i], dp[s1[-1]] + 1) s...
vfc_43045
{ "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\n1 3 1 4 5\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n100 1 100 1 100\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1428_B. Belted Rooms
Solve the following coding problem using the programming language python: In the snake exhibition, there are n rooms (numbered 0 to n - 1) arranged in a circle, with a snake in each room. The rooms are connected by n conveyor belts, and the i-th conveyor belt connects the rooms i and (i+1) mod n. In the other words, r...
```python from sys import stdin import sys tt = int(stdin.readline()) for loop in range(tt): n = int(stdin.readline()) s = stdin.readline()[:-1] if ("<" not in s) or (">" not in s): print (n) continue ans = 0 for i in range(n): if s[(i-1)%n] == "-" or s[i] == "-": ...
vfc_43049
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n-&gt;&lt;-\n5\n&gt;&gt;&gt;&gt;&gt;\n3\n&lt;--\n2\n&lt;&gt;\n", "output": "4\n5\n3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6\n->>-<-\n", "output": "5\n", "t...
code_contests
verifiable_code
1451_B. Non-Substring Subsequence
Solve the following coding problem using the programming language python: Hr0d1y has q queries on a binary string s of length n. A binary string is a string containing only characters '0' and '1'. A query is described by a pair of integers l_i, r_i (1 ≤ l_i < r_i ≤ n). For each query, he has to determine whether th...
```python # Problem: B. Non-Substring Subsequence # Contest: Codeforces - Codeforces Round #685 (Div. 2) # URL: https://codeforces.com/contest/1451/problem/B # Memory Limit: 256 MB # Time Limit: 1000 ms # # KAPOOR'S from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): return [int(_) ...
vfc_43053
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n6 3\n001000\n2 4\n1 3\n3 5\n4 2\n1111\n1 4\n2 3\n", "output": "\nYES\nNO\nYES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n6 3\n001000\n2 4\n1 3\n3 5\n4 2\n1111\n1 4\n1 3...
code_contests
verifiable_code
1475_B. New Year's Number
Solve the following coding problem using the programming language python: Polycarp remembered the 2020-th year, and he is happy with the arrival of the new 2021-th year. To remember such a wonderful moment, Polycarp wants to represent the number n as the sum of a certain number of 2020 and a certain number of 2021. F...
```python t=int(input()) for T in range(t): n=int(input()) x=n//2020 if (n-x*2020)<=x: print('YES') else: print('NO') ```
vfc_43057
{ "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\n1\n4041\n4042\n8081\n8079\n", "output": "\nNO\nYES\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2021\n", "output": "YES\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
14_E. Camels
Solve the following coding problem using the programming language python: Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with t humps, representing them as polylines in the plane. Each polyline consists of ...
```python import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, t = map(int, input().split()) dp = [[[0] * 5 for _ in range(2 * t + 1)] for _ in range(n)] dp[0][0] = [0] + [1] * 4 for i in range(n - 1): for j in range(min(2 * t, i + 1)): ...
vfc_43061
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "19 10\n...
code_contests
verifiable_code
1525_B. Permutation Sort
Solve the following coding problem using the programming language python: You are given a permutation a consisting of n numbers 1, 2, ..., n (a permutation is an array in which each element from 1 to n occurs exactly once). You can perform the following operation: choose some subarray (contiguous subsegment) of a and...
```python k = int(input()) a = [] import math def nhap(): r = input() r = r.split() r =[int(i) for i in r] return r def kq(a): minn = min(a) maxx = max(a) b = sorted(a) if(b == a): return 0 if(a[0]== maxx and a[-1]== minn): return 3 if(a[0]== minn or a[-1]== maxx): return 1 return 2 for i in range(k): num =...
vfc_43065
{ "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\n4\n1 3 2 4\n3\n1 2 3\n5\n2 1 4 5 3\n", "output": "\n1\n0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8\n6 2 3 1 8 4 5 7\n", "output": "2\n", "type": "stdin_stdout"...
code_contests
verifiable_code
156_D. Clues
Solve the following coding problem using the programming language python: As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues A ...
```python def dfs(node, my_cc): vis[node] = True acc[my_cc]+=1 for i in adj[node]: if not vis[i]: dfs(i, my_cc) def ittDfs(node): queue = [node] curr = 0 while(queue): node = queue.pop() if vis[node]: continue vis[node] = True acc[...
vfc_43069
{ "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 1 1000000000\n1 4\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0 100\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
177_G1. Fibonacci Strings
Solve the following coding problem using the programming language python: Fibonacci strings are defined as follows: * f1 = «a» * f2 = «b» * fn = fn - 1 fn - 2, n > 2 Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba". You are given a Fibonacci string and m strings si. For each str...
```python F = ['', 'a', 'b', 'ba', 'bab', 'babba', 'babbabab', 'babbababbabba', 'babbababbabbababbabab', 'babbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbab...
vfc_43073
{ "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": "6 5\na\nb\nab\nba\naba\n", "output": "3\n5\n3\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "50 100\nbb\naa\nb\nbaa\nbbba\naa\nba\na\nabba\nbaa\naa\naab\nab\nbabb\naabb\nbaa\nbaaa\n...
code_contests
verifiable_code
199_E. Delivering Carcinogen
Solve the following coding problem using the programming language python: Qwerty the Ranger arrived to the Diatar system with a very important task. He should deliver a special carcinogen for scientific research to planet Persephone. This is urgent, so Qwerty has to get to the planet as soon as possible. A lost day ma...
vfc_43077
{ "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": "50 60 10\n50 60 20 40\n", "output": "0.000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 0 1\n-10 0 2 8\n", "output": "9.584544103\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
223_A. Bracket Sequence
Solve the following coding problem using the programming language python: A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the orig...
```python import sys from math import gcd,sqrt,ceil,log2 from collections import defaultdict,Counter,deque from bisect import bisect_left,bisect_right import math import heapq from itertools import permutations # input=sys.stdin.readline # def print(x): # sys.stdout.write(str(x)+"\n") # sys.stdin = open('input.tx...
vfc_43081
{ "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": "(((\n", "output": "0\n\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "([])\n", "output": "1\n([])\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
271_E. Three Horses
Solve the following coding problem using the programming language python: There are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain two integers, the first one on top, the sec...
```python # written with help of editorial n, m = map(int, input().split()) a = list(map(int, input().split())) def gcd(x, y): while y: x, y = y, x % y return x g = 0 for x in a: g = gcd(g, x - 1) answer = 0 def process(x): global answer if x % 2 == 0: return 0 for i in range...
vfc_43089
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 6\n2\n", "output": " 11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10\n13 7\n", "output": " ...
code_contests
verifiable_code
295_B. Greg and Graph
Solve the following coding problem using the programming language python: Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: * The game consists of...
```python #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq from array import array def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """4 # 0 57148 51001 13357 # ...
vfc_43093
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n", "output": "17 23 404 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 5\n4 0\n1 2\n", "output": "9 0 \n", "type": "s...
code_contests
verifiable_code
318_E. Balance
Solve the following coding problem using the programming language python: A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directio...
vfc_43097
{ "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 10 1\n1 9\n5 5\n1 2\n", "output": "1\n2 1 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10 0\n5 2\n4 2\n", "output": "NO\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
342_E. Xenia and Tree
Solve the following coding problem using the programming language python: Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between two tre...
```python class CentroidDecomposition(): def __init__(self, g): self.g = g self.n = len(g) self.parent = [-1]*self.n self.size = [1]*self.n self.cdparent = [-1]*self.n self.cddepth = [0]*self.n self.cdorder = [-1]*self.n self.cdused = [0]*self.n ...
vfc_43101
{ "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": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5\n", "output": "0\n3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 1\n", "output": "0\n3\n0\...
code_contests
verifiable_code
366_B. Dima and To-do List
Solve the following coding problem using the programming language python: You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After ...
```python n,k = map(int, input().split()) t = list(map(int, input().split())) current_sum = None flag = 1 for i in range(k): if current_sum == None or sum(t[i :: k]) < current_sum: current_sum = sum(t[i :: k]) flag = i+1 print(flag) #print(min((sum(t[i :: k]), i) for i in range(k))[1] + 1) ```
vfc_43105
{ "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": "10 5\n1 3 5 7 9 9 4 1 8 5\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n3 2 1 6 5 4\n", "output": "1", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
38_A. Army
Solve the following coding problem using the programming language python: The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank. One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank...
```python #!/usr/bin/python3 def readln(): return tuple(map(int, input().split())) n, = readln() d = readln() a, b = readln() print(sum(d[a - 1:b - 1])) ```
vfc_43109
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 6\n1 2\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 6\n1 3\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
409_I. Feed the Golorp
Solve the following coding problem using the programming language python: Golorps are mysterious creatures who feed on variables. Golorp's name is a program in some programming language. Some scientists believe that this language is Befunge; golorps are tantalizingly silent. Variables consumed by golorps can take val...
```python """ Codeforces April Fools Contest 2014 Problem I Author : chaotic_iak Language: Python 3.3.4 """ class InputHandlerObject(object): inputs = [] def getInput(self, n = 0): res = "" inputs = self.inputs if not inputs: inputs.extend(input().split(" ")) if n == 0: ...
vfc_43113
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "?(__-_+_/_____):-__&gt;__,_____&lt;__.\n", "output": "false", "type": "stdin_stdout" }, { "fn_name": null, "input": "?(______________________/____+_______*__-_____*______-___):-__&lt;___,___&lt;____,...
code_contests
verifiable_code
45_F. Goats and Wolves
Solve the following coding problem using the programming language python: Once Vasya needed to transport m goats and m wolves from riverbank to the other as quickly as possible. The boat can hold n animals and Vasya, in addition, he is permitted to put less than n animals in the boat. If in one place (on one of the ba...
vfc_43121
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "33 3\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n", ...
code_contests
verifiable_code
530_A. Quadratic equation
Solve the following coding problem using the programming language python: You are given a quadratic equation with integer coefficients A * X2 + B * X + C = 0. It is guaranteed that A ≠ 0 and that the equation has at least one real root. Output the roots of the equation. Input The only line of input contains integers...
vfc_43133
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 -2 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 -1\n", "output": "-1 1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
556_A. Case of the Zeros and Ones
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation: we choose...
```python n = int(input()) s = input() x = s.count('0') y = s.count('1') print(abs(x-y)) ```
vfc_43137
{ "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\n1100\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n11101111\n", "output": "6", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
626_B. Cards
Solve the following coding problem using the programming language python: Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: * take any two (not necessarily adjacent) cards with different colors and exchange the...
```python ''' Author : Md. Rezwanul Haque Email : r.haque.249.rh@gmail.com ''' import sys from sys import stdout,stdin input = lambda : sys.stdin.readline() if __name__ == '__main__': n = int(input()) s = input() s = (s.count('B'), s.count('G'), s.count('R')) if s[0] > 0 and s[1] > 0 and s[2] > 0: ...
vfc_43149
{ "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\nRB\n", "output": "G", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nBBBBB\n", "output": "B", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nG...
code_contests
verifiable_code
64_I. Sort the Table
Solve the following coding problem using the programming language python: You are given a rectangular table containing words. Each of its columns has its own name. You are also given the list of rules of sorting in form "FIELD_NAME SORT_ORDER", where SORT_ORDER is either ASC (nondescending order) or DESC (nonascending...
vfc_43153
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "NAME GROUP AGE\nGROUP ASC, AGE DESC\nAlex 412 19\nPeter 422 19\nSergey 412 18\nAndrey 311 18\n", "output": "Andrey 311 18\nAlex 412 19\nSergey 412 18\nPeter 422 19\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
675_C. Money Transfers
Solve the following coding problem using the programming language python: There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself....
```python n = int(input()) b = list(map(int, input().split())) from collections import Counter from itertools import accumulate cum = list(accumulate(b)) cnt = Counter(cum) print (n - cnt.most_common(1)[0][1]) ```
vfc_43157
{ "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\n5 0 -5\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n-1 0 1 0\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
699_D. Fix a Tree
Solve the following coding problem using the programming language python: A tree is an undirected connected graph without cycles. Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, ...
```python input() A = list(map(int, input().split(' '))) root=-1 for i,a in enumerate(A) : if i == a-1 : root = i break v = [False]*len(A) if root>-1 : v[root]=True ans= 0 for i,a in enumerate(A) : if v[i] : continue v[i]= True l=[i] a-=1 while not v[a] : l.ap...
vfc_43161
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 2 2 5 3\n", "output": "0 \n3 2 2 5 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 3 3 4\n", "output": "1\n2 3 3 3 \n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
720_A. Closing ceremony
Solve the following coding problem using the programming language python: The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arranged in n rows, m seats in a row. Each seat has two coordinates (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m). There are two queues of people waiting to enter the hall: k p...
```python import bisect n,m = map(int,raw_input().split()) p1 = list(map(int,raw_input().split())) p2 = list(map(int,raw_input().split())) #print n,m #print p1,p2 s1 = sorted(p1[1:]) s2 = sorted(p2[1:]) #print s1 def f(n,m,s1,s2): for i in xrange(n,0,-1): for j in xrange(1,m+1): iter1 = bisect.b...
vfc_43165
{ "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 2\n3 3 3 2\n1 3\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n3 2 3 3\n1 2\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
741_C. Arpa’s overnight party and Mehrdad’s silent entering
Solve the following coding problem using the programming language python: Note that girls in Arpa’s land are really attractive. Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ...
```python import sys def solve(): n = int(input()) partner = [0]*(2*n) pacani = [] for line in sys.stdin: pacan, telka = [int(x) - 1 for x in line.split()] partner[pacan] = telka partner[telka] = pacan pacani.append(pacan) khavka = [None]*(2*n) for i in range(2*...
vfc_43169
{ "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\n1 4\n2 5\n3 6\n", "output": "1 2\n2 1\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 11\n7 1\n12 8\n4 10\n3 9\n5 6\n", "output": "2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n", ...
code_contests
verifiable_code
765_B. Code obfuscation
Solve the following coding problem using the programming language python: Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code...
```python Alphabet = "abcdefghijklmnopqrstuvwxyz" X = input() Checked = [] i, Index = 0, 0 while i < len(X): if X[i] not in Checked and X[i] == Alphabet[Index]: Checked.append(Alphabet[Index]) Index += 1 elif X[i] not in Checked and X[i] != Alphabet[Index]: print("NO") exit() ...
vfc_43173
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "jinotega\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacaba\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
788_D. Finding lines
Solve the following coding problem using the programming language python: After some programming contest Roma decided to try himself in tourism. His home country Uzhlyandia is a Cartesian plane. He wants to walk along each of the Main Straight Lines in Uzhlyandia. It is known that each of these lines is a straight lin...
vfc_43177
{ "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": "1\n1\n3\n2\n", "output": "0 1 2\n0 -2 -2\n0 5 6\n0 -2 2\n1 1 2\n2\n0 -3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
80_A. Panoramix's Prediction
Solve the following coding problem using the programming language python: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after x is the smallest prime number greater than x. For example, the next pr...
```python from math import ceil, sqrt def array(arr, struc): return (list(map(struc, arr.split()))) def isPrime(x): for i in range(2, ceil(sqrt(x))+1): if x % i == 0: return False return True arr = array(input(), int) prime1 = arr[0] prime2 = arr[1] counter = 0 tmp = prime1 + 1 ...
vfc_43181
{ "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": "7 9\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 11...
code_contests
verifiable_code
834_D. The Bakery
Solve the following coding problem using the programming language python: <image> Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so ...
```python import sys from collections import defaultdict as di range = range input = raw_input class LazySegmentTree: def __init__(self, data, default=0, func=max): """initialize the lazy segment tree with data""" self._default = default self._func = func self._len = len(data) ...
vfc_43185
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n1 2 2 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2\n1 3 3 1 4 4 4\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
855_B. Marvolo Gaunt's Ring
Solve the following coding problem using the programming language python: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its ...
```python cin=lambda:map(int,input().split()) n,p,q,r=cin() A=cin() tp,tq,tr=-1e20,-1e20,-1e20 for a in A: tp=max(tp,p*a) tq=max(tq,tp+q*a) tr=max(tr,tq+r*a) print(tr) # Made By Mostafa_Khaled ```
vfc_43189
{ "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 1 2 -3\n-1 -2 -3 -4 -5\n", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1 2 3\n1 2 3 4 5\n", "output": "30", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
879_E. Tournament
Solve the following coding problem using the programming language python: Recently a tournament in k kinds of sports has begun in Berland. Vasya wants to make money on the bets. The scheme of the tournament is very mysterious and not fully disclosed. Competitions are held back to back, each of them involves two sport...
vfc_43193
{ "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": "3 2\n2 3\n1 1\n3 2\n", "output": "1\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 5\n5 1\n10 10\n", "output": "1\n2\n1\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
903_B. The Modcrab
Solve the following coding problem using the programming language python: Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Mod...
```python class Character: def __init__(self, hPoints, attPoints, healPoints): self.hPoints = hPoints self.attPoints = attPoints self.healPoints = healPoints def attack(self, boss): boss.setHP(boss.getHP() - self.attPoints) def recAttack(self, boss): self.hPoints -= b...
vfc_43197
{ "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": "10 6 100\n17 5\n", "output": "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 6 100\n12 5\n", "output": "2\nSTRIKE\nSTRIKE\n", "type": "stdin...
code_contests
verifiable_code
925_C. Big Secret
Solve the following coding problem using the programming language python: Vitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence a_1, …, a_n. In order to not reveal the secret earlier than needed, Vitya encrypted th...
```python n=int(input()) s=[[] for i in range(60)] for b in list(map(int,input().split())): for i in range(59,-1,-1): if b>>i&1: s[i].append(b) break ans=[] cur=0 for i in range(n): fl=False for j in range(60): if s[j]!=[] and cur>>j&1==0: ans.append(s[j][-1]) cur^=s[j][-1] s[j].pop() fl=True ...
vfc_43201
{ "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\n1 2 3\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n4 7 7 12 31 61\n", "output": "Yes\n4 12 7 31 7 61 ", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
980_C. Posterized
Solve the following coding problem using the programming language python: Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the i-th integer represents the color ...
```python R = lambda: map(int, input().split()) n, k = R() a = list(range(0, 257)); v = [1]*257 for p in R(): if v[p]: t = p while t >= 0 and p-a[t]<=k-1: t -= 1 t += 1 for i in range(t, p+1): a[i] = a[t]; v[i] = 0 print(a[p], end=' ') ```
vfc_43209
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n0 2 1 255 254\n", "output": "0 1 1 254 254 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
9_C. Hexadecimal's Numbers
Solve the following coding problem using the programming language python: One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain...
```python n=int(input()) a=[] c=int for i in range(515): a.append(c(bin(i)[2:])) a.remove(0) ans=0 for i in a: if i<=n: ans+=1 print(ans) ```
vfc_43213
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1010011\...
code_contests
verifiable_code
beverage-paradigm-1
Solve the following coding problem using the programming language python: Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows, To decide the amount of beverage they plan to consume, say X. Then order for...
```python import itertools x=input() y=raw_input().split(" ") y=map(int,y) z=input() c=[] for i in range(1,len(y)): c.extend(itertools.combinations(y,i)) c=list(set(c)) con=0 for i in range(0,len(c)): s=0 for j in range(0,len(c[i])): s+=c[i][j] if s==z: print "True" con=1 break if con==0: print "False" ```
vfc_43217
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 4 45 6 10 8\n22\n\nSAMPLE", "output": "True\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n4 8 9 7 45 6 3 27\n156", "output": "False\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
find-product
Solve the following coding problem using the programming language python: You have been given an array A of size N consisting of positive integers. You need to find and print the product of all the number in this array Modulo 10^9+7. Input Format: The first line contains a single integer N denoting the size of the ...
```python x=input() s=raw_input() i=0 d=1 cities=s.split() for city in cities: d=(d*int(city))%((10**9)+7) i=i+1 if i==x: break print d ```
vfc_43225
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n\nSAMPLE", "output": "120\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 3 5\n\nSAMPLE", "output": "90\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
independence-day-main-war
Solve the following coding problem using the programming language python: We always knew they were coming back. Species on Earth always had faced the problems came from outer space. We call them Alien , but for them they are travellers, who want to expand their territory. When we had defeated them years back and sen...
```python t=int(raw_input().strip()) for i in range(0,t): no=int(raw_input().strip()) points=[] for j in range(0,no): points.append(map(float,raw_input().strip().split(" "))) x=[l[0] for l in points] y=[k[1] for k in points] x=sum(x)/len(points) y=sum(y)/len(points) print "(%.2f , %.2f)"%(round(x,2),ro...
vfc_43229
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n10\n4.44 -7.32\n10.78 4.08\n3.69 -2.35\n-2.75 0.68\n-5.14 -0.77\n4.31 0.77\n-9.51 -7.57\n-4.22 8.92\n8.70 6.99\n-7.23 9.58\n\nSAMPLE", "output": "(0.31 , 1.30)\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
matrix-symmetry
Solve the following coding problem using the programming language python: You are given a square matrix of size n. Rows are indexed 1 to n from top to bottom and columns are indexed 1 to n form left to right. Matrix consists of only '*' and '.'. You need to check whether matrix is symmetric or not. if it is, check it ...
```python t = raw_input() t = int(t) for i in range(t): n = raw_input() n = int(n) horizontal = [] vertical = [] for j in range(n): s = raw_input() horizontal.append(s) vertical = map(lambda *row: ''.join(list(row)), *horizontal) h = 1 v = 1 l=len(horizontal) for i in range(l/2): if(h==0 and v==0): b...
vfc_43233
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n*.*.\n.*.*\n*.*.\n.*.*\n3\n.*.\n*.*\n.*.\n3\n..*\n**.\n..*\n\nSAMPLE", "output": "NO\nBOTH\nHORIZONTAL\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "500\n12\n.***.**.***.\n.*.**.*....
code_contests
verifiable_code
oliver-and-the-game-3
Solve the following coding problem using the programming language python: Oliver and Bob are best friends. They have spent their entire childhood in the beautiful city of Byteland. The people of Byteland live happily along with the King. The city has a unique architecture with total N houses. The King's Mansion is a v...
```python # https://www.hackerearth.com/problem/algorithm/oliver-and-the-game-3/ import sys n = int(sys.stdin.readline()) neighbors = [ [] for _ in range(n)] for _ in range(n - 1): u, v = [int(x) - 1 for x in sys.stdin.readline().split()] neighbors[u].append(v) neighbors[v].append(u) vert = [[0, 0, 0] f...
vfc_43237
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "200\n34 138\n160 40\n109 52\n133 196\n49 141\n167 199\n156 128\n100 184\n192 66\n118 177\n30 185\n137 188\n169 182\n11 131\n131 112\n154 106\n65 42\n163 68\n88 39\n28 133\n7 180\n42 78\n39 152\n140 108\n125 190\n90 81\n173 62\n199 ...
code_contests
verifiable_code
rajus-class
Solve the following coding problem using the programming language python: Raju is the Class Representative of his class. His teacher assigned him a task to enroll the students' entries in the class register. He is given two information about each student: name and age. Now the teacher asked him to enroll entries accor...
```python import sys t=int(raw_input()) while(t>0): s=int(raw_input()) fd={} while(s>0): sd=sys.stdin.readline().strip('\n').split() if(len(sd)!=0): fd[int(sd[0])]=sd[1] s=s-1 x = sorted(fd) r=int(raw_input()) ss=x[r-1] print fd[ss] t=t-1 ```
vfc_43241
{ "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\n8 vaibhav\n9 raju\n11 prakhar\n2\n\nSAMPLE", "output": "raju\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n61\n20 ujzhf\n65 ubpvyvkxw\n60 knah\n75 ehbtv\n45 ay\n16 uwfdb\n79 og...
code_contests
verifiable_code
simple-math-1
Solve the following coding problem using the programming language python: Find the number of ways of distributing N objects into R groups such that each group gets 1 or more objects. Input: The one and only line of input contains two numbers separated by a single space, which are N and R respectively. Output: The co...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' import math n,m=map(int,raw_input().split()) if(n>=m): n=n-1 m=m-1 a=math.factorial(n) b=math.factorial(m) c=math.factorial(n-m) ans=a/(b*c) print ans%10000007 else: p...
vfc_43245
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "72 36", "output": "7708211\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
the-story-of-a-girl
Solve the following coding problem using the programming language python: Once upon a time there was a girl who loved to garden. This girl liked to work in the garden to plant peas, weed watermelon, and grown all sorts of tasty and interesting fruits and vegetables. In fact, not only did this girl have a green thumb, ...
```python fibs = {0: 0, 1: 1} def fib(n): if n in fibs: return fibs[n] if n % 2 == 0: fibs[n] = (((2 * fib((n / 2) - 1)) + fib(n / 2)) * fib(n / 2))%1000000007 return fibs[n] else: fibs[n] = ((fib((n - 1) / 2) ** 2) + (fib((n+1) / 2) ** 2))%1000000007 return fibs[n] for _ in...
vfc_43249
{ "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\n13\n\nSAMPLE", "output": "5\n233", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n37715446\n11794169\n32896615\n4674101\n7087908\n44167775\n92044044\n20008248\n28959725\n98164375\...
code_contests
verifiable_code
p00098 Maximum Sum Sequence II
Solve the following coding problem using the programming language python: Matrix of given integers a1,1 a1,2 ... a1, n a2,1 a2,2 ... a2, n :: an, 1 an, 2 ... an, n Then, create a program that outputs the maximum value of the sum of one or more consecutive terms (submatrix) in the vertical and horizontal directions...
```python n = int(input()) s = [[0 for i in range(n + 1)] for j in range(n + 1)] for r in range(n): inp = list(map(int, input().split())) for c in range(n): s[r + 1][c + 1] = inp[c] + s[r][c + 1] ans = -10001 for r_end in range(1, n + 1): for r_start in range(r_end): dp = [-10001] ...
vfc_43297
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 -2 3\n-4 5 6\n7 8 -9", "output": "16", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00230 Ninja Climbing
Solve the following coding problem using the programming language python: Ninja Atsushi guards the town from the roof of the Ninja Building from early morning to late night every day. This Ninja Building is two adjacent buildings of the same floor, and Atsushi's daily routine is to jump between buildings and head to t...
```python def bfs(b): mem=[[False for i in range(n)]for j in range(2)] st=[0,0] for i in range(2): if b[i][0]!=1:continue while st[i]<n-1 and b[i][st[i]+1]==1: st[i]+=1 if st[i]==n-1:return 0 mem[0][st[0]]=True mem[1][st[1]]=True que=[[0,st[0],0],[1,st[1],0]] ...
vfc_43301
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n0 0 0 2 2 2 0 0\n1 1 1 1 0 0 0 0\n4\n1 1 2 2\n0 0 2 2\n0", "output": "4\nNA", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n0 0 0 2 2 2 0 0\n1 1 1 1 1 0 0 0\n4\n1 1 2 2\n0 0 2 2\n0", ...
code_contests
verifiable_code
p00608 Indian Puzzle
Solve the following coding problem using the programming language python: In the Indian Puzzle, one is intended to fill out blanks with numbers and operators in a n by n grid in order to make equalities in the grid true (See Figure 1). <image> Figure 1 A blank cell should be filled out with a number (from 0 to ...
vfc_43309
{ "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 5\n4=..2\n+#=#+\n.-2=.\n=#*#=\n.-.=3\n6\n7 3 1 4 / 8\n1 6\n8..3=2\n2\n2 +\n0 0", "output": "Yes\nNo", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n4=..2\n+#=#+\n.-2=.\n=#*#=\n.-.=3\n...
code_contests
verifiable_code
p00745 Tighten Up!
Solve the following coding problem using the programming language python: We have a flat panel with two holes. Pins are nailed on its surface. From the back of the panel, a string comes out through one of the holes to the surface. The string is then laid on the surface in a form of a polygonal chain, and goes out to t...
vfc_43313
{ "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": "6 16\n5 4\n11 988\n474 975\n459 16\n985 12\n984 982\n242 227\n140 266\n45 410\n92 570\n237 644\n370 567\n406 424\n336 290\n756 220\n634 251\n511 404\n575 554\n726 643\n868 571\n907 403\n845 283\n10 4\n261 196\n943 289\n859 925\n56 ...
code_contests
verifiable_code
p00884 Membership Management
Solve the following coding problem using the programming language python: Peter is a senior manager of Agile Change Management (ACM) Inc., where each employee is a member of one or more task groups. Since ACM is agile, task groups are often reorganized and their members frequently change, so membership management is h...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x i...
vfc_43317
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\ndevelopment:alice,bob,design,eve.\ndesign:carol,alice.\n3\none:another.\nanother:yetanother.\nyetanother:dave.\n3\nfriends:alice,bob,bestfriends,carol,fran,badcompany.\nbestfriends:eve,alice.\nbadcompany:dave,carol.\n5\na:b,c,d,...
code_contests
verifiable_code
p01015 J's Final Problem
Solve the following coding problem using the programming language python: Problem A mysterious dungeon is a dungeon that involves structural changes. There are various mysterious dungeons, from deep to shallow, where evil monsters live and treasures sleep. Jay is a researcher studying a mysterious dungeon. One day, w...
vfc_43321
{ "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 2\n9 left : 9 left\n9 right : 9 right", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n1 left : 2 right\n2 left : 3 right\n2 left : 3 left\n1 right : 3 left\n2 right : ...
code_contests
verifiable_code
p01148 Princess
Solve the following coding problem using the programming language python: Princess, a Strategist Princess is a strategist English text is not available in this practice contest. A brave princess in a poor country is on an adventure to escape the castle and obtain ancient treasures. However, the area around the anci...
vfc_43325
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 1\n1 1\n1 2\n-1 2\n-1 1\n2 1 0\n0 1 0 1 2\n0 0 0", "output": "1\n1.000", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1 1\n1 1\n1 2\n-1 2\n0 1\n2 1 0\n0 1 0 1 2\n0 0 0", "output...
code_contests
verifiable_code
p01287 Colored Octahedra
Solve the following coding problem using the programming language python: A young boy John is playing with eight triangular panels. These panels are all regular triangles of the same size, each painted in a single color; John is forming various octahedra with them. While he enjoys his playing, his father is wondering...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in ...
vfc_43329
{ "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": "blue blue blue blue blue blue blue blue\nred blue blue blue blue blue blue blue\nred red blue blue blue blue blue blue", "output": "1\n1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "bl...
code_contests
verifiable_code
p01607 Magical Circle
Solve the following coding problem using the programming language python: Magic Circle Problem Statement ~ How to draw a magic circle ~ 1. Prepare a sufficiently large and white floor. 2. Draw a circle with radii 1, 2, ..., R centered on the point at the floor coordinates (0,0). 3. Paint blue between the circle wit...
vfc_43337
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n1 1\n-1 1\n-1 -1\n1 -1", "output": "11.707963268", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n0 0\n1 0\n0 1", "output": "0.500000000", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p01902 Unbalanced Old Maid
Solve the following coding problem using the programming language python: E: Without the Devil Old Maid --Unbalanced Old Maid - story Mr. Kosaka, Mr. Sonoda, and Mr. Minami have been good friends since childhood. The three went on a school trip to Okinawa, but a typhoon came and they couldn't play in the sea, so the...
vfc_43345
{ "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": "1\n1 1\n3 0 1 1\n1 1", "output": "0.0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1\n3 0 1 1\n0 1", "output": "0.0000000000\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p02039 Othello
Solve the following coding problem using the programming language python: problem Prepare the Othello board. The upper left is $ (1,1) $ and the lower right is $ (8,8) $. The board to be prepared here is $ (5,4) as follows. ) There is no $ black stone. ........ ........ ........ ... ox ... .... o ... ........ ........
```python q = int(input()) li = [input().split() for i in range(q)] for i in li: a, b, c, d = map(int, i) ans = 0 for j in range(a, c+1): for k in range(b, d+1): ans += 0 if j%2 == 1 and k%2 == 0 else 1 print(ans) ```
vfc_43349
{ "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": "3\n1 1 8 8\n2 4 3 8\n8 8 8 8", "output": "48\n7\n1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02183 Perfect
Solve the following coding problem using the programming language python: B: Tetris problem Consider a board consisting of a rectangle with 4 squares x 10 squares. A square of 1 square x 1 square is called a block. Tetromino is a combination of four blocks, and there are the following seven types (and those that ha...
vfc_43353
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n##.\n.##\n2 3\n#..\n###\n1 4\n####\n2 3\n###\n.#.\n2\n####....##\n####...###\n####..####\n####...###\n###..#####\n###...####\n###...####\n###....###", "output": "Yes\nYes", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p02325 Bitonic Traveling Salesman Problem
Solve the following coding problem using the programming language python: For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria: * Visit the points according to the following steps: 1. It starts from the leftmost point (starting point), goes strictly ...
```python import math pts = [] line = input() N = int(line) for _ in range(0, N): line = input() x, y = list(map(int, line.split())) pts += [[x, y]] def dist(i, j): x1, y1 = pts[i] x2, y2 = pts[j] return math.sqrt((x1 - x2)**2 + (y1 - y2)**2) def btsp(): dp = [ [0] * N for _ in range(...
vfc_43357
{ "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": "3\n0 0\n1 1\n2 0", "output": "4.82842712", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 0\n1 2\n2 1\n3 2\n4 0", "output": "10.94427191", "type": "stdin_stdout" }, {...
code_contests
verifiable_code
p02470 Euler's Phi Function
Solve the following coding problem using the programming language python: For given integer n, count the totatives of n, that is, the positive integers less than or equal to n that are relatively prime to n. Input n An integer n (1 ≤ n ≤ 1000000000). Output The number of totatives in a line. Examples Input ...
```python # https://tjkendev.github.io/procon-library/python/prime/eulers-totient-function.html # https://qiita.com/drken/items/a14e9af0ca2d857dad23#%E5%95%8F%E9%A1%8C-6-%E3%82%AA%E3%82%A4%E3%83%A9%E3%83%BC%E9%96%A2%E6%95%B0 # オイラー関数 # 1,2,...,NのうちNと互いに素であるものの個数 # Python3 program to calculate # Euler's Totient Functio...
vfc_43361
{ "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": "1000000", "output": "400000", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000100"...
code_contests
verifiable_code
cd1it5
Solve the following coding problem using the programming language python: Somewhere out there, there are N islands numbered from 1 to N with no network connectivity. Communication is such a pain for the islands' dwellers. So the Kings of the islands go to nearby islands and decide to connect the islands with underwate...
```python n,q=map(int,raw_input().split()) sz=[] idi=range(n+1)#array containing the objects idi[i]=i for i in range(n+1): sz.append(1) ''' unite to trees by pointing one root of one to the other''' def union(x,y): rootx=root(long(x)) rooty=root(long(y)) if(rootx==rooty): return if(sz[rootx]...
vfc_43365
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 7\n0 1 2\n1 2 1\n0 3 4\n1 1 4\n0 3 2\n1 2 3\n1 1 4", "output": "Yes\nNo\nYes\nYes", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
cvote
Solve the following coding problem using the programming language python: Chefs from all over the globe gather each year for an international convention. Each chef represents some country. Please, note that more than one chef can represent a country. Each of them presents their best dish to the audience. The audience ...
```python from sys import stdin b = stdin.readline().split() no_chef=int(b[0]) no_mails=int(b[1]) d={} chef={} country={} for i in range(0,no_chef): b = stdin.readline().split() d[b[0]]=b[1] chef[b[0]]=0 country[b[1]]=0 chf="" cntry="" for i in range(0,no_mails): s = stdin.readline().split() ...
vfc_43369
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\nNewton England\nEuclid Greece\nNewton\nEuclid", "output": "England\nEuclid\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
icecream
Solve the following coding problem using the programming language python: Pankaj likes to eat Ice cream when he is working late into the night. Today has been yet another long day for Pankaj. So, he wants to eat ice cream now. He opens the fridge and sees that he has 2 types of containers holding the ice cream. The fi...
```python # your code goes here from sys import stdin, stdout from math import pi t = int(stdin.readline()) while t: t -= 1 r1, h1, r2, h2 = map(float, stdin.readline().strip().split(' ')) v2 = pi*r2*r2*h2 v1 = pi*r1*r1 *h1 /3 v1 += 2*pi*r1*r1*r1 /3 stdout.write("%.18f" % v1 + ' '+"%.18f"%v2 +'\n') ```
vfc_43373
{ "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.00 1.00 1.00 1.00\n3.02 7.23 5.20 6.00", "output": "3.141592654 3.141592654\n126.739919445 509.691992118", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
mprob
Solve the following coding problem using the programming language python: You are given three integers A,B and C. We choose two real numbers x and y such that 0 ≤ x ≤ A and 0 ≤ y ≤ B. What is the probability that x+y≤C ? Input The first line of input contains T denoting the number of test cases. Each of the follow...
```python t = int(input()) for i in range(t): a,b,c = map(float, raw_input().split()) ans = 0.0 if(a==0 and b ==0): ans = 1 elif (a==0 and b!=0): if (c>=b): ans = 1.0 else: ans = c/b elif (a!=0 and b==0): if(c>=a): ans = 1.0 ...
vfc_43377
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 10 3\n4 10 11", "output": "0.1125\n0.8875", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
retpo
Solve the following coding problem using the programming language python: Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in the point (0, 0)) and carry it to some table (which ...
```python # Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in the point (0, 0)) and carry it to some table (which is in some point (x, y)) in a shortest way. But this is a beta ...
vfc_43381
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 3\n3 4", "output": "6\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 3\n3 0", "output": "6\n7\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
twstr
Solve the following coding problem using the programming language python: Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recip...
```python def twstr(): n=int(raw_input()) s=[] v=[] for i in range(n): x=raw_input().split() s.append(x[0]) v.append(int(x[1])) qn=int(raw_input()) for i in range(qn): q=raw_input().strip() maxs='NO' maxv=min(v)-1 for j in range(n): if q==s[j][:len(q)] and v[j]>maxv: maxv=v[j] maxs=s[j] ...
vfc_43385
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nflour-with-eggs 100\nchicken-ham -10\nflour-without-eggs 200\nfish-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nc\nfl\nchik", "output": "fish-with-pepper\nflour-without-eggs\nflour-with-eggs\nchicken-ham\nflour-without...
code_contests
verifiable_code
1019_A. Elections
Solve the following coding problem using the programming language python: As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the numbe...
```python n, m = map(int, input().split()) pc = [(0, 0) for _ in range(n)] party_votes = [0 for _ in range(m)] for i in range(n): p, c = map(int, input().split()) pc[i] = (p - 1, c) party_votes[p - 1] += 1 pc.sort(key=lambda x: x[1]) min_cost = 10**20 for votes in range(n + 1): _party_votes = part...
vfc_43389
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n1 100\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n", "output": "600\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1041_F. Ray in the tube
Solve the following coding problem using the programming language python: You are given a tube which is reflective inside represented as two non-coinciding, but parallel to Ox lines. Each line has some special integer points — positions of sensors on sides of the tube. You are going to emit a laser ray in the tube. T...
```python n, y1 = map(int, input().split()) a = list(map(int, input().split())) m, y2 = map(int, input().split()) b = list(map(int, input().split())) a_st, b_st = dict(), dict() osn = 2 ** 30 k_a, k_b = set(), set() for el in a: try: a_st[el % osn] += 1 except KeyError: a_st[el % osn] = 1...
vfc_43393
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n1 5 6\n1 3\n3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 94192\n0 134217728 268435456 402653184 536870912 671088640\n6 435192\n67108864 201326592 335544320 469...
code_contests
verifiable_code
1064_E. Dwarves, Hats and Extrasensory Abilities
Solve the following coding problem using the programming language python: This is an interactive problem. In good old times dwarves tried to develop extrasensory abilities: * Exactly n dwarves entered completely dark cave. * Each dwarf received a hat — white or black. While in cave, none of the dwarves was able...
vfc_43397
{ "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\n<span class=\"tex-span\"></span>\nblack\n<span class=\"tex-span\"></span>\nblack\n<span class=\"tex-span\"></span>\nwhite\n<span class=\"tex-span\"></span>\nwhite\n<span class=\"tex-span\"></span>\nblack\n", "output": "0 1...
code_contests
verifiable_code
1086_C. Vasya and Templates
Solve the following coding problem using the programming language python: Vasya owns three strings s , a and b, each of them consists only of first k Latin letters. Let a template be such a string of length k that each of the first k Latin letters appears in it exactly once (thus there are k! distinct templates). App...
vfc_43401
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\nbbcb\naada\naada\n3\nabc\nbbb\nbbb\n", "output": "YES\nbadc\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n5\nbcdbccc\nadaedae\neecdaca\n5\ndbeedcbcbaccdddbdcbcabacecbe\ndcae...
code_contests
verifiable_code
1106_C. Lunar New Year and Number Division
Solve the following coding problem using the programming language python: Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem. There are n positive integers a_1, a_2, …, a_n on Bob's homework paper, where n is always an even number. Bob is asked to divide those numbers i...
```python n = int(input()) a = [int(s) for s in input().split(" ")] a.sort() ans = 0 for i in range(n//2): ans += (a[i]+a[n-i-1])**2 print(ans) ```
vfc_43405
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1 1 2 2 2\n", "output": "27\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n8 5 2 3\n", "output": "164\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1133_D. Zero Quantity Maximization
Solve the following coding problem using the programming language python: You are given two arrays a and b, each contains n integers. You want to create a new array c as follows: choose some real (i.e. not necessarily integer) number d, and then for every i ∈ [1, n] let c_i := d ⋅ a_i + b_i. Your goal is to maximize...
```python from fractions import Fraction n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) count = {} ans = 0 zeros = 0 for i in range(n): if A[i] == 0 and B[i] != 0: continue elif A[i] == 0 and B[i] == 0: zeros += 1 else: temp = Fraction(abs...
vfc_43409
{ "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 0 0\n1 2 3 4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 5\n2 4 7 11 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
1154_A. Restoring Three Numbers
Solve the following coding problem using the programming language python: Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there a...
```python x,y,z,w = (int(i) for i in input().split()) s = (x+y+z+w)//3 for i in x,y,z,w: temp = s - i if s - i > 0: print(s-i, end=' ') ```
vfc_43413
{ "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": "40 40 40 60\n", "output": "20 20 20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "201 101 101 200\n", "output": "100 100 1 ", "type": "stdin_stdout" }, { "fn_na...