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 | p01978 Graph | Solve the following coding problem using the programming language python:
problem
You were solving a flow problem that is typical of graph algorithms.
The graph given in the problem is $ N $ vertices and $ M $ edges, with edges from $ x_i $ vertices to $ y_i $ vertices with capacity $ z_i $ and cost $ d_i $. However,... | vfc_46681 | {
"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": "5 3 1 4\n3 1 2 5\n3 4 2 3\n5 4 2 2",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 1 4\n3 1 2 5\n3 4 2 3\n5 4 2 0",
"output": "5\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | p02264 Queue | Solve the following coding problem using the programming language python:
Notes
Template in C
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 1000
* 1 ≤ timei ≤ 50000
* 1 ≤ length of namei ≤ 10
* 1 ≤ Sum of timei ≤ 1000000
Input
n q
name1 time1
name2 time2
...
namen timen
In the first line the number of processes n and ... | ```python
import sys
from collections import deque
s=sys.stdin.readlines()
_,q=map(int,s[0].split())
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t=0
while d:
k,v=d.popleft()
if v>q:
v-=q
t+=q
d.append([k,v])
else:
t+=v
print(k,t)
``` | vfc_46689 | {
"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": "5 100\np1 150\np2 80\np3 200\np4 350\np5 20",
"output": "p2 180\np5 400\np1 450\np3 550\np4 800",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 100\np1 150\np2 80\np3 200\np4 350\np5 14",
... |
code_contests | verifiable_code | p02412 How many ways? | Solve the following coding problem using the programming language python:
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are t... | ```python
n, x = map(int, input().split())
while n != 0 or x != 0:
count = 0
for i in range(1, n+1):
for j in range(i+1, n+1):
for k in range(j+1, n+1):
if i+j+k == x:
count += 1
print(count)
n, x = map(int, input().split())
``` | vfc_46693 | {
"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": "5 9\n0 0",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7\n0 0",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | astrgame | Solve the following coding problem using the programming language python:
Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguo... | ```python
__author__ = 'robert'
from collections import defaultdict
import sys
def solve(cache, between, i, j):
if (i, j) in cache:
return cache[(i, j)]
if not between[(i, j)]:
return 0
if len(between[(i, j)]) == 1:
return 1
grundy_numbers = set()
for word in between[(i, j)]... | vfc_46697 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi",
"output": "Tracy\nTracy\nTeddy",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\ncodechef\n2\ncode\nchef\nf... |
code_contests | verifiable_code | clnforum | Solve the following coding problem using the programming language python:
Long ago during the Jurassic Park age, there was a company TopHunters, which used to conduct hunting competitions for the Dinosaurs around the world. Petrosaurus was believed to be the greatest hunter of that time and all other dinosaurs enjoyed... | ```python
try:
x=input()
while x>0:
s=raw_input().split(' ')
for i in range(len(s)):
if s[i]=='8':
s[i]='ate'
elif s[i]=='w8':
s[i]='wait'
elif s[i]=='gr8':
s[i]='great'
elif s[i]=='4':
... | vfc_46701 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ni 8 food b4\ngr8 2 see you w8ing\n1234 5678 9",
"output": "i ate food before\ngreat 2 see you w8ing\n1234 5678 9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\ni 8 food b4\n... |
code_contests | verifiable_code | flow005 | Solve the following coding problem using the programming language python:
Consider a currency system in which there are notes of seven denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.... | ```python
for x in range(int(raw_input())):
varAmount = int(raw_input())
totalNotes = 0
for denomination in [100, 50, 10, 5, 2, 1]:
if varAmount != 0:
varNotes = varAmount//denomination
varAmount -= varNotes*denomination
totalNotes += varNotes
print totalNotes
``` | vfc_46705 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n1200\n500\n242",
"output": "12\n5\n7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | lediv | Solve the following coding problem using the programming language python:
The Little Elephant from the Zoo of Lviv has an array A that consists of N positive integers. Let A[i] be the i-th number in this array (i = 1, 2, ..., N).
Find the minimal number x > 1 such that x is a divisor of all integers from array A. Mor... | ```python
from fractions import gcd
def divisors_min(r):
if(r%2==0):
return 2
elif(r%3==0):
return 3
else:
y=2
i=5
while i<pow(r,0.5)+1:
if(r%i==0):
return i
i+=y
y=6-y
return r
def gcd2(l,n):
r=l[0]
... | vfc_46709 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n2 4 8\n3\n4 7 5",
"output": "2\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n2 4 8\n3\n4 10 5",
"output": "2\n-1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | potatoes | Solve the following coding problem using the programming language python:
Farmer Feb has three fields with potatoes planted in them. He harvested x potatoes from the first field, y potatoes from the second field and is yet to harvest potatoes from the third field. Feb is very superstitious and believes that if the sum... | ```python
import sys
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 31... | vfc_46713 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 3\n4 3",
"output": "1\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 3\n3 3",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | subinc | Solve the following coding problem using the programming language python:
Given an array A1, A2, ..., AN, count the number of subarrays of array A which are non-decreasing.
A subarray A[i, j], where 1 ≤ i ≤ j ≤ N is a sequence of integers Ai, Ai+1, ..., Aj.
A subarray A[i, j] is non-decreasing if Ai ≤ Ai+1 ≤ Ai+2 ≤ ..... | ```python
n = int(raw_input())
for i in xrange(n):
l = int(raw_input())
list_a = [0]
prev = -1
numList = [int(x) for x in raw_input().split()]
for num in numList:
if num >= prev:
list_a.append(list_a[-1] + 1)
else:
list_a.append(1)
prev = num
print sum(list_a)
``` | vfc_46717 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 4 2 3\n1\n5",
"output": "6\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n1 2 2 3\n1\n5",
"output": "10\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1033_B. Square Difference | Solve the following coding problem using the programming language python:
Alice has a lovely piece of cloth. It has the shape of a square with a side of length a centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length b centimeters (where b < a). Alice wanted to make Bob happy, ... | ```python
def check(n):
i=2
while i*i<=n:
if n%i==0:
return 1
i+=1
return 0
for _ in range(int(input())):
a,b=map(int,input().split())
if (a-b)!=1:
print('NO')
else:
if check((a*a)-(b*b)):print('NO')
else:print('YES')
``` | vfc_46725 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6 5\n16 13\n61690850361 24777622630\n34 33\n",
"output": "YES\nNO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5484081721 5484081720\n",
"output": "NO\n",
"ty... |
code_contests | verifiable_code | 1055_G. Jellyfish Nightmare | Solve the following coding problem using the programming language python:
Bob has put on some weight recently. In order to lose weight a bit, Bob has decided to swim regularly in the pool. However, the day before he went to the pool for the first time he had a weird dream. In this dream Bob was swimming along one of t... | vfc_46729 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\n0 0\n3 0\n3 3\n0 3\n3\n1 0 1\n4 2 2\n3 6 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1099_A. Snowball | Solve the following coding problem using the programming language python:
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second t... | ```python
w , h = map(int , input().split())
u1 , d1 = map(int , input().split())
u2 , d2 = map(int , input().split())
while h > 0:
if h == d1:
w = w + h
w = w - u1
h -= 1
elif h == d2:
w = w + h
w = w - u2
h -= 1
else:
w = w + h
h -= 1
... | vfc_46737 | {
"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\n9 2\n0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 1\n1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1119_H. Triple | Solve the following coding problem using the programming language python:
You have received your birthday gifts — n triples of integers! The i-th of them is { a_{i}, b_{i}, c_{i} }. All numbers are greater than or equal to 0, and strictly smaller than 2^{k}, where k is a fixed integer.
One day, you felt tired playing... | vfc_46741 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 2 1\n0 1 2\n1 2 3\n",
"output": "4 2 4 6 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2 3\n1 3 7\n0 2 5\n1 0 6\n3 3 2\n",
"output": "198 198 126 126 126 126 198 198 "... | |
code_contests | verifiable_code | 1146_E. Hot is Cold | Solve the following coding problem using the programming language python:
You are given an array of n integers a_1, a_2, …, a_n.
You will perform q operations. In the i-th operation, you have a symbol s_i which is either "<" or ">" and a number x_i.
You make a new array b such that b_j = -a_j if a_j s_i x_i and b_j ... | ```python
n,q=map(int,input().split())
a=list(map(int,input().split()))
swaps=[0]*q
for i in range(q):
b=input().split()
b[1]=int(b[1])
out=1 if (b[0]=="<" and b[1]<=0) or (b[0]==">" and b[1]>=0) else 0
split=b[1]+0.5 if b[0]==">" else b[1]-0.5
sign=1 if split>0 else -1
split=abs(split)
swap... | vfc_46745 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n0 1 -2 -1 2\n< -2\n< -1\n< 0\n< 1\n< 2\n",
"output": "0 -1 -2 -1 -2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11 3\n-5 -4 -3 -2 -1 0 1 2 3 4 5\n> 2\n> -4\n... |
code_contests | verifiable_code | 1185_G2. Playlist for Polycarp (hard version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in e... | vfc_46753 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 1\n1 1\n1 3\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 1\n1 2\n1 3\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": nul... | |
code_contests | verifiable_code | 1204_E. Natasha, Sasha and the Prefix Sums | Solve the following coding problem using the programming language python:
Natasha's favourite numbers are n and 1, and Sasha's favourite numbers are m and -1. One day Natasha and Sasha met and wrote down every possible array of length n+m such that some n of its elements are equal to 1 and another m elements are equal... | ```python
import sys
import math
MOD = 998244853
def prepare_c(n):
result = [1]
last = [1, 1]
for i in range(2, n + 1):
new = [1]
for j in range(1, i):
new.append((last[j - 1] + last[j]) % MOD)
new.append(1)
last = new
return new
def main():
(a, b) = tu... | vfc_46757 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 2\n",... |
code_contests | verifiable_code | 1221_D. Make The Fence Great Again | Solve the following coding problem using the programming language python:
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is gre... | ```python
import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
n = int(input())
dp = [[0] * n for _ in range(3)]
prev = 0
for i in range(n):
l, c = [int(item) for item in input().split()]
if i == 0:
dp[0][0] = 0
dp[1][0] = c
dp[2]... | vfc_46761 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n2 4\n2 1\n3 5\n3\n2 3\n2 10\n2 6\n4\n1 7\n3 3\n2 6\n1000000000 2\n",
"output": "2\n9\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n2 4\n2 1\n3 5\n3\n2 3\n2 2\n2 6\n4\n1 7\... |
code_contests | verifiable_code | 1248_A. Integer Points | Solve the following coding problem using the programming language python:
DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew n distinct lines, given by equations y = x + p_i for some distinct p_1, p_2, …, p_n.
Then JLS drew on the same paper sheet m distinct... | ```python
t = int(input())
for a in range(t):
n = int(input())
p = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
cnt = 0
evencnt = 0
oddcnt = 0
for i in range(m):
if(q[i] % 2 == 0):
evencnt += 1
else:
oddcnt += 1
for i in range(n):
if(p[i] %2 == 0):
cnt +=... | vfc_46765 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n1 3 2\n2\n0 3\n1\n1\n1\n1\n1\n2\n1\n1\n",
"output": "3\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n2\n1000000000 0\n2\n1000000000 0\n2\n1 0\n2\n1000000000 0\n2\n1 0\n2\n... |
code_contests | verifiable_code | 1266_E. Spaceship Solitaire | Solve the following coding problem using the programming language python:
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def main():
n = int(input())
a = [0]+list(map(int,input().split()))
su = sum(a)
le = [0]*(n+1)
dct = {}
for _ in range(int(input())):
s,t,u = map(int,input().split())
... | vfc_46769 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3\n5\n2 1 1\n2 2 1\n1 1 1\n2 1 2\n2 2 0\n",
"output": "4\n3\n3\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 1 1\n6\n1 1 1\n1 2 1\n1 2 2\n1 1 2\n1 1 3\n1 2 3\n",
"o... |
code_contests | verifiable_code | 1287_F. LCC | Solve the following coding problem using the programming language python:
An infinitely long Line Chillland Collider (LCC) was built in Chillland. There are n pipes with coordinates x_i that are connected to LCC. When the experiment starts at time 0, i-th proton flies from the i-th pipe with speed v_i. It flies to the... | vfc_46773 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7 10 0\n9 4 86\n14 5 100\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1331_C. ...And after happily lived ever they | Solve the following coding problem using the programming language python:
Input
The input contains a single integer a (0 ≤ a ≤ 63).
Output
Output a single number.
Examples
Input
2
Output
2
Input
5
Output
24
Input
35
Output
50
The input will be given via stdin and the output should be prin... | ```python
# And after happily lived ever they
n = int(input())
d = [0,5,3,2,4,1]
r=0
for dd in d:
r=r*2 + bool(n&1<<(5-dd))
print (r)
``` | vfc_46781 | {
"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": "35\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1371_C. A Cookie for You | Solve the following coding problem using the programming language python:
Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has a vanilla cookies and b chocolate cookies for the party.
She invited n guests of the firs... | ```python
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]
for _ in range(inp()):
a,b,n,m = ip()
if a+b < n+m:
print("No")
continue
no = min(n,m)
if a < no or b < no:
print("N... | vfc_46789 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2 2 1 2\n0 100 0 1\n12 13 25 1\n27 83 14 25\n0 0 1 0\n1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n",
"output": "Yes\nNo\nNo\nYes\nNo\nYes\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1418_E. Expected Damage | Solve the following coding problem using the programming language python:
You are playing a computer game. In this game, you have to fight n monsters.
To defend from monsters, you need a shield. Each shield has two parameters: its current durability a and its defence rating b. Each monster has only one parameter: its... | ```python
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x... | vfc_46797 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n4 2 6\n3 1\n1 2\n2 3\n",
"output": "0\n8\n665496236\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1436_D. Bandit in a City | Solve the following coding problem using the programming language python:
Bandits appeared in the city! One of them is trying to catch as many citizens as he can.
The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is t... | ```python
n = int(input())
parent = [0] + [x-1 for x in list(map(int, input().split()))]
citizen = list(map(int, input().split()))
sz = [1] * n
for i in range(1, n):
sz[parent[i]] = 0
#print(sz)
for i in range(n-1, 0, -1):
citizen[parent[i]] += citizen[i]
sz[parent[i]] += sz[i]
#print(citizen)
#print(sz)... | vfc_46801 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n3 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n3 1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1461_B. Find the Spruce | Solve the following coding problem using the programming language python:
Holidays are coming up really soon. Rick realized that it's time to think about buying a traditional spruce tree. But Rick doesn't want real trees to get hurt so he decided to find some in an n × m matrix consisting of "*" and ".".
<image>
To ... | ```python
for _ in range(int(input())):
n,m = list(map(int,input().split()))
arr = []
c = 0
for i in range(n):
z = list(input())
c+=z.count("*")
arr.append(z)
ans = []
for i in range(n):
ans.append([0]*m)
for i in range(m):
for g in range(n):
... | vfc_46805 | {
"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\n2 3\n.*.\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n5 7\n..*.*..\n.*****.\n*******\n.*****.\n..*.*..\n",
"output": "\n5\n3\n23\n34\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 1486_C2. Guessing the Greatest (hard version) | Solve the following coding problem using the programming language python:
The only difference between the easy and the hard version is the limit to the number of queries.
This is an interactive problem.
There is an array a of n different numbers. In one query you can ask the position of the second maximum element in... | ```python
from __future__ import print_function # for PyPy2
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
# from math import *
g = lambda : stdin.readl... | vfc_46809 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n\n3\n\n4\n\n",
"output": "\n? 1 5\n\n? 4 5\n\n! 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n5 1 6 2 8 3 4 10 9 7\n",
"output": "5\n",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | 1510_C. Cactus Not Enough | Solve the following coding problem using the programming language python:
There was no problem about a cactus at the NERC 2020 online round. That's a bad mistake, so judges decided to fix it. You shall not pass to the World Finals 2021 without solving a problem about a cactus!
A cactus is a connected undirected graph... | vfc_46813 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n7 1 2 5 6 2 3 4\n3 1\n4 1 2 3 1\n5 2\n3 1 3 5\n3 1 2 4\n7 2\n6 1 2 3 4 5 3\n3 6 5 7\n0 0\n",
"output": "\n1\n1 4\n0\n1\n5 4\n2\n1 3\n6 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... | |
code_contests | verifiable_code | 163_D. Large Refrigerator | Solve the following coding problem using the programming language python:
Vasya wants to buy a new refrigerator. He believes that a refrigerator should be a rectangular parallelepiped with integer edge lengths. Vasya calculated that for daily use he will need a refrigerator with volume of at least V. Moreover, Vasya i... | vfc_46821 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2 3\n1\n17 1\n3\n3 1\n2 3\n5 1\n",
"output": "24 2 2 2\n70 1 1 17\n148 4 5 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2 3\n1\n13 1\n3\n3 1\n2 3\n5 1\n",
"output": ... | |
code_contests | verifiable_code | 183_E. Candy Shop | Solve the following coding problem using the programming language python:
The prestigious Codeforces kindergarten consists of n kids, numbered 1 through n. Each of them are given allowance in rubles by their parents.
Today, they are going to the most famous candy shop in the town. The shop sells candies in packages: ... | ```python
import math
import time
from datetime import datetime
Debug = False
#import sys
#print sys.maxint
def sigma(a, b, k):
return a*k + b*(k+1)*k/2
def max_deliver(n, m, t):
return sigma(m+n, -n, t)
def max_candy_t_old(n, m, rs, t, c_candy):
candy = [0]*n
candy[n-1] = min(rs[n-1], max_deliver... | vfc_46825 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5000000\n12500002500000\n12500002500000\n",
"output": "12500002500000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n5\n10\n",
"output": "13\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 231_A. Team | Solve the following coding problem using the programming language python:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they wi... | ```python
n=int(input())
count=0
for _ in range(n):
l=list(map(int,input().split()))
if(sum(l)>=2):
count+=1
print(count)
``` | vfc_46833 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 0 0\n0 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 0\n1 1 1\n1 0 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 27_E. Number With The Given Amount Of Divisors | Solve the following coding problem using the programming language python:
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output th... | ```python
# # of divisors of p1^e1 p2^e2 ... is (e1 + 1)(e2 + 1) ... (en + 1)
# Try all possible partitions, sort, see which gives the least answer?
# 1: 1
# 2: 2
# 3: 4
# 4: 6, 2^3 = 8, 2 * 3 = 6
# 5: 16
# 6: 12
ans = [0, 1, 2, 4, 6, 16, 12, 64, 24, 36, 48, 1024, 60, 14096, 192, 144, 120, 65536, 180, 262144, 240, 57... | vfc_46841 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 302_D. Yaroslav and Time | Solve the following coding problem using the programming language python:
Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (xi, ... | vfc_46845 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1000\n1000\n0 0\n0 1\n0 3\n",
"output": "2000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1000\n1000\n1 0\n1 1\n1 2\n",
"output": "1000\n",
"type": "stdin_stdout"
}... | |
code_contests | verifiable_code | 350_C. Bombs | Solve the following coding problem using the programming language python:
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (xi, yi). We know that no two bombs are at the same point and that no bomb is at poin... | ```python
import os,sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writ... | vfc_46853 | {
"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\n1 1\n-1 -1\n",
"output": "12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 0\n0 5\n1 0\n",
"output": "12... |
code_contests | verifiable_code | 374_D. Inna and Sequence | Solve the following coding problem using the programming language python:
Dima's spent much time thinking what present to give to Inna and gave her an empty sequence w. Now they want to fill sequence w with numbers zero and one. For that, they decided to play an amusing game.
Before the game begins, Dima chooses m i... | vfc_46857 | {
"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 1\n1\n1\n-1\n",
"output": "Poor stack!\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3\n1 3 6\n-1\n1\n1\n0\n0\n-1\n0\n1\n-1\n1\n",
"output": "011",
"type": "stdin_stdout... | |
code_contests | verifiable_code | 397_A. On Segment's Own Points | Solve the following coding problem using the programming language python:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexe... | ```python
n=int(input())
d=[1]*100
a,b=map(int,input().split())
for i in range(n-1):
l,r=map(int,input().split())
for i in range(l,r):
d[i]=0
print(sum(d[a:b]))
``` | vfc_46861 | {
"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\n0 5\n2 8\n1 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 10\n1 5\n7 15\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 41_B. Martian Dollar | Solve the following coding problem using the programming language python:
One day Vasya got hold of information on the Martian dollar course in bourles for the next n days. The buying prices and the selling prices for one dollar on day i are the same and are equal to ai. Vasya has b bourles. He can buy a certain numbe... | ```python
I = lambda : map(int,input().split())
n,m = I()
li = list(I())
ma = li[n-1]
ans=m
for i in range(n-2,-1,-1) :
ma=max(ma,li[i])
ans = max(ans,m%li[i]+(m//li[i])*(ma))
print(ans)
``` | vfc_46865 | {
"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 4\n3 7\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 445_E. DZY Loves Colors | Solve the following coding problem using the programming language python:
DZY loves colors, and he enjoys painting.
On a colorful day, DZY gets a colorful ribbon, which consists of n units (they are numbered from 1 to n from left to right). The color of the i-th unit of the ribbon is i at first. It is colorful enough... | vfc_46869 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3\n",
"output": " 3\n 2\n ... | |
code_contests | verifiable_code | 468_A. 24 Game | Solve the following coding problem using the programming language python:
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and... | ```python
def test(n):
if n >= 4:
print('YES')
if n%2 == 0:
print("1 + 2 = 3")
print("3 + 3 = 6")
print("6 * 4 = 24")
i = 4
while (i <= n-2):
print(str(i+2)+' - '+str(i+1)+' = 1')
print("24 * 1 = 24")
... | vfc_46873 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n",
"output": "YES\n1 * 2 = 2\n2 * 3 = 6\n6 * 4 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "NO\n",
"... |
code_contests | verifiable_code | 490_A. Team Olympiad | Solve the following coding problem using the programming language python:
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we... | ```python
try:
n = int(input())
nums = list(map(int, input().split()))
def count(nums, x):
cnt_ar = []
for idx, ele in enumerate(nums):
if(ele == x):
cnt_ar.append(idx+1)
return cnt_ar
def teams(nums):
ones = count(nums, 1)
twos = co... | vfc_46877 | {
"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\n2 1 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 514_A. Chewbaсca and Number | Solve the following coding problem using the programming language python:
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.
Help Chewbacca to transform the initial number x to the minimum po... | ```python
x = list(input())
for i in range(len(x)):
if (i == 0 and '5' <= x[0] <= '8') or (i != 0 and '5' <= x[i] <= '9'):
x[i] = str(9-int(x[i]))
print(x[i], end = '')
``` | vfc_46881 | {
"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": "27\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4545\n",
"output": "4444\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "877... |
code_contests | verifiable_code | 540_B. School Marks | Solve the following coding problem using the programming language python:
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want ... | ```python
n, k, p, x, y = map(int, input().split())
b = list(map(int, input().split()))
lower_bound = 1
for i in range(k):
if b[i] < y: lower_bound += 1
ans = [1]*min((n+1) // 2 - lower_bound, n-k)
while len(ans) < n-k:
ans.append(y)
if sum(ans+b) <= x and (n+1) // 2 - lower_bound >= 0 and p >= y:
print(' '.joi... | vfc_46885 | {
"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 3 5 18 4\n3 5 4\n",
"output": "1 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 5 16 4\n5 5 5\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 568_C. New Language | Solve the following coding problem using the programming language python:
Living in Byteland was good enough to begin with, but the good king decided to please his subjects and to introduce a national language. He gathered the best of wise men, and sent an expedition to faraway countries, so that they would find out a... | vfc_46889 | {
"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": "VC\n2 1\n1 V 2 C\naa\n",
"output": "ab",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "VCC\n4 3\n1 C 2 V\n2 C 3 V\n3 V 4 V\nabac\n",
"output": "acaa",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 58_A. Chat room | Solve the following coding problem using the programming language python:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted f... | ```python
s=input()
s=s.lower()
ss='hello'
cnt=0
for i in range(len(s)):
if s[i]==ss[cnt]:
cnt+=1
if cnt==5:
break
if cnt==5:
print("YES")
else:
print("NO")
``` | vfc_46893 | {
"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": "ahhellllloou\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "hlelo\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 611_C. New Year and Domino | Solve the following coding problem using the programming language python:
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.
Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w columns. Each cell is... | ```python
from itertools import accumulate
import math
import bisect
def list_sum(L1, L2):
return [L1[i] + L2[i] for i in range(len(L1))]
h, w = [int(x) for x in input().split()]
M = []
for i in range(h):
M.append([1 if c == '.' else 0 for c in input().rstrip()])
H = [[0]+list(accumulate(M[i][j] and M[i][j+... | vfc_46897 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###...... |
code_contests | verifiable_code | 630_R. Game | Solve the following coding problem using the programming language python:
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field c... | ```python
n = int(input(""))
if n % 2 == 0:
print (2)
else:
print (1)
``` | vfc_46901 | {
"difficulty": "25",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"ou... |
code_contests | verifiable_code | 65_C. Harry Potter and the Golden Snitch | Solve the following coding problem using the programming language python:
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It a... | ```python
import math
import functools
import sys
def eulen(x, y):
r = functools.reduce(lambda x, y: x + y, \
map(lambda x: (x[0] - x[1]) ** 2, zip(x, y)))
return math.sqrt(r)
def output(t, p):
print('YES')
print(t)
print(' '.join(map(str, p)))
n = int(input())
points = []
for i in ra... | vfc_46905 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 2 3\n4 5 6\n20 10\n1 2 3\n",
"output": "YES\n0.000000000000000\n1.000000000000000 2.000000000000000 3.000000000000000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 683_B. The Teacher of Physical Education | Solve the following coding problem using the programming language python:
n pupils came to Physical Education lesson. We know the name and the height of each pupil.
Your task is to help the teacher of Physical Education to line up all pupils in non-decreasing order of their heights.
Input
The first line contains t... | vfc_46909 | {
"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\nIvan 150\nIgor 215\nDasha 158\nKatya 150\n",
"output": "Ivan\nKatya\nDasha\nIgor\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nSASHA 180\nSASHA 170\n",
"output": "SASHA\nSASH... | |
code_contests | verifiable_code | 729_C. Road to Cinema | Solve the following coding problem using the programming language python:
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that t... | ```python
from sys import stdin
def fast2():
import os, sys, atexit
from cStringIO import StringIO as BytesIO
# range = xrange
sys.stdout = BytesIO()
atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
return BytesIO(os.read(0, os.fstat(0).st_size)).readline
input = fast2()
rints = l... | vfc_46917 | {
"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 8 10\n10 8\n5 7\n11 9\n3\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 749_D. Leaving Auction | Solve the following coding problem using the programming language python:
There are n people taking part in auction today. The rules of auction are classical. There were n bids made, though it's not guaranteed they were from different people. It might happen that some people made no bids at all.
Each bid is define by... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(... | vfc_46921 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 10\n2 100\n3 1000\n1 10000\n2 100000\n3 1000000\n3\n1 3\n2 2 3\n2 1 2\n",
"output": "2 100000\n1 10\n3 1000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 772_C. Vulnerable Kerbals | Solve the following coding problem using the programming language python:
You are given an integer m, and a list of n distinct integers between 0 and m - 1.
You would like to construct a sequence satisfying the properties:
* Each element is an integer between 0 and m - 1, inclusive.
* All prefix products of the... | ```python
maxn = 200500
g = [[] for i in range(maxn)] # Array de array g[i][j] en el cual la posicion i representa gcd(a,m)
# y en el array [j] se guardan todos los ¨a¨ con gcd comunes
dp = [0 for i in range(maxn)] # guarda la profundidad mayor para cada nodo
ban = [0 for i in range(maxn)... | vfc_46925 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10\n2 9 1\n",
"output": "6\n3 9 2 4 8 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 5\n",
"output": "5\n1 2 4 3 0 \n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 797_C. Minimal string | Solve the following coding problem using the programming language python:
Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves:
* Extract the first character of s and append t with t... | ```python
s = list(input())
t = []
u = []
letters = [[] for _ in range(ord('z') - ord('a') + 1)]
for (index, letter) in enumerate(s):
letters[ord(letter) - ord('a')] += [index]
for indexes in letters:
indexes.reverse()
current = 0
while current < len(s):
if len(t) == 0:
t += s[current]
... | vfc_46929 | {
"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": "cab\n",
"output": "abc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "acdb\n",
"output": "abdc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "b... |
code_contests | verifiable_code | 817_E. Choosing The Commander | Solve the following coding problem using the programming language python:
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.
Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commande... | ```python
import sys
from collections import defaultdict
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
q = int(sys.stdin.readline())
root = Node(0)
# def search(node, bit, )
for _ in range(q):
l = list(map(int, sys.stdin.readline().split()))
if l[0] == 1:
# add
b... | vfc_46933 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3\n",
"output": "1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 3\n1 4\n3 8 3\n2 4\n3 6 3\n",
"output": "0\n0\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 842_E. Nikita and game | Solve the following coding problem using the programming language python:
Nikita plays a new computer game. There are m levels in this game. In the beginning of each level a new class appears in the game; this class is a child-class of the class yi (and yi is called parent-class for this new class). Thus, the classes ... | vfc_46937 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n1\n2\n3\n",
"output": "2\n2\n2\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1\n1\n2\n1\n",
"output": "2\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"f... | |
code_contests | verifiable_code | 863_E. Turn Off The TV | Solve the following coding problem using the programming language python:
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant i... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
#import threading
from collections import defaultdict
#threading.stack_siz... | vfc_46941 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3\n4 6\n1 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n3 4\n6 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 889_B. Restoration of string | Solve the following coding problem using the programming language python:
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if a... | ```python
import sys
n = int(input())
a=[]
for i in range(n):
a.append([j for j in input()])
b=[]
for i in range(n):
b.append({})
for j in a[i]:
if j in b[i]:
print('NO')
sys.exit()
b[i][j]=1
c=[-1 for i in range(26)]
d=[-1 for i in range(26)]
e=[0 for i in range(26)]
for word in a:
l=ord(word[0])-97
e... | vfc_46945 | {
"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\nkek\npreceq\ncheburek\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nmail\nai\nlru\ncf\n",
"output": "cfmailru\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 911_G. Mass Change Queries | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers. You have to process q queries to this array; each query is given as four numbers l, r, x and y, denoting that for every i such that l ≤ i ≤ r and ai = x you have to set ai equal to y.
Print the... | vfc_46949 | {
"difficulty": "13",
"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\n1 2 3 4 5\n3\n3 5 3 5\n1 5 5 1\n1 5 1 5\n",
"output": "5 2 5 4 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n1\n1 1 1 1\n",
"output": "1 2 3 4 5 ",
"type": ... | |
code_contests | verifiable_code | 933_E. A Preponderant Reunion | Solve the following coding problem using the programming language python:
East or west, home is best. That's why family reunion, the indispensable necessity of Lunar New Year celebration, is put in such a position.
After the reunion dinner, Little Tommy plays a game with the family. Here is a concise introduction to ... | vfc_46953 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 1 3 1\n",
"output": "2\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 2 1 3 1\n",
"output": "3\n4\n2\n1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 960_B. Minimize the error | Solve the following coding problem using the programming language python:
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined <image>. You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one elem... | ```python
n, k1, k2 = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
e = []
for i in range(n):
e.append(abs(a1[i]-a2[i]))
#print(e)
for k in range(k1+k2):
e[e.index(max(e))] = abs(max(e) - 1)
print(sum(i * i for i in e))
``` | vfc_46957 | {
"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 0\n1 2\n2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0 0\n1 2\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 987_E. Petr and Permutations | Solve the following coding problem using the programming language python:
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from 1 to n and then 3n times takes ... | ```python
n = int(input())
a = list(map(int,input().split()))
b = [x for x in range(1,n+1)]
c = [(x,y) for x,y in zip(a,b)]
d = set(c)
cnt = 0
while d:
x = d.pop()
sti = x[1]
while x[0] != sti:
x = c[x[0]-1]
cnt += 1
if x in d:
d.remove(x)
else:
break
... | vfc_46961 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 4 5 1 3\n",
"output": "Petr\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | alien-language | Solve the following coding problem using the programming language python:
Little Jhool considers Jaadu to be a very close friend of his. But, he ends up having some misunderstanding with him a lot of times, because Jaadu's English isn't perfect, and Little Jhool sucks at the language Jaadu speaks. So, he's in a fix - ... | ```python
for T in range(int(input())):
Text = raw_input()
S = raw_input()
l = len(S)
f = 0
for i in S:
if(i in Text):
f = 1
print("YES")
break
if(f == 0):
print("NO")
``` | vfc_46965 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nhackerearth\nhacker\nhackerearth\nwow\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nhackerearth\nhacker\nhackerearti\nwow\nSAMPLE",
"output": "YE... |
code_contests | verifiable_code | caesar-cipher | Solve the following coding problem using the programming language python:
Caesar Cipher is one of the earliest and simplest encryption technique.
To encrypt a message, we shift the alphabets of the message by a fixed position or key.
For example, if message is ABC , and we shift each character by 3 characters, we wi... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
##print 'Hello World!'
t=int(input())
while(t>0):
t-=1
n=int(raw_input())
s=raw_input()
x=''
for i in range(len(s)):
if ord(s[i])>=97 and ord(s[i])<=122:
x+=chr((or... | vfc_46969 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\nx\n3\noXyh\n2\nnn\n\nSAMPLE",
"output": "z\nrAbk\npp\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\nx\n3\noXyh\n4\nnn\n\nSAMPLE",
"output": "z\nrAbk\nrr\n",
"type"... |
code_contests | verifiable_code | debts-of-the-lannisters | Solve the following coding problem using the programming language python:
Tyrion, son of Tywin was released from the dungeons of vale after his champion Bronn defeated Ser Vardis in the trial by combat.
As a Lannister always pays his debts, he invited Bronn to play a game of mastermind with him.
The game is played a... | ```python
from sys import stdin
a = stdin.readline().strip()
di = {}
for i in a:
di[i] = di.get(i,0) + 1
t = int(stdin.readline())
for _ in xrange(t):
b = stdin.readline().strip()
fir = 0
sec = 0
for i in xrange(10):
if a[i] == b[i]:
fir+=1
hi = {}
for i in b:
hi[i] = hi.get(i,0)+1
for i in hi:
x = hi... | vfc_46973 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ROYGBIVVOG\n3\nVIBGYORROY\nRRRRRVVVVV\nROYGBIVVGO\n\nSAMPLE",
"output": "2 6\n3 0\n8 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "IBBRVOOOGY\n100\nYBBBYBOOYI\nROOIIYRVIB\nOROYGROBVO\nBR... |
code_contests | verifiable_code | game-of-riddle | Solve the following coding problem using the programming language python:
"Bless us and splash us , precious . Thats a meaty mouthful . " said Gollum on seeing
Bilbo Baggins . Poor Bilbo Baggins is lost in the Misty Mountains and worst of all now he is
stuck with Gollum who wants to finish him off. As Mr. Bilbo Bagg... | ```python
for _ in range(int(raw_input())):
n = int(raw_input())
a = map(int,raw_input().split())
nd = n/min(a)
if(nd==0):
print "-1"
continue
li = max(a.index(min(a)),(len(a)-1)-a[::-1].index(min(a)))
i1 = li+1
left = n%a[li]
no = []
j = 8
while(left>0 and j>li):
if(a[j]-a[li] > left):
j-=1
else:
... | vfc_46977 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n9 4 2 2 6 3 2 2 1\n2\n5 11 2 2 5 8 9 10 19\n5\n9 9 9 9 9 9 9 9 9\n\nSAMPLE",
"output": "99999\n4\n-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | killing-white-walkers | Solve the following coding problem using the programming language python:
"N" White Walkers are positioned in a circle from "1" to "N". First (No. 1) White Walker has a dragonglass . He kills the next White Walker (i.e. No. 2) and passes the dragonglass to the next (i.e. No. 3) who kills the 4th and passes the weap... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = int(raw_input())
while t > 0:
t = t - 1
n = int(raw_input())
if n == 0:
print "0"
continue
m = 1
while 1:
temp = m*2
if temp > n:
break
m = temp... | vfc_46981 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n100\n10\n4\n\nSAMPLE",
"output": "73\n5\n1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | modify-sequence | Solve the following coding problem using the programming language python:
Suppose we have a sequence of non-negative integers, Namely a_1, a_2, ... ,a_n. At each time we can choose one term a_i with 0 < i < n and we subtract 1 from both a_i and a_i+1. We wonder whether we can get a sequence of all zeros after several ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n = int(raw_input())
nums = map(int, raw_input().split())
#POSSIBLE = (reduce(lambda x,y : y-x, nums) == 0)
diff = nums[0]
for i in range(1, len(nums)):
diff = nums[i]-diff... | vfc_46985 | {
"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 2",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000\n949857476 994365971 344867097 904348384 848824306 497966101 312306958 343479655 453096396 747583877 928279278... |
code_contests | verifiable_code | pandaland-and-2-best-friends | Solve the following coding problem using the programming language python:
Its vacation time and Panda with two of his best friends Agham and Rishi is in his hometown, Pandaland. One day Panda came across a very delicious dish called PandaCake. He likes it very much and bought 'N' of them from a shop. Now on the day of... | ```python
from math import sqrt
for _ in range(int(raw_input())):
n = int(raw_input())
print int(sqrt(4 * (n-1) + 1))
``` | vfc_46989 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n1\n4\n\nSAMPLE",
"output": "4\n1\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n1\n4\n\nSAMPLE",
"output": "1\n1\n3\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | round-it-2 | Solve the following coding problem using the programming language python:
Most of the time when rounding a given number, it is customary to round to some multiple of a power of 10. However, there is no reason why we cannot use another multiple to do our rounding to. For example, you could round to the nearest multiple... | ```python
for _ in xrange(input()):
N,B=map(int,raw_input().split())
S=N
T=N
c1,c2=0,0
while S%B!=0:
S-=1
c1+=1
while T%B!=0:
T+=1
c2+=1
if c2<=c1:
print T
else:
print S
``` | vfc_46993 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 10\n4 10\n100 3\n\nSAMPLE",
"output": "10\n0\n99\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "26\n5 10\n4 10\n100 3\n123456 7\n49 7\n158854 50\n822992 101\n691238 345\n682373 49\n6... |
code_contests | verifiable_code | string-division | Solve the following coding problem using the programming language python:
Kevin has a string S consisting of N lowercase English letters.
Kevin wants to split it into 4 pairwise different non-empty parts. For example, string "happynewyear" can be splitted into "happy", "new", "ye" and "ar". He can't delete any cha... | ```python
for _ in range(int(raw_input())):
a=raw_input()
if len(a)<=3:
print 'NO'
continue
elif len(a)>=10:
print 'YES'
continue
else:
flag=0
for i in range(len(a)-3):
for j in range(i+1,len(a)-2):
for k in range(j+1,len(a)-1):
a1=a[0:i+1]
a2=a[i+1:j+1]
a3=a[j+1:k+1]
a4=a[k+1... | vfc_46997 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nababca\naaabb\n\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\nglnnnxnnmkqnagymndnkbzntnnonuoooannctnunwarxnwnntnrnnnnsronbhnnnxvvnnkkneibhamhbhurnvnn... |
code_contests | verifiable_code | upup | Solve the following coding problem using the programming language python:
You are given a string S. S consists of several words separated by one or more spaces. Word consists of Latin letters as well as other symbols (but not spaces).
In each word which starts from lowercase Latin letter replace starting letter with u... | ```python
try:
s = raw_input()
#print s
words = s.split(' ')
#print words
for i in words:
if len(i)==0:
print "",
continue
else:
# print "i =", i
letters = list(i)
# print "leters are",letters
letters[0] = letters[0].capitalize()
word = ''.join(letters)
print (word),
except:
print "excep... | vfc_47001 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Wish you were here\n\nSAMPLE",
"output": "Wish You Were Here\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ENgxbWGZONP dIafHGqv bgQyfNgtTLCqAEXYxiOLgpKXRoeZIZkNNdB mVCsxRlHzsGolcALiqdaSy... |
code_contests | verifiable_code | p00012 A Point in a Triangle | Solve the following coding problem using the programming language python:
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain.
Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.
Constraints
You can assume that:
* $ -100 \leq... | ```python
# A Point in a Triangle
import math
def simul_eq(a,b,c,d,e,f):
# A = [[a,b],[d,e]]
C = [c,f]
detA = a*e - b*d
# if detA == 0: raise # det(A) == 0.
At = [[e,-b],[-d,a]]
x = sum(map((lambda x,y: x*y), At[0], C)) / detA
y = sum(map((lambda x,y: x*y), At[1], C)) / detA
return (x,y)... | vfc_47045 | {
"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": "0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0",
"output": "YES\nNO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.8224818410475855... |
code_contests | verifiable_code | p00277 Programming Contest | Solve the following coding problem using the programming language python:
A programming contest is held every year at White Tiger University. When the total number of teams is N, each team is assigned a team ID from 1 to N. The contest starts with all teams scoring 0 and runs continuously for L seconds.
This year's c... | ```python
import sys
from heapq import heappush, heappop, heapreplace
def solve():
file_input = sys.stdin
N, R, L = map(int, file_input.readline().split())
pq = [[0, i] for i in range(1, N + 1)]
m = dict(zip(range(1, N + 1), pq))
time = [0] * (N + 1)
INVALID = -1
pre_t = 0
for... | vfc_47053 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 600\n3 100 5\n1 200 10\n2 400 20\n3 500 20",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00465 Authentication Level | Solve the following coding problem using the programming language python:
problem
Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here we call it JOI for short.
JOI has two offices, each of which has square rooms of the same size arranged in a grid pattern. All the rooms th... | ```python
from heapq import heappop as pop
from heapq import heappush as push
INF = 1000000000000
def bfs(lst, used, que, w, h):
v, y, x = pop(que)
if y > 0 and not used[y - 1][x]:
push(que, (lst[y - 1][x], y - 1, x))
used[y - 1][x] = True
if h > y + 1 and not used[y + 1][x]:
push(que, (lst[y + 1][x... | vfc_47057 | {
"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": "5\n2 2 1 2\n9 5\n1 17\n3 2 2 1\n6 1 20\n8 18 3\n8\n5 4 1 3\n5 5 4 5 5\n8 2 1 9 7\n1 1 3 5 1\n7 2 7 1 3\n6 5 6 2\n2 3 5 8 2 7\n1 6 9 4 5 1\n2 4 5 4 2 2\n5 4 2 5 3 3\n7 1 5 1 5 6\n6\n3 3 2 2\n2 9 2\n9 1 9\n2 9 2\n2 2 1 1\n1 3\n5 7\n0... |
code_contests | verifiable_code | p00800 The Devil of Gravity | Solve the following coding problem using the programming language python:
Haven't you ever thought that programs written in Java, C++, Pascal, or any other modern computer languages look rather sparse? Although most editors provide sufficient screen space for at least 80 characters or so in a line, the average number ... | vfc_47065 | {
"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\n12BC3BC4BNBBDD5\naaaBCNBBBCb\naaaBBCbNBC",
"output": "15234\naba\nERROR",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n12BC3BC4BNBBDD5\naaaBCbBBBCN\naaaBBCbNBC",
"output": "1523... | |
code_contests | verifiable_code | p00931 Cornering at Poles | Solve the following coding problem using the programming language python:
Example
Input
8 900 0
40 100
70 -80
350 30
680 -20
230 230
300 400
530 130
75 -275
Output
1210.99416
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_47069 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 900 0\n40 100\n70 -80\n350 30\n680 -20\n230 230\n300 400\n530 130\n75 -275",
"output": "1210.99416",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 900 0\n40 100\n70 -80\n350 30\n680 -20\... | |
code_contests | verifiable_code | p01064 Array Update 2 | Solve the following coding problem using the programming language python:
Problem
There is an arithmetic progression A with the number of terms N, the first term a, and the tolerance d. Since M statements that rewrite the sequence are given in the following format, find the value of the K item of the sequence A when ... | vfc_47073 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2\n3\n1 2 3\n2 3 5\n0 1 5\n1",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 1\n3\n0 1 2\n1 1 4\n2 2 4\n3",
"output": "2",
"type": "stdin_stdout"
}
... | |
code_contests | verifiable_code | p01197 Rakunarok | Solve the following coding problem using the programming language python:
You are deeply disappointed with the real world, so you have decided to live the rest of your life in the world of MMORPG (Massively Multi-Player Online Role Playing Game). You are no more concerned about the time you spend in the game: all you ... | vfc_47077 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n\n3 3\n0 2\n0 2 240 80\n0 1 130 60\n1 2 260 60\n\n3 3\n0 2\n0 2 180 60\n0 1 130 60\n1 2 260 60",
"output": "3.2500\n3.0000",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01334 Let's JUMPSTYLE | Solve the following coding problem using the programming language python:
Description
F, who likes to dance, decided to practice a hardcore dance called JUMP STYLE at a certain dance hall.
The floor is tiled in an N × N grid. To support the dance practice, each tile has the coordinates of the tile to jump to the nex... | ```python
while True:
n = int(input())
if n == 0:break
to = []
fr = [[] for _ in range(n * n)]
for i in range(n):
line = list(map(int, input().split()))
for j in range(n):
x, y = line[2 * j:2 * j + 2]
to.append(y * n + x)
fr[y * n + x].append(i * n + j)
order = []
used = [Fals... | vfc_47081 | {
"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\n0 0\n2\n1 1 0 1\n1 0 0 0\n2\n1 1 0 1\n1 1 1 0\n3\n0 1 2 2 2 1\n0 2 1 2 2 1\n0 0 0 1 1 1\n4\n3 2 2 0 3 2 2 1\n1 1 0 3 1 1 3 1\n0 3 2 3 3 0 2 3\n1 1 1 1 3 2 1 3\n0",
"output": "1\n2\n1\n2\n3",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p01501 Shelter | Solve the following coding problem using the programming language python:
Example
Input
4 1
0 0
3 0
3 3
0 3
1 1
Output
2.0000000000
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_47085 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n0 0\n3 0\n3 3\n0 3\n1 1",
"output": "2.0000000000",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01949 Route Calculator | Solve the following coding problem using the programming language python:
You have a grid with $H$ rows and $W$ columns. $H + W$ is even. We denote the cell at the $i$-th row from the top and the $j$-th column from the left by ($i, j$). In any cell ($i, j$), an integer between $1$ and $9$ is written if $i+j$ is even, ... | vfc_47097 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n2+2+1\n+1+1+\n1+2+2\n+1+1+\n1+1+2",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1+2\n+9*\n1*5",
"output": "46",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02236 Optimal Binary Search Tree | Solve the following coding problem using the programming language python:
Optimal Binary Search Tree is a binary search tree constructed from $n$ keys and $n+1$ dummy keys so as to minimize the expected value of cost for a search operation.
We are given a sequence $K = {k_1, k_2, ..., k_n}$ of $n$ distinct keys in so... | ```python
n=int(input())
A=[0.0]+[float(i) for i in input().split()]
B=[float(i) for i in input().split()]
W={}
E={}
for i in range(1,n+2):
W[i,i-1] = B[i-1]
E[i,i-1] = B[i-1],i
for i in range(1,n+1):
for j in range(i,n+1):
W[i,j] = W[i,j-1]+A[j]+B[j]
for i in range(1,n+1):
E[i,i] = E[i,i-1][0] ... | vfc_47105 | {
"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": "5\n0.1500 0.1000 0.0500 0.1000 0.2000\n0.0500 0.1000 0.0500 0.0500 0.0500 0.1000",
"output": "2.75000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n0.0400 0.0600 0.0800 0.0200 0.1000... |
code_contests | verifiable_code | p02382 Distance II | Solve the following coding problem using the programming language python:
Your task is to calculate the distance between two $n$ dimensional vectors $x = \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan dis... | ```python
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
d = []
for i in range(n):
d.append(abs(x[i]-y[i]))
print(sum(d))
print(sum(list(map(lambda x:x**2,d)))**(1/2))
print(sum(list(map(lambda x:x**3,d)))**(1/3))
print(max(d))
``` | vfc_47109 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n2 0 4",
"output": "4.000000\n2.449490\n2.154435\n2.000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 2 3\n2 0 4",
"output": "3.000000\n2.236068\n2.080084\n2.000000\... |
code_contests | verifiable_code | cd101 | Solve the following coding problem using the programming language python:
Three dinos go on a camping trip. There they decide to play a game. They mark distances of 1 km each on the ground up to 100 km i.e. 1, 2, 3...100. They can sit only on these 100 spots, with each one at a different spot. In one move, one of the ... | ```python
from sys import stdin
a,b,c=map(int,stdin.readline().split())
if c-b>b-a:
print c-b-1
elif c-b<b-a:
print b-a-1
else:
print c-b-1
``` | vfc_47113 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 7",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6 11",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 5 7"... |
code_contests | verifiable_code | csub | Solve the following coding problem using the programming language python:
Given a string S consisting of only 1s and 0s, find the number of substrings which start and end both in 1.
In this problem, a substring is defined as a sequence of continuous characters Si, Si+1, ..., Sj where 1 ≤ i ≤ j ≤ N.
Input
First line ... | ```python
for _ in range(input()):
input()
n = raw_input().strip().count('1')
print n * (n+1)/2
``` | vfc_47117 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1111\n5\n10001",
"output": "10\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n1111\n5\n10000",
"output": "10\n1\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | horses | Solve the following coding problem using the programming language python:
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the r... | ```python
def calculateMin(l):
l = sorted(l)
j=2
dis = abs(l[0]-l[1])
for i in range(1, len(l)-1):
val = abs(l[i]-l[j])
if(val<dis):
dis=val
j+=1
if(j>=len(l)):
break
return dis
t = input()
while(t>0):
n = input()
l = list(map(int, raw... | vfc_47121 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n4 9 1 32 13",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n7 9 1 32 13",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | mnmx | Solve the following coding problem using the programming language python:
Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A.
Select a pair of adjacent integers and remove the larger one of these two. This ... | ```python
t = input()
for i in range(t):
n = input()
l = []
l += map(int, raw_input().split())
l.sort()
cost = 0
for j in range(n-1):
large = max(l[0],l[1])
cost += min(l[0],l[1])
l.remove(large)
print cost
``` | vfc_47125 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n3 4\n3\n4 2 5",
"output": "3\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n3 4\n3\n4 2 9",
"output": "3\n4\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | resist | Solve the following coding problem using the programming language python:
The electrical resistance is the opposition to the passage of electric current. If two resistors with resistance R1 and R2 are connected to each other, the resultant resistance R depends on how their ends are connected. If they are connected in ... | ```python
matrix = [[1,1], [1,0]]
def matrixExponentiation(n,m):
if n:
temp = matrixExponentiation(n/2, m)
if n&1:
return matrixMultiply(matrixMultiply(temp, temp, m), matrix, m)
else:
return matrixMultiply(temp, temp, m)
else:
return [[1,0],[0,1]]
def matrixMultiply(a, b, m):
return [... | vfc_47129 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 10\n2 12\n100 10000",
"output": "1/1\n2/3\n4301/9525\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 10\n1 12\n100 10000",
"output": "1/1\n1/1\n4301/9525\n",
"type": ... |
code_contests | verifiable_code | twodogs | Solve the following coding problem using the programming language python:
In Chef's house there are N apples lying in a row on the floor. These apples are numbered from 1 (left most one) to N (right most one). The types of apples are also numbered by positive integers, and the type of apple i is Ti.
Chef has recently ... | ```python
a=[0]*1000001
t,k=[int(x) for x in raw_input().split()]
e=[int(x) for x in raw_input().split()]
flag=0
count=0
i=0
while i<t/2:
f=e[i]
b=e[t-i-1]
if((f!=b)&(f+b==k)):
count+=1
flag=1
break
elif(a[f]==1):
count+=1
flag=1
break
elif(a[b]==1):
... | vfc_47133 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n2 4 3 2 1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n2 4 9 2 5",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1017_E. The Supersonic Rocket | Solve the following coding problem using the programming language python:
After the war, the supersonic rocket became the most common public transportation.
Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n power sources, and the second one has m power s... | ```python
import sys
# > 0 anti-clock, < 0 clockwise, == 0 same line
def orientation(p1, p2, p3):
return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0])
def dot(p1, p2, p3, p4):
return (p2[0]-p1[0])*(p4[0]-p3[0]) + (p2[1]-p1[1])*(p4[1]-p3[1])
def theta(p1, p2):
dx = p2[0] - p1[0]
... | vfc_47137 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n0 0\n",
"output": "NO\n",
"type": "... |
code_contests | verifiable_code | 1041_B. Buying a TV Set | Solve the following coding problem using the programming language python:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets... | ```python
from fractions import gcd
a, b, x, y = map(int, input().split())
gcd = gcd(x, y)
x /= gcd
y /= gcd
res = int(min(a // x, b // y))
print(res)
``` | vfc_47141 | {
"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 2 6 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000 1000000000000000000 999999866000004473 999999822000007597\n",
"output": "1000000063\n",
... |
code_contests | verifiable_code | 1064_A. Make a triangle! | Solve the following coding problem using the programming language python:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she need... | ```python
a, b, c = map(int, input().split())
m = max(a, b, c)
n = a+b+c-m
if n<=m:
print(m-n+1)
else:
print(0)
``` | vfc_47145 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 10 10\n",
"output": "81\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 1085_F. Rock-Paper-Scissors Champion | Solve the following coding problem using the programming language python:
n players are going to play a rock-paper-scissors tournament. As you probably know, in a one-on-one match of rock-paper-scissors, two players choose their shapes independently. The outcome is then determined depending on the chosen shapes: "pape... | vfc_47149 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\nRPS\n1 S\n2 R\n3 P\n1 P\n2 P\n",
"output": "2\n2\n1\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 8\nRR\n2 P\n2 S\n1 P\n2 P\n2 R\n1 S\n2 P\n2 S\n",
"output": "2\n1\... | |
code_contests | verifiable_code | 1105_D. Kilani and the Game | Solve the following coding problem using the programming language python:
Kilani is playing a game with his friends. This game can be represented as a grid of size n × m, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell).
The game... | ```python
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in... | vfc_47153 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 2\n1 1\n1..\n...\n..2\n",
"output": "6 3 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1132_G. Greedy Subsequences | Solve the following coding problem using the programming language python:
For some array c, let's denote a greedy subsequence as a sequence of indices p_1, p_2, ..., p_l such that 1 ≤ p_1 < p_2 < ... < p_l ≤ |c|, and for each i ∈ [1, l - 1], p_{i + 1} is the minimum number such that p_{i + 1} > p_i and c[p_{i + 1}] > ... | vfc_47157 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 6\n4 5 2 5 3 6 6\n",
"output": "3 3 ",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1153_C. Serval and Parenthesis Sequence | Solve the following coding problem using the programming language python:
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School.
In his favorite math class, the teacher taught him the following interesting definitions.
A parenthesis sequence is a string, containing only charact... | ```python
n = int(input())
s = list(input())
if n % 2 == 1:
print(":(")
else:
op = n // 2 - s.count("(")
for i in range(n):
if s[i] == "?":
if op > 0:
s[i] = "("
else:
s[i] = ")"
op -= 1
#print("".join(s))
b = 0
for i in... | vfc_47161 | {
"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\n(?????\n",
"output": "((()))\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n(???(???(?\n",
"output": ":(\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1175_B. Catch Overflow! | Solve the following coding problem using the programming language python:
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains th... | ```python
import sys
MAX_NUMBER = 2**32 - 1
def solve():
input = sys.stdin.readline
n = int(input())
stack = []
for _ in range(n):
oper = input().strip()
if oper == 'add':
stack.append(1)
elif oper == 'end':
cur = 0
while len(stack) > 0:... | vfc_47165 | {
"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\nfor 62\nend\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\nfor 100\nfor 100\nfor 100\nfor 100\nfor 100\nadd\nend\nend\nend\nend\nend\n",
"output": "OVERFLOW!... |
code_contests | verifiable_code | 1194_A. Remove a Progression | Solve the following coding problem using the programming language python:
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You... | ```python
test=int(input())
while(test!=0):
n,x=map(int,input().split())
print(2*x)
test-=1
``` | vfc_47169 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1\n4 2\n69 6\n",
"output": "2\n4\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n241139 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 1252_G. Performance Review | Solve the following coding problem using the programming language python:
Randall is a software engineer at a company with N employees. Every year, the company re-evaluates its employees. At the end of every year, the company replaces its several worst-performing employees and replaces with the same number of new empl... | vfc_47181 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 3\n50 40 30 20 10\n4 1 2 3 100\n1 4\n2 6 7\n1 3 300\n2 1 400\n2 1 5\n",
"output": "\n1\n0\n1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1272_F. Two Bracket Sequences | Solve the following coding problem using the programming language python:
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessar... | ```python
def scs(str1, str2):
"""Shortest Common Supersequence"""
INF = 10 ** 9
dp = [[[INF] * 210 for _ in range(210)] for _ in range(210)]
dp[0][0][0] = 0
prv = [[[None] * 210 for _ in range(210)] for _ in range(210)]
len_str1 = len(str1)
len_str2 = len(str2)
str1 += "#"
str2... | vfc_47185 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": ")\n)))\n",
"output": "((()))\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "())\n(()(()(()(\n",
"output": "(()(()(()())))\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 131_A. cAPS lOCK | Solve the following coding problem using the programming language python:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
L... | ```python
a=str(input())
b=a[:];c=a[:];d=a[:]
b=b.upper();d=d.upper();c=c.lower()
if a==b:
a=a.lower()
elif a[0]==c[0]:
if len(a)>1:
if a[1:]==d[1:]:
a=a.capitalize()
else:
pass
else:
a=a.upper()
else:
pass
print(a)
``` | vfc_47193 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "cAPS\n",
"output": "Caps\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Lock\n",
"output": "Lock\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1360_B. Honest Coach | Solve the following coding problem using the programming language python:
There are n athletes in front of you. Athletes are numbered from 1 to n from left to right. You know the strength of each athlete — the athlete number i has the strength s_i.
You want to split all athletes into two teams. Each team must have at... | ```python
for i in range(int(input())):
n=int(input())
lst=list()
x=list(map(int,input().split()))
x.sort()
if len(set(x))!=len(x):
print(0)
else:
for i in range(n-1):
lst.append(x[i+1]-x[i])
print(min(lst))
``` | vfc_47201 | {
"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\n5\n3 1 2 6 4\n6\n2 1 3 2 4 3\n4\n7 9 3 1\n2\n1 1000\n3\n100 150 200\n",
"output": "1\n0\n2\n999\n50\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5\n3 1 2 6 4\n6\n2 1 3 2 4 3\n4\n7... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.