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 | 1486_D. Max Median | Solve the following coding problem using the programming language python:
You are a given an array a of length n. Find a subarray a[l..r] with length at least k with the largest median.
A median in an array of length n is an element which occupies position number ⌊ (n + 1)/(2) ⌋ after we sort the elements in non-decr... | ```python
import collections
def solveTestCase():
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
r = n + 1
l = 1
while r - l > 1:
m = (r+l)//2
b = [1 if i >= m else -1 for i in a]
for i in range(1, len(b)):
b[i] += b[i - 1]
ans = False
if b[k-1] > 0:
ans = True
m... | vfc_65541 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 3 2 1\n",
"output": "\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1 2 3 4\n",
"output": "\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1510_D. Digits | Solve the following coding problem using the programming language python:
Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers a_i wr... | ```python
import math;n, d = map(int, input().split());a = [int(_) for _ in input().split()];dp = [[-1e10] * 10 for _ in range(n + 1)]
come = [[(0, 0, 0) for i in range(10)] for j in range(n + 1)];dp[0][1] = 0
for i in range(n):
for j in range(10):
val = dp[i][j] + math.log(a[i])
if dp[i + 1][(j * a... | vfc_65545 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n1 3 1 5 3\n",
"output": "\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\n4 11 8 2 1 13\n",
"output": "\n5\n1 2 4 11 13 \n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1536_F. Omkar and Akmar | Solve the following coding problem using the programming language python:
Omkar and Akmar are playing a game on a circular board with n (2 ≤ n ≤ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 ≤ i ≤ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empt... | ```python
import sys
input = sys.stdin.readline
n = int(input())
mod = 10 ** 9 + 7
F = [0] * (n + 1)
F[0] = 1
for i in range(1, n + 1):
F[i] = i * F[i - 1] % mod
iF = [0] * (n + 1)
iF[-1] = pow(F[-1], mod - 2, mod)
for i in range(n - 1, -1, -1):
iF[i] = iF[i + 1] * (i + 1) % mod
def C(n, k):
if k > n: ret... | vfc_65549 | {
"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": "69420\n",
"output": "\n629909355\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "42069\n",
"output": "\n675837193\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 163_E. e-Government | Solve the following coding problem using the programming language python:
The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis.
We know that any of the k citizens can become a member of the Embezzland govern... | vfc_65553 | {
"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": "7 3\na\naa\nab\n?aaab\n-2\n?aaab\n-3\n?aaab\n+2\n?aabbaa\n",
"output": "6\n4\n3\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\na\naa\nab\n?aaab\n-2\n?aaab\n-1\n?aaab\n+2\n?aabbaa\... | |
code_contests | verifiable_code | 185_A. Plant | Solve the following coding problem using the programming language python:
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and... | ```python
n=int(input())
e=10**9+7
print(1if n==0else(pow(2,n-1,e)+pow(2,n*2-1,e))%e)
# Made By Mostafa_Khaled
``` | vfc_65557 | {
"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\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 231_B. Magic, Wizardry and Wonders | Solve the following coding problem using the programming language python:
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That... | ```python
n, d, L = map(int, input().split())
sp = []
for _ in range(n - 1):
if d <= 0:
sp.append(1)
d = 1 - d
else:
sp.append(L)
d = L - d
if 1 <= d <= L:
sp.append(d)
print(*sp)
else:
print(-1)
``` | vfc_65565 | {
"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 3 2\n",
"output": "2 1 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 -4 4\n",
"output": "1 4 1 3 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 257_A. Sockets | Solve the following coding problem using the programming language python:
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices o... | ```python
n,m,k=map(int,input().split(" "))
li=list(map(int,input().split(" ",n)[:n]))
li.sort(reverse=True)
fl=0
a,s=0,0
if m<=k:
print(0)
else:
while fl==0 and a<n:
s+=li[a]
a+=1
if a!=1:
s-=1
if s+k-1>=m and a!=0:
fl=1
break
if fl!=1:
... | vfc_65569 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 7 2\n3 3 2 4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 280_A. Rectangle Puzzle | Solve the following coding problem using the programming language python:
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the... | ```python
from math import radians, cos, sin, atan2
def rotate(point, alpha):
x = point[0]
y = point[1]
return (x * cos(alpha) - y * sin(alpha), x * sin(alpha) + y * cos(alpha))
def crs(a, b):
return a[0] * b[1] - a[1] * b[0]
def m(end, start):
return (end[0] - start[0], end[1] - start[1])
def a... | vfc_65573 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 4 30\n",
"output": "19.668384968\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 45\n",
"output": "0.828427125\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 302_E. Yaroslav and Algorithm | Solve the following coding problem using the programming language python:
Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm consists of some number of command. Сommand number i looks either... | ```python
C = [
"??0>>0??",
"??1>>1??",
"??2>>2??",
"??3>>3??",
"??4>>4??",
"??5>>5??",
"??6>>6??",
"??7>>7??",
"??8>>8??",
"??9>>9??",
"??>>?",
"0?<>1",
"1?<>2",
"2?<>3",
"3?<>4",
"4?<>5",
"5?<>6",
"6?<>7",
"7?<>8",
"8?<>9",
"9?>>?0",
"?<>1",
"0>>??0",
"1>>??1",
"2>>??2",
"3>>??3",
"4>>??4", ... | vfc_65577 | {
"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\n10\n79\n",
"output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?\n",
"type": "s... |
code_contests | verifiable_code | 32_A. Reconnaissance | Solve the following coding problem using the programming language python:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his de... | ```python
n, d = [int(i) for i in input().split()]
S = sorted([int(i) for i in input().split()])
k = 0
for i in range(n):
for j in range(i+1, n):
if(S[j]-S[i]<=d):
k += 1
else:
break
print(k*2)
``` | vfc_65581 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n55 30 29 31 55\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 350_D. Looking for Owls | Solve the following coding problem using the programming language python:
Emperor Palpatine loves owls very much. The emperor has some blueprints with the new Death Star, the blueprints contain n distinct segments and m distinct circles. We will consider the segments indexed from 1 to n in some way and the circles — i... | vfc_65585 | {
"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 2\n3 2 3 -2\n0 0 2\n6 0 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n0 0 0 1\n0 -1 0 1\n0 -1 0 0\n2 0 1\n-2 0 1\n",
"output": "3\n",
"type": "stdin... | |
code_contests | verifiable_code | 374_E. Inna and Babies | Solve the following coding problem using the programming language python:
Inna, Dima and Sereja are in one room together. It's cold outside, so Sereja suggested to play a board game called "Babies".
The babies playing board is an infinite plane containing n blue babies and m red ones. Each baby is a segment that gro... | vfc_65589 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n2 2\n3 2\n6 2\n4 2\n5 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n2 2\n5 5\n3 7\n5 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 397_B. On Corruption and Numbers | Solve the following coding problem using the programming language python:
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to g... | ```python
t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
print("No" if n // l * r < n else "Yes")
``` | vfc_65593 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 2 3\n6 4 5\n",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n69 6 6\n22 1 1\n23 3 3\n60 13 13\n13 3 3\n7 4 7\n6 1 1\n49 7 9\n68 8 8\n20 2 2\n34 1 1\n79 5 5\n2... |
code_contests | verifiable_code | 41_C. Email address | Solve the following coding problem using the programming language python:
Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.c... | ```python
a = input()
b = ''
if a[0] + a[1] + a[2] == 'dot':
b += 'dot'
i = 3
elif a[0] + a[1] == 'at':
b += 'at'
i = 2
else:
i = 0
at = 0
while i < len(a) - 3:
if a[i] == 'd' and a[i + 1] == 'o' and a[i + 2] == 't':
b += '.'
i += 3
elif a[i] == 'a' and a[i + 1] == 't' and at... | vfc_65597 | {
"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": "vasyaatgmaildotcom\n",
"output": "vasya@gmail.com\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 446_A. DZY Loves Sequences | Solve the following coding problem using the programming language python:
DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment o... | ```python
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def msi(): return map(str,input().split())
def li(): return list(mi())
n=ii()
a=li()
pre,suf = [1]*n,[1]*n
for i in range(1,n):
if a[i]>a[i-1]:
pre[i]+=pre[i-1]
for i in range(n-2,-1,-1):
... | vfc_65601 | {
"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\n7 2 3 1 5 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 3 7 5 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 468_B. Two Sets | Solve the following coding problem using the programming language python:
Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:
* If number x belongs to set A, then number a - x must also belong to set A.
* If numb... | ```python
import sys
import queue
sys.setrecursionlimit(100000)
# global constant
INF = int(1e7+1)
MAX = 100005
# For testing
#sys.stdin = open("INP.txt", 'r')
#sys.stdout = open("OUT.txt", 'w')
# global variables
parents = []
ranks = []
size = []
n = 0
# classes
class Pair:
def __init__(self, a, b):
... | vfc_65605 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 4\n1 2 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5 9\n2 3 4 5\n",
"output": "YES\n0 0 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 490_B. Queue | Solve the following coding problem using the programming language python:
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so ... | ```python
import math
from collections import deque
class Empty(Exception):
pass
class _DoublyLinkedBase:
"""A base class providing a doubly linked list representation."""
#-------------------------- nested _Node class --------------------------
# nested _Node class
class _Node:
"""Lightweight, nonpub... | vfc_65609 | {
"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\n92 31\n0 7\n31 0\n7 141\n",
"output": "92 7 31 141\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n10001 0\n0 10005\n10003 10001\n10002 10000\n10005 10002\n10004 10003\n",
"out... |
code_contests | verifiable_code | 514_B. Han Solo and Lazer Gun | Solve the following coding problem using the programming language python:
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these s... | ```python
n, x0, y0 = map(int, input().split())
slopes = {} # key: (num, den), val: count
for i in range(n):
x, y = map(int, input().split())
num = y - y0
den = x - x0
# print(num, den)
if den == 0 and "inf" in slopes:
slopes["inf"] += 1
elif den == 0:
slopes["inf"] = 1
else... | vfc_65613 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 2\n1 1\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 540_C. Ice Cave | Solve the following coding problem using the programming language python:
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are... | ```python
import queue
MAX = 500
dr = [0,0,1,-1]
dc = [1,-1,0,0]
def isValid(r, c):
return r in range(m) and c in range(n)
def BFS(sr, sc, fr, fc):
q = [0] * (MAX * MAX)
left = right = 0
q[0] = (sr, sc)
while left <= right:
ur, uc = q[left]
left += 1
for i in range(4):
vr = ur + dr[i]
... | vfc_65617 | {
"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": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 58_B. Coins | Solve the following coding problem using the programming language python:
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction h... | ```python
def O(x):
l=[]
if x==1:
return 1
for i in range(1,x//2+1):
if x%i==0:
l.append(i)
print(x)
return O(l[len(l)-1])
x=int(input())
O(x)
print(1)
``` | vfc_65625 | {
"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\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "4 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n"... |
code_contests | verifiable_code | 611_D. New Year and Ancient Prophecy | Solve the following coding problem using the programming language python:
Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to understand the prophecy. But he knows digits!
One fragment of the prophecy is a sequence of n ... | ```python
import itertools
from pprint import pprint
M = 10**9+7
n = int(raw_input())
d = [int(c) for c in raw_input()]
comp = [[0]*(n+1) for i in range(n-1)]
for l in range(1,n):
num_eq = 0
for i in range(n-l):
j = i+l
if d[i] == d[j]:
num_eq += 1
if num_eq >= l:
... | vfc_65629 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n123434\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n20152016\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 631_A. Interview | Solve the following coding problem using the programming language python:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following probl... | ```python
read = lambda: map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
f1 = f2 = 0
for i in a: f1 |= i
for i in b: f2 |= i
print(f1 + f2)
``` | vfc_65633 | {
"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\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 4 3 2\n2 3 3 12 1\n",
"output": "22\n",
"type": "stdin... |
code_contests | verifiable_code | 65_D. Harry Potter and the Sorting Hat | Solve the following coding problem using the programming language python:
As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabetical order, each of them should put a ... | ```python
def g(s,i):
s=list(s)
s[i]+=1
return tuple(s)
p="GHRS"
a=["Gryffindor","Hufflepuff","Ravenclaw","Slytherin"]
input()
s=set([(0,0,0,0)])
for c in raw_input():
if c=='?':
t=set()
for x in s:
for i,m in enumerate(x):
if min(x)==m:
t.add(g(x,i))
else:
t=set([g(x,p.index(c)) for x in s])
s... | vfc_65637 | {
"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\nH?\n",
"output": "Gryffindor\nRavenclaw\nSlytherin\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\nG????SS???H\n",
"output": "Gryffindor\nRavenclaw\n",
"type": "stdin_st... |
code_contests | verifiable_code | 683_C. Symmetric Difference | Solve the following coding problem using the programming language python:
You are given two sets of numbers. Your task is to print all numbers from the sets, that both sets don't contain simultaneously.
Input
The first line contains the description of the first set, the second line contains the description of the se... | vfc_65641 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 2 3\n3 2 3 4\n",
"output": "2 1 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 4 8 9 10\n4 1 2 8 10\n",
"output": "3 2 4 9",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 706_B. Interesting drink | Solve the following coding problem using the programming language python:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in t... | ```python
def binary(t,s):
fir=0
last=len(t)-1
mid=0
while(fir<=last):
mid=(fir+last)//2
if t[mid]>s:
last=mid-1
else:
fir=mid+1
return last+1
n=int(input())
t=list(map(int,input().split()))
m=int(input())
p=0
t.sort()
for i in range(m):
... | vfc_65645 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n",
"output": "0\n4\n1\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n1\n100005\n",
"output": "3\n",
"type": "stdin_stdout"
},... |
code_contests | verifiable_code | 729_D. Sea Battle | Solve the following coding problem using the programming language python:
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn'... | ```python
n,a,b,k = map(int, input().split())
open = 0
must = 0
must_arr = []
for i,c in enumerate(input()):
if c == '1':
open = 0
else:
open += 1
if open == b:
open = 0
must += 1
if must >= a:
must_arr.append(i+1)
must -= a - 1
pr... | vfc_65649 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 2 1\n00100\n",
"output": "2\n2 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 3 2 3\n1000000010001\n",
"output": "2\n3 5 \n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 797_D. Broken BST | Solve the following coding problem using the programming language python:
Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written o... | ```python
from collections import deque
nodes = []
parents = []
values = []
broken = []
upperBound = []
lowerBound = []
n = int(input())
for _ in range(n):
v, l, r = map(int, input().split())
nodes.append((v, l - 1, r - 1))
parents.append(-1)
values.append(v)
broken.append(False)
upperBound.a... | vfc_65661 | {
"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": "8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n15 -1 -1\n10 1 3\n5 -1 -1\n",
"output": "2\n"... |
code_contests | verifiable_code | 843_A. Sorting by Subsequences | Solve the following coding problem using the programming language python:
You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence als... | ```python
n = int(input())
d = list(map(int, input().split()))
temp = d[:]
d.sort()
from bisect import bisect_left
A = [bisect_left(d,i) for i in temp]
del d,temp
f = [False]*len(A)
result = []
for i in range(n):
if not f[i]:
L = [i+1]
f[i] = True
j = A[i]
while j != i:
L.append(j+1)
... | vfc_65669 | {
"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\n83 -75 -49 11 37 62\n",
"output": "1\n6 1 2 3 4 5 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3 2 1 6 5 4\n",
"output": "4\n2 1 3 \n1 2 \n2 4 6 \n1 5 \n",
"type": "... |
code_contests | verifiable_code | 863_F. Almost Permutation | Solve the following coding problem using the programming language python:
Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug.
Ivan clearly remem... | ```python
import sys
def is_feasible(cnt,L,R):
n = len(R)
inter = [(L[i],R[i]) for i in range(n)]
AUX = []
feasible = True
for x in range(n):
for p in inter:
if p[0] == x:
AUX.append(p[1])
while AUX and min(AUX) < x:
AUX.remove(min(AUX))
for quantity in range(cnt[x]):
if AUX:
AUX.remov... | vfc_65673 | {
"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": "3 0\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 889_C. Maximum Element | Solve the following coding problem using the programming language python:
One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for f... | vfc_65677 | {
"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": "5 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n"... | |
code_contests | verifiable_code | 912_A. Tricky Alchemy | Solve the following coding problem using the programming language python:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and... | ```python
y,b=input().split(' ')
ay,ag,ab=input().split(' ')
y=int(y)
b=int(b)
ay=int(ay)
ag=int(ag)
ab=int(ab)
b=b-(ab*3)
y=y-(ay*2)
b=b-ag
y=y-ag
br=0
if(y<0):
br=br-y
if(b<0):
br=br-b
print(br)
``` | vfc_65681 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 9\n1 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 934_A. A Compatible Pair | Solve the following coding problem using the programming language python:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which f... | ```python
n, m = [int(x) for x in input().split()]
lstT = [int(x) for x in input().split()]
lstB = [int(x) for x in input().split()]
z=-9999999999999999999999999999
T=0
B=0
for i in range(n):
for j in range(m):
if z<lstT[i]*lstB[j]:
T=i
B=j
... | vfc_65685 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n20 18\n2 14\n",
"output": "252\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 960_C. Subsequence Counting | Solve the following coding problem using the programming language python:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in... | ```python
X, d = map(int, input().split())
x = X
ans = list()
ln = 0
last = 1
while x > 0:
if last >= 10 ** 18:
print(-1)
exit()
i = 0
while 2 ** (i + 1) - 1 <= x:
i += 1
t = 2 ** i - 1
x -= t
if ln + i > 10000:
print(-1)
exit()
for _ in range(i):... | vfc_65689 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n",
"output": "5\n1 1 1 6 6 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 987_F. AND Graph | Solve the following coding problem using the programming language python:
You are given a set of size m with integer elements between 0 and 2^{n}-1 inclusive. Let's build an undirected graph on these integers in the following way: connect two integers x and y with an edge if and only if x \& y = 0. Here \& is the [bit... | vfc_65693 | {
"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": "5 5\n5 19 10 20 12\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | alook-and-magic-spells | Solve the following coding problem using the programming language python:
Alook was composing magical spells for his mage master. The mage was good at spellcasting but since spell design requires intricate mathematics, this task was given to Alook who had the gift of numbers.
The power contained in a spell is a funct... | ```python
def matmult(a,b,c,M):
#/multiply matrix a and b. put result in c
for i in xrange(2):
for j in xrange(2):
c[i][j]=0
for k in xrange(2):
c[i][j]+=(a[i][k]*b[k][j])
c[i][j]=c[i][j]%M
... | vfc_65697 | {
"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\n2\n\nSAMPLE",
"output": "2\n14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n204810695\n1000000000\n43793483\n1000000000\n717792015\n1000000000\n790882847\n1000000000\n60783582\... |
code_contests | verifiable_code | cakewalk-3 | Solve the following coding problem using the programming language python:
You are given a collection of words, say as in a dictionary.
You can represent it in the following compressed form:
The first word will be followed by a sequence of pair of a integer (x) and a word.
The number in the pair is the position t... | ```python
N=input(); Q=raw_input();
for _ in xrange(N-1):
n,s=raw_input().split(); m=int(n);
temp=Q[:m]; temp+=s; Q=temp;
print Q
``` | vfc_65701 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nzebra\n3 u\n2 nith\n1 iggurat\n\nSAMPLE",
"output": "ziggurat\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nzebra\n3 u\n2 htin\n1 iggurat\n\nSAMPLE",
"output": "ziggurat\n",
... |
code_contests | verifiable_code | decimal-help | Solve the following coding problem using the programming language python:
Bosky often helps his younger brother Nitin with his home work and also clears his doubts.
Today, Nitin learned about proper fractions. He went a step forward and tried to represent the same proper fraction in its decimal form, but runs into pr... | ```python
def nth_digit(a,b,c):
r=a
digit=0
for _ in xrange(c):
if r==0:
return 0
digit=(r*10)/b
r=(r*10)%b
return digit
for _ in xrange(input()):
temp=map(int,raw_input().split())
a,b,c=temp[0],temp[1],temp[2]
print nth_digit(a,b,c)
``` | vfc_65705 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1\n1 2 2\n1 2 20\n1234 12345 123\n\nSAMPLE",
"output": "5\n0\n0\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n1 2 1\n1 2 2\n1234 12345 123\n1 9 5\n5 8 6\n5 8 2\n9 10 5\n1 ... |
code_contests | verifiable_code | game-of-strengths-4 | Solve the following coding problem using the programming language python:
Andrew is very fond of Maths.He has N boxes with him,in each box there is some value which represents the Strength of the Box.The ith box has strength A[i].
He wants to calculate the Overall Power of the all N Boxes.
Overall Power here means Su... | ```python
t = input()
while (t > 0):
n = input()
a = []
i = 0
line = raw_input().split(' ')
while(i < n) :
a.append(int(line[i]))
i = i+1
a.sort(reverse=True)
x = n-1
temp = 0
for i in range(0,n):
temp += x*a[i]
x -= 2
print (temp*a[0])%1000000007
t = t-1
``` | vfc_65709 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n1 2\n5\n4 5 3 1 2\n\nSAMPLE",
"output": "2\n100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n41\n18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 99... |
code_contests | verifiable_code | king-kala-and-the-partition-line | Solve the following coding problem using the programming language python:
After obtaining a lot of gold from capturing different kingdoms, King Kala buys a large area of land. N trees are planted on the land, numbered from 1 to N. Each tree i, has coordinates as Xi, Yi. King Kala has two sons who, as their father, are... | ```python
t=input()
count=0
count1=0
while (t):
n=input()
d=map(int,raw_input().strip().split(' '))
a=d[0]
b=d[1]
c=d[2]
for i in range (n):
x,y=raw_input().strip().split(' ')
x,y=[int(x),int(y)]
w=a*x+b*y+c
if(w>0):
count=count+1
elif(w=... | vfc_65713 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n1 -1 0\n2 1\n1 3\n4 2\n3 3\n\nSAMPLE",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n522\n1 -1 0\n878 -937\n-406 10\n-375 -375\n494 362\n-433 -433\n128 553\n869 -8... |
code_contests | verifiable_code | pandaland-and-strings | Solve the following coding problem using the programming language python:
Pandaland is a place full of strings. One day Panda visited Pandaland and get confused wether Pandaland is a lucky place or not. According to Panda a place is lucky if all the strings in that place follows the following property 'P' : -
P:A pla... | ```python
import sys
flag = True
class Node:
def __init__(self,c):
self.c = c
self.next = {}
self.cnt = 0
self.ends = 0
def insert(node, word):
for w in word:
if w not in node.next:
node.next[w] = Node(w)
node = node.next[w]
node.cnt += 1
... | vfc_65721 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\npan\npanda\nlucky\n\nSAMPLE",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n83\nlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqh... |
code_contests | verifiable_code | roy-and-cipher-disk | Solve the following coding problem using the programming language python:
Roy's friends has been spying on his text messages, so Roy thought of an algorithm to encrypt text messages.
Encryption Algorithm is as follows:
We say message to be encrypted as Plain Text and encrypted form of message as Cipher.
Plain Text ... | ```python
for _ in xrange(input()):
text = raw_input()
pos = 0
output = ''
for c in text:
move = (ord(c) - ord('a') - pos) % 26
output += str(move if move <= 13 else move - 26) + ' '
pos = pos + move
print output[:-1]
``` | vfc_65725 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\naeiou\nhackerearth\ncorrect\n\nSAMPLE",
"output": "0 4 4 6 6\n7 -7 2 8 -6 13 13 -4 -9 2 -12\n2 12 3 0 13 -2 -9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\ngrwctfse\nuiufoftt\nr... |
code_contests | verifiable_code | string-length-117 | Solve the following coding problem using the programming language python:
Given a string, find the length of string.
Input Format:
First line contains single integer t, the number of test-cases. Each of next t lines contains a string of lower case alphabets.
Output Format:
Output t lines, each containing the single ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
number=int(input())
while(number>0):
word=raw_input()
print(len(word))
number=number-1
``` | vfc_65729 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nhello\nheckerearth\n\nSAMPLE",
"output": "5\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15\nljrvkquqxvdncoqsgiwabycgfipahyutinqugkmffpshfkcnvynyxseccufjsbecouyufkzkzusggwtduhctz... |
code_contests | verifiable_code | use-bit | Solve the following coding problem using the programming language python:
The problem statement is simple. You are given a string and you are
supposed to print all the distinct permutations of the string, as they would appear in an dictionary.
INPUT
The first and only line of the input contains a single string, S.
... | ```python
from itertools import permutations
perms = [''.join(p) for p in permutations(raw_input())]
perms = list(set(perms))
perms.sort()
for i in xrange(len(perms)):
print perms[i]
``` | vfc_65733 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abc\n\nSAMPLE",
"output": "abc\nacb\nbac\nbca\ncab\ncba",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "`bc\n\nSAMPLE",
"output": "`bc\n`cb\nb`c\nbc`\nc`b\ncb`\n",
"type": "stdin... |
code_contests | verifiable_code | p02592 AtCoder Grand Contest 047 - Product Simulation | Solve the following coding problem using the programming language python:
This is an output-only problem. You shouldn't read anything from the input.
In short, your task is to simulate multiplication by using only comparison (x < y) and addition (x + y). There is no input in this problem, you just print a sequence of... | ```python
n=97
p=print
r=range
def a(i,j,k,l=0):p(chr(43+l*17),i,j,k)
def b(i):a(i,i,i+1)
def d(x,i,j):
for t in r(30):
b(j+t-1);a(j+t,n,j+t)
for s in r(j+t,j+29):b(s)
a(j+29,x,i+t,1);b(j+t-1);a(j+t,i+t,j+t)
p(3933)
a(0,1,n)
a(2,n,n,1)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
for t in r(59):
a(2,2,2)
for s in r(... | vfc_65737 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "",
"output": "",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00013 Switching Railroad Cars | Solve the following coding problem using the programming language python:
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 r... | ```python
stack = []
while True:
try:
n = int(input())
except:
break
if n == 0:
print(stack.pop())
else:
stack.append(n)
``` | vfc_65777 | {
"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\n6\n0\n8\n10\n0\n0\n0",
"output": "6\n10\n8\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6\n0\n8\n10\n0\n1\n0",
"output": "6\n10\n1\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00278 Study Session | Solve the following coding problem using the programming language python:
At Akabe High School, a programmer training school, there is a unique study session run by the students themselves. It is important for programmers to constantly adopt new technologies, so the aim of this activity is to develop the habit of self... | ```python
from bisect import bisect
import operator
import sys
from collections import defaultdict
readline = sys.stdin.readline
write = sys.stdout.write
N, Q = map(int, readline().split())
R = [int(readline()) for i in range(N)]
S = list(set(R))
S.sort()
mp = {e: i for i, e in enumerate(S)}
D = defaultdict(int)
T = ... | vfc_65785 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 8\n5\n10\n8\n7\n3\nADD 1\nADD 3\nCHECK 0\nCHECK 1\nCHECK 2\nCHECK 3\nCHECK 4\nCHECK 5",
"output": "NA\n2\n1\n0\n0\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 8\n5\n10\n8\n7\n3\nAD... |
code_contests | verifiable_code | p00466 Receipt | Solve the following coding problem using the programming language python:
problem
Taro bought 10 books. Later, I tried to find out the price based on the receipt, but the receipt was dirty and I could not read the price of a book. We decided to calculate the price of the book from the total price of 10 books and the ... | ```python
while 1:
n=int(input())
if n==0:
break
else:
for i in range(9):
b=int(input())
n-=b
print(n)
``` | vfc_65789 | {
"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": "9850\n1050\n800\n420\n380\n600\n820\n2400\n1800\n980\n0",
"output": "600",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9850\n1050\n800\n420\n380\n600\n820\n2400\n2983\n980\n0",
"outp... |
code_contests | verifiable_code | p00657 Rearranging Seats | Solve the following coding problem using the programming language python:
Haruna is a high school student. She must remember the seating arrangements in her class because she is a class president. It is too difficult task to remember if there are so many students.
That is the reason why seating rearrangement is depre... | ```python
while 1:
a,b=map(int,input().split())
if a==b==0: break
if a*b%2: print("no")
else: print("yes")
``` | vfc_65793 | {
"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 1\n2 2\n0 0",
"output": "no\nyes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n2 2\n0 0",
"output": "yes\nyes\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | p00801 Numoeba | Solve the following coding problem using the programming language python:
A scientist discovered a strange variation of amoeba. The scientist named it numoeba. A numoeba, though it looks like an amoeba, is actually a community of cells, which always forms a tree.
The scientist called the cell leader that is at the ro... | vfc_65797 | {
"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\n5\n7\n15\n655\n2711\n6395\n7195\n8465\n0",
"output": "2 3\n1 1\n9 11\n105 65\n398 332\n415 332\n430 332\n428 332\n190 421",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0\n7\n15\n655\... | |
code_contests | verifiable_code | p00932 Sweet War | Solve the following coding problem using the programming language python:
Example
Input
2 5 4
5 7
4 8
Output
8 7
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | vfc_65801 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5 4\n5 7\n4 8",
"output": "8 7",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01198 Dock to the Future | Solve the following coding problem using the programming language python:
You had long wanted a spaceship, and finally you bought a used one yesterday! You have heard that the most difficult thing on spaceship driving is to stop your ship at the right position in the dock. Of course you are no exception. After a dozen... | vfc_65809 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n2 4 6\n4\n10 100\n2 3\n10 6\n7 6",
"output": "crash\ntry again\ngood 1.000\nperfect",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n2 1 6\n4\n10 100\n2 3\n10 6\n7 6",
"outp... | |
code_contests | verifiable_code | p01502 Sightseeing Tour | Solve the following coding problem using the programming language python:
Example
Input
3
0 2 7
2 0 4
5 8 0
Output
11
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import sys
def main():
n = int(input())
edges = []
for i in range(n):
edges.append( list(map(int, sys.stdin.readline().split())) )
# ?±?????????????????????????????????°??????
# ????????????????????°?????????????????????????????????????????¨????????????
# ????????????????... | vfc_65817 | {
"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\n0 2 7\n2 0 4\n5 8 0",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 3 7\n2 0 4\n5 8 0",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | p01673 Revenge of Minimum Cost Flow | Solve the following coding problem using the programming language python:
G - Revenge of Minimum Cost Flow
Problem Statement
Flora is a freelance carrier pigeon. Since she is an excellent pigeon, there are too much task requests to her. It is impossible to do all tasks, so she decided to outsource some tasks to Indu... | vfc_65821 | {
"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 2 0 1 5\n0 1 3 0 3\n0 1 2 1 6",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 0 1 5\n0 1 3 0 3\n0 1 2 1 6",
"output": "9\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | p02383 Dice I | Solve the following coding problem using the programming language python:
Write a program to simulate rolling a dice, which can be constructed by the following net.
<image>
<image>
As shown in the figures, each face is identified by a different label from 1 to 6.
Write a program which reads integers assigned to... | ```python
num=list(map(int,input().split()))
s=input()
for i in s:
if i=='E':
num=[num[3],num[1],num[0],num[5],num[4],num[2]]
if i=='W':
num=[num[2],num[1],num[5],num[0],num[4],num[3]]
if i=='S':
num=[num[4],num[0],num[2],num[3],num[5],num[1]]
if i=='N':
num=[num[1],n... | vfc_65841 | {
"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 2 4 8 16 32\nEESWN",
"output": "32",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | aehash | Solve the following coding problem using the programming language python:
Chef Ash and Chef Elsh invented a new hash function! Their hash function will map a binary string consisting of characters 'A' and 'E' into an integer called the hash value of the string.
The pseudocode of the hash function is as below. hash(S) ... | ```python
import sys
import math
M = 1000000007
rs = {}
def fn(An, En, V):
global rs, M
if V < 0:
return 0
try:
return rs[An][En][V]
except:
if rs.has_key(An):
if not rs[An].has_key(En):
rs[An][En] = {}
else:
rs[An] = {}
... | vfc_65845 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0 0\n1 0 1\n3 2 6\n4 2 8",
"output": "1\n1\n3\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 0\n1 0 1\n3 2 12\n4 2 8",
"output": "1\n1\n0\n4\n",
"type": "stdin_... |
code_contests | verifiable_code | chefsqua | Solve the following coding problem using the programming language python:
Chef loves squares! You are given N points with integers coordinates, Chef asks you to find out how many points he should add to these set of N points, so that one could create at least one square having its vertices from the points of the resul... | ```python
n = input()
s = []
dic = {}
for i in range(n):
a = map(int,raw_input().split())
s.append(a)
foo = str(a[0])+','+str(a[1])
dic[foo] = 1
if n == 0:
print '4'
elif n == 1:
print '3'
elif n == 2:
print '2'
else:
ans = 2
for i in range(n-1):
for j in range(i+1,n):
... | vfc_65849 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 0\n100 100\n200 200\n100 0\n0 100",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0\n2 2\n3 3",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | drctnsrm | Solve the following coding problem using the programming language python:
Problem description.
Sumit is enjoying his vacations alone in a 2D world (yes, he knows magic), until his GPS tracker stopped working. The great thing about his GPS tracker is that it sends the direction of his traveled path from the starting of... | ```python
for _ in range(0,input()):
a,ns,ew=raw_input(),['SOUTH','','NORTH'],['WEST','','EAST']
print ns[int(round((a.count('N')-a.count('S'))/abs(a.count('N')-a.count('S')+.1)))+1]+ ew[int(round((a.count('E')-a.count('W'))/abs(a.count('E')-a.count('W')+.1)))+1]
``` | vfc_65853 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nNEW\nNNSSE\nNE",
"output": "NORTH\nEAST\nNORTHEAST",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | jntuv3 | Solve the following coding problem using the programming language python:
Problem Description.
Nithin proposed to his girl friend on valentines day. But she had kept a condition that if he answers her task then she will accept his proposal. As Nithin is new to programming, help him in solving the task. Your task is ... | ```python
import math
print math.factorial(int(raw_input()))
``` | vfc_65857 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5",
"output": "120",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6",
"output": "720\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1",
"ou... |
code_contests | verifiable_code | numbers | Solve the following coding problem using the programming language python:
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with t... | ```python
t=int(raw_input())
while(t):
t-=1
n=int(raw_input())
table={}
ans="Nobody wins."
while(n):
n-=1
name,num=map(str,raw_input().split())
num=int(num)
if num in table:
table[num].append(name)
else:
table[num]=[name]
for i in sorted(table):
if len(table[i])==1:
ans=table[i][0]
break... | vfc_65861 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\nKouta 1\nYuka 1\nMayu 3\nLucy 2\nNana 5\n2\nLucy 2\nNana 2",
"output": "Lucy\nNobody wins.\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\nKouta 1\nYuka 1\nMayu 3\nyucL 2\nNana... |
code_contests | verifiable_code | sislove | Solve the following coding problem using the programming language python:
Neha is a cute little sweet girl and considers herself as one of the luckiest girls in the world for having a caring and supporting family especially her cute little younger sister Shreya. But one fine day, due to the harsh side of fate, she los... | ```python
import sys
def main():
store={'one':1, 'two':2, 'three':3, 'four': 4, 'five' : 5, 'six' : 6,
'seven' : 7, 'eight' : 8, 'nine' : 9, 'zero' : 0}
array=['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
'nine', 'zero']
t=int(sys.stdin.readline())
for i... | vfc_65865 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nowe\nseren\nrix",
"output": "1\n7\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\newo\nseren\nrix",
"output": "2\n7\n6\n\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1004_C. Sonya and Robots | Solve the following coding problem using the programming language python:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the le... | ```python
n=int(input())
a=[int(i) for i in input().split()]
dic={}
dic1={}
arr=[0]*(n)
count1=0
#print(arr)
for i in range(n-1,0,-1):
if(a[i] not in dic.keys()):
dic[a[i]]=1
count1+=1
arr[i-1]=count1
#print(dic,count1)
count=0
#print(arr)
for i in range(n-1):
if(a[i] not in dic1.keys()):
dic1[a[i]]=1
count... | vfc_65869 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 5 4 1 3\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1028_C. Rectangles | Solve the following coding problem using the programming language python:
You are given n rectangles on a plane with coordinates of their bottom left and upper right points. Some (n-1) of the given n rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or bel... | ```python
r=range(int(input()))
def s(a,b):
(c,d,e,f),(g,h,i,j)=a,b;return max(c,g),max(d,h),min(e,i),min(f,j)
def p(a):
b=[a[0]]
for i in range(1,len(a)):
b+=[s(b[i-1],a[i])]
return b
H=9**15
B=(-H,-H,H,H)
a=[B]+[tuple(map(int,input().split())) for i in r]+[B]
b=p(a)
c=p(a[::-1])[::-1]
for i in r:
I,J,K,L=s(b[i... | vfc_65873 | {
"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\n0 0 5 5\n0 0 4 4\n1 1 4 4\n1 1 4 4\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0 10 8\n1 2 6 7\n2 3 5 6\n3 4 4 5\n8 1 9 2\n",
"output": "3 4\n",
... |
code_contests | verifiable_code | 1046_I. Say Hello | Solve the following coding problem using the programming language python:
Two friends are travelling through Bubble galaxy. They say "Hello!" via signals to each other if their distance is smaller or equal than d_1 and
* it's the first time they speak to each other or
* at some point in time after their last ta... | ```python
from sys import stdin
stdin = iter(stdin)
class Vector:
''''''
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, other):
return Vector(self.x - other.x, self.y - other.y)
def __add__(self, other):
return Vector(self.x + other.x, self.y + othe... | vfc_65877 | {
"difficulty": "15",
"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 5\n0 0 0 10\n5 5 5 6\n5 0 10 5\n14 7 10 5\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n20 50\n41 176 16 161\n103 169 113 199\n74 46 79 16\n",
"output": "1",... |
code_contests | verifiable_code | 1070_H. BerOS File Suggestion | Solve the following coding problem using the programming language python:
Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature.
There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 cha... | ```python
smpl = {}
cntr = {}
def handle(s):
cur = set()
for i in range(len(s)):
for j in range(i + 1, len(s) + 1):
cur.add(s[i:j])
# print(cur)
for c in cur:
if c not in cntr:
cntr[c] = 0
cntr[c] += 1
smpl[c] = s
n = int(input())
for i in range(n):
s = input()
handle(s)
q = int(input())
for i in ... | vfc_65881 | {
"difficulty": "14",
"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\ntest\ncontests\ntest.\n.test\n6\nts\n.\nst.\n.test\ncontes.\nst\n",
"output": "1 contests\n2 .test\n1 test.\n1 .test\n0 -\n4 .test\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\ntes... |
code_contests | verifiable_code | 1092_D1. Great Vova Wall (Version 1) | Solve the following coding problem using the programming language python:
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresent... | ```python
n = int(input())
a = list(map(int,input().split()))
for i in range(n) : a[i] &= 1
b = list(a)
for i in range(n) : b[i] = a[i]^1
def check(a):
n = len(a)
s1,s2 = 0,0
for i in range(n):
if(i&1 == 0): s1 += a[i]
else : s2 += a[i]
diff = abs(s1-s2)
if(diff%3 == 0): return True
return False
possible... | vfc_65885 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 1 1 2 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 5 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1140_G. Double Tree | Solve the following coding problem using the programming language python:
You are given a special undirected graph. It consists of 2n vertices numbered from 1 to 2n. The following properties hold for the graph:
* there are exactly 3n-2 edges in the graph: n edges connect vertices having odd numbers with vertices ha... | vfc_65893 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 10, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 6 15 4 8\n1 2 5 4\n2 3 5 7\n1 4 1 5\n1 5 2 1\n3\n1 2\n5 6\n1 10\n",
"output": "3\n15\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 6 15 4 8\n1 2 5 4\n2 3 5 7\n1 4 1 5\n1 5 2... | |
code_contests | verifiable_code | 1159_E. Permutation recovery | Solve the following coding problem using the programming language python:
Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is e... | ```python
import sys
from array import array # noqa: F401
from typing import List, Tuple, TypeVar, Generic, Sequence, Union # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def main():
t = int(input())
ans = ['-1'] * t
for ti in range(t):
n = int(input())
... | vfc_65897 | {
"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": "6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n",
"output": "1 2 3\n2 1\n1 2 3\n-1\n1\n3 1 2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3\n2 3 4\n2\n3 3\n3\n-1 -... |
code_contests | verifiable_code | 1181_E1. A Story of One Country (Easy) | Solve the following coding problem using the programming language python:
This problem differs from the next problem only in constraints.
Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusual.
Initially, there were n different countries on the lan... | vfc_65901 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0 1 2\n0 2 1 3\n1 0 2 1\n1 1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 2 1\n1 2 3 3\n2 0 3 2\n0 1 1 3\n",
"output": "NO\n",
"type": "st... | |
code_contests | verifiable_code | 119_D. String Transformation | Solve the following coding problem using the programming language python:
Let s be a string whose length equals n. Its characters are numbered from 0 to n - 1, i and j are integers, 0 ≤ i < j < n. Let's define function f as follows:
f(s, i, j) = s[i + 1... j - 1] + r(s[j... n - 1]) + r(s[0... i]).
Here s[p... q] is ... | vfc_65905 | {
"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": "123342\n3324212\n",
"output": "-1 -1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "cbaaaa\naaaabc\n",
"output": "4 5\n",
"type": "stdin_stdout"
},
{
"fn_name": ... | |
code_contests | verifiable_code | 1217_B. Zmei Gorynich | Solve the following coding problem using the programming language python:
You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!
<image>
Initially Zmei Gorynich has x heads. You can deal n types of blows. If you deal a blow of the i-th type, you ... | ```python
#!/usr/bin/env python3
import sys
def rint():
return map(int, sys.stdin.readline().split())
#lines = stdin.readlines()
t = int(input())
for tt in range(t):
n, x = rint()
d_max = -1
diff_max = -1
for i in range(n):
dd, hh = rint()
d_max = max(d_max, dd)
diff_max ... | vfc_65909 | {
"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\n3 10\n6 3\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100\n",
"output": "2\n3\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 1\n2 2\n1 1\n",
"output": "1\n",
... |
code_contests | verifiable_code | 123_D. String | Solve the following coding problem using the programming language python:
You are given a string s. Each pair of numbers l and r that fulfill the condition 1 ≤ l ≤ r ≤ |s|, correspond to a substring of the string s, starting in the position l and ending in the position r (inclusive).
Let's define the function of two ... | vfc_65913 | {
"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": "aaaa\n",
"output": " 20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abacabadabacaba\n",
"output": " ... | |
code_contests | verifiable_code | 125_E. MST Company | Solve the following coding problem using the programming language python:
The MST (Meaningless State Team) company won another tender for an important state reform in Berland.
There are n cities in Berland, some pairs of the cities are connected by roads. Each road has its price. One can move along any road in any di... | vfc_65917 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 2\n1 2 1\n2 3 1\n3 4 1\n1 3 3\n1 4 2\n",
"output": "3\n1 5 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 20 4\n1 4 6\n3 9 3\n8 9 9\n2 10 10\n6 4 5\n8 7 1\n8 4 2\n10 1 3\n4 7 5\... | |
code_contests | verifiable_code | 1282_A. Temporarily unavailable | Solve the following coding problem using the programming language python:
Polycarp lives on the coordinate axis Ox and travels from the point x=a to x=b. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis Ox at the point x=c the base station of the mobile operator is placed. I... | ```python
kl=int(input())
for l in range(kl):
p=[int(i) for i in input().split()]
a=min(p[0], p[1])
b=max(p[0], p[1])
tn=p[2]-p[3]
tk=p[2]+p[3]
if tn>=b or tk<=a:
print(b-a)
else:
if tn>=a:
print((b-a) - (min(b, tk)-tn))
else:
print((b-a) -(min... | vfc_65921 | {
"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": "9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n",
"output": "7\n0\n4\n0\n30\n5\n4\n0\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1302_A. Nash equilibrium | Solve the following coding problem using the programming language python:
This is an unusual problem in an unusual contest, here is the announcement: [http://codeforces.com/blog/entry/73543](//codeforces.com/blog/entry/73543)
You are given a table A of integers n × m. The cell (x, y) is called Nash equilibrium if bot... | vfc_65925 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 2 3 4\n1 2 3 5\n1 2 3 6\n2 3 5 7\n",
"output": "\n1 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n7 7 7 7 7\n7 7 7 7 7\n7 7 7 7 7\n",
"output": "\n0 0\n",
"type... | |
code_contests | verifiable_code | 1326_A. Bad Ugly Numbers | Solve the following coding problem using the programming language python:
You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers:
In the decimal representation of s:
* s > 0,
* s consists of n digits,
* no digit in s equals 0,
* s ... | ```python
t = int(input())
for i in range(t):
n = int(input())
if n == 1:
print(-1)
else:
base = int('2' * n) + 1
print(int('2' + '3' * (n - 1)))
``` | vfc_65929 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n3\n4\n",
"output": "-1\n23\n233\n2333\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1344_F. Piet's Palette | Solve the following coding problem using the programming language python:
Piet Mondrian is an artist most famous for his minimalist works, consisting only of the four colors red, yellow, blue, and white. Most people attribute this to his style, but the truth is that his paint behaves in a very strange way where mixing... | vfc_65933 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\nmix 1 2 Y\nRB 1 2\nmix 1 2 W\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\nRY 1 1\nYB 1 1\nmix 1 1 B\n",
"output": "YES\nR\n",
"type": "stdin_stdo... | |
code_contests | verifiable_code | 1366_F. Jog Around The Graph | Solve the following coding problem using the programming language python:
You are given a simple weighted connected undirected graph, consisting of n vertices and m edges.
A path in the graph of length k is a sequence of k+1 vertices v_1, v_2, ..., v_{k+1} such that for each i (1 ≤ i ≤ k) the edge (v_i, v_{i+1}) is p... | ```python
import sys
n,m,q=map(int,input().split())
mod,mxw = 1000000007,0;wgts,neig=[0]*n,[0]*n
for i in range(n):
neig[i]=[0]
for i in range(m):
a,b,w=map(int,input().split())
a-=1;b-=1;neig[a][0]+=1;neig[b][0]+=1;neig[a].append([b,w]);neig[b].append([a,w])
mxw=max(mxw,w);wgts[a]=max(wgts[a],w);wgts[... | vfc_65937 | {
"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": "15 15 23\n13 10 12\n11 14 12\n2 15 5\n4 10 8\n10 2 4\n10 7 5\n3 10 1\n5 6 11\n1 13 8\n9 15 4\n4 2 9\n11 15 1\n11 12 14\n10 8 12\n3 6 11\n",
"output": "3250",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1387_B2. Village (Maximum) | Solve the following coding problem using the programming language python:
This problem is split into two tasks. In this task, you are required to find the maximum possible answer. In the task Village (Minimum) you are required to find the minimum possible answer. Each task is worth 50 points.
There are N houses in a ... | ```python
import sys;range = xrange;input = raw_input;inp = [int(x) for x in sys.stdin.read().split()]; ii = 0;n = inp[ii]; ii += 1;coupl = [[] for _ in range(n)]
for _ in range(n - 1):u = inp[ii] - 1; ii += 1;v = inp[ii] - 1; ii += 1;coupl[u].append(v);coupl[v].append(u)
root = 0;bfs = [root]
for node in bfs:
for ... | vfc_65941 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 750000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n4 2\n5 7\n3 4\n6 3\n1 3\n4 5\n",
"output": "18\n4 1 5 6 2 7 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2\n2 3\n3 4\n",
"output": "8\n4 3 2 1 ",
"type": "stdin_st... |
code_contests | verifiable_code | 1408_F. Two Different | Solve the following coding problem using the programming language python:
You are given an integer n.
You should find a list of pairs (x_1, y_1), (x_2, y_2), ..., (x_q, y_q) (1 ≤ x_i, y_i ≤ n) satisfying the following condition.
Let's consider some function f: N × N → N (we define N as the set of positive integers).... | ```python
import sys
readline = sys.stdin.readline
N = int(readline())
if N == 1:
print(0)
else:
BN = 1
while BN*2 <= N:
BN*= 2
Ans = []
for i in range(BN.bit_length()):
d = 1<<i
for j in range(1, BN+1, 2*d):
if j+d > BN:
break
for k in... | vfc_65945 | {
"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": "4\n",
"output": "8\n1 2\n3 4\n1 3\n2 4\n1 2\n3 4\n1 3\n2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "2\n1 2\n2 3\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1428_H. Rotary Laser Lock | Solve the following coding problem using the programming language python:
This is an interactive problem.
To prevent the mischievous rabbits from freely roaming around the zoo, Zookeeper has set up a special lock for the rabbit enclosure. This lock is called the Rotary Laser Lock.
The lock consists of n concentric ... | ```python
import sys;Z=sys.stdin.readline
def P(d=1,x=0):
print('?',x,2*d-1);sys.stdout.flush()
return int(Z())
def poke(n):
global K,S,C,L
h=len(S);l=0;D=[0]*h
while h-l>1:
m=(l+h)//2;d=1-D[l]
for i in range(m-l):
v=P(d,S[l+i]);D[l+i]=d
if v<P()+n:
if... | vfc_65949 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n0\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 7\n",
"output": "32\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1452_D. Radio Towers | Solve the following coding problem using the programming language python:
There are n + 2 towns located on a coordinate line, numbered from 0 to n + 1. The i-th town is located at the point i.
You build a radio tower in each of the towns 1, 2, ..., n with probability 1/2 (these events are independent). After that, yo... | ```python
def power(a, b, mod):
res = 1
while b:
if b%2:
res = (res*a)%mod
b //= 2
a = (a*a)%mod
return res%mod
def divide(a, b, mod):
return (a * power(b, mod-2, mod)) % mod
n = int(input())
MOD = 998244353
fib = [0, 1]
for i in rang... | vfc_65953 | {
"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": "5\n",
"output": "\n842268673\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1476_B. Inflation | Solve the following coding problem using the programming language python:
You have a statistic of price changes for one product represented as an array of n positive integers p_0, p_1, ..., p_{n - 1}, where p_0 is the initial price of the product and p_i is how the price was increased during the i-th month.
Using the... | ```python
T=int(input())
while(T):
T-=1
(n,k)=input().split()
n=int(n)
k=int(k)
a=[int(n) for n in input().split()]
s=0
for i in range(n):
s+=a[i]
ans=0
for i in range(n-1,0,-1):
s-=a[i]
t=int((a[i]*100-1)/k)+1
if s<t :
ans+=t-s
... | vfc_65957 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n20100 1 202 202\n3 100\n1 1 1\n",
"output": "\n99\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 3\n97 2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1501_A. Alexey and Train | Solve the following coding problem using the programming language python:
Alexey is travelling on a train. Unfortunately, due to the bad weather, the train moves slower that it should!
Alexey took the train at the railroad terminal. Let's say that the train starts from the terminal at the moment 0. Also, let's say th... | ```python
import sys,os,io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range (int(input())):
n = int(input())
a = []
b = []
for i in range (n):
ai,bi =[int(i) for i in input().split()]
a.append(ai)
b.append(bi)
t = [int(i) for i in input().split()]
... | vfc_65961 | {
"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\n2\n2 4\n10 12\n0 2\n5\n1 4\n7 8\n9 10\n13 15\n19 20\n1 2 3 4 5\n",
"output": "\n12\n32\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n1 8\n0\n",
"output": "1\n",
"typ... |
code_contests | verifiable_code | 1526_C2. Potions (Hard Version) | Solve the following coding problem using the programming language python:
This is the hard version of the problem. The only difference is that in this version n ≤ 200000. You can make hacks only if both versions of the problem are solved.
There are n potions in a line, with potion 1 on the far left and potion n on th... | ```python
#!/usr/bin/env pypy
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from heapq import heappush, heappop
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
MOD = 10**... | vfc_65965 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4 -4 1 -3 1 -3\n",
"output": "\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 158_A. Next Round | Solve the following coding problem using the programming language python:
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in ... | ```python
x,y=map(int,input().split())
z = list(map(int,input().split()))
i=0
count=0
for i in range (0,x):
if z[i] > 0:
if z[i] >= z[y-1]:
count=count+1
print(count)
``` | vfc_65969 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n0 0 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 5\n10 9 8 7 7 7 5 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1_B. Spreadsheets | Solve the following coding problem using the programming language python:
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 ... | ```python
import re
def from_excel(item):
row = ''.join([s for s in item if s.isdigit()])
column = excel_to_column(item.replace(row, ''))
return 'R{0}C{1}'.format(row, column)
def to_excel(item):
row, column = item.split('C')
row, column = int(row.replace('R', '')), int(column)
column = colu... | vfc_65977 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 10, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nR23C55\nBC23\n",
"output": "BC23\nR23C55\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nA1\n",
"output": "R1C1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 224_C. Bracket Sequence | Solve the following coding problem using the programming language python:
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the orig... | ```python
s = input()
st, v, vi, vj, vc = [], [], 0, 0, 0
for i, c in enumerate(s):
if c in '[(':
st.append(i)
continue
if st and s[st[-1]] + c in ('()', '[]'):
b = (st[-1], i+1)
if v and v[-1][1] == i: v[-1] = b
else: v.append(b)
if len(v) >= 2 and v[-2][1] == v[... | vfc_65981 | {
"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": "([])\n",
"output": "1\n([])\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 249_A. Robo-Footballer | Solve the following coding problem using the programming language python:
It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guy... | ```python
y1, y2, w, x, y, r = map(int, input().strip().split())
w -= r
y1 = 2 * w - y1 - y - r
y2 = 2 * w - y2 - y
if x * x * (y2 - y1) * (y2 - y1) <= (y1 * y1 + x * x) * r * r:
print(-1)
else:
print(f"{x * (y1 + y - w) / y1:.10f}")
``` | vfc_65985 | {
"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 4 6 2 2 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 10 13 10 3 1\n",
"output": "4.375000000000",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 273_B. Dima and Two Sequences | Solve the following coding problem using the programming language python:
Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be ... | ```python
from collections import defaultdict
def factorial(n, m, rep):
r = 1
for i in range(2, n + 1):
j = i
while j % 2 == 0 and rep > 0:
j = j// 2
rep -= 1
r *= j
r %= m
return r
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,in... | vfc_65989 | {
"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\n1\n2\n7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n2 3\n11\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 296_D. Greg and Graph | Solve the following coding problem using the programming language python:
Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game:
* The game consists of... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def solve():
n = int(input())
matrix = [array('i', list(map(int, input().split()))) for _ in range(n)]
a = tuple(map(lambda x: int(x) - 1, input().split()))
ans = [''] * n
... | vfc_65993 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n0\n1\n",
"output": "0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 5\n4 0\n1 2\n",
"output": "9 0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 31_B. Sysadmin Bob | Solve the following coding problem using the programming language python:
Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This li... | ```python
def main():
string = input()
comps = string.split('@')
ans = []
if '@' not in string:
print("No solution")
return
for i in range(len(comps)):
if i == 0 or i == len(comps) - 1:
if len(comps[i]) < 1:
print("No solution")
ret... | vfc_65997 | {
"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": "@aa@a\n",
"output": "No solution\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a@aa@a\n",
"output": "a@a,a@a\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 344_B. Simple Molecules | Solve the following coding problem using the programming language python:
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.
A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — th... | ```python
a,b,c=map(int,input().split())
s=(a+b+c)//2
if (a+b+c)%2!=0 or s-a<0 or s-b<0 or s-c<0:
print("Impossible")
else:
print(s-c,s-a,s-b)
``` | vfc_66001 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 1\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 5\n",
"output": "1 3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 367_D. Sereja and Sets | Solve the following coding problem using the programming language python:
Sereja has m non-empty sets of integers A1, A2, ..., Am. What a lucky coincidence! The given sets are a partition of the set of all integers from 1 to n. In other words, for any integer v (1 ≤ v ≤ n) there is exactly one set At such that <image>... | vfc_66005 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3 1\n4 1 3 5 7\n2 2 6\n1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 2\n1 2\n2 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"... | |
code_contests | verifiable_code | 411_B. Multi-core Processor | Solve the following coding problem using the programming language python:
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do not... | ```python
n,m,k=map(int,input().split())
L=[]
for i in range(n):
L.append(list(map(int,input().split())))
Locked=[-1]*n
Z={}
for i in range(m):
K={}
for j in range(n):
if(Locked[j]!=-1):
continue
if(L[j][i] in K):
K[L[j][i]].append(j)
else:
K[L[j]... | vfc_66013 | {
"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 1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 2\n1 2\n1 2\n2 2\n",
"output": "1\n1\n0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 439_A. Devu, the Singer and Churu, the Joker | Solve the following coding problem using the programming language python:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the ... | ```python
a,b=input().split()
a=int(a)
b=int(b)
clist=list(map(int,input().split()))
sumi=sum(clist)
d=b-sumi
if(d>=(a-1)*10):
print(d//5)
else:
print("-1")
``` | vfc_66017 | {
"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 20\n2 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 30\n2 2 1\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 460_C. Present | Solve the following coding problem using the programming language python:
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and... | ```python
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.... | vfc_66021 | {
"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 5 1\n5 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2 3\n2 2 2 2 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 484_B. Maximum Value | Solve the following coding problem using the programming language python:
You are given a sequence a consisting of n integers. Find the maximum possible value of <image> (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
Input
The first line contains integer n — the length of the sequence (1 ≤ ... | ```python
"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
from types import GeneratorType
BUFSIZE = 8192
class SortedList:
def __init__(self, iterable=[], _load=... | vfc_66025 | {
"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\n3 4 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 508_B. Anton and currency you all know | Solve the following coding problem using the programming language python:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have ... | ```python
n=list(input())
k=int(n[-1])
m=0
for i in range(len(n)):
z=int(n[i])
if(z%2==0):
temp=i
m=1
if(z<k):
break
if(m==0):
print("-1")
else:
n[-1],n[temp]=n[temp],n[-1]
print("".join(n))
``` | vfc_66029 | {
"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": "4573\n",
"output": "3574\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 530_H. Points in triangle | Solve the following coding problem using the programming language python:
You are given a set of points on a plane with positive integer coordinates. Find a triangle of minimum area with vertices in points (0, 0), (A, 0) and (0, B) (A and B are unknown positive integers) that contains all the given points inside it (p... | vfc_66033 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n1 3\n",
"output": "6.0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 557_C. Arthur and Table | Solve the following coding problem using the programming language python:
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has n legs, the length of the i-th leg is li.
Arthur decided to make the table stable... | ```python
"""
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout
def main():
n = int(stdin.readline())
leg = [int(_) for _ in stdin.readline().split()]
d = [int(_) for _ in stdin.readline().split()]
pairedLD = []
for x, y in zip(leg, d):
pairedLD.append((x, y))
pa... | vfc_66037 | {
"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\n1 5\n3 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 4 4\n1 1 1\n",
"output": "0\n",
"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.