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 | 316_E3. Summer Homework | Solve the following coding problem using the programming language python:
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the follow... | vfc_71409 | {
"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": "5 4\n1 3 1 2 4\n3 1 4 1\n2 2 4\n1 2 10\n2 1 5\n",
"output": "12\n45\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5\n",
"output": "... | |
code_contests | verifiable_code | 33_D. Knights | Solve the following coding problem using the programming language python:
Berland is facing dark times again. The army of evil lord Van de Mart is going to conquer the whole kingdom. To the council of war called by the Berland's king Valery the Severe came n knights. After long discussions it became clear that the kin... | vfc_71413 | {
"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 1\n0 0\n3 3\n2 0 0\n1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1\n0 0\n4 4\n1 0 0\n2 0 0\n3 0 0\n1 2\n",
"output": "3\n",
"type": "stdin_stdou... | |
code_contests | verifiable_code | 363_A. Soroban | Solve the following coding problem using the programming language python:
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This ... | ```python
def answer(n):
if n==0:
print('O-|-OOOO')
while n!=0:
i=n%10
if i<5:
x=4-i
print("O-|",end="")
while i>0:
print("O", end="")
i=i-1
print("-", end="")
while x>0:
... | vfc_71417 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "O-|OO-OO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "720\n",
"output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 386_D. Game with Points | Solve the following coding problem using the programming language python:
You are playing the following game. There are n points on a plane. They are the vertices of a regular n-polygon. Points are labeled with integer numbers from 1 to n. Each pair of distinct points is connected by a diagonal, which is colored in on... | ```python
from collections import deque
__author__ = 'asmn'
n = int(input())
end = tuple(sorted(map(lambda x: int(x) - 1, input().split())))
st = (0, 1, 2)
mat = [input() for i in range(n)]
v = set([st])
path = {}
dist = {st: 0}
queue = deque([st])
while end not in v and len(queue) > 0:
p = queue.popleft()
... | vfc_71421 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3 4\n*abc\na*ab\nba*b\ncbb*\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 3 4\n*aba\na*ab\nba*b\nabb*\n",
"output": "1\n4 1\n",
"type": "stdin_std... |
code_contests | verifiable_code | 407_C. Curious Array | Solve the following coding problem using the programming language python:
You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, each query can be described by three integers li, ri, ki. Query li, ri, ki means that we should add <image> to each element a[j], where li ≤ j ≤ ... | vfc_71425 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n0 0 0 0 0\n1 5 0\n",
"output": "1 1 1 1 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n1 2 3 4 5 0 0 0 0 0\n1 6 1\n6 10 2\n",
"output": "2 4 6 8 10 7 3 6 10 15 \n",
... | |
code_contests | verifiable_code | 434_D. Nanami's Power Plant | Solve the following coding problem using the programming language python:
Nanami likes playing games, and is also really good at it. This day she was playing a new game which involved operating a power plant. Nanami's job is to control the generators in the plant and produce maximum output.
There are n generators in ... | vfc_71429 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 8\n1 -8 20\n2 -4 0\n-1 10 -10\n0 1 0\n0 -1 1\n1 9\n1 4\n0 10\n3 11\n7 9\n2 1 3\n1 2 3\n2 3 3\n3 2 3\n3 4 3\n4 3 3\n4 5 3\n5 4 3\n",
"output": "46\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 457_A. Golden System | Solve the following coding problem using the programming language python:
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number <image>, in particular that q2 = q + 1, and she thinks it would make a good base for her new unique... | ```python
from sys import stdin
s=list(stdin.readline().strip()[::-1])
s1=list(stdin.readline().strip()[::-1])
def trans(s):
s.append("0")
i=len(s)-1
while i>1:
while i>=len(s):
s.append("0")
if s[i-1]=="1" and s[i-2]=="1":
s[i]="1"
s[i-1]="0"
... | vfc_71433 | {
"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": "110\n101\n",
"output": ">",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "00100\n11\n",
"output": "=",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 479_D. Long Jumps | Solve the following coding problem using the programming language python:
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l... | ```python
n,l,x,y = map(int, input().split())
a = list(map(int, input().split()))
i = 0
j = 1
tot = 0
can_measure_a = False
while j < n:
if a[j] - a[i] == x:
can_measure_a = True
break
elif a[j] - a[i] > x:
i += 1
else:
j += 1
i = 0
j = 1
can_measure_b = False
w... | vfc_71437 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 300 185 230\n0 300\n",
"output": "2\n185 230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 250 185 230\n0 185 250\n",
"output": "1\n230\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 501_D. Misha and Permutations Summation | Solve the following coding problem using the programming language python:
Let's define the sum of two permutations p and q of numbers 0, 1, ..., (n - 1) as permutation <image>, where Perm(x) is the x-th lexicographically permutation of numbers 0, 1, ..., (n - 1) (counting from zero), and Ord(p) is the number of permut... | ```python
import sys
class SegmTree():
def __init__(self, array=None):
size = len(array)
N = 1
while N < size:
N <<= 1
self.N = N
self.tree = [0] * (2*self.N)
for i in range(size):
self.tree[i+self.N] = array[i]
self.build()
def b... | vfc_71441 | {
"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\n1 2 0\n2 1 0\n",
"output": "1 0 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 1\n0 1\n",
"output": "0 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 552_E. Vanya and Brackets | Solve the following coding problem using the programming language python:
Vanya is doing his maths homework. He has an expression of form <image>, where x1, x2, ..., xn are digits from 1 to 9, and sign <image> represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this ... | ```python
def find_best(s):
best = eval(s)
for i in range(0, len(s), 2):
if i > 0 and s[i - 1] == '*' or i == 0:
for j in range(i + 2, len(s), 2):
if j < len(s) - 1 and s[j + 1] == '*' or j == len(s) - 1:
sp = s[:i] + '(' + s[i:j + 1] + ')' + s[j + 1:]
... | vfc_71449 | {
"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+5*7+8*4\n",
"output": "303\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2+3*5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | 579_E. Weakness and Poorness | Solve the following coding problem using the programming language python:
You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the po... | ```python
def main():
input()
a = list(map(int, input().split()))
def f(a):
maxend = maxnow = 0
for x in a:
maxend = max(0, maxend + x)
maxnow = max(maxnow, maxend)
return maxnow
f1 = lambda x: f(i - x for i in a)
f2 = lambda x: f(x - i for i in a)
Max = max(abs(i) for i in a)... | vfc_71453 | {
"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 2 3\n",
"output": "1.0000000037252903\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 4\n",
"output": "2.0\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 623_A. Graph and String | Solve the following coding problem using the programming language python:
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with t... | ```python
def dfs(v, used, g):
used[v] = True
for x in g[v]:
if not used[x]:
dfs(x, used, g)
from collections import defaultdict, Counter
n, m = map(int, input().split())
g = defaultdict(set)
p = Counter()
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
g[a... | vfc_71461 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2\n1 3\n1 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n",
"output": "Yes\nbb\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 644_C. Hostname Aliases | Solve the following coding problem using the programming language python:
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. F... | ```python
from sys import stdin
from collections import defaultdict
def main():
s, d = input(), defaultdict(set)
for s in stdin.read().splitlines():
i = s.find('/', 8)
if i == -1:
d[s].add('')
else:
d[s[:i]].add(s[i:])
e = defaultdict(list)
for s, v in d... | vfc_71465 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n",... |
code_contests | verifiable_code | 671_C. Ultimate Weirdness of an Array | Solve the following coding problem using the programming language python:
Yasin has an array a containing n integers. Yasin is a 5 year old, so he loves ultimate weird things.
Yasin denotes weirdness of an array as maximum gcd(ai, aj) value among all 1 ≤ i < j ≤ n. For n ≤ 1 weirdness is equal to 0, gcd(x, y) is the ... | vfc_71469 | {
"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\n2 6 3\n",
"output": " 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n6 2 14 13 17 21 5 23 18 4 12 3 15 20 11 19 9 10... | |
code_contests | verifiable_code | 717_G. Underfail | Solve the following coding problem using the programming language python:
You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons call... | ```python
import sys
from heapq import heappop, heappush
class Edge:
def __init__(self, u, v, cap, flow, cost, rev):
self.u = u
self.v = v
self.cap = cap
self.flow = flow
self.cost = cost
self.rev = rev
def add_edge(adj, u, v, capv, flowv, costv):
adj[u].append(... | vfc_71477 | {
"difficulty": "13",
"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\nabacba\n2\naba 6\nba 3\n3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\nafxfxfg\n3\nf 3\nx 2\nfxf 6\n1\n",
"output": "13\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 739_C. Alyona and towers | Solve the following coding problem using the programming language python:
Alyona has built n towers by putting small cubes some on the top of others. Each cube has size 1 × 1 × 1. A tower is a non-zero amount of cubes standing on the top of each other. The towers are next to each other, forming a row.
Sometimes Alyon... | vfc_71481 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 5 5 5 5\n3\n1 3 2\n2 2 1\n4 4 1\n",
"output": "2\n4\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n10 2 8 8 4 2 4\n7\n7 7 20\n3 4 75\n5 7 14\n1 5 10\n2 4 14\n5 7 51\n6 6 67\n",... | |
code_contests | verifiable_code | 762_B. USB vs. PS/2 | Solve the following coding problem using the programming language python:
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!
T... | ```python
from sys import stdin as fin
a,b,c = [int(i) for i in input().split()]
n = int(input())
usb = []
ps2 = []
for i in range(n):
a1,a2 =fin.readline().strip().split()
if a2=='USB':
usb.append(int(a1))
else:
ps2.append(int(a1))
usb = sorted(usb)
ps2 = sorted(ps2)
n1 = len(usb)
n2... | vfc_71485 | {
"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 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n",
"output": "3 14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 0\n1\n2 USB\n",
"output": "0 0\n",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | 785_C. Anton and Fairy Tale | Solve the following coding problem using the programming language python:
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build ... | ```python
def binary_search_first_true(predicate, from_inclusive, to_inclusive):
lo = from_inclusive - 1
hi = to_inclusive + 1
while hi - lo > 1:
mid = (lo + hi) // 2
if not predicate(mid):
lo = mid
else:
hi = mid
return hi
def tri(n):
return n*(n+1)//2
... | vfc_71489 | {
"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": "8 1\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 831_D. Office Keys | Solve the following coding problem using the programming language python:
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by s... | ```python
def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
n,k,p = map_input()
a = list_input()
b = list_input()
a.sort()
b.sort()
ans = 1000000000000000000
for i in range(k-n+1):
cur = 0
c1 = 0
... | vfc_71497 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 10\n11\n15 7\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4 50\n20 100\n60 10 40 80\n",
"output": "50",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 852_E. Casinos and travel | Solve the following coding problem using the programming language python:
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from... | ```python
n=int(input())
a=[0]*n
for i in range(n-1):
for j in input().split():
a[int(j)-1]+=1
l=a.count(1)
print((l*2**(n-l+1)+(n-l)*2**(n-l))%1000000007)
``` | vfc_71501 | {
"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\n1 2\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 876_F. High Cry | Solve the following coding problem using the programming language python:
Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary ec... | ```python
import os,io,sys
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n=int(input())
a=list(map(int,input().split()))
left=[]
right=[]
for i in range(31):
left.append([-1]*n)
right.append([n]*n)
for i in range(n):
for j in range(31):
if 1<<j&a[i]:
left[j][i]=i
else:
if i>0:
... | vfc_71505 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 2 1 6 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 3 3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 900_A. Find Extra One | Solve the following coding problem using the programming language python:
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
Input
The first line contains a single positive integer n (2 ≤ ... | ```python
foo = int(input())
gr = 0
lo = 0
for i in range(foo):
bar = int((input().split(' '))[0])
if bar < 0:
lo += 1
else:
gr += 1
if lo > 1 and gr > 1:
print('No')
break
else:
print('Yes')
``` | vfc_71509 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n2 1\n4 60\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n-1 -1\n2 -1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 922_E. Birds | Solve the following coding problem using the programming language python:
Apart from plush toys, Imp is a huge fan of little yellow birds!
<image>
To summon birds, Imp needs strong magic. There are n trees in a row on an alley in a park, there is a nest on each of the trees. In the i-th nest there are ci birds; to s... | ```python
def run1(unit,cst):
cst *= unit
for j in range(cnt+1)[::-1]:
if dp[j] >= cst:
dp[j+unit] = max(dp[j+unit],dp[j] - cst)
n,w,b,x = map(int,raw_input().split(" "))
cap = map(float,raw_input().split(" "))
cost = map(float,raw_input().split(" "))
dp = [-1.]*10005
dp[0] = float(w)
cnt ... | vfc_71513 | {
"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 10 7 11\n2 10\n6 1\n",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 12 0 4\n3 4\n4 2\n",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 950_A. Left-handers, Right-handers and Ambidexters | Solve the following coding problem using the programming language python:
You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players... | ```python
l, r, a = map(int, input().split())
while a != 0:
if l < r:
l += 1
else:
r += 1
a -= 1
print(min(l, r)*2)
``` | vfc_71517 | {
"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": "0 2 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 4 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5... |
code_contests | verifiable_code | 978_D. Almost Arithmetic Progression | Solve the following coding problem using the programming language python:
Polycarp likes arithmetic progressions. A sequence [a_1, a_2, ..., a_n] is called an arithmetic progression if for each i (1 ≤ i < n) the value a_{i+1} - a_i is the same. For example, the sequences [42], [5, 5, 5], [2, 11, 20, 29] and [3, 2, 1, ... | ```python
import math
import sys
import collections
import bisect
import time
import random
from itertools import permutations
def get_ints():return map(int, sys.stdin.readline().strip().split())
def get_list():return list(map(int, sys.stdin.readline().strip().split()))
def get_string():return sys.stdin.readline().stri... | vfc_71521 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n500 500\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 3 6 9 12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 998_C. Convert to Ones | Solve the following coding problem using the programming language python:
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* ... | ```python
n,x,y=map(int,input().split())
s=input()
c=0
for i in range(1,n):
if s[i]=='1' and s[i-1]=='0':
c+=1
if s[-1]=='0':
c+=1
if c==0:
print(0)
elif x>=y:
print(c*y)
else:
print((c-1)*x+y)
``` | vfc_71525 | {
"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 10 1\n01000\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2 3\n1111111\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | beautiful-primes | Solve the following coding problem using the programming language python:
John loves prime numbers. One day he was playing a game "primcia" with his wife alicia. The game is as follows, John write a number N on a table.
The number is of the form:
N = (P1^A1) * (P2^A2) * .............. * (Px^Ax).
Where Pi are prime... | ```python
M = 10**9 + 7
for t in xrange(input()):
X = input()
P = map(int,raw_input().split())
A = map(int,raw_input().split())
res = 1
for i in xrange(len(A)):
res *= ((pow(P[i],A[i]+1,M)-P[i]+M)%M)*(pow(P[i]-1,M-2,M))
res %= M
print res
``` | vfc_71529 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n2 3 5\n2 1 1\n\nSAMPLE",
"output": "90",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n2 3 5\n2 2 1\n\nSAMPLE",
"output": "360\n",
"type": "stdin_stdout"
},
{... |
code_contests | verifiable_code | coincide | Solve the following coding problem using the programming language python:
On a rod of length a+b+c, lengths a, b, c are measured at random. Your task is to calculate the probability that no point of the measured lines will coincide.
INPUT:
First line contains the number of test cases T, followed by T lines, each lin... | ```python
ts=input()
for i in range(ts):
a,b,c=map(int,raw_input().split(" "))
print str(c*c)+" / "+str((a+c)*(b+c))
``` | vfc_71533 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 1 1\n\nSAMPLE",
"output": "1 / 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n6443 5331 1231\n12 455 541\n1100 599 10\n1552 1479 742\n1122 258 741\n12 546 789\n12 12 12",
... |
code_contests | verifiable_code | fare-evaluator-2 | Solve the following coding problem using the programming language python:
Statement: Sourav and his friends are in kolkata city and they are
planning for a city tour. So, they booked a TUBER cab
(Stop Giggling). Please help them to find the estimated fare
according to the fare evaluator system of TUBER cabs.
How to ... | ```python
t=input()
for i in range(t):
flag=1
f=0
i,j=map(int,raw_input().split())
if i>60:
print "NA"
flag=0
elif i<=2:
f=50+j*2
else:
k=i-2
f+=(k*12)+(2*j)+50
if flag==1:
print f
``` | vfc_71537 | {
"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 2\n12 0\n61 3\n\nSAMPLE",
"output": "90\n170\nNA\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | humpty-dumpty | Solve the following coding problem using the programming language python:
Humpty Dumpty lives on a two-dimensional plane. He likes to jump. Currently, he is located in the point (0, 0). He would like to reach the point (x, y). You are given the point x & y.
Humpty Dumpty wants to reach the desired destination in a sp... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
import math
T = int(sys.stdin.readline())
for i in xrange(T):
N = int(sys.stdin.readline())
line = sys.stdin.readline().split()
x = int(line[0])
y = int(line[1... | vfc_71541 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n0 0\n1\n1\n2\n2\n5 4\n2\n5\n1\n3 4\n4\n\nSAMPLE",
"output": "Able\nAble\nNot able",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n1\n3 4\n4\n10\n11 12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1... |
code_contests | verifiable_code | mahabirs-queries | Solve the following coding problem using the programming language python:
Mahabir loves matrix and likes to rotate things a lot.
Today he is rotating an array in clock-wise direction. He gives you an array of size N X N and an positive integer Q.
Each Q number of integers contains an angle A (angle is always multip... | ```python
r=raw_input
def ints():
return map(int,r().split())
n,q=ints()
M=[]
for i in range(n):
M.append(ints())
angle=0
m=n-1
for t in range(q):
angle=(input())%360
#print angle
if angle==0:
for i in range(n):
print " ".join(map(str,M[i]))
print
elif angle==90:
for i in range(n):
for j in range(n):... | vfc_71545 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 4 5 \n6 7 8 \n4 0 5 \n90\n180\n450\n\nSAMPLE",
"output": "4 6 1\n0 7 4\n5 8 5\n\n5 0 4\n8 7 6\n5 4 1\n\n4 6 1\n0 7 4\n5 8 5\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 ... |
code_contests | verifiable_code | no-of-1s-0s | Solve the following coding problem using the programming language python:
Aravind has a hexadecimal number H. he is willing to find number of ones and zeros in that number. He needs your help to solve his problem.
input
first line consists of t testcases
next t lines contains a string consists of hexadecimal numbers(... | ```python
n = int(raw_input())
i = 0
while i < n:
'''
my_hexdata = raw_input()
scale = 16
num_of_bits = 8
print bin(int(my_hexdata, scale))[2:].zfill(num_of_bits)
#print bin(int(my_hexdata, scale))[2:]
'''
s = ""
tc = raw_input().strip()
for x in tc:
s += str(bin(int(x,16))[2:].zfill(4))
#first test c... | vfc_71549 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1234F\nAB2D\n\nSAMPLE",
"output": "9 11\n9 7",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | puzzleria | Solve the following coding problem using the programming language python:
Rohan bought new book Puzzleria in which he has to solve the puzzle.
So,now he need your help to solve one of the puzzle were he is given X consonant
and Y vowels to make a word from it whose length is equals to X + Y.
So now your are given the ... | ```python
import math
for _ in range(input()):
a,b = map(int,raw_input().split())
c= math.factorial(7)/(math.factorial(7-a)*math.factorial(a))
d= math.factorial(5)/(math.factorial(5-b)*math.factorial(b))
e = c*d*math.factorial(a+b)
print e
``` | vfc_71553 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 2\n\nSAMPLE",
"output": "1058400\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n5 2 \n4 2 \n5 3 \n6 5 \n3 3 \n3 4 \n2 5 \n2 2 \n4 1\n5 4",
"output": "1058400\n252000\n84672... |
code_contests | verifiable_code | shil-and-birthday-present | Solve the following coding problem using the programming language python:
Shil got an array of N integers as a present on his birthday. But he didn't liked it. Shil wants to make this array beautiful. Shil considers an array A1,A2,A3 . . . AN beautiful if A1 > AN. Inorder to make it beautiful Shil can swap any two n... | ```python
N=input()
s=raw_input().split(' ')
a=set()
for i in range(N):
a.add(int(s[i]))
l=len(a)
print (l*(l-1))/2
``` | vfc_71557 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 4 3 2 5\n\nSAMPLE",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | the-hound-vs-the-mountain-2 | Solve the following coding problem using the programming language python:
The Hound and his brother the Mountain are engaged in a fight against each other in King's Landing. At the end of the fight, one dies and the other wins. They both are given a decimal number each in the 8 bit binary representation A and B. These... | ```python
t = int(raw_input())
while t>0:
arr = [str(i) for i in raw_input().split()]
a = int(arr[0],2)
b = int(arr[1],2)
if pow(a,1.0/a) <= pow(b,1.0/b):
print 'The Hound'
else:
print 'The Mountain'
t-=1
``` | vfc_71561 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n00111011 01100101\n00110011 11001100\n01010101 10101010\n01011100 10100111\n11111100 01011000 \n00101101 11001011\n00101010 10101010\n\nSAMPLE",
"output": "The Mountain\nThe Mountain\nThe Mountain\nThe Mountain\nThe Hound\... |
code_contests | verifiable_code | p00082 Flying Jenny | Solve the following coding problem using the programming language python:
<image>
You know the merry-go-round in the amusement park. Vehicles such as horses and carriages are fixed on a large disk, and it is a standard playset that the vehicle swings up and down at the same time as the disk rotates. A merry-go-round... | ```python
from copy import copy
p = []
while(1):
try:
p = [int(i) for i in input().split()]
min_ = 10**10
point = 0
arrmin = []
arr = [4,1,4,1,2,1,2,1]
for _ in range(8):
temp = copy(arr[0])
repl = copy(arr[1:8])
arr[0:7] = repl
... | vfc_71609 | {
"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": "2 3 1 4 0 1 0 1\n4 2 3 2 2 2 1 1",
"output": "1 4 1 4 1 2 1 2\n4 1 4 1 2 1 2 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1 4 0 1 1 1\n4 2 3 2 2 2 1 1",
"output": "1 4 1 4 1 2... |
code_contests | verifiable_code | p00214 Autumnal Illumination | Solve the following coding problem using the programming language python:
In Square Town, where many people who love squares live, a festival is held to color the town with illuminations that combine square lightning boards. This electric board emits light when electricity is applied, and the plate in contact with the... | ```python
def dot3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy)
def cross3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (by - oy) - (bx - ox) * (ay - oy)
def dist2(A, B):
ax, ay = A; bx, by = B
return (ax - bx) ** 2 + (ay - ... | vfc_71613 | {
"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\n0 0 0 1 1 1 1 0\n2\n0 0 0 1 1 1 1 0\n100 100 100 200 200 200 200 100\n2\n0 0 0 100 100 100 100 0\n10 10 10 20 20 20 20 10\n2\n1\n30 40 40 50 40 20 20 10\n1\n30 40 40 50 40 20 20 10\n0",
"output": "1\n2\n1\n1\n1",
... |
code_contests | verifiable_code | p00728 ICPC Score Totalizer Software | Solve the following coding problem using the programming language python:
<image>
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that some... | ```python
while 1:
n = int(input())
if n == 0:
break
s = [int(input()) for i in range(n)]
s.sort()
x = sum(s) - (s[0] + s[-1])
print(x // (n - 2))
``` | vfc_71625 | {
"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\n1000\n342\n0\n5\n2\n2\n9\n11\n932\n5\n300\n1000\n0\n200\n400\n8\n353\n242\n402\n274\n283\n132\n402\n523\n0",
"output": "342\n7\n300\n326",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\... |
code_contests | verifiable_code | p00868 Spherical Mirrors | Solve the following coding problem using the programming language python:
A long time ago in a galaxy, far, far away, there were N spheres with various radii. Spheres were mirrors, that is, they had reflective surfaces . . . .
You are standing at the origin of the galaxy (0, 0, 0), and emit a laser ray to the directi... | vfc_71629 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n-20 -20 -24\n100 100 100 30\n10 8 3 5\n-70 -70 -84 5\n4\n0 47 84\n-23 41 42 8\n45 -10 14 19\n-5 28 47 12\n-27 68 34 14\n0",
"output": "79.0940 79.0940 94.9128\n-21.8647 54.9770 34.1761",
"type": "stdin_stdout"
},... | |
code_contests | verifiable_code | p00999 Rental DVD Shop NEO | Solve the following coding problem using the programming language python:
Problem
I started a part-time job at the rental DVD shop "NEO". First of all, I decided to study the fee system of this store.
There are three types of rental DVDs, old, semi-new, and new, and the rental fee for one DVD is a yen, b yen, and c ... | ```python
# AOJ 1509 Rental DVD Shop NEO
# Python3 2018.7.13 bal4u
while True:
a, b, c, d, e = map(int, input().split())
if a == 0: break
na, nb, nc = map(int, input().split())
if nc >= d: ans = e*nc + b*nb + a*na
else:
ans = c*nc + b*nb + a*na
k = d-nc;
if k <= nb: nb -= k; k = 0
else: k -= nb; nb = 0
... | vfc_71633 | {
"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": "70 100 340 4 200\n1 1 4\n70 100 340 4 200\n0 1 3\n70 100 340 4 200\n1 1 2\n0 0 0 0 0",
"output": "970\n800\n800",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "70 100 340 4 200\n1 1 4\n70 10... |
code_contests | verifiable_code | p01131 Keitai Message | Solve the following coding problem using the programming language python:
Alice wants to send an email to Miku on her mobile phone.
The only buttons that can be used for input on mobile phones are number buttons. Therefore, in order to input characters, the number buttons are pressed several times to input characters... | ```python
keylist = [
[],
['.', ',', '!', '?', ' '],
['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i'],
['j', 'k', 'l'],
['m', 'n', 'o'],
['p', 'q', 'r', 's'],
['t', 'u', 'v'],
['w', 'x', 'y', 'z']
]
for i in range(int(input())):
output = ''
for item in input().split('0'):
if i... | vfc_71637 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n20\n220\n222220\n44033055505550666011011111090666077705550301110\n000555555550000330000444000080000200004440000",
"output": "a\nb\nb\nhello, world!\nkeitai",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01270 Restrictive Filesystem | Solve the following coding problem using the programming language python:
You are a programmer on the development team for new recording media. This recording medium can be randomly accessed for reading and erasing data. On the other hand, when writing data, access is always performed in order from the beginning, and ... | ```python
from bisect import bisect_right
while True:
N = int(input())
if N==0:
break
mem = [] # (l, r, id)
for _ in range(N):
command = input().split()
if command[0]=="W":
Id, S = map(int, command[1:])
subS = S
idx_mem = 0
idx = ... | vfc_71641 | {
"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": "6\nW 0 2\nW 1 2\nD 0\nW 2 4\nR 3\nR 1\n1\nR 1000000000\n0",
"output": "1\n2\n\n-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\nW 0 2\nW 1 2\nD 0\nW 2 4\nR 3\nR 2\n1\nR 1000000000\n0",
... |
code_contests | verifiable_code | p01440 Revenge of Champernowne Constant | Solve the following coding problem using the programming language python:
Champernowne constant is an irrational number. Its decimal representation starts with "0.", followed by concatenation of all positive integers in the increasing order.
You will be given a sequence S which consists of decimal digits. Your task i... | vfc_71645 | {
"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": "45678\n67891011\n21\n314159265358979",
"output": "4\n6\n15\n2012778692735799",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "45678\n67891011\n21\n314159265358979\n#",
"output": "4\n6\n... | |
code_contests | verifiable_code | p01589 Strange Currency System | Solve the following coding problem using the programming language python:
The currency system in the Kingdom of Yoax-Musty is strange and fairly inefficient. Like other countries, the kingdom has its own currencty unit denoted by K $ (kingdom dollar). However, the Ministry of Finance issues bills for every value betwe... | vfc_71649 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01746 Directions | Solve the following coding problem using the programming language python:
Sunuke cannot move in the initial state. The price of the i-th ticket is pi, which can be bought to move from (x, y) to (x + tai, y + tbi) for any (x, y) and any non-negative real number t. become able to. Find the minimum total amount of ticket... | vfc_71653 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2 3\n4 5 6",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n0 3 1\n0 3 2\n1 -1 2\n0 0 1\n-2 4 1\n-4 0 1\n2 1 2",
"output": "4",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | p01886 Share the Ruins Preservation | Solve the following coding problem using the programming language python:
Example
Input
8
-10 0
-10 5
-5 5
-5 0
10 0
10 -5
5 -5
5 0
Output
50
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
from collections import defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def cross3(p0, p1, p2):
return (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p1[1] - p0[1]) * (p2[0] - p0[0])
def solve():
N = int(readline())
mp = defaultdict(list)
for i in range(N):
x, y = ... | vfc_71657 | {
"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": "8\n-10 0\n-10 5\n-5 5\n-5 0\n10 0\n10 -5\n5 -5\n5 0",
"output": "50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n-10 0\n-10 5\n-5 5\n-5 -1\n10 0\n10 -5\n5 -5\n5 0",
"output": "53... |
code_contests | verifiable_code | p02023 Ravage | Solve the following coding problem using the programming language python:
I: Ravage
Santa Claus was caught in the illuminations of the city and broke it.
There are N light bulbs in the illumination, and the $ i $ th light bulb only comes on when the voltage is above $ A_i $ and below $ B_i $.
The voltage should be ... | ```python
n=int(input())
l=[]
for _ in [0]*n:
a,b=map(int,input().split())
l.extend([(a,1),(b+1,-1)])
l.sort()
c = 0
a = 0
for _,v in l:
c+=v
a=max(a,c)
print(a)
``` | vfc_71661 | {
"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": "4\n1 4\n3 6\n2 7\n5 8",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 4\n3 6\n2 7\n5 8",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | arhn04 | Solve the following coding problem using the programming language python:
Dhapu is a school girl who hacks and programs in free time. But right now she has to do her boring school homework. It's a few addition and subtraction problems. She has gotten bored with doing these repetitive questions. So, she wants to automa... | ```python
q = int(raw_input())
while q>0:
q = q - 1
a, b = 0, 0
s = raw_input()
SA, SB = "", ""
OP = ""
for i in s:
if i=='+' or i=='-':
op = i
SB = SA
SA = ""
continue
else:
SA = SA + i
ans = 0
if op=='-':
ans = int (SB) - int (SA)
else:
ans = int (SB) + int (SA)
print ans
``` | vfc_71677 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1+1\n1-2\n141654614141045641415616417161565497897981246+489748946511344946164879465416948465489426\n5467246752197212658296172941726172167-5467246752197212658296172941726172166",
"output": "2\n-1\n14214436308755698636178129... |
code_contests | verifiable_code | clarissa | Solve the following coding problem using the programming language python:
Problem description
Clarissa Adele Fray (a.k.a Clary) has found out that she is a shadowhunter, a human with angelic qualities. She can create her own runes (magical spells). Last week, she created many powerful runes.
Right now, she is facin... | ```python
MOD = 10**9+7
def fast_exp(base, exp):
res = 1
while (exp>=1):
if (exp%2==1):
res = (res*base)%MOD
base = (base*base)%MOD
exp/=2
return res
for testCase in range(int(raw_input())):
n = int(raw_input())
a = map(int,raw_input().split())
m = max(a)
c = a.count(m)
print fast_exp(2,c)-1
``` | vfc_71681 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n100\n3\n80 90 90",
"output": "1\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | fcbarca | Solve the following coding problem using the programming language python:
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural ta... | ```python
t=raw_input()
t=int(t)
while t!=0:
n, k=raw_input().split(' ')
n=int(n)
k=int(k)
count=0
i=1
while i<n:
count=pow(k, i)-count
i+=1
print (count%1000000007);
t-=1
``` | vfc_71685 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 4\n4 2",
"output": "4\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 4\n4 2",
"output": "12\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | lealco | Solve the following coding problem using the programming language python:
The Little Elephant and his friends from the Zoo of Lviv were returning from the party. But suddenly they were stopped by the policeman Big Hippo, who wanted to make an alcohol test for elephants.
There were N elephants ordered from the left to ... | ```python
#!/usr/bin/python
from sys import stdin
T = int(stdin.readline())
global N,K,M,R
global minimal
def check(i,current):
global N,K,M,R
global minimal
#print current,minimal,i,R
if current >= minimal:
return
if i >= N:
if current < minimal:
minimal = current
... | vfc_71689 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 3 2\n1 3 1 2 1\n5 3 3\n7 7 7 7 7\n5 3 3\n7 7 7 8 8\n4 3 1\n1 3 1 2",
"output": "0\n1\n1\n-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | pinoch2 | Solve the following coding problem using the programming language python:
After confronting Pinocchio, Lampwick decided to further analyse his diary about Pinocchio. (You can find the details about the diary in Part 1 of this problem)
Now he needs to find out the maximum number of days that passed by in which Pinocch... | ```python
# cook your code here
t = int(raw_input())
for i in xrange(t):
n = int(raw_input())
nums = map(int, raw_input().split())
d = {}
for num in nums:
d[num] = d.get(num, 0) + 1
m = max(d.values())
print m-1
``` | vfc_71693 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n7\n1 2 2 3 4 5 5",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n7\n1 2 2 3 8 5 5",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | strq | Solve the following coding problem using the programming language python:
Chef likes strings a lot but moreover he likes good strings. Chef calls a string str a good string if str starts and ends at different characters. For eg : strings such as abab , baccba , abc are all good strings whereas strings like aba, baab ,... | ```python
ch=str(raw_input())
length=len(ch)
arr=[]
cur=0
temp=[]
for k in range(length):
if(ch[k]=='c'):
cur+=1
temp.append(cur)
else:
temp.append(cur)
arr.append(temp)
cur=0
temp=[]
for k in range(length):
if(ch[k]=='e'):
cur+=1
temp.append(cu... | vfc_71697 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "checfcheff\n5\nc h 1 10\nc f 1 10\ne c 1 10\nc f 1 5\nc f 6 10",
"output": "4\n8\n2\n2\n2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1009_E. Intercity Travelling | Solve the following coding problem using the programming language python:
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but ... | ```python
from sys import stdin, stdout
def main():
p = 998244353 # Constante brindada por el problema
n = int(stdin.readline())
a = list(readline())
answer = a[-1]
pow_ = 1 # Potencia de 2
for i in range(n - 1, 0, -1): # Se analizan todas las dificultades
answer = (answer + a[i - 1... | vfc_71701 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 3 3 7\n",
"output": "60",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 1032_B. Personalized Cup | Solve the following coding problem using the programming language python:
At many competitions that have a word «cup» in its official name the winner is presented with an actual cup. This time the organizers of one unusual programming competition have decided to please the winner even more and to add a nameplate to th... | ```python
def print2d(a):
for i in range(len(a)):
print(''.join(list(map(str, a[i]))))
st = input()
for i in range(1, 5 + 1):
vst = len(st) // i
ost = len(st) % i
if vst + min(ost, 1) > 20:
continue
a = [0] * i
ind = 0
f = 0
for j in range(len(a)):
a[j] = []
... | vfc_71705 | {
"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": "MyNameIsLifeIAmForeverByYourSideMyNameIsLife\n",
"output": "3 15\nMyNameIsLifeIA*\nmForeverByYourS\nideMyNameIsLife\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "tourist\n",
"outpu... |
code_contests | verifiable_code | 1077_A. Frog Jumping | Solve the following coding problem using the programming language python:
A frog is currently at the point 0 on a coordinate axis Ox. It jumps by the following algorithm: the first jump is a units to the right, the second jump is b units to the left, the third jump is a units to the right, the fourth jump is b units t... | ```python
t=int(input())
while(t):
l=[]
l=[int(x) for x in input().split()]
a=l[0]
b=l[1]
k=l[2]
p=int(k/2)
if k%2==0:
y=(p*a)-(p*b)
else:
y=(p*a)-(p*b)+a
print(y)
t=t-1
``` | vfc_71713 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 2 3\n100 1 4\n1 10 5\n1000000000 1 6\n1 1 1000000000\n1 1 999999999\n",
"output": "8 198 -17 2999999997 0 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n598 56 799\n",
"out... |
code_contests | verifiable_code | 1097_H. Mateusz and an Infinite Sequence | Solve the following coding problem using the programming language python:
A Thue-Morse-Radecki-Mateusz sequence (Thorse-Radewoosh sequence in short) is an infinite sequence constructed from a finite sequence gen of length d and an integer m, obtained in the following sequence of steps:
* In the beginning, we define... | vfc_71717 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n0 1 2\n2\n0 2\n6 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n0 1\n4\n0 1 1 0\n2 21\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 1119_A. Ilya and a Colorful Walk | Solve the following coding problem using the programming language python:
Ilya lives in a beautiful city of Chordalsk.
There are n houses on the street Ilya lives, they are numerated from 1 to n from left to right; the distance between every two neighboring houses is equal to 1 unit. The neighboring houses are 1 and ... | ```python
import math
from decimal import Decimal
import heapq
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,c
def dv():
n, m = map(int, input().split())
retu... | vfc_71721 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 1 3 1 1 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1145_E. Fourier Doodles | Solve the following coding problem using the programming language python:
In this problem you have to solve a simple classification task: given an image, determine whether it depicts a Fourier doodle.
You are given a set of 50 images with ids 1 through 50. You are also given a text file labels.txt containing the lab... | ```python
for id in range(21, 51):
print(((min(id, 25) + id) % (2 + id % 3)) > 0 and 1 or 0)
``` | vfc_71725 | {
"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": "0\n",
"output": "0\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1\n",
"output": "0\n1\n1\n0... |
code_contests | verifiable_code | 1166_D. Cute Sequences | Solve the following coding problem using the programming language python:
Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ... | ```python
for _ in range(int(input())):
a,b,m=map(int,input().split())
if a==b:
print(1,a)
continue
for k in range(2,51):
pw=1<<(k-2)
mn=pw*(a+1)
mx=pw*(a+m)
if mn<=b<=mx:
r=[0]*(k+1)
add=b-mn
r[1]=a
for i in ran... | vfc_71729 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 26 2\n3 9 1\n",
"output": "4 5 7 13 26 \n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 100000000000000 100000000000000\n",
"output": "2 1 100000000000000\n",
"ty... |
code_contests | verifiable_code | 1185_B. Email from Polycarp | Solve the following coding problem using the programming language python:
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly o... | ```python
def f():
a=input()
i=0
p=a[i]
l=[]
while(i<len(a)):
temp=1
t=[p]
i+=1
while(i<len(a)):
if a[i]!=p:
p=a[i]
break
p=a[i]
t.append(p)
i+=1
if i==len(a):
... | vfc_71733 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nhello\nhello\nhello\nhelloo\nhello\nhlllloo\nhello\nhelo\n",
"output": "YES\nYES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\naa\nbb\ncodeforces\ncodeforce\npolycarp\npool... |
code_contests | verifiable_code | 1203_F1. Complete the Projects (easy version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich cust... | ```python
n,r = map(int,(input().split()))
plus=[]
minn=[]
for i in range (0,n):
temp = list(map(int,input().split()))
if temp[1] <=0:
temp.append(temp[0]+temp[1])
minn.append(temp)
else:
plus.append(temp)
plus.sort()
minn.sort(reverse=True,key = lambda x: x[2])
flag = True
for ... | vfc_71737 | {
"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\n4 -5\n4 -2\n1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n4 6\n10 -2\n8 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 1220_D. Alex and Julian | Solve the following coding problem using the programming language python:
Boy Dima gave Julian a birthday present — set B consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he ca... | ```python
import sys
input=sys.stdin.readline
import copy
from math import *
n=int(input())
a=[int(x) for x in input().split()]
d=[0 for i in range(70)]
for i in range(n):
d[int(log(a[i]&(-a[i]),2))]+=1
print(n-max(d))
r=d.index(max(d))
for i in range(n):
if int(log(a[i]&(-a[i]),2))!=r:
print(a[i],end="... | vfc_71741 | {
"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\n1 2 3\n",
"output": "1\n 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 6\n",
"output": "0\n",
"type": "... |
code_contests | verifiable_code | 1245_F. Daniel and Spring Cleaning | Solve the following coding problem using the programming language python:
While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute 1 + 3 using the calculator, he gets 2 instead of 4. But when he tries computing 1 + 4, he gets ... | ```python
def g( a , b ):
cur = 1
res = 0
ze = 0
while cur <= b:
if b & cur:
b ^= cur
if a & b == 0:
res += ( 1 << ze )
if a & cur == 0:
ze = ze + 1
cur <<= 1
return res
def f( a , b ):
res = 0
if a == b:
r... | vfc_71745 | {
"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\n1 4\n323 323\n1 1000000\n",
"output": "8\n0\n3439863766\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1265_D. Beautiful Sequence | Solve the following coding problem using the programming language python:
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, …, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 ≤ i ≤ n - 1.
Trans has a numbers 0, b number... | ```python
_count = list(map(int, input().split()))
num = '0 1 2 3'.split()
for pos in range(4):
count = _count[:]
ans = []
for i in range(sum(count)):
ans.append(num[pos])
count[pos] -= 1
if pos == 1:
if count[0] > 0:
pos = 0
else:
... | vfc_71749 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 3 4\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 2 1\n",
"output": "YES\n0 1 0 1 2 3 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1305_H. Kuroni the Private Tutor | Solve the following coding problem using the programming language python:
As a professional private tutor, Kuroni has to gather statistics of an exam. Kuroni has appointed you to complete this important task. You must not disappoint him.
The exam consists of n questions, and m students have taken the exam. Each quest... | vfc_71757 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n0 6\n0 6\n2 5\n6 6\n4 6\n1\n3 3\n30\n",
"output": "-1 -1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n2 4\n2 3\n1 1\n0 1\n0 0\n1\n4 1\n7\n",
"output": "3 2\n",
"ty... | |
code_contests | verifiable_code | 132_E. Bits of merry old England | Solve the following coding problem using the programming language python:
Another feature of Shakespeare language is that the variables are named after characters of plays by Shakespeare, and all operations on them (value assignment, output etc.) look like a dialog with other characters. New values of variables are de... | vfc_71761 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 2\n1 2 2 4 2 1 2\n",
"output": "11 4\na=1\nprint(a)\nb=2\nprint(b)\nprint(b)\nb=4\nprint(b)\nb=2\nprint(b)\nprint(a)\nprint(b)\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n1 2 3 ... | |
code_contests | verifiable_code | 134_C. Swaps | Solve the following coding problem using the programming language python:
There are n players sitting at a round table. All of them have s cards of n colors in total. Besides, initially the first person had cards of only the first color, the second one had cards of only the second color and so on. They can swap the ca... | ```python
from heapq import *
n, s = map(int, raw_input().split())
a = map(int, raw_input().split())
q = [(-x, i) for (i, x) in enumerate(a) if x > 0]
heapify(q)
res = []
while q:
(x, i) = heappop(q)
if -x > len(q):
print 'No'
break
for (y, j) in [heappop(q) for _ in xrange(-x)]:
res... | vfc_71765 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 8\n2 2 2 2\n",
"output": "Yes\n4\n4 3\n4 2\n1 3\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n0 0 0 0 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1370_C. Number Game | Solve the following coding problem using the programming language python:
Ashishgup and FastestFinger play a game.
They start with a number n and play in turns. In each turn, a player can make any one of the following moves:
* Divide n by any of its odd divisors greater than 1.
* Subtract 1 from n if n is grea... | ```python
import math
def isPrime(n) :
# Corner cases
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <... | vfc_71769 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n2\n3\n4\n5\n6\n12\n",
"output": "FastestFinger\nAshishgup\nAshishgup\nFastestFinger\nAshishgup\nFastestFinger\nAshishgup\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n701\n702... |
code_contests | verifiable_code | 1392_H. ZS Shuffles Cards | Solve the following coding problem using the programming language python:
zscoder has a deck of n+m custom-made cards, which consists of n cards labelled from 1 to n and m jokers. Since zscoder is lonely, he wants to play a game with himself using those cards.
Initially, the deck is shuffled uniformly randomly and p... | ```python
def modInverse(a, m) :
m0 = m; y = 0; x = 1
if (m == 1): return 0
while (a > 1):
q = a // m; t = m; m = a % m; a = t; t = y; y = x - q * y; x = t
if (x < 0): x = x + m0
return x
prime = 998244353
n, m = map(int, input().split())
z = 0
for i in range(1, n+1): z += modInverse(i, ... | vfc_71773 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14 9\n",
"output": "969862773\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 1434_B. Shurikens | Solve the following coding problem using the programming language python:
Tenten runs a weapon shop for ninjas. Today she is willing to sell n shurikens which cost 1, 2, ..., n ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is ... | ```python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.... | vfc_71781 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n- 1\n+\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1459_B. Move and Turn | Solve the following coding problem using the programming language python:
A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly 1 meter in one of the four cardinal directions: north, south, west, and east. For the first step the robot can choose any of the four di... | ```python
def calculate(n):
res = 0
if (n%2 == 1):
for i in range(2, n+2, 2):
res += i
return res * 2
else:
if (n%4 == 0):
for i in range(1, int(n/2) + 1):
res += i
res *= 2
res += n/2 + 1
return int(res)
... | vfc_71785 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
... |
code_contests | verifiable_code | 1509_C. The Sports Festival | Solve the following coding problem using the programming language python:
The student council is preparing for the relay race at the sports festival.
The council consists of n members. They will run one after the other in the race, the speed of member i is s_i. The discrepancy d_i of the i-th stage is the difference ... | ```python
n = int(input())
s = list(map(int, input().split()))
s.sort()
dp = [0]*n
for i in range(1, n):
for j in range(n-i):
dp[j] = s[i+j] - s[j] + min(dp[j], dp[j+1])
print(dp[0])
``` | vfc_71793 | {
"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\n3 1 2\n",
"output": "\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 6 3 3 6 3\n",
"output": "\n11\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1535_D. Playoff Tournament | Solve the following coding problem using the programming language python:
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), an... | ```python
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
def solve(z, dp, s):
n = len(dp)
while 1:
dp[z] = 0
if s[z] == '?':
if 2 * z + 1 < n:
dp[z] += dp[2 * z + 1]
else:
... | vfc_71797 | {
"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\n0110?11\n6\n5 1\n6 ?\n7 ?\n1 ?\n5 ?\n1 1\n",
"output": "\n1\n2\n3\n3\n5\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0110?11\n6\n5 1\n6 ?\n7 ?\n2 ?\n5 ?\n1 1\n",
"output"... |
code_contests | verifiable_code | 162_G. Non-decimal sum | Solve the following coding problem using the programming language python:
You are given an array of integers written in base radix. Calculate their sum and output it written in the same base.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 10) — the size of the array. The second line contains an int... | vfc_71801 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n16\nF0\n20B\n004\n",
"output": "2FF\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10\n12\n34\n",
"output": "46\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 182_C. Optimal Sum | Solve the following coding problem using the programming language python:
And here goes another problem on arrays. You are given positive integer len and array a which consists of n integers a1, a2, ..., an. Let's introduce two characteristics for the given array.
* Let's consider an arbitrary interval of the array... | vfc_71805 | {
"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 3\n-2 -5 4\n1\n",
"output": " 11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n1 -3 -10 4 1\n3\n",
"output": " ... | |
code_contests | verifiable_code | 205_E. Little Elephant and Furik and Rubik | Solve the following coding problem using the programming language python:
Little Elephant loves Furik and Rubik, who he met in a small city Kremenchug.
The Little Elephant has two strings of equal length a and b, consisting only of uppercase English letters. The Little Elephant selects a pair of substrings of equal l... | ```python
import sys
import copy
import os
def main(cin):
n = int(cin.readline().strip())
a = cin.readline().strip()
b = cin.readline().strip()
total = 0.0
for i in range(n):
total+=(i+1)*(i+1)
f = 0.0
s = [0 for i in range(30)]
for i in range(n):
s[ord(a[i])-ord('A')]+= i+1
f+= s[ord(b[i])-ord('A')] *... | vfc_71809 | {
"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\nAAB\nCAA\n",
"output": "0.642857",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nAB\nBA\n",
"output": "0.400000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 22_D. Segments | Solve the following coding problem using the programming language python:
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segmen... | ```python
n = int(input())
lis = list()
cou = 1
arr = list()
for i in range(n):
a, b = map(int, input().split())
if a > b:
lis.append([b, a])
else:
lis.append([a, b])
lis = sorted(lis, key=lambda l: l[1])
i = 0
j = 1
arr.append(lis[i][1])
while(i < n and j < n):
if lis[i][1] < lis[j][0]:... | vfc_71813 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 2\n2 5\n",
"output": "1\n2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 255_C. Almost Arithmetical Progression | Solve the following coding problem using the programming language python:
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
* a1 = p, where ... | ```python
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
d... | vfc_71817 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10 20 10 30\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 279_C. Ladder | Solve the following coding problem using the programming language python:
You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + ... | ```python
n,q = map(int,input().split())
arr = [int(x) for x in input().split()]
inc = [-1] * n
dec = [-1] * n
inc[n-1] = n-1
for i in range(n-2, -1, -1):
if(arr[i]<=arr[i+1]):
inc[i] = inc[i+1]
else:
inc[i] = i
dec[n-1] = n-1
for i in range(n-2, -1, -1):
if(arr[i]>=arr[i+1]):
dec[i]... | vfc_71821 | {
"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": "8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8\n",
"output": "Yes\nYes\nNo\nYes\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 5\n13 13 16 12 16 3 19\n2 7\n3 4\n7 7\n1 2\n4... |
code_contests | verifiable_code | 301_B. 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, ... | ```python
import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def solve():
n, dc = mints()
a = list(mints())
a.append(0)
x = [0]*n
y = [0]*n
for i in range(n):
x[i], y[i] = mints()
d = [1<<30]*n
d[0] = 0
was = [False]*n... | vfc_71825 | {
"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 1000\n1000\n1 0\n1 1\n1 2\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1000\n1000\n0 0\n0 1\n0 3\n",
"output": "2000\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 327_E. Axis Walking | Solve the following coding problem using the programming language python:
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub lives at point 0 and Iahubina at point d.
Iahub has n positive integers a1, a2, ..., an. The sum of those numbers is d. Suppose p1, p2, ..., pn ... | vfc_71829 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2 2\n2\n1 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3 5\n2\n5 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... | |
code_contests | verifiable_code | 34_A. Reconnaissance 2 | Solve the following coding problem using the programming language python:
n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable w... | ```python
n = int(input())
a = list(map(int, input().split()))
x = a[0]
for i in range(n-1):
a[i] = abs(a[i] - a[i+1])
a[-1] = abs(x - a[-1])
m = min(a)
ind = a.index(m)
p, q = ind+1, ind+2
if q > n:
q = 1
print(p,q)
``` | vfc_71833 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10 20 30 40\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n10 12 13 15 10\n",
"output": "5 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 373_B. Making Sequences is Fun | Solve the following coding problem using the programming language python:
We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6.
You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need ... | ```python
from math import *
w, m, k = list(map(int, input().split()))
cnt = 0
add = 9*10**(-1) if m < 10 else 0
for i in range(int(log10(m)), int(1e10)):
v = (9 * 10**i - (m-1-9*10**(i-1)+add if i == int(log10(m)) else 0)) * (i+1) * k
if w - v < 0:
cnt += w//((i+1)*k)
break
w -= v
cnt ... | vfc_71837 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 1 1\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 394_D. Physical Education and Buns | Solve the following coding problem using the programming language python:
The Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-decreasing height form an arithmetic progression.
To achie... | ```python
q = 10001
n, a = int(input()), list(map(int, input().split()))
a.sort()
for i in range(40000 // (n - 1) + 1):
b = [a[j] - j * i for j in range(n)]
u, v = max(b), min(b)
p = (u - v + 1) // 2
if p < q: q, s, d = p, v + p, i
print(q)
print(s, d)
``` | vfc_71841 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n-3 -4 -2 -3 3\n",
"output": "2\n-3 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 417_E. Square Table | Solve the following coding problem using the programming language python:
While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size n × m, consisting of positive intege... | ```python
"""
Codeforces Round 241 Div 1 Problem E
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
re... | vfc_71845 | {
"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": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n... |
code_contests | verifiable_code | 444_C. 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_71849 | {
"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 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3\n",
"output": "3\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10\n",
"output": ... | |
code_contests | verifiable_code | 466_D. Increase Sequence | Solve the following coding problem using the programming language python:
Peter has a sequence of integers a1, a2, ..., an. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l, r]": add one to all elements of the sequence with indices from l to r (inclusive... | ```python
n,h = map(int,input().split())
a = list(map(int,input().split()))
a = [h-i for i in a]
if min(a) < 0 or a[0] > 1 or a[-1] > 1:
print(0)
else:
t = 1
for i in range(1,n):
dif = a[i-1]-a[i]
if dif >1 or dif <-1:t = 0
else:
if dif == 0:t*=(a[i-1]+1)
elif... | vfc_71853 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n3 2 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 513_E1. Subarray Cuts | Solve the following coding problem using the programming language python:
You are given an array of length n and a number k. Let's pick k non-overlapping non-empty subarrays of the initial array. Let si be the sum of the i-th subarray in order from left to right. Compute the maximum value of the following expression: ... | ```python
from itertools import *
n,k=map(int,raw_input().split())
a=[]
for i in range(0,n):
a.append(i+1)
p=combinations(a,k)
line=raw_input().split()
for i in range(0,n):
line[i]=int(line[i])
su=[0]*(n+2)
su[0]=0
su[1]=line[0]
for i in range(1,n):
su[i+1]=su[i]+line[i]
ma=0
for each in p:
temp=each
j=0
ans=abs(... | vfc_71861 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n5 2 4 3 1\n",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n7 4 3 7\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 538_H. Summer Dichotomy | Solve the following coding problem using the programming language python:
T students applied into the ZPP class of Summer Irrelevant School. The organizing committee of the school may enroll any number of them, but at least t students must be enrolled. The enrolled students should be divided into two groups in any man... | vfc_71865 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 20\n3 0\n3 6\n4 9\n16 25\n",
"output": "POSSIBLE\n4 16\n112",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10\n3 3\n0 10\n0 10\n0 10\n1 2\n1 3\n2 3\n",
"output": "IMPOSSIBLE\n",
... | |
code_contests | verifiable_code | 567_B. Berland National Library | Solve the following coding problem using the programming language python:
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the pilot launch of an automated readi... | ```python
'''input
2
+ 1
- 1
'''
m, p = 0, []
for _ in range(int(input())):
i = input().split()
if i[0] == "+":
p.append(i[1])
else:
if i[1] in p:
p.remove(i[1])
else:
m += 1
m = max(m, len(p))
print(m)
``` | vfc_71869 | {
"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\n+ 1\n- 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n- 1\n- 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 588_D. Duff in Beach | Solve the following coding problem using the programming language python:
While Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of l positive integers. This array was strange because it was extremely long, but there was another (maybe shorter) array, a0, ..., an - 1... | vfc_71873 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 10 3\n1 2 3 4 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 3\n5 9 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null... | |
code_contests | verifiable_code | 610_A. Pasha and Stick | Solve the following coding problem using the programming language python:
Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.
Pasha likes r... | ```python
x=int(input())
print((x%2==0)*((x//2-1)//2))
#fueaijskrgd/t
``` | vfc_71877 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 630_K. Indivisibility | Solve the following coding problem using the programming language python:
IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to e... | ```python
def precalc(st, end):
count = 0
for i in range(st, end + 1):
if not any(i % k == 0 for k in [2,3,5,7]):
count += 1
return count
n = int(input())
buckets = 2*3*4*5*6*7
c = int(n / buckets)
res = c * precalc(1, buckets) + precalc(c * buckets+1, n)
print(res)
``` | vfc_71881 | {
"difficulty": "17",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3628800\n"... |
code_contests | verifiable_code | 659_C. Tanya and Toys | Solve the following coding problem using the programming language python:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles.
Tania has managed to collect n diffe... | ```python
n, m = map(int, input().split())
a = set(map(int, input().split()))
s, z, k = "", 1, 0
while m >= z:
if z not in a:
m -= z
k += 1
s+=(str(z)+" ")
z += 1
print(k)
print(s)
``` | vfc_71885 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 14\n4 6 12 8\n",
"output": "4\n1 2 3 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n1 3 4\n",
"output": "2\n2 5\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 704_D. Captain America | Solve the following coding problem using the programming language python:
Steve Rogers is fascinated with new vibranium shields S.H.I.E.L.D gave him. They're all uncolored. There are n shields in total, the i-th shield is located at point (xi, yi) of the coordinate plane. It's possible that two or more shields share t... | vfc_71893 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n7 3\n10 3\n9 8\n10 3\n2 8\n2 8 0\n2 8 0\n1 2 0\n1 9 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n8 3\n2 10\n1 5\n9 10\n9 10\n2 8\n1 9 1\n1 2 1\n2 10 3\n2 1... | |
code_contests | verifiable_code | 727_B. Bill Total Value | Solve the following coding problem using the programming language python:
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1pr... | ```python
import re
def spnum(s):
a = s.split(".")
if len(a[-1]) == 2:
a.append(a[-1])
a[-2] = '.'
return eval("".join(a))
s = input()
dollars = re.findall(r"[.0-9]+", s)
for i in range(len(dollars)):
if "." in dollars[i]:
dollars[i] = spnum(dollars[i])
else:
dollar... | vfc_71897 | {
"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": "aa0.01t0.03\n",
"output": "0.04",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "chipsy48.32televizor12.390\n",
"output": "12.438.32",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 748_C. Santa Claus and Robot | Solve the following coding problem using the programming language python:
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, ..., pm with integer coordinates, do the following: denote its initial location by p0. First, the robot will ... | ```python
n = int(input())
line = input()
moves = 'UDLR'
used = dict()
opp = dict()
opp['U'] = 'D'
opp['D'] = 'U'
opp['L'] = 'R'
opp['R'] = 'L'
for i in moves:
used[i] = 0
i = len(line) - 1
ans = 0
while i >= 0:
ans += 1
for j in moves:
used[j] = 0
while i >= 0 and not used[opp[line[i]]]:
... | vfc_71901 | {
"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": "6\nRRULDD\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nRLL\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "26... |
code_contests | verifiable_code | 796_B. Find The Bone | Solve the following coding problem using the programming language python:
Zane the wizard is going to perform a magic show shuffling the cups.
There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.
The problemati... | ```python
n , m , k = list(map(int,input().split()))
h = list(map(int,input().split()))
used = [0] * int(1e7)
for x in h:
used[x] = 1
t = 1
for i in range(k):
u , v = list(map(int,input().split()))
if used[t]:
print(t)
exit(0)
elif u == t:
if used[v] == 1:
print(v)
exit(0)
t = v
elif v == t... | vfc_71909 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 2\n2\n1 2\n2 4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 841_C. Leha and Function | Solve the following coding problem using the programming language python:
Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element am... | ```python
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
a.reverse()
j=[]
for i in range(n):
j.append([b[i],i])
j.sort()
ans=[0]*n
for i in range(n):
ans[j[i][1]]=str(a[i])
print(' '.join(ans))
``` | vfc_71917 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n7 3 5 3 4\n2 1 3 2 3\n",
"output": "5 7 3 4 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n",
"output": "6 8 5 4 8 6 2\n",
"type": "stdin... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.