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 | 1025_C. Plasticine zebra | Solve the following coding problem using the programming language python:
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plastici... | ```python
import sys
s = input()
n = len(s)
if n == 1:
print(1)
sys.exit(0)
for i in range(n-1):
if s[i] == s[i+1] and (s[n-1] != s[0]):
x = s[:i+1]
y = s[i+1:n]
s = x[::-1] + y[::-1]
ans = 1
mx = 1
for i in range(1, n):
if s[i] != s[i-1]:
mx += 1
else:
ans = max(mx, ans)
mx = 1
print(max(mx, ans)... | vfc_50469 | {
"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": "bwwwbwwbw\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1068_E. Multihedgehog | Solve the following coding problem using the programming language python:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and dec... | ```python
from collections import deque
n, k = list(map(int, input().split()))
G = [set() for _ in range(n + 1)]
q, nq = deque(), deque()
for _ in range(n - 1):
u, v = list(map(int, input().split()))
G[u].add(v)
G[v].add(u)
for u in range(1, n + 1):
if len(G[u]) == 1:
q.append(u)
step = 0
... | vfc_50477 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n1 3\n2 3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 2\n1 4\n2 4\n3 4\n4 13\n10 5\n11 5\n12 5\n14 5\n5 13\n6 7\n8 6\n13 6\n9 6\n",
"output": "Yes\n",
... |
code_contests | verifiable_code | 1090_D. Similar Arrays | Solve the following coding problem using the programming language python:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the ... | ```python
# SHRi GANESHA author: Kunal Verma #
import os
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from functools import reduce
from io import BytesIO, IOBase
from itertools import combinations
from math import gcd, inf, sqrt, ceil, floor
#sys.setrecursi... | vfc_50481 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2\n1 3\n2 4\n",
"output": "YES\n1 3 4 2 \n1 3 4 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 2\n",
"output": "YES\n1 3 2 \n1 3 1 ",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 110_A. Nearly Lucky Number | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all nu... | ```python
# your code goes here
n=int(input())
n=str(n)
k=0
for i in range(len(n)):
if int(n[i]) == 4 or int(n[i]) == 7:
k=k+1
if k==4 or k==7:
print('YES')
else:
print('NO')
``` | vfc_50485 | {
"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": "40047\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7747774\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1139_D. Steps to One | Solve the following coding problem using the programming language python:
Vivek initially has an empty array a and some integer constant m.
He performs the following algorithm:
1. Select a random integer x uniformly in range from 1 to m and append it to the end of a.
2. Compute the greatest common divisor of in... | ```python
import sys
factors = []
dp = []
mod = (int)(1e9+7)
inv_m = 0
def sub(a, b):
a -= b
a %= mod
if a < 0: a += mod
return a
def add(a, b): return (a + b) % mod
def mul(a, b): return (a * b) % mod
def pow(a, b):
if b == 0:
return 1
if b & 1:
return mul(a, pow(a, b - 1))
else:
aux = pow(a, b >> 1)... | vfc_50489 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "333333338\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1157_D. N Problems During K Days | Solve the following coding problem using the programming language python:
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k day... | ```python
"""
b[i] = a[i] - i - 1
b[i] <= b[i+1] < 2b[i] + i - 1
sum(b) == r
"""
def solve(n, k):
r = n - k*(k+1)//2
if r < 0:
return None
b0 = r//k
r -= b0*k
seq = [None]*k
seq[0] = b0
b = b0
for i in range(1,k):
bn = b*2 + i - 1
h = r//(k-i)
i... | vfc_50493 | {
"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": "9 4\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 117_A. Elevator | Solve the following coding problem using the programming language python:
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first t... | ```python
n, m = map(int, input().split())
k = 2 * (m - 1)
for i in range(n):
s, f, t = map(int, input().split())
d = t % k
if s < f: print(k * (s <= d) + f - 1 + t - d)
elif f < s: print(k * (d + s > k + 1) + k + 1 - f + t - d)
else: print(t)
``` | vfc_50497 | {
"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 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5\n",
"output": "12\n10\n10\n8\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0\n",
"outpu... |
code_contests | verifiable_code | 1198_B. Welfare State | Solve the following coding problem using the programming language python:
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services... | ```python
n = int(input())
a = list(map(int,input().split()))
mark=[1 for i in range(n)]
query = []
q = int(input())
m = -1
for i in range(q):
next = list(map(int,input().split()))
if next[0]==2:
m = max(m,next[1])
query.append(next)
mx = 0
for i in range(n):
if a[i]<m:
a[i]=m
for i in r... | vfc_50501 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1\n",
"output": "3 2 3 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20\n",
"output": "8 8 20 8 10 ",
"type":... |
code_contests | verifiable_code | 1215_A. Yellow Cards | Solve the following coding problem using the programming language python:
The final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a_1 players in the first team and a_2 players in the second team.
The rules ... | ```python
a1=int(input())
a2=int(input())
k1=int(input())
k2=int(input())
n=int(input())
m1=n - (k1-1)*a1 - (k2-1)*a2
if m1<0:
m1=0
m2=0
if a1*k1 + a2*k2 <=n:
m2=a1+a2
elif k1<=k2:
if n//k1 <= a1:
m2=n//k1
else:
m2=m2+a1
n=n-a1*k1
m2=m2 + min(a2, n//k2)
elif k2 < k1... | vfc_50505 | {
"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\n1\n6\n7\n25\n",
"output": "4 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n5\n1\n8\n",
"output": "0 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 1238_C. Standard Free2play | Solve the following coding problem using the programming language python:
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each height x from 1 to h.
Each platform is either hidd... | ```python
n= int(input())
for z in range(n):
h, am = map(int, input().split())
arr = list(map(int, input().split()))
ch = h
i = 1
ac = 0
while i < am:
if ch - arr[i] >= 2:
ch = arr[i] + 1
elif i < am - 1 and arr[i + 1] == ch - 2 or ch == 2:
ch -= 2
... | vfc_50509 | {
"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\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1\n",
"output": "0\n1\n2\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 2\n3 2\n",
"output": "1\n",
"type": "stdi... |
code_contests | verifiable_code | 127_D. Password | Solve the following coding problem using the programming language python:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the... | ```python
from sys import stdin
def findpass(s):
arr = suff_array(s)
n = len(s)
maxidx = arr[n - 1]
valid = False
for i in range(n - 1):
if arr[i] == maxidx:
valid = True
break
if not valid:
maxidx = arr[maxidx - 1]
if maxidx == 0:
return ... | vfc_50517 | {
"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": "abcdabc\n",
"output": "Just a legend",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "fixprefixsuffix\n",
"output": "fix",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 12_C. Fruits | Solve the following coding problem using the programming language python:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includ... | ```python
n, m = input().split(" ")
n = int(n)
m = int(m)
priceList = []
res = []
least = 0
most = 0
fruitCount = 0
seq = input().split(" ")
for i in seq:
priceList.append(int(i))
item = []
count = []
for i in range(m):
inp = input()
if inp in item:
count[item.index(inp)] += 1
else:
... | vfc_50521 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n4 2 1 10 5\napple\norange\nmango\n",
"output": "7 19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n",
"output": "1... |
code_contests | verifiable_code | 1427_C. The Hard Work of Paparazzi | Solve the following coding problem using the programming language python:
You are a paparazzi working in Manhattan.
Manhattan has r south-to-north streets, denoted by numbers 1, 2,…, r in order from west to east, and r west-to-east streets, denoted by numbers 1,2,…,r in order from south to north. Each of the r south-... | ```python
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
impo... | vfc_50545 | {
"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": "500 10\n69 477 122\n73 186 235\n341 101 145\n372 77 497\n390 117 440\n494 471 37\n522 300 498\n682 149 379\n821 486 359\n855 157 386\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1474_A. Puzzle From the Future | Solve the following coding problem using the programming language python:
In the 2022 year, Mike found two binary integers a and b of length n (both of them are written only by digits 0 and 1) that can have leading zeroes. In order not to forget them, he wanted to construct integer d in the following way:
* he cre... | ```python
for tc in range(int(input())):
n = int(input())
b = input()
a = ['' for i in range(n)]
d = ['0' for i in range(n)]
if b[0] == '0':d[0] = '1'
else:d[0] = '2'
for i in range(1,n):
if b[i] == '0':
if d[i-1] != '1':
d[i] = '1'
else:d[i] =... | vfc_50553 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n0\n3\n011\n3\n110\n6\n111000\n6\n001011\n",
"output": "\n1\n110\n100\n101101\n101110\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1\n0\n3\n011\n3\n110\n6\n111100\n6\n001011\n",... |
code_contests | verifiable_code | 149_C. Division into Teams | Solve the following coding problem using the programming language python:
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water th... | ```python
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# 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... | vfc_50557 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 3 3 1 1\n",
"output": "3\n4 1 3 \n2\n5 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "2\n1 2 \n1\n3 \n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 155_B. Combination | Solve the following coding problem using the programming language python:
Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his car... | ```python
n=int(input())
arr=[]
for i in range(n):
a,b=map(int,input().split())
arr.append((b,a))
arr.sort(reverse=True)
counter=1
ans=0
i=0
while(counter and i<n):
counter-=1
counter+=arr[i][0]
ans+=arr[i][1]
i+=1
print(ans)
``` | vfc_50565 | {
"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\n1 0\n2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 0\n2 0\n0 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 177_C2. Party | Solve the following coding problem using the programming language python:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Be... | ```python
from collections import defaultdict
def Root(child):
while(Parent[child]!=child):
child = Parent[child]
return child
def Union(a,b):
root_a = Root(a)
root_b = Root(b)
if(root_a!=root_b):
if(Size[root_a]<Size[root_b]):
Parent[root_a] = root_b
... | vfc_50569 | {
"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": "9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n8\n1 2\n1 3\n1 4\n1 5\n2 4\n2 5\n3 4\n5 6\n3\n2 6\n5 7\n6 7\n"... |
code_contests | verifiable_code | 198_C. Delivering Carcinogen | Solve the following coding problem using the programming language python:
Qwerty the Ranger arrived to the Diatar system with a very important task. He should deliver a special carcinogen for scientific research to planet Persephone. This is urgent, so Qwerty has to get to the planet as soon as possible. A lost day ma... | vfc_50573 | {
"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": "50 60 10\n50 60 20 40\n",
"output": "0.0000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 0 1\n-10 0 2 8\n",
"output": "9.5845441029\n",
"type": "stdin_stdout"
}... | |
code_contests | verifiable_code | 245_E. Mishap in Club | Solve the following coding problem using the programming language python:
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor en... | ```python
#Problem Set N: Collaborated with no one
n = input()
in_visit = 0
out_visit = 0
for i in range(len(n)):
if n[i] == '+':
in_visit += 1
if out_visit:
out_visit -= 1
elif n[i] == '-':
out_visit += 1
if in_visit:
in_visit -= 1
pr... | vfc_50581 | {
"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": "+-+-+\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "---",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "++\n",
... |
code_contests | verifiable_code | 270_C. Magical Boxes | Solve the following coding problem using the programming language python:
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equa... | ```python
from math import*
n = int(input())
v=0
for i in range(n):
a = [int(x)for x in input().split(' ')]
k = ceil(fabs(log(a[1],4)))
if k==0: k=1
if k+a[0]>v:
v = k+a[0]
print(v)
``` | vfc_50585 | {
"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\n0 3\n1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 10\n2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 293_E. Close Vertices | Solve the following coding problem using the programming language python:
You've got a weighted tree, consisting of n vertices. Each edge has a non-negative weight. The length of the path between any two vertices of the tree is the number of edges in the path. The weight of the path is the total weight of all edges it... | vfc_50589 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 6\n1 3\n1 4\n1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2 17\n1 3\n2 5\n2 13\n1 6\n5 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 317_C. Balance | Solve the following coding problem using the programming language python:
A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directio... | ```python
read = lambda: map(int, input().split())
n, v, e = read()
adj = [[] for _ in range(n + 1)]
As = [0] + list(read())
Bs = [0] + list(read())
ans = []
for _ in range(e):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
def flow(a, b, d):
As[a] -= d
As[b] += d
ans.appe... | vfc_50593 | {
"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 10 1\n1 9\n5 5\n1 2\n",
"output": "1\n2 1 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 10 0\n5 2\n4 2\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 341_C. Iahub and Permutations | Solve the following coding problem using the programming language python:
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotag... | ```python
#lahub and Permutations
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗)
res = 1
while p > 0:
if p % 2 == 0:
n = n ** 2 % mod
p //= 2
else:
res = res * n % mod
... | vfc_50597 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n-1 -1 4 3 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n-1 -1 -1 -1 -1 -1\n",
"output": "265\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 388_D. Fox and Perfect Sets | Solve the following coding problem using the programming language python:
Fox Ciel studies number theory.
She thinks a non-empty set S contains non-negative integers is perfect if and only if for any <image> (a can be equal to b), <image>. Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki... | ```python
from math import factorial
MOD = 10**9+7
k = int(input())
bink = list(map(int, bin(k)[2:]))
N = len(bink)
# dp[i][j][k] = first i bits, j bases,
# k = 1 if maxor matches k, 0 else
dp = [[[0,0] for j in range(i+2)] for i in range(N+1)]
dp[0][0][1] = 1
for i in range(1, N+1):
for j in range(i+1):
... | vfc_50605 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
... |
code_contests | verifiable_code | 409_B. Mysterious Language | Solve the following coding problem using the programming language python:
You are given a mysterious language (codenamed "Secret") available in "Custom Invocation" tab. Figure out what this language is and write a program which prints its name. Note that the program must be written in this language.
Input
This progr... | ```python
"""====================================================================================
====================================================================================
___ _______ ___ _______ ___ ___
| /\ | | \ | | / | | | | |\ /|
... | vfc_50609 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "INTERCAL\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "INTERCAL\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 436_C. Dungeons and Candies | Solve the following coding problem using the programming language python:
During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at ... | ```python
def put():
return map(int, input().split())
def diff(x,y):
ans = 0
for i in range(n*m):
if s[x][i]!= s[y][i]:
ans+=1
return ans
def find(i):
if i==p[i]:
return i
p[i] = find(p[i])
return p[i]
def union(i,j):
if rank[i]>rank[j]:
i,j = j,i
... | vfc_50613 | {
"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 1 4 1\nA\n.\nB\n.\n",
"output": "3\n1 0\n2 0\n4 2\n3 0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 459_D. Pashmak and Parmida's problem | Solve the following coding problem using the programming language python:
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence a that consists... | ```python
# 459D
import sys
from collections import Counter
class BIT():
def __init__(self, n):
self.n = n
self.tree = [0] * n
def _F(self, i):
return i & (i + 1)
def _getSum(self, r):
'''
sum on interval [0, r]
'''
result = 0
while ... | vfc_50617 | {
"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": "3\n1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 505_C. Mr. Kitayuta, the Treasure Hunter | Solve the following coding problem using the programming language python:
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems... | vfc_50625 | {
"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 10\n10\n21\n27\n27\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 529_B. Group Photo 2 (online mirror version) | Solve the following coding problem using the programming language python:
Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent ... | ```python
from operator import neg
n = int(input())
a = [tuple(map(int, input().split())) for i in range(n)]
def check(max_h):
k = n // 2
b = []
for w, h in a:
if h > max_h:
if k <= 0 or w > max_h:
return 1 << 60
b.append((h, w))
k -= 1
el... | vfc_50629 | {
"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\n10 1\n20 2\n30 3\n",
"output": "180\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 10\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 602_B. Approximating a Constant Range | Solve the following coding problem using the programming language python:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of conse... | ```python
n = int(input())
arr = list(map(int,input().split()))
d = {}
mx = 0
for c in arr:
nd = {}
nd[c-0.5] = d.get(c-0.5,0)+1
nd[c+0.5] = d.get(c+0.5,0)+1
mx = max(mx,nd[c-0.5],nd[c+0.5])
d = nd
print(mx)
``` | vfc_50641 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 3 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n5 4 5 5 6 7 8 8 8 7 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 624_E. Electric Charges | Solve the following coding problem using the programming language python:
Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals.
A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Instit... | vfc_50645 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 10\n1 20\n1 30\n",
"output": " 0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 64_B. Expression | Solve the following coding problem using the programming language python:
You are given a line «n#m», where «n» and «m» are digits, and «#» is a sign «+» or «-». Print the value of the given expression.
Input
The only given line has a string in form «n#m», where «n» and «m» are digits (from 0 to 9), and «#» is a sig... | vfc_50649 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1-5\n",
"output": "-4\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 673_B. Problems for Round | Solve the following coding problem using the programming language python:
There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems ... | ```python
n, m = map(int, input().split())
s1 = set()
s2 = set()
for _ in range(m):
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
if a in s2 or b in s1:
print(0)
exit(0)
s1.add(a)
s2.add(b)
if not s2:
s2.add(n)
s1.add(1)
print(max(0, min(s2) - max(s1)))
``` | vfc_50653 | {
"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 2\n3 1\n3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2\n2 3\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 719_C. Efim and Strange Grade | Solve the following coding problem using the programming language python:
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. E... | ```python
n, t = map(int, input().split())
tmp = input()
s = []
for i in range(n):
s.append(tmp[i])
ind = n
perenos = 0
for i in range(n):
if (s[i] == '.'):
nach = i + 1
for i in range(nach, n):
if (int(s[i]) > 4):
ind = i
break
if (ind == n):
print(*s, sep="")
exit()
while (... | vfc_50661 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\n10.245\n",
"output": "10.3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 100\n9.2\n",
"output": "9.2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 740_A. Alyona and copybooks | Solve the following coding problem using the programming language python:
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one c... | ```python
n, a, b, c = map(int, input().split())
h=n%4
if h==0:
d=0
else:
if h==1:
d=min(a*3,a+b,c)
if h==2:
d=min(a*2,b,c*2)
if h==3:
d=min(a,b+c,c*3)
print(d)
``` | vfc_50665 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999999 1000000000 1000000000 1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 763_E. Timofey and our friends animals | Solve the following coding problem using the programming language python:
After his birthday party, Timofey went to his favorite tree alley in a park. He wants to feed there his favorite birds — crows.
It's widely known that each tree is occupied by a single crow family. The trees in the alley form a row and are numb... | vfc_50669 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n3\n1 3\n2 3\n4 5\n5\n1 1\n1 2\n2 3\n1 3\n1 5\n",
"output": "1\n2\n1\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n7\n7 9\n3 4\n5 10\n1 5\n3 8\n4 8\n2 7\n10\n8 10\n6 9\n5... | |
code_contests | verifiable_code | 787_B. Not Afraid | Solve the following coding problem using the programming language python:
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are n parallel universes participating in this e... | ```python
def test(l):
l1=[]
l2=[]
for i in range(len(l)):
if l[i]<0 and l[i] not in l2:
l2.append(l[i])
elif l[i]>0 and l[i] not in l1:
l1.append(l[i])
if len(l1)==0 or len(l2)==0:
return False
for x in l1:
if (x*(-1)) in l2:
retur... | vfc_50673 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1 -3\n4 -2 3 2 -3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{... |
code_contests | verifiable_code | 808_F. Card Game | Solve the following coding problem using the programming language python:
Digital collectible card games have become very popular recently. So Vova decided to try one of these.
Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number ci and level li. Vova wants to build a... | vfc_50677 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 8\n5 5 1\n1 5 4\n4 6 3\n1 12 4\n3 12 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n4 4 1\n5 8 2\n5 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 833_B. The Bakery | Solve the following coding problem using the programming language python:
<image>
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so ... | ```python
import sys
from collections import defaultdict as di
range = range
input = raw_input
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the lazy segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
... | vfc_50681 | {
"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": "4 1\n1 2 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 3\n7 7 8 7 7 8 1 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 853_E. Lada Malina | Solve the following coding problem using the programming language python:
After long-term research and lots of experiments leading Megapolian automobile manufacturer «AutoVoz» released a brand new car model named «Lada Malina». One of the most impressive features of «Lada Malina» is its highly efficient environment-fr... | vfc_50685 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4 1\n1 1\n-1 1\n2 3 1\n2 -2 1\n-2 1 1\n-2 -2 1\n0 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 3\n2 0\n-1 1\n-1 -2\n-3 0 6\n1 -2 1\n-3 -7 3\n3 2 2\n-1 -4 1\n0... | |
code_contests | verifiable_code | 878_C. Tournament | Solve the following coding problem using the programming language python:
Recently a tournament in k kinds of sports has begun in Berland. Vasya wants to make money on the bets.
The scheme of the tournament is very mysterious and not fully disclosed. Competitions are held back to back, each of them involves two sport... | vfc_50689 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 5\n5 1\n10 10\n",
"output": "1\n2\n1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 901_E. Cyclic Cipher | Solve the following coding problem using the programming language python:
<image>
Senor Vorpal Kickass'o invented an innovative method to encrypt integer sequences of length n. To encrypt a sequence, one has to choose a secret sequence <image>, that acts as a key.
Vorpal is very selective, so the key should be such ... | vfc_50693 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n100\n81\n",
"output": "2\n91\n109\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n0\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 924_B. Three-level Laser | Solve the following coding problem using the programming language python:
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k a... | ```python
import heapq
from bisect import bisect_left, bisect_right
from collections import Counter
from collections import OrderedDict
from collections import deque
from itertools import accumulate, product
import math
R = lambda: map(int, input().split())
n, u= R()
arr = list(R())
res = -1
for l in range(n):
r... | vfc_50697 | {
"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 1\n2 5 10\n",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 952_D. I'm Feeling Lucky! | Solve the following coding problem using the programming language python:
<image>
You have one chip and one chance to play roulette. Are you feeling lucky?
Output
Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares).
The input will be given vi... | ```python
print("red")
``` | vfc_50701 | {
"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": "1\n",
"output": "red\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "red",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0\n",
... |
code_contests | verifiable_code | 97_A. Domino | Solve the following coding problem using the programming language python:
Little Gennady was presented with a set of domino for his birthday. The set consists of 28 different dominoes of size 2 × 1. Both halves of each domino contain one digit from 0 to 6.
0-0 0-1 0-2 0-3 0-4 0-5 0-6
1-1 1-2 1-3 1... | vfc_50705 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 8\n.aabbcc.\n.defghi.\nkdefghij\nklmnopqj\n.lmnopq.\n.rstuvw.\nxrstuvwy\nxzzAABBy\n",
"output": "10080\n.001122.\n.001122.\n33440055\n33440055\n.225566.\n.225566.\n66113344\n66113344\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 99_A. Help Far Away Kingdom | Solve the following coding problem using the programming language python:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon ... | ```python
import sys
import math
import itertools
import collections
def getdict(n):
d = {}
if type(n) is list or type(n) is str:
for i in n:
if i in d:
d[i] += 1
else:
d[i] = 1
else:
for i in range(n):
t = ii()
... | vfc_50709 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0.0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1.50\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1234567890... |
code_contests | verifiable_code | benny-and-subsets | Solve the following coding problem using the programming language python:
This problem is about a little pig named Benny. Benny was given an array of N integers and another separate integer X. Benny has to find the number of subsets (not necessarily contiguous) of A such that Bitwise XOR of all elements contained with... | ```python
MOD=10000007
N,X=map(int, raw_input().split())
nums={}
nums[0]=1
arrA=sorted(map(int, raw_input().split()))
for A in arrA:
old=nums.copy()
for num in old:
B=num^A
nums[B]=(old[num]+old[B])%MOD if B in old else old[num]
print nums[X] if X in nums else "0"
``` | vfc_50713 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n1 2 3 0 100500 100500\n\nSAMPLE",
"output": "8",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | complete-string-4 | Solve the following coding problem using the programming language python:
A string is said to be complete if it contains all the characters from a to z. Given a string, check if it complete or not.
Input
First line of the input contains the number of strings N. It is followed by N lines each contains a single string.... | ```python
mydict={}
for i,each in enumerate("abcdefghijklmnopqrstuvwxyz"):
mydict[each]=i
lettercount = int(raw_input())
for each in range(lettercount):
letters = raw_input()
isexists=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for each in letters:
isexists[mydict[each]]=1
if 0 in isexists:
prin... | vfc_50717 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nwyyga\nqwertyuioplkjhgfdsazxcvbnm\nejuxggfsts\n\nSAMPLE",
"output": "NO\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nkpfoprikyfnjhmeuppwkxzrslbvqgvoxoeqgkczupwhdttloiffx... |
code_contests | verifiable_code | file-statistics | Solve the following coding problem using the programming language python:
Write a command line tool which takes a file path as input and prints the number of lines, number of words, number of characters in the file, userid of the owner of the file, groupid of owner of the file and last modification time of the file in... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
name = raw_input()
if name == "/home/sample.txt":
print 1
print 2
print 13
print 1000
print 1000
print 1258001628
else:
print 19
print 402
print 2612
print 0
prin... | vfc_50721 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "/home/sample.txt\n\nSAMPLE",
"output": "1\n2\n13\n1000\n1000\n1258001628\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "/home/input",
"output": "19\n402\n2612\n0\n0\n1358021928\n",
... |
code_contests | verifiable_code | ikshu-and-his-machine-gun | Solve the following coding problem using the programming language python:
Ikshu and his machine gun
To celebrate his new year Ikshu went to play "beyond to beyond" (abbreviated as BOB) with his friends.
BOB can be described as follows :
It consists of Infinite boxes arranged one over another, Lowest box being 1.
Give... | ```python
n=input()
l=map(int,raw_input().split())
l.sort()
for i in range(n):
print l[i]-i,
``` | vfc_50725 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3\n\nSAMPLE",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1458\n20236 26944 32269 17862 17313 744 6901 129 5195 31557 9164 24417 15371 12971 24310 37061 37401 22245... |
code_contests | verifiable_code | mark-the-stairs-1 | Solve the following coding problem using the programming language python:
Rahul likes to play with mathematics and geometry and when it comes for 2D geometry, he just can’t stop himself doing experiments. While working with 2D geometry, he came up with an interesting pattern of numbers as shown below.
He started at t... | ```python
for _ in range(input()):
a, b = map(int, raw_input().split())[:2]
if a==b or a==b+2:
print (a+b-1) if b%2==1 else (a+b)
else:
print "No Number"
``` | vfc_50729 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 2\n6 6\n3 4\n\nSAMPLE",
"output": "6\n12\nNo Number\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n1 3\n4 6\n7 9\n2 3\n5 6\n8 9\n5 5\n46 46\n89 89\n96 96\n94 94\n79 97",
"o... |
code_contests | verifiable_code | number-of-chocolates | Solve the following coding problem using the programming language python:
Guri and Prary are good friends and are chocolate lovers. They win a lottery and get a chance to visit ChocoLand for few minutes.
In ChocoLand, there are N number of chocolate containers kept one next to other, one unit apart. Each of the conta... | ```python
n,m=map(int,raw_input().split())
a=[0]+map(int,raw_input().split())
for i in range(1,n+1):
a[i]+=a[i-1]
for i in range(m):
q,w=map(int,raw_input().split())
e,r=map(int,raw_input().split())
if e<q: e,q=q,e
if r<w: r,w=w,r
if r<q: print a[r+1]-a[w]+a[e+1]-a[q]
elif r<=e and w<=q: print a[e+1]-a[w]
elif ... | vfc_50733 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 2\n1 2 1 1 3 1 1\n1 4\n2 6\n0 2\n3 5\n\nSAMPLE",
"output": "8\n9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "646 2680\n1578 1821 6473 9387 9262 5227 5350 717 8842 7342 7636 5587 5917 6... |
code_contests | verifiable_code | rachels-exhibition-visit | Solve the following coding problem using the programming language python:
Rachel works at a big Raf Laurens. There is a big event coming up and she has to select dresses for an exhibition.
She has N dresses numbered 1 to N. There are total 62 types of dresses, each represented by a different alphanumeric character (a-... | ```python
for _ in xrange(int(raw_input())):
a = str(raw_input()).split()
N,K,L,R = map(int,a)
dress = str(raw_input())
sp = str(raw_input())
arr = [0]*N
cnt=0
for i in range(N):
if dress[i] in sp:
arr[i] = 1
for i in range(N):
s = arr[i]
if s>=L and s <=R:
cnt +=1
for j in range(i+1,N):
... | vfc_50737 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 3 3 4\nAbcAb\nAbZ\n9 2 1 2\nadebfgbhd\nab\n\nSAMPLE",
"output": "3\n33",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | shil-and-wave-seqeuncemonk | Solve the following coding problem using the programming language python:
Given a sequence A1 , A2 , A3 .. AN of length N . Find total number of wave subsequences having length greater than 1.
Wave subsequence of sequence A1 , A2 , A3 .. AN is defined as a set of integers i1 , i2 .. ik such that Ai1 < Ai2 > Ai3 < Ai... | ```python
def readLine(func):
return [func(v) for v in raw_input().strip().split(' ')]
(n) = readLine(int)
arr = readLine(int)
MAX = 100001
MOD = 10**9+7
constTree = [0] * (MAX)
lowTree = [0] * (MAX)
highTree = [0] * MAX
def update(tree, num, val):
while num < MAX:
tree[num] += val
tree[num]%... | vfc_50741 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 5 4 2\n\nSAMPLE",
"output": "17",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | the-punishment-3 | Solve the following coding problem using the programming language python:
Everyone has got to know that HELL and Printf{} use cheats while playing Counter-Strike 1.6. Everyone decides to give them a punishment.
They are going to be made to paint all the rooms of the ground floor of the hostel.
There are a total of N... | ```python
t=input()
while(t>0):
t-=1
n,k=[int(x) for x in raw_input().split()]
#x = int(input())
#y = int(input())
#n=input()
#k=input()
foo=(10**k-1)*(10**(n-k)-1)
print foo
``` | vfc_50745 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1\n3 2\n\nSAMPLE",
"output": "81\n891\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 1\n3 2",
"output": "81\n891\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | p02669 AtCoder Grand Contest 044 - Pay to Win | Solve the following coding problem using the programming language python:
You start with the number 0 and you want to reach the number N.
You can change the number, paying a certain amount of coins, with the following operations:
* Multiply the number by 2, paying A coins.
* Multiply the number by 3, paying B coins.... | ```python
from heapq import heapify, heappop, heappush
from collections import defaultdict
Inf = 10**28
inpl = lambda: list(map(int,input().split()))
T = int(input())
for _ in range(T):
N, A, B, C, D = inpl()
visited = defaultdict(lambda: Inf)
ans = Inf
pool = [(0,N)] # coin, number
while pool:
... | vfc_50753 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n11 1 2 4 8\n11 1 2 2 8\n32 10 8 5 4\n29384293847243 454353412 332423423 934923490 1\n900000000000000000 332423423 454353412 934923490 987654321",
"output": "20\n19\n26\n3821859835\n23441258666",
"type": "stdin_stdout... |
code_contests | verifiable_code | p00601 Dominating Set | Solve the following coding problem using the programming language python:
What you have in your hands is a map of Aizu-Wakamatsu City. The lines on this map represent streets and the dots are street corners. Lion Dor Company is going to build food stores at some street corners where people can go to buy food. It is un... | vfc_50805 | {
"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 4\n0 1\n0 4\n1 2\n3 4\n5 4\n0 1\n0 4\n1 2\n3 4\n0 0",
"output": "2\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n0 1\n0 4\n1 2\n1 4\n5 4\n0 1\n0 4\n1 2\n3 4\n0 0",
"output"... | |
code_contests | verifiable_code | p00877 Separate Points | Solve the following coding problem using the programming language python:
Numbers of black and white points are placed on a plane. Let's imagine that a straight line of infinite length is drawn on the plane. When the line does not meet any of the points, the line divides these points into two groups. If the division b... | ```python
def dot(c1, c2):
return c1.real * c2.real + c1.imag * c2.imag
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
def on_segment(p, a, b):
# whether p is on segment ab
v1 = a - p
v2 = b - p
return cross(v1, v2) == 0 and dot(v1, v2) < 0
def ccw(p0, p1, p2):
return cro... | vfc_50813 | {
"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 3\n100 700\n200 200\n600 600\n500 100\n500 300\n800 500\n3 3\n100 300\n400 600\n400 100\n600 400\n500 900\n300 300\n3 4\n300 300\n500 300\n400 600\n100 100\n200 900\n500 900\n800 100\n1 2\n300 300\n100 100\n500 500\n1 1\n100 100\... |
code_contests | verifiable_code | p01140 Square Route | Solve the following coding problem using the programming language python:
Square Route
Square root
English text is not available in this practice contest.
Millionaire Shinada, who has decided to build a new mansion, is wondering in which city to build the new mansion. To tell the truth, Mr. Shinada is a strange per... | ```python
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())
wh... | vfc_50821 | {
"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 3\n1\n1\n4\n2\n3\n1\n1 2\n10\n10\n10\n0 0",
"output": "6\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1\n1\n4\n2\n3\n1\n1 2\n10\n4\n10\n0 0",
"output": "6\n1\n",
"ty... |
code_contests | verifiable_code | p01279 Defend the Bases | Solve the following coding problem using the programming language python:
A country Gizevom is being under a sneak and fierce attack by their foe. They have to deploy one or more troops to every base immediately in order to defend their country. Otherwise their foe would take all the bases and declare "All your base a... | vfc_50825 | {
"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 2\n10 20 1\n0 10 1\n0 10\n10 0\n0 0",
"output": "14.14213562",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n10 20 1\n0 10 1\n0 10\n18 0\n0 0",
"output": "20.59126028197245\n",
... | |
code_contests | verifiable_code | p01449 Space-Time Sugoroku Road | Solve the following coding problem using the programming language python:
All space-time unified dimension sugoroku tournament. You are representing the Earth in the 21st century in the tournament, which decides only one Sugoroku absolute champion out of more than 500 trillion participants.
The challenge you are curr... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_50829 | {
"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": "11\n0\n0\n-2\n0\n-4\n1\n-1\n2\n0\n0\n0",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n0\n0\n7\n0\n2\n0\n0\n3\n-6\n-2\n1\n0",
"output": "1",
"type": "stdin_std... |
code_contests | verifiable_code | p01599 Train King | Solve the following coding problem using the programming language python:
Problem I: Train King
Roland has been given a mission of dangerous material transfer by Train King. The material is stored in the station A and subject to being transferred to the station B. He will bring it by direct trains between A and B, on... | vfc_50833 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n10 0 100\n10 200 300\n10 400 500\n10 600 700\n10 800 900\n10 100 200\n10 300 400\n10 500 600\n10 700 800\n10 900 1000",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\... | |
code_contests | verifiable_code | p01895 Fuda | Solve the following coding problem using the programming language python:
This issue is a reactive issue. It is necessary to create a program that derives the correct answer by interactively responding to the program prepared on the server side.
Example
Input
Output
The input will be given via stdin and the... | vfc_50841 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02032 Divisor Game | Solve the following coding problem using the programming language python:
C: Divisor Game
problem
tsutaj is trying to play about a few games.
In a divisor game, a natural number N of 2 or more is given first, and then the game progresses according to the following procedure.
* Declare one integer from the divisors... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
------------------------
author : iiou16
------------------------
'''
import copy
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
... | vfc_50845 | {
"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": "18",
"output": "2 5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02175 Strange Plants | Solve the following coding problem using the programming language python:
problem
A mysterious $ X $ [cm] plant grows in one place. This plant has the following mysterious properties.
* Say "nobiro" to this plant and it will grow $ A $ [cm].
* Say "tidime" to this plant and it will grow $ B $ [cm].
* If you say "kar... | ```python
X,A,B = map(int,input().split())
N = int(input())
S = [input() for i in range(N)]
for s in S:
if s=='nobiro':
X += A
elif s=='tidime':
X += B
else:
X = 0
if X < 0: X = 0
print(X)
``` | vfc_50849 | {
"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": "10 30 10\n3\nnobiro\nnobiro\ntidime",
"output": "80",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 30 10\n0\nnobiro\nnobiro\ntidime",
"output": "10\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | p02318 Edit Distance (Levenshtein Distance) | Solve the following coding problem using the programming language python:
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations:
* insertion: Insert a character at... | ```python
s1=input()
s2=input()
dist=[[0 for i in range(len(s1)+1)] for j in range(len(s2)+1)]
for i in range(len(s1)+1):
dist[0][i]=i
for i in range(len(s2)+1):
dist[i][0]=i
for i in range(1,len(s2)+1):
for j in range(1,len(s1)+1):
k=1
if s1[j-1]==s2[i-1]:k=0
dist[i][j]=min(dist[i-1... | vfc_50853 | {
"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": "icpc\nicpc",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "acac\nacm",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ic... |
code_contests | verifiable_code | binop | Solve the following coding problem using the programming language python:
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in th... | ```python
for i in range(int(raw_input())):
a = list(raw_input())
b = list(raw_input())
d = []
summ = 0
if len(list(set(a))) == 1:
print "Unlucky Chef"
else:
c = 0
for x in range(len(a)):
if a[x] != b[x]:
c = c + 1
d.append(int(a[x]))
l1 = d.count(1)
l0 = d.count(0)
if l1 >= l0:
summ... | vfc_50861 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n101\n010\n1111\n1010",
"output": "Lucky Chef\n2\nUnlucky Chef\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cnr | Solve the following coding problem using the programming language python:
Chef has a special affection for sets of binary strings of equal length which have same numbers of 1's. Given three integers n, k and m, your task is to find the the lexicographically m^th smallest string among strings which have length n and ... | ```python
from math import *
def nCr(n, k):
if ((k>n) or (k<0)):
return 0
if (k==0):
return 1
if (k==1):
return n
if (k==n):
return 1
return factorial(n)/(factorial(n-k)*factorial(k))
def solve(m, n, k):
global ans
if (n==0):
return
check = nCr(n-1, k)
if (m <= check):
ans += '0'
solve(m, n-1, ... | vfc_50865 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 2 2",
"output": "101\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 2 3",
"output": "110\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | frjump | Solve the following coding problem using the programming language python:
Chef likes to travel a lot. Every day Chef tries to visit as much cities as possible. Recently he had a quite a few trips of great Chefland for learning various recipes. Chefland had N cities numbered from 1 to N. People in Chefland are very fri... | ```python
import math
n = int(raw_input())
friendliness = map(int, raw_input().split())
logSum = [0]
prodSum = [0]
d = [[] for i in range(n)]
for r in range(1, n+1):
l = 0
p = 1
for j in range(r,n, r):
l += math.log10(friendliness[j])
p = (p*friendliness[j])%(10**9 + 7)
d[j].append(r)
logSum.append(l)
prod... | vfc_50869 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n3\n2 1\n1 3 10\n2 2",
"output": "1 120\n5 50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n3\n2 1\n1 3 7\n2 2",
"output": "1 120\n3 35\n",
"type": "... |
code_contests | verifiable_code | lpair | Solve the following coding problem using the programming language python:
Today is the reunion of all chefs in the world. Our Chef wants to make this moment more happier. He arranged a mass wedding in this reunion. For this, he made a strange stage and drew two horizontal parallel lines on the stage. There are N unmar... | ```python
"""
She's just like the first rays of sunshine,
after a stormy night.
"""
def update_tree(bit,index,val):
index += 1
while index < len(bit):
bit[index] += val
index += index & -index
return bit
def sum_till(bit,index):
index += 1
ans = 0
while index > 0:
ans += ... | vfc_50873 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3\n3 6\n5 4",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 12\n10 11\n11 9\n30 1",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | primpatt | Solve the following coding problem using the programming language python:
There is a very large field, colored white and divided into squares. There is a coordinate system attached to the field: y-axis goes from south to north and x-axis goes from west to east. Sides of the squares are parallel to the axes. There is a... | ```python
def millerRabin(n):
# Returns true if probable prime, false if composite
bases = [2,3,5,7,11,13,17,19,23]
nm1 = n-1
m = nm1
d = 0
if n in bases:
return True
if n < 2:
return False
while not m&1:
d += 1
m >>= 1
for a in bases:
done_for_base = False
b = ... | vfc_50877 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n0 0\n1 0\n1 1\n0 1\n3 3\n-3 -3\n-1 2\n0 -3",
"output": "1\n1\n0\n0\n1\n1\n2\n2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | tashift | Solve the following coding problem using the programming language python:
You are given two strings A and B of the same length. Each string contains N Lower case Latin character (from 'a' to 'z'). A shift operation will remove the first character of a string and add the same character at the end of that string. For ex... | ```python
'''
KMP algorithm
'''
# making the table
def border(s):
table={}
table[0]=-1
table[1]=0
n=len(s)
j=0
for i in range(2,n+1):
while s[i-1]!=s[j] and j!=-1:
j=table[j]
j+=1
table[i]=j
return table
#searching
n=input()
a=raw_input()
b=raw_input()... | vfc_50881 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nccadd\nbddcc",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nccade\nbddcc",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1011_B. Planning The Expedition | Solve the following coding problem using the programming language python:
Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant.
The warehouse has m daily food packages. Each package has some food type a_i.
Each participant must eat exactly one foo... | ```python
'''input
3 9
42 42 42 42 42 42 42 42 42
'''
from collections import Counter
n, m = map(int, input().split())
if n > m:
print(0)
quit()
a = list(map(int, input().split()))
d = 1
c = Counter(a).values()
while True:
s = sum([i//d for i in c])
if s >= n:
d += 1
else:
break
print(d - 1)
``` | vfc_50885 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 10\n1 5 2 1 1 1 2 5 7 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n5 4 3 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 1036_C. Classy Numbers | Solve the following coding problem using the programming language python:
Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not.
You are given a segment [L; R]. Count ... | ```python
def ncr(n, r):
return int(fact(n) / (fact(r)
* fact(n - r)))
# Returns factorial of n
def fact(n):
res = 1
for i in range(2, n + 1):
res = res * i
return res
def f(s):
j=0
ans=0
cnt=0
n=len(s)
while(j<n):
if int(s[j])!=0:
... | vfc_50889 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1000\n1024 1024\n65536 65536\n999999 1000001\n",
"output": " 1000\n 1\n ... |
code_contests | verifiable_code | 1059_B. Forgery | Solve the following coding problem using the programming language python:
Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an em... | ```python
import sys, math
n, m = map(int, sys.stdin.readline().split())
arr = [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ans = [['.'] * m for _ in range(n)]
dx = [0,1,0,-1,1,1,-1,-1]
dy = [1,0,-1,0,1,-1,1,-1]
for i in range(n):
for j in range(m):
cnt = 0
for k in range(8):
... | vfc_50893 | {
"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 3\n###\n###\n###\n###\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1080_D. Olya and magical square | Solve the following coding problem using the programming language python:
Recently, Olya received a magical square with the size of 2^n× 2^n.
It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations.
A Splitting operation is an operation during which Olya ... | ```python
t=int(input())
for _ in range(t):
n,k=list(map(int,input().split()))
if n>=32:
print("YES "+str(n-1))
else:
ans=-1
for i in range(1,n+1):
p=(4**i)-(2**(i+1))+1
p*=(((4**(n-i))-1)//3)
g=(((4**i)-1)//3)
p+=(((4**i)-1)//3)
g=(((4**i)-1)//3)-(((4**(i-1))-1)//3)
if g<=k and p>=k:
ans... | vfc_50897 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n2 2\n2 12\n",
"output": "YES 0\nYES 1\nNO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 10_C. Digital Root | Solve the following coding problem using the programming language python:
Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root ... | ```python
n, ans, a = int(input()), 0, [0] * 10
for i in range(1, n + 1):
ans -= int(n/i)
a[i % 9] += 1
for i in range(9):
for j in range(9):
ans += a[i] * a[j] * a[(i * j) % 9]
print(ans)
``` | vfc_50901 | {
"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": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "127\n",
... |
code_contests | verifiable_code | 1121_B. Mike and Children | Solve the following coding problem using the programming language python:
Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.
Mike has n sweets with sizes a_1, a_2, …... | ```python
n = int(input())
a = list(map(int,input().split()))
res = 10**6 * [0]
for j in range(0, n):
for h in range(j + 1, n):
res[a[j] + a[h]] += 1
print(max(res))
``` | vfc_50905 | {
"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\n3 1 7 11 9 2 12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1 8 3 11 4 9 2 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1148_D. Dirty Deeds Done Dirt Cheap | Solve the following coding problem using the programming language python:
You are given n pairs of integers (a_1, b_1), (a_2, b_2), …, (a_n, b_n). All of the integers in the pairs are distinct and are in the range from 1 to 2 ⋅ n inclusive.
Let's call a sequence of integers x_1, x_2, …, x_{2k} good if either
* x_... | ```python
import sys
input=sys.stdin.readline
n=int(input())
li=[]
for i in range(n):
li.append(list(map(int,input().split()))+[i+1])
li.sort(key=lambda x:x[0],reverse=True)
ans1=0
xx1=[]
for i in range(n):
if(li[i][1]>li[i][0]):
ans1+=1
xx1.append(li[i][2])
ans2=0
xx2=[]
for i in range(n):
... | vfc_50909 | {
"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": "3\n5 4\n3 2\n6 1\n",
"output": "3\n3 2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 7\n6 4\n2 10\n9 8\n3 5\n",
"output": "3\n3 1 5 ",
"type": "stdin_stdout"
}
]
... |
code_contests | verifiable_code | 116_A. Tram | Solve the following coding problem using the programming language python:
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Al... | ```python
n = int(input())
tram = []
current = []
curr = 0
for i in range(0, n):
tram.extend([int(x) for x in input().split()])
for i in range(0, 2*n, 2):
curr -= tram[i]
curr += tram[i+1]
current.append(curr)
print(max(current))
``` | vfc_50913 | {
"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\n0 3\n2 5\n4 2\n4 0\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1188_A1. Add on a Tree | Solve the following coding problem using the programming language python:
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.
You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 d... | ```python
n = int(input())
# n, k = map(int, input().split())
# a = [int(i) for i in input().split()]
d = [0 for i in range(n + 1)]
for i in range(n - 1):
a, b = map(int, input().split())
d[a] += 1; d[b] += 1
for val in d:
if val == 2:
print("NO")
exit()
print("YES")
``` | vfc_50917 | {
"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\n1 2\n2 3\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2\n1 3\n1 4\n2 5\n2 6\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 1207_A. There Are Two Types Of Burgers | Solve the following coding problem using the programming language python:
There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.
You have b buns, p beef pattie... | ```python
t = int(input())
for case in range(t):
profit = 0
buns, beef_patties, cutlets = [int(b) for b in input().split()]
beef_price, cutlet_price = [int(h) for h in input().split()]
possible_burgers = buns // 2
if beef_price >= cutlet_price:
if beef_patties > possible_burgers:
beef_patties = possible_bur... | vfc_50921 | {
"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\n15 2 3\n5 10\n7 5 2\n10 12\n1 100 100\n100 100\n",
"output": "40\n34\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n18 6 4\n3 4\n",
"output": "31\n",
"type": "stdin_s... |
code_contests | verifiable_code | 1249_D2. Too Many Segments (hard version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all... | ```python
import heapq
n,k = map(int,input().split())
llis = [ [] for i in range(2 * (10**5) + 1) ]
rlis = [ [] for i in range(2 * (10**5) + 1) ]
flag = [0] * (2 * (10**5) + 1)
for i in range(n):
l,r = map(int,input().split())
llis[l].append([i+1,r])
rlis[r].append([i+1,l])
now = 0
rq = []
ans = [... | vfc_50929 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n",
"output": "3\n4 1 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n",
"output": "3\n7 4 6 ",
... |
code_contests | verifiable_code | 1268_A. Long Beautiful Integer | Solve the following coding problem using the programming language python:
You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right.
Also, you are given a positive integer k < n.
Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, s... | ```python
'''input
3 2
354
'''
s=list(map(int,input().split()))
x,k=s[0],s[1]
s=input()
m=x-k
print(x)
if k<m:
abc=s[0:k]
p=(m//k)+1
abc=abc*p
abc=abc[0:m]
abd=abc[::-1]
abc=abc+abd[0:k][::-1]
if int(abc)>=int(s):
print(abc)
else:
abc=str(int(s[0:k])+1)
p=(m//k)+1
abc=abc*p
abc=abc[0:m]
abd=abc[::-1... | vfc_50933 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1234\n",
"output": "4\n1313\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n353\n",
"output": "3\n353\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1290_B. Irreducible Anagrams | Solve the following coding problem using the programming language python:
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram ... | ```python
s = input()
n = len(s)
# print(ord('b'))
# print("s: {}".format(s))
prefix_letter_occurence = [[0 for i in range(n+1)] for i in range(26)]
for i in range(1, n+1):
cur_letter = s[i-1]
for l in range(26):
prefix_letter_occurence[l][i] = prefix_letter_occurence[l][i-1] + int(l == ord(cur_letter) - 97)
# ... | vfc_50937 | {
"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": "aabbbbbbc\n6\n1 2\n2 4\n2 2\n1 9\n5 7\n3 5\n",
"output": "NO\nYES\nYES\nYES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaa\n3\n1 1\n2 4\n5 5\n",
"output": "YES\nNO\nYE... |
code_contests | verifiable_code | 1310_C. Au Pont Rouge | Solve the following coding problem using the programming language python:
VK just opened its second HQ in St. Petersburg! Side of its office building has a huge string s written on its side. This part of the office is supposed to be split into m meeting rooms in such way that meeting room walls are strictly between le... | vfc_50941 | {
"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": "19 5 1821\naupontrougevkoffice\n",
"output": "au",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 1\nabac\n",
"output": "aba",
"type": "stdin_stdout"
},
{
"fn_na... | |
code_contests | verifiable_code | 1333_A. Little Artem | Solve the following coding problem using the programming language python:
Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.
Artem wants to paint an n × m board. Each cell of the board should be colored in white or black.
Let... | ```python
case = int(input())
for i in range(case):
a = list(map(int, input().rstrip().split()))
column = a[1]
row = a[0]
l = [["W"] * a[1] for _ in range(a[0])]
b = ((a[1] * a[0]) // 2)+1
w = b - 1
x = 0
y = 0
while (b > 0 and y < row):
l[y][x] = "B"
x += 2
i... | vfc_50945 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2\n3 3\n",
"output": "WB\nBB\nBB\nWBB\nBBB\nBBB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 2\n3 3\n",
"output": "WB\nBB\nBB\nWBB\nBBB\nBBB\n",
"type": "stdin_std... |
code_contests | verifiable_code | 1373_C. Pluses and Minuses | Solve the following coding problem using the programming language python:
You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode:
res = 0
for init = 0 to inf
cur = init
... | ```python
for _ in range(int(input())):
arr=list(input())
n=len(arr)
fix=1;mis=0;plus=0
ans=0
for i in range(n):
if(arr[i]=="-"):
if(plus>0):
plus-=1
continue
else:
ans+=(i+1)
if(arr[i]=="+"):
plus+=1... | vfc_50953 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n--+-\n---\n++--+-\n",
"output": "7\n9\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15\n-\n--\n+\n+-\n-\n+\n-\n+\n-\n-+\n-+\n-+\n-+\n-+\n-+\n",
"output": "2\n5\n1\n2\n2\n1\n2... |
code_contests | verifiable_code | 1396_B. Stoned Game | Solve the following coding problem using the programming language python:
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single ... | ```python
def win(a, last = -1):
for i, el in enumerate(a):
a2 = a[:]
a2[i] -= 1
if i != last and el > 0 and not win(a2, i):
return True
return False
def solve(a):
s = sum(a)
for i in a:
if i > s - i:
return True
return s % 2 == 1
for t in ra... | vfc_50957 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n2\n1 1\n",
"output": "T\nHL\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1 13\n",
"output": "T\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 141_D. Take-off Ramps | Solve the following coding problem using the programming language python:
Vasya participates in a ski race along the X axis. The start is at point 0, and the finish is at L, that is, at a distance L meters from the start in the positive direction of the axis. Vasya has been training so hard that he can run one meter i... | ```python
from heapq import *
n, L = [int(i) for i in input().split()]
dots = [0, L]
tr, ind = {}, {}
for i in range(n):
x, d, t, p = [int(i) for i in input().split()]
if x - p < 0 or t >= d:
continue
tr.setdefault(x - p, [])
tr[x - p].append((x + d, p + t, i))
dots.append(x - p)
dot... | vfc_50961 | {
"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 20\n9 8 12 6\n15 5 1 1\n",
"output": "16\n1\n2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 20\n5 10 5 5\n4 16 1 7\n",
"output": "15\n1\n1 ",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 1438_D. Powerful Ksenia | Solve the following coding problem using the programming language python:
Ksenia has an array a consisting of n positive integers a_1, a_2, …, a_n.
In one operation she can do the following:
* choose three distinct indices i, j, k, and then
* change all of a_i, a_j, a_k to a_i ⊕ a_j ⊕ a_k simultaneously, wher... | ```python
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import random
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Su... | vfc_50965 | {
"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\n4 2 1 7 2\n",
"output": "YES\n4\n1 2 3\n3 4 5\n1 2 5\n3 4 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10 4 49 22\n",
"output": "NO\n",
"type": "stdin_stdout"
},... |
code_contests | verifiable_code | 148_C. Terse princess | Solve the following coding problem using the programming language python:
«Next please», — the princess called and cast an estimating glance at the next groom.
The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she... | ```python
n,ohh,wow= list(map(int , input().split()))
if(wow==0):
if(n>=ohh+2):
print(1,end=" ")
print(1,end=" ")
for i in range(1,ohh+1):
print(i+1,end=" ")
for i in range(n-ohh-2):
print(ohh+1,end=" ")
elif(ohh==0):
for i in range(n):
... | vfc_50973 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 2 3\n",
"output": "1 2 4 8 9 10 1 1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0 0\n",
"output": "1 1 1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 1512_A. Spy Detected! | Solve the following coding problem using the programming language python:
You are given an array a consisting of n (n ≥ 3) positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array [4, 11, 4, 4] all numbers except one are equal to 4).
Print the index of the ... | ```python
t=int(input())
for i in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
my_list=[]
my_list1=[]
for j in range(len(arr)):
c_count=arr.count(arr[j])
my_list.append(arr[j])
my_list1.append(c_count)
mid= min(my_list1)
req=(my_list1.index(mid))
req1=my_list[req]
for k in range(len(arr... | vfc_50977 | {
"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\n4\n11 13 11 11\n5\n1 4 4 4 4\n10\n3 3 3 3 10 3 3 3 3 3\n3\n20 20 10\n",
"output": "\n2\n1\n5\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n5 6 6\n3\n7 7 6\n",
"output":... |
code_contests | verifiable_code | 1539_E. Game with Cards | Solve the following coding problem using the programming language python:
The Alice's computer is broken, so she can't play her favorite card game now. To help Alice, Bob wants to answer n her questions.
Initially, Bob holds one card with number 0 in the left hand and one in the right hand. In the i-th question, Ali... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
K, A0, B0, A1, B1 = [], [], [], [], []
for _ in range(n):
k = int(input())
a0, b0 = map(int, input().split())
a1, b1 = map(int, input().split())
K.append(k)
A0.append(a0)
B0.append(b0)
A1.append(a1)
B1.appe... | vfc_50981 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 10\n3\n0 3\n0 3\n7\n4 7\n1 3\n2\n2 3\n3 7\n8\n1 8\n1 8\n6\n1 6\n7 10\n",
"output": "Yes\n1 0 0 1 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 10\n3\n0 3\n0 2\n2\n3 4\n0 1\n",
... |
code_contests | verifiable_code | 166_B. Polygons | Solve the following coding problem using the programming language python:
You've got another geometrical task. You are given two non-degenerate polygons A and B as vertex coordinates. Polygon A is strictly convex. Polygon B is an arbitrary polygon without any self-intersections and self-touches. The vertices of both p... | ```python
def convex_hull(points):
points = sorted(set(points))
if len(points) <= 1:
return points
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
lower = []
for p in points:
while len(lower) >= 2 and cross(lower[-2], lower[-1], p) ... | vfc_50985 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1\n",
... |
code_contests | verifiable_code | 208_A. Dubstep | Solve the following coding problem using the programming language python:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number o... | ```python
word = input()
word = str.replace(word,'WUB',' ')
list1 = word.split()
print(' '.join(list1))
``` | vfc_50993 | {
"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": "WUBWUBABCWUB\n",
"output": "ABC\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n",
"output": "WE ARE THE CHAMPIONS MY FRIEND\n",
... |
code_contests | verifiable_code | 233_D. Table | Solve the following coding problem using the programming language python:
John Doe has an n × m table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size n × n have exactly k points.
John Doe wondered, ho... | ```python
n,m,k=map(int,input().split())
M=int(1e9+7)
N=n*n
iv=[0]*(N+1)
iv[1]=1
for i in range(2, N+1):
iv[i]=M-M//i*iv[M%i]%M
f1=[1]*(N+1)
for i in range(1, N+1):
f1[i]=f1[i-1]*i%M
f2=[1]*(N+1)
for i in range(1, N+1):
f2[i]=f2[i-1]*iv[i]%M
left=m%n
#m/n+1, m/n
def powM(b, p):
r=1
while p>0:
... | vfc_50997 | {
"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 6 1\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 703528038 1\n",
"output": "322849207\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 259_C. Little Elephant and Bits | Solve the following coding problem using the programming language python:
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from n... | ```python
s=list(input())
for i in range(len(s)):
if s[i]=='0':
break
del(s[i])
print("".join(s))
``` | vfc_51001 | {
"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": "101\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 282_C. XOR and OR | Solve the following coding problem using the programming language python:
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor o... | ```python
def helper(a,b):
n=len(a)
m=len(b)
if n!=m:
return 'NO'
if a==b:
return 'YES'
if a=='0'*n or b=='0'*m:
return'NO'
return 'YES'
a=input()
b=input()
print(helper(a,b))
``` | vfc_51005 | {
"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\n01\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n10\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 305_B. Continued Fractions | Solve the following coding problem using the programming language python:
A continued fraction of height n is a fraction of form <image>. You are given two rational numbers, one is represented as <image> and the other one is represented as a finite fraction of height n. Check if they are equal.
Input
The first line ... | ```python
#import math
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
p, q = map(int, input().split())
n = int(input())
data = list(map(int, input().split()))
a = 1
b = data[-1]
for i in range(2, n + 1):
a = b * data[n - i] + a
a, b = b, a
a, b = b, a
nod = gcd(p, q)
p = p // nod
... | vfc_51009 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 4\n3\n1 2 4\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 4\n3\n2 3 1\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.