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 | voters | Solve the following coding problem using the programming language python:
As you might remember, the collector of Siruseri had ordered
a complete revision of the Voters List. He knew that constructing
the list of voters is a difficult task, prone to errors. Some
voters may have been away on vacation, others may have m... | ```python
from sys import stdin,stdout
def write(s):
stdout.write(str(s))
stdout.write('\n')
n1,n2,n3 = map(int,stdin.readline().split())
l1 = []
l2 = []
l3 = []
l = set()
for _ in xrange(n1):
l1.append(int(stdin.readline()))
for _ in xrange(n2):
l2.append(int(stdin.readline()))
for _ in xrange(n3):
l3.append(int... | vfc_70865 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 5\n23\n30\n42\n57\n90\n21 \n23 \n35 \n57 \n90 \n92 \n21 \n23 \n30 \n57 \n90",
"output": "5\n21\n23\n30\n57\n90\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6 5\n23\n30\n42\n57\n90... |
code_contests | verifiable_code | 101_B. Buses | Solve the following coding problem using the programming language python:
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All ... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
from bisect import bisect_left as bt
def main():
mod = 10**9+7
n,m = map(int,input().split())
jump,x = [],[]
for i in range(m):
s,e = map(int,input().split())
jump.append... | vfc_70869 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 265000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n0 1\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n0 1\n0 2\n0 3\n0 4\n0 5\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 1065_E. Side Transmutations | Solve the following coding problem using the programming language python:
Consider some set of distinct characters A and some string S, consisting of exactly n characters, where each character is present in A.
You are given an array of m integers b (b_1 < b_2 < ... < b_m).
You are allowed to perform the following m... | ```python
n,m,a=map(int,input().split())
b=list(map(int,input().split()))
for i in range(m):
if i==0:
diffs=[b[0]]
else:
diffs.append(b[i]-b[i-1])
powers=[a%998244353]
for i in range(30):
powers.append(powers[-1]**2%998244353)
def power(x,y,binpowers):
prod=1
bits=bin(y)[2:]
bits... | vfc_70877 | {
"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": "9 2 26\n2 3\n",
"output": "150352234\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12 3 1\n2 5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1107_C. Brutality | Solve the following coding problem using the programming language python:
You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character.
You are playing the game on the new generation console so your gamepad have 26 buttons. Each button has a single lowerc... | ```python
# cook your dish here
#import sys
#sys.setrecursionlimit(10**9)
ll=lambda:map(int,input().split())
t=lambda:int(input())
ss=lambda:input()
lx=lambda x:map(int,input().split(x))
yy=lambda:print("YES")
nn=lambda:print("NO")
from math import log10 ,log2,ceil,factorial as fac,gcd,inf,sqrt,log
#from itertools im... | vfc_70885 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n10 10\nqq\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 1\n10 15 2 1 4 8 15 16\nqqwweerr\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1154_G. Minimum Possible LCM | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers a_1, a_2, ..., a_n.
Your problem is to find such pair of indices i, j (1 ≤ i < j ≤ n) that lcm(a_i, a_j) is minimum possible.
lcm(x, y) is the least common multiple of x and y (minimum positive... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
from array import array
def main():
INF = 10**18
n = int(input())
a = list(map(int,input().split()))
lim = max(a)+1
counter = array('i',[0]*lim)
for i in a:
counter[i] +=... | vfc_70893 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 4 8 3 6\n",
"output": "1 2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1176_E. Cover it! | Solve the following coding problem using the programming language python:
You are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
Your task is to choose at most ⌊n/2⌋ vertices in this graph so each... | ```python
n, m = map(int, input().split())
g = []
for i in range(n):
g.append([])
for i in range(m):
u, v = map(int, input().split())
u-=1
v-=1
g[u]+=[v]
g[v]+=[u]
start = max(range(n), key=lambda i: len(g[i]))
edges = []
vis = [False] * n
q = [start]
vis[start] = True
while q:
u = q.pop(0)... | vfc_70897 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n6 8\n2 5\n5 4\n4 3\n4 1\n1 3\n2 3\n2 6\n5 6\n",
"output": "1\n1 \n3\n3 4 6 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n2 1\n2 3\n2 4\n2 5\n3... |
code_contests | verifiable_code | 1195_D1. Submarine in the Rybinsk Sea (easy edition) | Solve the following coding problem using the programming language python:
This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this s... | ```python
n = int(input().strip())
arr = input().strip().split()
digs = []
l = len(str(arr[0]))
ans = 0
m = 1
for i in range(l-1, -1, -1):
total = 0
for j in range(n):
total += int(arr[j][i])
ans += total*n*m + total*n*(m*10)
m *= 100
print(ans%998244353)
``` | vfc_70901 | {
"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\n1\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n123 456\n",
"output": "1115598\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1234_F. Yet Another Substring Reverse | Solve the following coding problem using the programming language python:
You are given a string s consisting only of first 20 lowercase Latin letters ('a', 'b', ..., 't').
Recall that the substring s[l; r] of the string s is the string s_l s_{l + 1} ... s_r. For example, the substrings of "codeforces" are "code", "f... | vfc_70909 | {
"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": "abcdeefc\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aabbcc\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... | |
code_contests | verifiable_code | 1253_E. Antenna Coverage | Solve the following coding problem using the programming language python:
The mayor of the Central Town wants to modernize Central Street, represented in this problem by the (Ox) axis.
On this street, there are n antennas, numbered from 1 to n. The i-th antenna lies on the position x_i and has an initial scope of s_i... | ```python
#!/usr/bin/python3
import os
import sys
def main():
N, M = read_ints()
A = [tuple(read_ints()) for _ in range(N)]
print(solve(N, M, A))
def solve(N, M, A):
A.sort()
D = {0: 0}
for x, s in A:
#dprint(x, s)
#dprint(D)
d = D.copy()
for x0, c in d.item... | vfc_70913 | {
"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": "1 1\n1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 595\n43 2\n300 4\n554 10\n",
"output": "281",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1277_D. Let's Play the Words? | Solve the following coding problem using the programming language python:
Polycarp has n different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100".
Polycarp wants to offer his set of n binary words to play a game "word... | ```python
t = int(input())
for _ in range(t):
n = int(input())
words = []
for i in range(n):
words.append(input())
same_1 = []
same_0 = []
zero_1 = []
one_0 = []
index_zero_1 = []
index_one_0 = []
for index, w in enumerate(words):
if w[0] == w[-1]:
if ... | vfc_70917 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n0001\n1000\n0011\n0111\n3\n010\n101\n0\n2\n00000\n00001\n4\n01\n001\n0001\n00001\n",
"output": "1\n3\n-1\n0\n\n2\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4\n0001\n1000... |
code_contests | verifiable_code | 1297_D. Bonus Distribution | Solve the following coding problem using the programming language python:
For the first time, Polycarp's startup ended the year with a profit! Now he is about to distribute k burles as a bonus among n employees.
It is known that the current salary of the i-th employee is a_i and all the values of a_i in the company a... | vfc_70921 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 1\n3 1 4 2\n2 3\n10 2\n4 1000000000\n987654321 1000000000 999999999 500000000\n8 9\n5 6 1 8 3 4 2 7\n6 1\n6 3 1 8 5 9\n",
"output": "\n0 0 1 0 \n0 3 \n134259259 121913582 121913582 621913577 \n2 2 0 2 0 1 0 2 \n1 0 0 0 0... | |
code_contests | verifiable_code | 133_C. Turing Tape | Solve the following coding problem using the programming language python:
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print... | ```python
def obin(a):
a = ord(a)
text = bin(a)[bin(a).find('1'):]
ntext = '0'*(8-len(text))+text
return ntext
def rev(a):
return a[-1::-1]
def revascii(char):
return int(rev(obin(char)),base=2)
text = input()
for i in range(len(text)):
if i == 0:
lastele = 0
else:
las... | vfc_70929 | {
"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": "Hello, World!\n",
"output": "238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "|wB6qdp/]MLcsaTcq*k`ORMsjdW{\"i5gD_@ap*L0.QbDx:pW3-=-;... |
code_contests | verifiable_code | 1361_D. Johnny and James | Solve the following coding problem using the programming language python:
James Bond, Johnny's favorite secret agent, has a new mission. There are n enemy bases, each of them is described by its coordinates so that we can think about them as points in the Cartesian plane.
The bases can communicate with each other, s... | vfc_70933 | {
"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\n0 0\n1 1\n2 2\n3 3\n0 1\n0 2\n",
"output": "6.2426406871192851\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1401_F. Reverse and Swap | Solve the following coding problem using the programming language python:
You are given an array a of length 2^n. You should process q queries on it. Each query has one of the following 4 types:
1. Replace(x, k) — change a_x to k;
2. Reverse(k) — reverse each subarray [(i-1) ⋅ 2^k+1, i ⋅ 2^k] for all i (i ≥ 1);... | ```python
from sys import stdin
REPLACE_ID = 1
REVERSE_ID = 2
SWAP_ID = 3
SUM_ID = 4
def main():
n, q = _read_ints()
a = tuple(_read_ints())
requests = tuple(_read_ints() for _ in range(q))
for result in compute_requests_results(a, requests):
print(result)
def _read_ints():
return map(... | vfc_70941 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 8\n7 0 8 8 7 1 5 2\n4 3 7\n2 1\n3 2\n4 1 6\n2 3\n1 5 16\n4 8 8\n3 0\n",
"output": "29\n22\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n7 4 9 9\n1 2 8\n3 1\n4 2 4\n",
"ou... |
code_contests | verifiable_code | 1424_M. Ancient Language | Solve the following coding problem using the programming language python:
While exploring the old caves, researchers found a book, or more precisely, a stash of mixed pages from a book. Luckily, all of the original pages are present and each page contains its number. Therefore, the researchers can reconstruct the book... | ```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_70945 | {
"difficulty": "20",
"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\n2\nb\nb\nbbac\n0\na\naca\nacba\n1\nab\nc\nccb\n",
"output": "acb",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1470_D. Strange Housing | Solve the following coding problem using the programming language python:
Students of Winter Informatics School are going to live in a set of houses connected by underground passages. Teachers are also going to live in some of these houses, but they can not be accommodated randomly. For safety reasons, the following m... | ```python
import io
import os
from collections import deque
def solve(N, M, edges):
graph = [[] for i in range(N)]
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
source = 0
q = deque([source])
isTeacher = {}
while q:
node = q.popleft()
if node in is... | vfc_70953 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2\n3 2\n2 1\n4 2\n1 4\n2 3\n",
"output": "\nYES\n2\n1 3 \nNO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1497_C2. k-LCM (hard version) | Solve the following coding problem using the programming language python:
It is the hard version of the problem. The only difference is that in this version 3 ≤ k ≤ n.
You are given a positive integer n. Find k positive integers a_1, a_2, …, a_k, such that:
* a_1 + a_2 + … + a_k = n
* LCM(a_1, a_2, …, a_k) ≤ n/... | ```python
for nt in range(int(input())):
n, k = map(int,input().split())
ans = [1]*(k-3)
n -= (k-3)
if n%2:
ans.extend([1, n//2, n//2])
else:
if n//2%2:
ans.extend([2, n//2-1, n//2-1])
else:
ans.extend([n//2, n//4, n//4])
print (*ans)
``` | vfc_70957 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6 4\n9 5\n",
"output": "\n1 2 2 1 \n1 3 3 1 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n47310 15888\n115847 84112\n",
"output": "1 15712 15712 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
code_contests | verifiable_code | 151_B. Phone Numbers | Solve the following coding problem using the programming language python:
Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phoneb... | ```python
def num_type(h):
if h.count(h[0]) == 6:
return 0
for i in range(1,6):
if h[i] >= h[i-1]:
return 2
return 1
def pri(g,ind,p):
[maxx,st]=[0,[]]
for i in range(len(p)):
if p[i][ind] == maxx:
st.append(p[i][-1])
elif p[i][ind] > maxx:
... | vfc_70961 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32\n",
"output": "If you wan... |
code_contests | verifiable_code | 1547_B. Alphabetical Strings | Solve the following coding problem using the programming language python:
A string s of length n (1 ≤ n ≤ 26) is called alphabetical if it can be obtained using the following algorithm:
* first, write an empty string to s (i.e. perform the assignment s := "");
* then perform the next step n times;
* at the i-... | ```python
t = int(input())
for amp in range(t):
s = input()
n = len(s)
y = -1
for i in range(n):
if s[i] == "a" :
y = i
break
sol = "YES"
if y == -1 :
sol = "NO"
else:
val = ord(s[y])
l = z = y
q = 1
while ... | vfc_70965 | {
"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": "11\na\nba\nab\nbac\nihfcbadeg\nz\naa\nca\nacb\nxyz\nddcba\n",
"output": "YES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 174_D. Variable, or There and Back Again | Solve the following coding problem using the programming language python:
Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used!
Vasya's life goes in states of a program. In each state, Vasya can either be used (for example... | vfc_70969 | {
"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 3\n1 0 0 2\n1 2\n2 3\n3 4\n",
"output": "1\n1\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 0 2\n1 3\n",
"output": "1\n0\n1\n",
"type": "stdin_stdout"
}
... | |
code_contests | verifiable_code | 194_E. Hamming Distance | Solve the following coding problem using the programming language python:
Hamming distance between strings a and b of equal length (denoted by h(a, b)) is equal to the number of distinct integers i (1 ≤ i ≤ |a|), such that ai ≠ bi, where ai is the i-th symbol of string a, bi is the i-th symbol of string b. For example... | ```python
h = [[0 in range(10)] for j in range(10)]
for i in range(1, 4):
h[i] = [0 for j in range(i + 1)] + list(map(int, input().split()))
#for i in range(1, 4):
# print(" ".join(map(str, h[i][1:5])))
if (h[1][2] + h[1][3] < h[2][3] or (h[1][2] + h[1][3] - h[2][3]) % 2 == 1):
print("-1")
exit(0)
BB = ... | vfc_70973 | {
"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 4 4\n4 4\n4\n",
"output": "6\naaaaaa\naabbbb\nbbaabb\nbbbbaa",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "99828 54425 67603\n60232 60026\n59994\n",
"output": "-1\n",
"type":... |
code_contests | verifiable_code | 218_E. Formurosa | Solve the following coding problem using the programming language python:
The Bytelandian Institute for Biological Research (BIBR) is investigating the properties of two species of bacteria, named simply 0 and 1. Even under a microscope, bacteria of those two species are very difficult to distinguish. In fact, the onl... | vfc_70977 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n((?^?)&?)\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n?\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 242_B. Big Segment | Solve the following coding problem using the programming language python:
A coordinate line has n segments, the i-th segment starts at the position li and ends at the position ri. We will denote such a segment as [li, ri].
You have suggested that one of the defined segments covers all others. In other words, there is... | ```python
n = int(input())
segments = []
minl = 10**9
maxr = 1
for i in range(n):
a, b = map(int, input().split())
segments.append((a, b))
if a<minl:
minl = a
if b>maxr:
maxr = b
if (minl, maxr) in segments:
print(segments.index((minl, maxr))+1)
else:
print(-1)
... | vfc_70981 | {
"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\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 267_C. Berland Traffic | Solve the following coding problem using the programming language python:
Berland traffic is very different from traffic in other countries. The capital of Berland consists of n junctions and m roads. Each road connects a pair of junctions. There can be multiple roads between a pair of junctions. For each road we know... | vfc_70985 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n11\n1 2 7\n1 2 7\n1 3 7\n1 4 7\n2 3 7\n2 5 7\n3 6 7\n4 7 7\n5 4 7\n5 6 7\n6 7 7\n",
"output": "13.0000000000\n2.0000000000\n2.0000000000\n3.0000000000\n6.0000000000\n1.0000000000\n3.0000000000\n4.0000000000\n7.0000000000\n... | |
code_contests | verifiable_code | 290_C. WTF? | Solve the following coding problem using the programming language python:
HAI
I HAS A TUX
GIMMEH TUX
I HAS A FOO ITS 0
I HAS A BAR ITS 0
I HAS A BAZ ITS 0
I HAS A QUZ ITS 1
TUX IS NOW A NUMBR
IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0
I HAS A PUR... | ```python
"""
IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0
I HAS A PUR
GIMMEH PUR
PUR IS NOW A NUMBR
FOO R SUM OF FOO AN PUR
BAR R SUM OF BAR AN 1
BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ
O RLY?
YA RLY
BAZ R FOO
QUZ R BAR
OIC
IM OUTTA YR LOOP
BAZ IS NOW A NUMBAR
VISI... | vfc_70989 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0\n1\n1\n",
"output": "0.666667\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 316_B1. EKG | Solve the following coding problem using the programming language python:
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cul... | ```python
def f(x, p):
q = []
while x:
q.append(x)
x = p[x]
return q
from collections import defaultdict
n, k = map(int, input().split())
t = list(map(int, input().split()))
p = [0] * (n + 1)
for i, j in enumerate(t, 1):
p[j] = i
p = [f(i, p) for i, j in enumerate(t, 1) if j == 0]
s = de... | vfc_70993 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\n2 3 0 5 6 0\n",
"output": "2\n5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 338_E. Optimize! | Solve the following coding problem using the programming language python:
Manao is solving a problem with the following statement:
<image>
He came up with a solution that produces the correct answers but is too slow. You are given the pseudocode of his solution, where the function getAnswer calculates the answer to ... | vfc_70997 | {
"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 2 10\n5 3\n1 8 5 5 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 10\n5 3\n1 6 5 5 7\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 361_B. Levko and Permutation | Solve the following coding problem using the programming language python:
Levko loves permutations very much. A permutation of length n is a sequence of distinct positive integers, each is at most n.
Let’s assume that value gcd(a, b) shows the greatest common divisor of numbers a and b. Levko assumes that element pi ... | ```python
from sys import stdin,stdout
n,k=map(int ,stdin.readline().strip().split())
if n==k:
print(-1)
else:
result=[0]*n
for i in range(n-k,n):
result[i]=i+1
for i in range(1,n-k):
result[i]=i
result[0]=n-k
print(*result,sep=' ')
``` | vfc_71001 | {
"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 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "2 1 3 4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 405_D. Toy Sum | Solve the following coding problem using the programming language python:
Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.
There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teache... | ```python
import sys
from math import gcd,sqrt,ceil
from collections import defaultdict,Counter,deque
import math
# input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
# sys.stdout=open("CP1/output.txt",'w')
# sys.stdin=open("CP1/input.txt",'r')
import os
import sys
from io import BytesIO, IO... | vfc_71009 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n",
"output": "1\n1000000 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 4 5\n",
"output": "3\n1000000 999997 999996 ",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 432_E. Square Tiling | Solve the following coding problem using the programming language python:
You have an n × m rectangle table, its cells are not initially painted. Your task is to paint all cells of the table. The resulting picture should be a tiling of the table with squares. More formally:
* each cell must be painted some color (t... | ```python
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
ANS=[[-1]*m for i in range(n)]
for i in range(n):
for j in range(m):
if ANS[i][j]==-1:
for koma in ["A","B","C","D","E","F"]:
for k,l in [(i-1,j),(i,j-1),(i+1,j),(i,j+1)]:
if 0<=k<... | vfc_71013 | {
"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 4\n",
"output": "AAAB\nAAAC\nAAAB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n",
"output": "ABA\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 455_B. A Lot of Games | Solve the following coding problem using the programming language python:
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.
Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns.... | ```python
"""
Codeforces Contest 260 Div 1 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n,k = read()
s = set()
for i in range(n): s.add(read(0))
s = list(s)
s.sort()
s = treeify(s)
res = solve(s)
if res == 0: # neither: second player win
print("Second"... | vfc_71017 | {
"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\na\nb\nc\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\na\nb\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 477_E. Dreamoon and Notepad | Solve the following coding problem using the programming language python:
Dreamoon has just created a document of hard problems using notepad.exe. The document consists of n lines of text, ai denotes the length of the i-th line. He now wants to know what is the fastest way to move the cursor around because the documen... | vfc_71021 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 5\n1\n1 0 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 525_E. Anya and Cubes | Solve the following coding problem using the programming language python:
Anya loves to fold and stick. Today she decided to do just that.
Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that th... | ```python
fact = [ 1 ]
for i in range( 1, 20, 1 ):
fact.append( fact[ i - 1 ] * i )
from collections import defaultdict
N, K, S = map( int, input().split() )
A = list( map( int, input().split() ) )
ldp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ]
ldp[ 0 ][ 0 ][ 0 ] = 1
for i in range( N... | vfc_71029 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 7\n4 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1\n1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 551_A. GukiZ and Contest | Solve the following coding problem using the programming language python:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, n students will attend, and before the start, every one of them has some ... | ```python
n,x=int(input()),list(map(int, input().split(" ")))
tmp=sorted(x,reverse=True)
for i in x:
print(tmp.index(i)+1)
``` | vfc_71033 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n",
"output": "1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 3\n",
"output": "3 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 578_B. "Or" Game | Solve the following coding problem using the programming language python:
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum po... | ```python
def main():
n, k, x = map(int, input().split())
aa = list(map(int, input().split()))
x, lo, u = x ** k, [0] * n, 0
for i, a in enumerate(aa):
lo[i] = u
u |= a
hi, u = [], 0
for a in reversed(aa):
hi.append(u)
u |= a
hi.reverse()
for i, u, a, v in... | vfc_71037 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 2\n1 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 3\n1 2 4 8\n",
"output": "79\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 643_A. Bear and Colors | Solve the following coding problem using the programming language python:
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements)... | ```python
# n=int(input())
# n,k=map(int,input().split())
'''l=0
r=10**13
while l+1<r:
mid=(l+r)//2
val=(max(0,b_b*mid-b)*rb+max(0,b_s*mid-s)*rs+max(0,b_c*mid-b)*rc)
if val>money:
r=mid
if val<=money:
l=mid'''
# arr=list(map(int,input().split()))
# n=int(input())
#if all([size%ele==0 for... | vfc_71049 | {
"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 1\n",
"output": "6 0 0 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 670_A. Holidays | Solve the following coding problem using the programming language python:
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of... | ```python
n = int(input())
if n % 7 == 0:
print(n // 7 * 2, n // 7 * 2)
else:
x = (n // 7 + 1) * 7
if x - n == 6:
print((n // 7) * 2, (n // 7) * 2 + 1)
else:
if x - n == 1:
print((n // 7) * 2 + 1, (n // 7) * 2 + 2)
else:
print((n // 7) * 2, (n // 7) * 2 +... | vfc_71053 | {
"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\n",
"output": "0 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14\n",
"output": "4 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "23\n",
... |
code_contests | verifiable_code | 691_C. Exponential notation | Solve the following coding problem using the programming language python:
You are given a positive decimal number x.
Your task is to convert it to the "simple exponential notation".
Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part... | ```python
import sys
import bisect
from bisect import bisect_left as lb
input_=lambda: sys.stdin.readline().strip("\r\n")
from math import log
from math import gcd
from math import atan2,acos
from random import randint
sa=lambda :input_()
sb=lambda:int(input_())
sc=lambda:input_().split()
sd=lambda:list(map(int,input_(... | vfc_71057 | {
"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": "01.23400\n",
"output": "1.234\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 716_C. Plus and Square Root | Solve the following coding problem using the programming language python:
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '<image>' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Code... | ```python
n=int(input())
print(2)
for lvl in range(2,n+1):
print(lvl*(lvl+1)*(lvl+1)-(lvl-1))
``` | vfc_71061 | {
"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\n",
"output": "2\n17\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 736_E. Chess Championship | Solve the following coding problem using the programming language python:
Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were m players participating and each pair of players played exactly one game. The victory gives 2 po... | vfc_71065 | {
"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 1\n9\n",
"output": "no",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n8 6 4 2 0\n",
"output": "yes\nXWWWW\nLXWWW\nLLXWW\nLLLXW\nLLLLX\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 760_E. Nikita and stack | Solve the following coding problem using the programming language python:
Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the s... | vfc_71069 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1 2\n1 0\n",
"output": "2\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 0\n4 0\n3 1 1\n2 1 1\n1 1 2\n",
"output": "-1\n-1\n-1\n-1\n2\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 784_A. Numbers Joke | Solve the following coding problem using the programming language python:
Input
The input contains a single integer a (1 ≤ a ≤ 30).
Output
Output a single integer.
Example
Input
3
Output
27
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by ... | ```python
ls = [0, 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, 762, 778, 825, ]
print(ls[int(input())])
``` | vfc_71073 | {
"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": "3\n",
"output": "27\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 804_F. Fake bullions | Solve the following coding problem using the programming language python:
In Isart people don't die. There are n gangs of criminals. The i-th gang contains si evil people numerated from 0 to si - 1. Some of these people took part in a big mine robbery and picked one gold bullion each (these people are given in the inp... | vfc_71077 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1\n01\n00\n5 11000\n6 100000\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 1\n00000\n10000\n11011\n11000\n11010\n2 00\n1 1\n6 100110\n1 0\n1 0\n",
"output": ... | |
code_contests | verifiable_code | 82_E. Corridor | Solve the following coding problem using the programming language python:
Consider a house plan.
Let the house be represented by an infinite horizontal strip defined by the inequality - h ≤ y ≤ h. Strictly outside the house there are two light sources at the points (0, f) and (0, - f). Windows are located in the wa... | vfc_71081 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 4\n-1 0\n1 2\n",
"output": "23.3333333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 2\n-1 1\n",
"output": "10.0000000000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 851_A. Arpa and a research in Mexican wave | Solve the following coding problem using the programming language python:
Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.
* At time 1, the first spectator stands.
* At time 2, the second spectator stands.
* ...
* At t... | ```python
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) ... | vfc_71085 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5 7\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 875_C. National Property | Solve the following coding problem using the programming language python:
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library.
Some long and uninteresting story was removed...
The alphabet of Bookland is so large that its letters are de... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(... | vfc_71089 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2\n1 1\n3 1 3 2\n2 1 1\n",
"output": "Yes\n2\n2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1\n",
"output": "No\n",
"type": ... |
code_contests | verifiable_code | 89_B. Widget Library | Solve the following coding problem using the programming language python:
Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other.
A widget is some element of graphical in... | ```python
n = int(input())
widgets = {}
class Widget:
def __init__(self, w, h):
self.w = w
self.h = h
def calc_size(self):
return (self.w, self.h)
class Box:
def __init__(self, direction):
self.dir = direction
self.packed = []
self.border = 0
self.s... | vfc_71093 | {
"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": "12\nWidget me(50,40)\nVBox grandpa\nHBox father\ngrandpa.pack(father)\nfather.pack(me)\ngrandpa.set_border(10)\ngrandpa.set_spacing(20)\nWidget brother(30,60)\nfather.pack(brother)\nWidget friend(20,60)\nWidget uncle(100,20)\ngrand... |
code_contests | verifiable_code | 920_D. Tanks | Solve the following coding problem using the programming language python:
Petya sometimes has to water his field. To water the field, Petya needs a tank with exactly V ml of water.
Petya has got N tanks, i-th of them initially containing ai ml of water. The tanks are really large, any of them can contain any amount o... | ```python
import sys
n, k, v = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
if total < v:
print('NO')
exit()
dp = [[0]*k for _ in range(n+1)]
prev = [[-1]*(k+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(k):
if not dp[i][j]:
con... | vfc_71097 | {
"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 3 5\n2 3\n",
"output": "YES\n1 2 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 4\n2 3\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 949_B. A Leapfrog in the Array | Solve the following coding problem using the programming language python:
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he h... | ```python
import sys
input=sys.stdin.readline
n,q=list(map(int,input().split()))
for i in range(q):
a=int(input())
if a%2!=0:
print((a+1)//2)
else:
b=a//2
while 1>0:
a=a+(n-b)
b=a//2
if a%2!=0:
print((a+1)//2)
break... | vfc_71101 | {
"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": "13 4\n10\n5\n4\n8\n",
"output": "13\n3\n8\n9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 977_A. Wrong Subtraction | Solve the following coding problem using the programming language python:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
* if the last digit of the number is non-zero, ... | ```python
a, b = input().split(' ')
a=int(a)
for i in range(int(b)):
if (a%10 != 0):
a -= 1
else:
a /= 10
print(int(a))
``` | vfc_71105 | {
"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": "512 4\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 996_E. Leaving the Bar | Solve the following coding problem using the programming language python:
For a vector \vec{v} = (x, y), define |v| = √{x^2 + y^2}.
Allen had a bit too much to drink at the bar, which is at the origin. There are n vectors \vec{v_1}, \vec{v_2}, ⋅⋅⋅, \vec{v_n}. Allen will make n moves. As Allen's sense of direction is ... | ```python
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, per... | vfc_71109 | {
"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\n999999 0\n0 999999\n999999 0\n",
"output": "-1 -1 1 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | batman-vs-the-riddler | Solve the following coding problem using the programming language python:
Zubin is the dark messiah. He roams the streets at night, helping the poor and the innocent from evil. He's Batman.
Ghosh is Zubin's nemesis. He's the Riddler to Zubin's Batman. He delights in torturing people with his puzzles.
Tonight, Ghosh ha... | ```python
import math
t=input()
raw_input()
while t:
t-=1
n=input()
if (n==0 or n==1):
print 1
else:
print int(math.ceil((math.log(math.sqrt(2*math.pi*n))+n*math.log(n/math.e))/math.log(10)))
``` | vfc_71113 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n\n1\n5\n86\n23\n4\n\nSAMPLE",
"output": "1\n3\n131\n23\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n\n562189\n8112316\n9855612318\n8548\n12385561\n118\n0\n452157848\n44512\n855"... |
code_contests | verifiable_code | city-and-soldiers | Solve the following coding problem using the programming language python:
Today, King Trophies is on another rampage to destroy the small village controlled by Alex. Please help his soldiers.
At first, there are N individual soldiers, who haven't yet joined together; each of these soldiers is the leader of his/her ow... | ```python
def union(parents, i, j):
''' Union with under the deepest root '''
parents[i] = j
def find(parents, el):
''' Find an element and compress the sets '''
if parents[el] == el: return el
leader = find(parents, parents[el])
parents[el] = leader
return leader
def solve(n, xss):
re... | vfc_71117 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 1 2\n3 1\n\nSAMPLE",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 1 1\n3 1\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | even-divisors | Solve the following coding problem using the programming language python:
Tom gives a number N to Roy and ask him to tell the total number of even divisors of the number N. Help Roy to answer the question of Tom.
INPUT:
First line contains the number of testcases T, followed by T lines each containing an integer N. ... | ```python
def div(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
for _ in xrange(input()):
x= div(input())
print len([1 for i in x if i%2==0])
``` | vfc_71121 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n9\n8\n\nSAMPLE",
"output": "0\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | help-the-hungry-grasshopper | Solve the following coding problem using the programming language python:
Today grasshopper Jimmy Jumper is very hungry and his friend is notorious. Jimmy's friend puts an insect infront of him at a distance d. Jimmy can jump only a finite no of steps in each turn. Jimmy is initially at position 0. He can now jump 1 s... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
from math import sqrt
t=input()
while t>0:
t-=1
n=input()
a=0
b=1
while(a<n):
a+=b
b*=2
if n==a:
print"YES"
else:
print"NO"
``` | vfc_71125 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n15\n5\n\nSAMPLE",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n15\n5\n\nASMPLE",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | magic-fruit | Solve the following coding problem using the programming language python:
From the divine land of heaven came to earth a fruit known as Magic fruit.Unfortunately the fruit was found by two friends X and Y.
After lot of fighting,they came to the conclusion that they will share the fruit if and only if when they can div... | ```python
n=int(raw_input())
if(n==2 or n==0):
print "NO"
elif(n%2==0):
print "YES"
else:
print "NO"
``` | vfc_71129 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n\nSAMPLE",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | new-game-of-oz | Solve the following coding problem using the programming language python:
Today Oz is playing a new game. He has an array arr[] of N distinct integers . In each turn he is will follow two actions -
1) He select a random number from arr[]. Say value of this element is X.
2) He will remove X from arr[]. if X-1 is prese... | ```python
from math import ceil
def getCnt(n):
return int(round(float(n)/float(2)))
for t in xrange(input()):
L =input()
cnt = 0
ar = sorted(map(int,raw_input().split(' ')))
#print 'ar', ar
if not ar :
continue
elif L == 1:
print 1
continue
i = 1
seq_len = 1
while i < L:
#print i,ar[i-1]... | vfc_71133 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6\n291 292 295 297 298 299\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | professor-hatims-experiment | Solve the following coding problem using the programming language python:
Professor Hatim is researching the sexual behavior of a rare species of lizard. He assumes that they feature two different genders and that they only interact with lizard of the opposite gender. Each lizard has a integer printed on their back.
... | ```python
for _ in range(int(raw_input())):
n,m=map(int,raw_input().split())
a=[[] for i in range(n)]
color=[0]*n
def bipartite_visit(v,clr):
color[v]=clr
for i in range(len(a[v])):
if color[a[v][i]]==color[v]:
return 0
elif color[a[v][i]]==0:
... | vfc_71137 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3\n1 2\n2 3\n1 3\n4 2\n1 2\n3 4\n\nSAMPLE",
"output": "Suspicious lizards found!\nNo suspicious lizards found!\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3\n1 2\n2 3\n1 3\n4... |
code_contests | verifiable_code | sherlock-and-dice | Solve the following coding problem using the programming language python:
Sherlock rolls a N faced die M times. He adds all the numbers he gets on all throws. What is the probability that he has a sum of K.
A N faced die has all numbers from 1 to N written on it and each has equal probability of arriving when dice... | ```python
import sys
f = sys.stdin
dp = [0] * (51)
for i in range(0,51) :
dp[i] = [0] * (2501)
def solve(n,m,k) :
if m == 0 and k == 0 :
return 1
if m <= 0 :
return 0
if k <= 0 :
return 0
if dp[m][k] != -1 :
return dp[m][k]
dp[m][k] = 0
for i in range(1,n+1) :
dp[m][k] += solve(n,m-1,k-i)
return d... | vfc_71141 | {
"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 5 2\n2 3 2\n\nSAMPLE",
"output": "2.000 1\n1.111 1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | xenny-and-random-cubes-monk | Solve the following coding problem using the programming language python:
Xenny had N cubes. Each cube had six faces and each face had a Latin character on each of it's sides.
Xenny's friend Asdoc had an interesting activity in mind. He gave Xenny a string S and asked him to use the cubes to form that string. Xenny b... | ```python
MOD=1000000007
n,k =map(int, raw_input().split())
c=[]
for i in range(n):
c.append(raw_input().split())
s=raw_input()
def choose(l,chosen):
cnt=0
if l==k: return 1
for i in range(n):
if not (chosen & (1<<i)):
chosen |=1<<i
... | vfc_71149 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\na a a a a a\na a a a a a\nb b b b b b\nc c c c c c\nd d d d d d\nabcd\n\nSAMPLE",
"output": "2592",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 9\nd e b a e g\nd a e f a e\na b a e ... |
code_contests | verifiable_code | p00073 Surface Area of Quadrangular Pyramid | Solve the following coding problem using the programming language python:
Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also... | ```python
from math import sqrt
while True:
x, h = int(input()), int(input())
if x==h==0: break
sh = sqrt((x/2)**2 + h**2)
print((x*x) + sum([sh*x*0.5 for _ in range(4)]))
``` | vfc_71193 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4\n7\n9\n0\n0",
"output": "96.000000\n184.192455",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4\n5\n9\n0\n0",
"output": "96.0\n118.407708461\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p00205 Rock | Solve the following coding problem using the programming language python:
I decided to play rock-paper-scissors with a group of five good friends. Rock-paper-scissors has three hands: goo, choki, and par. If the game between goo and choki is a match between goo and choki, goo is "winning" and choki is "losing". , Par ... | ```python
d = {1:2, 2:3, 3:1}
while True:
h = int(input())
if h == 0:
break
h = [h] + [int(input()) for _ in range(4)]
if len(set(h)) == 3 or len(set(h)) == 1:
print(*[3]*5, sep='\n')
continue
for c in h:
print([2, 1][d[c] in h])
``` | vfc_71197 | {
"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": "1\n2\n3\n2\n1\n1\n2\n2\n2\n1\n0",
"output": "3\n3\n3\n3\n3\n1\n2\n2\n2\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n3\n2\n1\n1\n2\n2\n2\n1\n0",
"output": "3\n3\n3\n3\n3\n1\... |
code_contests | verifiable_code | p00719 Traveling by Stagecoach | Solve the following coding problem using the programming language python:
Once upon a time, there was a traveler.
He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in this problem is to write a program which determines the r... | ```python
INF = 10 ** 20
def search(rest, now, goal, dp, edges):
if now == goal:
return 0
if rest == ():
if now == goal:
return 0
else:
return INF
if (rest, now) in dp:
return dp[(rest, now)]
ret = INF
for i, t in enumerate(rest):
for dist, to in edges[now]:
ret = min(... | vfc_71209 | {
"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": "3 4 3 1 4\n3 1 2\n1 2 10\n2 3 30\n3 4 20\n2 4 4 2 1\n3 1\n2 3 3\n1 3 3\n4 1 2\n4 2 5\n2 4 3 4 1\n5 5\n1 2 10\n2 3 10\n3 4 10\n1 2 0 1 2\n1\n8 5 10 1 5\n2 7 1 8 4 5 6 3\n1 2 5\n2 3 4\n3 4 7\n4 5 3\n1 3 25\n2 4 23\n3 5 22\n1 4 45\n2 ... |
code_contests | verifiable_code | p00859 Slim Span | Solve the following coding problem using the programming language python:
Given an undirected weighted graph G, you should find one of spanning trees specified as follows.
The graph G is an ordered pair (V, E), where V is a set of vertices {v1, v2, ... , vn} and E is a set of undirected edges {e1, e2, ... , em}. Each... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_71213 | {
"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 5\n1 2 3\n1 3 5\n1 4 6\n2 4 6\n3 4 7\n4 6\n1 2 10\n1 3 100\n1 4 90\n2 3 20\n2 4 80\n3 4 40\n2 1\n1 2 1\n3 0\n3 1\n1 2 1\n3 3\n1 2 2\n2 3 5\n1 3 6\n5 10\n1 2 110\n1 3 120\n1 4 130\n1 5 120\n2 3 110\n2 4 120\n2 5 130\n3 4 120\n3 5 ... |
code_contests | verifiable_code | p01122 Flipping Colors | Solve the following coding problem using the programming language python:
<!--
Problem F
-->
Flipping Colors
You are given an undirected complete graph. Every pair of the nodes in the graph is connected by an edge, colored either red or black. Each edge is associated with an integer value called penalty.
By repea... | vfc_71221 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 3 1\n2 6\n-4\n3\n1 -10\n100\n5\n-2 -2 -2 -2\n-1 -1 -1\n-1 -1\n1\n4\n-4 7 6\n2 3\n-1\n0",
"output": "7\n11\n-1\n9",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01261 Bitwise Kingdom | Solve the following coding problem using the programming language python:
In the Bitwise Kingdom, located somewhere in the universe, there are exactly 2N citizens living and each of them has a unique identification string that represents his or her class in the society. An identification string is a binary string of l... | vfc_71225 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n3 5\n0 0",
"output": "010\n011",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n4 5\n0 0",
"output": "010\n1000\n",
"type": "stdin_stdout"
},
{
"fn_name": ... | |
code_contests | verifiable_code | p01421 Reverse Roads | Solve the following coding problem using the programming language python:
ICP city has an express company whose trucks run from the crossing S to the crossing T. The president of the company is feeling upset because all the roads in the city are one-way, and are severely congested. So, he planned to improve the maximu... | ```python
# AOJ 2304 Reverse Roads
# Python3 2018.7.21 bal4u
# *******************************************
# Dinic's Max Flow Algorithm
# *******************************************
INF = 0x7fffffff
class Donic:
def __init__(self, V):
self.V = V
self.level = [0] * V
self.iter = [0] * V
... | vfc_71229 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n2 1\n2 1",
"output": "1\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n2 1",
"output": "1\n1\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | p01575 Dungeon Master | Solve the following coding problem using the programming language python:
Once upon a time, in a fantasy world far, far away, monsters dug caves and dungeons for adventurers. They put some obstacles in their caves so it becomes more difficult and more exciting for the adventurers to reach the goal.
One day, Emils, on... | vfc_71233 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 2",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 1",
"output": "2",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01737 Spotlight Movement | Solve the following coding problem using the programming language python:
Ciel, an idol whose appearance and behavior are similar to a fox, is participating in a rehearsal for the live concert which takes place in a few days. To become a top idol, a large amount of effort is required!
The live stage can be expressed ... | vfc_71237 | {
"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": "2 1 1 9 -1\n2 2 1 1 -9 1\n1 2 -1 -1 9 -1",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 0 9 -1\n2 2 1 1 -9 1\n1 2 -1 -1 9 -1",
"output": "Yes\n",
"type": "s... | |
code_contests | verifiable_code | p02297 Area | Solve the following coding problem using the programming language python:
For a given polygon g, computes the area of the polygon.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of th... | ```python
x=range(int(input()))
P=[]
for _ in reversed(x):P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:_+=P[j+1][1]*P[j][0]-P[j][1]*P[j+1][0]
print(_*0.5)
``` | vfc_71253 | {
"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\n0 0\n1 1\n1 2\n0 2",
"output": "1.5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0\n2 2\n-1 1",
"output": "2.0",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | cg01 | Solve the following coding problem using the programming language python:
One day Chini while digging his ancestral farmland found the 2 boxes. He opened the 1st box, it was empty while in the second, there was 3 piles of gold coins. Whenever he chooses a pile of Y coins (y ≥ 1) from 2nd box, the coins in the 1st box... | ```python
def index(a):
m=0
ind=0
for i in range(len(a)):
if a[i]>m:
m=a[i]
ind=i
return ind
t=input()
while(t>0):
t-=1
a=map(int,raw_input().split())
n=input()
count=0
for i in range(n):
k=index(a)
if a[k]>=1:
count+=a[k]
... | vfc_71261 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 7 6\n3",
"output": "19",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | delsum | Solve the following coding problem using the programming language python:
You have a list of N numbers. You are deleting D numbers from the list. Print the minimum sum that can be obtained by adding the remaining numbers after deleting exactly D numbers from the list.
Input
The first line will contain an integer T ... | ```python
for i in range(input()):
test1 = map(int,raw_input().split())
test2 = map(int,raw_input().split())
test2.sort(reverse=True)
test3 = test2[test1[1]:len(test2)]
count = 0
for x in test3:
count += x
print count
``` | vfc_71265 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 3\n1 1 1 1 1\n2 1\n3 4",
"output": "2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 6\n1 1 1 1 1\n2 1\n3 4",
"output": "0\n3\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | iitk1p07 | Solve the following coding problem using the programming language python:
Given three integers x, m and n. Evaluate (1 + x + x^ 2 + .. + x^ m) (mod n)
Input
First line of the input contains a single integer T representing number of test cases that follow.
For next T lines, each line contains three space separate... | ```python
t=int(raw_input())
for _ in range(t):
x,m,n=map(int,raw_input().split())
if n==1:
print 0
elif x==1:
print (m+1)%n
else:
b = (x-1)*n
ans=pow(x,m+1,b)
ans-=1
ans%=b
ans/=x-1
print ans
``` | vfc_71269 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 2 5",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6 2 5",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1... |
code_contests | verifiable_code | nc1401 | Solve the following coding problem using the programming language python:
Haku Kale now wants to loot in a global scale. For that he needs the help of some underground gang leaders. But the problem is, he does not know the name of any gang leader. After a deep research, he got the name of gang leaders in an encrypted ... | ```python
t=input()
while t>0:
n=input()
B=[]
for i in xrange(n):
A=raw_input()
A=sorted(A)
B.append(A[len(A)/2])
print "".join(B)
t=t-1
``` | vfc_71273 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\nARCTV\nACADAPALA\nZHFGOSM\n4\nFJAOHVG\nAAAAA\nNUWRE\nIAT",
"output": "RAM\nHARI",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | rrplayer | Solve the following coding problem using the programming language python:
Petr, Nikita G. and Nikita are the most influential music critics in Saint-Petersburg. They have recently downloaded their favorite band's new album and going to listen to it. Nikita claims that the songs of entire album should be listened stric... | ```python
def expectation(n):
exp = 0.0
for i in range(1, n + 1):
exp += 1.0 / float(i)
print(exp * n)
t = input()
for i in range(0, t):
n = input()
expectation(n)
``` | vfc_71277 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3",
"output": "1.0\n3.0\n5.5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2\n2",
"output": "1.0\n3.0\n3.0\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 1023_A. Single Wildcard Pattern Matching | Solve the following coding problem using the programming language python:
You are given two strings s and t. The string s consists of lowercase Latin letters and at most one wildcard character '*', the string t consists only of lowercase Latin letters. The length of the string s equals n, the length of the string t eq... | ```python
#Stanley Tantysco - 2201814670
#Problem B - Wild Card
def str_limit(n):
if (n >= 1 and n <= 200000):
return True
else:
return False
def wild_counter(s):
count=0
for i in s:
if i == '*':
count += 1
if count <= 1:
return True
else:
re... | vfc_71285 | {
"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 10\ncode*s\ncodeforces\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 6\ngfgf*gfgf\ngfgfgf\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1044_B. Intersecting Subtrees | Solve the following coding problem using the programming language python:
You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's labelli... | ```python
import sys
from collections import deque
t=int(sys.stdin.readline())
for i in range(t):
n=int(sys.stdin.readline())#node
EDGE=[list(map(int,sys.stdin.readline().split())) for i in range(n-1)]
k1=int(sys.stdin.readline())
X=list(map(int,sys.stdin.readline().split()))
k2=int(sys.stdin.... | vfc_71289 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n1 2\n2 3\n1\n1\n1\n2\n2\n1\n",
"output": "B 2\nA 1\nC -1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1067_A. Array Without Local Maximums | Solve the following coding problem using the programming language python:
Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, ... | ```python
import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
MOD = 998244353
MODF = 1.0*MOD
from math import trunc
def quickmod(a):
return a-MODF*trunc(a/MODF)
def main():
n = int(input())
a = [int(i) for i in input().split()]
f0, f1 = [1.0] * 201, [0.0] * 201... | vfc_71293 | {
"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": "2\n-1 -1\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 -1 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1089_K. King Kog's Reception | Solve the following coding problem using the programming language python:
King Kog got annoyed of the usual laxity of his knights — they can break into his hall without prior notice! Thus, the King decided to build a reception with a queue where each knight chooses in advance the time when he will come and how long th... | vfc_71297 | {
"difficulty": "17",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "19\n? 3\n+ 2 2\n? 3\n? 4\n+ 5 2\n? 5\n? 6\n+ 1 2\n? 2\n? 3\n? 4\n? 5\n? 6\n? 7\n? 9\n- 8\n? 2\n? 3\n? 6\n",
"output": "0\n1\n0\n2\n1\n3\n2\n1\n2\n1\n0\n0\n2\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name":... | |
code_contests | verifiable_code | 1108_E1. Array and Segments (Easy version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is a number of elements in the array.
You are given an array a consisting of n integers. The value of the i-th element of the array is a_i.
You are also given a set of m segments. The j-th seg... | ```python
n,m=map(int, input().split())
a=list(map(int,input().split()))
i=0
l1=[]
l2=[]
while i<m:
e,f=map(int,input().split())
l1.append(e)
l2.append(f)
i+=1
i=0
j=0
ans=-1
s=[]
while i<n:
j=0
while j<n:
k=0
l=a[j]-a[i]
m1=[]
while k<m:
if l1[k]<=i+1... | vfc_71301 | {
"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 4\n2 -2 3 1 2\n1 3\n4 5\n2 5\n1 3\n",
"output": "6\n2\n1 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n2 -2 3 1 4\n3 5\n3 4\n2 4\n2 5\n",
"output": "7\n2\n2 3 \n",
... |
code_contests | verifiable_code | 1138_A. Sushi for Two | Solve the following coding problem using the programming language python:
Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers n pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy.
The pieces of sushi are of two ty... | ```python
n = int(input())
a = [int(s) for s in input().split()]
i = 0
j = 0
cur1 = 0
cur = 0
res = 0
b = a[0]
prev = 0
while j < n and a[j] == b:
j+=1
cur1 += 1
cur += 1
while i < n and j < n:
if b == 1:
b = 2
else:
b = 1
prev = cur
cur = 0
while j < n and a[j] == b:
... | vfc_71305 | {
"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 1 2 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n2 2 1 1 1 2 2 2 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1156_C. Match Points | Solve the following coding problem using the programming language python:
You are given a set of points x_1, x_2, ..., x_n on the number line.
Two points i and j can be matched with each other if the following conditions hold:
* neither i nor j is matched with any other point;
* |x_i - x_j| ≥ z.
What is the... | ```python
n,z=(int(i) for i in input().split())
k=0
x=sorted([int(i) for i in input().split()])
i,j=0,n//2
while i<n//2 and j<n:
if x[j]-x[i]>=z:
i+=1
k+=1
j+=1
print(k)
``` | vfc_71309 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 3 3 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n10 9 5 8 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1178_F1. Short Colorful Strip | Solve the following coding problem using the programming language python:
This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of m and the time limit. You need to solve both subtasks in order to hack this one.
There are n+1 distinct colours... | ```python
class SparseTable():
"""区間取得クエリをO(1)で答えるデータ構造をO(NlogN)で構築する
query(l, r): 区間[l, r)に対するクエリに答える
"""
def __init__(self, array, n):
n = len(array)
self.row_size = n.bit_length()
# log_tableを構築する
# log_table = [0, 0, 1, 1, 2, 2, 2, 2, ...]
self.log_table = [0... | vfc_71313 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7\n4 5 1 6 2 3 7\n",
"output": "165\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1196_E. Connected Component on a Chessboard | Solve the following coding problem using the programming language python:
You are given two integers b and w. You have a chessboard of size 10^9 × 10^9 with the top left cell at (1; 1), the cell (1; 1) is painted white.
Your task is to find a connected component on this chessboard that contains exactly b black cells ... | ```python
''' CODED WITH LOVE BY SATYAM KUMAR '''
from sys import stdin, stdout
import cProfile, math
from collections import Counter,defaultdict,deque
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as o... | vfc_71317 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n1 4\n2 5\n",
"output": "YES\n2 1\n2 2\nYES\n3 1\n3 2\n3 3\n2 2\n4 2\nYES\n3 1\n3 2\n3 3\n3 4\n3 5\n2 2\n4 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n370 123\n",
"ou... |
code_contests | verifiable_code | 1255_B. Fridge Lockers | Solve the following coding problem using the programming language python:
Hanh lives in a shared apartment. There are n people (including Hanh) living there, each has a private fridge.
n fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. T... | ```python
t = int(input())
for i in range(t):
n, m = map(int, input().split())
dop = list(map(int, input().split()))
suma = sum(dop)
mas = []
for i in range(n):
mas.append([dop[i], i])
if m < n or n == 2:
print (-1)
continue
mas.sort()
print(suma * 2 + (mas[0][0] + mas[1][0]) * (m - n))
for i in range(1,... | vfc_71329 | {
"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\n4 4\n1 1 1 1\n3 1\n1 2 3\n3 3\n1 2 3\n",
"output": "8\n1 2\n2 3\n3 4\n4 1\n-1\n12\n1 2\n2 3\n3 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1279_A. New Year Garland | Solve the following coding problem using the programming language python:
Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
The local store introduced a new service this year, called "Build your... | ```python
n = int(input())
for i in range(n):
l = [int(k) for k in input().split()]
l.sort()
if l[2] <= l[1]+l[0]+1 :
print("YES")
else :
print("NO")
``` | vfc_71333 | {
"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 3 3\n1 10 2\n2 1 1\n",
"output": "Yes\nNo\nYes\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1299_D. Around the World | Solve the following coding problem using the programming language python:
Guy-Manuel and Thomas are planning 144 trips around the world.
You are given a simple weighted undirected connected graph with n vertexes and m edges with the following restriction: there isn't any simple cycle (i. e. a cycle which doesn't pass... | vfc_71337 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 9\n1 2 0\n1 3 1\n2 3 9\n2 4 3\n2 5 4\n4 5 7\n3 6 6\n3 7 7\n6 7 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 2 27\n1 3 1\n1 4 1\n3 4 0\n",
"output": "6\... | |
code_contests | verifiable_code | 1322_B. Present | Solve the following coding problem using the programming language python:
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with ... | ```python
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
L = max(A).bit_length()+1
ans = 0
for l in range(L+1):
A1 = []
A2 = []
for a in A:
if a&(1<<l):
A1.append(a)
else:
A2.append(a)
A = A2 + A1
D = 1<<(l+1)
... | vfc_71341 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1341_A. Nastya and Rice | Solve the following coding problem using the programming language python:
Nastya just made a huge mistake and dropped a whole package of rice on the floor. Mom will come soon. If she sees this, then Nastya will be punished.
In total, Nastya dropped n grains. Nastya read that each grain weighs some integer number of g... | ```python
def main():
T = int(input())
for t in range(T):
n,a,b,c,d = list(map(int,input().split()))
pos = True
if((a-b)*n>(c+d)):
pos = False
elif((a-b)*n < (c-d)) and ((c-d)-(a-b)*n) > 2*b*n:
pos = False
print("YES") if pos else print("NO")
... | vfc_71345 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n7 20 3 101 18\n11 11 10 234 2\n8 9 7 250 122\n19 41 21 321 10\n3 10 8 6 1\n",
"output": "Yes\nNo\nYes\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n9 2 1 16 0\n",
"o... |
code_contests | verifiable_code | 1363_A. Odd Selection | Solve the following coding problem using the programming language python:
Shubham has an array a of size n, and wants to select exactly x elements from it, such that their sum is odd. These elements do not have to be consecutive. The elements of the array are not guaranteed to be distinct.
Tell him whether he can do ... | ```python
from sys import stdin,stdout
lis=lambda:list(map(int,input().split()))
Ma=lambda:map(int,input().split())
inte=lambda:int(input())
st=lambda:input()
import math
from collections import Counter
for i in range(inte()):
n,x=Ma()
a=lis()
o=0;e=0
for i in a:
if i%2==0:
e+=1
... | vfc_71349 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1\n999\n1 1\n1000\n2 1\n51 50\n2 2\n51 50\n3 3\n101 102 103\n",
"output": "YES\nNO\nYES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n4 3\n1 3 5 7\n",
"output": "Y... |
code_contests | verifiable_code | 1404_C. Fixed Point Removal | Solve the following coding problem using the programming language python:
Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated).
The weight of a is defined as the maximu... | ```python
'''explained excellently in editorial'''
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0... | vfc_71357 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 4 1 2 4\n0 0\n1 0\n",
"output": "2\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 5\n2 2 3 9 5 4 6 5 7 8 3 11 13\n3 1\n0 0\n2 4\n5 0\n0 12\n",
"output": "5\n11\n6\n1\n0... |
code_contests | verifiable_code | 1472_F. New Year's Puzzle | Solve the following coding problem using the programming language python:
Every year Santa Claus gives gifts to all children. However, each country has its own traditions, and this process takes place in different ways. For example, in Berland you need to solve the New Year's puzzle.
Polycarp got the following proble... | ```python
import sys
def solve():
sys.stdin.readline()
n, m = map(int,sys.stdin.readline().split())
dudes = []
for i in range(m):
r, c = map(int,sys.stdin.readline().split())
dudes.append((c,r))
dudes.sort()
dudes.reverse()
cells = []
while dudes:
if not cells or cells[-1][0]!=dudes[-1][0]:
cells.appe... | vfc_71369 | {
"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\n\n5 2\n2 2\n1 4\n\n3 2\n2 1\n2 3\n\n6 4\n2 1\n2 3\n2 4\n2 6\n",
"output": "\nYES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n\n5 2\n2 2\n1 4\n\n3 2\n2 1\n2 3\n\n6 4\n2 1\... |
code_contests | verifiable_code | 1520_F2. Guess the K-th Zero (Hard version) | Solve the following coding problem using the programming language python:
This is an interactive problem.
This is a hard version of the problem. The difference from the easy version is that in the hard version 1 ≤ t ≤ min(n, 10^4) and the total number of queries is limited to 6 ⋅ 10^4.
Polycarp is playing a computer... | ```python
n, t = map(int, input().split())
mem = {}
for _ in range(t):
k = int(input())
left, right = 1, n
while right > left:
mid = (left + right) // 2
if (left, mid) not in mem:
print(f'? {left} {mid}')
mem[(left, mid)] = mid - left + 1 - int(input())
nu... | vfc_71377 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\n\n2\n\n2\n\n1\n\n1\n\n0\n\n1\n\n0",
"output": "\n? 4 6\n\n? 1 1\n\n? 1 2\n\n? 5 5\n\n! 5\n\n? 2 2\n\n! 2\n\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 154_D. Flatland Fencing | Solve the following coding problem using the programming language python:
The King of Flatland will organize a knights' tournament! The winner will get half the kingdom and the favor of the princess of legendary beauty and wisdom. The final test of the applicants' courage and strength will be a fencing tournament. The... | ```python
x1, x2, a, b = map(int, input().split())
if a <= 0 <= b:
if x1 < x2:
if x2 - x1 <= b:
print("FIRST")
print(x2)
else:
print("DRAW")
else:
if x1 - x2 <= -a:
print("FIRST")
print(x2)
else:
print("DRAW"... | vfc_71381 | {
"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": "0 2 0 1\n",
"output": "DRAW\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 2 1 1\n",
"output": "SECOND\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 176_B. Word Cut | Solve the following coding problem using the programming language python:
Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation i... | ```python
# ------------------- fast io --------------------
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... | vfc_71385 | {
"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": "ab\nba\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ab\nab\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 196_D. The Next Good String | Solve the following coding problem using the programming language python:
In problems on strings one often has to find a string with some particular properties. The problem authors were reluctant to waste time on thinking of a name for some string so they called it good. A string is good if it doesn't have palindrome ... | vfc_71389 | {
"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\nabbabbbabbb\n",
"output": "abbbcaaabab\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 21_D. Traveling Graph | Solve the following coding problem using the programming language python:
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the ... | ```python
import math
N = 15
mat = 0
inf = 1000000000
answer = inf
def Get_Cycle_Length(v,graph):
global mat
global answer
if len(v) == 0:
answer = min(answer,mat)
return
end = v.pop()
i = 0
while i<len(v):
se = v.pop(i)
mat += graph[se][end]
Ge... | vfc_71393 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 1\n2 3 1\n3 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 2 3\n2 3 4\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 244_A. Dividing Orange | Solve the following coding problem using the programming language python:
One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k.
There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to ... | ```python
ar = []
for i in input().split():
ar.append(int(i))
ar2 = []
for i in input().split():
ar2.append(int(i))
temp = list(set(range(1, ar[0]*ar[1]+1))-set(ar2))
for i in range(len(ar2)):
res = []
res.append(ar2[i])
while (len(res) != ar[0]):
res.append(temp[0])
temp.pop(0)
... | vfc_71397 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n4 1\n",
"output": "4 2 \n1 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n2\n",
"output": "2 1 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 269_D. Maximum Waterfall | Solve the following coding problem using the programming language python:
Emuskald was hired to design an artificial waterfall according to the latest trends in landscape architecture. A modern artificial waterfall consists of multiple horizontal panels affixed to a wide flat wall. The water flows down the top of the ... | vfc_71401 | {
"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 5\n4 2 8\n3 1 2\n2 2 3\n2 6 12\n1 0 7\n1 8 11\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n4 1 6\n3 2 7\n5 9 11\n3 10 15\n1 13 16\n",
"output": "4\n",
... | |
code_contests | verifiable_code | 292_A. SMSC | Solve the following coding problem using the programming language python:
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC.
For that, he asked to give hi... | ```python
import re
import itertools
from collections import Counter, deque
class Task:
tasks = []
answer = ""
def getData(self):
numberOfTasks = int(input())
for i in range(0, numberOfTasks):
self.tasks += [[int(x) for x in input().split(' ')]]
#inFile = open('input.... | vfc_71405 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1000000 10\n",
"output": "1000010 10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 1\n2 1\n",
"output": "3 1",
"type": "stdin_stdout"
},
{
"fn_name": null... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.