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 | introsrm | Solve the following coding problem using the programming language python:
Problem description.
This problem deals with the I/O methods used in codechef. You are supposed to print the integer in its reverse form , or in simple words, print the reverse of the given integer . For instance , reverse of 120 is 21 (not 02... | ```python
# cook your code here
n=input()
for i in range(n):
x=raw_input()
print long(x[::-1])
``` | vfc_65021 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1234\n4567\n1",
"output": "4321\n7654\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1234\n4567\n2",
"output": "4321\n7654\n2\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | nmagic | Solve the following coding problem using the programming language python:
Alice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given numbe... | ```python
t=int(input())
while t>0:
t-=1
s=raw_input()
l=len(s)
loc=-1
for i in range(l-1,-1,-1):
if s[i]=='4':
loc=i
break
if loc==-1:
s='4'+s.replace('7','4')
else:
s=s[:loc]+'7'+s[loc+1:].replace('7','4')
print s
``` | vfc_65025 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n47",
"output": "7\n74",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n20",
"output": "7\n420\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 1003_A. Polycarp's Pockets | Solve the following coding problem using the programming language python:
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represente... | ```python
n = int(input())
mn = list(map(int, input().split()))
k = 1
for i in range(1, 101):
s = mn.count(i)
if s > k:
k = s
print(k)
``` | vfc_65033 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 2 4 3 3 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 1027_B. Numbers on the Chessboard | Solve the following coding problem using the programming language python:
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to ... | ```python
import sys
n,q=map(int,sys.stdin.readline().strip().split())
nc=n
# print(n,q)
if(n%2==0):
n2=int((n*n)/2)
else:
n2=int((n*n)/2)+1
n1=int(n/2)
if(1==1):
for i in range(q):
x,y=map(int,sys.stdin.readline().strip().split())
# print(n,q,x,y)
x1=int(x/2)
y1=int(... | vfc_65037 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n2 1\n4 2\n3 3\n3 4\n",
"output": "16\n9\n7\n20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n1 1\n4 4\n4 3\n3 2\n2 4\n",
"output": "1\n8\n16\n13\n4\n",
"type": "std... |
code_contests | verifiable_code | 1046_A. AI robots | Solve the following coding problem using the programming language python:
In the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three numbers: position (x_i), radius of sig... | vfc_65041 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n3 6 1\n7 3 10\n10 5 8\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 106_E. Space Rescuers | Solve the following coding problem using the programming language python:
The Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All y... | vfc_65045 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 0 0\n-5 0 0\n0 3 4\n4 -3 0\n2 2 -2\n",
"output": "-0.0000000666 0.0000000000 0.0000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-2 5 7\n5 9 1\n-4 6 -2\n",
"output":... | |
code_contests | verifiable_code | 1091_D. New Year and the Permutation Concatenation | Solve the following coding problem using the programming language python:
Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence p. For example, if n = 3, then p = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]. The length of this se... | ```python
n = int(input())
f_n = n
cnt = 0
for k in range(n-1, 0, -1):
cnt += f_n
f_n *= k
if f_n >= 998244353:
f_n %= 998244353
print((n*f_n-cnt)%998244353)
``` | vfc_65049 | {
"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": " 56",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1110_B. Tape | Solve the following coding problem using the programming language python:
You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired.
You have an infinitely long repair tape. You want to cut some pieces from the ta... | ```python
n, m, k = (int(x) for x in input().split())
b = [int(x) for x in input().split()]
deltaB = sorted([b[i + 1] - b[i] for i in range(n - 1)])
print(sum(deltaB[:n - k]) + k)
``` | vfc_65053 | {
"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 100 2\n20 30 75 80\n",
"output": "17",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 100 3\n1 2 4 60 87\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1158_C. Permutation recovery | Solve the following coding problem using the programming language python:
Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is e... | ```python
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n = int(input())
l = list(map(int, input().split()))
stack = []
out = [-1] * n
curr = 0
works = True
for i in range(n):
while stack and stack[-1][0] == i:
_, j = stack.pop()
... | vfc_65061 | {
"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\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n",
"output": "1 2 3 \n2 1 \n1 2 3 \n-1\n1 \n3 1 2 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3\n2 3 4\n2\n3 3\n3\... |
code_contests | verifiable_code | 1180_B. Nick and Array | Solve the following coding problem using the programming language python:
Nick had received an awesome array of integers a=[a_1, a_2, ..., a_n] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a_1 ⋅ a_... | ```python
n=int(input())
list1=[*map(int,input().split())]
list2=[]
if n%2==0:
for element in list1:
if element>=0:
print(-element-1)
else:
print(element)
else:
for element in list1:
if element>=0:
list2.append(-element-1)
else:
lis... | vfc_65065 | {
"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\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 2 2 2\n",
"output": "-3 -3 -3 -3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1199_B. Water Lily | Solve the following coding problem using the programming language python:
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance ... | ```python
import math
h, l = input().split()
h = int(h)
l = int(l)
a = float((pow(l,2)-pow(h,2))/(2*h))
print(a)
``` | vfc_65069 | {
"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 5\n",
"output": "2.6666666666667\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n",
"output": "1.5000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1216_A. Prefixes | Solve the following coding problem using the programming language python:
Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n.
He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a... | ```python
l = int(input())
s = list(input().strip())
ct = 0
for i in range(0,l-1,2):
if s[i] == s[i+1]:
ct += 1
if s[i] == 'a':
s[i] = 'b'
else:
s[i] = 'a'
print(ct)
print(''.join(s))
``` | vfc_65073 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nababab\n",
"output": "0\nababab",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nbbbb\n",
"output": "2\nabab",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1239_B. The World Is Just a Programming Task (Hard Version) | Solve the following coding problem using the programming language python:
This is a harder version of the problem. In this version, n ≤ 300 000.
Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gift... | ```python
def get_bal():
bal = [0] * n
bal[0] = u[0]
for i in range(1, n):
bal[i] = bal[i - 1] + u[i]
min_b = min(bal)
ans = 0
for i in range(n):
if bal[i] == min_b:
ans += 1
return ans
n = int(input())
u = list(input())
for i in range(n):
if u[i] == '(':
... | vfc_65077 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n)))(()\n",
"output": "0\n1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n()()())(()\n",
"output": "5\n8 7",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1257_D. Yet Another Monster Killing Problem | Solve the following coding problem using the programming language python:
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes cle... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write i... | vfc_65081 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n2 3 11 14 1 8\n2\n3 2\n100 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n",
"output": "5\n-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1280_E. Kirchhoff's Current Loss | Solve the following coding problem using the programming language python:
Your friend Kirchhoff is shocked with the current state of electronics design.
"Ohmygosh! Watt is wrong with the field? All these circuits are inefficient! There's so much capacity for improvement. The electrical engineers must not conduct thei... | vfc_65085 | {
"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\n5 *\n1 (* S *)\n1 (* P (* S *))\n",
"output": "REVOLTING 5\nREVOLTING 1 0\nREVOLTING 2 2 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 *\n1 (* S *)\n1 (* P (* S *))\n",
"... | |
code_contests | verifiable_code | 1300_D. Aerodynamic | Solve the following coding problem using the programming language python:
Guy-Manuel and Thomas are going to build a polygon spaceship.
You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P b... | ```python
import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1/0
def write(*args, sep="\n"):
for i in... | vfc_65089 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 0\n4 1\n3 4\n0 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n0 0\n1 0\n2 1\n3 3\n4 6\n3 6\n2 5\n1 3\n",
"output": "YES\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 1324_E. Sleeping Schedule | Solve the following coding problem using the programming language python:
Vova had a pretty weird sleeping schedule. There are h hours in a day. Vova will sleep exactly n times. The i-th time he will sleep exactly after a_i hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of th... | ```python
def indices(arr):
ind = []
for i, val in enumerate(arr):
if val >= 0:
ind.append(i)
return ind
def e(hours, mem, lo, hi, hour_day):
for i in range(len(hours)): # for each day
non_zero = indices(mem[i])
for v in non_zero:
next_hour = (v + hour... | vfc_65093 | {
"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": "7 24 21 23\n16 17 14 20 20 11 22\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "62 51 43 50\n40 36 14 6 44 12 23 23 50 37 15 14 21 16 6 9 40 21 20 11 21 6 34 50 40 43 44 ... |
code_contests | verifiable_code | 1343_D. Constant Palindrome Sum | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All a_i does not exceed some integer k.
Your task is to replace the minimum number of elements (replacement is the following operation: ch... | ```python
from bisect import bisect_left
from collections import Counter
def solve(n, k, a):
s = [a[i] + a[n-i-1] for i in range(n//2)]
amin = sorted([min(a[i], a[n-i-1]) for i in range(n//2)])
amax = sorted([max(a[i], a[n-i-1]) for i in range(n//2)])
ans = float('inf')
counter = Counter... | vfc_65097 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4\n",
"output": "0\n1\n4\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100\n86 366 161 188 28 209 450 355 100 24... |
code_contests | verifiable_code | 1365_E. Maximum Subsequence Value | Solve the following coding problem using the programming language python:
Ridhiman challenged Ashish to find the maximum valued subsequence of an array a of size n consisting of positive integers.
The value of a non-empty subsequence of k elements of a is defined as ∑ 2^i over all integers i ≥ 0 such that at least m... | ```python
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
for j in range(i,n):
for k in range(j,n):ans = max(ans,l[i] | l[j] | l[k])
print(ans)
``` | vfc_65101 | {
"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\n3 1 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n7 7 1 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 1385_E. Directing Edges | Solve the following coding problem using the programming language python:
You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some dire... | ```python
from sys import stdin, gettrace
from collections import deque
if gettrace():
inputi = input
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def solve():
n,m = map(int, inputi().split())
dadjs = [[] for _ in range(n)]
dadjd = ... | vfc_65105 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 1\n0 1 3\n5 5\n0 2 1\n1 1 5\n1 5 4\n0 5 2\n1 3 5\n4 5\n1 1 2\n0 4 3\n1 3 1\n0 2 3\n1 2 4\n4 5\n1 4 1\n1 1 3\n0 1 2\n1 2 4\n1 3 2\n",
"output": "YES\n3 1\nYES\n2 1\n1 5\n5 4\n2 5\n3 5\nYES\n1 2\n3 4\n3 1\n3 2\n2 4\nNO\n",... |
code_contests | verifiable_code | 1407_C. Chocolate Bunny | Solve the following coding problem using the programming language python:
This is an interactive problem.
We hid from you a permutation p of length n, consisting of the elements from 1 to n. You want to guess it. To do that, you can give us 2 different indices i and j, and we will reply with p_{i} mod p_{j} (remainde... | ```python
import sys
DEBUG = False
def debug(*args):
if not DEBUG:
return
print("\033[0;31m", end="", file=sys.stderr)
print(*args, file=sys.stderr)
print("\033[0m", end="", file=sys.stderr)
sys.stderr.flush()
def readInt():
line = input()
while line == "":
line = input(... | vfc_65109 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n\n1\n\n2\n\n1\n\n0",
"output": "? 1 2\n? 2 1\n? 1 3\n? 3 1\n! 1 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n4 8 2 6 3 1 5 7\n",
"output": "? 1 2\n? 2 1\n? 1 3\n? 3 1\n? ... |
code_contests | verifiable_code | 1451_A. Subtract or Divide | Solve the following coding problem using the programming language python:
Ridbit starts with an integer n.
In one move, he can perform one of the following operations:
* divide n by one of its proper divisors, or
* subtract 1 from n if n is greater than 1.
A proper divisor is a divisor of a number, excludi... | ```python
for _ in range(int(input())):
k = 3
n = int(input())
if n == 1:
print("0")
elif n == 2:
print("1")
elif n == 3:
print("2")
elif n%2==0:
print("2")
else:
print("3")
``` | vfc_65117 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1\n2\n3\n4\n6\n9\n",
"output": "\n0\n1\n2\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1\n2\n3\n4\n6\n16\n",
"output": "0\n1\n2\n2\n2\n2\n",
"type": "stdin_st... |
code_contests | verifiable_code | 1475_A. Odd Divisor | Solve the following coding problem using the programming language python:
You are given an integer n. Check if n has an odd divisor, greater than one (does there exist such a number x (x > 1) that n is divisible by x and x is odd).
For example, if n=6, then there is x=3. If n=4, then such a number does not exist.
In... | ```python
test_cases = 1
test_cases = int(input())
for ttttt in range(test_cases):
n = int(input())
while n%2==0:
n/=2
if n==1:
print("NO")
else:
print("YES")
``` | vfc_65121 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2\n3\n4\n5\n998244353\n1099511627776\n",
"output": "\nNO\nYES\nNO\nYES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4\n4\n4\n147862179\n",
"output": "NO\nNO\nNO\nYE... |
code_contests | verifiable_code | 1525_A. Potion-making | Solve the following coding problem using the programming language python:
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one s... | ```python
import math
for i in range(int(input())):
n=int(input())
a=100-n
b=n
if n==100:
print(1)
else:
g=math.gcd(a,b)
print(a//g+b//g)
``` | vfc_65129 | {
"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\n3\n100\n25\n",
"output": "\n100\n1\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3... |
code_contests | verifiable_code | 156_C. Cipher | Solve the following coding problem using the programming language python:
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't... | ```python
S, N = 2501, 101
m = 1000000007
k = 26
p = [[0] * (S + k) for i in range(N)]
p[0][0] = 1
for n in range(1, N):
for s in range(S):
p[n][s] = (p[n][s - 1] + p[n - 1][s] - p[n - 1][s - k]) % m
r = []
for j in range(int(input())):
t = input()
s = sum(ord(q) - 97 for q in t)
print(p[len(t)]... | vfc_65133 | {
"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\naaaaaaaaaaa\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nab\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 177_F2. Script Generation | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series.
There are n single men and n sing... | vfc_65137 | {
"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": "2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n",
"output": "8",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 199_D. Jumping on Walls | Solve the following coding problem using the programming language python:
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas ... | ```python
from collections import deque
l, j = [int(i) for i in input().split(' ')]
wallA = list(input())
wallB = list(input())
g = {}
for i in range(l):
# Each 4-tuple represents: (Visited?, Current Height, Current Water Height, Drowned?)
if wallA[i] == '-':
g[(1,i+1)] = (-1, 0, 0, False)
if wal... | vfc_65141 | {
"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": "6 2\n--X-X-\nX--XX-\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\n---X--X\n-X--XX-\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 222_E. Decoding Genome | Solve the following coding problem using the programming language python:
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special cha... | ```python
import sys
def pyes_no(condition) :
if condition :
print ("YES")
else :
print ("NO")
def plist(a, s = ' ') :
print (s.join(map(str, a)))
def rint() :
return int(sys.stdin.readline())
def rints() :
return map(int, sys.stdin.readline().split())
def rfield(n, m = None) :
if m == None :
... | vfc_65145 | {
"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 3 0\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\naa\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 246_C. Beauty Pageant | Solve the following coding problem using the programming language python:
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion... | ```python
n, k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
t = [[i] for i in p]
for i in range(1, n):
t += [t[-1] + i for i in t[: n - i]]
print('\n'.join(str(len(i)) + ' ' + ' '.join(map(str, i)) for i in t[: k]))
``` | vfc_65149 | {
"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 1\n7 12\n",
"output": "1 7 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2 3\n",
"output": "1 1 \n1 2 \n1 3 \n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 318_D. Ants | Solve the following coding problem using the programming language python:
It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and... | vfc_65161 | {
"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": "6 5\n0 -2\n0 -1\n0 0\n0 1\n0 2\n",
"output": "0\n1\n2\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n0 1\n0 0\n0 -1\n",
"output": "0\n1\n0\n",
"type": "stdin_stdout... | |
code_contests | verifiable_code | 342_D. Xenia and Dominoes | Solve the following coding problem using the programming language python:
Xenia likes puzzles very much. She is especially fond of the puzzles that consist of domino pieces. Look at the picture that shows one of such puzzles.
<image>
A puzzle is a 3 × n table with forbidden cells (black squares) containing dominoes ... | ```python
def main():
l = int(raw_input())
m = [raw_input().strip() for _ in range(3)]
dp = [1] * 1 + [0] * 15
mod = 10 ** 9 + 7
y = [1, 2, 4]
for i, col in enumerate(zip(*m)):
ndp = [0] * 16
r = sum([q for c, q in zip(col, y) if c != '.'])
for j in xrange(16):
... | vfc_65165 | {
"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\n.....\n.O...\n.....\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n...\n...\n..O\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 389_E. Fox and Card Game | Solve the following coding problem using the programming language python:
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top ... | ```python
n = int(input())
lista = []
aux = []
somaA = 0
somaB = 0
for i in range(n):
a = [int(i) for i in input().split()][1:]
if len(a) > 1:
somaA += sum(a[0:len(a)//2])
somaB += sum(a[-(len(a)//2):])
if len(a) % 2 == 1:
aux.append(a[len(a)//2])
aux.sort(reverse=True)
for i... | vfc_65173 | {
"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\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n",
"output": "7000 7000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 409_H. A + B Strikes Back | Solve the following coding problem using the programming language python:
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
Input
The input contains two integ... | ```python
import sys
import os
a,b=input().split()
a=int(a)
b=int(b)
print(a+b)
``` | vfc_65177 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "381 492\n",
"output": "873\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 437_C. The Child and Toy | Solve the following coding problem using the programming language python:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by a... | ```python
def mlt(): return map(int, input().split())
x, y = mlt()
s = [0] + list(mlt())
res = 0
for n in range(y):
a, b = mlt()
res += min(s[a], s[b])
print(res)
``` | vfc_65181 | {
"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 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"output": "400",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 45_E. Director | Solve the following coding problem using the programming language python:
Vasya is a born Berland film director, he is currently working on a new blockbuster, "The Unexpected". Vasya knows from his own experience how important it is to choose the main characters' names and surnames wisely. He made up a list of n names... | vfc_65185 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nAnn\nAnna\nSabrina\nJohn\nPetrov\nIvanova\nStoltz\nAbacaba\n",
"output": "Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nAa\nA... | |
code_contests | verifiable_code | 482_D. Random Function and Tree | Solve the following coding problem using the programming language python:
You have a rooted tree consisting of n vertices. Let's number them with integers from 1 to n inclusive. The root of the tree is the vertex 1. For each i > 1 direct parent of the vertex i is pi. We say that vertex i is child for its direct parent... | ```python
from sys import stdin
Modulo = 10 ** 9 + 7
n = int(stdin.readline())
p = map(int, stdin.readline().split())
son = [[] for i in xrange(n)]
dp = [[0, 0] for i in xrange(n)]
for i, x in enumerate(p, 1):
son[x - 1].append(i)
for i in xrange(n - 1, -1, -1):
t0, t1 = 0, 1
for j in son[i]:
t0, t1 = (t0 + t0 *... | vfc_65189 | {
"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\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 52_C. Circular RMQ | Solve the following coding problem using the programming language python:
You are given circular array a0, a1, ..., an - 1. There are two types of operations with it:
* inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v;
* rmq(lf, rg) — this operation returns minim... | ```python
import math,sys,bisect,heapq,os
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
from functools import lru_cache
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
def input(): return sys.stdin.readline().rstrip('\r\n')
#input = iter(sys.stdin.buffer.read()... | vfc_65197 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n",
"output": "1\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1\n",... |
code_contests | verifiable_code | 555_E. Case of Computer Network | Solve the following coding problem using the programming language python:
Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible attack by hackers on a major computer network.
In this network are n vertices, some pairs of vertices are connected by m undirected channels. It ... | vfc_65201 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2\n1 2\n3 2\n1 3\n2 1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 2\n1 2\n1 2\n3 2\n1 3\n2 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 603_C. Lieges of Legendre | Solve the following coding problem using the programming language python:
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile co... | ```python
def grundy(n, k):
if k % 2 == 0:
if n <= 2:
return n
else:
return n % 2 == 0
else:
if n <= 4:
return [0, 1, 0, 1, 2][n]
elif n % 2 == 1:
return 0
else:
return 2 if grundy(n // 2, k) == 1 else 1
if __n... | vfc_65209 | {
"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 2\n3\n",
"output": "Nicky\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n3 4\n",
"output": "Kevin\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 626_A. Robot Sequence | Solve the following coding problem using the programming language python:
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin ... | ```python
import io
import sys
import time
import random
start = time.clock()
#~ test = '''6
#~ URLLDR'''
#~ test = '''7
#~ RLRLRLR'''
#~ test = '''200
#~ '''
#~ for i in range(200):
#~ test += random.choice("UDLR")
#~ print(test)
#~ test = '10 15'
#~ test = '1 1000000' #28733372
#~ test = '1 11' #55
#~ test = '1... | vfc_65213 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nURLLDR\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nDLUU\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7... |
code_contests | verifiable_code | 64_H. Table Bowling | Solve the following coding problem using the programming language python:
Table bowling tournament participant completed the competition according to the given final standings table. The table is given as a sequence of lines, each line has a format "name score". Your task is to prepare another table consisting of line... | vfc_65217 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nvasya 10\nted 11\npetya 10\nkatya 33\nmike 44\n",
"output": "1 mike\n2 katya\n3 ted\n4-5 petya\n4-5 vasya\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\na 1\nb 13\nc 1\n",
"ou... | |
code_contests | verifiable_code | 675_B. Restoring Painting | Solve the following coding problem using the programming language python:
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
* The pain... | ```python
n,a,b,c,d=map(int,input().split())
count=0
for x in range(1,n+1):
y=x+b-c
z=x+a-d
w=y+a-d
if (y>=1 and y<=n) and(z>=1 and z<=n) and (w>=1 and w<=n):
count+=1
print(count*n)
``` | vfc_65221 | {
"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 3 1 2 3\n",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 699_C. Vacations | Solve the following coding problem using the programming language python:
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For t... | ```python
size = int(input())
days = [int(a) for a in input().split()]
daysoff = 0
yesterday = 0
if days[0] == 0:
daysoff += 1
yesterday = 0
elif days[0] == 3:
yesterday = 0
else:
yesterday = days[0]
for i in range(1, size):
if days[i] == 0:
yesterday = 0
daysoff += 1
elif da... | vfc_65225 | {
"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\n1 3 2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 3 3 2 1 2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 71_E. Nuclear Fusion | Solve the following coding problem using the programming language python:
There is the following puzzle popular among nuclear physicists.
A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chem... | ```python
numbersDict = {
"1": "H",
"2": "He",
"3": "Li",
"4": "Be",
"5": "B",
"6": "C",
"7": "N",
"8": "O",
"9": "F",
"10": "Ne",
"11": "Na",
"12": "Mg",
"13": "Al",
"14": "Si",
"15": "P",
"16": "S",
"17": "Cl",
"18": "Ar",
"19": "K",
"20": "Ca",
"21": "Sc",
"22": "Ti",
"23": "V",
"24": "Cr",
"25": "Mn",
"26": "Fe",
"... | vfc_65229 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nBk Fm\nCf Es\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\nH H\nHe\n",
"output": "YES\nH+H->He\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 741_B. Arpa's weak amphitheater and Mehrdad's valuable Hoses | Solve the following coding problem using the programming language python:
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendshi... | ```python
n, m, k = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
ab = [(0, 0)] + list(zip(a, b))
l = list(range(n + 1))
def f(x):
if x == l[x]:
return x
l[x] = f(l[x])
return l[x]
for i in range(m):
x, y = map(int, input().split())
x, y = f(... | vfc_65233 | {
"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 5\n3 2 5\n2 4 2\n1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 765_A. Neverending competitions | Solve the following coding problem using the programming language python:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konsta... | ```python
import sys,math
from collections import deque
#input = sys.stdin.buffer.readline
def solve():
return;
# for _ in range(int(input())):
# solve()
n = int(input())
h = input()
cnt=0
for i in range(n):
s = input()
if h==s[:3] or h==s[-3:]:
cnt+=1
if cnt%2==0:
print("home")
else:
print("contest")
... | vfc_65237 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n",
"output": "contest\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"o... |
code_contests | verifiable_code | 788_C. The Great Mixing | Solve the following coding problem using the programming language python:
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a gl... | ```python
##
##
##
import sys
def line():
return sys.stdin.readline()
def numbers():
return list(map(int, line().split()))
def number():
return int(line())
adjlist = {}
n, k = 0, 0
mark = [False]*2010
edges = [False]*1010
# bfs for "ssph"
def bfs(s):
i = 0
frontier = [s]
while frontier:... | vfc_65241 | {
"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": "400 4\n100 300 450 500\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50 2\n100 25\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 834_C. The Meaningless Game | Solve the following coding problem using the programming language python:
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup------------------------... | vfc_65249 | {
"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\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n",
"output": "Yes\nYes\nYes\nNo\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6 12\n",
"output": "No\n",
"... |
code_contests | verifiable_code | 855_A. Tom Riddle's Diary | Solve the following coding problem using the programming language python:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to kn... | ```python
l = []
for _ in range(int(input())):
s = input()
if s not in l:
print('NO')
l.append(s)
else:
print('YES')
``` | vfc_65253 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"output": "NO\nNO\nNO\nNO\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\na\na\na\n",
"output": "NO\nYES\nYES\n",
"t... |
code_contests | verifiable_code | 879_D. Teams Formation | Solve the following coding problem using the programming language python:
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips... | ```python
def main():
_, k, m = [int(x) for x in input().split()]
a = []
last = ("-1", 0)
a.append(last)
for ai in input().split():
if last[0] == ai:
last = (ai, last[1]+1)
a[-1] = last
else:
last = (ai, 1)
a.append(last)
if la... | vfc_65257 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 9 10\n1\n",
"output": " 1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 903_A. Hungry Student Problem | Solve the following coding problem using the programming language python:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan ... | ```python
t = int(input())
for i in range(0,t):
flag = 0
x = int(input())
b = 0
temp = x
while temp >= 0 :
if(temp%3 == 0):
flag = 1
break
b = b+1
temp = x-7*b
if flag == 1 :
print("YES")
else:
print("NO")
``` | vfc_65261 | {
"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\n6\n5\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n2... |
code_contests | verifiable_code | 925_B. Resource Distribution | Solve the following coding problem using the programming language python:
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of... | ```python
def fin(c, x):
return (x + c - 1) // c
def ck(x, b):
r = (n, n)
for i in range(b, n):
r = min(r, (i + fin(c[i][0], x), i))
return r
def sol(r, l):
if r[0] <= n and l[0] <= n and r[1] < n and l[1] < n :
print("Yes")
print(r[0] - r[1], l[0]- l[1])
print(' '... | vfc_65265 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 8 16\n3 5 2 9 8 7\n",
"output": "Yes\n2 2\n2 6\n5 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 20 32\n21 11 11 12\n",
"output": "Yes\n1 3\n1 \n2 3 4 ",
"type": "stdin_... |
code_contests | verifiable_code | 954_C. Matrix Walk | Solve the following coding problem using the programming language python:
There is a matrix A of size x × y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be de... | ```python
def main():
int(input())
a = list(map(int, input().split()))
ds = [i - j for i, j in zip(a[1:], a)]
dss = set(abs(x) for x in ds)
if 0 in dss:
return False
try:
dss.remove(1)
except KeyError:
pass
if len(dss) > 1:
return False
if not dss:
... | vfc_65269 | {
"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\n1 2 1 2 5 3\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 10\n",
"output": "YES\n1000000000 9",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 980_B. Marlin | Solve the following coding problem using the programming language python:
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n... | ```python
EMPTY = "."
HOTEL = "#"
def main():
n, k = map(int, input().split())
print("YES")
print(EMPTY * n)
if k % 2 == 0:
m = k // 2
s = EMPTY + HOTEL * m + EMPTY * (n - m - 1)
print(s)
print(s)
elif k < n - 1:
s = (HOTEL * k).center(n, EMPTY)
p... | vfc_65273 | {
"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": "7 2\n",
"output": "YES\n.......\n.#.....\n.#.....\n.......\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 9_B. Running Student | Solve the following coding problem using the programming language python:
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Po... | ```python
# -*- coding: utf - 8 -*-
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: mr.math0777@gmail.com |
| created: 27.01.2018 9:50 |
"""""""""""""""""""""""""""""""""""""""""""""
# inp = open("input.txt", "r"); input = inp.readline; ... | vfc_65277 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 2\n0 2 4 6\n4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\n0 100000\n100000 100000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | beta-testing | Solve the following coding problem using the programming language python:
After a lot of hard work, Goyal has finally completed his app. But before he launches it, he needs to test it. His friends are helping him on this. Whenever a friend uses the app, his name is recorded in the logs. At the end of the day, Goyal ma... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 3 19:24:47 2015
@author: ishank011
"""
n=int(raw_input())
s=raw_input().split()
d={}
for a in s:
d[a]=0
for a in s:
d[a]+=1
for i in range(101, 0, -1):
for key in d:
if d[key]==i:
print key, d[key]
``` | vfc_65281 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nMohit Karan Mohit Mohit Ajay Karan\n\nSAMPLE",
"output": "Mohit 3\nKaran 2\nAjay 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\nArjun Mohit Karan Mohit Mohit Ajay Karan",
"o... |
code_contests | verifiable_code | connections | Solve the following coding problem using the programming language python:
Now After eliminating the invalid registrations they are planning to form connections to the participants laptops. The connection can be direct or indirect form and there should be only one connection exists between them. After setting the conne... | ```python
n=input();c=[];t=[]
for j in range(input()):
c.append(raw_input().split(" "))
for i in range(input()):
t.append(raw_input().split(" "))
for k in t:
if k in c:
print "Direct Connection"
else:
found=False
z=k[0]
for i in c:
if z==i[0]:
... | vfc_65285 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n1 2\n2 3\n3\n1 2\n1 3\n1 4\n\nSAMPLE",
"output": "Direct Connection\nIndirect Connection\nNo Connection\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n5\n1 2\n2 4 \n4 6\n6 5\n5 ... |
code_contests | verifiable_code | indent-ruby-1 | Solve the following coding problem using the programming language python:
Write your program in Ruby which takes an un-indented Ruby code as string and outputs the indented Ruby code as string.
Input Format
A string which is un-indented Ruby code
Output Format
A string which is indented Ruby code
SAMPLE INPUT
class... | ```python
a = ""
st = ""
g = 0;
while(a!="end"):
a = raw_input()
i = 0
n = len(a)
while(a[i]==" "):
i = i + 1
b = a[i:n]
c = map(str,b.split(" "))
if "class" in c:
print b
elif "def" in c:
st = st + " "
print st + b
elif "if" in c:
st = st + " ... | vfc_65293 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "class YabbaDabbaDoo\n def foo\n if foo == 42\n puts 'world hello'\n elsif foo == 24\n puts 'bk201'\n else\n puts 'congrats!'\n end\n end\nend\n\nSAMPLE",
"output"... |
code_contests | verifiable_code | old-keypad-in-a-foreign-land-24 | Solve the following coding problem using the programming language python:
Some people remain old fashioned and John is one of them. He doesn't like the new smart phones with full keypads and still uses the old keypads which require you to tap a key multiple times to type a single letter. For example, if the keyboard h... | ```python
n = input()
freq = map(int,raw_input().split())
freq.sort(reverse=True)
k = input()
key = map(int,raw_input().split())
ans=0
indx=1
if(sum(key)<n):
print -1
else:
i=0
while i<n:
j=0
while j<k and i<n:
if(key[j]>0):
ans += freq[i]*indx
key[j] -=1
i +=1
j +=1
indx +=1
print ans
``` | vfc_65301 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7 3 4 1\n2\n2 2\n\nSAMPLE",
"output": "19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3... |
code_contests | verifiable_code | raju-and-his-girlfriend | Solve the following coding problem using the programming language python:
Raju has a very pretty girlfriend. He chats with her all day and night through his phone. His phone lacks a QWERTY keypad, instead it has a T9 keypad.
This takes a lot of time to type a message in his phone and he often fears that his girlfrien... | ```python
l1 = [['.',',','?','!','1'],['a','b','c','2'],['d','e','f','3'],['g','h','i','4'],['j','k','l','5'],['m','n','o','6'],['p','q','r','s','7'],['t','u','v','8'],['w','x','y','z','9'],['_','0']]
T = input()
while T > 0:
X,Y,Z = map(int,raw_input().split())
string = raw_input()
current = 0
final = ''
tot = 0... | vfc_65305 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1 15\nilu\n1 1 10\nilu\n\nSAMPLE",
"output": "ilu\nil",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | simple-divison-1 | Solve the following coding problem using the programming language python:
Tom is very weak at maths, his teacher gave him a simple problem of dividing two numbers but as usual Tom is having difficulty solving the problem. Can you help tom solve the problem ?
Teacher has given him 3 numbers a, b and c. The task is to ... | ```python
import string
import math
from decimal import *
t1 = int(raw_input())
while t1>0:
a,b,c = (raw_input().split(' '))
a = int(a)
b,c = int(b),int(c)
x=a/b
ta = a
getcontext().rounding = ROUND_DOWN
t = 0;
if x==0:
t = c +1
else:
t = c + int(math.log10(x))+1
getcontext().prec = t
a = Decimal(a)/D... | vfc_65309 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n21 4 0\n5 4 3\n22 7 10\n\nSAMPLE",
"output": "5\n1.250\n3.1428571428\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | the-sleeping-barber | Solve the following coding problem using the programming language python:
Most of you know that how much the sleeping barber loves sleeping, and the way he works.
For those who don't know, it isn't important for now.
Because the problem , that the sleeping barber is facing is a new one for him and because he forgot t... | ```python
d=int(input())
while d :
g,m=map(int,raw_input().split())
people=map(int,raw_input().split())
people.sort()
cnt=0
capacity=0
while capacity<=m and cnt<g+1:
cnt+=1
capacity+=people[cnt-1]
print cnt-1
d-=1
``` | vfc_65313 | {
"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 5\n3 2 1 4 7\n5 10\n5 5 2 7 4\n\nSAMPLE",
"output": "2\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 5\n3 3 1 4 7\n5 10\n5 5 2 7 4\n\nSAMPLE",
"output": "2\n2\n",
... |
code_contests | verifiable_code | p00097 Sum of Integers II | Solve the following coding problem using the programming language python:
Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 an... | ```python
dp = [[0 for _ in range(1001)] for _ in range(10)]
dp[1][0] = dp[0][0] = 1
for now in range(1, 101):
for used in range(9, 0, -1):
dpu = dp[used]
dpu_1 = dp[used - 1]
for s in range(now, 1001):
dpu[s] = dpu_1[s - now] + dpu[s]
while True:
n, s = map(int, input().split())
if not n:
... | vfc_65361 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\n3 1\n0 0",
"output": "3\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 12\n3 1\n0 0",
"output": "12\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | p00229 Big Hit ! | Solve the following coding problem using the programming language python:
Ataru Oafoot of Aizu Gakuen University High School decided to play with a slot machine.
When you insert a medal on this machine, three reels will start spinning and each reel will stop automatically. In a normal game (normal game), 3 medals are... | ```python
while 1:
b, r, g, c, s, t = map(int, input().split())
if t == 0:
break
ans = 100
ans += (15 - 2) * (5*b) + (15 - 3) * b
t -= 6*b
ans += (15 - 2) * (3*r) + (15 - 3) * r
t -= 4*r
ans += (7 - 3) * g
t -= g
ans += (2 - 3) * c
t -= c
t -= s
ans += (... | vfc_65365 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 30 3 26 226\n9 0 18 3 20 118\n5 5 12 2 15 203\n7 4 19 2 22 197\n7 4 24 4 17 209\n0 0 0 0 0 0",
"output": "127\n793\n414\n629\n617",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 30 3... |
code_contests | verifiable_code | p00607 Emacs-like Editor | Solve the following coding problem using the programming language python:
Emacs is a text editor which is widely used by many programmers.
The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be moved right, left, down, and up by pushing f, b, n, p with the ... | ```python
class Editer:
def __init__(self, text):
# カーソルの位置
self.row = 0 #行
self.col = 0 #列
# 編集中のテキスト
self.text = [list(t) + ['\n'] for t in text]
# バッファー
self.buffer = []
def row_head(self):
return 0
def row_tail(self):
return len(... | vfc_65373 | {
"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": "hyo\nni\nEND_OF_TEXT\nf\nd\nf\nf\nk\np\np\ne\ny\na\nk\ny\ny\nn\ny\n-",
"output": "honihoni\nhoni",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "oyh\nni\nEND_OF_TEXT\nf\nd\nf\nf\nk\np\np\ne\... |
code_contests | verifiable_code | p00744 Cards | Solve the following coding problem using the programming language python:
There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards.
A blue card and a red card can be paired when both of the numbers pri... | ```python
import collections
import math
class Dinic:
"""Dinic Algorithm: find max-flow
complexity: O(EV^2)
used in GRL6A(AOJ)
"""
class edge:
def __init__(self, to, cap, rev):
self.to, self.cap, self.rev = to, cap, rev
def __init__(self, V, E, source, sink):
... | vfc_65377 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 6 6 15\n2 3 5\n2 3\n4 9\n8 16 32\n4 2\n4 9 11 13\n5 7\n5 5\n2 3 5 1001 1001\n7 11 13 30 30\n10 10\n2 3 5 7 9 11 13 15 17 29\n4 6 10 14 18 22 26 30 34 38\n20 20\n195 144 903 63 137 513 44 626 75 473\n876 421 568 519 755 840 3... |
code_contests | verifiable_code | p00883 Infected Land | Solve the following coding problem using the programming language python:
The earth is under an attack of a deadly virus. Luckily, prompt actions of the Ministry of Health against this emergency successfully confined the spread of the infection within a square grid of areas. Recently, public health specialists found a... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
dd0 = ((-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1))
DD = []
for k in range(6):
ddk = []
for y in range(k):
for x in range(k):
v = 0
for dx, dy in dd... | vfc_65381 | {
"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\n...\n.@.\n...\n3\n.##\n.#.\n@##\n3\n##.\n#..\n@..\n5\n....@\n##...\n#....\n...#.\n##.##\n5\n#...#\n...#.\n#....\n...##\n..@..\n5\n#....\n.....\n.....\n.....\n..@..\n5\n#..#.\n#.#.#\n.#.#.\n....#\n.#@##\n5\n..##.\n..#..\n#....\n#... |
code_contests | verifiable_code | p01014 Rolling Block | Solve the following coding problem using the programming language python:
Problem
Rolling Block is a game in which a rectangular parallelepiped metal body is rotated and moved, and dropped into a hole in the goal.
The condition to clear this game is to drop the metal body to the goal.
image0
About blocks
From (1) i... | vfc_65385 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 2\n#####\n#S.G#\n#...#\n#...#\n#####",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 12 2\n\nS...A.a..G#",
"output": "-1",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | p01147 Princess | Solve the following coding problem using the programming language python:
Princess, a Cryptanalyst
Decryption of the princess
English text is not available in this practice contest.
A brave princess in a poor country's tomboy got an old document written in Japanese, a town she went out in stealth. The princess can ... | vfc_65389 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\napple\nlength\nthings\nthin\n2\nicp\ncpc\n3\nzeta\neta\nalphabet\n2\nuntil\ntill\n0",
"output": "applengthings\nicpc\nzetalphabet\nuntill",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4... | |
code_contests | verifiable_code | p01285 Find the Point | Solve the following coding problem using the programming language python:
We understand that reading English is a great pain to many of you. So we’ll keep this problem statememt simple. Write a program that reports the point equally distant from a set of lines given as the input. In case of no solutions or multiple so... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
EPS = 1e-9
def line_cross_point(P1, P2, Q1, Q2):
x0, y0 = P1; x1, y1 = P2
x2, y2 = Q1; x3, y3 = Q2
dx0 = x1 - x0; dy0 = y1 - y0
dx1 = x3 - x2; dy1 = y3 - y2
s = (y0-y2)*dx1 - (x0-x2)*dy1
sm = dx0*dy1 - dy0*dx1
if ... | vfc_65393 | {
"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\n-35 -35 100 100\n-49 49 2000 -2000\n4\n0 0 0 3\n0 0 3 0\n0 3 3 3\n3 0 3 3\n4\n0 3 -4 6\n3 0 6 -4\n2 3 6 6\n-1 2 -4 6\n0",
"output": "Many\n1.5000 1.5000\n1.000 1.000",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | p01455 Intelligible Double Magic | Solve the following coding problem using the programming language python:
The 15th month of 2119. A spellbook was written by the court magician Sengemon Lugene. This magic book "In Magiray" was an innovative book in that it systematized "double magic", which is deeply related to the basis of the magic law of this worl... | vfc_65397 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 10\nriris\nsoa\nelah\nclar\narma\nmemori\nneoles\nqhaon\nclue\nclar riris\nriris memori\nriris neoles\nsoa clar\nsoa memori\nneoles elah\nelah qhaon\nneoles qhaon\nclue riris\narma elah",
"output": "54",
"type": "stdi... | |
code_contests | verifiable_code | p01901 Suntan | Solve the following coding problem using the programming language python:
D: Sunburn-Suntan-
story
Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. Cute like an angel. Aizu Nyan is planning to participate in this summer festi... | ```python
# AOJ 2801: Suntan
# Python3 2018.7.11 bal4u
from bisect import bisect_left
T, N = int(input()), int(input())
a, s, t = [0], [0], [0]
for i in range(N):
_s, _t = map(int, input().split())
s.append(_s)
t.append(_t)
a.append(a[-1]+_t-_s)
s.append(1<<62)
t.append(1<<62)
ans = 0
k = bisect_left(t, T, 0)-1
f... | vfc_65409 | {
"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": "20\n1\n0 10",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n1\n1 10",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | p02038 Tanuki and Fox | Solve the following coding problem using the programming language python:
problem
There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $).
$ M (x, y) $ represents an animal that came out by pu... | ```python
from functools import reduce
def M(x, y):
if x == 'T' and y == 'T':
return 'T'
elif x == 'T' and y == 'F':
return 'F'
elif x == 'F' and y == 'T':
return 'T'
else:
return 'T'
_ = input()
P = input().split()
print(reduce(M, P))
``` | vfc_65413 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nF T T",
"output": "T",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nF S T",
"output": "T\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n... |
code_contests | verifiable_code | p02182 Spot The Difference | Solve the following coding problem using the programming language python:
A: Find the difference
problem
Given rectangular boards A and B with N squares vertically and M squares horizontally. For each board, each square is painted white or black.
The color of the square in the i-th row and j-th column of the board ... | ```python
N, M = map(int, input().split())
table1 = ''
table2 = ''
for i in range(2 * N):
if i < N:
table1 += input()
else:
table2 += input()
count = 0
for i, j in zip(table1, table2):
if i != j:
count+=1
print(count)
``` | vfc_65417 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n..#\n##.\n.##\n#..",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02324 Chinese Postman Problem | Solve the following coding problem using the programming language python:
For a given weighted undirected graph G(V, E), find the distance of the shortest route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* The route must go through every edge at least once.
C... | ```python
import sys
f_i = sys.stdin
V, E = map(int, f_i.readline().split())
# adjacency matrix
no_edge = float("inf")
adj = [[no_edge] * V for i in range(V)]
for i in range(V):
adj[i][i] = 0
odd_b = 0 # bit DP to record odd vertex
ans = 0
# acceptance of input
for l_i in f_i:
s, t, d = map(int, l_i.spl... | vfc_65421 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n0 1 1\n0 2 2\n1 3 3\n2 3 4\n1 2 5",
"output": "18",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n0 1 1\n0 2 2\n1 3 3\n2 3 4",
"output": "10",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p02469 Least Common Multiple | Solve the following coding problem using the programming language python:
Find the least common multiple (LCM) of given n integers.
Constraints
* 2 ≤ n ≤ 10
* 1 ≤ ai ≤ 1000
* Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1
Input
n
a1 a2 ... an
n is given in the first line. Then, n integers a... | ```python
from functools import reduce
import math
n = int(input())
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
numlis = [int(a) for a in input().split()]
print(lcm_list(numlis))
``` | vfc_65425 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 5",
"output": "30",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 4 6",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4... |
code_contests | verifiable_code | clost | Solve the following coding problem using the programming language python:
Churu is taking the course called “Introduction to Data Structures”. Yesterday, he learned how to use a stack to check is a given parentheses expression is balanced or not. He finds it intriguing, and more importantly, he was given an assignment... | ```python
t=input()
while t>0:
t-=1
n,k=map(int,raw_input().split())
li=['0']*n
flag=0
while k>0:
k-=1
a,b=map(int,raw_input().split())
for i in range(a,b+1,2):
li[i]="("
li[i+1]=")"
for i in range(n):
if li[i]=='0' and flag==0:
... | vfc_65433 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n0 3\n4 2\n0 3\n1 2",
"output": "()()\n(())",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4 1\n0 3\n4 1\n0 3\n1 2",
"output": "()()\n()()\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | flow006 | Solve the following coding problem using the programming language python:
You're given an integer N. Write a program to calculate the sum of all the digits of N.
Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
Output
Calculate the su... | ```python
t=int(raw_input())
while(t>0):
n=[]
a=raw_input()
n=list(a)
n=map(int,list(n))
print sum(n)
t-=1
``` | vfc_65437 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n12345\n31203\n2123",
"output": "15\n9\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 \n12345\n50368\n2123",
"output": "15\n22\n8\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | leexams | Solve the following coding problem using the programming language python:
Little Elephant from the Zoo of Lviv hates exams. Since Little Elephant lives in Ukraine, he is going to take exams called 'ZNO'. Help him.
There will be n tickets on the table. Each ticket has a number written on it. The i-th ticket can be numb... | ```python
#! /usr/bin/env python
# -* - coding: UTF-8 -* -
rounds = int(raw_input())
A,B,P = [],[],[]
def main():
for _ in range(rounds):
tickets = int(raw_input())
global A, B, P
A,B,P = [],[],[]
for _ in range(tickets):
p, a, b = raw_input().split(" ")
P.... | vfc_65441 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n50 1 2\n50 2 1\n3\n100 1 3\n47 2 1\n74 3 2",
"output": "0.5\n0.3478\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n54 1 2\n50 2 1\n3\n100 1 3\n47 2 1\n74 3 2",
"output":... |
code_contests | verifiable_code | pour1 | Solve the following coding problem using the programming language python:
Given two vessels, one of which can accommodate a liters of water and the other which can accommodate b liters of water, determine the number of steps required to obtain exactly c liters of water in one of the vessels.
At the beginning both ves... | ```python
def gcd(a, b):
while b:
a, b = b, a%b
return a
def solve(a,b,c):
if c==0:return 0
if c==a or c==b:return 1
if a>b:a,b=b,a
if c>b:return -1
if c==b-a:return 2
d=gcd(a,b)
if d!=1:
if c%d:return -1
a/=d;b/=d;c/=d;
q=b/a
rk=0
r=a
while T... | vfc_65445 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n2\n3\n2\n3\n4",
"output": "2\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\n2\n3\n2\n2\n4",
"output": "2\n-1\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 100_F. Polynom | Solve the following coding problem using the programming language python:
You are given a polynom in form p(x) = (x + a1)·(x + a2)·... (x + an). Write Pike program to print it in a standard form p(x) = xn + b1xn - 1 + ... + bn - 1x + bn. You should write each addend in form «C*X^K» (for example, 5*X^8).
Please, write... | vfc_65453 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n-1\n1\n",
"output": "X^2-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n1\n",
"output": "X^2+2*X+1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1033_C. Permutation Game | Solve the following coding problem using the programming language python:
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.... | ```python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self... | vfc_65457 | {
"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": "15\n3 11 2 5 10 9 7 13 15 8 4 12 6 1 14\n",
"output": "ABAAAABBBAABAAB",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n3 6 5 4 2 7 1 8\n",
"output": "BAAAABAB",
"type": "stdin... |
code_contests | verifiable_code | 1056_A. Determine Line | Solve the following coding problem using the programming language python:
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line ... | ```python
n = int(input())
def intersect(a, b):
x = []
for i in a:
if i in b:
x.append(i)
return x
things = [input().split()[1:] for i in range(n)]
ans = things[0]
for i in range(1, n):
ans = intersect(ans, things[i])
print(" ".join(ans))
``` | vfc_65461 | {
"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\n3 1 4 6\n2 1 4\n5 10 5 6 4 1\n",
"output": "1 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1\n10 10 9 8 7 100 5 4 3 99 1\n5 1 2 3 4 5\n5 4 1 3 2 5\n4 10 1 5 3\n",
"outp... |
code_contests | verifiable_code | 1078_B. The Unbearable Lightness of Weights | Solve the following coding problem using the programming language python:
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights.
However, your friend does know the mass of each weight. You can ask your f... | ```python
from collections import defaultdict
def calcBinomials(N):
global binom
N += 1
binom = [[0]*N for _ in range(N)]
for n in range(N):
binom[n][0] = binom[n][n] = 1
for k in range(1, n):
binom[n][k] = binom[n-1][k] + binom[n-1][k-1]
n = int(input())
a = list(map(int, ... | vfc_65465 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 2 4 4 4 9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 4 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1099_B. Squares and Segments | Solve the following coding problem using the programming language python:
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and c... | ```python
# cook your dish here
t=int(input())
l=int(t**(0.5))
if l==(t**(0.5)):
print(2*l)
else:
if abs((l**2)-t) < ((l+1)**2)-t:
print(2*l+1)
else:
print(2*(l+1))
``` | vfc_65469 | {
"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\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
... |
code_contests | verifiable_code | 111_A. Petya and Inequiations | Solve the following coding problem using the programming language python:
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 ≥ x
* a1 + a2 + ... + an ≤ y
Input
The first line contains three space-separa... | ```python
from math import sqrt, ceil
n, x, y = map(int, input().split())
t = 1 if x < n else ceil(sqrt(x - n + 1))
if t + n - 1 > y: print(-1)
else: print(str(t), '\n1' * (n - 1))
``` | vfc_65473 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 15 15\n",
"output": "1\n1\n1\n1\n11\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1167_F. Scalar Queries | Solve the following coding problem using the programming language python:
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct.
Let's define function f(l, r) as follows:
* let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i};
* sort array b in increasing order;
* re... | ```python
import sys
MOD = (int)(1e9+7)
def add(a, b):
a += b
if a >= MOD: a -= MOD
return a
def mul(a, b):
return (a * b) % MOD
class fenwickTree:
def __init__(self, max_val):
self.max_val = max_val + 5
self.tree = [0] * self.max_val
def update(self, idx, value):
idx += 1
while idx < self.max_val:... | vfc_65481 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n123456789 214365879 987654321\n",
"output": "582491518\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 2 4 7\n",
"output": "167\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1186_A. Vus the Cossack and a Contest | Solve the following coding problem using the programming language python:
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine w... | ```python
def solve(n, m, k):
if min(m,k) >= n:
return "Yes"
else:
return "No"
def main():
n, m, k = list(map(int, input().split()))
print(solve(n, m, k))
if __name__ == '__main__':
main()
``` | vfc_65485 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 5 20\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 9 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1205_A. Almost Equal | Solve the following coding problem using the programming language python:
You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied:
For every n consecutive numbers on the circle write their sum on the blackboa... | ```python
n = int(input())
if n%2 == 0:
print("NO")
exit(0)
arr = []
for i in range(1, n+1):
if i%2 == 1:
arr.append(2*i-1)
else:
arr.append(2*i)
for i in range(n):
if arr[i] % 2 == 1:
arr.append(arr[i]+1)
else:
arr.append(arr[i]-1)
print("YES")
print(*arr)
``` | vfc_65489 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "YES\n1 4 5 2 3 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 1221_E. Game With String | Solve the following coding problem using the programming language python:
Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisti... | ```python
q = int(input())
for i in range(q):
a, b = [int(item) for item in input().split()]
s = input().rstrip() + "#"
cnt = 0
bob_world = 0
alice_world = 0
length = 0
bob_winning = False
for ch in s:
if ch == ".":
cnt += 1
else:
if cnt < b:
... | vfc_65493 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2\nXX......XX...X\n4 2\nX...X.X..X\n5 3\n.......X..X\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n5 4\n...............\n5 4\n...............X.....\n5... |
code_contests | verifiable_code | 1248_B. Grow The Tree | Solve the following coding problem using the programming language python:
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a... | ```python
a=int(input());b=sorted(list(map(int,input().split())),reverse=True);from math import ceil as c;print(sum(b[:c(len(b)/2)])**2+sum(b[c(len(b)/2):])**2)
``` | vfc_65497 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 2 2\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "26\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1266_F. Almost Same Distance | Solve the following coding problem using the programming language python:
Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1.
You are given a tree on n vertices. For each i between 1... | vfc_65501 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 2\n1 3\n1 4\n4 5\n4 6\n",
"output": "4 4 2 1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2\n1 3\n1 4\n4 5\n",
"output": "4 3 2 1 1 \n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 1288_A. Deadline | Solve the following coding problem using the programming language python:
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can ... | ```python
import math
for _ in range(int(input())):
n,d = map(int,input().split())
if ((1-n)**2) - (4*(d-n)) >= 0:
print('YES')
else:
print('NO')
``` | vfc_65505 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n4 5\n5 11\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000000 1000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 130_A. Hexagonal numbers | Solve the following coding problem using the programming language python:
Hexagonal numbers are figurate numbers which can be calculated using the formula hn = 2n2 - n. You are given n; calculate n-th hexagonal number.
Input
The only line of input contains an integer n (1 ≤ n ≤ 100).
Output
Output the n-th hexagon... | vfc_65509 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "45\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1331_D. Again? | Solve the following coding problem using the programming language python:
Input
The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9.
Output
Output a single integer.
Examples
Input
A278832
Output
0
... | ```python
value = input()
print(int(value, 16)%2)
``` | vfc_65513 | {
"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": "A089956\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A089957\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1351_B. Square? | Solve the following coding problem using the programming language python:
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. I... | ```python
for t in range(int(input())):
a, b = map(int, input().split())
c, d = map(int, input().split())
a, b = min(a, b), max(a, b)
c, d = min(c, d), max(c, d)
if a + c == b == d:
print("YES")
else:
print("NO")
``` | vfc_65517 | {
"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\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n64 9\n41 36\n",
"output": "No\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1371_D. Grid-00100 | Solve the following coding problem using the programming language python:
A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!
You are given integers n,k. Construct a grid A with size n × n consisting of integers 0 and 1. The very important condition should be satisfied: the sum of all e... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wri... | vfc_65521 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 2\n3 8\n1 0\n4 16\n",
"output": "0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n297 47297\n103 6336\n",
"output"... |
code_contests | verifiable_code | 1394_A. Boboniu Chats with Du | Solve the following coding problem using the programming language python:
Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.
In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.
Du will chat in the group fo... | ```python
#! /usr/bin/python3
n, d, m = [int(inp) for inp in input().split()]
aArr = sorted([int(inp) for inp in input().split()], reverse = True)
i = sum([j > m for j in aArr])
aU = aArr[:i]
aL = aArr[i:]
aUS = aU
for i in range(1, len(aU)):
aUS[i] += aUS[i - 1]
aUS = [0] + aUS
aLS = aL
for i in range(1, len(aL)... | vfc_65525 | {
"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": "20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n",
"output": "195\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1418_F. Equal Product | Solve the following coding problem using the programming language python:
You are given four integers n, m, l and r.
Let's name a tuple (x_1, y_1, x_2, y_2) as good if:
1. 1 ≤ x_1 < x_2 ≤ n;
2. 1 ≤ y_2 < y_1 ≤ m;
3. x_1 ⋅ y_1 = x_2 ⋅ y_2;
4. l ≤ x_1 ⋅ y_1 ≤ r.
Find any good tuple for each x_1 from 1 ... | vfc_65529 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n1 10\n",
"output": "1 2 2 1\n2 2 4 1\n-1\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 20\n91 100\n",
"output": "-1\n-1\n-1\n-1\n-1\n6 16 8 12\n-1\n-1\n",
"type": ... | |
code_contests | verifiable_code | 1436_E. Complicated Computations | Solve the following coding problem using the programming language python:
In this problem MEX of a certain array is the smallest positive integer not contained in this array.
Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including toda... | ```python
class SegmentTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
self.range = [(-1,n)] * 2 * self.num
# 配列の値を葉... | vfc_65533 | {
"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": "5\n1 4 3 1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.