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 | shuttle | Solve the following coding problem using the programming language python:
Chef has decided to arrange the free shuttle service for his employees. City of Bhiwani has a strange layout - all of its N shuttle boarding points are arranged in a circle, numbered from 1 to N in clockwise direction. Chef's restaurant is at bo... | ```python
def init_primes(n):
primes = []
is_prime = [True] * n
is_prime[0] = False
is_prime[1] = False
for i in xrange(2, n):
if not is_prime[i]:
continue
for j in xrange(i * i, n, i):
is_prime[j] = False
primes = [i for i in xrange(n) if is_prime[i]]
... | vfc_67117 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n3\n4",
"output": "1\n2\n2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1004_A. Sonya and Hotels | Solve the following coding problem using the programming language python:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She... | ```python
n, d = map(int,input().split())
a = list(map(int,input().split()))
count = 0
for i in range(n-1):
if a[i + 1] - a[i] == 2 * d:
count +=1
elif a[i + 1] - a[i] > 2 * d:
count += 2
print(count + 2)
``` | vfc_67121 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n4 8 11 18 19\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1028_A. Find Square | Solve the following coding problem using the programming language python:
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.... | ```python
import os
import sys
import math
def main():
n,m = [int(i) for i in input().split()]
centeri, centerj = -1,-1
starti, startj = -1,-1
for i in range(n):
s = input()
if not 'B' in s:
continue
if starti == -1:
starti = i
a = [int(pos) f... | vfc_67125 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\nWWW\nBWW\nWWW\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW\n",
"output": "2 4\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1046_G. Space Isaac | Solve the following coding problem using the programming language python:
Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is \{0,1,…,M-1\}, f... | ```python
import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
a = list(map(int, input().split())) + [0]*500000
ans_S = 0
a[n] = a[0] + m
s = [0]*600600
for i in range(n):
s[i] = a[i + 1] - a[i]
s[n] = -1
for i in range(n):
s[2*n - i] = s[i]... | vfc_67129 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1000000000\n5 25 125 625\n",
"output": "0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n3 4\n",
"output": "1\n2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1070_F. Debate | Solve the following coding problem using the programming language python:
Elections in Berland are coming. There are only two candidates — Alice and Bob.
The main Berland TV channel plans to show political debates. There are n people who want to take part in the debate as a spectator. Each person is described by thei... | ```python
arr = [[],[],[]]
ans = 0
temp=0
for _ in range(int(input())):
s,c = input().split()
if s=='11':
ans+=int(c)
temp+=1
elif s=='00':
arr[0].append(int(c))
elif s=='01':
arr[1].append(int(c))
else:
arr[2].append(int(c))
temp1 = min(len(arr[1]),len(arr[2]... | vfc_67133 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n11 1\n01 1\n00 100\n10 1\n01 1\n",
"output": "103\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n11 6\n10 4\n01 3\n00 3\n00 7\n00 9\n",
"output": "22\n",
"type": "stdin_... |
code_contests | verifiable_code | 1092_B. Teams Forming | Solve the following coding problem using the programming language python:
There are n students in a university. The number of students is even. The i-th student has programming skill equal to a_i.
The coach wants to form n/2 teams. Each team should consist of exactly two students, and each student should belong to e... | ```python
n1=int(input())
s1=list(map(int,input().split()))
s1.sort()
sa1=0
se2=0
for i in range(0,n1,2):
sa1=sa1+s1[i]
for i in range(1,n1,2):
se2=se2+s1[i]
print(se2-sa1)
``` | vfc_67137 | {
"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": "6\n5 10 2 3 14 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 100\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1110_H. Modest Substrings | Solve the following coding problem using the programming language python:
You are given two integers l and r.
Let's call an integer x modest, if l ≤ x ≤ r.
Find a string of length n, consisting of digits, which has the largest possible number of substrings, which make a modest integer. Substring having leading zeros... | vfc_67141 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12345\n12346\n6\n",
"output": "1\n012345\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n11\n3\n",
"output": "5\n111\n",
"type": "stdin_stdout"
},
{
"fn_name":... | |
code_contests | verifiable_code | 1140_E. Palindrome-less Arrays | Solve the following coding problem using the programming language python:
Let's denote that some array b is bad if it contains a subarray b_l, b_{l+1}, ..., b_{r} of odd length more than 1 (l < r and r - l + 1 is odd) such that ∀ i ∈ \{0, 1, ..., r - l\} b_{l + i} = b_{r - i}.
If an array is not bad, it is good.
Now... | ```python
class PalArray():
P = 998244353
def __init__(self, n, k, a):
self.n, self.k, self.a = n, k, a
self.dp = None
def fast_pow(self, a, b):
r = 1
while b > 0:
if b%2 == 1:
r = (r*a)%self.P
a = (a*a)%self.P
b = int(b/2)... | vfc_67145 | {
"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 3\n-1 -1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n1 -1 -1 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1159_C. The Party and Sweets | Solve the following coding problem using the programming language python:
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal... | ```python
n, m = list(map(int, input().split()))
b = list(map(int, input().split()))
g = list(map(int, input().split()))
b.sort()
g.sort()
if b[-1] > g[0]:
print(-1)
elif b[-1] == g[0]:
print(sum(g) + m * (sum(b) - b[-1]))
elif n == 1:
print(-1)
else :
print(sum(g) + b[-1] + b[-2] * (m - 1) + m * (sum(b... | vfc_67149 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n0 1\n1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 0\n1 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1181_C. Flag | Solve the following coding problem using the programming language python:
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in n ⋅ m colored pieces that form a rectangle with n rows and m columns.
The colored... | ```python
import os
from io import BytesIO, StringIO
#input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
DEBUG = True
debug_print = print if DEBUG else lambda *x,**y: None
def input_as_list():
return list(map(int, input().split()))
def array_of(f, *dim):
return [array_of(f, *dim[1:]) for _ in range(di... | vfc_67153 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\na\na\nb\nb\nc\nc\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\naaa\nbbb\nccb\nddd\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 119_B. Before Exam | Solve the following coding problem using the programming language python:
Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner... | ```python
n,k = map(int, input().split())
a = list(map(int, input().split()))
ansMin, ansMax = 10**10, -10**10
were = [0]*n
sz = n//k
for i in range(int(input())):
cur = 0.0
t = map(int, input().split())
for x in t:
were[x-1]=1
cur+=a[x-1]
cur/=sz
ansMin = min(ansMin, cur)
ansM... | vfc_67157 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3\n7 15 0 19 10 5 12\n2\n1 6\n7 4\n",
"output": "5.0000000000 15.5000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n10 8 1 17\n2\n2 3\n3 2\n",
"output": "4.5000000000 ... |
code_contests | verifiable_code | 123_B. Squares | Solve the following coding problem using the programming language python:
You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square... | ```python
a, b, x_1, y_1, x_2, y_2 = map(int, input().split())
a_b, a_e = (x_2 + y_2), (x_1 + y_1)
b_b, b_e = (x_2 - y_2), (x_1 - y_1)
if a_b > a_e:
a_b, a_e = a_e, a_b
if b_b > b_e:
b_b, b_e = b_e, b_b
if a_b % (2 * a) != 0:
a_b = (a_b // (2 * a) + 1) * (2 * a)
a_result, b_result = 0, 0
if a_b <= a... | vfc_67165 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4 3 -1 3 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 10 11 0 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 125_C. Hobbits' Party | Solve the following coding problem using the programming language python:
Everyone knows that hobbits love to organize all sorts of parties and celebrations. There are n hobbits living in the Shire. They decided to organize the Greatest Party (GP) that would last for several days. Next day the hobbits wrote a guest li... | ```python
n = int(input())
d = int(0.5 + (1 + 8*n)**0.5 / 2)
curr = 1
res = [[] for _ in range(d)]
for i in range(d):
j = i + 1
while len(res[i]) < d - 1:
res[i].append(str(curr))
res[j].append(str(curr))
curr += 1
j += 1
print(d)
for l in res:
print(' '.join(l))
``` | vfc_67169 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "3\n1 2 \n1 3 \n2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "3\n1 2 \n1 3 \n2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 1281_E. Jeremy Bearimy | Solve the following coding problem using the programming language python:
Welcome! Everything is fine.
You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity.
You have a list of k pairs of peo... | ```python
import sys
def input():
return sys.stdin.readline().strip()
def solve():
k = int(input())
n = 2*k
e = [[] for i in range(n)]
p = [None]*(n)
for i in range(n-1):
a, b, t = map(int, input().split())
a -= 1
b -= 1
e[a].append((b,t))
e[b].append((a,t))
q = [0]
qi = 0
while qi < len(q):
x = ... | vfc_67173 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 2 3\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 3\n",
"output": "15 33\n6 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n2 1 4\n",
"output": "4 4\n",
"ty... |
code_contests | verifiable_code | 1301_E. Nanosoft | Solve the following coding problem using the programming language python:
Warawreh created a great company called Nanosoft. The only thing that Warawreh still has to do is to place a large picture containing its logo on top of the company's building.
The logo of Nanosoft can be described as four squares of the same s... | ```python
def main():
import sys
input = sys.stdin.buffer.readline
# max
def STfunc(a, b):
if a > b:
return a
else:
return b
# クエリは0-indexedで[(r1, c1), (r2, c2))
class SparseTable():
def __init__(self, grid):
# A: 処理したい2D配列
... | vfc_67177 | {
"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": "8 8 8\nRRRRGGGG\nRRRRGGGG\nRRRRGGGG\nRRRRGGGG\nYYYYBBBB\nYYYYBBBB\nYYYYBBBB\nYYYYBBBB\n1 1 8 8\n5 2 5 7\n3 1 8 6\n2 3 5 8\n1 2 6 8\n2 1 5 5\n2 1 7 7\n6 5 7 5\n",
"output": "64\n0\n16\n4\n16\n4\n36\n0\n",
"type": "stdin_... |
code_contests | verifiable_code | 1325_E. Ehab's REAL Number Theory Problem | Solve the following coding problem using the programming language python:
You are given an array a of length n that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.
A sequence... | ```python
from collections import deque
import sys
input=sys.stdin.readline
def make_mf():
res=[-1]*(mxa+5)
ptoi=[0]*(mxa+5)
pn=1
for i in range(2,mxa+5):
if res[i]==-1:
res[i]=i
ptoi[i]=pn
pn+=1
for j in range(i**2,mxa+5,i):
if re... | vfc_67181 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6 15 10\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 3 6 6\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 1344_D. Résumé Review | Solve the following coding problem using the programming language python:
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming proje... | ```python
import os
import sys
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
readline = sys.stdin.readline
#####################################################################################
class CF(object):
def __init__(self):
self.eps = 1e-7
self.n, self.k = list(... | vfc_67185 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 8\n4 4 8 2 1\n",
"output": "2 2 2 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 32\n1 2 3 4 5 5 5 5 5 5\n",
"output": "1 2 3 3 3 4 4 4 4 4 ",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1387_A. Graph | Solve the following coding problem using the programming language python:
You are given an undirected graph where each edge has one of two colors: black or red.
Your task is to assign a real number to each node so that:
* for each black edge the sum of values at its endpoints is 1;
* for each red edge the sum ... | ```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_67193 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n1 2 1\n",
"output": "YES\n1 0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 2 2\n2 2 1\n2 1 1\n1 2 2\n",
"output": "NO",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1408_D. Searchlights | Solve the following coding problem using the programming language python:
There are n robbers at coordinates (a_1, b_1), (a_2, b_2), ..., (a_n, b_n) and m searchlight at coordinates (c_1, d_1), (c_2, d_2), ..., (c_m, d_m).
In one move you can move each robber to the right (increase a_i of each robber by one) or move... | ```python
n, m = map(int, input().split())
robbers = []
lights = []
for i in range(n):
a, b = map(int, input().split())
robbers.append((a, b))
for i in range(m):
c, d = map(int, input().split())
lights.append((c, d))
C = [0] * 1000002
for a, b in robbers:
for c, d in lights:
if a <= c:
... | vfc_67197 | {
"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": "7 3\n0 8\n3 8\n2 7\n0 10\n5 5\n7 0\n3 5\n6 6\n3 11\n11 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 6\n6 1\n10 1\n1 10\n7 7\n",
"output": "4\n",
"t... |
code_contests | verifiable_code | 1428_G1. Lucky Numbers (Easy Version) | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The only difference is that in this version q=1. You can make hacks only if all versions of the problem are solved.
Zookeeper has been teaching his q sheep how to write and how to add. The i-th sheep has... | vfc_67201 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3 4 5 6\n1\n63\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3 4 5 6\n1\n57\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn... | |
code_contests | verifiable_code | 1452_B. Toy Blocks | Solve the following coding problem using the programming language python:
You are asked to watch your nephew who likes to play with toy blocks in a strange way.
He has n boxes and the i-th box has a_i blocks. His game consists of two steps:
1. he chooses an arbitrary box i;
2. he tries to move all blocks from ... | ```python
from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
from io import BytesIO as stream
else:
f... | vfc_67205 | {
"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\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0\n",
"output": "\n1\n0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n3\n1000000000 1000000000 1000000000\n3\n1000000000 1000000000 1000000000\n3\n... |
code_contests | verifiable_code | 1475_G. Strange Beauty | Solve the following coding problem using the programming language python:
Polycarp found on the street an array a of n elements.
Polycarp invented his criterion for the beauty of an array. He calls an array a beautiful if at least one of the following conditions must be met for each different pair of indices i ≠ j:
... | ```python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
def __init__(self, file):
self.newlines = 0
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write ... | vfc_67209 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n7 9 3 14 63\n3\n2 14 42\n4\n45 9 3 18\n3\n2 2 8\n",
"output": "\n2\n0\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n101 128\n2\n101 256\n",
"output": "1\n1\n",
... |
code_contests | verifiable_code | 1500_E. Subset Trick | Solve the following coding problem using the programming language python:
Vanya invented an interesting trick with a set of integers.
Let an illusionist have a set of positive integers S. He names a positive integer x. Then an audience volunteer must choose some subset (possibly, empty) of S without disclosing it to ... | vfc_67213 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 11\n1 2 3\n2 1\n1 5\n1 6\n1 7\n2 6\n2 2\n2 3\n1 10\n2 5\n2 7\n2 10\n",
"output": "\n4\n1\n6\n12\n19\n13\n8\n2\n10\n3\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 20\n79\n1 75\... | |
code_contests | verifiable_code | 157_D. Suspects | Solve the following coding problem using the programming language python:
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, ... | ```python
"""
Brandt Smith, Lemuel Gorion and Peter Haddad
codeforces.com
Problem 156B
"""
import sys
n, m = map(int, input().split(' '))
inp = []
guess = [0] * (n + 1)
for i in range(n):
temp = int(input())
inp.append(temp)
if temp < 0:
m -= 1
guess[-temp] -= 1
else:
guess... | vfc_67221 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n-1\n-2\n-3\n",
"output": "Not defined\nNot defined\nNot defined\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n+2\n-3\n+4\n-1\n",
"output": "Lie\nNot defined\nLie\nNot def... |
code_contests | verifiable_code | 224_A. Parallelepiped | Solve the following coding problem using the programming language python:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single ... | ```python
a,b,c=map(int,input().split())
print(int(4*pow(a*c/b,0.5)+4*pow(a*b/c,0.5)+4*pow(b*c/a,0.5)))
``` | vfc_67233 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6 6\n",
"output": "28",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n",
"output": "12",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 248_D. Sweets for Everyone! | Solve the following coding problem using the programming language python:
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"
Dr. Suess, How The Grinch Stole Christmas
... | ```python
def check(n, casas):
#print('n:',n)
global T,N,street
current = n
time = T
need = 0
last_house = 0
for ind, i in enumerate(street):
time -= 1
if i == 'S':
current += 1
elif i == 'H':
need += 1
i... | vfc_67237 | {
"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": "23 50\nHHSS.......SSHHHHHHHHHH\n",
"output": "8",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 272_E. Dima and Horses | Solve the following coding problem using the programming language python:
Dima came to the horse land. There are n horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the number of enemies of each horse is at most 3.
R... | vfc_67241 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"output": "1100000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2\n3 2\n3 1\n",
"output": "100",
"type": "stdin_stdout"
},... | |
code_contests | verifiable_code | 296_B. Yaroslav and Two Strings | Solve the following coding problem using the programming language python:
Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly,... | ```python
#!/usr/bin/python3
def build(n, s, t):
ans = 1
for i in range(n):
if s[i] == '?' and t[i] == '?':
ans = (55 * ans) % (10 ** 9 + 7)
elif s[i] == '?':
ans = ((ord(t[i]) - ord('0') + 1) * ans) % (10 ** 9 + 7)
elif t[i] == '?':
ans = ((ord('9') ... | vfc_67245 | {
"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\n90\n09\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 319_E. Ping-Pong | Solve the following coding problem using the programming language python:
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 f... | ```python
def dfs(G, start, path_exists):
s = [start]
visited = set([])
if not start in path_exists:
path_exists[start] = set([])
while(s):
node = s.pop()
if not node in visited:
visited.add(node)
path_exists[start].add(node)
a, b = G[node]
... | vfc_67249 | {
"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\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 -311 -186\n1 -1070 -341\n1 -1506 -634\n1 688 1698\n2 2 4\n1 70 1908\n2 1 ... |
code_contests | verifiable_code | 343_E. Pumping Stations | Solve the following coding problem using the programming language python:
Mad scientist Mike has applied for a job. His task is to manage a system of water pumping stations.
The system consists of n pumping stations, which are numbered by integers from 1 to n. Some pairs of stations are connected by bidirectional pip... | vfc_67253 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 11\n1 2 10\n1 6 8\n2 3 4\n2 5 2\n2 6 3\n3 4 5\n3 5 4\n3 6 2\n4 5 7\n4 6 2\n5 6 3\n",
"output": "77\n1 2 6 3 5 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 17\n9 1 8\n7 10 1\n5 4... | |
code_contests | verifiable_code | 367_B. Sereja ans Anagrams | Solve the following coding problem using the programming language python:
Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of p... | ```python
from sys import stdin, stdout
from math import log, sqrt
lines = stdin.readlines()
n = int(lines[0].split()[0])
m = int(lines[0].split()[1])
p = int(lines[0].split()[2])
a = [int(x) for x in lines[1].split()]
b = [int(x) for x in lines[2].split()]
def hash_elem(x):
x = (x * 1662634645 + 32544235) & 0xf... | vfc_67257 | {
"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 1\n1 2 3 2 1\n1 2 3\n",
"output": "2\n1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3 2\n1 3 2 2 3 1\n1 2 3\n",
"output": "2\n1 2 ",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 38_F. Smart Boy | Solve the following coding problem using the programming language python:
Once Petya and Vasya invented a new game and called it "Smart Boy". They located a certain set of words — the dictionary — for the game. It is admissible for the dictionary to contain similar words.
The rules of the game are as follows: first ... | vfc_67261 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\naba\nabac\n",
"output": "Second\n29 35\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nartem\nnik\nmax\n",
"output": "First\n2403 1882\n",
"type": "stdin_stdout"
}
... | |
code_contests | verifiable_code | 40_E. Number Table | Solve the following coding problem using the programming language python:
As it has been found out recently, all the Berland's current economical state can be described using a simple table n × m in size. n — the number of days in each Berland month, m — the number of months. Thus, a table cell corresponds to a day an... | ```python
import itertools
import math
n, m = [int(x) for x in input().split()]
if n%2 != m%2:
print(0)
else:
k = int(input())
S = [[] for i in range(max(n,m))]
for i in range(k):
a, b, c = [int(x) for x in input().split()]
if n<m:
S[b-1].append(c==-1)
else:
... | vfc_67265 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 216000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n0\n100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1\n1 1 -1\n100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 438_D. The Child and Sequence | Solve the following coding problem using the programming language python:
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks.
Fortunately, Picks remembers how to repair the sequence.... | vfc_67269 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n1 2 3 4 5\n2 3 5 4\n3 3 5\n1 2 5\n2 1 3 3\n1 1 3\n",
"output": "8\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n6 9 6 7 6 1 10 10 9 5\n1 3 9\n2 7 10 9\n2 5 10 8\n1 4 7\n3 ... | |
code_contests | verifiable_code | 460_A. Vasya and Socks | Solve the following coding problem using the programming language python:
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, ... | ```python
n, m = map(int, input().split() )
r = 0
t = 1
while n:
n -= 1
if t % m == 0:
n += 1
t += 1
print(t-1)
``` | vfc_67273 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 530_F. Jumping frogs | Solve the following coding problem using the programming language python:
A rectangular swamp is inhabited by 10 species of frogs. Frogs of species i can jump from hillocks to hillock exactly i units along X-axis or Y-axis. Initially frogs of all types sit at the hillock at coordinates (0, 0). You are given coordinate... | vfc_67285 | {
"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\n0 1\n0 -2\n0 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 1\n0 2\n0 3\n2 2\n2 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn... | |
code_contests | verifiable_code | 557_A. Ilya and Diplomas | Solve the following coding problem using the programming language python:
Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the... | ```python
ttl = int(input())
mx1 = [int(i) for i in list(input().split(" "))]
mx2 = [int(i) for i in list(input().split(" "))]
mx3 = [int(i) for i in list(input().split(" "))]
min1 = mx1[0]
min2 = mx2[0]
min3 = mx3[0]
max1 = mx1[1]-min1
max2 = mx2[1]-min2
max3 = mx3[1]-min3
ttl -=(mx1[0]+mx2[0]+mx3[0])
while(ttl>0):
... | vfc_67289 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 3\n2 2\n2 2\n",
"output": "2 2 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 5\n2 6\n3 7\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 582_D. Number of Binominal Coefficients | Solve the following coding problem using the programming language python:
For a given prime integer p and integers α, A calculate the number of pairs of integers (n, k), such that 0 ≤ k ≤ n ≤ A and <image> is divisible by pα.
As the answer can be rather large, print the remainder of the answer moduly 109 + 7.
Let u... | vfc_67293 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n5000\n",
"output": "8576851\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... | |
code_contests | verifiable_code | 604_D. Moodular Arithmetic | Solve the following coding problem using the programming language python:
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird fun... | ```python
MOD = 10**9+7
def f(a,b):
if b == 1:
return a%MOD
elif b % 2 == 0:
return f((a*a)%MOD,b//2)
else:
return (a*f((a*a)%MOD,b//2)) % MOD
p,k = map(int,input().split())
if k == 0:
print(f(p,p-1))
exit()
if k == 1:
print(f(p,p))
exit()
t = 1
a = k
while a != ... | vfc_67297 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n",
"output": "25\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 650_E. Clockwork Bomb | Solve the following coding problem using the programming language python:
My name is James diGriz, I'm the most clever robber and treasure hunter in the whole galaxy. There are books written about my adventures and songs about my operations, though you were able to catch me up in a pretty awkward moment.
I was able t... | vfc_67305 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n2 3\n1 3\n3 2\n",
"output": "1\n1 2 1 3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 676_C. Vasya and String | Solve the following coding problem using the programming language python:
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal let... | ```python
######### ## ## ## #### ##### ## # ## # ##
# # # # # # # # # # # # # # # # # # #
# # # # ### # # # # # # # # # # # #
# ##### # # # # ### # # # # # # # # #####
# # # # # # # # # # # # # # # # # # ... | vfc_67309 | {
"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": "8 1\naabaabaa\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\nabba\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 69_C. Game | Solve the following coding problem using the programming language python:
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats ... | ```python
# Not really fair, since I already solved this one previously. ;)
k, n, m, q = [int(i) for i in input().split()]
basic = [input() for i in range(n)]
composite = {}
for i in range(m):
name, items = input().split(":")
composite[name] = {}
for item in items.split(","):
component, cnt = item.split()
comp... | vfc_67313 | {
"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": "2 3 2 5\ndesolator\nrefresher\nperseverance\nvanguard: desolator 1, refresher 1\nmaelstorm: perseverance 2\n1 desolator\n2 perseverance\n1 refresher\n2 desolator\n2 perseverance\n",
"output": "1\nvanguard 1\n2\ndesolator 1\nm... |
code_contests | verifiable_code | 720_F. Array Covering | Solve the following coding problem using the programming language python:
Misha has an array of integers of length n. He wants to choose k different continuous subarrays, so that each element of the array belongs to at least one of the chosen subarrays.
Misha wants to choose the subarrays in such a way that if he cal... | vfc_67317 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n6 -4 -10 -4 7\n",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6\n957 -819 -414\n",
"output": "-1647",
"type": "stdin_stdout"
},
{
"fn_name"... | |
code_contests | verifiable_code | 742_C. Arpa's loud Owf and Mehrdad's evil plan | Solve the following coding problem using the programming language python:
As you have noticed, there are lovely girls in Arpa’s land.
People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi.
<image>
Someday Arpa shouted Owf loudly from the... | ```python
from math import gcd
def DFS(v):
re = 0
cur = v
while not used[cur]:
used[cur] = True
re += 1
cur = gr[cur]
if re % 2 == 0:
re //= 2
return 0 if cur != v else re
n = int(input())
used = [False] * (n + 1)
gr = [0] + list(map(int, input().split()))
res = 1
f... | vfc_67321 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3 1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 4 4 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 765_G. Math, math everywhere | Solve the following coding problem using the programming language python:
If you have gone that far, you'll probably skip unnecessary legends anyway...
You are given a binary string <image> and an integer <image>. Find the number of integers k, 0 ≤ k < N, such that for all i = 0, 1, ..., m - 1
<image> Print the answ... | vfc_67325 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n2 1\n3 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "01\n2\n3 2\n5 1\n",
"output": "15",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 810_A. Straight «A» | Solve the following coding problem using the programming language python:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is... | ```python
n,k=tuple(int(i) for i in input().strip().split(" "))
a=input().strip().split(" ")
sum=0
o=0
for i in a:
sum+=int(i)
if sum/n>=k-0.5:
print(0)
exit(0)
while sum/n<k-0.5:
sum+=k
n+=1
o+=1
print(o)
``` | vfc_67333 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n4 4 4\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 10\n8 9\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 835_D. Palindromic characteristics | Solve the following coding problem using the programming language python:
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.
A string is 1-palindrome if and only if it reads the same backwar... | ```python
def main():
s = input()
n = len(s)
isPalindrome = [[False for i in range(n + 1)] for i in range(n + 1)]
for i in range(n):
isPalindrome[i][i] = True
for i in range(n - 1, -1, -1):
for j in range(i + 1, n):
if (s[i] == s[j] and (i + 1 == j or isPalindrome[i + 1][... | vfc_67337 | {
"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": "abacaba\n",
"output": "12 4 1 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abba\n",
"output": "6 1 0 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 87_E. Mogohu-Rea Idol | Solve the following coding problem using the programming language python:
A long time ago somewhere in the depths of America existed a powerful tribe governed by the great leader Pinnie-the-Wooh. Once the tribe conquered three Maya cities. Pinnie-the-Wooh grew concerned: there had to be some control over the conquered... | vfc_67345 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0\n1 0\n1 1\n\n4\n8 8\n5 5\n6 4\n8 4\n\n3\n-1 -1\n-3 -1\n-2 -2\n\n5\n0 0\n2 1\n7 1\n1 1\n5 3\n",
"output": "NO\nYES\nNO\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 903_G. Yet Another Maxflow Problem | Solve the following coding problem using the programming language python:
In this problem you will have to deal with a very special network.
The network consists of two parts: part A and part B. Each part consists of n vertices; i-th vertex of part A is denoted as Ai, and i-th vertex of part B is denoted as Bi.
For ... | vfc_67349 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 2\n1 2\n3 4\n5 6\n2 2 7\n1 4 8\n4 3 9\n1 100\n2 100\n",
"output": "9\n14\n14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10 10\n291546518 199012865\n327731857 137263959\n1451402... | |
code_contests | verifiable_code | 926_B. Add Points | Solve the following coding problem using the programming language python:
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neigh... | ```python
import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
g = 0
for i in range(n - 1):
g = math.gcd(g, a[i + 1] - a[i])
print((a[-1] - a[0]) // g - n + 1)
``` | vfc_67353 | {
"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\n-5 10 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10 9 0 -1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 981_B. Businessmen Problems | Solve the following coding problem using the programming language python:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid ... | ```python
drugs_a = {}
drugs_b = {}
for _ in range(int(input())):
n,p = map(int,input().split())
drugs_a[n] = p
for _ in range(int(input())):
n,p = map(int,input().split())
drugs_b[n] = p
try:
if drugs_b[n] > drugs_a[n]:
del drugs_a[n]
else:
del drugs_b[n... | vfc_67361 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89\n",
"output": "408\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"output": "24\n",
"typ... |
code_contests | verifiable_code | 2-fast-2-furious | Solve the following coding problem using the programming language python:
Problem Statement:
Dom and Brian were trying to evade the truck drivers of Verone's gang. They were too fast, too furious for them, and could get away from the truck drivers easily. They decided to race with each other, and divided the city int... | ```python
n=input(); D=map(int,raw_input().split()); B=map(int,raw_input().split()); val,val2=0,0;
for i in xrange(n-1):
val=max(val,abs(D[i+1]-D[i]))
for i in xrange(n-1):
val2=max(val2,abs(B[i+1]-B[i]))
if val==val2: print "Tie"; print val;
elif val>val2: print "Dom"; print val;
else: print "Brian"; print val2;
``` | vfc_67365 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n1 2 4\n\nSAMPLE",
"output": "Brian\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n1 2 4\n\nSAMPKE",
"output": "Brian\n2\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | bhulla-and-captain-cold-1 | Solve the following coding problem using the programming language python:
Mr. Bhulla, now a member of the Mafia, is ordered by his capo Captain Cold to buy guns, ammunition and masks for the organization. Captain Cold is used to playing games with his men and so gives Bhulla some rules regarding the purchase. He says:... | ```python
for t in range(input()):
n = input()
a = [ [] for i in range(n) ]
for i in range(n):
a[i] = map( int, raw_input().split() )
for i in range(1,n):
a[i][0] += min( a[i-1][1], a[i-1][2] )
a[i][1] += min( a[i-1][2], a[i-1][0] )
a[i][2] += min( a[i-1][0], a[i-1][1] )
print min(a[-1])
``` | vfc_67369 | {
"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\n25 10 30\n20 10 15\n15 20 30\n\nSAMPLE",
"output": "40\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | count-divisors | Solve the following coding problem using the programming language python:
You have been given 3 integers l, r and k. Find how many numbers between l and r (both inclusive) are divisible by k. You do not need to print these numbers, you just have to find their count.
Input Format
The first and only line of input con... | ```python
s = raw_input()
l,r,k = s.split()
l = int(l)
r = int(r)
k = int(k)
count = 0
for i in range(l,r+1):
if(i%k==0):
count = count +1
print count
``` | vfc_67373 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10 1\n\nSAMPLE",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10 2\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | find-the-substrings | Solve the following coding problem using the programming language python:
Given a string S made of letters a, b and c, find the number of sub strings that do not contain all the letters a, b and c. That is the number of sub strings that do not contain at least one of the letters a or b or c.
Note that the sub string ... | ```python
t=int(raw_input())
for w in range(t):
s=raw_input()
l=len(s)
cnt=l*(l+1)/2
a=0
b=0
c=0
for i in range(len(s)):
if s[i]=='a':
a=i+1
cnt-=min(b,c)
if s[i]=='b':
b=i+1
cnt-=min(a,c)
if s[i]=='c':
c=i+1... | vfc_67377 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nababa\nabc\nbabac\n\nSAMPLE",
"output": "15\n5\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nababa\ncba\nbabac\n\nSAMPLE",
"output": "15\n5\n12\n",
"type": "stdin_s... |
code_contests | verifiable_code | intelligent-girl-1 | Solve the following coding problem using the programming language python:
Soumika has a string S and its starting index is 1. The string S consists of characters from 1-9. As she is very intelligent, she wants to test his brother Vinay Tendulkar. She asked her brother Vinay Tendulkar to count the number of even number... | ```python
x=map(int,' '.join(raw_input()).split())
#print x
s= [0 for i in x]
for i in range(len(x)):
if(x[i]%2==0):
s[i]=1
#print s
ss = [sum(s[i:]) for i in range(len(s)) ]
ss = map(str,ss)
print ' '.join(ss)
``` | vfc_67381 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "574674546476\n\nSAMPLE",
"output": "7 7 7 6 5 5 4 4 3 2 1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4645557347476",
"output": "6 5 4 3 3 3 3 3 3 2 2 1 1\n",
"type": "st... |
code_contests | verifiable_code | maximum-difference-5 | Solve the following coding problem using the programming language python:
Given N space separated integers. Your task is to arrange them such that the summation M of the absolute differences between every two adjacent numbers is maximum.
Input:
First line of the input contains an integer N.
Second line conta... | ```python
import math
n = int(raw_input())
a = map(int,raw_input().split())
a = sorted(a)
b = []
c = []
for i in xrange(n/2):
b.append(a[i])
b.append(a[n-1-i])
c.append(a[n-1-i])
c.append(a[i])
if n%2 != 0 :
b.append(a[n/2])
c.append(a[n/2])
ans = 0
ans1 = 0
#print b,c
for i in xrange(n-1)... | vfc_67385 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 7\n\nSAMPLE",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "504\n10905 17006 12109 32008 643 25345 30694 14989 16713 2289 1682 5967 29164 32392 31370 31608 19071 560... |
code_contests | verifiable_code | one-way-or-another-juneclash-3 | Solve the following coding problem using the programming language python:
The link to the Russian translation.
Stefan is stuck in Marty's body and in order to fix him, Valerie has encountered a problem with dead witches spirits.
In order to allow her to do such magic, the witches gave her a huge grid (10^18 by 10^1... | ```python
def mod(val):
return val%2
def differenceOf(x,y):
if x > y:
return x-y
return y-x
T = int(raw_input())
result = []
for i in xrange(0,T):
n = int(raw_input())
if n==1:
result.append("No")
else:
r_one = 0
c_one = 0
x_one = 0
isPossible = True
for j in xrange(0,n):
inVal = raw_input().sp... | vfc_67389 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n5 4 2\n1 5 2\n5\n1 4 4\n3 1 2\n1 2 5\n3 3 3\n1 1 1\n5\n1 4 1\n4 1 1\n5 2 5\n2 5 3\n5 3 4\n\nSAMPLE",
"output": "No\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n5 4 ... |
code_contests | verifiable_code | random-shuffle | Solve the following coding problem using the programming language python:
In computer Science there is common need to generate random permutation. It can be seen as the shuffle of the numbers. Start with sorted permutation of n, at each step select the random no between 1 to n and put it at front. after doing n steps ... | ```python
def bell_seq_generator():
bell = [1]
N = 0
while N<=1000:
yield bell[N]%MOD
x = bell[-1]
bell.append(0)
N += 1
for j in xrange(0, N):
x, bell[j] = (bell[j]+x)%MOD, x%MOD
bell[N] = x
MOD=1000000007
if __name__ == '__main__':
x=list(bell_... | vfc_67393 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | skipping-sum-1 | Solve the following coding problem using the programming language python:
You are given an array of N integers A[1] , A[2] , ... , A[N] . You have to answer Q queries. Each query consists of 3 integers L, R and K. For each query, you have to find the value of the Skipping Sum in the following manner :
def skip... | ```python
[N,Q] = [int(i) for i in raw_input().strip().split(" ")]
A = [int(i) for i in raw_input().strip().split(" ")]
dp = [[0 for i in range(len(A))]for i in range(10)]
for i in range(10):
for j in range(len(A)):
if j<=i:
dp[i][j]=A[j]
else:
dp[i][j]=A[j]+dp[i][j-i-1]
for i in range(Q):
[L,R,K] = [int(i)... | vfc_67397 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 6\n5 4 2 1 7 9 10 9\n1 8 1\n1 8 2\n4 8 9\n3 7 2\n3 7 3\n3 7 4\n\nSAMPLE",
"output": "47\n24\n1\n19\n11\n12\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | the-treasure-lock | Solve the following coding problem using the programming language python:
In vardhaman college of engineering, there is competition with name treasure lock.
To make this competition the key for the lock should satisfy following rules.
1 .3, 5, or both as its digits. No other digit is allowed.
2. Number of times 3 appe... | ```python
def ans(n):
if(n == 0):
return True
elif(n < 0):
return False
else:
return ans(n-5) or ans(n-3)
for _ in xrange(input()):
n=input()
if ans(n):
if(n%5==0):
print str(3)*n
else:
c = 5*(2*n%3)
print str(5)*(n-c)+str(3)*c
... | vfc_67401 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n3\n5\n17\n\nSAMPLE",
"output": "-1\n555\n33333\n55555555555533333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1\n3\n5\n17\n\nLAMPSE",
"output": "-1\n555\n33333\n55555555... |
code_contests | verifiable_code | p00103 Baseball Simulation | Solve the following coding problem using the programming language python:
Ichiro likes baseball and has decided to write a program which simulates baseball.
The program reads events in an inning and prints score in that inning. There are only three events as follows:
Single hit
* put a runner on the first base.
* t... | ```python
n = int(input())
for i in range(n):
out_cnt = 0
score = 0
runner = [0,0,0,0]
while True:
event = input()
if event=="OUT":
out_cnt += 1
if out_cnt == 3:
break
elif event=="HIT":
if 1 in runner:
for ind... | vfc_67449 | {
"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\nHIT\nOUT\nHOMERUN\nHIT\nHIT\nHOMERUN\nHIT\nOUT\nHIT\nHIT\nHIT\nHIT\nOUT\nHIT\nHIT\nOUT\nHIT\nOUT\nOUT",
"output": "7\n0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00613 A Piece of Cake | Solve the following coding problem using the programming language python:
In the city, there are two pastry shops. One shop was very popular because its cakes are pretty tasty. However, there was a man who is displeased at the shop. He was an owner of another shop. Although cause of his shop's unpopularity is incredib... | ```python
while True:
K = int(input())
if K == 0:
break
c = [int(i) for i in input().split()]
S = 0
for i in range(len(c)):
S = S + c[i]
print(int(S/(K-1)))
``` | vfc_67461 | {
"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\n2\n3\n5 4 3\n0",
"output": "2\n6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00751 Old Memories | Solve the following coding problem using the programming language python:
In 4272 A.D., Master of Programming Literature, Dr. Isaac Cornell Panther-Carol, who has miraculously survived through the three World Computer Virus Wars and reached 90 years old this year, won a Nobel Prize for Literature. Media reported every... | vfc_67465 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 4\nAABBCCDDEEFFGGHHIJJKKLLMMNNOOPP\nAABBCCDDEEFFGG\nCCDDEEFFGGHHII\nFFGGHHIIJJKKLL\nJJKKLLMMNNOOPP\n2 3\nABRACADABRA.ABBRACADABRA.\nABRACADABRA.A\n.ABRACADABRA.\nBRA.ABRACADAB\n2 2\nAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAA\nAAAAAAAAAAAAA\... | |
code_contests | verifiable_code | p00889 Find the Multiples | Solve the following coding problem using the programming language python:
You are given a sequence a0a1...aN-1 digits and a prime number Q. For each i ≤ j with ai ≠ 0, the subsequence aiai+1...aj can be read as a decimal representation of a positive integer. Subsequences with leading zeros are not considered. Your tas... | ```python
from collections import defaultdict
def gen(N, S, W):
g = S
for i in range(N):
yield (g//7) % 10
if g % 2 == 0:
g //= 2
else:
g = (g//2) ^ W
def solve():
N, S, W, Q = map(int, input().split())
if N == 0:
return False
bs = list(gen(N... | vfc_67469 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 32 64 7\n4 35 89 5\n5 555 442 3\n5 777 465 11\n100000 666 701622763 65537\n0 0 0 0",
"output": "2\n4\n6\n3\n68530",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 32 64 13\n4 35 89 5\n5 5... |
code_contests | verifiable_code | p01020 Lonely Adventurer | Solve the following coding problem using the programming language python:
Boy G was on a voyage with his father to celebrate his 13th birthday. However, during the voyage, unfortunately the ship was hit by a storm and the ship capsized. When he woke up, it was an uninhabited island. Partly due to the influence of the ... | vfc_67473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 4",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 3 3 3 3",
"output": "21",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... | |
code_contests | verifiable_code | p01153 Gather on the Clock | Solve the following coding problem using the programming language python:
There is a self-playing game called Gather on the Clock.
At the beginning of a game, a number of cards are placed on a ring. Each card is labeled by a value.
In each step of a game, you pick up any one of the cards on the ring and put it on th... | vfc_67477 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 0 1 2 3\n6 1 8 0 3 5 9",
"output": "6\n34",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01292 Secret Operation | Solve the following coding problem using the programming language python:
Mary Ice is a member of a spy group. She is about to carry out a secret operation with her colleague.
She has got into a target place just now, but unfortunately the colleague has not reached there yet. She needs to hide from her enemy George W... | vfc_67481 | {
"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": "50 100\n2\n50 50 0\n51 51 50\n2\n0 0 0\n1 1 50\n0\n0 0",
"output": "50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50 100\n2\n50 50 0\n51 51 50\n2\n0 -1 0\n1 1 50\n0\n0 0",
"output... | |
code_contests | verifiable_code | p01461 Multi Ending Story | Solve the following coding problem using the programming language python:
You are a programmer who loves bishojo games (a sub-genre of dating simulation games). A game, which is titled "I * C * P * C!" and was released yesterday, has arrived to you just now. This game has multiple endings. When you complete all of tho... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
A = [0]*N
B = [0]*N
for i in range(N-1):
a, b = map(int, readline().split())
if not a <= b:
a, b = b, a
A[i] = a-1
B[i] =... | vfc_67485 | {
"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\n5 2\n3 5\n5 4\n5 5",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 3\n4 4\n4 4",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01620 King's Inspection | Solve the following coding problem using the programming language python:
A great king of a certain country suddenly decided to visit the land of a friendly country. The country is famous for trains, and the king visits various stations.
There are 52 train stations, each with a single uppercase or lowercase alphabeti... | ```python
def horizontal_input(T=str):
return list(map(T,input().split()))
def vertical_input(n,T=str,sep=False,septype=tuple):
data=[]
if sep:
for i in range(n):
data.append(septype(map(T,input().split())))
else:
for i in range(n):
data.append(T(input()))
re... | vfc_67489 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\nbdd\n3\n3 2 1\nDDDA\n5\n3 1 4 5 3\ndcdkIlkP\n0",
"output": "abc\nABCx\nabZfFijL",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\nbdd\n3\n3 2 1\nDDDA\n5\n3 1 4 5 2\ndcdkIlkP\n0... |
code_contests | verifiable_code | p01773 Cram School Schedule | Solve the following coding problem using the programming language python:
B: Cram School Schedule / Cram School Timetable
story
You are the owner of a cram school. Your cram school is a private lesson system with one student and one teacher. The teachers at this cram school are very good and can teach all classes re... | vfc_67493 | {
"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": "2 10:00-11:30 12:00-13:00\n2\n1 10:00-15:00\n2 09:00-12:00 18:10-18:55\n2\n2 10:00-13:00 15:30-16:40\n3 06:00-08:00 12:00-13:10 15:00-17:00",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | p01907 Fractal Tree | Solve the following coding problem using the programming language python:
problem
AOR Ika likes rooted trees with a fractal (self-similar) structure. Consider using the weighted rooted tree $ T $ consisting of $ N $ vertices to represent the rooted tree $ T'$ with the following fractal structure.
* $ T'$ is the addi... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LS(): return input().split()
def I(): return int(input())... | vfc_67497 | {
"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": "0.75\n4\n1 2 1\n2 3 3\n3 4 10",
"output": "24.8569335938",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0.75\n4\n1 2 1\n2 3 3\n3 4 20",
"output": "40.611328125\n",
"type": "stdi... |
code_contests | verifiable_code | p02045 Poison Swamp | Solve the following coding problem using the programming language python:
Poisonous swamp
You are playing a retro role-playing game. The field of this game is a grid of 100 squares vertically and 100 squares horizontally. The cells in the xth column from the left and the yth row from the top of this field are represe... | vfc_67501 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3 5 7\n3 3\n7 3\n7 7\n5\n1 10 100 10\n1 1\n100 1\n50 20\n50 80\n51 21\n51 1\n0",
"output": "5\n174",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3 5 7\n3 3\n7 3\n7 7\n5\n1 10 100... | |
code_contests | verifiable_code | p02188 Restricted DFS | Solve the following coding problem using the programming language python:
G: Restricted DFS
problem
There is an undirected tree G that consists of N vertices N-1 edges and has no self-loops or multiple edges. The vertices are each numbered from 1 to N, the edges are also numbered from 1 to N-1, and the i-th edge con... | vfc_67505 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n1 2\n1 3",
"output": "2\n3\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 3\n1 2\n1 3",
"output": "2\n3\n3\n",
"type": "stdin_stdout"
},
{
"fn_... | |
code_contests | verifiable_code | cbars | Solve the following coding problem using the programming language python:
A few days ago Chef decided to cook a new dish – chocolate. This must be something amazing. The idea is that chocolate bar will be divided into cells. It must be long, but narrow. To interest customers every bar must be unique. Bar will consist... | ```python
#!/usr/bin/python
mod = 1000000007
#import psyco
#psyco.full()
def matrix_mult(A, B):
C = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(3):
for j in range(3):
for k in range(3):
C[i][k] = (C[i][k] + A[i][j] * B[j][k])
if(C[i][k] > 1000000007):
C[i][k] = C[i][k] % 100000000... | vfc_67517 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2",
"output": "14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3",
"output": "322",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cseq | Solve the following coding problem using the programming language python:
Given three positive integers N, L and R, find the number of non-decreasing sequences of size at least 1 and at most N, such that each element of the sequence lies between L and R, both inclusive.
Print the answer modulo 10^6+3.
Input
First l... | ```python
p=1000003
'''
calculating modulo inverse of 'a' using Euclid's Extended Lemma
'''
def invert_mod(a):
n=1
old=0
q=p
r=0
h=0
pos=0
while a>0:
r=q%a
q=q/a
h=q*n+old
old=n
n=h
q=a
a=r
if pos==0:
pos=1
else:
pos=0
if(pos):
return old
else:
return p-old
'''
Calculating C(... | vfc_67521 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 4 5\n2 4 5",
"output": "2\n5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | hello | Solve the following coding problem using the programming language python:
Chef talks a lot on his mobile phone. As a result he exhausts his talk-value (in Rokdas) very quickly. One day at a mobile recharge shop, he noticed that his service provider gives add-on plans which can lower his calling rates (Rokdas/minute). ... | ```python
#!/usr/bin/env python
import sys
def parse_line(fmt):
args = sys.stdin.readline().split()
rv = []
for v in fmt:
arg = args.pop(0)
if v == 'r':
rv.append(float(arg))
elif v == 'i':
rv.append(int(arg))
else:
rv.append(arg)
if ... | vfc_67525 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1.00 200 1\n1 0.50 28\n1.00 200 2\n1 0.75 40\n3 0.60 100\n1.00 50 2\n1 0.75 40\n3 0.60 100\n1.00 100 2\n3 0.50 10\n2 0.10 20",
"output": "1\n2\n0\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | mime2 | Solve the following coding problem using the programming language python:
Many internet protocols these days include the option of associating a
media type with the content being sent.
The type is usually inferred from the file extension.
You are to write a program that facilitates the lookup of media types for
a numb... | ```python
import os
# print hello
a,b = map(int,raw_input().split())
fileTypeHash = dict()
for i in range(0,a):
line=raw_input().split()
ext=line[0]
filetype=line[1]
fileTypeHash[ext]=filetype
# print hash
for i in range(0,b):
line =raw_input().split()[0]
ind = line.rfind('.')
if(ind == -1):
print("unkno... | vfc_67529 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\nhtml text/html\nhtm text/html\npng image/png\nsvg image/svg+xml\ntxt text/plain\nindex.html\nthis.file.has.lots.of.dots.txt\nnodotsatall\nvirus.exe\ndont.let.the.png.fool.you\ncase.matters.TXT",
"output": "text/html\ntex... |
code_contests | verifiable_code | rectsq | Solve the following coding problem using the programming language python:
Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell some parts of his plots. The specialty o... | ```python
import sys
import fractions
t=int(sys.stdin.readline())
for tc in xrange(t):
l,m=map(int,sys.stdin.readline().split())
gcd=fractions.gcd(l,m)
l/=gcd
m/=gcd
print l*m
``` | vfc_67533 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 15\n4 6",
"output": "6\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10 15\n4 1",
"output": "6\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | tricoin | Solve the following coding problem using the programming language python:
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?
Chef has a unusual way of forming a triangle using gold coins, which is described a... | ```python
import math
def CoinsAndTriangle():
for i in xrange(int(raw_input())):
n=int(raw_input())
output=int((-1+math.sqrt((1+(8*n))))/2)
print output
CoinsAndTriangle()
``` | vfc_67537 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n5\n7",
"output": "2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n5\n11",
"output": "2\n2\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1040_B. Shashlik Cooking | Solve the following coding problem using the programming language python:
Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.
This time Miroslav laid out n skewers parallel to each other, and enu... | ```python
n,k=map(int,input().split())
if n%(2*k+1)==0:
print(n//(2*k+1))
for i in range(k+1,n+1,2*k+1):
print(i,end=" ")
else:
if n%(2*k+1)>=k+1:
print(n//(2*k+1)+1)
for i in range(k+1,n+1,2*k+1):
print(i,end=" ")
else:
print(n//(2*k+1)+1)
for i in ra... | vfc_67545 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n",
"output": "2\n2 5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1063_B. Labyrinth | Solve the following coding problem using the programming language python:
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step y... | ```python
from collections import deque
def move(tx, ty, s, left=False):
if 0 <= tx < n and 0 <= ty < m:
if smap[tx][ty] == '.' and mp[tx][ty] == -1:
mp[tx][ty] = s
if left:
q.appendleft((tx, ty))
else:
q.append((tx, ty))
[n, m] = map(int... | vfc_67549 | {
"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": "4 5\n3 2\n1 2\n.....\n.***.\n...**\n*....\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1085_A. Right-Left Cipher | Solve the following coding problem using the programming language python:
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the cu... | ```python
s=str(input())
if len(s)<=2: print(s)
else:
first=(len(s)-1)//2
s1=(s[first-1::-1])
s2=list(s[first:])
#print(s1,s2)
k=2
for i in range(len(s1)):
s2.insert(k,s1[i])
k+=2
print(''.join(s2))
``` | vfc_67553 | {
"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": "z\n",
"output": "z\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "erfdcoeocs\n",
"output": "codeforces\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1104_D. Game with modulo | Solve the following coding problem using the programming language python:
This is an interactive problem.
Vasya and Petya are going to play the following game: Petya has some positive integer number a. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer n... | ```python
import sys
while True:
S = input()
if S=='end':
sys.exit()
if S=='mistake':
sys.exit()
if S=='start':
while True:
i=0
print('?',0,1)
sys.stdout.flush()
T=input()
if T=='x':
print('!',1)
... | vfc_67557 | {
"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": "start\nx\nx\nstart\nx\nx\ny\nstart\nx\nx\ny\ny\nend\n",
"output": "? 0 1\n! 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n60\n76\n89\n77\n41\n81\n42\n49\n39\n37\n48\n56\n26\n38\n8... |
code_contests | verifiable_code | 1132_B. Discounts | Solve the following coding problem using the programming language python:
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows yo... | ```python
n = int(input())
ar = sorted(list(map(int, input().split())))
r = sum(ar)
m = int(input())
br = list(map(int, input().split()))
for i in br:
print(r - ar[-i])
``` | vfc_67561 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n7 1 3 1 4 10 8\n2\n3 4\n",
"output": "27\n30\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n7 8 4 5 5 5 8\n2\n3 5\n",
"output": "35\n37\n",
"type": "stdin_stdout"
},... |
code_contests | verifiable_code | 1152_E. Neko and Flashback | Solve the following coding problem using the programming language python:
A permutation of length k is a sequence of k integers from 1 to k containing each integer exactly once. For example, the sequence [3, 1, 2] is a permutation of length 3.
When Neko was five, he thought of an array a of n positive integers and a ... | ```python
from collections import defaultdict, Counter
from sys import exit
N = int(input())
B = list(map(int, input().split()))
C = list(map(int, input().split()))
Edge = defaultdict(list)
Edc = defaultdict(int)
for b, c in zip(B, C):
if b > c:
print(-1)
exit()
Edge[b].append(c)
Edc[(b, c)]... | vfc_67565 | {
"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": "8\n2 3 1 1 2 4 3\n3 4 4 2 5 5 4\n",
"output": "2 5 4 3 4 1 2 3 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1174_C. Ehab and a Special Coloring Problem | Solve the following coding problem using the programming language python:
You're given an integer n. For every integer i from 2 to n, assign a positive integer a_i such that the following conditions hold:
* For any pair of integers (i,j), if i and j are coprime, a_i ≠ a_j.
* The maximal value of all a_i should b... | ```python
def main():
buf = input()
n = int(buf)
prime_map = dict()
a = []
for i in range(2, n+1):
first_prime = first_prime_factor(i)
if first_prime not in prime_map:
prime_map[first_prime] = len(prime_map)+1
a.append(prime_map[first_prime])
print(' '.join(l... | vfc_67569 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "1 2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "1 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "35291\n... |
code_contests | verifiable_code | 1192_B. Dynamic Diameter | Solve the following coding problem using the programming language python:
You are given a weighted undirected tree on n vertices and a list of q updates. Each update changes the weight of one edge. The task is to output the diameter of the tree after each update.
(The distance between two vertices is the sum of the w... | vfc_67573 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 2000\n1 2 100\n2 3 1000\n2 4 1000\n2 1030\n1 1020\n1 890\n",
"output": "2030\n2080\n2050\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10 10000\n1 9 1241\n5 6 1630\n10 5 1630\n2 6... | |
code_contests | verifiable_code | 1272_A. Three Friends | Solve the following coding problem using the programming language python:
Three friends are going to meet each other. Initially, the first friend stays at the position x = a, the second friend stays at the position x = b and the third friend stays at the position x = c on the coordinate axis Ox.
In one minute each fr... | ```python
for _ in range(int(input())):
a,b,c=[int(x) for x in input().split()]
m=max(a,b,c)-min(a,b,c)
if m>1:print((m-2)*2)
else:print('0')
``` | vfc_67589 | {
"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": "8\n3 3 4\n10 20 30\n5 5 5\n2 4 3\n1 1000000000 1000000000\n1 1000000000 999999999\n3 2 5\n3 2 6\n",
"output": "0\n36\n0\n0\n1999999994\n1999999994\n2\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1295_B. Infinite Prefixes | Solve the following coding problem using the programming language python:
You are given string s of length n consisting of 0-s and 1-s. You build an infinite string t as a concatenation of an infinite number of strings s, or t = ssss ... For example, if s = 10010, then t = 100101001010010...
Calculate the number of p... | ```python
import math
tt=int(input())
for i in range(tt):
n,x=map(int,input().split())
s=input()
a=1
b={}
def bind(x):
return -((2*x)-1)
if x<0:
a=-1
x=-x
sbal=0
for i in s:
sbal+=(bind(int(i))*a)
b[sbal]=b.get(sbal,0)+1
ans=0
if sbal==0:
... | vfc_67593 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6 10\n010010\n5 3\n10101\n1 0\n0\n2 0\n01\n",
"output": "3\n0\n1\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 2\n00\n",
"output": "1\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1337_D. Xenia and Colorful Gems | Solve the following coding problem using the programming language python:
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a we... | ```python
import bisect
def nearest_with_leader(reds, greens, blues):
minimum = 10**19*3
for g in greens:
bi = bisect.bisect_left(blues, g)
ri = bisect.bisect_right(reds, g)
if ri == 0 or bi == len(blues):
continue
b = blues[bi]
r = reds[ri-1]
minimum... | vfc_67601 | {
"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": "5\n2 2 3\n7 8\n6 3\n3 1 4\n1 1 1\n1\n1\n1000000000\n2 2 2\n1 2\n5 4\n6 7\n2 2 2\n1 2\n3 4\n6 7\n3 4 1\n3 2 1\n7 3 3 4\n6\n",
"output": "14\n1999999996000000002\n24\n24\n14\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 137_C. History | Solve the following coding problem using the programming language python:
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polyc... | ```python
import sys
import math
n=int(input())
k=[]
for i in range(n):
a,b=map(int,input().split())
k.append((a,b))
k.sort()
t,con=0,0
for (a,b) in k:
if(b<t):
con+=1
else:
t=b
print(con)
``` | vfc_67609 | {
"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": "1\n1 1000000000\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 10\n2 9\n3 8\n4 7\n5 6\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 13_C. Sequence | Solve the following coding problem using the programming language python:
Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the ... | ```python
from bisect import insort
def min_steps_N(arr):
pri_q = []
ans = 0
for n in arr:
if pri_q:
if pri_q[-1] > n:
ans += pri_q[-1] - n
pri_q.pop()
insort(pri_q, n)
insort(pri_q, n)
return ans
if __name__ == '__main__':
... | vfc_67613 | {
"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": "5\n2 1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 2 -1 2 11\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1423_L. Light switches | Solve the following coding problem using the programming language python:
Nikola owns a large warehouse which is illuminated by N light bulbs, numbered 1 to N. At the exit of the warehouse, there are S light switches, numbered 1 to S. Each switch swaps the on/off state for some light bulbs, so if a light bulb is off, ... | vfc_67617 | {
"difficulty": "19",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 4\n2 1 2\n2 2 3\n1 2\n1 1\n2 1 3\n3 1 2 3\n3 1 2 4\n",
"output": "2\n2\n3\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 8 10\n2 1 3\n5 1 4 5 6 7\n2 1 4\n6 1 3 4 5 6 7\n3 5 6 7\... | |
code_contests | verifiable_code | 1443_E. Long Permutation | Solve the following coding problem using the programming language python:
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, [1], [4, 3, 5, 1, 2], [3, 2, 1] — are permutations, and [1, 1], [4, 3, 1], [2, 3, 4] — no.
Permutation a is lexicographically smal... | ```python
from math import factorial
def short_perm_to_num(perm, n): # O(n**2), but n <= 70
result = 0
is_used = {}
for i in range(n):
for j in range(perm[i]):
if not (j in is_used):
result += factorial(n-1-i)
is_used[perm[i]] = True
return result
def perm_t... | vfc_67621 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 2 4\n2 3\n1 1 2\n1 3 4\n",
"output": "9\n4\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 1 2\n2 1\n1 2 2\n",
"output": "3\n1\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 1494_B. Berland Crossword | Solve the following coding problem using the programming language python:
Berland crossword is a puzzle that is solved on a square grid with n rows and n columns. Initially all the cells are white.
To solve the puzzle one has to color some cells on the border of the grid black in such a way that:
* exactly U cell... | ```python
def solve():
n, u, r, d, l = map(int, input().split())
for i in range(16):
ur = i & 1
dr = bool(i & 1<<1)
dl = bool(i & 1<<2)
ul = bool(i & 1<<3)
uu=u
rr=r
dd=d
ll=l
uu -= ur + ul
rr -= ur + dr
dd -= dr + dl
... | vfc_67629 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 2 5 3 1\n3 0 0 0 0\n4 4 1 4 0\n2 1 1 1 1\n",
"output": "\nYES\nYES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 2 5 3 1\n3 0 0 0 0\n4 4 1 4 0\n2 1 1 1 1\n4 4 1 4 0\n"... |
code_contests | verifiable_code | 1517_A. Sum of 2050 | Solve the following coding problem using the programming language python:
A number is called 2050-number if it is 2050, 20500, ..., (2050 ⋅ 10^k for integer k ≥ 0).
Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers req... | ```python
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
def main():
# sys.stdin = open('input.txt', 'r')
#... | vfc_67633 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n205\n2050\n4100\n20500\n22550\n25308639900\n",
"output": "\n-1\n1\n2\n1\n2\n36\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "-1\n",
"type": "stdin_stdo... |
code_contests | verifiable_code | 1543_E. The Final Pursuit | Solve the following coding problem using the programming language python:
Finally, you have defeated Razor and now, you are the Most Wanted street racer. Sergeant Cross has sent the full police force after you in a deadly pursuit. Fortunately, you have found a hiding spot but you fear that Cross and his force will eve... | ```python
from collections import deque
from sys import stdin
import sys
tt = int(stdin.readline())
for loop in range(tt):
n = int(stdin.readline())
lis = [ [] for i in range(2**n)]
for i in range(n*(2**(n-1))):
u,v = map(int,stdin.readline().split())
lis[u].append(v)
lis[v].ap... | vfc_67637 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n0 1\n2\n0 1\n1 2\n2 3\n3 0\n3\n0 1\n0 5\n0 7\n1 2\n1 4\n2 5\n2 6\n3 5\n3 6\n3 7\n4 6\n4 7\n",
"output": "0 1\n0 0\n0 1 3 2\n0 0 1 1\n0 1 5 2 7 4 3 6\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 171_G. Mysterious numbers - 2 | Solve the following coding problem using the programming language python:
Input
The only line of input contains three integers a1, a2, a3 (1 ≤ a1, a2, a3 ≤ 20), separated by spaces.
Output
Output a single integer.
Examples
Input
2 3 2
Output
5
Input
13 14 1
Output
14
Input
14 5 9
Output
464
In... | ```python
f = [0] * 22
f[0], f[1], idx = [int(x) for x in input().split()]
for i in range (2, 22) : f[i] = f[i - 1] + f[i - 2]
print(f[idx])
``` | vfc_67641 | {
"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": "17 18 3\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 191_E. Thwarting Demonstrations | Solve the following coding problem using the programming language python:
It is dark times in Berland. Berlyand opposition, funded from a neighboring state, has organized a demonstration in Berland capital Bertown. Through the work of intelligence we know that the demonstrations are planned to last for k days.
Fortun... | vfc_67645 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 4 2\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.