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 | 228_E. The Road to Berland is Paved With Good Intentions | Solve the following coding problem using the programming language python:
Berland has n cities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not.
The King of Berland Valera II wants to asphalt all roads of Berland, for that he gathered a group of workers. Every d... | ```python
s=list(map(int,input().split()))
n=s[0]
m=s[1]
roads=[]
for i in range(0,n+1):
roads.append([])
for i in range(0,m):
s=list(map(int,input().split()))
roads[s[0]].append([s[1],s[2]])
roads[s[1]].append([s[0],s[2]])
col=[-1]*(n+1)
##def dfs(v,c):
## success=True
## col[v]=c
## for e... | vfc_34341 | {
"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 3\n1 2 0\n2 3 0\n3 1 0\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 2 1\n2 4 0\n4 3 1\n3 2 0\n",
"output": "2\n1 2\n",
"type": "stdin_stdo... |
code_contests | verifiable_code | 252_C. Points on Line | Solve the following coding problem using the programming language python:
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d... | ```python
n,d=map(int,input().split())
nums=list(map(int,input().split()))
count=0
j=0
for i in range(n):
while j<n and nums[j]-nums[i]<=d:
j+=1
temp_length=(j-i-1)
count+=int((temp_length*(temp_length-1))/2)
print(count)
``` | vfc_34345 | {
"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 3\n1 2 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n-3 -2 -1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 2_A. Winner | Solve the following coding problem using the programming language python:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more diffic... | ```python
n = int(input())
d = {}
l = []
for _ in range(n):
name, score = input().split()
score = int(score)
l.append((name,score))
d[name] = d.get(name, 0) + score
m = max([x for x in d.values()])
ties = [x for x,y in d.items() if y == m]
# print(ties)
if len(ties) == 1:
print(ties[0])
... | vfc_34353 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nandrew 3\nandrew 2\nmike 5\n",
"output": "andrew\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nmike 3\nandrew 5\nmike 2\n",
"output": "andrew\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 325_A. Square and Rectangles | Solve the following coding problem using the programming language python:
You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the inte... | ```python
xmin, ymin, xmax, ymax, a = 31400, 31400, 0, 0, 0
for i in range(int(input())):
x1, y1, x2, y2 = map(int, input().split())
xmin = min(xmin, x1)
ymin = min(ymin, y1)
xmax = max(xmax, x2)
ymax = max(ymax, y2)
a += (x2 - x1) * (y2 - y1)
print('YES' if xmax - xmin == ymax - ymin and a == (... | vfc_34357 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n",
"output": "NO\n",
"t... |
code_contests | verifiable_code | 348_B. Apple Tree | Solve the following coding problem using the programming language python:
You are given a rooted tree with n vertices. In each leaf vertex there's a single integer — the number of apples in this vertex.
The weight of a subtree is the sum of all numbers in this subtree leaves. For instance, the weight of a subtree th... | ```python
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a // gcd(a, b) * b
def cal((f1, k1), (f2, k2)):
if f1 > f2:
f1, k1, f2, k2 = f2, k2, f1, k1
A = (f1 - f2) % k2
B = 0
x1 = 0
k11 = k1 % k2
k1x1 = 0
while B != A and k1x1 <= f1:
... | vfc_34361 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n0 0 12 13 5 6\n1 2\n1 3\n1 4\n2 5\n2 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 100000000\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 371_C. Hamburgers | Solve the following coding problem using the programming language python:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recip... | ```python
st = input()
B = st.count('B')
S = st.count('S')
C = st.count('C')
b,s,c=map(int,input().split())
bp, sp, cp = map(int,input().split())
r=int(input())
lm=0; rm=int(1e15)+1
while rm-lm>1:
m=(rm+lm)//2
# print(m)
bb=max(m*B-b,0)
ss=max(m*S-s,0)
cc=max(m*C-c, 0)
#print(bp*bb+ss*sp+cc*cp)
... | vfc_34365 | {
"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": "BBC\n1 10 1\n1 10 1\n21\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BSC\n1 1 1\n1 1 3\n1000000000000\n",
"output": "200000000001\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 392_E. Deleting Substrings | Solve the following coding problem using the programming language python:
SmallR likes a game called "Deleting Substrings". In the game you are given a sequence of integers w, you can modify the sequence and get points. The only type of modification you can perform is (unexpected, right?) deleting substrings. More for... | vfc_34369 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 4 5 6 7 1000\n2 1 1 2 2 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 3\n1 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 416_A. Guess a number! | Solve the following coding problem using the programming language python:
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. Th... | ```python
n = int(input())
questions = []
for _ in range(n):
questions.append(input())
lower_bound, upper_bound = None, None
for q in questions:
bound = int(q.split()[1])
if (q.startswith('>') and q.endswith('Y')) or (q.startswith('<') and q.endswith('N')):
if ('Y' in q and '=' not in q) or ('N' ... | vfc_34373 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N\n",
"output": "-2000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n> 100 Y\n< -100 Y\n",
"output": "-2000000000\n",
... |
code_contests | verifiable_code | 442_D. Adam and Tree | Solve the following coding problem using the programming language python:
When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions:
* There is no vertex tha... | vfc_34377 | {
"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": "11\n1 1 1 3 4 4 7 3 7 6 6\n",
"output": "1 1 1 1 1 2 2 2 2 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 1 2 2 3 3 4 4 5 5\n",
"output": "1 1 1 2 2 2 2 2 2 3 ",
"typ... | |
code_contests | verifiable_code | 464_E. The Classic Problem | Solve the following coding problem using the programming language python:
You are given a weighted undirected graph on n vertices and m edges. Find the shortest path from vertex s to vertex t or else state that such path doesn't exist.
Input
The first line of the input contains two space-separated integers — n and m... | vfc_34381 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 768000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2 4\n2 3 5\n3 4 6\n1 4\n",
"output": "112\n4\n1 2 3 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 4 2\n1 2 0\n2 3 0\n3 4 0\n1 4\n",
"output": "3\n4\n1 2 3 4 ",
... | |
code_contests | verifiable_code | 488_D. Strip | Solve the following coding problem using the programming language python:
Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.
Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:
* Each piece should contain at least l numbers.... | ```python
def split(a,n,s,l):
pieces = []
i = 1
tmpmin = a[0]
tmpmax = a[0]
tmppc = [a[0]]
while i<n:
if abs(a[i]-tmpmin)<=s and abs(a[i]-tmpmax)<=s:
tmppc.append(a[i])
if a[i]<tmpmin: tmpmin=a[i]
elif a[i]>tmpmax: tmpmax = a[i]
else:
... | vfc_34385 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 2 2\n1 3 1 2 4 1 2\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2 2\n1 100 1 100 1 100 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 536_D. Tavas in Kansas | Solve the following coding problem using the programming language python:
Tavas lives in Kansas. Kansas has n cities numbered from 1 to n connected with m bidirectional roads. We can travel from any city to any other city via these roads. Kansas is as strange as Tavas. So there may be a road between a city and itself ... | vfc_34393 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n1 2\n2 2 -5 -4 6\n1 2 4\n2 3 5\n2 4 2\n4 5 2\n",
"output": "Break a heart\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n-5 -5\n1 2 10\n",
"output": "Flowers\n",
... | |
code_contests | verifiable_code | 560_E. Gerald and Giant Chess | Solve the following coding problem using the programming language python:
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white a... | ```python
#!/usr/bin/env python
# 560E_chess.py - Codeforces.com 560E Chess program
#
# Copyright (C) 2015 Sergey
"""
Input
The first line of the input contains three integers:
h,w,n the sides of the board and the number of black cells
Next n lines contain the description of black cells. The ith
of these lines conta... | vfc_34397 | {
"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": "100 100 3\n15 16\n16 15\n99 88\n",
"output": "545732279\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 2\n2 2\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 587_A. Duff and Weight Lifting | Solve the following coding problem using the programming language python:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away.... | ```python
N = int(1e6+100)
n = int(input())
arr = list(map(int, input().split()))
cnt = [0] * N
for i in arr:
cnt[i] += 1
res, s = 0, 0
for i in range(N):
s += cnt[i]
res += s % 2
s //= 2
print(res)
``` | vfc_34401 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 2 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 609_C. Load Balancing | Solve the following coding problem using the programming language python:
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server.
In order to balance the load f... | ```python
input()
servers = [int(x) for x in input().split(" ", )]
servers.sort()
avg = int(sum(servers) / len(servers))
extra = sum(servers) % len(servers)
count = 0
for i in range(len(servers)):
count += abs(avg + (i >= (len(servers) - extra)) - servers[i]) / 2
print(int(count))
... | vfc_34405 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n10 11 10 11 10 11 11\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 630_B. Moore's Law | Solve the following coding problem using the programming language python:
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.
Moore's law is the observation that the n... | ```python
n,t=map(int,input().split())
print(n*((1.000000011)**t))
``` | vfc_34409 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000 1000000\n",
"output": "1011.060722405749039",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4907 244618708\n",
"output": "72346.605605857597617",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 656_F. Ace It! | Solve the following coding problem using the programming language python:
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
... | ```python
s = input()
ans = 1
for i in s[1:]:
x = int(i)
if x == 0:
x = 9
ans += x
print(ans)
``` | vfc_34413 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A232726\n",
"output": "23\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 702_F. T-Shirts | Solve the following coding problem using the programming language python:
The big consignment of t-shirts goes on sale in the shop before the beginning of the spring. In all n types of t-shirts go on sale. The t-shirt of the i-th type has two integer parameters — ci and qi, where ci — is the price of the i-th type t-s... | vfc_34421 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n100 500\n50 499\n4\n50 200 150 100\n",
"output": "1 2 2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n7 5\n3 5\n4 3\n2\n13 14\n",
"output": "2 3 \n",
"type": "stdin_... | |
code_contests | verifiable_code | 746_G. New Roads | Solve the following coding problem using the programming language python:
There are n cities in Berland, each of them has a unique id — an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads.
That is why there was a decision to build n - 1 r... | ```python
if __name__ == '__main__':
n, t, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0 for _ in range(t)]
b[t-1] = a[t-1]
maxk = a[t-1]
for i in range(t-2, -1, -1):
b[i] = b[i+1]
if a[i+1] < a[i]:
b[i] += a[i] - a[i+1]
maxk += a[i]-1
if b[0] > k or maxk < k:
print(-1)
el... | vfc_34429 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3 3\n2 3 1\n",
"output": "7\n1 2\n1 3\n2 4\n3 5\n2 6\n4 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1\n2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 76_C. Mutation | Solve the following coding problem using the programming language python:
Scientists of planet Olympia are conducting an experiment in mutation of primitive organisms. Genome of organism from this planet can be represented as a string of the first K capital English letters. For each pair of types of genes they assigne... | vfc_34433 | {
"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 3 13\nBACAC\n4 1 2\n1 2 3\n2 3 4\n3 4 10\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 793_G. Oleg and chess | Solve the following coding problem using the programming language python:
Oleg the bank client solves an interesting chess problem: place on n × n chessboard the maximum number of rooks so that they don't beat each other. Of course, no two rooks can share the same cell.
Remind that a rook standing in the cell (a, b) ... | vfc_34437 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5\n1 1 2 1\n1 3 1 5\n4 1 5 5\n2 5 2 5\n3 2 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n4\n2 2 4 6\n1 8 1 8\n7 1 8 2\n5 4 6 8\n",
"output": "8\n",
... | |
code_contests | verifiable_code | 814_D. An overnight dance in discotheque | Solve the following coding problem using the programming language python:
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it?
The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts ... | ```python
n = int(input())
d = [1] * n
p = [[] for i in range(n)]
def f():
x, y, r = map(int, input().split())
return r * r, x, y
t = sorted(f() for i in range(n))
for i in range(n):
r, x, y = t[i]
for j in range(i + 1, n):
s, a, b = t[j]
if (a - x) ** 2 + (b - y) ** 2 < s:
... | vfc_34441 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1\n",
"output": "138.230076757951\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8\n",
... |
code_contests | verifiable_code | 83_D. Numbers | Solve the following coding problem using the programming language python:
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particula... | ```python
def pr(x):
d = 2
while d * d <= x:
if x % d == 0:
return 0
d += 1
return 1
def cnt(n, k):
if not pr(k) or n < k: return 0
n1 = n // k
return n1 - sum(cnt(n1, i) for i in range(2, min(k, n1 + 1)))
a, b, k = map(int, input().split())
ans = cnt(b, k) - cn... | vfc_34445 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12 23 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 85_E. Guard Towers | Solve the following coding problem using the programming language python:
In a far away kingdom lives a very greedy king. To defend his land, he built n guard towers. Apart from the towers the kingdom has two armies, each headed by a tyrannical and narcissistic general. The generals can't stand each other, specificall... | vfc_34449 | {
"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": "3\n0 0\n1000 1000\n5000 5000\n",
"output": "2000\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0\n1 1\n",
"output": "0\n2\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 886_E. Maximum Element | Solve the following coding problem using the programming language python:
One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for f... | vfc_34453 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n"... | |
code_contests | verifiable_code | 909_E. Coprocessor | Solve the following coding problem using the programming language python:
You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular de... | ```python
n, m = [int(x) for x in input().split()]
tps = {i:int(t) for i, t in enumerate(input().split())}
deps = {i:0 for i in range(n)}
parents = {i:[] for i in range(n)}
leafs = {i for i in range(n)}
for i in range(m):
x, y = [int(x) for x in input().split()]
deps[x] += 1
parents[y].append(x)
if x in... | vfc_34457 | {
"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": "4 3\n1 1 1 0\n0 1\n0 2\n3 0\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 931_B. World Cup | Solve the following coding problem using the programming language python:
The last stage of Football World Cup is played using the play-off system.
There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, th... | ```python
n,a,b=map(int,input().split())
a,b,r=a-1,b-1,0
while a!=b:
a//=2
b//=2
r+=1
print(r if 2**r<n else 'Final!')
``` | vfc_34461 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 7 5\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 958_E3. Guard Duty (hard) | Solve the following coding problem using the programming language python:
Now that Heidi knows that she can assign Rebel spaceships to bases (recall the easy subtask), she is asking you: how exactly to do this? Now, given positions of N spaceships and N bases on a plane, your task is to connect spaceships and bases wi... | vfc_34465 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6 6\n5 1\n2 4\n4 0\n5 4\n1 2\n2 1\n3 5\n",
"output": "4\n2\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0\n2 5\n-2 -8\n2 -9\n4 -8\n-6 5\n-7 3\n7 6\n8 3\n8 0\n",
"out... | |
code_contests | verifiable_code | 985_B. Switches and Lamps | Solve the following coding problem using the programming language python:
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the ... | ```python
def main():
n,m=map(int,input().split())
counts=[0]*m
a=[None]*n
for i in range(n):
line=input()
a[i]=line
for j in range(m):
counts[j]+=1 if line[j]=='1' else 0
if 1 not in counts:
print('YES')
return
checks=[]
for i in range(m):
if counts[i]==1:
checks.append(i)
leng=len(checks)
... | vfc_34469 | {
"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 5\n10100\n01000\n00110\n00101\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n10101\n01000\n00111\n10000\n",
"output": "YES\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | abc-string-61 | Solve the following coding problem using the programming language python:
Given an integer N,Find how many strings of length N are possible, consisting only of characters { 'A','B' and 'C' } with each character {'A','B' and 'C'} occurs at least once.
Input:
First line of each test case contains number of test cas... | ```python
MOD=10**9+7
def power(base,pow):
ans=1
while (pow!=0):
if(pow%2==1):
ans=(ans*base)%MOD
base=(base*base)%MOD
pow=pow/2
return ans
if __name__ =="__main__":
t=int(raw_input())
for i in range(t):
n=int(raw_input())
if(n<3):
print 0
else:
print (3*(power(3,n-1) -power(2,n) +1 ))%M... | vfc_34473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n3\n4\n\nSAMPLE",
"output": "0\n6\n36\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n2\n4\n\nSAMPLE",
"output": "0\n0\n36\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | bogo-sort-1 | Solve the following coding problem using the programming language python:
Given an array A of N integers, sort them in non-decreasing order.
Input Format
The first line of the input file contains a positive integer <N.
Then, N lines follow, each containing a single integer Ai, which is the i^th element of A.
Output ... | ```python
N = input()
A = []
for i in xrange(N):
A.append(int(raw_input()))
A.sort()
for a in A:
print a
``` | vfc_34477 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n567\n23\n-10982\n1000000\n-999999\n-3456\n1729\n65535\n\nSAMPLE",
"output": "-999999\n-10982\n-3456\n23\n567\n1729\n65535\n1000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n567... |
code_contests | verifiable_code | cubic-currency | Solve the following coding problem using the programming language python:
People in Cubeland use cubic coins. Not only the unit of currency is called a cube but also the coins are shaped like cubes and their values are cubes. Coins with values of all cubic numbers up to 9261 (= 213), i.e., coins with the denominations... | ```python
a=[]
for i in xrange(1,22):
a.append(i**3)
ans=[0]*10001
ans[0]=1
for j in a:
for i in xrange(j,10001):
ans[i]+=ans[i-j]
for _ in xrange(input()):
print ans[input()]
``` | vfc_34481 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n10\n\nSAMPLE",
"output": "1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n78\n77\n9999\n111\n786",
"output": "23\n22\n440022018293\n47\n24881",
"type": "stdin_stdou... |
code_contests | verifiable_code | fuck-this-problem | Solve the following coding problem using the programming language python:
Problem Statement
Unseen gang is the team of most wanted criminal. Unseen gang has planted bombs in different street and corner of the city. Gang members are sitting in the other part of the city, far away from the bomb site. They are controlli... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
s = raw_input()
n=int(raw_input())
j =0
temp =""
for i in s:
if j==n:
print temp
temp=""
j=0
temp+=i
j = j+1
if temp!="":
print temp
``` | vfc_34485 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Vhaveplanted bomb @allthe location intheCITY.\n8\n\nSAMPLE",
"output": "Vhavepla\nnted bom\nb @allth\ne locati\non inthe\nCITY.\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Vhaveplant... |
code_contests | verifiable_code | jumping-numbers-1 | Solve the following coding problem using the programming language python:
Call a number stepping if adjacent digits, as well as the first and last digits, differ by one. How many n-digit base 11 stepping numbers are there? Give your answer modulo 4294967143.
For example, 8789A9 is a 6-digit base 11 stepping number. 9... | ```python
noc = input()
series = []
while noc:
noc -=1
series.append(input())
print "19"
print "54"
print "171"
print "1958"
``` | vfc_34489 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n4\n6\n10\n\nSAMPLE",
"output": "19\n54\n171\n1958",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2\n4\n6\n10",
"output": "19\n54\n171\n1958",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | minimise-maximum-sum | Solve the following coding problem using the programming language python:
You are given an array containing 2 \times n elements.You have to partition the numbers in to n pairs with the property that partition minimize the maximum sum of a pair.
Input
First line contains T number of test cases. Next line contain N ... | ```python
t=input()
for i in xrange(t):
n=input()
arr=[]
arr=map(int,raw_input().split())
arr.sort()
l=len(arr)
m=l
arr2=[]
for k in xrange(l/2):
su=arr[k]+arr[m-1]
arr2.append(su)
m-=1
print max(arr2)
``` | vfc_34493 | {
"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\n5 6 2 3 9 8\n\nSAMPLE",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | palindrome-9 | Solve the following coding problem using the programming language python:
The events have started and one of them is Void fnx, the most anticipated Coding Event of the college. This year, one question has been bugging the coders for hours, Help them solve it. It goes as follows:
The palindromic number 595 can be writ... | ```python
import math
def ispalin(x):
o=[]
while x:
o.append(x%10)
x/=10
r=reversed(o)
for i,j in zip(o,r):
if i!=j:
return False
return True
s,b=raw_input().split()
s,b=(int)(s),(int)(b)
sq=(int)(math.sqrt(b))
a=[]
for i in range(1,10001):
num=i*i
fo... | vfc_34497 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10\n\nSAMPLE",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "111 555",
"output": "1978",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | reversing-a-number | Solve the following coding problem using the programming language python:
Dark was deeply studying in the afternoon and came across a concept called as "REVERSE OF A NUMBER"
Hearing first time he became eager to learn and searched on "INTERNET" , after his research on reverse of a number he decided to design a progr... | ```python
t = int(raw_input())
while(t):
str=raw_input()
str1=str[::-1]
number=int(str1)
if number%2==0:
print "EVEN"
else:
print "ODD"
t-=1
``` | vfc_34501 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n3\n6\n15\n\nSAMPLE",
"output": "ODD\nODD\nEVEN\nODD\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | special-numbers-7 | Solve the following coding problem using the programming language python:
Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and she is better than him at it. Prime numbers are of mystical importance in Arithmancy, and Lucky Numbers even more so. Lucky ... | ```python
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return set(factors)
ans=[0]
for k in xrange(30,2700):
if len(prime_factors(k))>2:
... | vfc_34505 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n\nSAMPLE",
"output": "30\n42",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | trailing-zeroes-2 | Solve the following coding problem using the programming language python:
Let there be a function f(N) such that f(N) denotes number of zeroes at the end of N! (factorial of N).
For example, f(5) = 1 because 5! = 120.
You have to compute f(N) for given N.
Input format : Input begins with integer t ( 1 ≤ t ≤ 10000)... | ```python
for _ in range(int(raw_input())):
tz = 0
n = int(raw_input())
i = 1
r = 1
while r:
r = n / 5 ** i
tz += r
i += 1
print tz
``` | vfc_34509 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4\n5\n10\n25\n100\n\nSAMPLE",
"output": "0\n1\n2\n6\n24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n65\n85\n45\n23\n85\n63\n52\n79\n24\n5\n6\n74\n64\n64\n99\n45\n66\n76\n65\n2... |
code_contests | verifiable_code | p00128 Abacus | Solve the following coding problem using the programming language python:
<image>
At the request of a friend who started learning abacus, you decided to create a program to display the abacus beads. Create a program that takes a certain number as input and outputs a row of abacus beads. However, the number of digits... | ```python
f=0
while 1:
try:n=int(input())
except:break
if f:print()
f=1
a=[['*' for _ in range(5)]for _ in range(8)]
for i in range(4,-1,-1):
b=n%10
a[not b//5][i]=' '
a[b%5+3][i]=' '
n//=10
a[2]='='*5
for i in a:
print(''.join(i),end='')
p... | vfc_34557 | {
"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": "2006\n1111",
"output": "****\n *\n=====\n * *\n****\n* ***\n*****\n*****\n\n*****\n\n=====\n ****\n*\n*****\n*****\n*****",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2006\n1101",
... |
code_contests | verifiable_code | p00261 Aka-beko and 40 Thieves | Solve the following coding problem using the programming language python:
Aka Beko, trying to escape from 40 bandits, got lost in the city of A. Aka Beko wants to go to City B, where the new hideout is, but the map has been stolen by a bandit.
Kobborg, one of the thieves, sympathized with Aka Beko and felt sorry for ... | ```python
# -*- coding: utf-8 -*-
"""
Aka-beko and 40 Thieves
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0266
"""
import sys
def solve(s):
path = {'A': {'0': 'X', '1': 'Y'}, 'B': {'0': 'Y', '1': 'X'},
'W': {'0': 'B', '1': 'Y'}, 'X': {'0': None, '1': 'Z'}, 'Y': {'0': 'X', '1': None}, 'Z': {'0': ... | vfc_34561 | {
"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": "0100\n0101\n10100\n01000\n0101011\n0011\n011111\n#",
"output": "Yes\nNo\nYes\nNo\nYes\nNo\nYes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0100\n0101\n10100\n01000\n0101011\n0011\n011110... |
code_contests | verifiable_code | p00639 Accelerated Railgun | Solve the following coding problem using the programming language python:
She catched the thrown coin that draws parabolic curve with her sparkling fingers. She is an ESPer. Yes, she is an electro-master who has the third strongest power among more than one million ESPers in the city. Being flicked by her thumb, the c... | ```python
# AOJ 1053: Accelerated Railgun
# Python3 2018.7.7 bal4u
EPS = 1e-7
while True:
d = float(input())
if d == 0: break
px, py, vx, vy = map(float, input().split())
ans = d+1
dp = (px*px + py*py)**0.5
dv = (vx*vx + vy*vy)**0.5
x = (px*vx + py*vy)/(dp*dv)
if abs(x+1) <= EPS: ans = dp
elif abs(1-x) <= EPS... | vfc_34569 | {
"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": "10.0\n0.5 0.0 -0.2 0.0\n1.0\n0.1 0.0 0.2 0.2\n0",
"output": "0.50000000\nimpossible",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10.0\n0.5 0.8573113359511872 -0.2 0.0\n1.0\n0.1 0.0 0.2 0.... |
code_contests | verifiable_code | p00782 Mobile Phone Coverage | Solve the following coding problem using the programming language python:
A mobile phone company ACMICPC (Advanced Cellular, Mobile, and Internet-Connected Phone Corporation) is planning to set up a collection of antennas for mobile phones in a city called Maxnorm. The company ACMICPC has several collections for locat... | ```python
# AOJ 1202: Mobile Phone Coverage
# Python3 2018.7.28
from bisect import bisect_left
cno = 0
while True:
n = int(input())
if n == 0: break
tbl, xx, yy = [], set(), set()
for i in range(n):
x, y, r = map(float, input().split())
x, y, r = int(100*x), int(100*y), int(100*r)
x1, y1, x2, y2 = x-r, y-r, ... | vfc_34573 | {
"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\n4.0 4.0 3.0\n5.0 6.0 3.0\n5.5 4.5 1.0\n2\n3.0 3.0 3.0\n1.5 1.5 1.0\n0",
"output": "1 52.00\n2 36.00",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4.0 4.0 3.0\n5.0 6.0 3.0\n5.5 4.5 1.... |
code_contests | verifiable_code | p00915 The Last Ant | Solve the following coding problem using the programming language python:
A straight tunnel without branches is crowded with busy ants coming and going. Some ants walk left to right and others right to left. All ants walk at a constant speed of 1 cm/s. When two ants meet, they try to pass each other. However, some sec... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x i... | vfc_34577 | {
"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 6\nR 1\nL 2\nL 5\n1 10\nR 1\n2 10\nR 5\nL 7\n2 10\nR 3\nL 8\n2 99\nR 1\nL 98\n4 10\nL 1\nR 2\nL 8\nR 9\n6 10\nR 2\nR 3\nL 4\nR 6\nL 7\nL 8\n0 0",
"output": "5 1\n9 1\n7 1\n8 2\n98 2\n8 2\n8 3",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p01048 Divisor | Solve the following coding problem using the programming language python:
Problem
Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N.
Constraints
* 1 ≤ N ≤ 12
Input
One natural number N is given in one line.
Output
Output the smalles... | ```python
def solve(n):
for i in range(1,10000):
cnt=0
for j in range(1,i+1):
if i%j==0:
cnt+=1
if cnt==n:
return(i)
while True:
try:
n=int(input())
print(solve(n))
except EOFError:
break
``` | vfc_34581 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 267386880,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01180 The Closest Circle | Solve the following coding problem using the programming language python:
You are given N non-overlapping circles in xy-plane. The radius of each circle varies, but the radius of the largest circle is not double longer than that of the smallest.
<image>
Figure 1: The Sample Input
The distance between two circles C1... | ```python
def _get_distance(c1, c2):
return ((c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2) ** 0.5 - c1[0] - c2[0]
from itertools import combinations
def _get_min_distance(circles):
min_d = float("inf")
for c1, c2 in combinations(circles, 2):
min_d = min(min_d, _get_distance(c1, c2))
return min_... | vfc_34585 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1.0 0.0 0.0\n1.5 0.0 3.0\n2.0 4.0 0.0\n1.0 3.0 4.0\n0",
"output": "0.5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1.0 0.0 0.0\n1.5 0.0 3.0\n2.4193437752467455 4.0 0.0\n1.0 3.0 4.0... |
code_contests | verifiable_code | p01317 Mr. Rito Post Office | Solve the following coding problem using the programming language python:
Problem D: Mr. Rito Post Office
You are a programmer working at a post office on a remote island. The area you live in consists of multiple islands. There is one or more port towns on each island. There may be other towns and villages in additi... | ```python
# # AOJ 2200
#
# INF = float('inf')
#
#
# def floyd_warshall(d):
# v = len(d)
# for k in range(v):
# dk = d[k]
# for i in range(v):
# di = d[i]
# for j in range(v):
# di[j] = min(di[j], di[k] + dk[j])
#
#
# def main():
# while True:
# ... | vfc_34589 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 5 L\n1 2 7 S\n2 3 11 S\n3\n1 2 3\n5 5\n1 2 15 L\n2 3 10 L\n4 5 7 L\n1 3 30 S\n3 4 100 S\n5\n1 3 5 4 1\n0 0",
"output": "18\n269",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n... |
code_contests | verifiable_code | p01485 Satan Attacks | Solve the following coding problem using the programming language python:
Time Limit: 8 sec / Memory Limit: 64 MB
Example
Input
2
0 0 5 0 10
1 0 6 0 10
1
0.000000 0.000000
6.000000 0.000000
Output
2
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the pro... | vfc_34593 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 0 5 0 10\n1 0 6 0 10\n1\n0.000000 0.000000\n6.000000 0.000000",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0 5 0 10\n2 0 6 0 10\n1\n0.000000 0.000000\n6.000000 0.... | |
code_contests | verifiable_code | p01647 Texas hold 'em | Solve the following coding problem using the programming language python:
Problem Statement
Texas hold 'em is one of the standard poker games, originated in Texas, United States. It is played with a standard deck of 52 cards, which has 4 suits (spades, hearts, diamonds and clubs) and 13 ranks (A, K, Q, J and 10-2), w... | vfc_34597 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "SA SK\nDA CA\nSQ SJ ST\nSA HA\nD2 C3\nH4 S5 DA\nHA D9\nH6 C9\nH3 H4 H5\n#",
"output": "1.00000000000000000000\n0.34444444444444444198\n0.63030303030303025391",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | p01798 Midpoint | Solve the following coding problem using the programming language python:
Example
Input
2 2 3
0 0
2 0
0 0
0 2
0 0
1 1
1 1
Output
3
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | vfc_34601 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 10, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 3\n0 0\n2 0\n0 0\n0 2\n0 0\n1 1\n1 1",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 3\n0 0\n2 0\n0 1\n0 2\n0 0\n1 1\n1 1",
"output": "2\n",
"type": "stdin... | |
code_contests | verifiable_code | p01932 All Japan Association of Return home | Solve the following coding problem using the programming language python:
problem
AOR Co., Ltd. (Association Of Return home) has $ N $ employees.
Employee $ i $ wants to use the elevator to go down to the $ 1 $ floor and arrives in front of the elevator on the $ F_i $ floor at time $ t_i $. You decide to remotely co... | ```python
n, d = map(int, input().split())
lst = sorted([list(map(int, input().split())) for _ in range(n)]) + [[10 ** 20, 1]]
cnt = 0
time = 0
floor = 1
ans = 0
for i in range(n):
t, f = lst[i]
if f - floor > t - time or cnt >= d:
print(-1)
break
ans += cnt * (t - time)
cnt += 1
time = t
floor = f... | vfc_34605 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n2 2\n3 3",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n2 1\n3 3",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02070 Permutation Sort | Solve the following coding problem using the programming language python:
Problem Statement
One day (call it day 0), you find a permutation $P$ of $N$ integers written on the blackboard in a single row. Fortunately you have another permutation $Q$ of $N$ integers, so you decide to play with these permutations.
Every... | vfc_34609 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02366 Articulation Points | Solve the following coding problem using the programming language python:
Find articulation points of a given undirected graph G(V, E).
A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph.
Constraints
* 1 ≤ |V| ≤ 100,000
* 0 ≤ |E| ≤ 100,000
* The graph is c... | ```python
import sys
sys.setrecursionlimit(10**7)
v, e = list(map(int, input().split()))
G = [[] for _ in range(v)]
for _ in range(e):
s, t = map(int, input().split())
G[s].append(t)
G[t].append(s)
def solve():
used = [False for _ in range(v)]
ord = [0 for _ in range(v)]
low = [float("i... | vfc_34617 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n0 1\n1 2\n2 3\n3 4",
"output": "1\n2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n0 1\n0 2\n1 2\n2 3",
"output": "2",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | bitcj5 | Solve the following coding problem using the programming language python:
Doge and Cate can no longer coexist in the same planet. Time has finally come to decide once and for all, who will reign over this planet.
They agreed on a non violent way to settle this. Both are given an array of N integers and a positive inte... | ```python
T=int(raw_input());
for t in range(T) :
l=raw_input().split();
N=int(l[0]);
K=int(l[1]);
l=raw_input().split();
A=[int(i) for i in l];
countdict={};
for i in A :
if i in countdict :
countdict[i]=countdict[i]+1;
else :
countdict[i]=1;
mindiff=N+1;
for key in countdict :
if K>countdict[key]... | vfc_34621 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 1\n1 2 3 4 5\n4 3\n1 2 2 1",
"output": "0\n1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | coins | Solve the following coding problem using the programming language python:
In Byteland they have a very strange monetary system.
Each Bytelandian gold coin has an integer number written on it. A coin n
can be exchanged in a bank into three coins: n/2, n/3 and n/4.
But these numbers are all rounded down (the banks have... | ```python
def solve(coin2):
d = {0:0}
def exchange(coin):
if coin in d:
return d[coin]
else:
d[coin] = max(coin, exchange(coin/2) + exchange(coin/3) + exchange(coin/4))
return d[coin]
return exchange(coin2)
def coins():
import sys
for coin in sys... | vfc_34625 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\n2",
"output": "13\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n1",
"output": "13\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | galactik | Solve the following coding problem using the programming language python:
WARNING Large input/output files. Use faster I/O.
It's Galactik Football time! The Galactik Football Assosiation (GFA) has announced a football tournament between all the teams of all the planets in the galaxy (say N). Teams like Snow Kids, Shad... | ```python
#! /usr/bin/python
import sys
max_val = sys.maxint
inp = sys.stdin.readline().split()
N, M = int(inp[0]), int(inp[1])
g = range(N+1) # group of i'th point which is equal to least point index in the group;
# all points connected to each other are in a same group
for i in xrange(M):
i... | vfc_34629 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n1 2\n2 3\n1 3\n4 5\n5 6\n4 6\n1\n3\n5\n2\n4\n6",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n2 3\n1\n-1\n-1",
"output": "-1\n",
"type": "stdin_stdout... |
code_contests | verifiable_code | lucky10 | Solve the following coding problem using the programming language python:
The Little Elephant loves lucky strings. Everybody knows that the lucky string is a string of digits that contains only the lucky digits 4 and 7. For example, strings "47", "744", "4" are lucky while "5", "17", "467" are not.
The Little Elepha... | ```python
import sys, os
import unittest
def getToTarget(target, values, priorities):
returnTarget = 0
returnValues = values
for p in priorities:
x = values[p]
toTarget = target-returnTarget
add = min(x,toTarget)
returnValues[p] = x-add
returnTarget += add
ret... | vfc_34633 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n7\n435\n479\n7\n8\n1675475\n9756417",
"output": "7\n74\n\n777744",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | promo | Solve the following coding problem using the programming language python:
Mo the pro does not want to be late for the promo of Incident'14, the annual cultural fest of NITK. In his excitement, he drops his only 2 wrist watches. He sets his watches according to a wall clock. After some time N he discovers that one of... | ```python
tc = int(raw_input())
while (tc>0):
tc = tc - 1
a, b, c = map(int, raw_input().split())
print a*720/(b+c)
``` | vfc_34637 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 5 5\n1 1 1",
"output": "720\n360",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | tech04 | Solve the following coding problem using the programming language python:
In this problem, you are given two strings S1 and S2, your task is to determine whether one string is an anagram of the other. An anagram of a string is a string obtained by permuting the letters of a string. For example aaba and aaab are anagra... | ```python
t =int(raw_input())
for i in range(0,t):
input = raw_input().split(" ")
a = input[0]
b =input[1]
da = {}
for ch in a:
if da.has_key(ch):
da[ch]+=1
else:
da[ch]=1
db={}
for ch in b:
if db.has_key(ch):
db[ch]+=1
els... | vfc_34641 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\naaba aaab\nabcd deba",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\naaba baaa\nabcd deba",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1012_A. Photo of The Sky | Solve the following coding problem using the programming language python:
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates... | ```python
n=int(input())-1
s=sorted(map(int,input().split()))
sp=(s[n]-s[0])*(s[2*n+1]-s[n+1])
for i in range(n+1):
sp=min(sp,(s[n+i]-s[i])*(s[2*n+1]-s[0]))
print(sp)
``` | vfc_34645 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 1 3 2 3 2 1 3\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 8 5 5 7 5\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1037_A. Packets | Solve the following coding problem using the programming language python:
You have n coins, each of the same value of 1.
Distribute them into packets such that any amount x (1 ≤ x ≤ n) can be formed using some (possibly one or all) number of these packets.
Each packet may only be used entirely or not used at all. No... | ```python
import math
n, = map(int, input().split())
print(math.floor(math.log2(n)) + 1)
``` | vfc_34649 | {
"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": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "723061816\n... |
code_contests | verifiable_code | 105_B. Dark Assembly | Solve the following coding problem using the programming language python:
Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assemb... | ```python
#!/usr/bin/env python3
n, k, A = map(int, input().rstrip().split())
senators = []
mx_bribe = 0
for i in range(n):
lvl, loy = map(int, input().rstrip().split())
senators.append((lvl, loy))
mx_bribe += (100 - loy) // 10
bribe = [0] * n
def calc(votes):
bsum, cnt, p = 0, 0, 1.0
for i, s ... | vfc_34653 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 100\n11 80\n14 90\n23 70\n80 30\n153 70\n",
"output": "0.9628442962\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6 100\n11 80\n14 90\n23 70\n80 30\n153 70\n",
"output": "1.0... |
code_contests | verifiable_code | 1081_C. Colorful Bricks | Solve the following coding problem using the programming language python:
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick i... | ```python
from math import factorial
[n, m, k] = [int(i) for i in input().split()]
mod = 998244353
l = m*((m-1)**k)
L = factorial(n-1)//factorial(n-1-k)//factorial(k)
print((l*L)%mod)
``` | vfc_34657 | {
"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 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "185... |
code_contests | verifiable_code | 1100_C. NN and the Optical Illusion | Solve the following coding problem using the programming language python:
NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles:
<image>
It turned out that the circles are equa... | ```python
import math
n, r = map(int, input().split())
s = math.sin(math.pi / n)
print(s*r / (1-s))
``` | vfc_34661 | {
"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 1\n",
"output": "6.464101615",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 100\n",
"output": "3.242939086",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1129_A1. Toy Train (Simplified) | Solve the following coding problem using the programming language python:
This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of... | ```python
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
s = [[] for _ in range(n)]
for q in a:
s[q[0]-1].append(q[1]-1)
d = []
for q in range(len(s)):
if len(s[q]) == 0:
d.append(0)
else:
p = min(s[q], key=lambda x: (x-q) % n)
d.append((len(... | vfc_34665 | {
"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 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"output": "10 9 10 10 9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 2\n1 2\n1 2\n",
"output": "5 6\n",
"type": "stdin_stdo... |
code_contests | verifiable_code | 1149_A. Prefix Sum Primes | Solve the following coding problem using the programming language python:
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the... | ```python
n = int(input())
a = list(map(int, input().split()))
aset = set(a)
if len(aset) == 1:
print(' '.join(map(str, a)))
else:
count = [-1, -1]
for elem in a:
count[elem - 1] += 1
print(2, 1, end = ' ')
for i in range(count[1]):
print(2, end = ' ')
for i in range(count[0]):
... | vfc_34669 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n1 1 2 1 1 1 2 1 1\n",
"output": "2 1 2 1 1 1 1 1 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1170_A. Three Integers Again | Solve the following coding problem using the programming language python:
We have three positive integers a, b and c. You don't know their values, but you know some information about them. Consider all three pairwise sums, i.e. the numbers a+b, a+c and b+c. You know exactly two (any) of three pairwise sums.
Your task... | vfc_34673 | {
"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\n123 13\n2 2\n2000000000 2000000000\n",
"output": "\n111 1 12\n1 1 1\n1999999999 1 1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1188_E. Problem from Red Panda | Solve the following coding problem using the programming language python:
At Moscow Workshops ICPC team gets a balloon for each problem they solved first. Team MSU Red Panda got so many balloons that they didn't know how to spend them. So they came up with a problem with them.
There are several balloons, not more tha... | vfc_34677 | {
"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\n0 1 2\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0 1 2 3\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... | |
code_contests | verifiable_code | 1207_G. Indie Album | Solve the following coding problem using the programming language python:
Mishka's favourite experimental indie band has recently dropped a new album! Songs of that album share one gimmick. Each name s_i is one of the following types:
* 1~c — a single lowercase Latin letter;
* 2~j~c — name s_j (1 ≤ j < i) with a... | vfc_34681 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20\n1 d\n2 1 a\n2 2 d\n2 3 a\n2 4 d\n2 5 a\n2 6 d\n2 7 a\n1 d\n2 9 o\n2 10 k\n2 11 i\n2 12 d\n2 13 o\n2 14 k\n2 15 i\n2 1 o\n2 17 k\n2 18 i\n2 15 i\n12\n8 da\n8 dada\n8 ada\n6 dada\n3 dada\n19 doki\n19 ok\n16 doki\n15 doki\n9 d\n1 ... | |
code_contests | verifiable_code | 1225_G. To Make 1 | Solve the following coding problem using the programming language python:
There are n positive integers written on the blackboard. Also, a positive number k ≥ 2 is chosen, and none of the numbers on the blackboard are divisible by k. In one operation, you can choose any two integers x and y, erase them and write one e... | vfc_34685 | {
"difficulty": "13",
"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 2\n1 1\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1269_A. Equation | Solve the following coding problem using the programming language python:
Let's call a positive integer composite if it has at least one divisor other than 1 and itself. For example:
* the following numbers are composite: 1024, 4, 6, 9;
* the following numbers are not composite: 13, 1, 2, 3, 37.
You are give... | ```python
n = int(input())
if n == 1:
print(15, 14)
elif n == 2:
print(16, 14)
elif n % 2 == 1:
print(n*3, n*3-n)
else:
print(n*2, n*2-n)
``` | vfc_34693 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "512\n",
"output": "516 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "9 8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1333_F. Kate and imperfection | Solve the following coding problem using the programming language python:
Kate has a set S of n integers \{1, ..., n\} .
She thinks that imperfection of a subset M ⊆ S is equal to the maximum of gcd(a, b) over all pairs (a, b) such that both a and b are in M and a ≠ b.
Kate is a very neat girl and for each k ∈ \{2... | ```python
from collections import *
from math import *
N = int(5e5+5)
p = [0 for i in range(N)]
for i in range(2,N):
if(p[i] == 0):
for j in range(i*i,N,i):
if(p[j] == 0): p[j] = i
n = int(input())
a = [1 for i in range(n+1)]
primes = []
ct = 0
for i in range(1,n+1):
if p[i] == 0:
ct += 1
primes.append(i)
... | vfc_34705 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6310\n",
... |
code_contests | verifiable_code | 1374_A. Required Remainder | Solve the following coding problem using the programming language python:
You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 ≤ k ≤ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it.
In other words, with giv... | ```python
t=int(input())
for i in range(t):
x, y, n=map(int,input().split())
print(n-(n-y)%x)
``` | vfc_34713 | {
"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": "7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999\n",
"output": "12339\n0\n15\n54306\n999999995\n185\n999999998\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1397_B. Power Sequence | Solve the following coding problem using the programming language python:
Let's call a list of positive integers a_0, a_1, ..., a_{n-1} a power sequence if there is a positive integer c, so that for every 0 ≤ i ≤ n-1 then a_i = c^i.
Given a list of n positive integers a_0, a_1, ..., a_{n-1}, you are allowed to:
* ... | ```python
import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7
def gcd(a, b):
while b:
a, b = b, a%b
return a
def isPrime(n):
if (n <= 1):
return False
i = 2
while i ** 2 <= n:
if n % i == 0:
return False
i += 1
return True
def primeFactors(... | vfc_34717 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1000000000 1000000000 1000000000\n",
"output": "1999982505\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1490_C. Sum of Cubes | Solve the following coding problem using the programming language python:
You are given a positive integer x. Check whether the number x is representable as the sum of the cubes of two positive integers.
Formally, you need to check if there are two integers a and b (1 ≤ a, b) such that a^3+b^3=x.
For example, if x =... | ```python
t = int(input())
f = []
for _ in range(t):
n = int(input())
cubes = {}
for i in range(1,int(n**(1./3.))+8):
cubes[i**3] = 1
for i in range(1,len(cubes)):
a = i**3
b = n - a
g = cubes.get(b)
if (g == None):
ans = "No"
else:
... | vfc_34733 | {
"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\n4\n34\n35\n16\n703657519796\n",
"output": "\nNO\nYES\nNO\nNO\nYES\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n999998011905\n999998011906\n999998011907\n",
"... |
code_contests | verifiable_code | 153_D. Date Change | Solve the following coding problem using the programming language python:
You are given a date in "DD.MM.YYYY" ("day.month.year") format and a number of days shift you have to add to this date. Output the resulting date.
Input
The first line of input contains the date in "DD.MM.YYYY" format: two digits for day (with... | vfc_34741 | {
"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": "10.02.2012\n12\n",
"output": "22.02.2012\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "01.02.2010\n-40\n",
"output": "23.12.2009\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 167_B. Wizards and Huge Prize | Solve the following coding problem using the programming language python:
One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees.
One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one ... | ```python
from collections import *
f = lambda: list(map(int, input().split()))
n, l, a = f()
p, s = f(), f()
m = s.count(-1)
x = {(0, min(a, m)): 1}
r = [1]
for p, s in zip(p, s):
p /= 100
if s > 0:
y = defaultdict(int)
for (k, a), q in x.items():
y[(k, a)] += q - q ... | vfc_34745 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 0\n10 20 30\n-1 -1 2\n",
"output": "0.3000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n100\n123\n",
"output": "1.0000000\n",
"type": "stdin_stdout"
}
]
... |
code_contests | verifiable_code | 188_C. LCM | Solve the following coding problem using the programming language python:
Least common multiple (LCM) of two numbers is the smallest positive integer which is divisible by both of them. You are given integers a and b. Calculate their LCM.
Input
The input contains two integers a and b (1 ≤ a, b ≤ 103), separated by a... | vfc_34749 | {
"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": "10 42\n",
"output": "210\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 209_A. Multicolored Marbles | Solve the following coding problem using the programming language python:
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.
A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequ... | ```python
n=int(input())
mod=10**9+7
if n>=2:
dp=[0 for i in range(n)]
dp[0],dp[1]=1,2
ans=3
for i in range(2,n):
dp[i]=(dp[i-1]+dp[i-2])%mod
ans=(ans+dp[i])%mod
print(ans)
else:
print(1)
``` | vfc_34753 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "11",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 234_E. Champions' League | Solve the following coding problem using the programming language python:
In the autumn of this year, two Russian teams came into the group stage of the most prestigious football club competition in the world — the UEFA Champions League. Now, these teams have already started to play in the group stage and are fighting... | vfc_34757 | {
"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": "8\n1 3 1 7\nBarcelona 158\nMilan 90\nSpartak 46\nAnderlecht 48\nCeltic 32\nBenfica 87\nZenit 79\nMalaga 16\n",
"output": "Group A:\nBarcelona\nBenfica\nSpartak\nCeltic\nGroup B:\nMilan\nZenit\nAnderlecht\nMalaga\n",
"ty... | |
code_contests | verifiable_code | 25_C. Roads in Berland | Solve the following coding problem using the programming language python:
There are n cities numbered from 1 to n in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing... | ```python
n = int(input())
mat = []
for _ in range(n):
mat.append(list(map(int, input().split())))
q = int(input())
ans= []
for _ in range(q):
x, y, w = map(int, input().split())
x-=1
y-=1
mat[x][y] = mat[y][x] = min(mat[x][y], w)
sum1 = 0
for i in range(n):
for j in range(n):
... | vfc_34761 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 5\n5 0\n1\n1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n",
"output": "17 12\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 283_C. Coin Troubles | Solve the following coding problem using the programming language python:
In the Isle of Guernsey there are n different types of coins. For each i (1 ≤ i ≤ n), coin of type i is worth ai cents. It is possible that ai = aj for some i and j (i ≠ j).
Bessie has some set of these coins totaling t cents. She tells Jessie... | vfc_34765 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 17\n3 1 2 5\n4 2\n3 4\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 306_B. Optimizer | Solve the following coding problem using the programming language python:
A process RAM is a sequence of bytes that are indexed from 1 to n. Polycarpus's program contains such instructions as "memset", that is, the operations of filling memory cells on a segment with some value. The details are: the code only contains... | ```python
n,m = map(int, raw_input().split())
data = []
for i in xrange(1,m+1):
x,y = map(int, raw_input().split())
data.append([x, x+y-1,i])
data.sort(key=lambda x: x[0], reverse=True)
ans = []
while len(data):
#print data
now = data.pop()
while len(data) and data[-1][0] == now[0]:
if data[... | vfc_34769 | {
"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": "10 4\n3 3\n3 1\n4 1\n9 2\n",
"output": "2\n2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 331_D1. Escaping on Beaveractor | Solve the following coding problem using the programming language python:
Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a b × b square on a plane. Each point x, y (0 ≤ x, y ≤ b) belongs to BSA. To make the path quick and funny, the Bea... | vfc_34773 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n0 0 0 1\n0 2 2 2\n3 3 2 3\n12\n0 0 L 0\n0 0 L 1\n0 0 L 2\n0 0 L 3\n0 0 L 4\n0 0 L 5\n0 0 L 6\n2 0 U 2\n2 0 U 3\n3 0 U 5\n1 3 D 2\n1 3 R 2\n",
"output": "0 0\n0 1\n0 2\n1 2\n2 2\n3 2\n3 2\n2 2\n3 2\n1 3\n2 2\n1 3\n",
... | |
code_contests | verifiable_code | 354_A. Vasya and Robot | Solve the following coding problem using the programming language python:
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya... | ```python
import sys
n,L,r,QL,QR=map(int,sys.stdin.readline().split())
W=list(map(int,sys.stdin.readline().split()))
minn=10**10
SumsL=[0]*n
SumsR=[0]*n
s=0
for i in range(n):
s+=W[i]
SumsL[i]=s
for i in range(n-1):
ans=L*SumsL[i]+r*(s-SumsL[i])
if(n-(i+1)>i+1):
ans+=(abs(n-(i+1)-(i+1))... | vfc_34777 | {
"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 4 4 19 1\n42 3 99\n",
"output": "576\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7 2 3 9\n1 2 3 4\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 378_B. Semifinals | Solve the following coding problem using the programming language python:
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best re... | ```python
n = int(input())
sem1 = []
sem2 = []
l = [0,0]
for cont in range(0,n):
l = list(map(int, input().split()))
sem1.append(l[0])
sem2.append(l[1])
kmax = int(n/2)
max1 = 0
max2 = 0
for cont in range(0,n):
if sem1[max1] < sem2[max2]:
max1 += 1
else:
max2 += 1
ris1 = ['1']*(ma... | vfc_34781 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n9840 9920\n9860 9980\n9930 10020\n10040 10090\n",
"output": "1110\n1100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110\n",
"outp... |
code_contests | verifiable_code | 39_D. Cubical Planet | Solve the following coding problem using the programming language python:
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the p... | ```python
#دو تا نقطه تو مختصات سه بعدی میده میگه اینا تو یک وجه از مکعل هستند یا نه
print('YES' if any(i == j for i,j in zip(list(input().split()) ,list(input().split()))) else 'NO')
``` | vfc_34785 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 0\n1 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 0\n0 1 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 424_E. Colored Jenga | Solve the following coding problem using the programming language python:
Cold winter evenings in Tomsk are very boring — nobody wants be on the streets at such a time. Residents of Tomsk while away the time sitting in warm apartments, inventing a lot of different games. One of such games is 'Colored Jenga'.
This gam... | vfc_34789 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nRGB\nGRG\nBBB\nGGR\nBRG\nBRB\n",
"output": "17.1192136966\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nGGR\nGRR\nGRR\n",
"output": "14.0315500686\n",
"type": "stdin_st... | |
code_contests | verifiable_code | 449_C. Jzzhu and Apples | Solve the following coding problem using the programming language python:
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the gre... | ```python
apples=int(input())
if apples<=3:
print(0)
else:
halfpr=int(apples/2)
def primes(n):
isPrime = [True for i in range(n + 1)]
isPrime[0] = isPrime[1] = False
idx = 2
while idx * idx <= n:
if isPrime[idx]:
for i in range... | vfc_34793 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "2\n3 6\n2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n",
"output": "3\n3 9\n2 4\n6 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 470_B. Hexakosioihexekontahexaphobia | Solve the following coding problem using the programming language python:
This (unpronounceable) word means simply fear of number 666.
You are given a string of digits. Check whether it is scary for a person suffering from this phobia, i.e., whether it contains number 666 as a substring.
Input
The input will consi... | vfc_34797 | {
"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": "123098\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16660\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... | |
code_contests | verifiable_code | 493_E. Vasya and Polynomial | Solve the following coding problem using the programming language python:
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is cal... | ```python
t,a,b=map(int,input().split())
if t==2 and a==3 and b>10000: res=0
elif a==t: res=('inf' if a==1 else 2) if a==b else 0
else: res=0 if (a-b)%(t-a) else (1 if t != b else 0)
print(res)
``` | vfc_34801 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 518_D. Ilya and Escalator | Solve the following coding problem using the programming language python:
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that n people stand in the queue for the escalator. At each second one of the two fol... | ```python
import sys
n, p, t = map(str, sys.stdin.readline().split())
n = int(n)
p = float(p)
t = int(t)
def CC(nn,k):
tmp = n
t = max(nn - k, k)
for i in range(1, min(nn - k, k) + 1):
tmp = tmp * (t + i) * (1 - p) / i
if k > nn - k:
tmp = tmp * pow(1-p,k + k - nn)
return tmp
def ... | vfc_34805 | {
"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 0.50 1\n",
"output": "0.500000000000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 571_A. Lengthening Sticks | Solve the following coding problem using the programming language python:
You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total b... | ```python
def f(a, b, c, l):
k = min(l, a - b - c)
return 0 if a < b + c else (k + 1) * (k + 2) // 2
solve = lambda i: f(a + i, b, c, l - i) + f(b + i, c, a, l - i) + f(c + i, a, b, l - i)
a, b, c, l = map(int, input().split())
ans = (l + 1) * (l + 2) * (l + 3) // 6 - sum(solve(i) for i in range(l + 1))
print(... | vfc_34813 | {
"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": "1 1 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 3 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 592_D. Super M | Solve the following coding problem using the programming language python:
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cit... | ```python
from collections import deque
from sys import stdin
from sys import exit
#parsea una línea
def parser():
return map(int, stdin.readline().split())
#Método usado para obtener los vértices por los que debe pasar Super M
def DFS_Discriminiting():
visited=[False for x in range(n)]
visited[numbers_of... | vfc_34817 | {
"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": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7\n",
"output": "2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6\n",
"output": "2\n4",
"type": "st... |
code_contests | verifiable_code | 614_B. Gena's Code | Solve the following coding problem using the programming language python:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their ... | ```python
import sys
def esdist(s):
n=len(s)
if (s[0] != '1'): return True
for i in range(1,n):
if (s[i]!='0'): return True
return False
l=0
for line in sys.stdin:
if l==0: n = int(line)
else: nums = line.split()
l+=1
res = "1"
ceros = 0
for i in range(n):
s = nums[i]
if (not esdist(s)): ceros += len(s)-1... | vfc_34821 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 10 1\n",
"output": "50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 3 1 100 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 662_B. Graph Coloring | Solve the following coding problem using the programming language python:
You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges wi... | ```python
from collections import deque
n, m = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
u, v, c = input().split()
u, v = int(u)-1, int(v)-1
adj[u].append((v, c))
adj[v].append((u, c))
visited = S = T = None
def bfs(i, k):
q = deque([(i, 0)])
while q:
... | vfc_34829 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 686_E. Optimal Point | Solve the following coding problem using the programming language python:
When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.
Mole, who lives in this garden, ... | vfc_34833 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n3 5 9\n2\n3 5 9\n3 5 9\n",
"output": "3 5 9\n3 5 9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n0 0 4\n0 0 -4\n0 4 0\n4 0 0\n1 1 1\n",
"output": "0 0 2147483644\n",
... | |
code_contests | verifiable_code | 709_D. Recover the String | Solve the following coding problem using the programming language python:
For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of the string s equal to the sequence {x, y}.
In these problem you are given four in... | ```python
a00, a01, a10, a11 = map(int, input().split())
numZeros = 0
numOnes = 0
ans = True
for n0 in range(1, 2*a00 + 1):
if n0 * (n0 - 1) == 2 * a00:
numZeros = n0
break
elif n0 * (n0 - 1) > 2 * a00:
ans = False
break;
for n1 in range(1, 2*a11 + 1):
if n1 * (n1 - 1) == 2... | vfc_34837 | {
"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": "Impossible",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 2 1\n",
"output": "0110",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 730_F. Ber Patio | Solve the following coding problem using the programming language python:
Polycarp is a regular customer at the restaurant "Ber Patio". He likes having lunches there.
"Ber Patio" has special discount program for regular customers. A customer can collect bonuses and partially cover expenses in the restaurant.
Let's a... | vfc_34841 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 21\n12 75 52\n",
"output": "110\n2 5 22 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 39\n58 64 33\n",
"output": "107\n28 4 16 ",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 774_J. Stepan's Series | Solve the following coding problem using the programming language python:
Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he... | ```python
def process(S, k):
n = len(S)
if k > n:
return 'NO'
current = 0
for i in range(n):
if S[i]=='N':
current+=1
if current > k:
return 'NO'
else:
current = 0
start_work = True
for i in range(k):
if S[i]=='Y... | vfc_34849 | {
"difficulty": "16",
"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 1\n????NN\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\nNYNNY\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.