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 | 733_D. Kostya the Sculptor | Solve the following coding problem using the programming language python:
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble f... | ```python
n = int(input())
data = {}
ans = 0
res = 0
pos = 0
ind = []
for i in range(n):
tmp = sorted(list(map(int, input().split())))
if min(tmp) > ans:
ans = min(tmp)
ind = [i, -1]
t = (tmp[1], tmp[2])
if t in data:
third, _ = data[t]
if min([third + tmp[0], tmp[1], tmp[2]]) > ans:
ans = min([third ... | vfc_42333 | {
"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": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n",
"output": "2\n1 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n",
"output":... |
code_contests | verifiable_code | 757_E. Bash Plays with Functions | Solve the following coding problem using the programming language python:
Bash got tired on his journey to become the greatest Pokemon master. So he decides to take a break and play with functions.
Bash defines a function f0(n), which denotes the number of ways of factoring n into two factors p and q such that gcd(p,... | vfc_42337 | {
"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\n0 30\n1 25\n3 65\n2 5\n4 48\n",
"output": " 8\n 5\n ... | |
code_contests | verifiable_code | 779_B. Weird Rounding | Solve the following coding problem using the programming language python:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k.
In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number... | ```python
n , k = map(int,input().split())
n = list(str(n))
counter = 0
zero_counter = 0
if n.count('0') >= k :
for i in range(len(n)-1 , -1 , -1):
if (n[i] != '0'):
counter += 1
if (n[i] == '0'):
zero_counter += 1
if (zero_counter == k):
break
print(counter)
else:
print(len(n) - 1)
``` | vfc_42341 | {
"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": "10203049 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30020 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | 802_J. Send the Fool Further! (easy) | Solve the following coding problem using the programming language python:
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Sen... | ```python
def dfs(u,cur):
global ans
vis[u]=True
flag=True
for x in vec[u] :
v=x[0]
c=x[1]
if not vis[v] :
dfs(v,cur+c)
flag=False
if flag:
ans=max(cur,ans)
ans=0
vec=[]
vis=[]
i=0
n=int(input())
while(i<n) :
vec.append([])
vis.append(F... | vfc_42345 | {
"difficulty": "16",
"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\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n",
"output": "105\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 4\n0 2 2\n2 3 3\n",
"output": "5\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 825_F. String Compression | Solve the following coding problem using the programming language python:
Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters.
Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely lo... | ```python
def prefix(s):
p = [0]
for i in range(1, len(s)):
j = p[-1]
while j > 0 and s[j] != s[i]:
j = p[j - 1]
if s[i] == s[j]:
j += 1
p.append(j)
return p
s = input()
n = len(s)
ans = [0] * (n + 1)
i = n - 1
while i >= 0:
p = prefix(s[i:])
... | vfc_42349 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "cczabababab\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abcab\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 848_D. Shake It! | Solve the following coding problem using the programming language python:
A never-ending, fast-changing and dream-like world unfolds, as the secret door opens.
A world is an unordered graph G, in whose vertex set V(G) there are two special vertices s(G) and t(G). An initial world has vertex set {s(G), t(G)} and an ed... | ```python
mod = int(1e9 + 7)
n, m = map(int, input().split())
f = [ [0 for i in range(60)] for j in range(60) ]
g = [ [0 for i in range(60)] for j in range(60) ]
s = [ [0 for i in range(60)] for j in range(60) ]
inv = [ 1 ]
f[0][0] = s[0][0] = 1
def pow(x, exp) :
res = 1
for i in range(0, 31) :
if exp ... | vfc_42353 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "31 8\n",
"output": "64921457\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 870_B. Maximum of Maximums of Minimums | Solve the following coding problem using the programming language python:
You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over th... | ```python
I = lambda: map(int, input().split())
_, k = I()
A = list(I())
print(min(A) if k<2 else max(A) if k>2 else max(A[0], A[-1]))
``` | vfc_42357 | {
"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 1\n-4 -5 -3 -2 -1\n",
"output": "-5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n1 2 3 4 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 897_A. Scarborough Fair | Solve the following coding problem using the programming language python:
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows ho... | ```python
_,m=map(int,input().split())
a=input()
for _ in [0]*m:
l,r,b,c=input().split();l=int(l)-1;r=int(r)
a=a[:l]+a[l:r].replace(b,c)+a[r:]
print(a)
``` | vfc_42361 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\nioi\n1 1 i n\n",
"output": "noi\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n",
"output": "gaaak\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 918_B. Radio Station | Solve the following coding problem using the programming language python:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (name... | ```python
a , b = map(int , input().split())
names = dict()
for i in range(a):
x , y = input().split()
names[y] = x
for i in range(b):
com = input()
h = com.split()[-1][:-1]
print(f"{com} #{names[h]}")
``` | vfc_42365 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 940_B. Our Tanya is Crying Out Loud | Solve the following coding problem using the programming language python:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations:
1. Subtract 1 from... | ```python
n = int(input())
k = int(input())
A = int(input())
B = int(input())
ans = 0
if k == 1:
print(A*(n-1))
exit(0)
while n > 1:
subt = (n % k)
ans += A * subt
n -= (n%k)
ans += min(A * (n - (n // k)),B)
n //= k
if n == 0:
ans -= A
print(ans)
``` | vfc_42369 | {
"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": "19\n3\n4\n2\n",
"output": "12\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 967_E. Big Secret | Solve the following coding problem using the programming language python:
Vitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence a_1, …, a_n. In order to not reveal the secret earlier than needed, Vitya encrypted th... | vfc_42373 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4 7 7 12 31 61\n",
"output": "Yes\n4 12 7 31 7 61",
"type": "stdin_stdout"
},
{
"fn_... | |
code_contests | verifiable_code | 993_E. Nikita and Order Statistics | Solve the following coding problem using the programming language python:
Nikita likes tasks on order statistics, for example, he can easily find the k-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number x is the k-th number in... | ```python
from math import pi
from cmath import exp
def fft(a, lgN, rot=1): # rot=-1 for ifft
N = 1<<lgN
assert len(a)==N
rev = [0]*N
for i in range(N):
rev[i] = (rev[i>>1]>>1)+(i&1)*(N>>1)
A = [a[rev[i]] for i in range(N)]
h = 1
while h<N:
w_m = exp((0+1j) * rot * (pi / h))
for k in range(0, ... | vfc_42377 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 3 4 5\n",
"output": "6 5 4 0 0 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 6\n-5 9\n",
"output": "1 2 0 ",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | atul-and-multiplication-2 | Solve the following coding problem using the programming language python:
Atul opens a book store and soon he recives his first bill form his wholeseller. To see the bill is correct or not he try to cross check the bill. since he is weak at mathematics he ask you to sove his problem
P is product Q is quantity of prod... | ```python
def getres(p,q,t):
if p*q == t:
print "YES"
else:
print "NO"
n = int(raw_input())
for mem in range(n):
p,q,t = [ int(x) for x in raw_input().split() ]
getres(p,q,t)
``` | vfc_42381 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1010\n500 600 300000\n550 690 3795\n600 780 4680\n650 870 565500\n700 960 672000\n750 1050 787500\n800 1140 912000\n850 1230 1045500\n900 1320 11880\n950 1410 1339500\n1000 1500 1500088\n1050 1590 1669500\n1100 1680 1848000\n1150 1... |
code_contests | verifiable_code | choclate-weight | Solve the following coding problem using the programming language python:
Raju has a crush on girl of his class. He wanted to become close friend of her so he started trying to impress her. She came to know about raju and she also likes him but she is not ready to tell him about her feelings. She gave him a task,she w... | ```python
T = int(raw_input())
num = map(int,raw_input().split())
N = len(num)
for i in range(N):
for j in range(i + 1, N):
num.append(num[i] + num[j])
N = int(raw_input())
for i in range(N):
j = int(raw_input())
if j in num:
print "I Like You"
else:
print "I Hate You"
``` | vfc_42385 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 2 3 4 1\n4\n10\n4\n2\n12\n\nSAMPLE",
"output": "I Hate You\nI Like You\nI Like You\nI Hate You\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25 \n2145 4578 5124 5689 2145 2354 1254 ... |
code_contests | verifiable_code | dummy-4 | Solve the following coding problem using the programming language python:
Its NU-Tech'15 and participants are pouring in large numbers. Its the first day of the fest and everybody has gathered around the registration desks but are confused on receiving a set of very large numbers on the registration slip. They are lat... | ```python
case = int(raw_input())
lst = []
def num_sum(n):
st = str(n)
ln = len(st)
val = False
total = 0
for i in range(0, ln):
total += int(st[i])
return total
def one_check(num):
val = False
if(len(str(num)) == 1):
val = True
else:
val = False
return val
for i in range(0, case):
num = int(raw_i... | vfc_42389 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n23\n99\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "300\n5971139573113294350599586075339897369686287822672741685186994603372187737481010614584416264654442125... |
code_contests | verifiable_code | guess-the-triangle | Solve the following coding problem using the programming language python:
You are given 3 points - middles of the sides of some triangle. Find coordinates of the triangle vertices.
Input
Input has 3 lines with 2 space-separated reals each - coordinates of the middles of the sides.
Output
Output 3 lines with 2 space... | ```python
x1, y1 = tuple(map(float, raw_input().split()))
x2, y2 = tuple(map(float, raw_input().split()))
x3, y3 = tuple(map(float, raw_input().split()))
X3 = x1+x2-x3; Y3 = y1+y2-y3;
X2 = x1+x3-x2; Y2 = y1+y3-y2;
X1 = x3+x2-x1; Y1 = y3+y2-y1;
out = [[X1, Y1], [X2, Y2], [X3, Y3]]
out.sort()
for i in out:
print "%.4f... | vfc_42393 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5.00 3.00\n4.0 4.0\n5.0 5.000\n\nSAMPLE",
"output": "4.0000 2.0000\n4.0000 6.0000\n6.0000 4.0000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1.0 1.0\n2.0 2.9\n3.0 1.5",
"output":... |
code_contests | verifiable_code | little-vaishnavi-and-plywood-1 | Solve the following coding problem using the programming language python:
Little Vaishnavi is bored during the vacation which is going on. Being the only little girl in the neighbourhood she did not have any one else to play with. Her parents are so strict that they will not let her out of the house even to see what t... | ```python
T=input()
for _ in xrange(T):
[M,K]=map(int,raw_input().split())
ans=0
if(K==0):
print M-1
else:
ans=(K-1)*4 + 5
if(M!=5 and M!=1):
if(K&1==1):
ans+=4-M
elif(K&1==0):
ans+=M-2
else:
if(M==1):
ans=8*K
elif(M==5):
ans=4+8*K
print ans
``` | vfc_42397 | {
"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 3\n1 0\n\nSAMPLE",
"output": "15\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3\n1 0\n\nSAMPLE",
"output": "14\n0\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | mystery-14 | Solve the following coding problem using the programming language python:
Solve the mystery.
Input :
First line contains T - No. of test cases.
For each test case there are two lines.
first line contains N.
Second line contains N space separated integers A[1] to A[N].
Output :
Print answer of the mystery in... | ```python
from sys import stdin
t = int(stdin.readline())
for _ in xrange(t):
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 0
for i in a:
if i%2:
ans += i
print ans
``` | vfc_42401 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n3\n2 2 2\n3\n1 2 3\n5\n2 2 3 3 4\n5\n1 2 3 4 5\n4\n2 4 5 6\n6\n1 2 3 1 2 3\n\nSAMPLE",
"output": "0\n4\n6\n9\n5\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n10\n9 83 61 91 57 ... |
code_contests | verifiable_code | scheduling-of-task | Solve the following coding problem using the programming language python:
You have a long list of tasks that you need to do today. To accomplish task i you need Mi minutes, and the deadline for this task is Di. You need not complete a task at a stretch. You can complete a part of it, switch to another task, and then s... | ```python
import sys
import math
stdin = sys.stdin
Mid= lambda x : ((x[0] + x[1])>>1)
Lowbit = lambda x : (x&(-x))
used = {}
class Task:
def __init__(self , _d , _m , _index):
self.d = int(_d)
self.m = int(_m)
self.index = int(_index)
def __lt__(self , other):
if (self.d == ... | vfc_42409 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 2\n1 1\n4 3\n10 1\n2 1\n\nSAMPLE",
"output": "0\n1\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "65\n55 915\n8 857\n34 492\n48 366\n70 937\n13 552\n118 229\n26 408\n115 122... |
code_contests | verifiable_code | tape-december-easy-easy-medium | Solve the following coding problem using the programming language python:
You are a product engineer and would like to improve the quality of duct tapes that your company manufactures. An entire tape can be represented as a single row of N cells. Each cell has its Stickiness factor, which stands for its ability to sti... | ```python
def solve(n,k,d,l):
ll = [0]*n
p,j = 0,-1
for i in xrange(n):
if l[i] == 0:
if i - j >= k: return -1
else:
p,j = l[i],i
ll[i] = (p,j)
r = 0
t = 0
for i in xrange(k-1): t += l[i]
i = k-1
while i < n:
if i != k-1: t -= l[... | vfc_42413 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 4\n1 1 1 \n\nSAMPLE",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7751 1 22232\n8 5 5 1 8 2 4 6 2 5 6 3 3 4 8 9 2 4 8 1 9 3 2 9 3 7 5 9 3 4 9 7 8 10 7 10 5 2 5 8 1 10 10... |
code_contests | verifiable_code | will-rick-survive-or-not-2 | Solve the following coding problem using the programming language python:
After Governor's attack on prison, Rick found himself surrounded by walkers. They are coming towards him from all sides. Now, suppose Rick have infinite number of bullets with him. Suppose Rick need 1 bullet to kill each walker (yeah he is good ... | ```python
T = int(raw_input());
while T > 0:
T = T-1;
N = int(raw_input());
arr = raw_input().split(' ');
A = map(int, arr);
A.sort();
index = 0;
minute = 1;
myR = 1;
while index < N:
if minute > A[index]:
print 'Goodbye Rick';
print index;
... | vfc_42417 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n2 4 2 5 6\n4\n2 2 2 2\n\nSAMPLE",
"output": "Rick now go and save Carl and Judas\nGoodbye Rick\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\n2 4 2 5 6\n4\n4 2 2 2\n\nSAMPL... |
code_contests | verifiable_code | p00055 Sequence | Solve the following coding problem using the programming language python:
I have a sequence defined as follows:
* All even-numbered terms are equal to the previous term multiplied by 2.
* All odd-numbered terms are equal to the previous term divided by 3.
Create a program that reads the first term a of this sequen... | ```python
while True:
try:
a1 = float(input())
lst = [a1]
for i in range(2,11):
if i % 2:
a1 /= 3
lst.append(a1)
else:
a1 *= 2
lst.append(a1)
print(sum(lst))
except EOFError:
break
``` | vfc_42461 | {
"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.0\n2.0\n3.0",
"output": "7.81481481\n15.62962963\n23.44444444",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1.0\n2.0\n3.0275795971873247",
"output": "7.81481481481\n15.6296296296\n... |
code_contests | verifiable_code | p00186 Aizu Chicken | Solve the following coding problem using the programming language python:
In April 2008, Aizuwakamatsu City succeeded in making yakitori with a length of 20 m 85 cm. The chicken used at this time is Aizu local chicken, which is a specialty of Aizu. Aizu local chicken is very delicious, but it is difficult to breed, so... | ```python
def check(mid, b, c1, c2, q1):
if mid + (b - mid * c1) // c2 < q1:
return False
return True
while True:
s = input()
if s == "0":
break
q1, b, c1, c2, q2 = map(int, s.split())
max_aizu = min(b // c1, q2)
if max_aizu <= 0:
print("NA")
continue
if c2 >= c1:
max_norma... | vfc_42465 | {
"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": "48 9297 240 126 32\n20 3010 157 141 7\n30 117002 5680 962 15\n8 1673 1712 190 22\n64 8478 87 54 307\n23 5477 117 92 12\n50 7558 1396 187 17\n279 88677 4522 514 14\n0",
"output": "28 20\n7 13\n15 33\nNA\n97 0\n12 44\nNA\nNA",
... |
code_contests | verifiable_code | p00537 Railroad Trip | Solve the following coding problem using the programming language python:
Railroad Trip
There are N cities in the JOI country, numbered 1, 2, ..., and N, respectively. In addition, there are N − 1 railroads, which are numbered 1, 2, ..., and N − 1, respectively. The railroad i (1 ≤ i ≤ N − 1) connects the city i and ... | ```python
import itertools
def main():
n, m = map(int, input().split())
plst = tuple(map(int, input().split()))
abclst = [tuple(map(int, input().split())) for _ in range(n - 1)]
sec = [0] * n
for pi, pi1 in zip(plst, plst[1:]):
p1, p2 = min(pi, pi1) - 1, max(pi, pi1) - 1
sec[p1] += 1
sec[p2] -... | vfc_42473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 3 2 4\n120 90 100\n110 50 80\n250 70 130",
"output": "550",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 3 2 4\n120 90 100\n110 50 80\n250 70 24",
"output": "444\n",
... |
code_contests | verifiable_code | p00840 Mobile Computing | Solve the following coding problem using the programming language python:
There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful stones on the planet, and the Yaen people love to collect them. They bring the stones back home and make nice mobile arts of them to decorate their ... | ```python
def solve():
from itertools import combinations
from sys import stdin
f_i = stdin
def dfs(base, stones):
key = tuple(stones)
if key in rec:
return set((base + l, base + r) for l, r in rec[key])
edges = set()
positions = set()
fo... | vfc_42481 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1.3\n3\n1\n2\n1\n1.4\n3\n1\n2\n1\n2.0\n3\n1\n2\n1\n1.59\n4\n2\n1\n1\n3\n1.7143\n4\n1\n2\n3\n5",
"output": "-1\n1.3333333333333335\n1.6666666666666667\n1.5833333333333335\n1.7142857142857142",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p01241 Finding the Top RPS Player | Solve the following coding problem using the programming language python:
A company “ACM Foods” is preparing for opening its chain shop in a certain area, but another company “ICPC Pizza” is also planning to set up its branch shop in the same area. In general, two competitive shops gain less incomes if they are locate... | vfc_42493 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n10 5\n15 10\n0 0",
"output": "Case 1: 1\nCase 2: 11\nCase 3: 210",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n10 5\n15 6\n0 0",
"output": "Case 1: 1\nCase 2: 11\nCase 3: 1... | |
code_contests | verifiable_code | p01857 Eggs | Solve the following coding problem using the programming language python:
Problem statement
It was a month ago. Nikunishi, an elementary school student, did not do his summer vacation homework. Therefore, the independent study decided to investigate the strength of the eggs at home.
In this study, we define the stre... | vfc_42509 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 1\n5 2\n1 2",
"output": "5\n3\n1",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01992 Shiritori Compression | Solve the following coding problem using the programming language python:
D: Shiritori Compression
problem
Ebi-chan and Kana-chan did a shiritori. Ebi-chan is looking at the memo of the word that came out in Shiritori.
Ebi-chan wants to remove redundant continuous subsequences from this word sequence w_1, w_2, ...,... | ```python
from collections import deque
N = int(input())
idxs = [deque() for i in range(26)]
def ctoi(c):
return ord(c) - ord('a')
cs = []
for i in range(N):
c = input()[0]
cs.append(c)
ci = ctoi(c)
idxs[ci].append(i)
dp = [i for i in range(N)]
dp[0] = 0
for i in range(N):
c = cs[i]
ci = ... | vfc_42513 | {
"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": "7\nbanana\nat\ntomb\nbus\nsound\ndoes\nsome",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02279 Rooted Trees | Solve the following coding problem using the programming language python:
A graph G = (V, E) is a data structure where V is a finite set of vertices and E is a binary relation on V represented by a set of edges. Fig. 1 illustrates an example of a graph (or graphs).
<image>
Fig. 1
A free tree is a connnected, acyclic... | ```python
import sys
n = int(input())
nodes = [[-1, None, None] for _ in range(n)]
depths = [None for _ in range(n)]
for _ in range(n):
nid, k, *children = list(map(int, sys.stdin.readline().split()))
if k > 0:
nodes[nid][1] = children[0]
children.append(None)
for i in range(k):
cid ... | vfc_42521 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "13\n0 3 1 4 10\n1 2 2 3\n2 0\n3 0\n4 3 5 6 7\n5 0\n6 0\n7 2 8 9\n8 0\n9 0\n10 2 11 12\n11 0\n12 0",
"output": "node 0: parent = -1, depth = 0, root, [1, 4, 10]\nnode 1: parent = 0, depth = 1, internal node, [2, 3]\nnode 2: pa... |
code_contests | verifiable_code | bintour | Solve the following coding problem using the programming language python:
Knights' tournaments were quite popular in the Middle Ages. A lot of boys were dreaming of becoming a knight, while a lot of girls were dreaming of marrying a knight on a white horse.
In this problem we consider one of these tournaments.
Let'... | ```python
import sys
def inverseMod(a, b):
MOD = 1000000009
if a == 1:
return b
div = MOD / a + 1
return inverseMod((a * div) % MOD, (b * div) % MOD)
def solve():
K, MOD = int(raw_input()), 1000000009
if K == 1:
print '2'
print '2'
else:
half = 1<<(K-1)
... | vfc_42529 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2",
"output": "0\n8\n16\n24",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cntsols | Solve the following coding problem using the programming language python:
Little Chief loves math. Most of all, he loves equations. He can solve any equation in the whole world. Recently he found one interesting and easy equation
x1^d+x2^d+x3^d ≡ m (mod N)
Where x1, x2 and x3 are non negative integer numbers.
But, as ... | ```python
def fn():
mod = 1000000007
u,d,m,n = map(int,raw_input().split())
a = []
for i in range(3):
t = []
for j in range(n):
t.append(0)
a.append(t)
for i in range(n):
t1 = pow(i,d,n)
t2 = (u-i)/n + 1
t2 %= mod
... | vfc_42533 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2 3 5\n1 2013 3 31",
"output": "4\n1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | frogv | Solve the following coding problem using the programming language python:
Nobody knows, but N frogs live in Chef's garden.
Now they are siting on the X-axis and want to speak to each other. One frog can send a message to another one if the distance between them is less or equal to K.
Chef knows all P pairs of frogs, ... | ```python
def f(x):
return x[1]
n, k, p= map(int, raw_input().split())
a = map(int, raw_input().split())
l = [] #index, position, max_dist
for i in range(n):
l.append([i, a[i], 0])
l = sorted(l, key = f, reverse = True)
#print l
l[0][2] = l[0][1] + k
for i in range(1,n):
if (l[i-1][1] - l[i][1] <= k):
... | vfc_42537 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 3\n0 3 8 5 12\n1 2\n1 3\n2 5",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 3\n0 3 8 5 12\n1 2\n1 3\n1 5",
"output": "Yes\nYes\nNo\n",
"type"... |
code_contests | verifiable_code | prladdu | Solve the following coding problem using the programming language python:
DevuLand is a very strange place. There are n villages in it. Some of the villages are occupied by dinosaurs while the remaining ones by villagers.
You are given the information of DevuLand
by an array D of size n. If D[i] is non-negative, it ... | ```python
# Devajit Asem
# PRLADDU
t = int(raw_input())
def display(a):
for i in a:
print i,
print
for i in range(t):
n = int(raw_input())
D = map(int,raw_input().split())
c=0
k=0
for i in xrange(n):
c+=D[i]
k+=abs(c)
print k
``` | vfc_42545 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n5 -5\n2\n-5 5\n3\n1 2 -3",
"output": "5\n5\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n5 -5\n2\n-5 5\n3\n1 2 -3",
"output": "5\n5\n4\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | tavisual | Solve the following coding problem using the programming language python:
At the end of a busy day, The Chef and his assistants play a game together. The game is not just for fun but also used to decide who will have to clean the kitchen. The Chef is a Game Master, so his concern is how to manage the game but not how ... | ```python
n=input()
for x in range(n):
b=raw_input()
c=b.split()
for y in range(len(c)):
c[y]=int(c[y])
pos=c[1]
for y in range(c[2]):
d=raw_input()
e,f=d.split()
e=int(e)
f=int(f)
if(e<=pos and f>=pos):
pos=e+f-pos
print pos
``` | vfc_42549 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 2 3\n1 4\n3 5\n1 5",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 2 3\n1 4\n3 5\n0 5",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 1036_D. Vasya and Arrays | Solve the following coding problem using the programming language python:
Vasya has two arrays A and B of lengths n and m, respectively.
He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to t... | ```python
from sys import stdin
input=stdin.readline
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
if sum(a)!=sum(b):
print(-1)
exit()
j,k=0,0
sa,sb=0,0
cnt=0
pa,pb=1,1
while j<n and k<m:
if pa==1:
sa+=a[j]
if pb==1:
sb+=b[k]
if sa==sb:
cnt+=1
... | vfc_42557 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n3\n1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n11 2 3 5 7\n4\n11 7 3 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 1059_C. Sequence Transformation | Solve the following coding problem using the programming language python:
Let's call the following process a transformation of a sequence of length n.
If the sequence is empty, the process ends. Otherwise, append the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) (GCD) of all the ele... | ```python
from math import log2
n = int(input())
if n == 3:
print(1,1,3)
elif n == 1:
print(1)
else:
num = n // 2
num3 = 2 ** int(log2(num)) * 2
num2 = n % 2
print("1 " * (num2 + num),end="")
cur_num = 2
while num > 1:
num2 = num % 2
num //= 2
print((str(cur_num)+... | vfc_42561 | {
"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\n",
"output": "1 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
... |
code_contests | verifiable_code | 1080_E. Sonya and Matrix Beauty | Solve the following coding problem using the programming language python:
Sonya had a birthday recently. She was presented with the matrix of size n× m and consist of lowercase Latin letters. We assume that the rows are numbered by integers from 1 to n from bottom to top, and the columns are numbered from 1 to m from ... | vfc_42565 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3\naba\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\naca\naac\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... | |
code_contests | verifiable_code | 10_D. LCIS | Solve the following coding problem using the programming language python:
This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist ... | ```python
n = int(input())
a = [0] + list(map(int, input().split()))
m = int(input())
b = [0] + list(map(int, input().split()))
d = [[0 for j in range(m+1)] for i in range(n+1)]
prev = [0] * (n+1)
for i in range(1, n+1):
for j in range(1, m+1):
if a[i] == b[j]:
d[i][j] = 1
for k in ... | vfc_42569 | {
"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\n1 2 0 2 1\n3\n1 0 1\n",
"output": "2\n0 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n",
"output": "3\n1 5 6 \n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1121_C. System Testing | Solve the following coding problem using the programming language python:
Vasya likes taking part in Codeforces contests. When a round is over, Vasya follows all submissions in the system testing tab.
There are n solutions, the i-th of them should be tested on a_i tests, testing one solution on one test takes 1 secon... | ```python
n,k = map(int,input().split())
a = list(map(int,input().split()))
caption = 0
tested = [0 for i in range(n)]
interesting = [0 for i in range(n)]
ans = 0
while len(a) != 0:
m = min(a[0:k])
for j in range(m):
for i in range(min(k,len(a))):
tested[i] += 1
a[i] -= 1
... | vfc_42573 | {
"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": "14 5\n48 19 6 9 50 20 3 42 38 43 36 21 44 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n49 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1148_E. Earth Wind and Fire | Solve the following coding problem using the programming language python:
There are n stones arranged on an axis. Initially the i-th stone is located at the coordinate s_i. There may be more than one stone in a single place.
You can perform zero or more operations of the following type:
* take two stones with ind... | ```python
from collections import namedtuple
Stone = namedtuple('Stone', ['s', 'i'])
def debug(*args, **kwargs):
import sys
#print(*args, *('{}={}'.format(k, v) for k, v in kwargs.items()), sep='; ', file=sys.stderr)
def solve(n, s, t):
#debug(s=s, t=t)
s = list(map(lambda s_i: Stone(s_i[1], s_i[0... | vfc_42577 | {
"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": "3\n1 5 10\n3 5 7\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 116_B. Little Pigs and Wolves | Solve the following coding problem using the programming language python:
Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size n × m. Each cell in this grid was either empty, containing one little pig, or containing one wolf.
A little pig and a wolf are adjacent if the ... | ```python
n,m = map(int,input().split())
x,cnt = [],0
for _ in range(n):
s = list(map(str,input()))
for i in s:
x.append(i)
if n==m==1: print(0)
elif n==1 or m==1:
for i in range(len(x)):
if x[i]=='W':
if i==0:
if x[i+1]=='P': x[i+1]='.';cnt+=1
elif i==(len(x)-1):
if x[i-1]=='P': x[i-1]='.';cnt+=1
... | vfc_42581 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\nPPW\nW.P\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\nP.W\n.P.\nW.P\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 1188_A2. Add on a Tree: Revolution | Solve the following coding problem using the programming language python:
Note that this is the second problem of the two similar problems. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.
You are given a tree with n nodes. In the beginning, 0 is writte... | ```python
from sys import*
class solution():
def dfs(self, x, par, adj_arr):
for adj in adj_arr[x]:
if adj != par:
return self.dfs(adj, x, adj_arr)
return x
def get_two_child(self, x, y, adj_arr):
if len(adj_arr[x]) == 1:
return x + 1, x + 1
... | vfc_42585 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 2\n2 3 4\n3 4 10\n3 5 18\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2 6\n1 3 8\n1 4 12\n2 5 2\n2 6 4\n",
"output": "YES\n16\n3 5 3\n4 6 3\n3 4 -3\n... |
code_contests | verifiable_code | 1225_C. p-binary | Solve the following coding problem using the programming language python:
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binary nu... | ```python
if __name__ == '__main__':
n, p = map(int, input().split())
aws = 1
while True:
min_number = aws * ((2**0) + p)
if min_number > n:
aws = -1
break
elif min_number == n:
break
elif bin((n - aws * p)).count('1') <= aws:
b... | vfc_42593 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "24 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "24 -1... |
code_contests | verifiable_code | 1249_E. By Elevator or Stairs? | Solve the following coding problem using the programming language python:
You are planning to buy an apartment in a n-floor building. The floors are numbered from 1 to n from the bottom to the top. At first for each floor you want to know the minimum total time to reach it from the first (the bottom) floor.
Let:
*... | ```python
N = 2*10**5 + 5;
a=[0 for i in range(N)]
b=[0 for i in range(N)]
dp=[[0 for i in range(2)] for i in range(N)]
def main():
n,c=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dp[0][0] = 0
dp[0][1] = c
for i in range(1,n):
dp[i][0] ... | vfc_42597 | {
"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": "10 2\n7 6 18 6 16 18 1 17 17\n6 9 3 10 9 1 10 1 5\n",
"output": "0 7 13 18 24 35 36 37 40 45 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n3 2 3 1 3 3 1 4 1\n1 2 3 4 4 1 2 1 3\n",... |
code_contests | verifiable_code | 1268_B. Domino for Young | Solve the following coding problem using the programming language python:
You are given a Young diagram.
Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1).
<image> Young diagram for a=[3,2,2,2,1].
Your goal is to find the largest number of non-overlapping dominos tha... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def main():
n = int(input())
a = list(map(int,input().split()))
base,su,bl = 0,sum(a),0
for i in range(n):
if not base:
bl += (a[i]+1)//2
else:
bl +=... | vfc_42601 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 2 2 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 1310_D. Tourism | Solve the following coding problem using the programming language python:
Masha lives in a country with n cities numbered from 1 to n. She lives in the city number 1.
There is a direct train route between each pair of distinct cities i and j, where i ≠ j. In total there are n(n-1) distinct routes. Every route has a ... | vfc_42609 | {
"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": "5 8\n0 1 2 2 0\n0 0 1 1 2\n0 1 0 0 0\n2 1 1 0 0\n2 0 1 2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n0 1 1\n2 0 1\n2 2 0\n",
"output": "3\n",
"type"... | |
code_contests | verifiable_code | 1373_D. Maximum Sum on Even Positions | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers. Indices of the array start from zero (i. e. the first element is a_0, the second one is a_1, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that ... | ```python
import sys,random
input=sys.stdin.readline
T=int(input())
for _ in range(T):
n=int(input())
A=list(map(int,input().split()))
'''n=random.randint(1,10)
A=[]
for i in range(n):
A.append(random.randint(1,10))
print(n)
print(*A)'''
B=[]
C=[]
for i in range(0... | vfc_42621 | {
"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\n8\n1 7 3 4 7 6 2 9\n5\n1 2 1 2 1\n10\n7 8 4 5 7 6 8 9 7 3\n4\n3 1 2 1\n",
"output": "26\n5\n37\n5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1396_C. Monster Invaders | Solve the following coding problem using the programming language python:
Ziota found a video game called "Monster Invaders".
Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.
For the sake of simplicity, we only consider two different types of monsters and t... | ```python
import sys;input=sys.stdin.readline
N, a, b, c, k = map(int, input().split())
X = list(map(int, input().split()))
dp = [[10**18]*2 for _ in range(N+1)]
dp[0][0] = 0
R = 10**18
for i in range(N):
dp[i+1][0] = min(dp[i][0] + a*X[i]+c, dp[i][1] + min(a*(X[i]+2), a+b))
dp[i+1][1] = dp[i][0] + min(a*(X[i]+... | vfc_42625 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 4 4 1\n4 5 1 2\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1 3 4 3\n3 2 5 1\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 141_E. Clearing Up | Solve the following coding problem using the programming language python:
After Santa Claus and his assistant Elf delivered all the presents and made all the wishes come true, they returned to the North Pole and found out that it is all covered with snow. Both of them were quite tired and they decided only to remove t... | ```python
class DSU(object):
def __init__(self, n):
self.pnt = [-1] * n
def find(self, x):
pnt = self.pnt
if pnt[x] == -1:
return x
pnt[x] = self.find(pnt[x])
return pnt[x]
def join(self, u, v):
pnt = self.pnt
u = self.find(u)
v =... | vfc_42629 | {
"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": "1 2\n1 1 S\n1 1 M\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2 S\n1 3 M\n2 3 S\n",
"output": "2\n1 2 \n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1438_E. Yurii Can Do Everything | Solve the following coding problem using the programming language python:
Yurii is sure he can do everything. Can he solve this task, though?
He has an array a consisting of n positive integers. Let's call a subarray a[l...r] good if the following conditions are simultaneously satisfied:
* l+1 ≤ r-1, i. e. the su... | ```python
from sys import *
input = stdin.readline
def solve(n, a, t):
ans = 0
for i in range(n):
sum = 0
high1 = a[i].bit_length()-1
for j in range(i+1, n-1):
high2 = a[j+1].bit_length()-1
sum += a[j]
if(sum >= (1<<(high1+1))):
break
if((a[i]^a[j+1]) == sum and (t == 0 or high1 != high2)):
... | vfc_42633 | {
"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": "10\n997230370 58052053 240970544 715275815 250707702 156801523 44100666 64791577 43523002 480196854\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n3 1 2 3 1 2 3 15\n",... |
code_contests | verifiable_code | 1463_D. Pairs | Solve the following coding problem using the programming language python:
You have 2n integers 1, 2, ..., 2n. You have to redistribute these 2n elements into n pairs. After that, you choose x pairs and take minimum elements from them, and from the other n - x pairs, you take maximum elements.
Your goal is to obtain t... | ```python
from collections import deque
def solve():
n = int(input())
a = list(map(int, input().split()))
In_a = [False]*(2*n + 1)
for v in a:
In_a[v] = True
b = []
for v in range(2*n, 0, -1):
if In_a[v] == False:
b.append(v)
def possible(K):
tmpa = a[:... | vfc_42637 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n1\n5\n1 4 5 9 10\n2\n3 4\n",
"output": "\n1\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n1\n5\n1 4 5 9 10\n2\n1 4\n",
"output": "1\n3\n1\n",
"type": "stdin... |
code_contests | verifiable_code | 148_D. Bag of mice | Solve the following coding problem using the programming language python:
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate... | ```python
w,b = list( map(int, input().split()) )
p = []
for i in range(w+1): p.append([0]*(b+1))
for i in range(1,w+1): p[i][0] = 1
for i in range(1,w+1):
for j in range(1,b+1):
p[i][j] = i/(i+j)
if j>=3:
p[i][j] += (j/(i+j)) * ((j-1)/(i+j-1)) * ((j-2)/(i+j-2)) * p[i][j-3]
if j... | vfc_42641 | {
"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 3\n",
"output": "0.500000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n",
"output": "0.658730159\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1512_B. Almost Rectangle | Solve the following coding problem using the programming language python:
There is a square field of size n × n in which two cells are marked. These cells can be in the same row or column.
You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.
For examp... | ```python
for _ in range(int(input())):
n=int(input())
l=[]
r1=-1
c1=-1
c2=-1
r2=-1
for i in range(n):
s=input()
for j in range(n):
if(s[j]=="*"):
if(r1==-1):
r1=i
c1=j
else:
... | vfc_42645 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4\n..*.\n....\n*...\n....\n2\n*.\n.*\n2\n.*\n.*\n3\n*.*\n...\n...\n5\n.....\n..*..\n.....\n.*...\n.....\n4\n....\n....\n*...\n*...\n",
"output": "\n*.*.\n....\n*.*.\n....\n**\n**\n**\n**\n*.*\n*.*\n...\n.....\n.**..\n........ |
code_contests | verifiable_code | 1539_F. Strange Array | Solve the following coding problem using the programming language python:
Vasya has an array of n integers a_1, a_2, …, a_n. Vasya thinks that all numbers in his array are strange for some reason. To calculate how strange the i-th number is, Vasya created the following algorithm.
He chooses a subsegment a_l, a_{l+1},... | vfc_42649 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n3 6 5 6 2 1 3\n",
"output": "2 3 1 3 2 3 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 4 3 2 1\n",
"output": "2 1 1 2 2 \n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 166_C. Median | Solve the following coding problem using the programming language python:
A median in an array with the length of n is an element which occupies position number <image> after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2, 6, 1, 2, 3) is the ... | ```python
n, x = map(int, input().split())
a = list(map(int, input().split()))
ret = 0
if x not in a:
a.append(x)
ret += 1
a.sort()
while a[(len(a) + 1) // 2 - 1] != x:
a.append(x)
a.sort()
ret += 1
print(ret)
``` | vfc_42653 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10\n10 20 30\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 187_D. BRT Contract | Solve the following coding problem using the programming language python:
In the last war of PMP, he defeated all his opponents and advanced to the final round. But after the end of semi-final round evil attacked him from behind and killed him! God bless him.
Before his death, PMP signed a contract with the bus rapi... | vfc_42657 | {
"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 3 2\n5 2\n5\n1\n2\n3\n4\n5\n",
"output": "8\n9\n12\n12\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 7\n10 1 1 8 900000005 1000000000\n3\n1\n10\n1000000000\n",
"output": ... | |
code_contests | verifiable_code | 208_B. Solitaire | Solve the following coding problem using the programming language python:
A boy named Vasya wants to play an old Russian solitaire called "Accordion". In this solitaire, the player must observe the following rules:
* A deck of n cards is carefully shuffled, then all n cards are put on the table in a line from left ... | ```python
n = int(input())
arr = list(input().split())
def evl(c1, c2):
return c1[0] == c2[0] or c1[1] == c2[1]
vt = set()
q = [arr[:]]
while q:
ar = q.pop()
vt.add(''.join(ar))
if len(ar) > 3 and evl(ar[-1], ar[-4]):
tmp = ar[:len(ar) - 1]
tmp[-3] = ar[-1]
if ''.join(tmp) no... | vfc_42661 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3S 2C\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 259_D. Little Elephant and Elections | Solve the following coding problem using the programming language python:
There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.
Political parties find their number in the ballot highly imp... | ```python
from itertools import combinations
from collections import Counter
from math import factorial
def getLuckySubsetCount(mArr, luckySubset):
width = len(mArr)
A = map(lambda x: [0,0,0], range(width))
for i in range(width):
A[i][0] = 8 if not (i in luckySubset) else 2
A[i][1] = len(fi... | vfc_42669 | {
"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": "8\n",
"output": "1440\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "44\n",
... |
code_contests | verifiable_code | 282_D. Yet Another Number Game | Solve the following coding problem using the programming language python:
Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland... | ```python
from math import *
n=int(input())
if n==3:
li=list(map(int,input().split()))
ans=0
flag=0
for i in li:
ans^=i
if ans==0:
print("BitAryo")
else:
print("BitLGM")
elif n==2:
li=list(map(int,input().split()))
li.sort()
phi=(1+sqrt(5))/2
ch=[0]*(785)
... | vfc_42673 | {
"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\n1 1\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 305_C. Ivan and Powers of Two | Solve the following coding problem using the programming language python:
Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers ... | ```python
n = int(input())
a = list(map(int, input().split()))
s = set()
for i in a:
j = i
while j in s:
s.remove(j)
j += 1
s.add(j)
print(max(s)-len(s)+1)
``` | vfc_42677 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 331_B2. Shave Beaver! | Solve the following coding problem using the programming language python:
The Smart Beaver has recently designed and built an innovative nanotechnologic all-purpose beaver mass shaving machine, "Beavershave 5000". Beavershave 5000 can shave beavers by families! How does it work? Very easily!
There are n beavers, each... | vfc_42681 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 4 2 5\n6\n1 1 5\n1 3 4\n2 2 3\n1 1 5\n2 1 5\n1 1 5\n",
"output": "2\n1\n3\n5\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 353_B. Two Heaps | Solve the following coding problem using the programming language python:
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube fro... | ```python
from math import*
from random import*
n = int(input()) * 2
A = list(map(int, input().split()))
amount = [0] * 101
B = []
for i in range(n):
if amount[A[i]] < 2:
amount[A[i]] += 1
B += [(A[i], i)]
B.sort()
x, y = [], []
for i in range(len(B)):
if(i % 2 == 0):
x.append(B[i][1])... | vfc_42685 | {
"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\n10 99\n",
"output": "1\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n13 24 13 45\n",
"output": "4\n1 1 2 2\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 377_C. Captains Mode | Solve the following coding problem using the programming language python:
Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, as the captain of the team, realizes that t... | vfc_42689 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1\n2\np 1\np 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n6 4 5 4 5 5\n4\nb 2\np 1\nb 1\np 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 399_E. Tree and Array | Solve the following coding problem using the programming language python:
User ainta likes trees. This time he is going to make an undirected tree with n vertices numbered by integers from 1 to n. The tree is weighted, so each edge of the tree will have some integer weight.
Also he has an array t: t[1], t[2], ..., t[... | vfc_42693 | {
"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": "7",
"output": "1 4 1\n2 5 1\n3 6 1\n4 5 1\n5 6 3\n6 7 5\n1 2\n2 3\n1 3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 424_A. Squats | Solve the following coding problem using the programming language python:
Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly <image> hamsters to stand up and t... | ```python
n = int(input())
s = str(input())
half = n//2
sit = s.count('x')
stand = s.count('X')
ans = max(sit, stand) - half
t = ans
while ans!=0:
if sit>stand:
temp = s.index('x')
s = s[:temp] + 'X' + s[temp+1:]
sit = sit-1
stand = stand +1
ans = ans -1
else:
tem... | vfc_42697 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nXX\n",
"output": "1\nxX\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\nxXXxXx\n",
"output": "0\nxXXxXx\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 448_D. Multiplication Table | Solve the following coding problem using the programming language python:
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on... | ```python
def main():
from math import sqrt
m, n, k = map(int, input().split())
if n < m:
n, m = m, n
lo, hi = 1, k + 1
while lo + 1 < hi:
mid = (lo + hi) // 2
t = mid - 1
v = min(int(sqrt(t)), m)
tn, tm = (t - 1) // m, t // n
vv = [t // i for i in ran... | vfc_42701 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 4\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10 5\... |
code_contests | verifiable_code | 46_E. Comb | Solve the following coding problem using the programming language python:
Having endured all the hardships, Lara Croft finally found herself in a room with treasures. To her surprise she didn't find golden mountains there. Lara looked around and noticed on the floor a painted table n × m panels in size with integers w... | vfc_42705 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n-1 2\n1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7\n-5 7 0 1 0 -4 4\n9 -4 -1 9 -3 7 2\n7 0 6 5 -1 -5 7\n-8 9 -9 -7 -5 -1 -6\n9 -7 -1 8 -7 6 0\n-7 -3 -1 7 1... | |
code_contests | verifiable_code | 493_A. Vasya and Football | Solve the following coding problem using the programming language python:
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is ... | ```python
home=input()
away=input()
n=int(input())
yellows=set()
reds=set()
s={'h':home,'a':away}
while n:
x=input().split()
time=int(x[0])
team=x[1]
shirt=int(x[2])
card=x[3]
if card=='y':
if (shirt,team) in yellows and (shirt,team) not in reds:#2nd time
print(s[team],shirt,... | vfc_42709 | {
"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": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n",
"output": "MC 25 70\nMC 42 82\nCSKA 13 90\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 516_E. Drazil and His Happy Friends | Solve the following coding problem using the programming language python:
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - ... | ```python
n, m = (int(x) for x in input().split())
happy_boys = [0 for _ in range(n)]
happy_girls = [0 for _ in range(m)]
boys = [int(x) for x in input().split()]
girls = [int(x) for x in input().split()]
if boys[0]:
for i in range(1, len(boys)):
happy_boys[boys[i]] = 1
if girls[0]:
for i in range(1, l... | vfc_42713 | {
"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": "2 3\n1 0\n1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n0\n1 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 543_E. Listening to Music | Solve the following coding problem using the programming language python:
Please note that the memory limit differs from the standard.
You really love to listen to music. During the each of next s days you will listen to exactly m songs from the playlist that consists of exactly n songs. Let's number the songs from t... | vfc_42717 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 1 2 3\n5\n1 1 2\n1 3 2\n1 3 3\n1 3 5\n1 3 1\n",
"output": "2\n0\n2\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n5\n3\n1 1 4\n1 1 5\n1 1 6\n",
"output": "0\n0\n... | |
code_contests | verifiable_code | 570_B. Simple Game | Solve the following coding problem using the programming language python:
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.
Then, by using a random generator they choose a random ... | ```python
n,m = map(int, input().split())
p = [m+int(m<n),m-int(m>1)]
print(p[n-m<=m-1])
``` | vfc_42721 | {
"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\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 591_E. Three States | Solve the following coding problem using the programming language python:
The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was dec... | vfc_42725 | {
"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": "4 5\n11..2\n#..22\n#.323\n.#333",
"output": "2",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 613_C. Necklace | Solve the following coding problem using the programming language python:
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remain... | ```python
from fractions import gcd
from functools import reduce
LETTERS = 'abcdefghijklmnopqrstuvwxyz'
def necklace_odd(a):
oi = next(i for i, ai in enumerate(a) if ai%2)
o = a[oi]
g = reduce(gcd, a)
s = [LETTERS[i] * (a[i]//(2*g)) for i in range(len(a)) if i != oi]
return g, (''.join(s) + (LET... | vfc_42729 | {
"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\n4 2 1\n",
"output": "1\naabcbaa\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n4\n",
"output": "4\naaaa\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 633_C. Spy Syndrome 2 | Solve the following coding problem using the programming language python:
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentence... | ```python
import sys
p = sys.stdin.read().split()
n, t = int(p[0]), p[1][::-1]
d = {q.lower(): q for q in p[3:]}
k, s = 0, []
l = sorted(set(map(len, d)))
while n:
k -= 1
if len(l) + k < 0: k, n = s.pop()
elif n >= l[k] and t[n - l[k]:n] in d:
s.append((k, n))
n -= l[k]
k = 0
print(*... | vfc_42733 | {
"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": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n",
"output": "HI there hello\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\n... |
code_contests | verifiable_code | 661_F. Primes in Interval | Solve the following coding problem using the programming language python:
You are given two integers a and b (a ≤ b). How many prime numbers are there on the interval from a to b, inclusive?
Input
The input contains two integers a and b (2 ≤ a ≤ b ≤ 1 000 000), separated by a single space.
Output
Output a single i... | vfc_42737 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 20\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "23 23\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "271... | |
code_contests | verifiable_code | 686_A. Free Ice Cream | Solve the following coding problem using the programming language python:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the... | ```python
x, y = input().split(" ")
a = x,y
a = list(a)
for i in range(len(a)):
a[i]=int(a[i])
count=0
num =a[1]
for i in range(a[0]):
z,f = input().split(" ")
char=z
inp=int(f)
if char == '+':
num = num + inp
elif char == '-':
num = num - inp
if num < 0:
coun... | vfc_42741 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"output": "22 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n",
"output": "3 2\n",
"type": "stdin_st... |
code_contests | verifiable_code | 708_E. Student's Camp | Solve the following coding problem using the programming language python:
Alex studied well and won the trip to student camp Alushta, located on the seashore.
Unfortunately, it's the period of the strong winds now and there is a chance the camp will be destroyed! Camp building can be represented as the rectangle of ... | vfc_42745 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 2\n1\n",
"output": "937500007\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n3 10\n1\n",
"output": "95964640\n",
"type": "stdin_stdout"
},
{
"fn_name... | |
code_contests | verifiable_code | 730_B. Minimum and Maximum | Solve the following coding problem using the programming language python:
This is an interactive problem. You have to use flush operation right after printing each line. For example, in C++ you should use function fflush(stdout), in Java — System.out.flush(), in Pascal — flush(output) and in Python — sys.stdout.flush(... | ```python
import sys
T = int(input())
def compare(l,r,arr):
print('?',a[l]+1,a[r]+1)
sys.stdout.flush()
res = input()
if (res == '>'): return 1;
else: return 0;
while (T > 0):
T -= 1
Max_a = []
Min_a = []
n = int(input())
a = range(n)
for i in range(int(n/2)):
if... | vfc_42749 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n \n>\n \n3\n \n=\n \n=\n ",
"output": "? 1 2\n! 2 1\n? 1 2\n! 2 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 774_F. Pens And Days Of Week | Solve the following coding problem using the programming language python:
Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.
On every working day (from Monday to Saturday... | ```python
import sys
def Min(x, y):
if x > y:
return y
else:
return x
def Gcd(x, y):
if x == 0:
return y
else:
return Gcd(y % x, x)
def Lcm(x, y):
return x * y // Gcd(x, y)
n = int(input())
a = [int(i) for i in input().split()]
d = [int(0) for i in range(0, n)]
o... | vfc_42757 | {
"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": "5\n5 4 5 4 4\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 799_F. Beautiful fountains rows | Solve the following coding problem using the programming language python:
Butler Ostin wants to show Arkady that rows of odd number of fountains are beautiful, while rows of even number of fountains are not.
The butler wants to show Arkady n gardens. Each garden is a row of m cells, the i-th garden has one fountain i... | vfc_42761 | {
"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": "1 5\n2 4\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6\n2 4\n3 6\n4 4\n",
"output": "19\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 81_A. Plug-in | Solve the following coding problem using the programming language python:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. Fo... | ```python
from collections import deque
def plugin(s):
# stack for characters to check
string_stack = deque()
# input string in a list
arr_s = [c for c in s]
# for each character, append to stack. if
for c in arr_s:
string_stack.append(c)
if len(string_stack) > 1:
... | vfc_42765 | {
"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": "hhoowaaaareyyoouu\n",
"output": "wre\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "reallazy\n",
"output": "rezy\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 845_D. Driving Test | Solve the following coding problem using the programming language python:
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types.
* speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of th... | ```python
n = int(input())
events = []
for i in range(n):
events.append(list(map(lambda s: int(s), input().split())))
max_speeds = []
overtaking_forbidden = 0
current_speed = 0
ignores = 0
for event in events:
if event[0] == 1:
current_speed = event[1]
while max_speeds and current_speed > ... | vfc_42769 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 20\n2\n6\n4\n6\n6\n2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 865_F. Egg Roulette | Solve the following coding problem using the programming language python:
The game of Egg Roulette is played between two players. Initially 2R raw eggs and 2C cooked eggs are placed randomly into a carton. The shells are left on so there is no way to distinguish a raw egg from a cooked egg. One at a time, a player wil... | vfc_42773 | {
"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": "1 1\n??BB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n?BA??B??A???\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 892_A. Greed | Solve the following coding problem using the programming language python:
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first ... | ```python
import sys
sys.setrecursionlimit(100000000)
# def input(): return sys.stdin.readline()[:-1]
def iin(): return int(input())
def impin(): return map(int, input().split())
def irrin(): return [int(x) for x in input().split()]
def imrin(n): return [int(input()) for _ in range(n)]
n = iin()
arr = irrin()
brr = i... | vfc_42777 | {
"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\n4 1 0 3\n5 2 2 3\n",
"output": "yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n6 8 9\n6 10 12\n",
"output": "no\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 914_A. Perfect Squares | Solve the following coding problem using the programming language python:
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.
A number x is said to be a perfect square if there exists an integer y such that x = y2.
Input
The first line contains a single i... | ```python
n = int(input())
a = [int(i) for i in input().split()]
p = []
i = 0
while(True):
p.append(i*i)
i += 1
if(p[-1] > 1000000):
break
m = -99999999
for i in a:
if i not in p:
m = max(i,m)
print(m)
``` | vfc_42781 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1 2 4 8 16 32 64 576\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 936_C. Lock Puzzle | Solve the following coding problem using the programming language python:
Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete log... | ```python
n = int(input())
t = input()[:n]
s = input()[:n]
ops =[]
def shift(k, cur):
if k == 0:
return cur
return cur[:-k-1:-1] + cur [:-k]
def move_to_front(k, curst):
if k == n-1:
ops.append(1)
curst = curst[-1] +curst [:-1]
else:
ops.append(n-1)
ops.appen... | vfc_42785 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nabacbb\nbabcba\n",
"output": "18\n4 1 6 5 1 6 3 1 6 5 1 6 4 1 6 5 1 6 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\naba\nbba\n",
"output": "-1",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 962_A. Equator | Solve the following coding problem using the programming language python:
Polycarp has created his own training plan to prepare for the programming contests. He will train for n days, all days are numbered from 1 to n, beginning from the first.
On the i-th day Polycarp will necessarily solve a_i problems. One evening... | ```python
n=int(input())
l=list(map(int,input().split()))
s=sum(l)/2
#print(s)
i=0;
curr=0
while(curr<s):
curr+=l[i]
i+=1
print(i)
``` | vfc_42789 | {
"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": "6\n2 2 2 2 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 3 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 98_B. Help King | Solve the following coding problem using the programming language python:
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived ... | ```python
from fractions import *
n,L=int(input()),0
while (n%2==0):n,L=n//2,L+1
if (n==1):print('%d/1'%L)
else:
s,t=1,1
for i in range(n):
t=t*2%n
s*=2
if (t==1):
m=i+1
break
r,t,i,ans=s,s*n,L,0
while (r>1):
i,t=i+1,t//2
if (r-t>0):
... | vfc_42793 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "8/3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | andrew-and-wengaluru-city | Solve the following coding problem using the programming language python:
Andrew has recently moved to Wengaluru. He finds this city amazing as all the buildings of the city are of same shape. There are N buildings in a row with no space in between. Buildings may have different heights while width in other two dimensi... | ```python
from collections import *
from heapq import *
from bisect import *
from math import *
mapper=map
mi=int
mf=float
inf=mf('inf')
ri=raw_input
t=mi(ri())
while t>0:
t-=1
n=mi(ri())
arr=mapper(mi, ri().split())
total=0
i=1
start=arr[0]
while i<n:
tmptotal=0
lastmax=i-1
while i<n and arr[i]<start:
... | vfc_42797 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n3 2 1 4 5\n5\n1 2 3 4 5\n\nSAMPLE",
"output": "3\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\n3 4 1 4 5\n5\n1 2 3 4 5\n\nSAMPLE",
"output": "3\n0\n",
"type": ... |
code_contests | verifiable_code | chacha-chaudhary-and-sabu | Solve the following coding problem using the programming language python:
Babu and Sabu are enemies but they fight with each other with the help of the mind games not guns. One day Babu asks Sabu to give the answer for this mathematical query as following:
Let f(m, n) = m^n
But Sabu is little weak in mathematics and... | ```python
#http://ideone.com/bOxFqJ
#http://stackoverflow.com/questions/4223313/finding-abc-mod-m
def totient(n) :
result = 1
p = 2
while p**2 <= n :
if(n%p == 0) :
result *= (p-1)
n /= p
while(n%p == 0) :
result *= p
... | vfc_42801 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 1 2 2 15\n\nSAMPLE",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "243\n0 0 0 0 1\n0 0 0 0 2\n0 0 0 0 3\n0 0 0 1 1\n0 0 0 1 2\n0 0 0 1 3\n0 0 0 2 1\n0 0 0 2 2\n0 0 0 2 3\... |
code_contests | verifiable_code | diedie | Solve the following coding problem using the programming language python:
Link to Russian translation of problem
There are N ants staying at the vertices of the N-regular polygon (one ant at one vertex). At some moment of time all the ants choose one of the edges their vertex is adjacent to and start walking along th... | ```python
t=input()
mod=10**9+7
for _ in xrange(t):
n=input()
print ((2%mod)*pow(pow(2,n,mod),mod-2,mod))%mod
``` | vfc_42805 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n\nSAMPLE",
"output": "250000002\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6\n\nSAMPLE",
"output": "281250002\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | generate-composite-numbers | Solve the following coding problem using the programming language python:
In this problem you will be given a range 'n', and you are supposed to find all composite numbers within that range. Make your program efficient as time limit of the program is set to 1 second. Choose an efficient algorithm to find all the compo... | ```python
limit = 10000
def primes_sieve2(limit):
a = [True] * limit
a[0] = a[1] = False
for (i, isprime) in enumerate(a):
if isprime:
for n in xrange(i*i, limit, i):
a[n] = False
return a
if __name__ == "__main__":
a = primes_sieve2(limit)
n = input()
... | vfc_42809 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n\nSAMPLE",
"output": "4 6 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n\nTAMPLE",
"output": "4 6 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | least-common-multiple | Solve the following coding problem using the programming language python:
Gennady and Artem are discussing solutions of different problems.
Gennady told Artem about a number theory problem he solved the day before.
One of steps to solve the problem was to calculate the least common multiple (LCM) of all integers from ... | ```python
from sys import stdin
import math
import random
def mod(a,b,c):
if b==0:
return 1
if b<=10:
return (a**b)%c
if b%2==1:
return (a*mod(a,b-1,c))%c
x=mod(a,b/2,c)
return (x*x)%c
def check(p):
if p<=1:
return 0
if p==2:
return 1;
if p%2==0:
return 0
count = 5
s=p-1
while s%2==0:
... | vfc_42813 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n\nSAMPLE",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9999999... |
code_contests | verifiable_code | monk-in-the-grass-fields | Solve the following coding problem using the programming language python:
Our code monk, high on excitement after solving the rest of the problems , goes on a trek in the mountains .
On his way, he encounters Janemba, the evil magician! Janemba takes our monk to a poison field and plays a game with him described as ... | ```python
for t in range(0, int(raw_input())):
temp = raw_input().strip().split(' ')
k, n = int(temp.pop()), int(temp.pop())
c = [0]*n
r = [0]*n
sr = [0]*(k+1)
sc = [0]*(k+ 1)
for i in range(0,n):
temp = raw_input().strip().split(' ')
for j in range(0,n):
e = int(temp[j])
c[j] += e
r[i] += e... | vfc_42817 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 1\n1 3\n2 4\n2 2\n1 3\n2 4\n2 3\n1 3\n2 4\n2 4\n1 3\n2 4\n\nSAMPLE",
"output": "3\n8\n14\n22\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | permutations | Solve the following coding problem using the programming language python:
A permutation is a list of K numbers, each between 1 and K (both inclusive), that has no duplicate elements.
Permutation X is lexicographically smaller than Permutation Y if for some i ≤ K:
All of the first i-1 elements of X are equal to fi... | ```python
k = int(raw_input())
p = map(int, raw_input().split(' '))
matrix = []
for _ in range(k):
matrix.append([i == 'Y' for i in raw_input()])
def floyd_warshal(matrix):
k = len(matrix)
for kk in range(k):
for i in range(k):
for j in range(k):
if matrix[i][kk] and ma... | vfc_42821 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2 1\nNYN\nYNY\nNYN\n\nSAMPLE",
"output": "1 2 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4 2 1 3 5\nNNNNY\nNNNYY\nNNNNN\nNYNNY\nYYNYN",
"output": "2 3 1 4 5",
"typ... |
code_contests | verifiable_code | subpalindrome-2 | Solve the following coding problem using the programming language python:
For every string given as input, you need to tell us the number of subsequences of it that are palindromes (need not necessarily be distinct). Note that the empty string is not a palindrome.
SAMPLE INPUT
1
aab
SAMPLE OUTPUT
4
Explanation
th... | ```python
t=input()
paliCount=[[]]
def cPalis(s,i,j):
if j<i: return 0
if i==j: return 1
if paliCount[i][j]: return paliCount[i][j]
su=cPalis(s,i,j-1)
for k in range(i,j+1):
if s[k]==s[j]:
su+=1+cPalis(s,k+1,j-1)
#print k,j,s[k],s[j]
return su
for _ in range(t):
s=raw_input()
n=len(s)
paliCount=[[... | vfc_42829 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\naab\n\nSAMPLE",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nbaa\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | vanya-and-gcd-array | Solve the following coding problem using the programming language python:
Vanya has been studying all day long about sequences and other Complex Mathematical Terms. She thinks she has now become really good at it. So, her friend Vasya decides to test her knowledge and keeps the following challenge it front of her:
V... | ```python
def gcd( a, b ):
if ( a==0 ):
return b
return gcd ( b%a, a )
MOD = 10**9 +7
try:
N = int(raw_input())
A = map(int, raw_input().split())
dp = [[[0]*101 for i in range(101)] for j in range(N)]
dp[0][A[0]][A[0]] = 1
for i in range(1, N):
dp[i][A[i]][A[i]] = 1
for j in range(101):
for ... | vfc_42833 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n\nSAMPLE",
"output": "5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00027 What day is today? | Solve the following coding problem using the programming language python:
Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.
Input
The input is a sequence of datasets. The end... | ```python
days = [31,29,31,30,31,30,31,31,30,31,30,31]
ans = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
while True:
idx = 3
m,d = map(int, input().split())
if m==0: break
print(ans[(idx+sum(days[:m-1])+d-1)%7])
``` | vfc_42877 | {
"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 1\n2 29\n0 0",
"output": "Thursday\nSunday",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n2 26\n0 0",
"output": "Thursday\nThursday\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00158 Collatz's Problem | Solve the following coding problem using the programming language python:
For a positive integer n
* If n is even, divide by 2.
* If n is odd, multiply by 3 and add 1.
If you repeat the above operation, the result will be 1. A problem called "Colatz conjecture" is that repeating this operation for any positive int... | ```python
while 1:
n = int(input())
if n == 0:
break
cnt = 0
while n != 1:
if n % 2 == 0:
n //= 2
else:
n = n * 3 + 1
cnt += 1
print(cnt)
``` | vfc_42881 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10\n0",
"output": "7\n6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00485 Shopping in JOI Kingdom | Solve the following coding problem using the programming language python:
There are N towns in JOI, which are connected by M bidirectional roads. There are shopping malls in K towns, and the people go to one of those towns through the road to shop.
Depending on the location of your home, you may have to travel long d... | ```python
from heapq import heappop as pop
from heapq import heappush as push
INF = 10 ** 18
class edge:
def __init__(self, to, cost):
self.to = to
self.cost = cost
#V, E, r = map(int,input().split())
N, M, K = map(int,input().split())
G = [[] for i in range(N)]
#G[i]...頂点iからの辺list、(行き先、コスト)
d = [INF for... | vfc_42889 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 1\n1 2 1\n2 3 1\n3 1 1\n1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 1\n1 2 1\n2 3 1\n3 1 1\n1",
"output": "2\n",
"type": "stdin_stdout"
},
{
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.