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 | 1157_C2. Increasing Subsequence (hard version) | Solve the following coding problem using the programming language python:
The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).
You are given a sequence a consisting of n integers.
You are making a sequence of moves. During... | ```python
import sys
sys.setrecursionlimit(10**7)
N = int(input())
number = list(map(int, input().split()))
seq = []
ans = []
l = 0
r = N-1
def correct(ans, l, r, action):
for i in range(len(ans)-1, -1, -1):
if not ans[i] == 'X':
break
ans[i] = action
if action == 'L':
... | vfc_32161 | {
"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 3 5 6 5 4 2\n",
"output": "6\nLRLRRR",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 4 3 2\n",
"output": "4\nLRRR",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 1198_A. MP3 | Solve the following coding problem using the programming language python:
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If th... | ```python
import math
n, m = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.sort()
lastval = -1
b = list()
for x in a:
if x != lastval:
b.append(1)
lastval = x
else:
b[-1] += 1
k = len(b)
while k > (1 << ((8*m)//n)):
k -= 1
ans = 0
for x in range(k):
ans += b[x]
res = ... | vfc_32169 | {
"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 1\n2 1 2 3 4 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 1\n1 1 2 2 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1238_B. Kill 'Em All | Solve the following coding problem using the programming language python:
Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.
The main part of the level is a large corridor (so large and narrow that it can be represented as... | ```python
import sys
def input():
str = sys.stdin.readline()
return str[:-1]
def unique(x, first, last):
if first == last:
return last
result = first
while first + 1 != last:
first += 1
if(x[result] != x[first]):
result += 1
x[result] = x[first]
re... | vfc_32177 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2\n1 3 5\n4 1\n5 2 3 5\n",
"output": "2\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 1383\n1 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 127_C. Hot Bath | Solve the following coding problem using the programming language python:
Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water ... | ```python
import math
def gcd(a,b):
if(b==0):
return a
return gcd(b,a%b)
l=input().split()
t1=int(l[0])
t2=int(l[1])
x1=int(l[2])
x2=int(l[3])
t0=int(l[4])
num1=t2-t0
num2=t0-t1
if(t1==t2):
print(x1,x2)
quit()
if(num1==0):
print(0,x2)
quit()
if(num2==0):
print(x1,0)
quit()
z=num2... | vfc_32185 | {
"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": "300 500 1000 1000 300\n",
"output": "1000 0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 12_B. Correct Solution? | Solve the following coding problem using the programming language python:
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this num... | ```python
def sort(s):
return sorted(sorted(s), key=str.upper)
s=input()
s1=input()
l=sort(s)
c=l.count('0')
res=""
if(len(l)>c):
res=res+l[c]
for i in range(c):
res=res+l[i]
for i in range(c+1,len(s)):
res=res+l[i]
if(s1==res):
print("OK")
else:
print("WRONG_ANSWER")
``` | vfc_32189 | {
"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": "3310\n1033\n",
"output": "OK\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5\n",
"output": "WRONG_ANSWER\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1323_D. Present | Solve the following coding problem using the programming language python:
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with ... | ```python
from bisect import bisect_left, bisect_right
def go():
n = int(input())
a = list(map(int, input().split()))
b = max(a).bit_length()
res = 0
vals = a
for i in range(b + 1):
# print("")
b2 = 2 << i
b1 = 1 << i
a0 = [aa for aa in a if aa & b1==0]
... | vfc_32193 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1342_C. Yet Another Counting Problem | Solve the following coding problem using the programming language python:
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for ... | ```python
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
t = int(input())
for i in range(t):
a, b, q = map(int, input().split())
mi = min(a, b)
ma = max(a, b)
for j in range(q):
l, r = map(int, input().split())
l = max(l, ma)
if a == b or ... | vfc_32197 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200\n",
"output": "0\n0\n0\n2\n4\n0\n91\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n200 200 1\n1 1000000000000000000\n",
"o... |
code_contests | verifiable_code | 1364_C. Ehab and Prefix MEXs | Solve the following coding problem using the programming language python:
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If su... | ```python
n=int(input())
arr=list(map(int,input().split()))
flag=0
vis=[0]*(10**6+1)
for i in range(n):
if arr[i]>i+1:
flag=1
vis[arr[i]]=1
if flag==1:
print(-1)
quit()
b=[-1]*(n)
for i in range(1,n):
if arr[i-1]!=arr[i]:
b[i]=arr[i-1]
not_vis=[]
for i in range(10**6+1):
if vis[i... | vfc_32201 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "0 1 2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1406_A. Subset Mex | Solve the following coding problem using the programming language python:
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smalle... | ```python
t=int(input())
while t!=0:
t-=1
n=int(input())
li=list(map(int,input().split()))
dic={}
dic2={}
a=0
b=0
flag=0
ans=[0]*101
for i in li:
if i not in dic and i not in dic2:
dic[i]=1
else:
ans[i]=1
dic2[i]=1
i... | vfc_32209 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n",
"output": "5\n3\n4\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... |
code_contests | verifiable_code | 1427_B. Chess Cheater | Solve the following coding problem using the programming language python:
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if... | ```python
from functools import reduce
import os
import sys
from collections import *
#from fractions import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value(): return tuple(map(int, input().split())) # multiple va... | vfc_32213 | {
"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": "8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"output": "7\n11\n6\n26\n46\n0\n1\n6\n",
"type": "stdin_stdout"
}
]
... |
code_contests | verifiable_code | 1450_B. Balls of Steel | Solve the following coding problem using the programming language python:
You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls.
I... | ```python
# cook your dish here
remaing_test_cases = int(input())
while remaing_test_cases > 0:
points_count,K = map(int,input().split())
points = []
for i in range(points_count):
x,y = map(int,input().split())
points.append([x,y])
flag = 0
for i in range(points_count):
c... | vfc_32217 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n0 1\n0 2\n0 3\n",
"output": "\n-1\n1\n-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1473_G. Tiles | Solve the following coding problem using the programming language python:
Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are... | vfc_32221 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 2\n2 3\n",
"output": "\n850\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n328 323\n867 868\n715 718\n721 722\n439 435\n868 870\n834 834\n797 796\n",
"output": "\n759099319\... | |
code_contests | verifiable_code | 155_A. I_love_%username% | Solve the following coding problem using the programming language python:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where hi... | ```python
n=int(input())
a=list(map(int,input().split()))
c=[]
d=0
c.append(a[0])
for i in range(1,n):
y=a[i]-a[i-1]
if y>0 and a[i]>max(c):
c.append(a[i])
d+=1
elif y<0 and a[i]<min(c):
c.append(a[i])
d+=1
print(d)
#print(c)
``` | vfc_32233 | {
"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": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n100 50 200 150 200\n",
"output": "2\n",
"type": "stdin... |
code_contests | verifiable_code | 177_C1. Party | Solve the following coding problem using the programming language python:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Be... | ```python
# maa chudaaye duniya
n = int(input())
parents = [i for i in range(n+1)]
ranks = [1 for i in range(n+1)]
def find(x):
if parents[x] != x:
parents[x] = find(parents[x])
return parents[x]
def union(x, y):
xs = find(x)
ys = find(y)
if xs == ys:
return
if ranks[xs] > ranks[ys]:
parents[ys] = xs
eli... | vfc_32237 | {
"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": "9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n",
"output": "3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 198_B. Jumping on Walls | Solve the following coding problem using the programming language python:
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas ... | ```python
from sys import stdin, stdout
from collections import deque
n, k = map(int, stdin.readline().split())
maps = []
maps.append(list(stdin.readline() + '-'))
maps.append(list(stdin.readline() + '-'))
visit = [[0, 0] for i in range(n + 1)]
visit[0][0] = 1
queue = deque()
label = 0
queue.append((0, -1, 0))#твой... | vfc_32241 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3\n---X--X\n-X--XX-\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2\n--X-X-\nX--XX-\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 221_C. Little Elephant and Problem | Solve the following coding problem using the programming language python:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he ... | ```python
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
res = 0
for i in range(n):
if a[i] != b[i]:
res += 1
print('YES' if res <= 2 else 'NO')
``` | vfc_32245 | {
"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\n3 2 1\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 3 2 1\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | 245_D. Restoring Table | Solve the following coding problem using the programming language python:
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to... | ```python
n=int(input())
A=[0]*n
ans=[0]*n
for i in range(n):
A[i]=list(map(int,input().split()))
for j in range(n):
if(j==i):continue
ans[i]|=A[i][j]
for i in range(n):
print(ans[i],' ',end='')
``` | vfc_32249 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n-1 18 0\n18 -1 0\n0 0 -1\n",
"output": "18 18 0 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 270_B. Multithreading | Solve the following coding problem using the programming language python:
Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n... | ```python
n = int(input())
arr = list(map(int,input().split()))
ans = n-1
for i in range(-1,-n,-1):
if arr[i]>arr[i-1]:
ans-=1
else:
break
print(ans)
``` | vfc_32253 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 2 1 3 4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 293_D. Ksusha and Square | Solve the following coding problem using the programming language python:
Ksusha is a vigorous mathematician. She is keen on absolutely incredible mathematical riddles.
Today Ksusha came across a convex polygon of non-zero area. She is now wondering: if she chooses a pair of distinct points uniformly among all integ... | vfc_32257 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n17 136\n859 937\n16 641\n",
"output": "66811.370415516887746\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n-1 3\n4 5\n6 2\n3 -5\n",
"output": "8.1583333333333333329\n",
... | |
code_contests | verifiable_code | 317_B. Ants | Solve the following coding problem using the programming language python:
It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and... | ```python
from sys import *
f = lambda: map(int, stdin.readline().split())
n, t = f()
m = 65
r = range(m)
p = [[0] * m for i in r]
p[1][0] = n // 4
p[0][0] = n % 4
q = k = 1
while q:
k += 1
q = 0
for x in r[1:k]:
for y in r[:x + 1]:
if p[x][y] < 4: continue
q = 1
... | vfc_32261 | {
"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": "6 5\n0 -2\n0 -1\n0 0\n0 1\n0 2\n",
"output": "0\n1\n2\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n0 1\n0 0\n0 -1\n",
"output": " ... |
code_contests | verifiable_code | 341_B. Bubble Sort Graph | Solve the following coding problem using the programming language python:
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initial... | ```python
from bisect import bisect_left, bisect_right, insort
R = lambda: map(int, input().split())
n, arr = int(input()), list(R())
dp = []
for i in range(n):
idx = bisect_left(dp, arr[i])
if idx >= len(dp):
dp.append(arr[i])
else:
dp[idx] = arr[i]
print(len(dp))
``` | vfc_32265 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91... |
code_contests | verifiable_code | 364_D. Ghd | Solve the following coding problem using the programming language python:
John Doe offered his sister Jane Doe find the gcd of some set of numbers a.
Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbers of the set are evenly divisi... | vfc_32269 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n6 2 3 4 5 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 5 6 10 15\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 388_C. Fox and Card Game | Solve the following coding problem using the programming language python:
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top ... | ```python
import re
def main():
n=eval(input())
a=[]
s=[]
s.append(0)
s.append(0)
while n:
n-=1
temp=re.split(' ',input())
k=eval(temp[0])
for i in range(k>>1):
s[0]+=eval(temp[i+1])
if k&1:
a.append(eval(temp[(k+1)>>1]))
for i in range((k+1)>>1,k):
s[1]+=eval(temp... | vfc_32273 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"output": "18 18\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 100\n2 1 10\n",
"output": "101 10\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 409_A. The Great Game | Solve the following coding problem using the programming language python:
Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the... | ```python
"""
Codeforces April Fools Contest 2014 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
... | vfc_32277 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "[]()[]8<\n8<[]()8<\n",
"output": "TEAM 2 WINS",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 436_B. Om Nom and Spiders | Solve the following coding problem using the programming language python:
Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
<image>
The park can be repres... | ```python
#!/usr/bin/python
import re
import inspect
from sys import argv, exit
def rstr():
return input()
def rint():
return int(input())
def rints(splitchar=' '):
return [int(i) for i in input().split(splitchar)]
def varnames(obj, namespace=globals()):
return [name for name in namespace if namespa... | vfc_32281 | {
"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": "2 2 2\n..\nRL\n",
"output": "1 1 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 459_C. Pashmak and Buses | Solve the following coding problem using the programming language python:
Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def base(x,k,d):
ans = []
while x:
ans.append(x%k+1)
x //= k
ans.reverse()
return [1]*(d-len(ans))+ans
def main():
n,k,d = map(int,input().split())
if n == 1:
... | vfc_32285 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2\n",
"output": "1 2 1\n1 1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 480_B. Long Jumps | Solve the following coding problem using the programming language python:
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l... | ```python
def main():
from bisect import bisect_left
n, l, x, y = map(int, input().split())
aa, d = list(map(int, input().split())), {}
for z in (x, y, y + x):
for a in aa:
a += z
if a > l:
break
b = aa[bisect_left(aa, a)]
if b <= a... | vfc_32289 | {
"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 250 185 230\n0 185 250\n",
"output": "1\n230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 300 185 230\n0 300\n",
"output": "2\n185 230\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 505_B. Mr. Kitayuta's Colorful Graph | Solve the following coding problem using the programming language python:
Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process ... | ```python
def build_graph():
line1 = input().strip().split()
n = int(line1[0])
m = int(line1[1])
graph = {}
for _ in range(m):
line = input().strip().split()
u = int(line[0])
v = int(line[1])
c = int(line[2])
if c not in graph:
graph[c] = {j: [] fo... | vfc_32293 | {
"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": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n",
"output": "1\n1\n1\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 ... |
code_contests | verifiable_code | 529_A. And Yet Another Bracket Sequence | Solve the following coding problem using the programming language python:
Polycarpus has a finite sequence of opening and closing brackets. In order not to fall asleep in a lecture, Polycarpus is having fun with his sequence. He is able to perform two operations:
* adding any bracket in any position (in the beginni... | vfc_32297 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "()(\n",
"output": "(())\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "()(())\n",
"output": "(())()\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... | |
code_contests | verifiable_code | 554_C. Kyoya and Colored Balls | Solve the following coding problem using the programming language python:
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed th... | ```python
from sys import stdin
c = [[0]*1002 for _ in range(0,1002)]
MOD = int(1e9+7)
for i in range(0,1002):
c[i][0] = c[i][i] = 1
for j in range(0,i):
c[i][j] = (c[i-1][j-1] + c[i-1][j])%MOD
r = map(int,stdin.read().split())
n = next(r)
ans = 1
sum = 0
for _ in range(0,n):
x = next(r)
ans... | vfc_32301 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n2\n1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 580_B. Kefa and Company | Solve the following coding problem using the programming language python:
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the... | ```python
n, d = map(int, input().split())
v = []
for i in range(0, n):
a, b = map(int, input().split())
v.append((a, b))
v = sorted(v)
lo = 0
totalFriendship = v[0][1]
bestFriendship = totalFriendship
for i in range(1, n):
while v[i][0] - v[lo][0] >= d:
totalFriendship -= v[lo][1]
lo +... | vfc_32305 | {
"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 100\n0 7\n11 32\n99 10\n46 8\n87 54\n",
"output": "111",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 602_A. Two Bases | Solve the following coding problem using the programming language python:
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in ... | ```python
# print ("Input digits and base for number one")
n1, b1 = (int(x) for x in input().split())
# print ("Input all the digits")
d1 = list(int(x) for x in input().split())
d1.reverse()
# print ("Input digits and base for number two")
n2, b2 = (int(x) for x in input().split())
# print ("Input all the digits")
d2 ... | vfc_32309 | {
"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 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n",
"output": ">",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 624_D. Array GCD | Solve the following coding problem using the programming language python:
You are given array ai of length n. You may consecutively apply two operations to this array:
* remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins;
* change some elements of the array by at most 1, and... | vfc_32313 | {
"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": "3 1 4\n4 2 3\n",
"output": " 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 3 4\n3 7 5 4 3 12 9 4\n",
"output": " ... | |
code_contests | verifiable_code | 64_A. Factorial | Solve the following coding problem using the programming language python:
Print the factorial of the given integer number n. The factorial of n is equal to 1·2·...·n.
Input
The only line contains n (1 ≤ n ≤ 10).
Output
Print the factorial of n.
Examples
Input
3
Output
6
Input
5
Output
120
The input wi... | vfc_32317 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "120\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 673_A. Bear and Game | Solve the following coding problem using the programming language python:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV ... | ```python
n=int(input())
tl = list(map(int, input().split()))
time=cnt=0
while cnt <15 and time<90:
time+=1
if tl.count(time)>0:
cnt=0
else:
cnt+=1
print(time)
``` | vfc_32321 | {
"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\n7 20 88\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n15 20 30 40 50 60 70 80 90\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 698_B. Fix a Tree | Solve the following coding problem using the programming language python:
A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, ... | ```python
from collections import defaultdict
from sys import stdin,setrecursionlimit
setrecursionlimit(10**6)
import threading
def f(a):
n=len(a)
a=list(map(lambda s:s-1,a))
root=None
for i in range(len(a)):
if a[i]==i:
root=i
vis=[0]*(n)
traitors=[]
for i in range(0,n):
cycle=-1
cur=i
move=set()
... | vfc_32325 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 2 2 5 3\n",
"output": "0\n3 2 2 5 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n2 3 5 4 1 6 6 7\n",
"output": "2 \n2 3 5 4 4 4 6 7 \n",
"type": "stdin_stdout"
},... |
code_contests | verifiable_code | 719_B. Anatoly and Cockroaches | Solve the following coding problem using the programming language python:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly ... | ```python
#http://codeforces.com/problemset/problem/719/B
#solved
n = int(input())
s = input()
red_black = True
swap_red = {"b": 0, "r": 0}
swap_black = {"b": 0, "r": 0}
for c in s:
if red_black is True and c != "b":
swap_black["r"] += 1
elif red_black is False and c != "r":
swap_black["b"] ... | vfc_32329 | {
"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": "5\nrbbrr\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nbbbbb\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 73_F. Plane of Tanks | Solve the following coding problem using the programming language python:
Vasya plays the Plane of Tanks. The tanks in this game keep trying to finish each other off. But your "Pedalny" is not like that... He just needs to drive in a straight line from point A to point B on the plane. Unfortunately, on the same plane ... | vfc_32333 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 10 0\n1\n5 -5 4.71238 1\n0\n",
"output": "4.244116\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 10 0\n1\n5 -5 4.71238 1\n1\n",
"output": "0.0000\n",
"type": "stdin_s... | |
code_contests | verifiable_code | 763_D. Timofey and a flat tree | Solve the following coding problem using the programming language python:
Little Timofey has a big tree — an undirected connected graph with n vertices and no simple cycles. He likes to walk along it. His tree is flat so when he walks along it he sees it entirely. Quite naturally, when he stands on a vertex, he sees t... | vfc_32337 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n1 7\n1 8\n9 4\n5 1\n9 2\n3 5\n10 6\n10 9\n5 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n2 3\n",
"output": "1\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 787_A. The Monster | Solve the following coding problem using the programming language python:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<imag... | ```python
import math
R=lambda:list(map(int,input().split()))
a,b=R()
c,d=R()
if abs(b-d)%math.gcd(a,c)!=0:
print(-1)
exit(0)
while b != d:
if b<d: b+=a
else: d+=c
print(b)
``` | vfc_32341 | {
"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": "20 2\n9 19\n",
"output": "82\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n16 12\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 808_E. Selling Souvenirs | Solve the following coding problem using the programming language python:
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been wo... | ```python
def f():
n, m = map(int, input().split())
l = list(tuple(map(int, input().split())) for _ in range(n))
l.sort(key=lambda e: (0, 6, 3, 2)[e[0]] * e[1], reverse=True)
last, r = [0] * 4, 0
for i, (w, c) in enumerate(l):
if m < w:
break
m -= w
r += c
... | vfc_32345 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n3 10\n2 7\n2 8\n1 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 3\n2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 833_A. The Meaningless Game | Solve the following coding problem using the programming language python:
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or... | ```python
import sys,os,io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left , bisect_right
import math
def ii():
return int(input())
def li():
return list(map(int,input().split()... | vfc_32349 | {
"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\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n",
"output": "Yes\nYes\nYes\nNo\nNo\nYes\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 853_D. Michael and Charging Stations | Solve the following coding problem using the programming language python:
Michael has just bought a new electric car for moving across city. Michael does not like to overwork, so each day he drives to only one of two his jobs.
Michael's day starts from charging his electric car for getting to the work and back. He sp... | vfc_32353 | {
"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": "6\n2000 2000 2000 2000 2000 1000\n",
"output": "10000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1000 2000 1000\n",
"output": "3700",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 878_B. Teams Formation | Solve the following coding problem using the programming language python:
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips... | ```python
import sys
from collections import deque
input=sys.stdin.readline
n,k,m=map(int,input().split())
a=list(map(int,input().split()))
r=a[0]
flag=0
for i in range(n):
if r!=a[i]:
flag=1
break
if flag==0:
print((m*n)%k)
sys.exit()
if k>n:
print(m*n)
sys.exit()
curr=a[0]
tmp=1
que=deque([(a[0],1)]... | vfc_32357 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 5\n1 2 3 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 9 10\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 924_A. Mystical Mosaic | Solve the following coding problem using the programming language python:
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. ... | ```python
def read_data():
n, m = map(int, input().strip().split())
a = []
for i in range(n):
line = list(input().strip())
for j in range(len(line)):
if line[j] == ".":
line[j] = 0
else:
line[j] = 1
a.append(line)
return n, ... | vfc_32365 | {
"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 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"output": "No\... |
code_contests | verifiable_code | 952_C. Ravioli Sort | Solve the following coding problem using the programming language python:
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have ... | ```python
n = int(input())
l = [int(x) for x in input().split()]
while len(l) > 1:
if len([i for i in range(len(l)-1) if abs(l[i] - l[i+1]) > 1 ])>0:
print ('NO')
exit(0)
l.remove(max(l))
print('YES')
``` | vfc_32369 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1 2\n",
"output": "NO",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 979_E. Kuro and Topological Parity | Solve the following coding problem using the programming language python:
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.
Kuro challenged Katie to crea... | ```python
n,p=map(int,input().split())
nums=[0]+list(map(int,input().split()))
mod=10**9+7
f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)]
_2=[0]*(n+1)
_2[0]=1
for i in range(1,n+1):
_2[i]=(_2[i-1]<<1)%mod
f[0][0][0][0]=1
if nums[1]!=0:
f[1][1][0][1]+=1
if nums[1]!=1:
f[1][1][1]... | vfc_32373 | {
"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 1\n-1 0 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 999_F. Cards and Joy | Solve the following coding problem using the programming language python:
There are n players sitting at the card table. Each player has a favorite number. The favorite number of the j-th player is f_j.
There are k ⋅ n cards on the table. Each card contains a single integer: the i-th card contains number c_i. Also, y... | ```python
def solve():
n, k = map(int, input().split())
c = list(map(int, input().split()))
f = list(map(int, input().split()))
h = list(map(int, input().split()))
cnt = {}
for i in c:
cnt[i] = cnt.get(i, 0) + 1
likecolor = {}
for i in range(n):
likecolor.setdefault(f[i],... | vfc_32377 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n",
"output": "21\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | compiler-version-2 | Solve the following coding problem using the programming language python:
You are converting an old code for a new version of the compiler.
In the old code we have used "->" for pointers. But now we have to replace each "->" with a ".". But this replacement shouldn't be done inside commments. A comment is a string t... | ```python
while(True):
try:
str=raw_input()
except:
break
new="."
old="->"
x=str.find("//")
if(x==-1):
print str.replace(old,new)
else:
print str[:x].replace(old,new)+str[x:]
``` | vfc_32385 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "int t; //variable t\nt->a=0; //t->a does something\nreturn 0;\n\nSAMPLE",
"output": "int t; //variable t\nt.a=0; //t->a does something\nreturn 0;\n\nSAMPLE\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | fight-for-chocolate | Solve the following coding problem using the programming language python:
Tapan and Divya have a rectangular shaped chocolate bar with chocolates labeled T, D and U. They want to split the bar into exactly two pieces such that:
Tapan's piece can not contain any chocolate labeled D and similarly, Divya's piece can not... | ```python
n,m,s=map(int,raw_input().split())
lst=[]
for _ in range(n):
lst.append(raw_input())
fac=n*m
if n==1:print (2*m-1)
elif m>=8:
print n
elif lst[0]!=lst[1]:print (n*m*fac-n*m)
else:print (n*m*fac-fac)
``` | vfc_32389 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 4\nUU\nUU\n\nSAMPLE",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 8 29\nUUUUUUUU\nDDDUDDDD\nUUUUUUUU\nUUUUUUUU",
"output": "4",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | ikshu-and-his-class-1 | Solve the following coding problem using the programming language python:
Ikshu and his class
Ikshu's class is very fond of playing games. Their teacher tied them with many ropes with each other, Such that each student is tied with exactly one rope. It means that if students 2 and 3 are connected and 2 is connected t... | ```python
class DisjointSet(object):
def __init__(self):
self.leader = {} # maps a member to the group's leader
self.group = {} # maps a group leader to the group (which is a set)
def add(self, a, b):
leadera = self.leader.get(a)
leaderb = self.leader.get(b)
if leadera ... | vfc_32393 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 2\n3 4\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n0 2\n3 4\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | mark-the-answer-1 | Solve the following coding problem using the programming language python:
Our friend Monk has an exam that has quite weird rules. Each question has a difficulty level in the form of an Integer. Now, Monk can only solve the problems that have difficulty level less than X . Now the rules are-
Score of the student is equ... | ```python
n, x = map(int, raw_input().split())
new_a = map(int, raw_input().split())
count = 0
skip = 0
for i in range(n):
if(new_a[i] <= x and skip <= 1):
count = count + 1
if(new_a[i] > x):
skip = skip + 1
print count
``` | vfc_32397 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 6\n4 3 7 6 7 2 2\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 10\n11 12 9 1 3",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | number-miss | Solve the following coding problem using the programming language python:
Vicky, the Artist, had two lists A and B, such that B was a permutation of A. Vicky was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers were left out of A. Can you find the missing n... | ```python
n=input()
a=map(int,raw_input().split())
m=input()
b=map(int,raw_input().split())
a=sorted(a)
b=sorted(b)
i=0
j=0
ans=[]
while i<len(a):
if (a[i]==b[j]):
i+=1
j+=1
else:
if (len(ans)==0 or ans[-1]!=b[j]):
ans.append(b[j])
j+=1
if (j!=len(b) and (len(ans)==0 or ans[-1]!=b[j])):
ans.append(b[j])
f... | vfc_32401 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n203 204 205 206 207 208 203 204 205 206\n13\n203 204 204 205 206 207 205 208 203 206 205 206 204\n\nSAMPLE",
"output": "204 205 206 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\... |
code_contests | verifiable_code | racers | Solve the following coding problem using the programming language python:
There are N bikers present in a city (shaped as a grid) having M bikes. All the bikers want to participate in the HackerRace competition, but unfortunately only K bikers can be accommodated in the race. Jack is organizing the HackerRace and want... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from sys import stdin
import math
from operator import indexOf
def dist(a,b):
return (((a[0]-b[0])*(a[0]-b[0])+((a[1]-b[1])*(a[1]-b[1]))))
def ... | vfc_32405 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 2\n0 1\n0 2\n0 3\n100 1\n200 2 \n300 3\n\nSAMPLE",
"output": "40000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | shil-and-survival-game | Solve the following coding problem using the programming language python:
The Mad King arrested Shil's comrades for participating in a rebellion against the King. Instead of punishing them with death, the King decided to play the Game of survival with them. The game is played as follows:
All the N people are forced ... | ```python
n=input()
a=map(int,raw_input().split())
i=a.index(max(a))
c=[i]
l1=a[:i]
l2=a[i+1:]
max2=l2[-1]
for x in xrange(n-i-2,-1,-1):
if l2[x]>=max2:
max2=l2[x]
c.append(i+1+x)
max=l1[0]
for y in range(i):
if l1[y]>=max:
c.append(y)
max=l1[y]
for j in sorted(c):
print j+1,
else:print
``` | vfc_32409 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 6 8 1 3\n\nSAMPLE",
"output": "1 2 3 5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 10 8 1 3\n\nSAMPLE",
"output": "1 2 3 5\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | the-old-monk | Solve the following coding problem using the programming language python:
Big Chandan is a dire lover of Biryani, especially Old Monk's Biryani. Today, he went over to have some of it. To his surprise, the waiter turns out be to be a coding geek and refuses to serves him unless Chandu solves his two- arrays problem, s... | ```python
'''def findMaxMonkiness(A, al, ah, B, bl, bh):
if (al<ah) | (bl<bh):
print(al)
print(bl)
print(ah)
print(bh)
amid=(al+ah)/2
bmid=(bl+bh)/2
if A[amid]<B[bmid]:
print('less')
print(amid)
print(bmid)
retur... | vfc_32413 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n9\n7 7 3 3 3 2 2 2 1\n8 8 7 7 5 5 4 3 2\n6\n6 5 4 4 4 4\n2 2 2 2 2 2\n\nSAMPLE",
"output": "5\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n9\n7 7 3 3 3 2 2 2 1\n8 8 9 7 5 5 4 3... |
code_contests | verifiable_code | p00090 Overlaps of Seals | Solve the following coding problem using the programming language python:
Stick n circular stickers with a radius of 1 on a square origami paper with a side length of 10. The stickers can be stacked. Create a program that reads the coordinates of the position where the stickers are to be attached and outputs the numbe... | ```python
import itertools
x=[0.]*100;y=[0.]*100
for e in iter(input,'0'):
a=0
n=int(e)
for i in range(n):x[i],y[i]=map(float,input().split(','))
for i,j in itertools.product(range(100),range(100)):
c=0
for k in range(n):
if pow(x[k]-(i/10),2)+pow(y[k]-(j/10),2)<=... | vfc_32461 | {
"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": "15\n3.14979,8.51743\n2.39506,3.84915\n2.68432,5.39095\n5.61904,9.16332\n7.85653,4.75593\n2.84021,5.41511\n1.79500,8.59211\n7.55389,8.17604\n4.70665,4.66125\n1.63470,4.42538\n7.34959,4.61981\n5.09003,8.11122\n5.24373,1.30066\n0.1351... |
code_contests | verifiable_code | p00600 Computation of Minimum Length of Pipeline | Solve the following coding problem using the programming language python:
The Aizu Wakamatsu city office decided to lay a hot water pipeline covering the whole area of the city to heat houses. The pipeline starts from some hot springs and connects every district in the city. The pipeline can fork at a hot spring or a ... | ```python
while(1):
s,d=[int(x) for x in input().split()]
A=[999 for x in range(d)]
if s==0: break
for j in range(s):
l=[int(x) for x in input().split()]
for i in range(d):
if l[i]!=0:
A[i]=min(A[i], l[i])
B=[[999 for x in range(d)] for y in range(d)]
... | vfc_32473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n12 8 25 19 23\n9 13 16 0 17\n20 14 16 10 22\n17 27 18 16\n9 7 0\n19 5\n21\n0 0",
"output": "38",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n12 8 25 19 44\n9 13 16 0 17\n20 14 16... |
code_contests | verifiable_code | p00736 How can I satisfy thee? Let me count the ways... | Solve the following coding problem using the programming language python:
Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "true" are represented by 0, 1 and 2 respectively.
Let "-" be a unary operator... | ```python
class N:
def __init__(self, a):
self.a = a
def __mul__(self, b):
if self.a == 0:
return N(0)
elif self.a == 1:
return N((b.a >= 1) * 1)
else:
return b
def __add__(self, b):
if self.a == 0:
return b
el... | vfc_32477 | {
"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": "(P*Q)\n(--R+(P*Q))\n(P*-P)\n2\n1\n(-1+(((---P+Q)*(--Q+---R))*(-R+-P)))\n.",
"output": "3\n11\n0\n27\n0\n7",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00876 Swimming Jam | Solve the following coding problem using the programming language python:
Despite urging requests of the townspeople, the municipal office cannot afford to improve many of the apparently deficient city amenities under this recession. The city swimming pool is one of the typical examples. It has only two swimming lanes... | ```python
from collections import deque
while 1:
N = int(input())
if N == 0:
break
T = [0]*N; C = [0]*N
que0 = deque()
que1 = deque()
P = [list(map(int, input().split())) for i in range(N)]
P.sort()
for i in range(N):
t, c = P[i]
que0.append((i, t))
T[i] ... | vfc_32481 | {
"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\n10 30\n15 20\n2\n10 240\n15 160\n3\n2 6\n7 2\n8 2\n4\n2 4\n7 2\n8 2\n18 1\n0",
"output": "600\n4800\n36\n40",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10 30\n15 20\n2\n10 240\n15 ... |
code_contests | verifiable_code | p01139 Surrounding Area | Solve the following coding problem using the programming language python:
Surrounding Area
Land fence
English text is not available in this practice contest.
Two real estate agents were boarding a passenger ship to the southern island. Blue sky, refreshing breeze ... The two enjoyed a voyage with other passengers. ... | ```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
def dfs(x, y, symbol,land):
if land[y][x] != '.':
return ([land[y][x]] if not str(land[y][x]).isnumeric() else False), 0
land[y][x] = symbol
count = 1
dxdy = [(1,0),(-1,0),(0,1),(0,-1)]
owner_l... | vfc_32489 | {
"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": "10 10\n.....W....\n....W.W...\n...W...W..\n....W...W.\n.....W...W\n......W.W.\nBBB....W..\n..B..BBBBB\n..B..B....\n..B..B..W.\n5 3\n...B.\n...BB\n.....\n1 1\n.\n0 0",
"output": "6 21\n12 0\n0 0",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p01278 Voronoi Island | Solve the following coding problem using the programming language python:
Some of you know an old story of Voronoi Island. There were N liege lords and they are always involved in territorial disputes. The residents of the island were despaired of the disputes.
One day, a clever lord proposed to stop the disputes and... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def cross3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (by - oy) - (bx - ox) * (ay - oy)
def cross_point(p0, p1, q0, q1):
x0, y0 = p0; x1, y1 = p1
x2, y2 = q0; x3, y3 = q1
dx0 = x1 - x0; dy0 = y1 - y0
... | vfc_32493 | {
"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\n0 0\n8 0\n0 8\n2 2\n4 2\n2 4\n0 0",
"output": "9.0\n11.5\n11.5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n0 0\n8 -1\n0 8\n2 2\n4 2\n2 4\n0 0",
"output": "9.562500\n11.87... |
code_contests | verifiable_code | p01448 A Way to Invite Friends | Solve the following coding problem using the programming language python:
From tomorrow, the long-awaited summer vacation will begin. So I decided to invite my friends to go out to the sea.
However, many of my friends are shy. They would hate it if they knew that too many people would come with them.
Besides, many o... | ```python
n = int(input())
l = [0 for i in range(n+2)]
for i in range(n):
[a,b] = list(map(int,input().split()))
if a <= n+1:
l[a] += 1
if b+1 <= n+1:
l[b+1] -= 1
ans = 0
for i in range(n+2):
if i != 0:
l[i] = l[i-1] + l[i]
if l[i] >= i-1:
ans = i-1
print(ans)
``` | vfc_32497 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n8 100001\n7 100001\n12 100001\n8 100001\n3 100001",
"output": "0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01597 Nezumi's Treasure | Solve the following coding problem using the programming language python:
Problem G: Nezumi's Treasure
There were a mouse and a cat living in a field. The mouse stole a dried fish the cat had loved. The theft was found soon later. The mouse started running as chased by the cat for the dried fish.
There were a number... | vfc_32501 | {
"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": "8\n0 0 2 1\n2 2 4 3\n5 3 7 4\n7 5 9 6\n0 2 1 4\n2 4 3 6\n6 0 7 2\n8 2 9 4",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 2 1\n3 0 4 2\n0 2 1 4\n2 3 4 4",
"output... | |
code_contests | verifiable_code | p02317 Longest Increasing Subsequence | Solve the following coding problem using the programming language python:
For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... , aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < .... | ```python
N = int(input())
A = [int(input()) for _ in range(N)]
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
def solve(N,A):
lis = []
for i in range(N):
ind = bisect_left(lis,A[i])
if ind == len(lis):
lis.append(A[i])
else:
... | vfc_32521 | {
"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\n5\n1\n3\n2\n4",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n1\n1",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | acmicl3 | Solve the following coding problem using the programming language python:
Problem description.
In Bytelandian University, everyone has to enter his/her name on a computer when entering or leaving the library. The names are stored in a file on that computer. Assume that everyone adheres to this rule. Given the file, fi... | ```python
for _ in xrange(int(input())):
n=int(input())
dic={}
for i in xrange(n):
s=raw_input()
if s not in dic:
dic[s]=1
else:
dic[s]+=1
count=0
for i in dic:
if(dic[i]%2!=0):
count+=1
print count
``` | vfc_32529 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n8\nShubham\nHasil\nShubham\nRavi\nShikhar\nHasil\nJaiwant\nHasil",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n8\nShubham\nHasil\nShubham\nRavi\nShikhar\nHasil\nJaiw... |
code_contests | verifiable_code | chefseg | Solve the following coding problem using the programming language python:
Chef loves to play games. Now he plays very interesting game called "Segment". At the beginning Chef has segment [0, X] and no points on it. On each step Chef chooses the subsegment of maximal length possible such as it contains no points on it.... | ```python
import math;
t=int(input());
while t>0:
t=t-1;
inp=raw_input();
x=int(inp.split()[0]);
k=int(inp.split()[1]);
roun=int(math.log(k,2))+1;
deno=pow(2,roun-1);
points=0;
if roun==1:
points=0;
else:
points=pow(2,roun-1)-1;
pos=k-points;
print format(((x*1.0)/(deno*1.0))*(pos-1)+(1.0*x)/(2.0*deno),'... | vfc_32533 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10 1\n10 2\n10 3\n1000000000 1234567",
"output": "5.0000000000000000\n2.5000000000000000\n7.5000000000000000\n177375316.6198730468750000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | doors | Solve the following coding problem using the programming language python:
There are N doors of a palace, all of which are operated by a set of buttons. One day, Alice, who is just 8 years old, gets access to these buttons. Having recently learnt the multiplication tables, she decides to press buttons in a particular o... | ```python
t=int(raw_input())
for i in xrange(t):
n=int(raw_input())
print int(n**0.5)
``` | vfc_32537 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n10\n16\n27",
"output": "2\n3\n4\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4\n6\n16\n27",
"output": "2\n2\n4\n5\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | j7 | Solve the following coding problem using the programming language python:
Johnny needs to make a rectangular box for his physics class project. He has bought P cm of wire and S cm^2 of special paper. He would like to use all the wire (for the 12 edges) and paper (for the 6 sides) to make the box.
What is the largest v... | ```python
#!/usr/bin/python
import math
def main():
num_times = int(raw_input())
for i in xrange(0, num_times):
P, S = map(int, raw_input().split())
l1 = ((P/2) + math.sqrt(math.pow(P/2, 2) - 6*S))/6
l2 = ((P/2) - math.sqrt(math.pow(P/2, 2) - 6*S))/6
h1 = P/4 - 2*l1
h2 ... | vfc_32541 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n20 14\n20 16",
"output": "3.00\n4.15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n20 14\n20 14",
"output": "3.0\n3.0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | seq | Solve the following coding problem using the programming language python:
The number of submissions of CodeChef from Students of Graphic Era University had been growing since the day the CodeChef campus chapter, GEU_Coders had been formed here. This rise in user submissions alerted the staff members at CodeChef. They ... | ```python
for i in xrange(input()):
N=input()
c=1
S=2
while c<N:
if c%2!=0:
S=(S*2)-1
else:
S=(S*2)+1
c+=1
print S
``` | vfc_32549 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n7",
"output": "13\n107",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1003_E. Tree Constructing | Solve the following coding problem using the programming language python:
You are given three integers n, d and k.
Your task is to construct an undirected tree on n vertices with diameter d and degree of each vertex at most k, or say that it is impossible.
An undirected tree is a connected undirected graph with n - ... | ```python
def main():
n, d, k = map(int, input().split())
r, odd = divmod(d, 2)
k -= 1
cap = d + 1 if k == 1 else 1
if k > 1:
cap = 2 * (k ** (r + 1) - 1) // (k - 1) if odd else 1 + (k + 1) * (k ** r - 1) // (k - 1)
if n == 1 or k < 1 < n - 1 or k == 1 and d != n - 1 or d >= n or k > 1 a... | vfc_32553 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 5 3\n",
"output": "YES\n1 2\n2 3\n3 4\n4 5\n5 6\n2 7\n3 8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1027_F. Session in BSU | Solve the following coding problem using the programming language python:
Polycarp studies in Berland State University. Soon he will have to take his exam. He has to pass exactly n exams.
For the each exam i there are known two days: a_i — day of the first opportunity to pass the exam, b_i — day of the second opportu... | vfc_32557 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 13\n1 5\n1 7\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1070_D. Garbage Disposal | Solve the following coding problem using the programming language python:
Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.
For each of next n days Vasya knows a_i — number of units o... | ```python
import sys
n, k = tuple(int(i) for i in sys.stdin.readline().split())
a = tuple(int(i) for i in sys.stdin.readline().split())
assert len(a) == n
bags = 0
r = 0
for ai in a:
leftovers = (r > 0)
q, r = divmod(ai + r, k)
if q == 0:
if leftovers:
bags += 1
r = 0
e... | vfc_32565 | {
"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": "3 2\n1 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n2 8 4 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 1091_H. New Year and the Tricolore Recreation | Solve the following coding problem using the programming language python:
Alice and Bob play a game on a grid with n rows and infinitely many columns. In each row, there are three tokens, blue, white and red one. Before the game starts and after every move, the following two conditions must hold:
* Any two tokens ... | vfc_32569 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 6\n0 3 9\n",
"output": "Alice\nBob\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n0 3 9\n",
"output": "Alice\nBob\n",
"type": "stdin_stdout"
},
{
"fn_name... | |
code_contests | verifiable_code | 1110_F. Nearest Leaf | Solve the following coding problem using the programming language python:
Let's define the Eulerian traversal of a tree (a connected undirected graph without cycles) as follows: consider a depth-first search algorithm which traverses vertices of the tree and enumerates them in the order of visiting (only the first vis... | vfc_32573 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 10\n1 1\n3 2\n3 3\n1 1 5\n5 4 5\n4 1 2\n",
"output": "3\n0\n13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11 8\n1 7\n2 1\n1 20\n1 2\n5 6\n6 2\n6 3\n5 1\n9 10\n9 11\n5 1 11\n1 1... | |
code_contests | verifiable_code | 1140_C. Playlist | Solve the following coding problem using the programming language python:
You have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied ... | ```python
import heapq
n,k=map(int,input().split())
b_l=[]
for _ in range(n):
t,b=map(int,input().split())
b_l.append([b,t])
b_l.sort(reverse=True)
ans=0
sum_fg=0
h=[]
heapq.heapify(h)
for i in range(n):
sum_fg+=b_l[i][1]
heapq.heappush(h,b_l[i][1])
while(len(h)>k):
g=heapq.heappop(h)
... | vfc_32577 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n12 31\n112 4\n100 100\n13 55\n55 50\n",
"output": "10000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n4 7\n15 1\n3 6\n6 8\n",
"output": "78",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1159_A. A pile of stones | Solve the following coding problem using the programming language python:
Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.
You are given n operations ... | ```python
'''
t= input()
lng= len(t)
li1=[]; li2=[]
for i in range(lng):
if t[i]!='a':
li1.append(t[i])
elif t[i]=='a':
li2.append(i)
aa= ''.join(li1)
if len(aa)==0:
print(t); exit(0)
if len(aa)%2==1:
print(':('); exit(0)
if len(aa)%2==0:
#print(123)
l= int(len(aa)/2); l... | vfc_32581 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n-+\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n---\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\... |
code_contests | verifiable_code | 1181_A. Chunga-Changa | Solve the following coding problem using the programming language python:
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha ... | ```python
x,y,z=map(int,input().split())
sum=(x+y)//z
i1=x//z
i2=y//z
x=x%z
y=y%z
current=i1+i2
nu=0
if current==sum:
print(sum,end=' ')
print(nu)
else:
if x>y:
h=x
else:
h=y
current=sum-current
current=current*z
nu=current-h
print(sum, end=' ')
print(nu)
``` | vfc_32585 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 8 2\n",
"output": "7 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 3\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1199_F. Rectangle Painting 1 | Solve the following coding problem using the programming language python:
There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You a... | vfc_32589 | {
"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###\n#.#\n###\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n#...#\n.#.#.\n.....\n.#...\n#....\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 1216_E1. Numerical Sequence (easy version) | Solve the following coding problem using the programming language python:
The only difference between the easy and the hard versions is the maximum value of k.
You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The fi... | ```python
def isqrt(x):
if x < 0:
raise ValueError('square root not defined for negative numbers')
n = int(x)
if n == 0:
return 0
a, b = divmod(n.bit_length(), 2)
x = 2**(a+b)
while True:
y = (x + n//x)//2
if y >= x:
return x
x = y
p = [0, 45, ... | vfc_32593 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2132\n506\n999999999\n1000000000\n",
"output": "8\n2\n9\n8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 125_A. Measuring Lengths in Baden | Solve the following coding problem using the programming language python:
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to c... | ```python
n=int(input())
e=(n+1)//36
n-=36*e
print(e,(n+1)//3)
``` | vfc_32601 | {
"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": "42\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "0 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
... |
code_contests | verifiable_code | 1281_C. Cut and Paste | Solve the following coding problem using the programming language python:
We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i.
There is one cursor. The cursor's location ℓ is denoted by an integer in... | ```python
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
MAX=10**9+7
def solve():
x = int(input())
s = [int(i) for i in input()]
ans=len(s)
c = ""
l = 0
while l < x:
l += 1
k=len(s)
if k < x:
#s += s[l:]*(s[l - 1]-1)
fo... | vfc_32605 | {
"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\n5\n231\n7\n2323\n6\n333\n24\n133321333\n",
"output": "25\n1438\n1101\n686531475\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n... |
code_contests | verifiable_code | 1301_C. Ayoub's function | Solve the following coding problem using the programming language python:
Ayoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols "0" and "1"). The function f(s) is equal to the number of substrings in the string s that contains at le... | ```python
'''input
5
3 1
3 2
3 3
4 0
5 2
'''
import sys
read = lambda: list(map(int,sys.stdin.readline().strip().split()))
# try:
sigma = lambda x:x*(x+1)//2
for _ in range(int(input())):
n,m = read()
k = n-m
total = sigma(n)
# if m==0 or m==n:
# print(total)
# continue
if k>m:
... | vfc_32609 | {
"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\n3 1\n3 2\n3 3\n4 0\n5 2\n",
"output": "4\n5\n6\n0\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 1\n3 2\n3 3\n0 0\n5 2\n",
"output": "4\n5\n6\n0\n12\n",
"type": "s... |
code_contests | verifiable_code | 1366_B. Shuffle | Solve the following coding problem using the programming language python:
You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.
You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, an... | ```python
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq... | vfc_32621 | {
"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\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2\n",
"output": "6\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n100 50 6\n1 49\n51 100\n40 60\n30 70\n20 30\n70 80\n100 ... |
code_contests | verifiable_code | 1386_B. Mixture | Solve the following coding problem using the programming language python:
Serge, the chef of the famous restaurant "Salt, Pepper & Garlic" is trying to obtain his first Michelin star. He has been informed that a secret expert plans to visit his restaurant this evening.
Even though the expert's name hasn't been disclo... | vfc_32625 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 3\n6\nA 5 6 7\nA 3 10 17\nR 1\nA 15 18 21\nA 5 10 15\nR 3\n",
"output": "0\n2\n0\n2\n1\n1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1428_E. Carrots for Rabbits | Solve the following coding problem using the programming language python:
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to fe... | ```python
import sys
from heapq import heapify, heappush, heappop
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e f... | vfc_32633 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 4\n19\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6\n5 3 1\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 1525_E. Assimilation IV | Solve the following coding problem using the programming language python:
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.
Monocarp's empire has n cities. In order to conquer new lands he plans to build one Monument in each city. The game is t... | ```python
ans = 0
n,m = map(int,input().split())
mod = 998244353
a = [list(map(int,input().split())) for i in range(n)]
fac = 1
for i in range(1,n+1): fac *= i
inv = pow(fac,mod-2,mod)
for j in range(m):
na = sorted([a[i][j] for i in range(n)])
now = 1
able = 0
for i in range(n):
while l... | vfc_32649 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3\n",
"output": "\n166374062\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 157_B. Trace | Solve the following coding problem using the programming language python:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts... | ```python
n=int(input())
s=0
X=[int(x) for x in input().split(" ")]
X.sort(reverse=True)
for i in range(n):
s=s+(-1)**(i)*X[i]*X[i]
print(3.1415926536*s)
``` | vfc_32653 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n",
"output": "3.141592653589793\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 4 2\n",
"output": "40.840704496667314\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 19_C. Deletion of Repeats | Solve the following coding problem using the programming language python:
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a re... | ```python
def pow(x, exp, mod):
res = 1
while exp:
if exp & 1:
res = (res * x) % mod
x = (x * x) % mod
exp >>= 1
return res
MOD = 2 ** 121 - 1
M = int(1e9) + 1
n = int(input())
vals = list(map(int, input().split()))
groups = dict()
for i in range(n):
groups.setde... | vfc_32661 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 2 3 1 2 3\n",
"output": "3\n1 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n4 5 6 5 6 7 7\n",
"output": "1\n7 ",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 223_D. Spider | Solve the following coding problem using the programming language python:
A plane contains a not necessarily convex polygon without self-intersections, consisting of n vertexes, numbered from 1 to n. There is a spider sitting on the border of the polygon, the spider can move like that:
1. Transfer. The spider moves... | vfc_32665 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0\n1 1\n0 2\n-1 1\n3 3\n",
"output": "0.000000000000000000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 248_B. Chilly Willy | Solve the following coding problem using the programming language python:
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.
Chilly Willy w... | ```python
n = int(input())
if n < 3:
print(-1)
else:
t = 10**(n-1)
print(t+210-t%210)
``` | vfc_32669 | {
"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\n",
"output": "10080\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 272_C. Dima and Staircase | Solve the following coding problem using the programming language python:
Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the sta... | ```python
# https://codeforces.com/problemset/problem/272/C
# we just check if the box dropped falls above the previous box or on stair number(1...w)
# the box is dropped from the top and hence we need to check the heights from the top -
# which height is suitable and higher
m = int(input())
arr = list(map(int, inpu... | vfc_32673 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n",
"output": "1\n3\n13\n23\n33\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n2\n1 1\n3 1\n",
"output": "1\n3\n",
"type": "stdi... |
code_contests | verifiable_code | 295_E. Yaroslav and Points | Solve the following coding problem using the programming language python:
Yaroslav has n points that lie on the Ox axis. The coordinate of the first point is x1, the coordinate of the second point is x2, ..., the coordinate of the n-th point is — xn. Now Yaroslav wants to execute m queries, each of them is of one of t... | vfc_32677 | {
"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": "8\n36 50 28 -75 40 -60 -95 -48\n20\n2 -61 29\n1 5 -53\n1 1 429\n1 5 130\n2 -101 -71\n2 -69 53\n1 1 404\n1 5 518\n2 -101 53\n2 50 872\n1 1 -207\n2 -99 -40\n1 7 -389\n1 6 -171\n1 2 464\n1 7 -707\n1 1 -730\n1 1 560\n2 635 644\n1 7 -67... | |
code_contests | verifiable_code | 319_C. Kalila and Dimna in the Logging Industry | Solve the following coding problem using the programming language python:
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a1, a2, ..., an. They b... | ```python
n = int(input())
a = [0] + [int(x) for x in input().split()]
b = [0] + [int(x) for x in input().split()]
q = [0 for i in range(n + 1)]
f = [0 for _ in range(n + 1)]
l, r, q[1] = 1, 1, 1
for i in range(2, n + 1):
while l < r and f[q[l + 1]] - f[q[l]] < a[i] * (b[q[l]] - b[q[l + 1]]):
l += 1
f[i... | vfc_32681 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n5 4 3 2 0\n",
"output": "25\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 343_C. Read Time | Solve the following coding problem using the programming language python:
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the a... | ```python
import sys
from itertools import *
from math import *
def solve():
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = list(map(int, input().split()))
ss, ll = 0, int(2.2e10)
while ss < ll:
avg = (ss + ll) // 2
works = True
hidx = 0
pidx... | vfc_32685 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n2 5 6\n1 3 6 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2 3\n1 2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 366_E. Dima and Magic Guitar | Solve the following coding problem using the programming language python:
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then p... | ```python
def solution() : # 最大的距离来自于角落附近的点
n,m,k,s = map(int, input().split())
dis = lambda a,b : abs(a[0] - b[0]) + abs(a[1] - b[1])
corner = [(0,0), (0,m-1), (n-1,0), (n-1,m-1)]
vertex = [[(n,m), (n,-1), (-1,m), (-1,-1)] for _ in range(k+1)]
for i in range(n) :
for j,note in enumerate(map(int, input().split()... | vfc_32689 | {
"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": "4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1... |
code_contests | verifiable_code | 38_D. Vasya the Architect | Solve the following coding problem using the programming language python:
Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart.
Let us consider the building process. Vasya takes a brick and puts it on top of the al... | ```python
a=[list(map(int,input().split())) for i in range(int(input()))]
n=len(a)
z=n
for i in range(n):
if i!=0:
c=[(a[i][0]+a[i][2])/2,(a[i][1]+a[i][3])/2]
m=abs(a[i][0]-a[i][2])**3
for j in range(i-1,-1,-1):
x1,y1,x2,y2=min(a[j][0],a[j][2]),min(a[j][1],a[j][3]),max(a[j][0],a[... | vfc_32693 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 3 3\n1 0 4 3\n2 0 5 3\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0 3 3\n1 0 4 3\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 40_C. Berland Square | Solve the following coding problem using the programming language python:
Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's ... | ```python
def readGen(trans):
while 1:
for x in input().split():
yield(trans(x))
readint=readGen(int)
[N,x,M,y]=(next(readint) for i in range(4))
d=abs(y-x)
def interval(a,b): return range(a,b+1)
def case1(N,M,d): # d>=N
ans=0
for r in interval(1, min(M,d-N)):
ans+=1
if (M<=d-N):
return ans
for r in... | vfc_32697 | {
"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 4 7\n",
"output": " 17\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0 1 2\n",
"output": " ... |
code_contests | verifiable_code | 483_C. Diverse Permutation | Solve the following coding problem using the programming language python:
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that th... | ```python
from collections import Counter
import string
import math
import sys
# sys.setrecursionlimit(10**6)
from fractions import Fraction
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
if arrber_of_variables==1:
return int(sys.stdin.readline())
... | vfc_32709 | {
"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 2\n",
"output": "1 3 2 4 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n",
"output": "1 2 3 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 507_C. Guess Your Way Out! | Solve the following coding problem using the programming language python:
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is lo... | ```python
import sys
def main():
rdl = list(map(int,input().split()))
obx(rdl[0],rdl[1],0,1)
def obx(lvl, ind, kl, current):
if lvl ==0:
print(int(kl))
sys.exit()
all = 0
for i in range(lvl+1):
all += 2**i
all -= 1
if ind > (2**(lvl))/2:
if current == 1:
... | vfc_32713 | {
"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": "1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1024\n",
"output": "2046\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.