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 | donuts | Solve the following coding problem using the programming language python:
There is new delicious item in Chef's menu - a doughnut chain. Doughnuts connected successively in line forming a chain.
Chain of 3 doughnuts
Chef has received an urgent order for making a chain of N doughnuts. He noticed that there are exact... | ```python
for t in xrange(input()):
n, m = map(int, raw_input().strip().split())
arr = map(int, raw_input().strip().split())
arr.sort()
cuts = 0
for i in xrange(m):
k = m - i - cuts - 1
if k <= arr[i]:
ans = cuts + k
break
cuts += arr[i]
print ... | vfc_30029 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n11 3\n4 3 4\n6 3\n3 2 1",
"output": "2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n11 3\n2 3 4\n6 3\n3 2 1",
"output": "2\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | ism1 | Solve the following coding problem using the programming language python:
Hackers! Hackers! Everywhere!
Some days back your email ID was hacked. Some one read the personal messages and Love Letters you sent to your girl friend. That's a terrible thing, well, you know how are the boys at ISM. So, you have decided that ... | ```python
t=input()
while t>0:
b=[]
a=raw_input().split()
for i in range(len(a)):
str=a[i]
rev=str[::-1]
b.append(rev)
for i in range(len(b)):
print b[i],
print "\n"
t=t-1
``` | vfc_30033 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ncan you meet me outside ccd today\na\nthis year hard kaur is coming to entertain us",
"output": "nac uoy teem em edistuo dcc yadot\na\nsiht raey drah ruak si gnimoc ot niatretne su",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | nopc10 | Solve the following coding problem using the programming language python:
Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date.
You are required to find a day from a particular date given to you.
Input
It consists of ... | ```python
import datetime
dt='21/03/2012'
day, month, year = (int(x) for x in dt.split('/'))
ans=datetime.date(year,month,day)
print (ans.strftime("%A"))
``` | vfc_30037 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14 3 2012",
"output": "Wednesday",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 2 2012",
"output": "Wednesday\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | seg003 | Solve the following coding problem using the programming language python:
Problem description.
The problem statement is simple , you are given an array and you have to perform two types of operation on it.
Type 1 : update the value of array at the given index.
Type 2 : find the maximum sum you can obtained in the ... | ```python
# your code goes here
from math import ceil, log
from sys import stdin, stdout
st = []
def getMid(s, e):
return s + (e-s) / 2
def construct(st, arr, ss, se, si, type):
if se == ss:
if se%2 == type:
st[si] = arr[ss]
else:
st[si] = 0
return st[si]
m = getMid(ss, se)
st[si] = max(construct(st, a... | vfc_30041 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 \n1 2 3 4 5\n2 1 5\n1 2 5\n2 1 5",
"output": "9 \n10",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1003_D. Coins and Queries | Solve the following coding problem using the programming language python:
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d).
Polycarp wants to know answers on q queries. The j-th query is descri... | ```python
# @oj: codeforces
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-10-14 16:44
# @url:https://codeforc.es/contest/1003/problem/D
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio
BUFSIZE = 8192
BUFSIZE = 8192
c... | vfc_30045 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n2 4 8 2 4\n8\n5\n14\n10\n",
"output": "1\n-1\n3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n... |
code_contests | verifiable_code | 1046_D. Interstellar battle | Solve the following coding problem using the programming language python:
In the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N-1 wormholes. The wormholes are of extreme religious importance in Bubbledom, a set of planets in Bubbledom co... | vfc_30053 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0.50 0.29 0.49 0.95 0.83\n2 3\n0 3\n3 4\n2 1\n3\n4 0.66\n1 0.69\n0 0.36\n",
"output": "1.6804000000\n1.4844000000\n1.6174000000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1070_C. Cloud Computing | Solve the following coding problem using the programming language python:
Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered ... | vfc_30057 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 13 5\n2 3 10 7\n3 5 10 10\n1 2 10 6\n4 5 10 9\n3 4 10 8\n",
"output": "462\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 100 3\n3 3 2 5\n1 1 3 2\n2 4 4 4\n",
"output": "64\n",
... | |
code_contests | verifiable_code | 1091_G. New Year and the Factorisation Collaboration | Solve the following coding problem using the programming language python:
Integer factorisation is hard. The RSA Factoring Challenge offered $100 000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number.
Sinc... | ```python
import sys
import random
def gcd(x, y):
return x if y == 0 else gcd(y, x % y)
def isPrime(n):
"""
Miller-Rabin primality test.
A return value of False means n is certainly not prime. A return value of
True means n is very likely a prime.
"""
if n!=int(n):
return False
... | vfc_30061 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "21\n\n7\n\n17\n\n15\n\n17\n\n11\n\n-1\n\n15\n\n",
"output": "+ 12 16\n\n- 6 10\n\n* 8 15\n\n/ 5 4\n\nsqrt 16\n\nsqrt 5\n\n^ 6 12\n\n! 2 3 7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\... |
code_contests | verifiable_code | 1110_E. Magic Stones | Solve the following coding problem using the programming language python:
Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to c_i.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, where 2 ≤ i ≤ n - 1), and after that synch... | ```python
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
f=a[0]==b[0]
a=sorted([a[i+1]-a[i] for i in range(n-1)])
b=sorted([b[i+1]-b[i] for i in range(n-1)])
print('YES' if f and a==b else 'NO')
``` | vfc_30065 | {
"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": "4\n7 2 4 12\n7 15 10 12\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 4 4\n1 2 3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 1158_F. Density of subarrays | Solve the following coding problem using the programming language python:
Let c be some positive integer. Let's call an array a_1, a_2, …, a_n of positive integers c-array, if for all i condition 1 ≤ a_i ≤ c is satisfied. Let's call c-array b_1, b_2, …, b_k a subarray of c-array a_1, a_2, …, a_n, if there exists such ... | vfc_30073 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 2 1 2 1\n",
"output": "10 17 4 0 0 0 ",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1180_E. Serge and Dining Room | Solve the following coding problem using the programming language python:
Serge came to the school dining room and discovered that there is a big queue here. There are m pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As ... | vfc_30077 | {
"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": "1 1\n1\n1\n1\n2 1 100\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1216_D. Swords | Solve the following coding problem using the programming language python:
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some sing... | ```python
n= int(input())
s = list(map(int,input().split()))
s.sort()
maxm = s[n-1]
ans = 0
def computeGCD(x, y):
while(y):
x, y = y, x % y
return x
a = maxm-s[0]
for i in range(1,n-1):
a = computeGCD(a,maxm-s[i])
for i in range(0,n-1):
ans += maxm - s[i]
print(ans//a,a)
``` | vfc_30085 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 9\n",
"output": "1 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 12 6\n",
"output": "5 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 1239_E. Turtle | Solve the following coding problem using the programming language python:
Kolya has a turtle and a field of size 2 × n. The field rows are numbered from 1 to 2 from top to bottom, while the columns are numbered from 1 to n from left to right.
Suppose in each cell of the field there is a lettuce leaf. The energy value... | vfc_30089 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 0 1\n0 0 0\n",
"output": "0 0 1 \n1 0 0 ",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1257_G. Divisor Set | Solve the following coding problem using the programming language python:
You are given an integer x represented as a product of n its prime divisors p_1 ⋅ p_2, ⋅ … ⋅ p_n. Let S be the set of all positive integer divisors of x (including 1 and x itself).
We call a set of integers D good if (and only if) there is no p... | vfc_30093 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2999999 43 2999957\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 3 2 3 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": ... | |
code_contests | verifiable_code | 1281_B. Azamon Web Services | Solve the following coding problem using the programming language python:
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough ... | ```python
for _ in range(int(input())):
a,c=input().split()
a=list(a)
b=sorted(a)
if a!=b:
for i,x in enumerate(b):
if a[i]!=x:
tmp=a[i]
a[i]=x
break
for i in range(len(a)-1,-1,-1):
if a[i]==x:
a[i]=t... | vfc_30097 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nAZAMON APPLE\nAZAMON AAAAAAAAAAALIBABA\nAPPLE BANANA\n",
"output": "AAZMON\n---\nAEPLP\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nAZAMON APPLE\nAZAMON AAAAAAAAAAALIBABA\nAPPLE B... |
code_contests | verifiable_code | 1301_B. Motarack's Birthday | Solve the following coding problem using the programming language python:
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows tha... | ```python
# import sys
# file = open('test1')
# sys.stdin = file
def ii(): return int(input())
def ai(): return list(map(int, input().split()))
def mi(): return map(int, input().split())
for _ in range(int(input())):
n = ii()
lst = ai()
nlst = []
for ind, ele in enumerate(lst):
if ele==-1:
if ind!=0 and lst[i... | vfc_30101 | {
"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\n5\n-1 10 -1 12 -1\n5\n-1 40 35 -1 35\n6\n-1 -1 9 -1 3 -1\n2\n-1 -1\n2\n0 -1\n4\n1 -1 3 -1\n7\n1 -1 7 5 2 -1 5\n",
"output": "1 11\n5 37\n3 6\n0 0\n0 0\n1 2\n3 4\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1366_A. Shovels and Swords | Solve the following coding problem using the programming language python:
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamo... | ```python
import math
t=int(input())
for i in range(t):
a,b=map(int,input().split())
m=min(a,b,(a+b)/3)
print(math.floor(m))
``` | vfc_30113 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 4\n1000000000 0\n7 15\n8 7\n",
"output": "2\n0\n7\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n656 656\n",
"output": "437\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1386_A. Colors | Solve the following coding problem using the programming language python:
Linda likes to change her hair color from time to time, and would be pleased if her boyfriend Archie would notice the difference between the previous and the new color. Archie always comments on Linda's hair color if and only if he notices a dif... | vfc_30117 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n\n7\n\n1\n\n1\n\n0\n\n0\n\n1\n",
"output": "? 3\n? 6\n? 5\n? 7\n= 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "46\n63 1\n63 63\n123 1\n123 123\n63 2\n63 62\n123 2\n123 122\n63 3\n6... | |
code_contests | verifiable_code | 1428_D. Bouncing Boomerangs | Solve the following coding problem using the programming language python:
To improve the boomerang throwing skills of the animals, Zookeeper has set up an n × n grid with some targets, where each row and each column has at most 2 targets each. The rows are numbered from 1 to n from top to bottom, and the columns are n... | ```python
n, *a = map(int, open(0).read().split())
now = 1
heights = [[] for _ in range(n)]
st0 = []
st1 = []
failed = False
for i in range(n - 1, -1, -1):
if a[i] == 1:
heights[i].append(now)
st0.append((now, i))
now += 1
elif a[i] == 2:
if len(st0):
h, j = st0.pop()... | vfc_30125 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n0\n",
"output": "0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 0 3 0 1 1\n",
"output": "5\n6 6\n5 5\n4 3\n4 5\n6 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1451_D. Circle Game | Solve the following coding problem using the programming language python:
Utkarsh is forced to play yet another one of Ashish's games. The game progresses turn by turn and as usual, Ashish moves first.
Consider the 2D plane. There is a token which is initially at (0,0). In one move a player must increase either the x... | ```python
import sys
input = lambda:sys.stdin.readline().strip()
t = int(input())
while t:
t-=1
d,k = map(int,input().split())
x = 0
y = 0
while 1:
if x<=y and (x+k)*(x+k)+y*y<=d*d:
x+=k
elif x>y and (y+k)*(y+k)+x*x<=d*d:
y+=k
else:
brea... | vfc_30129 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 1\n5 2\n10 3\n25 4\n15441 33\n",
"output": "\nUtkarsh\nAshish\nUtkarsh\nUtkarsh\nAshish\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 1\n5 2\n10 3\n25 4\n25479 33\n",
"ou... |
code_contests | verifiable_code | 1500_B. Two chandeliers | Solve the following coding problem using the programming language python:
Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he or... | ```python
def main():
n, m, k = list(map(lambda x: int(x), str(input()).split(' ')))
a = list(map(lambda x: int(x), str(input()).split(' ')))
b = list(map(lambda x: int(x), str(input()).split(' ')))
if n < m:
print(solve(m, n, k, b, a))
return
print(solve(n, m, k, a, b))
def solve(n... | vfc_30137 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 8 41\n1 3 2\n1 6 4 3 5 7 2 8\n",
"output": "\n47\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 31\n1\n1 2\n",
"output": "\n62\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1525_D. Armchairs | Solve the following coding problem using the programming language python:
There are n armchairs, numbered from 1 to n from left to right. Some armchairs are occupied by people (at most one person per armchair), others are not. The number of occupied armchairs is not greater than n/2.
For some reason, you would like t... | ```python
import sys
input = sys.stdin.buffer.readline
import math
n=int(input())
arr=[int(x) for x in input().split()]
h=[]
v=[]
for i in range(n):
if arr[i]:
v.append(i)
else:
h.append(i)
hh=len(h)
vv=len(v)
dp=[[0 for j in range(hh+1)] for i in range(vv+1)]
for i in range(1,vv+1):
dp... | vfc_30141 | {
"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\n1 1 1 0 0 0\n",
"output": "\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0 0 0 0\n",
"output": "\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 157_A. Game Outcome | Solve the following coding problem using the programming language python:
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains e... | ```python
n = int(input())
r = lambda : list(map(int, input().split()))
arr = []
for i in range(n):
a = r()
arr.append(a)
row = [sum(i) for i in arr]
col = []
for i in range(n):
c = 0
for j in range(n): c+=arr[j][i]
col.append(c)
ans = 0
for i in range(n):
for j in range(n):
if row[... | vfc_30145 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 19_B. Checkout Assistant | Solve the following coding problem using the programming language python:
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is... | ```python
n=int(input())
ar=[float('inf')]*(n+1)
ar[0]=0
for i in range(n):
t,c=map(int,input().split())
for j in range(n-1,-1,-1):
w=min(j+t+1,n)
ar[w]=min(ar[w],ar[j]+c)
print(ar[n])
``` | vfc_30153 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 10\n0 20\n1 5\n1 3\n",
"output": "8",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 223_C. Partial Sums | Solve the following coding problem using the programming language python:
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
1. First we build by the array a an array s of partial sums, consisting of n elements. Element number... | ```python
n, k = map(int, input().split())
num = list(map(int, input().split()))
MOD = 10 ** 9 + 7
cf = [1]
for i in range(1, 2020):
cf.append((cf[-1] * (k + i - 1) * pow(i, MOD - 2, MOD)) % MOD)
ans = [0 for i in range(n)]
for i in range(n):
for j in range(i + 1):
ans[i] = (ans[i] + cf[i - j] * num[j... | vfc_30157 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 0\n3 14 15 92 6\n",
"output": "3 14 15 92 6 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 2 3\n",
"output": "1 3 6 ",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 248_A. Cupboards | Solve the following coding problem using the programming language python:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to... | ```python
k = int(input())
lo=ro=rc=lc=0
for _ in range(k):
n , m = map(int,input().split())
if(n==0):
lo+=1
else:
lc=lc+1
if(m==0):
ro+=1
else :
rc=rc+1
print(min(lo,lc)+min(ro,rc))
``` | vfc_30161 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0\n",
"output": "7\n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 272_B. Dima and Sequence | Solve the following coding problem using the programming language python:
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) ... | ```python
def f(x):
return str(bin(x)).count('1')
n = int(input())
a = list(map(int, input().split()))
ans = [f(x) for x in a]
s = set(ans)
counts = {x:ans.count(x) for x in s}
ans = 0
for i in counts:
ans += (counts[i]*(counts[i]-1))//2
print(ans)
``` | vfc_30165 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 4\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 3 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6... |
code_contests | verifiable_code | 295_D. Greg and Caves | Solve the following coding problem using the programming language python:
Greg has a pad. The pad's screen is an n × m rectangle, each cell can be either black or white. We'll consider the pad rows to be numbered with integers from 1 to n from top to bottom. Similarly, the pad's columns are numbered with integers from... | vfc_30169 | {
"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 5\n",
"output": "451\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n... | |
code_contests | verifiable_code | 319_B. Psychos in a Line | Solve the following coding problem using the programming language python:
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might... | ```python
n, t = int(input()), list(map(int, input().split()))
p, s, r = [0] * n, [0] * n, t[0]
for i in range(n - 1):
j = i + 1
x = t[j]
if x > r: r = x
else:
while t[i] < x: s[j], i = max(s[j], s[i]), p[i]
p[j] = i
s[j] += 1
print(max(s))
# Made By Mostafa_Khaled
`... | vfc_30173 | {
"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\n1 2 3 4 5 6\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 343_B. Alternating Current | Solve the following coding problem using the programming language python:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started e... | ```python
list_inp=input()
stack_jud=[]
for i in list_inp:
if len(stack_jud)>0:
if stack_jud[-1]==i:stack_jud.pop()
else: stack_jud.append(i)
else: stack_jud.append(i)
if stack_jud==[]:print ('Yes')
else:print ('No')
``` | vfc_30177 | {
"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": "-++-\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "++\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 366_D. Dima and Trap Graph | Solve the following coding problem using the programming language python:
Dima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal...
Dima constructed a trap graph. He shout... | ```python
import sys
sys.setrecursionlimit(100000)
def dfs(v, l, r, mark):
if v == n - 1:
return True
mark[v] = True
for u, e in graph[v]:
if not mark[u] and edges[e][0] <= l <= r <= edges[e][1]:
if dfs(u, l, r, mark):
return True
return False
n, m = map(... | vfc_30181 | {
"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 4\n1 2 1 10\n2 4 3 5\n1 3 1 5\n2 4 2 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n1 2 1 10\n2 5 11 20\n1 4 2 5\n1 3 10 11\n3 4 12 10000\n4 5 6 6\n",
"out... |
code_contests | verifiable_code | 38_C. Blinds | Solve the following coding problem using the programming language python:
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is... | ```python
m, l = map(int, input().split())
a = list(map(int, input().split()))
print(max(i * sum(ai // i for ai in a) for i in range(l, 101)))
``` | vfc_30185 | {
"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\n5 5 7 3 1\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1 2 3 4\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 40_B. Repaintings | Solve the following coding problem using the programming language python:
A chessboard n × m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly four corner-adjacent squares painted i - ... | ```python
import itertools
import math
n, m = [int(k) for k in input().split()]
x = int(input())
if n-2*(x-1) < 1 or m-2*(x-1) < 1:
print(0)
elif n-2*(x-1) == 1 or m-2*(x-1) == 1:
print((n+m-4*(x-1))//2)
else: print(n+m-2 - 4*(x-1))
``` | vfc_30189 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3... |
code_contests | verifiable_code | 438_A. The Child and Toy | Solve the following coding problem using the programming language python:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by a... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.rea... | vfc_30193 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"output": "400\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"output": "40\n",
"type": "stdin... |
code_contests | verifiable_code | 45_H. Road Problem | Solve the following coding problem using the programming language python:
The Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several... | ```python
import sys
import threading
def main():
p = input().split()
n = int(p[0]) #number of locations
m = int(p[1]) #number of passages
if n==1: #if there's only one location, there's nothing to do
print(0)
return
if n==2: #if there's only two nodes, the only edge between ... | vfc_30197 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 2\n2 3\n2 4\n3 4\n",
"output": "1\n1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2\n2 3\n3 4\n",
"output": "1\n1 4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 483_B. Friends and Presents | Solve the following coding problem using the programming language python:
You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also mean... | ```python
c1,c2,x,y=map(int,input().split())
def fn(val):
f=[val//x,val//y]
both=val//(x*y)
f=[i-both for i in f]
oth=val-f[0]-f[1]-both
cnt=[c1-f[1],c2-f[0]]
if cnt[0]<0:cnt[0]=0
if cnt[1] < 0: cnt[1] = 0
return (sum(cnt)<=oth)
l=0;r=int(1e18)
while r-l>1:
m=(r+l)//2
if fn(m):
... | vfc_30201 | {
"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 1 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 507_B. Amr and Pins | Solve the following coding problem using the programming language python:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circ... | ```python
import math #.sqrt
def ceil (a, b):
return -(-a // b)
def answer(r, x, y, xp, yp):
d = math.sqrt((xp-x)**2 + (yp-y)**2)
num_rs = ceil(d, 2*r)
return int(num_rs)
def main():
r, x, y, xp, yp = [int(i) for i in input().split()]
print(answer(r, x, y, xp, yp))
return
main()
``` | vfc_30205 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1 4 4\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 530_C. Diophantine equation | Solve the following coding problem using the programming language python:
You are given an equation A * X + B * Y = C, A, B, C are positive integer coefficients, X and Y are variables which can have positive integer values only. Output the number of solutions of this equation and the solutions themselves.
Input
The ... | vfc_30209 | {
"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 5 35\n",
"output": "2\n5 4\n10 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 35 5\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 556_C. Case of Matryoshkas | Solve the following coding problem using the programming language python:
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka... | ```python
n, m = [int(x) for x in input().split()]
a = []
for i in range(m):
a.append([int(x) for x in input().split()][1:])
b = []
curt = 0
for i in a:
j = 0
b.append([])
while (j < len(i)) and (i[j] == (j + 1)):
j += 1
if j != 0:
b[-1] = [j]
b[-1] += [1] * (len(i) - j)
curt... | vfc_30213 | {
"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 2\n2 1 2\n1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 582_A. GCD Table | Solve the following coding problem using the programming language python:
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of b... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write i... | vfc_30217 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n",
"output": "6 4 3 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n42\n",
"output": "42 ",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 604_A. Uncowed Forces | Solve the following coding problem using the programming language python:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowe... | ```python
t=list(map(int,input().split()))
w=list(map(int,input().split()))
q,z=map(int,input().split())
c=0
v=0
for i in range(500,3000,500):
x=(1-(t[v]/250))*i-50*w[v]
a=max(0.3*i,x)
c=c+a
v=v+1
f=q*100-z*50
dp=c+f
print(int(dp))
``` | vfc_30221 | {
"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 40 60 80 100\n0 1 2 3 4\n1 0\n",
"output": "4900\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0\n",
"output": "4930\n",
"type": "stdin_... |
code_contests | verifiable_code | 650_B. Image Preview | Solve the following coding problem using the programming language python:
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Simila... | ```python
def main():
n, a, b, t = map(int, input().split())
b += 1
l = [b if char == "w" else 1 for char in input()]
t -= sum(l) - a * (n + 2)
hi, n2 = n, n * 2
n21 = n2 + 1
lo = res = 0
l *= 2
while lo <= n and hi < n2:
t -= l[hi]
hi += 1
b = hi - n
... | vfc_30229 | {
"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 2 4 13\nhhwhh\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 100 10\nwhw\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 675_E. Trains and Statistic | Solve the following coding problem using the programming language python:
Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.
Let ρi, j be the minimum numbe... | ```python
n=int(input())
a=list(map(int, input().split()))
a=[ai-1 for ai in a]
a[n:n] = [n - 1]
dp=[0]*n
ans=0
i=n-2
nmax=2**17
tree=[[0,0]]*2*nmax;
#Build Segment tree
j=0
while j<n:
tree[nmax + j] = [a[j], j]
j=j+1
j=nmax-1
while j>0:
tree[j]=max(tree[j*2],tree[j*2+1])
j=j-1
#get max of a int... | vfc_30233 | {
"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\n4 4 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 3 5 5\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 699_F. Limak and Shooting Points | Solve the following coding problem using the programming language python:
Bearland is a dangerous place. Limak can’t travel on foot. Instead, he has k magic teleportation stones. Each stone can be used at most once. The i-th stone allows to teleport to a point (axi, ayi). Limak can use stones in any order.
There are ... | vfc_30237 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 8\n10 20\n0 0\n20 40\n300 600\n30 60\n170 340\n50 100\n28 56\n90 180\n-4 -8\n-1 -2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n-2 -1\n4 5\n4 2\n2 1\n4 -1\n1 -1\... | |
code_contests | verifiable_code | 720_C. Homework | Solve the following coding problem using the programming language python:
Today Peter has got an additional homework for tomorrow. The teacher has given three integers to him: n, m and k, and asked him to mark one or more squares on a square grid of size n × m.
The marked squares must form a connected figure, and th... | vfc_30241 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 3 4\n3 3 5\n3 3 3\n",
"output": "***\n*.*\n***\n\n***\n**.\n...\n\n***\n*.*\n**.\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n317 314 18260\n",
"output": "**************... | |
code_contests | verifiable_code | 741_E. Arpa’s abnormal DNA and Mehrdad’s deep interest | Solve the following coding problem using the programming language python:
All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D
Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biol... | vfc_30245 | {
"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": "abbbbbbaaa baababaaab 10\n1 2 1 0 0\n2 7 8 4 7\n2 3 9 2 8\n3 4 6 1 1\n0 8 5 2 4\n2 8 10 4 7\n7 10 1 0 0\n1 4 6 0 2\n0 9 8 0 6\n4 8 5 0 1\n",
"output": "1 4 2 -1 2 4 10 1 1 5\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 765_D. Artsem and Saunders | Solve the following coding problem using the programming language python:
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all it... | ```python
n = int(input())
f = list(map(int, input().split()))
h = []
ind_h = [-1] * (n + 1)
g = [0] * n
occs = {}
for i in range(len(f)):
if f[i] not in occs:
occs[f[i]] = {i + 1}
h.append(f[i])
ind_h[f[i]] = len(h) - 1
g[i] = len(h)
else:
g[i] = ind_h[f[i]] + 1
... | vfc_30249 | {
"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": "3\n1 2 3\n",
"output": "3\n1 2 3 \n1 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 2 2\n",
"output": "1\n1 1 1 \n2 ",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 789_A. Anastasia and pebbles | Solve the following coding problem using the programming language python:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only ... | ```python
import math
n,k = map(int,input().split())
stones = list(map(int, input().split()))
days = 0
for i in range(n):
days += math.ceil(stones[i]/k)
print(math.ceil(days/2))
``` | vfc_30253 | {
"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 4\n3 1 8 9 7\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n2 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 80_C. Heroes | Solve the following coding problem using the programming language python:
The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 1 14:28:37 2019
@author: PC-4
"""
from itertools import combinations, product
Teams = [[1, 1, 5],
[1, 2, 4],
[1, 3, 3],
[2, 2, 3]]
Names = {}
Names["Anka"] = 0
Names["Chapay"] = 1
Names["Cleo"] = 2
Names["Dracul"] = 3
Names["Hexadec... | vfc_30257 | {
"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\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n",
"output": "30 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nAnka likes Chapay\nChapay likes Anka\n... |
code_contests | verifiable_code | 835_A. Key races | Solve the following coding problem using the programming language python:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The secon... | ```python
s, v1, v2, t1, t2 = list(map(int, input().split()))
a = 2*t1 + s*v1
b = 2*t2 + s*v2
if a > b:
print("Second")
elif a < b:
print("First")
else:
print("Friendship")
``` | vfc_30261 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 3 1 5\n",
"output": "Friendship\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 2 1 2\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 855_D. Rowena Ravenclaw's Diadem | Solve the following coding problem using the programming language python:
Harry, upon inquiring Helena Ravenclaw's ghost, came to know that she told Tom Riddle or You-know-who about Rowena Ravenclaw's diadem and that he stole it from her.
Harry thought that Riddle would have assumed that he was the only one to disco... | vfc_30265 | {
"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 -1\n1 0\n2 0\n2\n1 1 3\n2 1 3\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-1 -1\n1 0\n1 1\n2\n2 2 3\n2 3 2\n",
"output": "YES\nNO\n",
"type"... | |
code_contests | verifiable_code | 87_B. Vasya and Types | Solve the following coding problem using the programming language python:
Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To f... | ```python
types = {'void':'void', 'errtype':'errtype'}
def getRealType(type_expr):
expr_type = type_expr.strip('&*')
full_type_name = type_expr.replace(expr_type, types.get(expr_type, "errtype"))
base_type = full_type_name.strip('&*')
if base_type == "void":
addr_count = full_type_name.count('*')
... | vfc_30269 | {
"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": "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&... |
code_contests | verifiable_code | 903_D. Almost Difference | Solve the following coding problem using the programming language python:
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the ... | ```python
from sys import stdin, stdout
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
d = dict()
ans, sm = 0, 0
for i in range(n):
if a[i] not in d.keys():
d[a[i]] = 0
d[a[i]] += 1
ans += i * a[i] - sm
if (a[i] + 1) in d.keys():
ans += 1 * d[a[i] + 1]
if (a... | vfc_30273 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6 6 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 1 3\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 925_E. May Holidays | Solve the following coding problem using the programming language python:
It's May in Flatland, and there are m days in this month. Despite the fact that May Holidays are canceled long time ago, employees of some software company still have a habit of taking short or long vacations in May.
Of course, not all managers... | vfc_30277 | {
"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": "5 6\n1 2 3 4\n4 0 0 1 0\n1 5 2 3 -5 -1\n",
"output": "0 2 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 8\n4 5 1 1 5 5\n0 0 0 1 2 0 0\n2 6 3 7 -2 4 -3 1\n",
"output": "1 1... | |
code_contests | verifiable_code | 954_F. Runner's Problem | Solve the following coding problem using the programming language python:
You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.
You start in (2, 1) and have to end your path in (2, m). From the cel... | ```python
from operator import itemgetter
import sys
input = sys.stdin.buffer.readline
def _mul(A, B, MOD):
C = [[0] * len(B[0]) for i in range(len(A))]
for i in range(len(A)):
for k in range(len(B)):
for j in range(len(B[0])):
C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD
... | vfc_30281 | {
"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": "2 5\n1 3 4\n2 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50 100\n1 71 96\n2 34 52\n2 16 95\n1 54 55\n1 65 85\n1 76 92\n2 19 91\n1 26 43\n2 83 95\n2 70 88\n2 67 88... |
code_contests | verifiable_code | 980_E. The Number Games | Solve the following coding problem using the programming language python:
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to ever... | ```python
import sys
# import time
def calc_result(n, k, edges):
# t1 = time.clock()
storage = [-1] * (4 * n)
storage_index = 0
lookup = [-1] * (n + 1)
for u, v in edges:
storage[storage_index] = lookup[u]
storage[storage_index + 1] = v
lookup[u] = storage_index
st... | vfc_30285 | {
"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": "6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n",
"output": "1 3 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n",
"output": "1 3 4 5 ",
"type": "stdin... |
code_contests | verifiable_code | 9_E. Interesting Graph and Apples | Solve the following coding problem using the programming language python:
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to o... | ```python
def dfs(v, comp):
used[v] = comp
for u in graph[v]:
if not used[u]:
dfs(u, comp)
n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
v, u = map(int, input().split())
graph[v - 1].append(u - 1)
graph[u - 1].append(v - 1)
used = [0] * n
nc... | vfc_30289 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 2\n2 3\n",
"output": "YES\n1\n1 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | bhavanas-and-bhuvanas-bet | Solve the following coding problem using the programming language python:
Bhavana and Bhuvana place bet every time they see something interesting that can occur with a probability 0.5.
Both of them place a bet for a higher amount which they don’t posses at that time. But when one wins she demands other for the bet am... | ```python
from sys import stdin
t=stdin.readline()
a=stdin.readlines()
for i in a:
n = int(i)
cur = 1
ans = 0
while cur<=n:
cur = cur*2
ans+=1
ans-=1
if n==0:
ans = 0
if ans==0:
ans = -2147483648
print ans
``` | vfc_30293 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n10",
"output": "1\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cost-of-data-11 | Solve the following coding problem using the programming language python:
Strings can be efficiently stored as a data structure, to have efficient searching methods.
A new startup is going to use this method, but they don't have much space. So they want to check beforehand how much memory will be required for their da... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
class Node():
def __init__(self,alphabet):
self.value = alphabet
self.children = []
class Trie():
def __init__(self):
self.root = Node("root")
def insertWord(self,w... | vfc_30297 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\net\neq\nbd\nbe\nbdp\n\nSAMPLE",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\neu\neq\nbd\nbe\nbdp\n\nSAMPLE",
"output": "8\n",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | find-the-nth-prime | Solve the following coding problem using the programming language python:
Given the value of n, print the n'th prime number.
Input : A single integer n.
Output : A single number which is the n'th prime number.
Constraints :
1 ≤ n ≤ 1000
SAMPLE INPUT
2
SAMPLE OUTPUT
3
Explanation
The first few prime numbers are:... | ```python
no = input()
c = 0
for pk in range(2,7920):
am = 0
for qd in range(2,(pk/2)+1):
if (pk % qd == 0):
am = 1
break
if (am == 0):
c = c + 1
if(c == no):
print pk
break
``` | vfc_30301 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | insect-colony-2 | Solve the following coding problem using the programming language python:
Yesterday Oz heard a story about insect colony. The specialty of insects is that they splits sometimes i.e an insect of size A can split into two insects of positive integral sizes B and C such that A = B + C. Also sometimes they attack each oth... | ```python
t = int(raw_input())
for i in range(t):
arr = list(map(int,raw_input().split()))
arr = arr[1:]
ans = sum(arr)
if ans%2 == 1:
print 'No'
else:
print 'Yes'
``` | vfc_30305 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 9 17\n1 1\n\nSAMPLE",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n75 995991040 148627929 566366239 458028006 823890903 945174886 530827147 546010999 7207639... |
code_contests | verifiable_code | once-upon-a-time-in-time-land | Solve the following coding problem using the programming language python:
In a mystical TimeLand, a person's health and wealth is measured in terms of time(seconds) left.
Suppose a person there has 24x60x60 = 86400 seconds left, then he would live for another 1 day.
A person dies when his time left becomes 0. Some ti... | ```python
def solve():
n,k=[int(x) for x in raw_input().split()]
nums =[0]
nums.extend( [int(x) for x in raw_input().split()])
for i in xrange(1,1+k+1):
nums[i] = max(nums[i-1],nums[i])
for i in xrange(1+k+1,n+1):
nums[i] = max(nums[i-1],nums[i-k-1]+nums[i])
print nums[n]
def main():
for _ in xran... | vfc_30313 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 1\n1 2 -3 -5 4 6 -3 2 -1 2\n10 2\n1 2 -3 -5 4 6 -3 2 -1 2\n\nSAMPLE",
"output": "12\n10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n16 3\n-334 -500 -169 -724 -478 -358 -962 -... |
code_contests | verifiable_code | rams-love-for-sita-2 | Solve the following coding problem using the programming language python:
Sita loves chocolate and Ram being his boyfriend wants to give Sita as many chocolates as he can. So, he goes to a chocolate store with Rs. N in his pocket. The price of each chocolate is Rs. C. The store offers a discount that for every M wrapp... | ```python
for _ in xrange(input()):
n,c,m=map(int,raw_input().split())
nc=n/c
nw=nc
if nw>=m:
while True:
c=nw/m
nc+=c
nw=nw%m+c
if nw<m:
break
print nc
``` | vfc_30317 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 2 5\n12 4 4\n6 2 2\n\nSAMPLE",
"output": "6\n3\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n10 2 5\n12 4 8\n6 2 2\n\nSAMPLE",
"output": "6\n3\n5\n",
"type": "std... |
code_contests | verifiable_code | simple-prime-factorization | Solve the following coding problem using the programming language python:
Surya loves to play with primes. One day, he asked his friend don to print any number in the form of multiple of prime factors. Help don in solving the problem.
Input
The first line will contain an integer t (1 ≤ t ≤ 10^6) denoting number of t... | ```python
def CheckIfProbablyPrime(x):
return (2 << x - 2) % x
def primes(n):
primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d)
n //= d
d += 1
if n > 1:
primfac.append(n)
return primfac
for i in range(input()):
a=input()
s="... | vfc_30321 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n32\n100\n9085\n\nSAMPLE",
"output": "2^5\n2^2*5^2\n2^0*5^1*23^1*79^1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n999001\n999002\n999003\n999004\n999005\n999006\n999007\n999008\n... |
code_contests | verifiable_code | the-strongest-string-1-1 | Solve the following coding problem using the programming language python:
Maga and Alex are good at string manipulation problems. Just now they have faced a problem related to string. But it is not a standard string problem. They have no idea to solve it. They need your help.
A string is called unique if all characte... | ```python
input()
ans=''
inp=raw_input()
init=0
for j in xrange(ord('z'),ord('a')-1,-1):
a=chr(j)
for k in xrange(init,len(inp)):
if inp[k]==a:
ans+=a
init=k+1
break
print ans
``` | vfc_30325 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nabvzx\n\nSAMPLE",
"output": "zx\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nabvzx\n\nSAMOLE",
"output": "zx\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | p00100 Sale Result | Solve the following coding problem using the programming language python:
There is data on sales of your company. Your task is to write a program which identifies good workers.
The program should read a list of data where each item includes the employee ID i, the amount of sales q and the corresponding unit price p. ... | ```python
while True:
try:
n=int(input())
except:
break
if n==0:
break
data={}
staff=[]
for i in range(n):
spam=list(map(int,input().split()))
if spam[0] in data.keys():
data[spam[0]]+=spam[1]*spam[2]
else:
data[spam[0]]=spa... | vfc_30373 | {
"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": "4\n1001 2000 520\n1002 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0",
"output": "1001\n1003\nNA\n2013",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | p00232 Life Game | Solve the following coding problem using the programming language python:
Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. Fir... | ```python
from heapq import heappush, heappop
def main():
while True:
x, y, z = map(int, input().split())
if x == 0:break
vlst = list(map(int, input().split()))
events = {}
for _ in range(z):
n, e, a = map(int, input().split())
events[n] = (e, a)
que = []
heappush(que, (... | vfc_30377 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 0\n1\n1 2 1\n1\n1 2 100\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0",
"output": "0\n100\n0\n50\n20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | p00610 Cleaning Robot 2 | Solve the following coding problem using the programming language python:
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful.
First, he renovated his house. Once his house had 9 rooms th... | ```python
# AOJ 1024 Cleaning Robot 2.0
# Python3 2018.7.5 bal4u
mv = ((-1,0), (0,1), (1,0), (0,-1))
d2c = {0:'.', 1:'E'}
while True:
n, k = map(int, input().split())
if n == 0: break
k, n1 = k-1, n-1
if (n & 1) or k >= (1<<(n>>1)):
print("No\n")
continue
arr = [[-1 for c in range(n)] for r in range(n)]
for... | vfc_30385 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n2 3\n6 4\n0 0",
"output": "..\n..\n\nNo\n\n..EEEE\n..E..E\nEEE..E\nE..EEE\nE..E..\nEEEE..",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n2 3\n6 4\n0 0",
"output": "No\n\nNo\... |
code_contests | verifiable_code | p00748 Pollock's conjecture | Solve the following coding problem using the programming language python:
The nth triangular number is defined as the sum of the first n positive integers. The nth tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the nth tetrahedral number is equal to n(n+1)(n+2) ⁄ 6.... | ```python
def main():
INIT = 100
query = []
ans = []
while True:
q = int(input())
if q == 0:
break
query.append(q)
MAX = max(query)
table = [INIT] * (MAX + 1)
table[0] = 0
all_item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)]
odd_item = [i for i in all_item if i % 2]
... | vfc_30389 | {
"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": "40\n14\n5\n165\n120\n103\n106\n139\n0",
"output": "2 6\n2 14\n2 5\n1 1\n1 18\n5 35\n4 4\n3 37",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "40\n14\n5\n165\n120\n133\n106\n139\n0",
"o... |
code_contests | verifiable_code | p01150 Eight Princes | Solve the following coding problem using the programming language python:
Once upon a time in a kingdom far, far away, there lived eight princes. Sadly they were on very bad terms so they began to quarrel every time they met.
One day, the princes needed to seat at the same round table as a party was held. Since they ... | vfc_30401 | {
"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\n16\n17\n0",
"output": "0\n0\n685440",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01458 Kth Sentence | Solve the following coding problem using the programming language python:
A student, Kita_masa, is taking an English examination. In this examination, he has to write a sentence of length m.
Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating t... | vfc_30409 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 6\na\naa\nb",
"output": "aba",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 10 2\nhello\nworld",
"output": "helloworld",
"type": "stdin_stdout"
},
{
"fn_name... | |
code_contests | verifiable_code | p01609 One | Solve the following coding problem using the programming language python:
One
Problem Statement
A beautiful mountain range can be seen from the train window.
The window is a rectangle with the coordinates of the lower left corner (0, 0) and the coordinates of the upper right corner (W, H).
N peaks can be seen from t... | vfc_30413 | {
"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": "20 20 2\n-1 10 10\n-2 10 5",
"output": "21.520346288593280",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 100 2\n-2 5 100\n-2 10 100",
"output": "126.921542730127873",
"type"... | |
code_contests | verifiable_code | p01904 Minimum Enclosing Rectangle | Solve the following coding problem using the programming language python:
G: Minimum Enclosing Rectangle-Minimum Enclosing Rectangle-
story
Hello everyone! It's Airi Aiza from the Hachimori Naka Prokon Club. Suddenly, I want everyone to solve the problem that Airi couldn't solve before. I solved the A problem of ICP... | vfc_30421 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "001",
"output": "1.000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "001",... | |
code_contests | verifiable_code | p02042 ABSum | Solve the following coding problem using the programming language python:
problem
Given a sequence $ A $ of length $ N $. You can swap the $ i $ th and $ j $ th ($ 0 \ leq i, j \ leq N-1 $) elements of a sequence up to $ M $ times.
Find the maximum value of $ \ sum_ {i = 0} ^ {N -1} abs (A_i --i) $ in the sequence c... | vfc_30425 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n0 3 2 1 4",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n0 1 2 1 4",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | p02185 Many Decimal Integers | Solve the following coding problem using the programming language python:
D: Many Decimal Integers
problem
Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length.
Consider changing each `?` That exists in T to one of the numbers from 0 to 9 t... | ```python
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline(... | vfc_30429 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "73\n6?",
"output": "645",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "73\n?6",
"output": "252\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "73\... |
code_contests | verifiable_code | bico | Solve the following coding problem using the programming language python:
The much anticipated video game "BiCo Grid" has been released. The rules of "Bico Grid" are very simple.
The game field is a 100x100 matrix, where each cell is either a blocked cell, or a cell with some number of coins. For a regular player the ... | ```python
C = [[0 for x in xrange(100)] for x in xrange(100)]
def dp():
for i in range(100):
for j in range(min(99, i)):
if j == 0 or j == i:
C[i][j] = 1
else:
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
def work(r, c, g):
maxUsed = -1
ans = []
... | vfc_30441 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2 5\n3 3 10\n5 4 7",
"output": "2\n3 2 \n1\n10 \n3\n5 1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 2 5\n3 1 10\n5 4 7",
"output": "2\n3 2 \n1\n10\n3\n5 1 1 \n",
... |
code_contests | verifiable_code | cng | Solve the following coding problem using the programming language python:
In the country of Numberia, there is a city called Primeland. Sherry is one of the rich inhabitants of the city, who likes to collect coins of various denominations. Coins in primeland are little strange , they are only available in prime denomi... | ```python
t=int(raw_input())
for i in range (t):
c,d=map(int,raw_input().split())
print (c*d-c-d)
``` | vfc_30445 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 5\n2 3",
"output": "7\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 7\n2 3",
"output": "11\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | frgtnlng | Solve the following coding problem using the programming language python:
Forgotten languages (also known as extinct languages) are languages that are no longer in use. Such languages were, probably, widely used before and no one could have ever imagined that they will become extinct at some point. Unfortunately, that... | ```python
for i in range(input()):
NK = map(int, raw_input().split())
strings = map(str, raw_input().split())
phrases = []
for j in range(NK[1]):
phrases.append(map(str, raw_input().split()))
for j in strings:
out = "NO"
for k in phrases:
if j in k:
... | vfc_30449 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2\npiygu ezyfo rzotm\n1 piygu\n6 tefwz tefwz piygu ezyfo tefwz piygu\n4 1\nkssdy tjzhy ljzym kegqz\n4 kegqz kegqz kegqz vxvyj",
"output": "YES YES NO\nNO NO NO YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | lowsum | Solve the following coding problem using the programming language python:
The Head Chef is studying the motivation and satisfaction level of his chefs . The motivation and satisfaction of a Chef can be represented as an integer . The Head Chef wants to know the N th smallest sum of one satisfaction value and one mot... | ```python
def solve(a,b,num):
# temp=[w for w in c]
# heapify(temp)
# for i in xrange(num):
# ans=heappop(temp)
# heapify(temp)
# return ans
while(len(a)*len(b)>num):
if len(a)==1 or len(b)==1:
break
if a[-1]>b[-1]:
a.pop()
else:
b.pop()
p=[]
for i in xrange(len(a)):
for j in xrange(len(b))... | vfc_30453 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 1\n1 2 3\n4 5 6\n4",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 1\n1 4 3\n4 5 6\n4",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | prime1 | Solve the following coding problem using the programming language python:
Shridhar wants to generate some prime numbers for his cryptosystem. Help him!
Your task is to generate all prime numbers between two given numbers.
Input
The first line contains t, the number of test cases (less then or equal to 10).
Follow... | ```python
import sys
import math
def prime_gen(n1,n2):
primes = []
notprimes=[0]*(n2-n1+1)
l=int(math.sqrt(n2))
for i in xrange(2,l+1):
j=n1//i
while j*i<=n2:
if j > 1 and j*i >= n1 :
notprimes[j*i-n1] = 1
j=j+1
for i in xrange(n1,n2+1):
... | vfc_30457 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 10\n3 5",
"output": "2\n3\n5\n7\n3\n5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1011_A. Stages | Solve the following coding problem using the programming language python:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of lette... | ```python
n,k = list(map(int,input().split()))
data = sorted(list(input()))
data = list(map(lambda x:ord(x)-ord('a')+1,data))
result = 0
used = 0
idx =0
prev = -2
# print(data)
for d in data:
if d > prev+1:
result+= d
prev = d
used += 1
if used == k:
break
if used < k:
... | vfc_30465 | {
"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 4\nproblem\n",
"output": "34\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1059_A. Cashier | Solve the following coding problem using the programming language python:
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes ... | ```python
n,l,a = map(int,input().split())
b =[]
for i in range(n):
b.append([int(e) for e in input().split()])
ans = 0
for i in range(n-1):
ans += (b[i+1][0] - b[i][1] - b[i][0])//a
if(n > 0):
ans += b[0][0]//a
ans += (l - b[n-1][1] - b[n-1][0])//a
else:
ans += l//a
print(ans)
``` | vfc_30473 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 11 3\n0 1\n1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1080_C. Masha and two friends | Solve the following coding problem using the programming language python:
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be sp... | ```python
def num_sq(x,y,x2,y2):
# b, w
a = (abs(x2-x)+1)
b = (abs(y2-y)+1)
if a % 2 == 0 or b % 2 == 0:
return (a*b // 2, a*b // 2)
if (x+y) % 2 == 0:
num_b = a * b // 2
return (num_b, a * b - num_b)
num_w = a * b // 2
return (a * b - num_w, num_w)
def pt_in(p1, r1, ... | vfc_30477 | {
"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\n2 2\n1 1 2 2\n1 1 2 2\n3 4\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\n",
"output": "0 4\n3 9\n2 3\n8 8\n4 8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 10_B. Cinema Cashier | Solve the following coding problem using the programming language python:
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themse... | ```python
__author__ = 'Darren'
def solve():
n, k = map(int, input().split())
group = map(int, input().split())
available = [[k, 1][:] for _ in range(k+1)]
center = (k + 1) // 2
for m in group:
closest, best_row, best_col = 10000, -1, -1
for row in range(1, k+1):
col = ... | vfc_30481 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2 3 1\n",
"output": "2 2 2\n1 1 2\n3 1 3\n2 1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 1\n",
"output": "1 1 1\n-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1148_C. Crazy Diamond | Solve the following coding problem using the programming language python:
You are given a permutation p of integers from 1 to n, where n is an even number.
Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type:
* take two indices i and j such that 2 ⋅ |i - ... | ```python
n = int(input())
p = [*map(int, input().split())]
p = [i - 1 for i in p]
#print(p)
pos = {}
ans = []
for i, j in enumerate(p):
pos[j] = i
def swap(i, j):
ans.append((i + 1, j + 1))
pos[p[i]], pos[p[j]] = pos[p[j]], pos[p[i]]
p[i], p[j] = p[j], p[i]
def do(i):
j=pos[i]
if j<n//2... | vfc_30489 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1\n",
"output": "1\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 4 1 2\n",
"output": "2\n1 3\n2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 1169_E. And Reachability | Solve the following coding problem using the programming language python:
Toad Pimple has an array of integers a_1, a_2, …, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < … < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 ≤ i < k.
H... | vfc_30493 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 3 0 2 1\n1 3\n2 4\n1 4\n",
"output": "Fou\nShi\nShi\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n300000 300000\n1 2\n",
"output": "Shi\n",
"type": "stdin_stdout"... | |
code_contests | verifiable_code | 1187_G. Gang Up | Solve the following coding problem using the programming language python:
The leader of some very secretive organization has decided to invite all other members to a meeting. All members of the organization live in the same town which can be represented as n crossroads connected by m two-directional streets. The meeti... | vfc_30497 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 4 2 3\n3 2 2 3\n1 2\n2 3\n2 3\n",
"output": "38\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1206_F. Almost All | Solve the following coding problem using the programming language python:
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied:
For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of thi... | ```python
import math
n = int(input())
if n == 1:
print()
else:
edge = [list(map(int, input().split())) for i in range(1, n) ]
g = {}
for x, y in edge:
if x not in g:
g[x] = []
if y not in g:
g[y] = []
g[x].append(y)
g[y].appe... | vfc_30501 | {
"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": "4\n2 4\n2 3\n2 1\n",
"output": "2 4 1\n2 3 2\n2 1 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3\n2 1\n",
"output": "2 3 1\n2 1 2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1249_D1. Too Many Segments (easy version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all... | ```python
import sys
from heapq import *
#sys.stdin = open('in', 'r')
#n = int(input())
n,k = map(int, input().split())
seg = []
for i in range(n):
l, r = map(int, input().split())
seg.append((l, r, i+1))
seg.sort()
c = 0
res = []
i = 0
hmin = []
hmax = []
rem = set()
while i < n:
l,r,si = seg[i]
while ... | vfc_30509 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n",
"output": "3\n4 1 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n",
"output": "3\n7 4 6 ",
... |
code_contests | verifiable_code | 1267_L. Lexicography | Solve the following coding problem using the programming language python:
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it.
At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple... | ```python
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in... | vfc_30513 | {
"difficulty": "19",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 1\nabcabc\n",
"output": "aab\nbcc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 2\nabcdef\n",
"output": "ad\nbc\nef\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1310_B. Double Elimination | Solve the following coding problem using the programming language python:
The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. 2^n teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify th... | vfc_30521 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 3 5 7\n",
"output": "14",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1332_G. No Monotone Triples | Solve the following coding problem using the programming language python:
Given a sequence of integers a of length n, a tuple (i,j,k) is called monotone triples if
* 1 ≤ i<j<k≤ n;
* a_i ≤ a_j ≤ a_k or a_i ≥ a_j ≥ a_k is satisfied.
For example, a=[5,3,4,5], then (2,3,4) is monotone triples for sequence a whi... | ```python
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from operator import itemgetter
import bisect
n,q=map(int,input().split())
A=[-1]+list(map(int,input().split()))
Q=[list(map(int,input().split()))+[i] for i in range(q)]
Q.sort(key=itemgetter(1))
Q_ind=0
ANS1=[-1000,-1000,... | vfc_30525 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\n3 1 4 1 5 9\n1 3\n4 6\n",
"output": "3\n1 2 3 \n0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n448242954 927941687 223935474 107020324 288030870 635970780 444360884 6978476... |
code_contests | verifiable_code | 1373_B. 01 Game | Solve the following coding problem using the programming language python:
Alica and Bob are playing a game.
Initially they have a binary string s consisting of only characters 0 and 1.
Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. D... | ```python
from sys import stdin,stdout
t=int(stdin.readline().strip())
for _ in range(t):
s=stdin.readline().strip()
stdout.write(("NET","DA")[min(s.count('0'),s.count('1')) % 2]+"\n")
``` | vfc_30533 | {
"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\n01\n1111\n0011\n",
"output": "DA\nNET\nNET\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n00000000000\n",
"output": "NET\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 1396_A. Multiples of Length | Solve the following coding problem using the programming language python:
You are given an array a of n integers.
You want to make all elements of a equal to zero by doing the following operation exactly three times:
* Select a segment, for each number in this segment we can add a multiple of len to it, where len ... | ```python
n=int(input());vals=list(map(int,input().split()))
if n>=2:
print(1,n)
ans=[-i*n for i in vals]
print(*ans)
print(2,n)
a1=[i*(n-1) for i in vals[1:n]]
print(*a1)
print(1,1)
print(vals[0]*(n-1))
else:
print(1,1)
print(-vals[0])
print(1,1)
print(0)
print(1,1)
... | vfc_30537 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 2 4\n",
"output": "1 1\n-1\n2 4\n9 6 12\n1 4\n0 -12 -8 -16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n-2\n",
"output": "1 1\n2\n1 1\n0\n1 1\n0\n",
"type": "stdin... |
code_contests | verifiable_code | 141_C. Queue | Solve the following coding problem using the programming language python:
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand i... | ```python
def solve(arr,n):
arr.sort()
names = [x[1] for x in arr]
counts = [x[0] for x in arr]
segments = []
curr_count = counts[0]
curr_len = 0
L = 0
for i in range(n):
if counts[i]==curr_count:
curr_len += 1
else:
segments.append((L,i-1))
... | vfc_30541 | {
"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\nvasya 0\npetya 1\nmanya 3\ndunay 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\na 0\nb 2\nc 0\nd 0\n",
"output": "a 1\nc 3\nd 4\nb 2\n",
"type": "std... |
code_contests | verifiable_code | 1463_B. Find The Array | Solve the following coding problem using the programming language python:
You are given an array [a_1, a_2, ..., a_n] such that 1 ≤ a_i ≤ 10^9. Let S be the sum of all elements of the array a.
Let's call an array b of n integers beautiful if:
* 1 ≤ b_i ≤ 10^9 for each i from 1 to n;
* for every pair of adjacent... | ```python
for _ in range(int(input())):
n = map(int, input().split())
a = list(map(int, input().split()))
c = 1
i = 0
while c <= 1000000000:
d = 2 * c
if c <= a[i] <= d:
print(c, end=" ")
i += 1
d = 1
if i == len(a):
break
... | vfc_30549 | {
"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\n5\n1 2 3 4 5\n2\n4 6\n2\n1 1000000000\n6\n3 4 8 1 2 3\n",
"output": "\n3 3 3 3 3\n3 6\n1 1000000000\n4 4 8 1 3 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n1000000000 500000... |
code_contests | verifiable_code | 148_B. Escape | Solve the following coding problem using the programming language python:
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princ... | ```python
vp = int(input())
vd = int(input())
t = int(input())
f = int(input())
c = int(input())
distance = t * vp
time = t
treasure = 0
if vp == vd:
if t == 0:
print(1)
else:
print(0)
elif vp > vd:
print(0)
else:
while distance < c:
timeadd = distance/(vd - vp)
distance ... | vfc_30553 | {
"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\n2\n1\n1\n10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1\n1\n8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1511_F. Chainword | Solve the following coding problem using the programming language python:
A chainword is a special type of crossword. As most of the crosswords do, it has cells that you put the letters in and some sort of hints to what these letters should be.
The letter cells in a chainword are put in a single row. We will consider... | vfc_30557 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\nababa\nab\na\n",
"output": "\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\nab\ncd\n",
"output": "\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... | |
code_contests | verifiable_code | 1539_D. PriceFixed | Solve the following coding problem using the programming language python:
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store:
* The store has an infinite number of items of eve... | ```python
n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int, input().split())))
arr.sort(key=lambda x:x[1])
# print(arr)
lo, hi = 0, n-1
ans, counter = 0, 0
while lo<=hi:
# print(lo, hi, counter)
to_buy, req = arr[lo]
if counter>=req or to_buy==0:
counter += to_buy
an... | vfc_30561 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 7\n2 8\n1 2\n2 4\n1 8\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 4\n1 3\n1 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 166_A. Rank List | Solve the following coding problem using the programming language python:
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are show... | ```python
n, k = map(int, input().split())
table =[]
table_dic = dict()
for i in range(n):
p, t = map(int, input().split())
table_dic[i + 1] = [p,t]
table.append([p, 50 - t])
ranking = sorted(table, key=lambda table: (table[0], table[1]), reverse=True)
for i in range(n):
ranking[i][1] = 50 - ranking[i... | vfc_30565 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"output": "3\n",
"type": "stdin_st... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.