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 | 628_C. Bear and String Distance | Solve the following coding problem using the programming language python:
Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, <image>... | ```python
#import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
alph = 'abcdefghijklmnopqrstuvwxyz'
n,k = map(int, input().split())
s = input()
res = ''
for c in s:
if k > 0:
r = ord('z') - ord(c)
l = ord(c) - ord('a')
if r >= l:
if k >... | vfc_49397 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 26\nbear\n",
"output": "zgar",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 652_D. Nested Segments | Solve the following coding problem using the programming language python:
You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.
Input
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line... | ```python
#!/usr/bin/env python3
from __future__ import division, print_function
import collections
def least_significant_bit(i):
return ((i) & -(i))
class FenwickTree():
def __init__(self, n):
# 1-indexed
self.n = n + 1
self.data = [0,] * self.n
def add(self, index, val... | vfc_49401 | {
"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\n1 8\n2 3\n4 7\n5 6\n",
"output": "3\n0\n1\n0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 678_B. The Same Calendar | Solve the following coding problem using the programming language python:
The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is ... | ```python
y = int(input())
r = 0
def getDays(year):
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
return 366
else:
return 365
days = getDays(y)
while r == 0 or not (r % 7 == 0 and getDays(y) == days):
r += getDays(y)
y += 1
print(y)
``` | vfc_49405 | {
"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": "2000\n",
"output": "2028",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50501\n",
"output": "50507",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 700_B. Connecting Universities | Solve the following coding problem using the programming language python:
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town.
In Treeland there are 2k universities which are located in different towns.
Recently, the presid... | ```python
def bfs(source):
q = [0] * (n + 1);
fa = [-1] * n
l, r = [1] * 2
fa[source] = source
q[1] = source
while l <= r:
x = q[l]
l += 1
for y in e[x]:
if fa[y] == -1:
fa[y] = x
r += 1
q[r] = y
... | vfc_49409 | {
"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": "9 3\n3 2 1 6 5 9\n8 9\n3 2\n2 7\n3 4\n7 6\n4 5\n2 1\n2 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n1 5 6 2\n1 3\n3 2\n4 5\n3 7\n4 3\n4 6\n",
"output": "6\... |
code_contests | verifiable_code | 722_D. Generating Sets | Solve the following coding problem using the programming language python:
You are given a set Y of n distinct positive integers y1, y2, ..., yn.
Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integer... | ```python
from collections import defaultdict
import heapq
pow=[1]
for i in range(30):
pow.append(pow[-1]*2)
n=int(input())
b=list(map(int,input().split()))
d=defaultdict(lambda:0)
for j in b:
d[j]=1
for j in range(n):
b[j]=-b[j]
heapq.heapify(b)
ans=[]
f=1
while(f):
j= -heapq.heappop(b)
can=0
... | vfc_49413 | {
"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": "6\n9 7 13 17 5 11\n",
"output": "1 2 3 4 5 6 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "1 2 3 4 5 \n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 744_B. Hongcow's Game | Solve the following coding problem using the programming language python:
This is an interactive problem. In the interaction section below you will see the information about flushing the output.
In this problem, you will be playing a game with Hongcow. How lucky of you!
Hongcow has a hidden n by n matrix M. Let Mi, ... | ```python
from sys import stdout
def g(k, p):
print(str(k) + '\n' + ' '.join(map(str, p)))
stdout.flush()
n = int(input())
s = [9e9] * n
def f(q):
global s
p = [k + 1 for k, v in enumerate(q) if v]
g(len(p), p)
s = [i if j else min(i, int(k)) for i, j, k in zip(s, q, input().split())]
ret... | vfc_49417 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 0\n0 0",
"output": "1\n1 \n1\n2 \n-1\n0 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 0\n2 7 0\n0 0 4\n3 0 8\n0 5 4",
"output": "2\n1 3 \n1\n2 \n2\n1 2 \n1\n3 \n-1\n2 ... |
code_contests | verifiable_code | 767_D. Cartons of milk | Solve the following coding problem using the programming language python:
Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after which you can't drink it (you still can drink it ... | ```python
import sys, collections
raw_input = sys.stdin.readline
n, m, k = map(int, raw_input().split())
current = map(int, raw_input().split())
store = map(int, raw_input().split())
milk = [0]*(10**7 + 1)
store_indexes = collections.defaultdict(list)
current.sort()
max_index = 10**7 + 1
valid = True
ans = []
count = ... | vfc_49421 | {
"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 1 2\n0 0 0\n1\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 837_G. Functions On The Segments | Solve the following coding problem using the programming language python:
You have an array f of n functions.The function fi(x) (1 ≤ i ≤ n) is characterized by parameters: x1, x2, y1, a, b, y2 and take values:
* y1, if x ≤ x1.
* a·x + b, if x1 < x ≤ x2.
* y2, if x > x2.
There are m queries. Each query is... | vfc_49433 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 2 1 4 5 10\n1\n1 1 2\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5\n",
"output": "19\n17\n1... | |
code_contests | verifiable_code | 858_C. Did you mean... | Solve the following coding problem using the programming language python:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from ... | ```python
s = input()
res = []
l = 0
for r in range(2, len(s)):
if r - l >= 2 and not any(c in 'aeiou' for c in s[r - 2:r + 1]) and s[r - 2:r + 1].count(s[r]) < 3:
res.append(s[l:r])
l = r
res.append(s[l:])
print(' '.join(res))
``` | vfc_49437 | {
"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": "abacaba\n",
"output": "abacaba\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 883_I. Photo Processing | Solve the following coding problem using the programming language python:
Evlampiy has found one more cool application to process photos. However the application has certain limitations.
Each photo i has a contrast vi. In order for the processing to be truly of high quality, the application must receive at least k ph... | ```python
from bisect import bisect_left, bisect_right
class Result:
def __init__(self, index, value):
self.index = index
self.value = value
class BinarySearch:
def __init__(self):
pass
@staticmethod
def greater_than(num: int, func, size: int = 1):
"""Searches for sm... | vfc_49441 | {
"difficulty": "15",
"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 2\n50 110 130 40 120\n",
"output": "20",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 928_A. Login Verification | Solve the following coding problem using the programming language python:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and u... | ```python
def f(s):
return s.lower().replace('1', 'l').replace('0', 'o').replace('i', 'l')
s = f(input())
n = int(input())
l = {f(input()) for _ in range(n)}
print('No' if s in l else 'Yes')
``` | vfc_49449 | {
"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": "000\n3\n00\nooA\noOo\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1_wat\n2\n2_wat\nwat_1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 957_C. Three-level Laser | Solve the following coding problem using the programming language python:
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k a... | ```python
n,u = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 1
f = 1
ma = -1
while not((i==j) and (i==n-1)):
if j<=i:
j+=1
if j < n-1:
if a[j+1]-a[i] <= u:
j+=1
else:
if j-i >= 2:
f=0
#print(i,j)
... | vfc_49453 | {
"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": "10 8\n10 13 15 16 17 19 20 22 24 25\n",
"output": "0.8750000000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 982_C. Cut 'em all! | Solve the following coding problem using the programming language python:
You're given a tree with n vertices.
Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
Input
The first line contains an integer n ... | ```python
from collections import defaultdict
import threading
from sys import stdin,setrecursionlimit
setrecursionlimit(300000)
input=stdin.readline
def dfs(node,g,par,sz):
for i in g[node]:
if i!=par:
sz[node]+=dfs(i,g,node,sz)
return sz[node]+1
def main():
n=int(input())
if n%2!=0:
print(-1)
exit(0)
... | vfc_49457 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 4\n4 1\n3 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | a-conversion-2 | Solve the following coding problem using the programming language python:
Again a simple task from Oz! He has given you two strings STR1 and STR2. Each character of both strings is from the set {A, B, C, D, E, F, G, H, I, J}. You can perform 3 types of conversions on string STR1 :
Replace a character(except 'J') by ne... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def solution(s1, s2, i):
if i == len(s2):
return 0
mop = abs(s2[i] - s1[i]) + solution(s1, s2, i + 1)
for x in xrange(i + 1, len(s1)):
s1[i], s1[x] = s1[x], s1[i]
mop... | vfc_49461 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\nBC\nDA\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | binomial-coefficient-1 | Solve the following coding problem using the programming language python:
Our hero - Maga has been working on a research related to Pascal’s Triangle for about a month. He has recently found a new problematic thing for his research. He has to calculate a big number. But he is very busy. Could you do it for him?
You a... | ```python
import sys
f = sys.stdin
mod = 1000000007
def inv(x,y):
res = 1
while y:
if y%2:
res = res*x%mod
y/=2
x=x*x%mod
return res
a,b,n,k = [int(x) for x in f.readline().split()]
num = 1
deno = 1
for i in range(1,n+1):
num = num*i%mod
for i in range(1,k+1):
deno = deno*i%mod
num = num*a%mod
for i ... | vfc_49465 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 4 2\n\nSAMPLE",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 1 4 2\n\nSAMPLE",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | counting-triangles-4 | Solve the following coding problem using the programming language python:
Abhimanyu simply drew two triangles, as shown in the picture below-
He says this, Level 1 Triangles.
Then he drew two more triangles, as shown in the picture below-
He says this, Level 2 Triangles.
Similarly he defined Level 3, 4, 5, ..., N Tr... | ```python
tests=input()
while(tests>0):
n=input()
print n*8+(n-1)*6
tests=tests-1
``` | vfc_49469 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n\nSAMPLE",
"output": "8\n22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n1000001\n1009001\n1018001\n1027001\n1036001\n1045001\n1054001\n1063001\n1072001\n1081001\n1090001... |
code_contests | verifiable_code | first-6 | Solve the following coding problem using the programming language python:
After a furious battle Pirate Jack won a battle against Captain Luthur. Pirate Jack found a golden chest from Luthur's treasures. But the problem is that Luthur's coders have locked this chest. You have found the function which Luthurs Coders wr... | ```python
word = raw_input()
for i in word:
c = -(ord(i))-1
print c,
``` | vfc_49473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "hack\n\nSAMPLE",
"output": "-105 -98 -100 -108 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | its-all-about-magic | Solve the following coding problem using the programming language python:
Recently Oz has found a magical string consisting of single digit "1". After experimenting on the string, Oz found a weird magical property of the string that is whenever he touches the string then each digit "1" of string changed to digit "0" ... | ```python
t = int(raw_input())
iterations = 0
while iterations < t:
iterations += 1
zeros=0
ones=1
n = int(raw_input())
for i in range(n):
nzeros = ones;
nzeros = nzeros + zeros;
ones = zeros;
zeros = nzeros;
print ones,zeros
``` | vfc_49477 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n\nSAMPLE",
"output": "0 1\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80",
"output":... |
code_contests | verifiable_code | mental-math | Solve the following coding problem using the programming language python:
Mohan and his friends got bore so they decided to play something which help them to improve their Mental Math as exams are near by.So all of them frame their own questions for the game.
But when Mohan asked his question none his friends was abl... | ```python
def _gcd(a, b):
if b==0:
return a
return _gcd(b, a%b)
t = input()
while t>0:
a, b, m, n = map(int, raw_input().split())
a = a-m
b = b-n
print _gcd(a,b)
t-=1
``` | vfc_49481 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n8 4 0 0\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n8 4 1 0\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | ozos-equations-1 | Solve the following coding problem using the programming language python:
Ozo is making a project on mathematical equation given by his teacher, but he want to test the given equation,
whether this equation contain any positive integral root or not. Because if equation does not contain integral root his project will g... | ```python
from sys import stdin;
import math
def dig(u):
total = 0
while u:
total+=u%10
u/=10
return total
def sol(u):
roo = int(math.sqrt(u))
roo+=1;
st = 1
if roo>100:
st = roo-100
# print "root is ",roo, " and we start from ",st
while st<=roo:
if u%st==0:
b = st + dig(st)
if b*st==u:
return... | vfc_49485 | {
"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\n4\n\nSAMPLE",
"output": "1\n-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | rasta-and-tavas | Solve the following coding problem using the programming language python:
Rasta calls a number like a Tavas if and only if 1 ≤ a ≤ n and the sum of all primes (like p) that p | a is exactly equal to k.
He asks you to find the number of Tavases.
Input format
The first and only line of input contains two integers, n a... | ```python
n,k=map(int,raw_input().split())
s=[0]*(n+1)
for i in range(2,n+1):
if(s[i]==0):
for j in xrange(i,n+1,i):
s[j]=s[j]+i
count=0
for i in range(n+1):
if(s[i]==k):
count+=1;
print count
``` | vfc_49489 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20 7\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "28 7\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | sock-scramble | Solve the following coding problem using the programming language python:
1) Rama is late to college as usual. As he went on to pull a pair of socks , he found that the number of socks was odd. Though he had a pair of socks to put on he was curious on finding the socks whose pair was missing. The colours of socks are... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import math
ts=input()
for i in range(ts):
ts1=input()
dat=raw_input().split()
dat=map(int,dat)
z=max(dat)
v=min(dat)
for x in range(v,z+1):
if dat.count(x) is not 0 a... | vfc_49493 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20\n3\n88 7439 88 \n5\n8801 8801 2157 4596 4596 \n3\n1377 5701 1377 \n9\n1860 1860 4126 72 72 6086 6086 7394 7394 \n5\n985 985 9625 1899 1899 \n7\n6013 6013 146 146 7606 3026 7606 \n11\n3973 3973 4322 4322 7112 7112 6404 6404 1250 ... |
code_contests | verifiable_code | tic-tac-toe-numbers-3 | Solve the following coding problem using the programming language python:
Tic-Tac-Toe are three cousins. They are playing a game on Fibonacci numbers. The rule of the game is simple -
If the sum of Non-Fibonacci numbers upto N is prime, Tic wins.
If the sum of Non-Fibonacci numbers upto N is even, Tac wins.
If the sum... | ```python
import math
def ips(n):
s=int(math.sqrt(n))
return (s*s==n)
def isfibo(n):
return ips(5*n*n+4) or ips(5*n*n-4)
def isprime(n):
if n==2 or n==3:
return True
if n<2 or n%2==0:
return False
if n<9:
return True
if n%3==0:
return False
r = int(n**(0.5))
f = 5
while f<=r:
if n%f==0:
return Fa... | vfc_49497 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n91\n12\n135\n7\n66\n\nSAMPLE",
"output": "Tac\nTic\nTac\nTac\nTic\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n461\n957\n567\n344\n648\n861\n133\n115\n631\n126\n172\n413\n349\n54... |
code_contests | verifiable_code | p00112 A Milk Shop | Solve the following coding problem using the programming language python:
Mr. Suzuki has opened a new mobile sales shop for freshly squeezed milk in the Aizu area. It is assumed that all the customers who come to buy that day are already in the store with bottles to take home and will not increase any more. Customers ... | ```python
while True:
inputCount = int(input())
if inputCount == 0:
break
timeList = [int(input()) for item in range(inputCount)]
timeList.sort()
waitTimeList = [0]
for lp in range(inputCount - 1):
waitTime = waitTimeList[-1] + timeList[lp]
waitTimeList.append(waitTi... | vfc_49545 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2\n6\n4\n3\n9\n0",
"output": "31",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2\n6\n4\n6\n9\n0",
"output": "38\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | p00246 Bara-Bara Manju | Solve the following coding problem using the programming language python:
The manager of the Japanese sweets shop Tomogurido in Aizuwakamatsu City is a very skillful craftsman, but he feels a little mood. The buns made by the manager are very delicious, but the size varies depending on the mood at that time.
The stor... | vfc_49549 | {
"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\n4 9 1 3 8\n10\n8 5 3 6 2 1 4 5 4 5\n9\n5 7 3 8 2 9 6 4 1\n0",
"output": "1\n4\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4 9 1 3 8\n10\n8 5 3 6 2 1 4 5 4 5\n9\n5 7 3 8 2 9 6 8 ... | |
code_contests | verifiable_code | p00427 Card Game II | Solve the following coding problem using the programming language python:
Consider the following game. There are k pairs of n cards with numbers from 1 to n written one by one. Shuffle these kn cards well to make piles of k cards and arrange them in a horizontal row. The i-th (k-card) pile from the left of the n piles... | ```python
# AOJ 0504: Card Game II
# Python3 2018.7.1 bal4u
from decimal import *
while True:
n, k, m, r = map(int, input().split())
if n == 0: break
setcontext(Context(prec=r, rounding=ROUND_HALF_UP))
one = Decimal(1)
ans = one/Decimal(n)
if m == 1:
s = 0
for i in range(1, n): s += one/Decimal(i)
ans... | vfc_49553 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 0 5\n3 1 1 3\n2 2 1 3\n0 0 0 0",
"output": "0.50000\n0.833\n1.000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 0 5\n3 1 2 3\n2 2 1 3\n0 0 0 0",
"output": "0.50000\n0.833\n1.... |
code_contests | verifiable_code | p00622 Monster Factory | Solve the following coding problem using the programming language python:
Nantendo Co., Ltd. has released a game software called Packet Monster. This game was intended to catch, raise, and fight monsters, and was a very popular game all over the world.
This game had features not found in traditional games. There are ... | ```python
# AOJ 1036: Monster Factory
# Python3 2018.7.6 bal4u
while True:
in1 = list(input())
if in1[0] == '-': break
in2 = list(input())
out = list(input())
k = in2.pop(0)
ans, f = '', True
while len(in1) or len(in2):
if len(out) and out[0] == k:
k = in1.pop(0)
del out[0]
else:
ans += k
if len... | vfc_49557 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "CBA\ncba\ncCa\nX\nZY\nZ\n-",
"output": "BbA\nXY",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "CBA\ncba\ncCa\nX\nYZ\nZ\n-",
"output": "BbA\nYX\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00766 Patisserie ACM | Solve the following coding problem using the programming language python:
Amber Claes Maes, a patissier, opened her own shop last month. She decided to submit her work to the International Chocolate Patissier Competition to promote her shop, and she was pursuing a recipe of sweet chocolate bars. After thousands of tri... | ```python
from collections import deque
class Dinic:
"""
Dinicのアルゴリズム。最大流問題を解くことができます。
https://tjkendev.github.io/procon-library/python/max_flow/dinic.html
"""
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap):
forward =... | vfc_49561 | {
"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 5\n###.#\n#####\n###..\n4 5\n.#.##\n.####\n####.\n##.#.\n8 8\n.#.#.#.#\n########\n.######.\n########\n.######.\n########\n.######.\n########\n8 8\n.#.#.#.#\n########\n.##.#.#.\n##....##\n.##.###.\n##...###\n.##.###.\n###.#.##\n4 ... |
code_contests | verifiable_code | p00898 Driving an Icosahedral Rover | Solve the following coding problem using the programming language python:
After decades of fruitless efforts, one of the expedition teams of ITO (Intersolar Tourism Organization) finally found a planet that would surely provide one of the best tourist attractions within a ten light-year radius from our solar system. T... | vfc_49565 | {
"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": "0 0 1\n3 5 2\n-4 1 3\n13 -13 2\n-32 15 9\n-50 50 0\n0 0 0",
"output": "6\n10\n9\n30\n47\n100",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 1\n3 5 2\n-4 1 3\n21 -13 2\n-32 15 9\n-50 50 ... | |
code_contests | verifiable_code | p01163 Space Coconut Crab II | Solve the following coding problem using the programming language python:
A space hunter, Ken Marineblue traveled the universe, looking for the space coconut crab. The space coconut crab was a crustacean known to be the largest in the universe. It was said that the space coconut crab had a body of more than 400 meters... | vfc_49573 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n12\n15\n777\n4999\n5000\n0",
"output": "0\n1\n2\n110\n2780\n0",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01301 Crystal Jails | Solve the following coding problem using the programming language python:
Artistic Crystal Manufacture developed products named Crystal Jails. They are cool ornaments forming a rectangular solid. They consist of colorful crystal cubes. There are bright cores on the center of cubes, which are the origin of the name. Th... | vfc_49577 | {
"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 3 5\n3 2 2\n***\n.*.\n\n.*.\n...\n\n3 2 1\n***\n**.\n\n3 1 3\n..*\n\n.**\n\n**.\n\n3 2 2\n..*\n...\n\n***\n..*\n\n3 1 3\n.**\n\n.**\n\n***\n\n3 3 3 2\n3 3 3\n***\n***\n***\n\n***\n*.*\n***\n\n***\n***\n***\n\n1 1 1\n*\n\n3 2 1 ... | |
code_contests | verifiable_code | p01470 Four Arithmetic Operations | Solve the following coding problem using the programming language python:
Problem statement
There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows.
1. $ X_0 = 0 $
2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $... | ```python
m=10000000019
x=0
def mod(x):return (x%m+m)%m
def pow(x,a):
ret=1
while a:
if(a&1):ret=mod(x*ret)
x=mod(x*x)
a>>=1
return ret
for _ in range(int(input())):
o,y=map(int,input().split())
if o==1:x=(x+y)%m
elif o==2:x=(x-y)%m
elif o==3:x=mod(x*y)
else:x=mo... | vfc_49581 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1\n4 2\n2 4\n3 4",
"output": "-14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1\n4 2\n2 4\n3 4",
"output": "-16\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | p01630 B2D | Solve the following coding problem using the programming language python:
Problem Statement
Do you know the data structure called BDD (Binary Decision Diagram)? In recent years, ZDD, which has become a hot topic in the video related to Combinatorial Explosion Sister, is a data structure derived from BDD. This problem... | ```python
def root(x):
if x == par[x]:
return x
par[x] = root(par[x])
return par[x]
def unite(x,y):
x = root(x)
y = root(y)
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
n = int(input())
par = [i for i in r... | vfc_49585 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0000",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n11110101011100110010111100010001",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | p01782 Decoding Ancient Messages | Solve the following coding problem using the programming language python:
Example
Input
3
aab
czc
baa
Output
aac
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import heapq
class edge:
def __init__(self,to,cap,cost,rev):
self.to = to
self.cap = cap
self.cost = cost
self.rev = rev
class min_cost_flow:
INF = 52**60
def __init__(self, n):
self.V = n
self.G = [[] for _ in range(n)]
self.h = [0 for _ i... | vfc_49589 | {
"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": "3\naab\nczc\nbaa",
"output": "aac",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\naab\nccz\nbaa",
"output": "aac\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | p01917 Dance Now! | Solve the following coding problem using the programming language python:
B: Dansunau www --Dance Now!-
story
Last lab life! Daigakuin! !! Dosanko Snow has won 9th place in the event "Master Idol World", which can be said to be the outpost of the biggest competition "Lab Life" where master idols compete. The sharp d... | ```python
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(input())
R = list(map(int,input().split()))
SPC = []
S = []
P = []
C = []
ans = 10**5
for i in range(n):
s,p,c = map(int,input().split())
S.append(s)
P.append(p)
C.append(c)
SPC.append([s,p,c])
you = list(SPC[0])
... | vfc_49593 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 267386880,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n9 8 7 6 5 4 3 2 1\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n9 9 9",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n9 8 7 6 5 4 3 2 1\n1 1 1\n3 2 2\n3 3 3\n... |
code_contests | verifiable_code | p02055 Two Colors Sort | Solve the following coding problem using the programming language python:
D: Two Colors Sort
problem
During the walk, umg found a sequence of length N, P_1, P_2, ..., P_N, which can be made by rearranging 1,2, ..., N.
umg can use mysterious powers to exchange places by choosing two different numbers painted in the ... | ```python
import sys
N, R = map(int, input().split())
if 2*R > N:
R = N - R
P = [0] + list(map(int, input().split()))
L = []
used = [False]*(N+1)
pre = 0
for i in range(1, N+1):
cnt = 0
while not used[i]:
used[i] = True
cnt += 1
i = P[i]
if cnt:
L.append(cnt)
table = [0... | vfc_49597 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 3 2",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 3 2",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | p02197 Twins | Solve the following coding problem using the programming language python:
Twins
square1001 and E869120 are twins.
Please output the one that was born first.
input
No input is given.
output
Output the correct character string on one line.
However, insert a line break at the end.
Output example 1
square1001
... | ```python
print('square1001')
``` | vfc_49601 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02351 RSQ and RAQ | Solve the following coding problem using the programming language python:
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:
* add(s, t, x): add x to as, as+1, ..., at.
* getSum(s, t): report the sum of as, as+1, ..., at.
Note that the initial values of ai (i = 1, ... | ```python
import sys
input = sys.stdin.readline
class LazyPropSegmentTree:
def __init__(self, lst, op, apply, comp, e, identity):
self.n = len(lst)
self.depth = (self.n - 1).bit_length()
self.N = 1 << self.depth
self.op = op # binary operation of elements
self.apply = apply ... | vfc_49605 | {
"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": "4 3\n1 1 4\n0 1 4 1\n1 1 4",
"output": "0\n4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | axr1p3 | Solve the following coding problem using the programming language python:
Yesterday was Anish's birthday. The most interesting gift was definitely the chessboard. Anish quickly learned the rules of chess and started to beat all his peers.
That day night Anish was reading a Book on puzzles and Enigma. He opened the... | ```python
while(1):
try:
x=input()
if((x==1) or (x==0)):
print x
else:
print 2*(x-1)
except:
break;
``` | vfc_49609 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1",
"out... |
code_contests | verifiable_code | cmb02 | Solve the following coding problem using the programming language python:
A positive integer is called a palindrome if its representation in the
decimal system is the same when read from left to right and from right
to left. For a given positive integer K of not more than 5 digits,
write the value of the smalles... | ```python
def palindrome(x):
n = str(x)
str1 = ''
for i in range(len(n)-1,-1,-1):
str1 += n[i]
if str1 == n:
return True
else:
return False
a = input()
for h in range(a):
num = input() + 1
while palindrome(num) != True:
num += 1
print num
``` | vfc_49613 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n808",
"output": "818\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1559",
"output": "1661\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | flow013 | Solve the following coding problem using the programming language python:
Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degress.
Input
The first line contains an integer T, to... | ```python
T = int(raw_input())
for i in range(T):
a = map(int, raw_input().split())
if (a[0]+a[1]+a[2]) == 180 and 0 not in a:
print 'YES'
else:
print 'NO'
``` | vfc_49617 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n30 40 110\n45 45 90\n180 0 0",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 \n30 40 110\n12 45 90\n180 0 0",
"output": "YES\nNO\nNO\n",
"type":... |
code_contests | verifiable_code | lepermut | Solve the following coding problem using the programming language python:
The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ..., N.
He calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of ... | ```python
for t in range(int(raw_input())):
n=int(raw_input())
a=[]
N=map(int,raw_input().split())
add=0
count=0
for i in range(n):
for j in range(i,n):
if N[i]>N[j]:
count+=1
for i in range(n-1):
if N[i]>N[i+1]:
add+=1
if add=... | vfc_49621 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n1\n2\n2 1\n3\n3 2 1\n4\n1 3 2 4",
"output": "YES\nYES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1\n1\n2\n2 1\n3\n3 1 1\n4\n1 3 2 4",
"output": "YES\nYES\nNO\n... |
code_contests | verifiable_code | prayas01 | Solve the following coding problem using the programming language python:
Vicky has great love for gardening and prime numbers. He wants to create a rectangular garden such that the square of the diagonal of the rectangle is a prime number (the diagonal of course can be any real number) and its sides are positive int... | ```python
t=input("")
while t:
t=t-1
a=input("")
if(a==2):
print "YES"
elif(a%4==1):
print "YES"
else:
print "NO"
``` | vfc_49625 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | sweet | Solve the following coding problem using the programming language python:
India celebrates her Republic day on 26th January every year. It is celebrated in every colleges and schools.
While preparing for the celebration in BIT-Deoghar, Lemon Kumar, a student in-charge of the Republic day event, went to buy sweet packe... | ```python
T=input()
for _ in xrange(T):
N,C=map(int,raw_input().split())
A=map(int,raw_input().split())
val,temp=0,0
for x in A:
x-=C
temp=max(0,temp+x)
val=max(temp,val)
print val
``` | vfc_49629 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 5\n1 5 7",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 5\n1 6 7",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 1034_A. Enlarge GCD | Solve the following coding problem using the programming language python:
Mr. F has n positive integers, a_1, a_2, …, a_n.
He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers.
But this problem is too simple for him, so he does not want to d... | ```python
from math import gcd
n = int(input())
l = list(map(int,input().split()))
m = max(l)+1
prime = [0]*(m)
commondivisor = [0]*(m)
def seive():
for i in range(2,m):
if prime[i] == 0:
for j in range(i*2,m,i):
prime[j] = i
for i in range(2,m):
if not prime[i]:
prime[i] = i
gc = l[... | vfc_49637 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6 9 15 30\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1056_F. Write The Contest | Solve the following coding problem using the programming language python:
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i — its difficulty ... | ```python
from math import sqrt
class pro(object):
def __init__(self,dif,sc):
self.dif=dif
self.sc=sc
def __lt__(self,other):
return self.dif>other.dif
T=int(input())
mul=[1]
for i in range(100):
mul.append(mul[i]*10/9)
inf=1000000007
for t in range(T):
n=int(input())
effi,... | vfc_49641 | {
"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": "2\n4\n1.000 31.000\n12 3\n20 6\n30 1\n5 1\n3\n1.000 30.000\n1 10\n10 10\n20 8\n",
"output": "7\n20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n1.000 31.000\n12 3\n20 6\n30 1\n5 1... |
code_contests | verifiable_code | 107_B. Basketball Team | Solve the following coding problem using the programming language python:
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which a... | ```python
from math import lgamma, exp
n, m, h = map(int, input().split())
ds = list(map(int, input().split()))
s, d = sum(ds), ds[h - 1]
if s < n:
print(-1)
elif s + 1 < n + d:
print(1)
else:
print(1 - exp(lgamma(s - d + 1) + lgamma(s - n + 1) - lgamma(s) - lgamma(s - d - n + 2)))
``` | vfc_49645 | {
"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 2 1\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n2 2\n",
"output": "0.6666666666666666666666666667\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 109_A. Lucky Sum of Digits | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly wha... | ```python
n = int(input())
i = 0
j = 0
while n>=0:
if n%7==0:
j = n//7
ans = ['4'] * i + ['7'] * j
print("".join(ans))
break
n-=4
i+=1
else:
print(-1)
``` | vfc_49649 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n"... |
code_contests | verifiable_code | 1120_A. Diana and Liana | Solve the following coding problem using the programming language python:
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.
The work material for the wreaths for all n citizen... | ```python
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e6))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as... | vfc_49653 | {
"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": "7 3 2 2\n1 2 3 3 2 1 2\n2 2\n",
"output": "1\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 4 1 3\n3 2 6 4 1 4 4 7 1 3 3 2 4\n4 3 4\n",
"output": "2\n2\n3\n",
"type": "s... |
code_contests | verifiable_code | 1147_C. Thanos Nim | Solve the following coding problem using the programming language python:
Alice and Bob are playing a game with n piles of stones. It is guaranteed that n is an even number. The i-th pile has a_i stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exa... | ```python
n = int(input())
jog = [int(i) for i in input().split()]
mi = min(jog)
qtd = 0
for i in range(len(jog)):
if(jog[i] == mi):
qtd+=1
if(qtd <= n//2 and qtd!=0):
print("Alice")
else:
print("Bob")
``` | vfc_49657 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 1 4 1\n",
"output": "Alice\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n8 8\n",
"output": "Bob\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1168_D. Anagram Paths | Solve the following coding problem using the programming language python:
Toad Ilya has a rooted binary tree with vertex 1 being the root. A tree is a connected graph without cycles. A tree is rooted if one vertex is selected and called the root. A vertex u is a child of a vertex v if u and v are connected by an edge ... | vfc_49661 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 ?\n1 ?\n2 ?\n3 ?\n4 a\n5 b\n",
"output": "Shi 352\nShi 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 ?\n1 ?\n2 ?\n2 a\n3 b\n2 b\n",
"output": "Shi 351\nShi 1\nFou\n... | |
code_contests | verifiable_code | 1187_A. Stickers and Toys | Solve the following coding problem using the programming language python:
Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total.
Each Kinder Surprise can be one of three types:
* it can contain a single sticker and no toy;
* ... | ```python
for _ in range(int(input())):
n,s,t = map(int,input().split())
print(max(n-s+1,n-t+1))
``` | vfc_49665 | {
"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\n10 5 7\n10 10 10\n2 1 1\n",
"output": "6\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 1\n1000000000 1000000000 1000000000\n1000000000 999999999 1\n999999999 666666667 66... |
code_contests | verifiable_code | 1205_F. Beauty of a Permutation | Solve the following coding problem using the programming language python:
Define the beauty of a permutation of numbers from 1 to n (p_1, p_2, ..., p_n) as number of pairs (L, R) such that 1 ≤ L ≤ R ≤ n and numbers p_L, p_{L+1}, ..., p_R are consecutive R-L+1 numbers in some order. For example, the beauty of the permu... | vfc_49669 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1\n5 6\n5 8\n5 10\n",
"output": "YES\n1\nYES\n2 4 1 5 3\nNO\nYES\n4 1 2 3 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4 10\n100 1\n",
"output": "YES\n1 2 3 4 \nNO\n",
... | |
code_contests | verifiable_code | 1223_C. Save the Nature | Solve the following coding problem using the programming language python:
You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!
You have n tickets to sell. The price of the i-th ticket is p_i. As a teller, you have a possibility to ... | ```python
t = int(input())
for case_num in range(t):
n = int(input())
p = list(map(int, input().split(' ')))
x, a = map(int, input().split(' '))
y, b = map(int, input().split(' '))
k = int(input())
p.sort()
p.reverse()
sum = [0]
for i in range(n):
sum.append(sum[-1] + p[i])
... | vfc_49673 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n100\n50 1\n49 1\n100\n8\n100 200 100 200 100 200 100 100\n10 2\n15 3\n107\n3\n1000000000 1000000000 1000000000\n50 1\n50 1\n3000000000\n5\n200 100 100 100 100\n69 5\n31 2\n90\n",
"output": "-1\n6\n3\n4\n",
"type":... |
code_contests | verifiable_code | 1267_E. Elections | Solve the following coding problem using the programming language python:
Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constitu... | ```python
import math
IP = lambda: list(map(int, input().split()))
INF = 1e9
n, m = IP()
lst = [[] for i in range(n)]
for i in range(m):
d = IP()
for j in range(n):
lst[j].append(d[j])
# print(*lst, sep = '\n')
s = [sum(i) for i in lst]
ret = [[] for i in range(n-1)]
if s[-1] <= max(s[:-1]):
print(... | vfc_49681 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n2 3 8\n4 2 9\n3 1 7\n",
"output": "3\n1 2 3",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1288_F. Red-Blue Graph | Solve the following coding problem using the programming language python:
You are given a bipartite graph: the first part of this graph contains n_1 vertices, the second part contains n_2 vertices, and there are m edges. The graph can contain multiple edges.
Initially, each edge is colorless. For each edge, you may e... | vfc_49685 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 3 4 5\nRRR\nB\n2 1\n1 1\n3 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 3 4 5\nURU\nB\n2 1\n1 1\n3 1\n",
"output": "14\nRBB\n",
"type": "stdin_st... | |
code_contests | verifiable_code | 130_F. Prime factorization | Solve the following coding problem using the programming language python:
You are given an integer n. Output its prime factorization.
If n = a1b1a2b2 ... akbk, where ak are prime numbers, the output of your program should look as follows: a1 a1 ... a1 a2 a2 ... a2 ... ak ak ... ak, where factors are ordered in non-de... | vfc_49689 | {
"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": "245\n",
"output": "5 7 7 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n",
"output": "13 \n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1372_B. Omkar and Last Class of Math | Solve the following coding problem using the programming language python:
In Omkar's last class of math, he learned about the least common multiple, or LCM. LCM(a, b) is the smallest positive integer x which is divisible by both a and b.
Omkar, having a laudably curious mind, immediately thought of a problem involvin... | ```python
from math import ceil, sqrt
for _ in range(int(input())):
n = int(input())
if n % 2 == 0: print(n // 2, n // 2)
else:
for i in range(3, ceil(sqrt(n)) + 1):
if n % i == 0:
print(n // i, n - (n // i))
break
else:
print(1, n - 1... | vfc_49701 | {
"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\n4\n6\n9\n",
"output": "2 2\n3 3\n3 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n646185419\n",
"output": "58744129 587441290\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1395_A. Boboniu Likes to Color Balls | Solve the following coding problem using the programming language python:
Boboniu gives you
* r red balls,
* g green balls,
* b blue balls,
* w white balls.
He allows you to do the following operation as many times as you want:
* Pick a red ball, a green ball, and a blue ball and then change their ... | ```python
n = int(input(''))
for i in range(n):
r,g,b,w= map(int,input().split())
num = r%2+g%2+b%2+w%2
less = min(r,min(g,b))
if less == 0:
if num > 1:
print('No')
else:
print('Yes')
else:
if num == 2:
print('No')
else:
... | vfc_49705 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1 1 1\n8 1 9 3\n0 0 0 0\n1000000000 1000000000 1000000000 1000000000\n",
"output": "No\nYes\nYes\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0 2 2 3\n",
"output": "Y... |
code_contests | verifiable_code | 1419_D1. Sage's Birthday (easy version) | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and she ... | ```python
n = int(input())
a = sorted([int(i) for i in input().split()])
b = []
for i in range(n // 2):
b.append(a[-1-i])
b.append(a[i])
if n % 2 == 1:
b.append(a[n // 2])
print((n - 1) // 2)
print(' '.join([str(i) for i in b]))
``` | vfc_49709 | {
"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 3 4 5\n",
"output": "2\n3 1 4 2 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 2 4\n",
"output": "1\n2 1 4 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1437_D. Minimal Height Tree | Solve the following coding problem using the programming language python:
Monocarp had a tree which consisted of n vertices and was rooted at vertex 1. He decided to study BFS ([Breadth-first search](https://en.wikipedia.org/wiki/Breadth-first_search)), so he ran BFS on his tree, starting from the root. BFS can be des... | ```python
tests = int (input())
for test in range (tests):
n = int (input())
a = list(map (int, input().split()))
res = 1
tails = 1
ntails = 0
i = 1
while i < n:
if tails == 0:
res += 1
tails = ntails
ntails = 0
while (i + 1 < n and a[i] < a[i+1]):
i += 1
ntails += 1... | vfc_49713 | {
"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\n4\n1 4 3 2\n2\n1 2\n3\n1 2 3\n",
"output": "3\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4\n1 4 2 3\n2\n1 2\n3\n1 2 3\n",
"output": "2\n1\n1\n",
"type": "stdin... |
code_contests | verifiable_code | 1487_C. Minimum Ties | Solve the following coding problem using the programming language python:
A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other.
There are two possible outcomes of a game:
* the game may result in a tie, then both teams get 1 p... | ```python
import math
import sys
import collections
import bisect
import heapq
ans = []
testcases = int(sys.stdin.readline())
for _ in range(testcases):
n = int(sys.stdin.readline())
arr = [[None]*n for i in range(n)]
if n % 2 == 0:
x = 1
y = 0
for i in range(n//2):
... | vfc_49721 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n3\n",
"output": "\n0 \n1 -1 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n42\n",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -... |
code_contests | verifiable_code | 1538_E. Funny Substrings | Solve the following coding problem using the programming language python:
Polycarp came up with a new programming language. There are only two types of statements in it:
* "x := s": assign the variable named x the value s (where s is a string). For example, the statement var := hello assigns the variable named var... | ```python
def count(string):
c=0
for i in range(len(string)-3):
k=0
va=0
for j in "haha":
if string[i+k]==j:
va+=1
else:
break
k+=1
if va==4:
c+=1
return c
def values(string):
length=len(strin... | vfc_49729 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6\na := h\nb := aha\nc = a + b\nc = c + c\ne = c + c\nd = a + c\n15\nx := haha\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x... |
code_contests | verifiable_code | 164_E. Polycarpus and Tasks | Solve the following coding problem using the programming language python:
Polycarpus has many tasks. Each task is characterized by three integers li, ri and ti. Three integers (li, ri, ti) mean that to perform task i, one needs to choose an integer si (li ≤ si; si + ti - 1 ≤ ri), then the task will be carried out cont... | vfc_49733 | {
"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": "13\n1 8 5\n2 9 4\n3 10 1\n4 11 3\n8 12 5\n9 13 5\n10 14 5\n11 15 1\n12 16 1\n13 17 1\n14 18 3\n15 19 3\n16 20 2\n",
"output": "0\n0\n0\n2\n-1\n-1\n0\n0\n0\n0\n7\n0\n12\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 186_A. Comparing Strings | Solve the following coding problem using the programming language python:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is re... | ```python
g1=list(input())
g2=list(input())
cntr=0
if sorted(g1)!=sorted(g2):
print('NO')
else:
for i in range(len(g1)):
if g1[i]!=g2[i]:
cntr=cntr+1
if cntr==2:
print('YES')
else:
print('NO')
``` | vfc_49737 | {
"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": "ab\nba\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aa\nab\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 232_B. Table | Solve the following coding problem using the programming language python:
John Doe has an n × m table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size n × n have exactly k points.
John Doe wondered, ho... | ```python
n,m,k=map(int,input().split())
M=int(1e9+7)
N=n*n
iv=[0]*(N+1)
iv[1]=1
for i in range(2, N+1):
iv[i]=M-M//i*iv[M%i]%M
f1=[1]*(N+1)
for i in range(1, N+1):
f1[i]=f1[i-1]*i%M
f2=[1]*(N+1)
for i in range(1, N+1):
f2[i]=f2[i-1]*iv[i]%M
left=m%n
#m/n+1, m/n
def powM(b, p):
r=1
while p>0:
... | vfc_49745 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 1\n",
"output": " 45\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "80 500000000000000000 3200\n",
"output": "722478... |
code_contests | verifiable_code | 258_A. Little Elephant and Bits | Solve the following coding problem using the programming language python:
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from n... | ```python
n=input()
c=0
res=''
for i in range(len(n)):
if(n[i]=='0' and c==0):
c+=1
elif(n[i]=='0' and c>0):
res+="0"
elif(n[i]=='1'):
res+="1"
else:
pass
l=len(res)
if c==0:
res=res[:l-1]
print(res)
``` | vfc_49749 | {
"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": "110010\n",
"output": "11010\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 281_A. Word Capitalization | Solve the following coding problem using the programming language python:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input
A single line contains a non... | ```python
n=list(input())
print(n[0].upper()+str(''.join(n[1:])))
``` | vfc_49753 | {
"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": "konjac\n",
"output": "Konjac\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ApPLe\n",
"output": "ApPLe\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 303_E. Random Ranking | Solve the following coding problem using the programming language python:
Imagine a real contest or exam of n participants. Every participant will get a particular score. We can predict the standings board more or less, if we do some statistics on their previous performance.
<image>
Let's say the score of the partic... | vfc_49757 | {
"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": "8\n0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n",
"output": "0.8750000000 0.1250000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 \n0.1250000000 0.7500000000 0.1250000000 0.0000000000 0.00000000... | |
code_contests | verifiable_code | 330_A. Cakeminator | Solve the following coding problem using the programming language python:
You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows:
<image>
The cakeminator is going to eat the cake! Each time he eats, he choose... | ```python
r,c = map(int,input().split())
data = [list(input()) for i in range(r)]
total=0
for i in range(r):
if 'S' not in data[i]:
total+=c
row = total//c
for j in range(c):
for k in range(r):
if data[k][j]=='S':
break
else:
total=total+r-row
print(total)
... | vfc_49761 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\nS...\n....\n..S.\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\nS.SS\nS.SS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 351_D. Jeff and Removing Periods | Solve the following coding problem using the programming language python:
Cosider a sequence, consisting of n integers: a1, a2, ..., an. Jeff can perform the following operation on sequence a:
* take three integers v, t, k (1 ≤ v, t ≤ n; 0 ≤ k; v + tk ≤ n), such that av = av + t, av + t = av + 2t, ..., av + t(k - 1... | vfc_49765 | {
"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\n2 2 1 1 2\n5\n1 5\n1 1\n2 2\n1 3\n2 3\n",
"output": "2\n1\n1\n2\n2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 375_E. Red and Black Tree | Solve the following coding problem using the programming language python:
You have a weighted tree, consisting of n vertices. Each vertex is either painted black or is painted red. A red and black tree is called beautiful, if for any its vertex we can find a black vertex at distance at most x.
The distance between tw... | vfc_49769 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n0 1 0 0\n1 2 2\n2 3 2\n3 4 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 0 0\n1 2 2\n2 3 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
... | |
code_contests | verifiable_code | 398_B. Painting The Wall | Solve the following coding problem using the programming language python:
User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the rules below.
1. Firstly user ainta... | vfc_49773 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 1\n1 2\n",
"output": "2.0000000000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 420_C. Bug in Code | Solve the following coding problem using the programming language python:
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting sa... | ```python
from collections import defaultdict
from bisect import bisect_left as lower
import sys
input = sys.stdin.readline
def put():
return map(int, input().split())
try:
n,m = put()
cnt, mp, ans = [0]*n, defaultdict(), [0]*n
for _ in range(n):
x,y = put()
x,y = x-1,y-1
key = ... | vfc_49777 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 6\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 447_A. DZY Loves Hash | Solve the following coding problem using the programming language python:
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash functio... | ```python
Str=input()
ss=[int(s) for s in Str.split() if s.isdigit()]
p=ss[0]
n=ss[1]
ll=[]
for i in range(n):
x=int(input())
r=x%p
if r not in ll:
ll.append(r)
else:
print(i+1)
break
else:
print(-1)
``` | vfc_49781 | {
"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": "10 5\n0\n21\n53\n41\n53\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n0\n1\n2\n3\n4\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 469_B. Chat Online | Solve the following coding problem using the programming language python:
Little X and Little Z are good friends. They always chat online. But both of them have schedules.
Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders incl... | ```python
p,q,l,r=list(map(int,input().split()))
a=[]
for i in range(p):
k,j=list(map(int,input().split()))
a.append((k,j))
b=[]
for i in range(q):
k,j=list(map(int,input().split()))
b.append((k,j))
b.sort(key=lambda h:h[0])
count=0
for i in range(l,r+1):
for j in range(len(b)):
gg=0
... | vfc_49785 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 0 4\n2 3\n0 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 491_A. Up the hill | Solve the following coding problem using the programming language python:
Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.
It is known that there were N stops, all on different integer heights between 1 and N kilometers (inclusive) above the... | ```python
A, B = int(input()), int(input())
print(*range(B+1, A+B+2), *reversed(range(1, B+1)))
``` | vfc_49789 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0\n1\n",
"output": "2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1",
"output": "2 3 4 1 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 515_B. 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
def slve(n,m,b,g):
bo = [0] * n;gi = [0] * m;i=0
for i in range(1, len(b)):
bo[b[i]] = 1
for i in range(1, len(g)):
gi[g[i]] = 1
while i <=10000:
if bo[(i % n)] == 1 or gi[(i % m)] == 1:bo[(i % n)], gi[(i % m)] = 1, 1
if bo == [1] * n and gi == [1] * m:return 'Y... | vfc_49793 | {
"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\n0\n1 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 0\n1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 542_C. Idempotent functions | Solve the following coding problem using the programming language python:
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function <image>, that for any <image> the formula g(g(x)) = g(x) holds.
Let's denote as f(k)(x) the function f applied k ti... | ```python
from random import randint
from copy import deepcopy
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
a[i] -= 1
def gen(n):
a = []
for i in range(n):
a.append(randint(0, n - 1))
return a
def stupid(a, v=False):
n = len(a)
init = [a[i] for i in range(n)... | vfc_49797 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 569_D. Symmetric and Transitive | Solve the following coding problem using the programming language python:
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the tw... | ```python
def main():
mod = 10 ** 9 + 7
n = int(input())
a = [[0] * (n + 1) for i in range(n + 1)]
a[0][0] = 1
for i in range(1, n + 1):
a[i][0] = a[i - 1][i - 1]
for j in range(1, i + 1):
a[i][j] = (a[i][j - 1] + a[i - 1][j - 1]) % mod
print(a[n][n - 1])
main()
``` | vfc_49801 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 612_A. The Text Splitting | Solve the following coding problem using the programming language python:
You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.
For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
... | ```python
n, p, q = map(int, input().split())
s = input()
for i in range(n // p + 1):
for j in range(n // q + 1):
if i * p + j * q == n:
print(i + j)
for k in range(i):
print(s[k * p: (k + 1) * p])
for k in range(j):
print(s[i * p + k * q: ... | vfc_49809 | {
"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": "10 9 5\nCodeforces\n",
"output": "2\nCodef\norces\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 1 1\nabacabac\n",
"output": "8\na\nb\na\nc\na\nb\na\nc\n",
"type": "stdin_st... |
code_contests | verifiable_code | 632_A. Grandma Laura and Apples | Solve the following coding problem using the programming language python:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had n buyers and each of them bou... | ```python
n,k = map(int,input().split())
s = [input() for i in range(n)]
s = s[::-1]
x = 0
# print(s)
cost = 0
for i in s:
if i == "halfplus":
x = 2*x+1
cost += x/2*k
else:
x = 2*x
cost += x/2*k
print(int(cost))
``` | vfc_49813 | {
"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 10\nhalf\nhalfplus\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10\nhalfplus\nhalfplus\nhalfplus\n",
"output": "55\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 660_D. Number of Parallelograms | Solve the following coding problem using the programming language python:
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
Input
The first line of the input contains integer n (1 ≤ n ≤ 20... | ```python
n=int(input())
def inp(n):
coor=[[int(i) for i in input().split()] for j in range(n)]
return coor
coor=inp(n)
def newlist(a):
d={}
s=len(a)
for i in range(1,s):
for j in range(i):
if (a[i][0]+a[j][0],a[i][1]+a[j][1]) in d:
d[a[i][0]+a[j][0],a[i][... | vfc_49817 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1\n1 0\n1 1\n2 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n0 0\n0 2\n1 3\n1 1\n100 10\n100 11\n101 11\n101 10\n",
"output": "5\n",
"type": "stdin... |
code_contests | verifiable_code | 683_H. Exchange of Books | Solve the following coding problem using the programming language python:
n pupils, who love to read books, study at school. It is known that each student has exactly one best friend, and each pupil is the best friend of exactly one other pupil. Each of the pupils has exactly one interesting book.
The pupils decided ... | vfc_49821 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n2 4 1 3\n",
"output": "3 1 4 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n3 4 5 2 1\n",
"output": "3 4 5 2 1 \n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 707_B. Bakery | Solve the following coding problem using the programming language python:
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.
To bake muffins in her bakery, Masha needs to establish flour supply f... | ```python
def solve():
n, m, k = list(map(int, input().split()))
graph = [dict() for i in range(n + 1)]
for i in range(m):
u, v, l = list(map(int, input().split()))
if v not in graph[u]:
graph[u][v] = l
graph[v][u] = l
else:
graph[u][v] = min(gra... | vfc_49825 | {
"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 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1\n1 2 3\n3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 72_C. Extraordinarily Nice Numbers | Solve the following coding problem using the programming language python:
The positive integer a is a divisor of the positive integer b if and only if there exists a positive integer c such that a × c = b.
King Astyages thinks a positive integer x is extraordinarily nice if the number of its even divisors is equal t... | vfc_49829 | {
"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\n",
"output": "yes\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 74_E. Shift It! | Solve the following coding problem using the programming language python:
There is a square box 6 × 6 in size. It contains 36 chips 1 × 1 in size. Those chips contain 36 different characters — "0"-"9" and "A"-"Z". There is exactly one chip with each character.
You are allowed to make the following operations: you may... | ```python
ls="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s,cnt,a1,a2=[],0,[],[]
for i in range(6):
s.append(list(input()))
def add(c,i):
global cnt
cnt+=1
a1.append(c)
a2.append(i)
def right(i):
add('R',i+1)
tmp=s[i][5]
for j in range(5,0,-1):
s[i][j]=s[i][j-1]
s[i][0]=tmp
def left(i):
add('L',i+1)
tmp=s[i][... | vfc_49833 | {
"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": "01W345\n729AB6\nCD8FGH\nIJELMN\nOPKRST\nUVQXYZ\n",
"output": "260\nD3\nR2\nD3\nL2\nD3\nR2\nD3\nL2\nD3\nR2\nD3\nL2\nD3\nR2\nD3\nR2\nU3\nR2\nD3\nR2\nU3\nR2\nD3\nR2\nU3\nR2\nD6\nR2\nD6\nL2\nD6\nR2\nD6\nL2\nD6\nR2\nD6\nL2\nD6\nD5... |
code_contests | verifiable_code | 773_D. Perishable Roads | Solve the following coding problem using the programming language python:
In the country of Never, there are n cities and a well-developed road system. There is exactly one bidirectional road between every pair of cities, thus, there are as many as <image> roads! No two roads intersect, and no road passes through inte... | vfc_49837 | {
"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": "6\n2 9 9 6 6\n7 1 9 10\n9 2 5\n4 10\n8\n",
"output": "6\n5\n7\n5\n7\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n3\n",
"output": "2\n2\n3\n",
"type": "stdin_stdo... | |
code_contests | verifiable_code | 798_C. Mike and gcd problem | Solve the following coding problem using the programming language python:
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>.
Mike wants to change his sequence in order to make it beautiful. In... | ```python
def gcd(a, b):
while b:
a, b = b, a % b
return a
n = int(input())
a = list(map(int, input().split()))
ans = 0
l = 0
g = a[0]
for i in range(n):
g = gcd(a[i], g)
if g > 1:
print('YES\n0')
else:
for i in range(n):
if a[i] % 2:
l += 1
else... | vfc_49841 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n",
"output": "YES\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 3\n",
"output": "YES\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 818_E. Card Game Again | Solve the following coding problem using the programming language python:
Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq,bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(1... | vfc_49845 | {
"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 4\n6 2 8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6\n9 1 14\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 844_A. Diversity | Solve the following coding problem using the programming language python:
Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.
String s consists only of lowercase Latin letters, and it is allowed to change char... | ```python
m=input()
n=int(input())
if n>len(m):
print("impossible")
else:
v=n-len(set(m))
print(v if v>0 else 0)
``` | vfc_49849 | {
"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": "yahoo\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "google\n7\n",
"output": "impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 864_D. Make a Permutation! | Solve the following coding problem using the programming language python:
Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n.
Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in su... | ```python
def solve(printing):
n = int(input())
nums = [int(st)-1 for st in input().split(" ")]
numdupe = [0] * n
dupeindex = []
dupeindexindv = {}
missing = []
if printing:
print("nums"); print(nums)
for i in range(n):
numdupe[nums[i]] += 1
for i in range(n):
... | vfc_49853 | {
"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\n3 2 2 3\n",
"output": "2\n1 2 4 3 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 88_C. Trains | Solve the following coding problem using the programming language python:
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, h... | ```python
a, b = input().split()
a = int(a); b = int(b)
def gcd(a, b):
if a < b:
return gcd(b, a)
elif not a%b:
return b
return gcd(b, a%b)
lcm = a*b//gcd(a, b)
if a > b:
d_count = lcm//a
m_count = lcm//b - 1
if m_count > d_count:
print("Masha")
elif m_count == d_count:
print("Equal")
else:
print(... | vfc_49857 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n",
"output": "Masha\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 913_A. Modular Exponentiation | Solve the following coding problem using the programming language python:
The following problem is well-known: given integers n and m, calculate
<image>,
where 2n = 2·2·...·2 (n factors), and <image> denotes the remainder of division of x by y.
You are asked to solve the "reverse" problem. Given integers n and m, ... | ```python
n,m=int(input()),int(input())
n=min(n,31)
print(m%(2**n))
``` | vfc_49861 | {
"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": "98765432\n23456789\n",
"output": "23456789\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n42\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 935_A. Fafa and his Company | Solve the following coding problem using the programming language python:
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this ev... | ```python
n = int(input())
count = 1
for i in range(2,(n//2)+1):
if (n-i)%i ==0:
count+=1
print(count)
``` | vfc_49865 | {
"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": "10\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12345\n",
... |
code_contests | verifiable_code | 988_E. Divisibility by 25 | Solve the following coding problem using the programming language python:
You are given an integer n from 1 to 10^{18} without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move t... | ```python
def idx(s, c, start = 0):
try:
return s[::-1].index(c, start)
except:
return -1
def main():
s = input()
zero_cnt = 0
while zero_cnt < len(s) - 1 and s[zero_cnt + 1] == '0':
zero_cnt += 1
i01 = idx(s, '0')
i02 = idx(s, '0', i01 + 1)
i2 = idx(s, '2')
... | vfc_49873 | {
"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": "705\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | amazing-test | Solve the following coding problem using the programming language python:
Akshara is a Maths teacher at Dynamic Public School.One day she decided to take an unusual test of all her students.She took all her students to a fair.There she took them to a candy room.The room had 2 doors and behind each door was unlimited s... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
print 'Hello World!'
'''
def maxsum(c, i, w):
if (i <= 0 or w <= 0):
return 0
if (c[i-1] > w):
return maxsum(c, i-1, w)
if (d[i-1][w] != -1):
... | vfc_49877 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 4\n2 4 2\n3 3\n3 3 3\n\n\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n3 2\n2 4 2\n100 4653\n96 86 92 95 97 88 99 89 98 97 96 87 91 90 89 91 95 94 9... |
code_contests | verifiable_code | candy-distribution-2 | Solve the following coding problem using the programming language python:
It is Jawa's birthday today. His each friend tells him the least number of toffees he wants. Later, his friends together decided that if he is able to satisfy the condition of atleast one of his friends than they will buy him a $1000 gift.
You h... | ```python
T = int (raw_input ())
for t in xrange (T):
N = int (raw_input ())
l = [int (i) for i in raw_input ().split ()]
print sum (l) - N + 1
``` | vfc_49881 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n8 6 9\n1\n4\n\nSAMPLE",
"output": "21\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n8 6 9\n0\n4\n\nSAMPLE",
"output": "21\n5\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | detecting-the-fraud-registrations | Solve the following coding problem using the programming language python:
Vardhaman college of engg. is conducting a coding challenge. The registrations are opened. Many people from different colleges are being registered for this event. Some of them are trying to make some errors in the registrations. They have regis... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t=input()
l=[]
p=[]
while t>0:
t-=1
s=raw_input()
if s in l:
if s not in p:
p.append(s)
else:
l.append(s)
print len(p)
p.sort()
for i in p:... | vfc_49885 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\nraghav\nsitish\nraghu\nvishwa\nkumar \nraghu\nraghu\nraghav\nritesh\ndeepesh\n\nSAMPLE",
"output": "2\nraghav\nraghu\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nraghav\nsitish\... |
code_contests | verifiable_code | gandhi-tree-march | Solve the following coding problem using the programming language python:
Gandhijee is interested in building human tree. He defined a human node as follows :
Person_Id = English alphabet {a...z} .
Person_Chain_Definition = Person_Id ( Person_Chain_Definition Person_Chain_Definition )
For example :
a( b(... | ```python
#!/usr/bin/python
#gandhi tree problem
import copy
def convert(key, mystr):
global column,temp,Fcolumn
L = list(mystr)
#check if binary or single
open = 0
close = 0
LFindex = 0
LLindex = 0
RFindex = 0
RLindex = 0
#stores the a of a()
column[key] = L.pop(0)
#removes '(' and ')'
L.pop(0)
L.pop(len... | vfc_49889 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n-1 a(c(f(.h(..))b(g(..).))e(.d(..)))\n3 b(c(..)a(..))\n\nSAMPLE",
"output": "cgh\nCommon Gandhijee!",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n-1 a(c(f(.h(..))b(g(..).))e(.d(..)))... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.