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 | nice-p-sequence | Solve the following coding problem using the programming language python:
A Nice-P sequence is defined as a sequence such that a1 x a2=1 (mod p), a2 x a3=1 (mod p) ..., an-1 x an = 1 (mod p). In addition, a1, a 2, a 3, ... an must be less than p and greater than or equal to 0. Given one element, a1, find the sum of th... | ```python
#import sys
#sys.stdin = open("input.txt","r")
from fractions import gcd
def egcd(a, b):
x,y, u,v = 0,1, 1,0
while a != 0:
q, r = b//a, b%a
m, n = x-u*q, y-v*q
b,a, x,y, u,v = a,r, u,v, m,n
g = b
return g, x, y
for testCases in range(input()):
a,p,n = map(int,raw_in... | vfc_64465 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3 2\n3 7 2\n\nSAMPLE",
"output": "4\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n6412 7309 17407\n13331 22745 1854\n409 2203 26171\n2710 10398 2287\n1820 10031 29403\n1317 ... |
code_contests | verifiable_code | sherlock-holmes-and-the-temple-mystery-7 | Solve the following coding problem using the programming language python:
There is a mysterious temple in Mysteryland. The door of the temple is always closed.It can only be opened by a unique procedure.There are two boxes and N items outside the temple.Sherlock holmes visits the temple many times.Each time Sherlock h... | ```python
def isSubSetSum(sett, n, summ):
subset = []
for i in range(summ+1):
a = []
for j in range(n+1):
a.append(True)
subset.append(a)
for i in range(n):
subset[0][i] = True;
for i in range(summ):
subset[i][0] = False;
for i in range(summ):
for i in range(n):
subset[i][j] = subset[i][j-... | vfc_64473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n4 3 5 5 3\n4\n1 2 3 4\n2\n1 2\n\nSAMPLE",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5\n4 3 6 5 3\n4\n1 2 3 4\n2\n1 2\n\nSAMPLE",
"output": "NO\... |
code_contests | verifiable_code | the-final-confusion | Solve the following coding problem using the programming language python:
As predicted by the great Gods, Little Arjit has got nothing to do this summer. (Are you surprised?) But, he's not one of those people to lose hope... not so easily. He decided to work hard this summer on the two things he wants the most, as of ... | ```python
from math import factorial
t = int(raw_input())
while t > 0:
t -= 1
n = input()
print factorial(2*n)/(factorial(n)**2 * (n + 1))
``` | vfc_64477 | {
"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\n3\n\nSAMPLE",
"output": "1\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n3\n\nSPMALE",
"output": "1\n5\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | xsquare-and-double-strings-1 | Solve the following coding problem using the programming language python:
Xsquare got bored playing with the arrays all the time. Therefore, he has decided to play with the strings. Xsquare called a string P a "double string" if string P is not empty and can be broken into two strings A and B such that A + B = P and A... | ```python
from collections import Counter
for _ in range(int(raw_input())):
s=Counter(raw_input())
f=0
for i in s.values():
if i>1:
f=1
break
if f:
print "Yes"
else:
print "No"
``` | vfc_64481 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nwow\ntata\na\nab\nlala\n\n\n\nSAMPLE",
"output": "Yes\nYes\nNo\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nwpw\ntata\na\nab\nlala\n\n\n\nSAMPLE",
"output": "Yes\nY... |
code_contests | verifiable_code | p00078 Magic Square | Solve the following coding problem using the programming language python:
The numbers 1 to n x n are contained in the n x n square squares one by one, and the sum of the squares in any vertical column and the sum of the squares in any horizontal column are diagonal squares. Those with the same sum of eyes are called m... | ```python
while 1:
n = int(input())
if n == 0:
break
l = [[ 0 for i in range(n)] for j in range(n)]
i = n//2 + 1
j = n//2
l[i][j] = ' 1'
c = 2
d = '{: >4}'.format(c)
for x in range(n**2 - 1):
i = (i + 1) % n
j = (j + 1) % n
while l[i][j] != 0:
... | vfc_64525 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n0",
"output": "4 9 2\n 3 5 7\n 8 1 6\n 11 24 7 20 3\n 4 12 25 8 16\n 17 5 13 21 9\n 10 18 1 14 22\n 23 6 19 2 15",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | p00210 The Squares | Solve the following coding problem using the programming language python:
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore,... | ```python
from sys import stdin
# from line_profiler import LineProfiler
def main():
head = [[8,1,2,4],[1,2,4,8],[2,4,8,1],[4,8,1,2]]
while(True):
W,H = map(int, stdin.readline().split())
m = [[0]*W for _ in range(H)]
ps = []
if not (W or H): break
for h in range(H):
... | vfc_64529 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3\n##########\n#E.......X\n##########\n4 4\n####\n#N.#\n#..X\n####\n5 5\n#####\n#N..#\n###.X\n#S..#\n#####\n6 6\n######\n#..#X#\n#.EE.#\n####N#\n#....#\n######\n8 8\n##X#####\n#....E.#\n#####.##\n#.#...##\n#.W.#..#\n#.#.N#.X\n#X... |
code_contests | verifiable_code | p00587 Binary Tree Intersection And Union | Solve the following coding problem using the programming language python:
Given two binary trees, we consider the “intersection” and “union” of them. Here, we distinguish the left and right child of a node when it has only one child. The definitions of them are very simple. First of all, draw a complete binary tree (a... | ```python
import re
class bintree():
def __init__(self, str1):
self.str1 = str1
if self.str1[1] != ",":
c = 0
counter = 0
for s in str1[1:]:
counter += 1
if s == "(":
c += 1
elif s == ")":
... | vfc_64537 | {
"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": "i ((,),(,)) ((,(,)),)\nu ((,),(,)) ((,(,)),)",
"output": "((,),)\n((,(,)),(,))",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00724 Hexerpents of Hexwamp | Solve the following coding problem using the programming language python:
Hexwamp is a strange swamp, paved with regular hexagonal dimples. Hexerpents crawling in this area are serpents adapted to the environment, consisting of a chain of regular hexagonal sections. Each section fits in one dimple.
Hexerpents crawl m... | vfc_64541 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 15, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 -2\n2 -1\n1 0\n1\n0 2\n0 0\n4\n2 -2\n2 -1\n2 0\n3 0\n2\n1 -1\n0 2\n0 0\n8\n-6 0\n-5 0\n-4 0\n-3 0\n-2 0\n-1 0\n0 0\n1 0\n1\n-1 1\n0 0\n6\n2 -3\n3 -3\n3 -2\n3 -1\n3 0\n2 1\n3\n1 -1\n1 0\n1 1\n0 0\n3\n-8000 4996\n-8000 4997\n-80... | |
code_contests | verifiable_code | p00864 Grey Area | Solve the following coding problem using the programming language python:
Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the world everyday. He is extremely good at sophisticated visualization tools, but yet his favorite is a simple self-made histogram generator.
Figure 1 is... | ```python
# coding: utf-8
while 1:
n,w=map(int,input().split())
if n==0:
break
dic={}
mx=-1
max_section=-1
for i in range(1+100//w):
dic[i]=0
for i in range(n):
x=int(input())
dic[x//w]+=1
mx=max(mx,dic[x//w])
max_section=max(max_section,x//w)
... | vfc_64545 | {
"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 50\n100\n0\n100\n3 50\n100\n100\n50\n10 10\n1\n2\n3\n4\n5\n16\n17\n18\n29\n30\n0 0",
"output": "0.51\n0.26\n1.4766666666666667",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 50\n100\n0\... |
code_contests | verifiable_code | p01127 X-Ray Screening System | Solve the following coding problem using the programming language python:
This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, an... | ```python
n = int(input())
for _ in range(n):
h, w = map(int, input().split())
mp = [list(input()) for _ in range(h)]
range_dic = {}
keys = []
for y in range(h):
for x in range(w):
c = mp[y][x]
if c in range_dic:
x1, x2, y1, y2 = range_dic[c]
range_dic[c] = (min(x, x1), max(x, ... | vfc_64553 | {
"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": "6\n1 1\n.\n3 3\n...\n.W.\n...\n10 10\n..........\n.DDDDCCC..\n.DDDDCCC..\n.DDDDCCC..\nADDDDCCC..\nAAA..CCC..\nAAABBBBC..\nAAABBBB...\n..BBBBB...\n..........\n10 10\n..........\n.DDDDDD...\n.DDDDCCC..\n.DDDDCCC..\nADDDDCCC..\nAAA..C... |
code_contests | verifiable_code | p01266 Robot Communication | Solve the following coding problem using the programming language python:
In the year 21xx, human beings are proliferating across the galaxy. Since the end of the last century, thousands of pioneer spaceships have been launched in order to discover new habitation planets.
The Presitener is one of those spaceships, he... | vfc_64557 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n2 0 0 1\n0 4 1 0\n4 6 0 -1\n6 2 -1 0\n4 6\n2 0 0 1\n0 4 1 0\n4 6 0 -1\n6 2 -1 0\n0 0",
"output": "6.00000000\n4.24264069",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01426 Vector Compression | Solve the following coding problem using the programming language python:
You are recording a result of a secret experiment, which consists of a large set of N-dimensional vectors. Since the result may become very large, you are thinking of compressing it. Fortunately you already have a good compression method for vec... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def calc(V, es, r):
mins = [(10**18, -1)]*V
for s, t, w in es:
mins[t] = min(mins[t], (w, s))
mins[r] = (-1, -1)
group = [0]*V
comp = [0]*V
cnt = 0
used = [0]*V
for v in range(V):
if not used[v... | vfc_64561 | {
"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 3\n1.0 1.0\n-1.0 0.0\n0.5 0.5",
"output": "1.0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1.0 1.0 0.0 0.0\n-1.0 0.0 -1.0 0.0\n0.5 0.5 0.5 0.5",
"output": "3.0",
"type... |
code_contests | verifiable_code | p01582 Cover Time | Solve the following coding problem using the programming language python:
Let G be a connected undirected graph where N vertices of G are labeled by numbers from 1 to N. G is simple, i.e. G has no self loops or parallel edges.
Let P be a particle walking on vertices of G. At the beginning, P is on the vertex 1. In ea... | vfc_64565 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01742 Dictionary | Solve the following coding problem using the programming language python:
Sunuke-kun's dictionary contains the words s1, ..., sn, which consist of n lowercase letters. This satisfies s1 <... <sn when compared in lexicographical order. Unfortunately, some characters are faint and unreadable. Unreadable characters are r... | ```python
# seishin.py
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
MOD = 10**9 + 7
N = int(readline())
M = 20
L = 26
ca = ord('a')
cq = ord('?')
S = [[ca-1]*M for i in range(N)]
for i in range(N):
s = readline().strip()
S[i][:len(s)] = ... | vfc_64569 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n?sum??mer\nc??a??mp",
"output": "703286064",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nsnuje\n????e\nsnule",
"output": "1",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | p01882 We don't wanna work! | Solve the following coding problem using the programming language python:
Example
Input
4
Durett 7
Gayles 3
Facenda 6
Daughtery 0
1
+ Mccourtney 2
Output
Mccourtney is not working now.
Durett is working hard now.
The input will be given via stdin and the output should be printed to stdout by your code.
Now solv... | ```python
from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
P = []; Q = []
E = []; R = {}
L = N + 20000
for i in range(N):
s, a = readline().split(); a = int(a) * L + i
E.append(s)
... | vfc_64573 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nDurett 7\nGayles 3\nFacenda 6\nDaughtery 0\n1\n+ Mccourtney 2",
"output": "Mccourtney is not working now.\nDurett is working hard now.",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02019 Training | Solve the following coding problem using the programming language python:
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, mu... | ```python
n,a,b,c = map(int,input().split())
print(n - (a+b-c))
``` | vfc_64577 | {
"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": "6 3 2 1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5 2 1",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 5 2... |
code_contests | verifiable_code | p02449 Permutation | Solve the following coding problem using the programming language python:
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the follo... | ```python
import operator
def permutations(li):
"""Returns a list of previous, current, and
next permutations of li.
>>> permutations([1, 2])
[[1, 2], [2, 1]]
>>> permutations([1, 3, 2])
[[1, 2, 3], [1, 3, 2], [2, 1, 3]]
"""
def perm(op):
def func(xs):
i = len(xs)... | vfc_64589 | {
"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": "3\n3 2 1",
"output": "3 1 2\n3 2 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 1 3",
"output": "1 3 2\n2 1 3\n2 3 1",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | caos1 | Solve the following coding problem using the programming language python:
Problem Statement
Past
In the year of 2048, the Virtual Reality Massively Multiplayer Online Role-Playing Game (VRMMORPG), Code Art Online (CAO), is released. With the Chef Gear, a virtual reality helmet that stimulates the user's five senses vi... | ```python
for _ in xrange(input()):
r,c = map(int,raw_input().split())
a = [list(raw_input()) for _ in range(r)]
tot = 0
for i in range(r):
for j in range(c):
if a[i][j] != '^':
continue
L = 0
for k in range(i-1,-1,-1):
if a[k][... | vfc_64593 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 5\n^^^^^\n^^^^^\n^^^^#\n^^^^^\n^^^^^\n5 7\n^^#^^^^\n^^#^#^#\n#^^^^^^\n^^#^^#^\n^^^^^^^",
"output": "0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 5\n^^^^^\n^^^^^\n^^^]#\n^... |
code_contests | verifiable_code | crace | Solve the following coding problem using the programming language python:
In CycleLand Jack and Jenny are two friends.They want to go CycleSchool By a cycle ( Assume that they live in same house) . Distance between CycleSchool and their house is n units. Jack and jenny both like Jelly . They decided to play a game who... | ```python
# python3
def optimal(n):
if(n >= 5):
res = 5
elif(n < 5 and n >= 3):
res = 3
elif(n < 3 and n >= 1):
res = 1
elif(n < 1):
return -1
return res
if __name__ == "__main__":
count = -1
l = []
test = int(raw_input())
while(test):
n = in... | vfc_64597 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3",
"output": "JENNY\nJACK\nJENNY",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n3\n3",
"output": "JENNY\nJENNY\nJENNY\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | graysc | Solve the following coding problem using the programming language python:
The Gray code (see wikipedia for more details) is a well-known concept.
One of its important properties is that every two adjacent numbers have exactly one different digit in their binary representation.
In this problem, we will give you n non... | ```python
import sys
def main():
s = sys.stdin.readline
n = int(s())
if n>=135:
print "Yes"
return
nums = map(int, s().split())
for i in xrange(n):
for j in xrange(i+1,n):
for k in xrange(j+1,n):
for l in xrange(k+1, n):
if num... | vfc_64601 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 0 2 3 7",
"output": "Yes",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | maxgame | Solve the following coding problem using the programming language python:
Tug of war is a sport that directly puts two teams against each other in a test of strength.
During school days, both Chef Shifu and Chef Po were champions of tug of war.
On behalf of restaurant's anniversary, Chef Shifu and Chef Po have decide... | ```python
import sys
mod= 100000000000007
a=[0]*10004
a[0]=1
a[1]=0
for j in xrange(2,10002):
a[j]=(j-1)*(2*a[j-1]+3*a[j-2])/(j+1)
for j in xrange(0,10002):
a[j]=(a[j]+a[j+1])
c=[0]*10004
c[0]=1
for j in xrange(0,10001):
c[j+1]=2*(2*j+1)*c[j]/(j+2)
t=int(sys.stdin.readline())
while t:
t-=1
n,k=map(int,sys.... | vfc_64605 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2\n4 0\n2 1",
"output": "4\n0\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 2\n0 0\n2 1",
"output": "4\n0\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | rbtree | Solve the following coding problem using the programming language python:
Chef likes trees a lot. Today he has an infinte full binary tree (each node has exactly two childs) with special properties.
Chef's tree has the following special properties :
Each node of the tree is either colored red or black.
Root of the tr... | ```python
Q = int(raw_input())
flag = False
while Q != 0:
s = raw_input()
s = s.split()
q = s[0]
if q != 'Qi':
x = int(s[1])
y = int(s[2])
n = 0
start = 'b'
while True:
if x > y:
x /= 2
n += 1
if start ==... | vfc_64609 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nQb 4 5\nQr 4 5\nQi\nQb 4 5\nQr 4 5",
"output": "2\n1\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nQb 4 5\nQr 4 5\nQi\nQb 4 5\nQr 6 5",
"output": "2\n1\n1\n3\n",
... |
code_contests | verifiable_code | totr | Solve the following coding problem using the programming language python:
A tourist is visiting Byteland. The tourist knows English very well. The language of Byteland is rather different from English. To be exact it differs in following points:
Bytelandian alphabet has the same letters as English one, but possibly d... | ```python
# cook your code here
import string
testcases, KEY = map(str, raw_input().split())
KEYUP = string.swapcase(KEY)
Dic = {'_':' '}
Lower = string.ascii_lowercase
Upper = string.ascii_uppercase
for i in xrange(len(KEY)) :
Dic[Lower[i]] = KEY[i]
Dic[Upper[i]] = KEYUP[i]
#print Dic
for tester in xrange(in... | vfc_64613 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 qwertyuiopasdfghjklzxcvbnm\nPh\nPcssi\nBpke_kdc_epclc_jcijsc_mihyo?\nEpcf_kdc_liswhyo_EIED_hy_Vimcvpcn_Zkdvp_siyo_viyecle.\nIpp!",
"output": "Hi\nHello\nWhat are these people doing?\nThey are solving TOTR in Codechef March ... |
code_contests | verifiable_code | 1015_E2. Stars Drawing (Hard Edition) | Solve the following coding problem using the programming language python:
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
#sys.setrecursionlimit(300000)
# --------------------... | vfc_64617 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n.*...\n****.\n.****\n..**.\n.....\n",
"output": "3\n2 2 1\n3 3 1\n3 4 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 8\n....*...\n...**...\n..*****.\n...**...\n....*...\n........... |
code_contests | verifiable_code | 1061_F. Lost Root | Solve the following coding problem using the programming language python:
The graph is called tree if it is connected and has no cycles. Suppose the tree is rooted at some vertex. Then tree is called to be perfect k-ary tree if each vertex is either a leaf (has no children) or has exactly k children. Also, in perfect ... | vfc_64625 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n\nNo\n\nYes\n",
"output": "? 1 3 2\n\n? 1 2 3\n\n! 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 8\n1 9 2 3 6 5 4 8 7\n",
"output": "16\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 1083_E. The Fair Nut and Rectangles | Solve the following coding problem using the programming language python:
The Fair Nut got stacked in planar world. He should solve this task to get out.
You are given n rectangles with vertexes in (0, 0), (x_i, 0), (x_i, y_i), (0, y_i). For each rectangle, you are also given a number a_i. Choose some of them that th... | vfc_64629 | {
"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 2 4\n1 6 2\n2 4 3\n5 3 8\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1103_A. Grid game | Solve the following coding problem using the programming language python:
You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in ful... | ```python
b= [['3 4','1 4'],['1 1','1 3']];o = [0,0]
for i in map(int,input()):print(b[i][o[i]%2]);o[i] +=1
``` | vfc_64633 | {
"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": "010\n",
"output": "1 1\n4 3\n3 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1131_A. Sea Battle | Solve the following coding problem using the programming language python:
In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 a... | ```python
w1, h1, w2, h2 = map(int, input().split())
if w2 > w1:
res = w1 + 1 + h1 + h2 + 1 + w2 + 1 + h2 + (w1 - w2) + h1 + 1
else:
res = (w1 + h1 + h2) * 2 + 4
print(res)
``` | vfc_64637 | {
"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 1 2 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 1 2\n",
"output": "16\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1151_C. Problem for Nazar | Solve the following coding problem using the programming language python:
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task.
Consider two infinite sets of numbers. The first set consists of odd... | ```python
import math
def Solve(x):
if x == 0:
return 0
stage = int(math.floor(math.log(x,2)))
odd = math.ceil(stage/2)
even = math.floor(stage/2)
even_terms = 2*(pow(4,even)-1)//3
odd_terms = (pow(4,odd)-1)//3
total = even_terms+odd_terms
if (stage+1)%2 == 0:
even_... | vfc_64641 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 14\n",
"output": "105\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8800... |
code_contests | verifiable_code | 1173_B. Nauuo and Chess | Solve the following coding problem using the programming language python:
Nauuo is a girl who loves playing chess.
One day she invented a game by herself which needs n chess pieces to play on a m× m chessboard. The rows and columns are numbered from 1 to m. We denote a cell on the intersection of the r-th row and c-t... | ```python
import sys
import math
from functools import reduce
n = int(input())
m = 1
while True:
if m * 2 <= n:
m += 1
else:
break
print(m)
for x in range(m):
print(1, x+1)
t = n - m
for _ in range(n - m):
print(m, m - t + 1)
t -= 1
``` | vfc_64645 | {
"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\n",
"output": "2\n1 1\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "3\n1 1\n1 2\n1 3\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1209_G2. Into Blocks (hard version) | Solve the following coding problem using the programming language python:
This is a harder version of the problem. In this version q ≤ 200 000.
A sequence of integers is called nice if its elements are arranged in blocks like in [3, 3, 3, 4, 1, 1]. Formally, if two elements are equal, everything in between must also ... | vfc_64653 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n1 2 1 2 1\n2 1\n4 1\n5 3\n2 3\n4 2\n2 1\n",
"output": " 2\n 1\n ... | |
code_contests | verifiable_code | 122_B. Lucky Substring | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was deliver... | ```python
s=input()
s=s.strip('0')
four=s.count('4')
seven=s.count('7')
if '4' not in s and '7' not in s:
print(-1)
else:
if four>=seven:
print('4')
else:
print('7')
``` | vfc_64657 | {
"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": "472747\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1251_A. Broken Keyboard | Solve the following coding problem using the programming language python:
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malf... | ```python
'''
@judge CodeForces
@id 1251A
@name Broken Keyboard
@tag Simulation
'''
from sys import stdin
from itertools import groupby
def solve(s):
return ''.join(sorted(set(map(lambda p: str(p[0]), filter(lambda p: len(list(p[1])) & 1, groupby(s))))))
input()
for line in stdin:
print(solve(line.strip()))
``... | vfc_64661 | {
"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\na\nzzaaz\nccff\ncbddbb\n",
"output": "a\nz\n\nbc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\naababbaaamr\n",
"output": "abmr\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1293_F. Chaotic V. | Solve the following coding problem using the programming language python:
[Æsir - CHAOS](https://soundcloud.com/kivawu/aesir-chaos)
[Æsir - V.](https://soundcloud.com/kivawu/aesir-v)
"Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.
The time right now...... 00:01:12.... | vfc_64669 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 1 4 1 5\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 1 4 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 1313_E. Concatenation with intersection | Solve the following coding problem using the programming language python:
Vasya had three strings a, b and s, which consist of lowercase English letters. The lengths of strings a and b are equal to n, the length of the string s is equal to m.
Vasya decided to choose a substring of the string a, then choose a substri... | ```python
import sys, logging
logging.basicConfig(level=logging.INFO)
logging.disable(logging.INFO)
def build(S, n):
Z = [0 for i in range(3 * n + 3)]
#logging.info(S)
n = len(S)
L = 0
R = 0
Z[0] = n
for i in range(1, n):
if(i > R):
L = R = i
while(R < n and ... | vfc_64673 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\nazaza\nzazaz\nazaz\n",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\naabbaa\nbaaaab\naaaaa\n",
"output": "4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1358_F. Tasty Cookie | Solve the following coding problem using the programming language python:
Oh, no!
The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces yo... | ```python
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI():... | vfc_64681 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 7\n5 7\n",
"output": "SMALL\n0\n\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1379_B. Dubious Cyrpto | Solve the following coding problem using the programming language python:
Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer n, he encrypts it in the following way: he picks three integers a, b and c such that l ≤ a,b,c ≤ r, and then he... | ```python
#!/usr/local/bin/python3
"""
Given l, r, m, you know that
m = n*a + b - c
for some l <= a,b,c <= r, and n is an integer.
Can you find a,b,c? (any value is fine)
Examples
l,r,m = 10,20,90
Choose 10 <= a,b,c <= 20 s.t.
90 = n*a + b - c
a=10,b=10,c=10,n=9
l,r,m = 8,9,95
Choose 8 <= a,b,c <= 9
... | vfc_64685 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 6 13\n2 3 1\n",
"output": "4 5 4\n2 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n10 12 43\n25 49 1\n5 7 39\n8 9 44\n16 17 50\n30 40 975\n601 801 1000\n100 102 909\n599 799 ... |
code_contests | verifiable_code | 1399_F. Yet Another Segments Subset | Solve the following coding problem using the programming language python:
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i ≤ x ≤ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of th... | ```python
def f(sl):
sl.sort(key=lambda s:(s[1],-s[0]))
tl = sorted(list(set([s[0] for s in sl] + [s[1] for s in sl])))
cd = {tl[i]:i for i in range(len(tl))}
csl = [[] for i in range(len(tl))]
for s0,s1 in sl:
csl[cd[s1]].append(cd[s0])
# start dp!
n = len(tl)
dp = [[len(cs... | vfc_64689 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n1 5\n2 4\n2 3\n3 4\n5\n1 5\n2 3\n2 5\n3 5\n2 2\n3\n1 3\n2 4\n2 3\n7\n1 10\n2 8\n2 5\n3 4\n4 4\n6 8\n7 7\n",
"output": "3\n4\n2\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1... |
code_contests | verifiable_code | 1423_D. Does anyone else hate the wind? | Solve the following coding problem using the programming language python:
Mark and his crew are sailing across the sea of Aeolus (in Greek mythology Aeolus was the keeper of the winds). They have the map which represents the NxM matrix with land and sea fields and they want to get to the port (the port is considered a... | vfc_64693 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n5 2 15\nM S S\nS S S\nS S P\nS W N N N N N N N N N N N N N\n2 1 0\n1 2 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n5 2 15\nM S S\nS S S\nS S P\nS E N N N ... | |
code_contests | verifiable_code | 1468_E. Four Segments | Solve the following coding problem using the programming language python:
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 ≤ i ≤ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monoca... | ```python
t = int(input())
while (t):
a = list(map(int,input().split()))
a.sort()
print(a[0]*a[2])
t -= 1
``` | vfc_64701 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 4\n5 5 5 5\n3 1 4 1\n100 20 20 100\n",
"output": "\n3\n25\n3\n2000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 0 3 4\n5 5 5 5\n3 1 4 1\n100 20 20 100\n",
"output": ... |
code_contests | verifiable_code | 1492_D. Genius's Gambit | Solve the following coding problem using the programming language python:
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zero... | ```python
#tests = int(input())
#for t in range(tests):
#n = int(input())
a, b, k = list(map(int, input().split()))
if a == 0 and k!=0:
print('No')
elif k ==0:
print('Yes')
print('1'*b + '0'*a)
print('1'*b + '0'*a)
elif b==1 or k > (a+b-2):
print('No')
else:
shift = a+b-2-k
print('Yes')
... | vfc_64705 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 3\n",
"output": "\nYes\n101000\n100001\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 5\n",
"output": "\nNo\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1515_E. Phoenix and Computers | Solve the following coding problem using the programming language python:
There are n computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer i-1 and computer i+1 are both on, computer i (2 ≤ i ≤ n-1) will turn on aut... | ```python
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
n, MOD = map(int, input().split())
factorial = [1]
for i in range(2, n + 1):
factorial.append(factorial[-1] * i % MOD)
for i in range(len(factorial)):
factorial[i] = pow(factorial[i], MOD - ... | vfc_64709 | {
"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": "400 234567899\n",
"output": "\n20914007\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 16_D. Logging | Solve the following coding problem using the programming language python:
The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lin... | ```python
from sys import stdin
lines = int(stdin.readline())
days = 1
count = 0
h1 = 0
m1 = 0
for x in range(lines):
log = stdin.readline().strip()
hour = int(log[1:3])
if hour == 12:
hour = 0
if log[7] =='p':
hour += 12
minute = int(log[4:6])
#print(hour,minute)
#print(h1,m1)
if hour < h1... | vfc_64717 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n[05:00 a.m.]: Server is started\n[05:00 a.m.]: Rescan initialized\n[01:13 p.m.]: Request processed\n[01:10 p.m.]: Request processed\n[11:40 p.m.]: Rescan completed\n",
"output": "2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 214_B. Hometask | Solve the following coding problem using the programming language python:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given... | ```python
def hometask(arr):
n="0"
if arr.count(0)==0:
return -1
arr.remove(0)
ans=[]
arr=sorted(arr,reverse=True)
while arr :
c=sum(arr)%3
if c==0:
break
flag=True
for i in range(len(arr)-1,-1,-1):
if arr[i]%3==c:
a... | vfc_64725 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n3 4 5 4 5 3 5 3 4 4 0\n",
"output": "5554443330\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 238_B. Boring Partition | Solve the following coding problem using the programming language python:
This problem is the most boring one you've ever seen.
Given a sequence of integers a1, a2, ..., an and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements). Each... | ```python
#https://codeforces.com/problemset/problem/238/B
n, h = map(int, input().split())
a = list(map(int, input().split()))
b = [[x, i] for i, x in enumerate(a)]
b = sorted(b, key=lambda x:x[0])
def solve(a, n, h):
if n == 2:
return 0, [1, 1]
min_ = (a[-1][0] + a[-2][0]) - (a[0][0] +... | vfc_64729 | {
"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 10\n0 1 0 2 1\n",
"output": "3\n1 1 1 1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 2 3\n",
"output": "1\n1 2 2 \n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 262_E. Maxim and Matrix | Solve the following coding problem using the programming language python:
Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m + 1) × (m + 1):
<image>
Maxim asks you to count, how many numbers m (1 ≤ m ≤ n) are there, such that the sum of values in the cells in ... | ```python
def comb(n, r):
if r > n or r < 0:
return 0
r = min(r, n-r)
result = 1
for i in range(1, r+1):
result = result*(n+1-i)//i
return result
def F(n, t):
if t == 0:
return 1
elif n == 0:
return 0
elif n == 1:
return int(t == 1)
m = len(bi... | vfc_64733 | {
"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": "1000000000000 1048576\n",
"output": "118606527258",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 286_E. Ladies' Shop | Solve the following coding problem using the programming language python:
A ladies' shop has recently opened in the city of Ultima Thule. To get ready for the opening, the shop bought n bags. Each bag is characterised by the total weight ai of the items you can put there. The weird thing is, you cannot use these bags ... | vfc_64737 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 10\n5 6 7 8 9 10\n",
"output": "YES\n5\n5 6 7 8 9 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10\n6\n",
"output": "YES\n1\n6 ",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 311_E. Biologist | Solve the following coding problem using the programming language python:
SmallR is a biologist. Her latest research finding is how to change the sex of dogs. In other words, she can change female dogs into male dogs and vice versa.
She is going to demonstrate this technique. Now SmallR has n dogs, the costs of each ... | vfc_64741 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 9\n0 1 1 1 0\n1 8 6 2 3\n0 7 3 3 2 1 1\n1 8 1 5 1\n1 0 3 2 1 4 1\n0 8 3 4 2 1 0\n1 7 2 4 1 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 8\n1 0 1 1 1\n6 5 4 2 8\... | |
code_contests | verifiable_code | 334_C. Secrets | Solve the following coding problem using the programming language python:
Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of thr... | ```python
n = int(input())
res = 1
x = 1
while x <= n:
if n%x != 0:
res = max(res, (n+x-1)//x)
x *= 3
print(res)
``` | vfc_64745 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": " 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": " ... |
code_contests | verifiable_code | 357_C. Knight Tournament | Solve the following coding problem using the programming language python:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There'... | ```python
n, m = map(int, input().split())
p, d = [0] * (n + 2), list(range(1, n + 3))
for i in range(m):
l, r, x = map(int, input().split())
while l < x:
if p[l]:
k = d[l]
d[l] = x
l = k
else:
d[l], p[l] = x, x
l += 1
... | vfc_64749 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2 1\n1 3 3\n1 4 4\n",
"output": "3 1 4 0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n",
"output": "0 8 4 6 4 8 6 1 \n",
"type": "st... |
code_contests | verifiable_code | 380_B. Sereja and Tree | Solve the following coding problem using the programming language python:
Sereja adores trees. Today he came up with a revolutionary new type of binary root trees.
His new tree consists of n levels, each vertex is indexed by two integers: the number of the level and the number of the vertex on the current level. The ... | vfc_64753 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n1 4 4 7 1\n1 3 1 2 2\n2 1 1\n2 4 1\n2 3 3\n",
"output": "2\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n2 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 401_A. Vanya and Cards | Solve the following coding problem using the programming language python:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in ... | ```python
inp = input().split(' ')
n = int(inp[0])
x = int(inp[1])
su = 0
inp = input().split(' ')
for i in inp:
su += int(i)
count = 0
while su!=0:
count += 1
if su > 0:
su += max(-x, -su)
else:
su += min(x, -su)
print(count)
``` | vfc_64757 | {
"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 2\n-1 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n-2 -2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 429_B. Working out | Solve the following coding problem using the programming language python:
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout a... | ```python
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/7/20
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(N, M, A):
dpa = [[0 for _ in range(M+2)] for _ in range(N+2)]
dpb = [[0 for _ in range(M+2)] for _ in range(N+2)]
... | vfc_64761 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n100 100 100\n100 1 100\n100 100 100\n",
"output": "800\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n3 1 2\n3 2 0\n2 3 2\n",
"output": "16\n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 450_E. Jzzhu and Apples | Solve the following coding problem using the programming language python:
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the gre... | ```python
import math
apples=int(input())
if apples<=3:
print(0)
else:
halfpr=int(apples/2)
def primes(n):
primeslistsa=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
89, 97, 101, 103, 107, 109, 113, 127, 131,
... | vfc_64765 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "2\n3 6\n2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9... |
code_contests | verifiable_code | 472_F. Design Tutorial: Change the Goal | Solve the following coding problem using the programming language python:
There are some tasks which have the following structure: you are given a model, and you can do some operations, you should use these operations to achive the goal. One way to create a new task is to use the same model and same operations, but ch... | ```python
n=int(raw_input())
x=map(int,raw_input().split())
y=map(int,raw_input().split())
cnt=0
ans1=[]
ans2=[]
bit=dict()
for i in range(30,-1,-1):
for j in range(0,n):
if x[j]&1<<i > 0 and x[j] < 1<<i+1:
if i not in bit:
bit[i] = j
else:
x[j] ^= x[... | vfc_64769 | {
"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": "3\n1 2 3\n4 5 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0 0 0 0\n1 2 3 4 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 497_B. Tennis Game | Solve the following coding problem using the programming language python:
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. ... | ```python
n = int(input())
line = input().split()
lst = []
for num in line:
lst.append(int(num))
cnt1 = [0]
cnt2 = [0]
c1 = 0
c2 = 0
for num in lst:
if num == 1:
c1 += 1
cnt1.append(c2)
else:
c2 += 1
cnt2.append(c1)
w = lst[n - 1]
ans = []
c1 = len(cnt1)
c2 = len(cnt2)
fo... | vfc_64773 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n2 1 2 1 1 1 1 1\n",
"output": "3\n1 6\n2 3\n6 1\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 520_D. Cubes | Solve the following coding problem using the programming language python:
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is dir... | vfc_64777 | {
"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\n0 0\n0 1\n0 2\n0 3\n0 4\n",
"output": "2930\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 548_A. Mike and Fax | Solve the following coding problem using the programming language python:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.
<image>
He is not sure if this is his o... | ```python
def isPalindrome(t):
for i in range(len(t)//2):
if t[i] != t[len(t)-i-1]:
return False
return True
s = input()
k = int(input())
if len(s) % k:
print('NO')
else:
t = len(s)//k
for i in range(k):
if not isPalindrome(s[i*t: i*t+t]):
print('NO')
... | vfc_64781 | {
"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": "saddastavvat\n2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "saba\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 574_C. Bear and Poker | Solve the following coding problem using the programming language python:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.
Each play... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
for i in range(n):
while arr[i]%2==0:
arr[i]/=2
while arr[i]%3==0:
arr[i]/=3
print("Yes" if all(arr[0]==arr[i] for i in range(n))else "No")
``` | vfc_64785 | {
"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\n75 150 75 50\n",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n100 150 250\n",
"output": "No",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 596_A. Wilbur and Swimming Pool | Solve the following coding problem using the programming language python:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of ... | ```python
def judgeTwoPoints( pa , pb ):
if pa[0] != pb[0] and pa[1] != pb[1]:
#print( "ok!" , pa , pb , abs( pa[0] - pb[0] ) * abs( pa[1] - pb[1] ) )
return abs( pa[0] - pb[0] ) * abs( pa[1] - pb[1] )
else:
return -1
def solve( pts , n ):
if n == 1:
return -1
pts.sort(... | vfc_64789 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 617_C. Watering Flowers | Solve the following coding problem using the programming language python:
A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set s... | ```python
f = lambda: map(int, input().split())
n, a, b, c, d = f()
t = []
for i in range(n):
x, y = f()
t.append(((x - a) ** 2 + (y - b) ** 2, (x - c) ** 2 + (y - d) ** 2))
t.sort()
s = 8e14
q = 0
for u, v in reversed(t):
s = min(s, u + q)
q = max(q, v)
print(min(s, q))
``` | vfc_64793 | {
"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 -1 0 5 3\n0 2\n5 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4\n",
"output": "33\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 637_D. Running with Obstacles | Solve the following coding problem using the programming language python:
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters ... | ```python
n,m,s,d=map(int,input().split())
x=list(map(int,input().split()))+[m+s+1]
x.sort()
cur=l=0
ans=[]
while l<m:
r=min(x[cur]-1,m)
ans.append(("RUN",r-l))
if r==m:
break
if r-l<s:
print("IMPOSSIBLE")
exit()
t=x[cur]+1
while x[cur+1]-1-t<s:
cur+=1
t=x[cur]+1
if t-r>d:
print("I... | vfc_64797 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 9 2 3\n6 4\n",
"output": "IMPOSSIBLE\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 665_D. Simple Subset | Solve the following coding problem using the programming language python:
A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), xi + xj is a prime.
You are given an array a with n positive integers a1, a2, ..., an (not necessary distinct). You wa... | ```python
n = int(input())
L = list(map(int, input().split()))
P = [-1 for _ in range(2000001)]
def premier(n):
if P[n] >= 0:
return P[n]
for i in range(2,int(n**0.5)+1):
if n%i==0:
P[n] = False
return False
P[n] = True
return True
e = L.count(1)
if n == 1:
... | vfc_64801 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2\n",
"output": "1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n",
"output": "2\n2 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 68_B. Energy exchange | Solve the following coding problem using the programming language python:
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some a... | ```python
def check(a, k, cur):
need = 0
have = 0
for x in a:
if x < cur:
need += cur - x
else:
have += (x - cur) * (1 - k / 100)
return need <= have
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
l = 0
r = 1000
for i in range(100):
cur = (l + r) / 2
if check(a, k, cur):... | vfc_64805 | {
"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 90\n1 11\n",
"output": "1.9090909088\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 711_E. ZS and The Birthday Paradox | Solve the following coding problem using the programming language python:
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interestin... | ```python
#copied
import math
n, k = [int(x) for x in input().split()]
if n<70 and k>2**n:
print(1,1)
exit(0)
mod = int(1e6)+3
def fastpow(a,b):
t, ans = a, 1
while b:
if(b&1):
ans = ans*t%mod
t = t*t %mod
b>>=1
return ans
t=k-1
cnt=0
while t: # gets highest pos... | vfc_64809 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3\n",
"output": "1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n",
"output": "23 128",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 732_E. Sockets | Solve the following coding problem using the programming language python:
The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy preparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstation... | ```python
n,m=map(int,raw_input().split())
comp=map(int,raw_input().split())
sockets=map(int,raw_input().split())
c_d={}
s_d={}
ans_s=[0]*(m)
ans_c=[0]*(n)
for i,x in enumerate(comp):
if x in c_d:
c_d[x].append(i)
else:
c_d[x]=[i]
for i,x in enumerate(sockets):
if x in s_d:
s_d[x].ap... | vfc_64813 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 1\n2 2\n",
"output": "2 2\n1 1 \n1 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n2 100\n99\n",
"output": "1 6\n6 \n1 0 ",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 756_F. Long number | Solve the following coding problem using the programming language python:
Consider the following grammar:
* <expression> ::= <term> | <expression> '+' <term>
* <term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')'
* <number> ::= <pos_digit> | <number> <digit>
* <digit> ::= '0' | <pos_dig... | vfc_64817 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8-11\n",
"output": "891011\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 778_B. Bitwise Formula | Solve the following coding problem using the programming language python:
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.
Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will cons... | ```python
#from math import *
from sys import *
from decimal import *
def main():
n,k=(int(z) for z in stdin.readline().split())
d=[]
nm=[0]*n
bt1=[False]*(n+1)
bt2=[False]*(n+1)
bt2[-1]=True
nam=dict()
nam["?"]=-1
for i in range(n):
fl=0
s=stdin.readline()[:-1].spli... | vfc_64821 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n",
"output": "0\n0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 825_A. Binary Protocol | Solve the following coding problem using the programming language python:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of... | ```python
x = int(input())
a = input()
l = 0
c = []
v = ''
b = a.split("0")
for i in b:
g = len(i)
c.append(g)
for p in c:
v += str(p)
print(v)
``` | vfc_64829 | {
"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\n111\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n110011101\n",
"output": "2031\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 847_L. Berland SU Computer Network | Solve the following coding problem using the programming language python:
In the computer network of the Berland State University there are n routers numbered from 1 to n. Some pairs of routers are connected by patch cords. Information can be transmitted over patch cords in both direction. The network is arranged in s... | ```python
import math
import sys
read = sys.stdin.readline
n = int(read())
sub = [[] for _ in range(n)]
for i in range(n):
data = read().strip()
for j in data.split('-'):
tree = list(map(int, j.split(':')[1].split(',')))
for k in range(len(tree)):
tree[k] -= 1
sub[i].append(s... | vfc_64833 | {
"difficulty": "19",
"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\n4:2,5,3,4\n1:4-1:1-2:5,3\n4:4,5,2,1\n4:2,1,3,5\n1:3-3:4,2,1\n",
"output": "4\n1 2\n2 4\n2 5\n3 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1:2-1:3\n1:1-1:3\n1:1-1:2\n",
"... |
code_contests | verifiable_code | 86_B. Tetris revisited | Solve the following coding problem using the programming language python:
Physicist Woll likes to play one relaxing game in between his search of the theory of everything.
Game interface consists of a rectangular n × m playing field and a dashboard. Initially some cells of the playing field are filled while others ar... | ```python
import sys
n,m = map(int,raw_input().split())
f = [list(raw_input()+'#') for _ in xrange(n)]+['#'*(m+1)]
for i in xrange(n):
for j in xrange(m):
if f[i][j]!='.': continue
c=(i%3)+(j%3)*3
f[i][j]=c
if f[i][j+1]=='.':
f[i][j+1]=c
elif f[i+1][j]=='.':
... | vfc_64837 | {
"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 3\n...\n.##\n.#.\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n.#.\n...\n..#\n",
"output": "0#0\n010\n11#\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 896_A. Nephren gives a riddle | Solve the following coding problem using the programming language python:
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? A... | ```python
f0 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
ft1, ft2, ft3 = 'What are you doing while sending "', '"? Are you busy? Will you send "', '"?'
flen = [2 * 10 ** 18] * (10 ** 5 + 1)
flen[0] = len(f0)
for i in range(1, 56):
flen[i] = len(ft1) + len(ft2) + len(ft3) + 2 * f... | vfc_64841 | {
"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\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n",
"output": "Areyoubusy\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n1 2\n1 111111111111\n",
"... |
code_contests | verifiable_code | 917_B. MADMAX | Solve the following coding problem using the programming language python:
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) wit... | ```python
def mat(shape, inital_val=None):
if len(shape) > 1:
return [mat(shape[1:], inital_val) for _ in range(shape[0])]
else:
return [inital_val] * shape[0]
def main():
n, m = [int(x) for x in input().split()]
graph = [{} for _ in range(n)]
for _ in range(m):
... | vfc_64845 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n",
"output": "BAAA\nABAA\nBBBA\nBBBB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n",
... |
code_contests | verifiable_code | 93_B. End of Exams | Solve the following coding problem using the programming language python:
Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams!
Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, w, m = map(int, input().split())
w = float(w)
eps = 1e-9
req = n * w / m
cup = [req] * m
ans = [[] for _ in range(m)]
j = 0
for i in range(n):
milk = w
cnt = 0
while j < m a... | vfc_64849 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 500 2\n",
"output": "YES\n1 500.00000000000000000000 2 500.00000000000000000000 3 250.00000000000000000000 \n3 250.00000000000000000000 4 500.00000000000000000000 5 500.00000000000000000000 \n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 965_E. Short Code | Solve the following coding problem using the programming language python:
Arkady's code contains n variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.
He wants to replace each variable name with its non-empty prefix so that these new nam... | vfc_64853 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ntelegram\ndigital\nresistance\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nabba\nabb\nab\naa\naacada\n",
"output": "11\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 992_E. Nastya and King-Shamans | Solve the following coding problem using the programming language python:
Nastya likes reading and even spends whole days in a library sometimes. Today she found a chronicle of Byteland in the library, and it stated that there lived shamans long time ago. It is known that at every moment there was exactly one shaman i... | ```python
import sys
range = xrange
input = sys.stdin.readline
class maxseg:
def __init__(self,data):
n = len(data)
m = 1
while m<n:m*=2
self.n = n
self.m = m
self.data = [0]*(m+m)
for i in range(n):
self.data[m+i]=data[i]
for i in rever... | vfc_64857 | {
"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": "10 7\n0 3 1 4 6 2 7 8 10 1\n2 5\n1 3\n9 36\n4 10\n4 9\n1 2\n1 0\n",
"output": "1\n-1\n9\n-1\n4\n-1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 3\n1 2\n",
"output": "-1\... |
code_contests | verifiable_code | chess-tournament-4 | Solve the following coding problem using the programming language python:
2^N participants (P1 , P2 , P3 .... , P2^N ) have enrolled for a knockout chess tournament. In the first round, each participant P2k-1 is to play against participant P2k, (1 ≤ k ≤ 2^N-1) . Here is an example for k = 4 :
Some information about ... | ```python
import copy
n = int(raw_input())
table = [[None for i in range(pow(2,n))] for j in range(pow(2,n))]
for i in range(1,pow(2,n)):
temp = map(int,raw_input().split())
for j in range(len(temp)):
table[i][j] = temp[j]
# for _ in range(pow(2,n)-1):
# table.append(map(int,raw_input().split()))
game = [i for ... | vfc_64865 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0\n1 0\n0 1 1\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n0 \n0 1 \n1 0 0 \n1 0 0 0 \n1 0 0 1 0 \n0 1 1 1 0 1 \n0 1 0 1 1 1 1 \n1 0 1 0 0 1 0 0 \n0 1 1 1... |
code_contests | verifiable_code | drunk-man | Solve the following coding problem using the programming language python:
A drunk person was moving from one point on the street to another point on the same street. His starting point was between two manholes on that street. He was following a systematic scheme of his movement and had a fix movement repeated after an... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n_test=int(raw_input(""))
debug=False
for test in range(n_test):
inp=raw_input("").split(" ")
d=inp[0]
D="F"
fw,bw,vf,vb,sp=map(int,inp[1:])
spd_s=vf-vb
spd_t=vf+vb
t0=... | vfc_64869 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nF 10 10 4 3 1\nB 10 10 3 4 2\nF 15 10 3 5 4\nF 19 12 3 3 2\n\nSAMPLE",
"output": "F46\nB92\nB160\nSURVIVED",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nF 10 15 2 3 1\nB 6 1 4 2 3",
... |
code_contests | verifiable_code | grouping-surveillance-team-2 | Solve the following coding problem using the programming language python:
As of now, you helped agent OO7 to find men with different capability values. Now his task is to group up his men and work as a team. He wants to form the groups with minimum 2 men in it. Help him out to find how many such groups are possible.
I... | ```python
num=input()
groupSize=dict()
def gs(n,m):
if m<2: return 0
if(m==n): return 1
if n<m: return 0
if (n,m) in groupSize: return groupSize[(n,m)]
res=1
for i in range(m,n-1):
res+=gs(n-i,i)
groupSize[(n,m)]=res
return res
for _ in range(num):
n=input()
print gs(n,2)
``` | vfc_64873 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n6\n\nSAMPLE",
"output": "2\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n16\n174\n29\n64\n32\n15\n25\n72\n61\n21\n69\n79\n194\n8\n37\n197\n4\n25\n174\n78",
"output": "55... |
code_contests | verifiable_code | little-monty-and-fibonacci-1 | Solve the following coding problem using the programming language python:
Little Monty is very fond of Fibonacci numbers and challenges his friend Lopa
that he can solve any question regarding the same. Lopa however is jealous
and after thinking for a long time came up with a problem.
She says given
N(the numbe... | ```python
t=int(input())
while(t>0):
count=0
n=int(input())
for i in range(3,n+1):
count=int(count+n/i)
if (n==1):
print(1)
elif (n==2):
print(4)
else:
print(int(count+2*n))
t-=1
``` | vfc_64877 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3\n\nSAMPLE",
"output": "1\n4\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2\n4\n\nSAMPLE",
"output": "1\n4\n10\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | myfibonacci-easy-contest | Solve the following coding problem using the programming language python:
Many of you know the famous Fibonacci sequence F:
F[1] = 1
F[2] = 1
F[i] = F[i - 1] + F[i - 2] for i > 2
Thus each number in sequence is a sum of two previous numbers except two first which are define as 1.
You've decided to create you own Fib... | ```python
a,b,n = map(int,raw_input().split())
lis = list();
lis.append(a)
lis.append(b)
for i in range(2,n):
lis.append(lis[i - 1] + lis[i - 2])
print lis[n-1]
``` | vfc_64881 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3 4\n\nSAMPLE",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 6",
"output": "27\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | prime-sum-1 | Solve the following coding problem using the programming language python:
Abhishek is a computer science student at the Department of computer science India His teacher recently gave him a single assignment with only a single problem.
The problem was simple.He has to find out the min number of single digit prime numb... | ```python
t = int(raw_input())
prim = [1,2,3,5,7]
for i in range(t):
n = int(raw_input())
if n<1:
print -1
continue
dp = []*n
sumi = 0
sumi+=n/7
n%=7
if n==1 or n==2 or n==3 or n==5:
sumi+=1
elif n:
sumi+=2
print sumi
``` | vfc_64885 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n9\n12\n19\n\nSAMPLE",
"output": "1\n2\n2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n7\n10\n14\n11",
"output": "1\n2\n2\n3",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | sandy-permutes | Solve the following coding problem using the programming language python:
Sandy is given an array of N integers which is a permutation of the first N natural numbers. He can swap any two elements of the array and can make at most K swaps. He needs to tell the largest permutation, in numerical order, could be made? You... | ```python
N, K = map(int, raw_input().split())
arr = map(int, raw_input().split())
swaps_made = 0
for i, j in enumerate(sorted(arr, reverse=True)):
if j > arr[i]:
p = arr.index(j, i)
arr[i], arr[p] = arr[p], arr[i]
swaps_made += 1
if swaps_made >= K:
break
print ' '.joi... | vfc_64889 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n4 2 3 5 1\n\nSAMPLE",
"output": "5 2 3 4 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n4 2 3 5 1\n\nSAMOLE",
"output": "5 2 3 4 1\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | supertables-3 | Solve the following coding problem using the programming language python:
Little Timmy is exceptionally good at math tables, so his maths teacher decided to make things a bit more interesting. His teacher takes two numbers A and B and merges the tables of A and B in sorted order (ascending order), removing the duplica... | ```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!'
from fractions import gcd
t=input()
while t>0:
t-=1
a,b,n=map(int,raw_input().split())
c=(a*b)/(gcd(a,b))
l,r=1,1000000000000
while(l<=r):
m=(l+r)... | vfc_64893 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 5 2\n3 5 3\n2 3 4\n2 3 6\n\nSAMPLE",
"output": "5\n6\n6\n9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 5 2\n3 5 3\n2 3 4\n2 3 2\n\nSAMPLE",
"output": "5\n6\n6\n3\n",
... |
code_contests | verifiable_code | whens-the-separatist-next-attack | Solve the following coding problem using the programming language python:
Separatist
Always finding new ways to destroy the Republic forces by surprise attacks.
Now they trapped the Republic fleet near the Abregado system. They have developed a way to communicate through the encrypted message to its fleet around the... | ```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!'
n = input()
ans = []
def find(a):
f = 0
n = []
l = []
k = []
t = 1
for i in a:
f = 0
try:
l.index(i)
except ValueError:
f = 1
if t =... | vfc_64897 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n11001001\ncats\nzig\n\nSAMPLE",
"output": "201\n75\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n11001001\ncats\nzig\n\nSAMLPE",
"output": "201\n75\n11\n",
"type": ... |
code_contests | verifiable_code | p00050 Apple and Peach | Solve the following coding problem using the programming language python:
Fukushima Prefecture is also famous for producing fruits, and among them, peaches and apples boast one of the highest production volumes in Japan. By the way, when I made a print manuscript of an English pamphlet for sale, I mistakenly wrote the... | ```python
a,p,t='apple','peach','_'
print(input().replace(a,t).replace(p,a).replace(t,p))
``` | vfc_64941 | {
"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": "the cost of one peach is higher than that of one apple.",
"output": "the cost of one apple is higher than that of one peach.",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "the cost of one p... |
code_contests | verifiable_code | p00527 Take the 'IOI' train | Solve the following coding problem using the programming language python:
Take the'IOI'train
A new railway has been laid in IOI. Trains running on railways in IOI are a combination of several vehicles, and there are two types of vehicles, I and O. Vehicles can only be connected to different types of vehicles. Also, b... | ```python
def main():
M, N = map(int, input().split())
S = input()
T = input()
INF = 10**18
dp0 = [[0]*(N+1) for i in range(M+1)]
dp1 = [[-INF]*(N+1) for i in range(M+1)]
for p in range(M+1):
for q in range(N+1):
v0 = dp0[p][q]
v1 = dp1[p][q]
if... | vfc_64953 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\nOIOOI\nOOIOI",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\nOIOOI\nOOIOI",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | p00694 Strange Key | Solve the following coding problem using the programming language python:
Professor Tsukuba invented a mysterious jewelry box that can be opened with a special gold key whose shape is very strange. It is composed of gold bars joined at their ends. Each gold bar has the same length and is placed parallel to one of the ... | ```python
def solve(sentence):
now = [0, 0, 0] # x,y,z
num_p = {}
positions = []
for s in sentence:
if s.isdecimal():
if s in num_p:
now = num_p[s]
else:
num_p[s] = now
else:
sign = 1 if s[0] == "+" else -1
... | vfc_64957 | {
"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": "19\n 1 +x 1 +y +z 3 +z\n 3 +y -z +x +y -z -x +z 2 +z\n 2 +y\n19\n 1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y\n 3 +z\n 2 +z\n19\n 1 +x 1 +y +z 3 +z\n 3 +y -z +x +y -z -x +z 2 +y\n 2 +z\n18\n 1 -y\n 1 +y -z +x\n 1 +z +y +x ... |
code_contests | verifiable_code | p00835 Crossing Prisms | Solve the following coding problem using the programming language python:
Prof. Bocchan is a mathematician and a sculptor. He likes to create sculptures with mathematics.
His style to make sculptures is very unique. He uses two identical prisms. Crossing them at right angles, he makes a polyhedron that is their inter... | vfc_64961 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 0\n0 10\n7 5\n10 5\n4\n7 5\n10 5\n5 0\n0 10\n4\n0 10\n10 10\n10 0\n0 0\n3\n0 0\n0 10\n10 0\n4\n0 10\n10 5\n0 0\n9 5\n4\n5 0\n0 10\n5 5\n10 10\n4\n0 5\n5 10\n10 5\n5 0\n4\n7 1\n4 1\n0 1\n9 5\n0",
"output": "194.8255\n194.... | |
code_contests | verifiable_code | p01099 Warp Drive | Solve the following coding problem using the programming language python:
Warp Drive
<image>
The warp drive technology is reforming air travel, making the travel times drastically shorter. Aircraft reaching above the warp fields built on the ground surface can be transferred to any desired destination in a twinkling... | vfc_64969 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n100 4\n100 0\n0 0\n1 2 1.00\n2 1 1.00\n3 1 9.99\n3 2 9.99\n7 6\n0 0\n1 0\n2 0\n0 10\n1 10\n2 10\n20 5\n1 7 1.00\n2 7 1.00\n3 7 1.00\n4 7 1.00\n5 7 1.00\n6 7 1.00\n4 4\n-1 -1\n1 -1\n-1 1\n1 1\n1 4 1.10\n4 2 2.10\n2 3 3.10\n3 1 ... | |
code_contests | verifiable_code | p01236 Median Filter | Solve the following coding problem using the programming language python:
The median filter is a nonlinear digital filter used to reduce noise in images, sounds, and other kinds of signals. It examines each sample of the input through a window and then emits the median of the samples in the win- dow. Roughly speaking,... | vfc_64973 | {
"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 5\n\n\n\n\n\n4 4\n\n\n\n\n4 4\n...\n....\n....\n...#\n4 4\n.#.#\n.#.\n.#.#\n.#.\n0 0",
"output": "Case 1: 10\nCase 2: 6\nCase 3: 2\nCase 4: Impossible",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | p01398 Swap Cipher | Solve the following coding problem using the programming language python:
Problem A: Swap crypto
A 2D enthusiast at R University, he often writes embarrassing sentences that blush when seen by people. Therefore, in order for a third party to not be able to see the text he is writing, he encrypts the text using a meth... | ```python
while True:
n = int(input())
if n == 0:break
mes = list(input())
mes = [ord(c) - ord("a") for c in mes]
ablst = [tuple(map(int, input().split())) for _ in range(n)]
ablst.reverse()
for a, b in ablst:
a -= 1
b -= 1
mes[b], mes[a] = (mes[a] + (b - a)) % 26, (mes[b] + (b - a)) % 26
me... | vfc_64977 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\ntojxo\n1 4\n5\nuhcqmlmkv\n4 5\n6 9\n3 6\n1 7\n3 6\n5\nshzxadexonr\n8 9\n3 9\n5 8\n4 9\n10 11\n0",
"output": "aojwo\nshinryaku\nshitadegeso",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01551 DNA | Solve the following coding problem using the programming language python:
A gene is a string consisting of `A`,` T`, `G`,` C`. The genes in this world are strangely known to obey certain syntactic rules.
Syntax rules are given in the following form:
Non-terminal symbol 1: Symbol 1_1 Symbol 1_2 ... Symbol 1_n1
Non-t... | ```python
from collections import defaultdict
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
MOD = 10**9 + 7
Na, Nt, Ng, Nc = map(int, readline().split())
L = Na + Nt + Ng + Nc
M = int(readline())
MP = {}
S = []
for i in range(M):
s = readline(... | vfc_64981 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 262144000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1 2\n1\nk: [ATG] [ATG] [ATG] [C] [C]",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01707 Cookie Counter | Solve the following coding problem using the programming language python:
Problem Statement
One day, my grandmas left $N$ cookies. My elder sister and I were going to eat them immediately, but there was the instruction. It said
* Cookies will go bad; you should eat all of them within $D$ days.
* Be careful about ove... | vfc_64985 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 5\n3 3 3\n5 4 5\n4 1 2\n1 5 1\n1250 50 50\n0 0 0",
"output": "4\n7\n52\n0\n0\n563144298",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 5\n3 3 3\n5 4 5\n4 1 2\n1 5 1\n743 50 50\n0 0 ... | |
code_contests | verifiable_code | p01852 Finger Counting | Solve the following coding problem using the programming language python:
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fing... | ```python
n = int(input())
print(0 * (n == 0) + len(str(bin(n))[2:]) * (n != 0))
``` | vfc_64989 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2",
"output... |
code_contests | verifiable_code | p01987 Casino | Solve the following coding problem using the programming language python:
casino
The company you work for is developing a new casino game. Today I decided to consider a recently proposed game.
In this game, N dice are rolled at the same time, and the total number of rolls is the score. The player plays with the goal... | vfc_64993 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n2 1\n2 2\n0 0",
"output": "4.25\n7\n7.9722222222",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n4 1\n2 2\n0 0",
"output": "4.25000\n14.00000\n7.97222\n",
"type": "stdi... | |
code_contests | verifiable_code | p02274 The Number of Inversions | Solve the following coding problem using the programming language python:
For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the follow... | ```python
import bisect
#int bit[n+1],n
def sum(i):#[1,i]のsumを求める
s = 0
while(i > 0):
s += bit[i]
i = i&(i-1)
return s
def add(i,x):#i番目にxを加算 i & (-i):iの最後の1のbit
while(i <= n):
bit[i] += x
i += i & (-i)
n = int(input())
a = list(map(int,input().split()))
aa = sorted(a)... | vfc_65001 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1 2",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02421 Card Game | Solve the following coding problem using the programming language python:
Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigge... | ```python
n = int(input())
t = 0
h = 0
for _ in range(n):
tc, hc = input().split()
if tc > hc:
t += 3
elif tc < hc:
h += 3
else:
t += 1
h += 1
print(t, h)
``` | vfc_65005 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ncat dog\nfish fish\nlion tiger",
"output": "1 7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nact dog\nfish fish\nlion tiger",
"output": "1 7\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | abhstr | Solve the following coding problem using the programming language python:
Abhi and his friends (Shanky,Anku and Pandey) love to play with strings. Abhi invented a simple game. He will give a string S to his friends. Shanky and Anku will play the game while Pandey is just a spectator. Shanky will traverse the string fr... | ```python
# cook your code here
T = int(raw_input())
for i in range(T):
s = raw_input()
l = [0 for j in range(26)]
length = len(s)
for j in range(length):
index = ord(s[j])-97
l[index] = l[index]+1
flag = 0
x = 0
y = 0
for j in range(length):
x = ord(s[j])-97
... | vfc_65009 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ngoogle\nbreakraekb\naman",
"output": "SHANKY\nPANDEY\nANKU",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\ngoogle\nbreakraekb\nnama",
"output": "SHANKY\nPANDEY\nSHANKY\n",
... |
code_contests | verifiable_code | chefluck | Solve the following coding problem using the programming language python:
Every great chef knows that lucky numbers are 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.
Our chef has recently returned from the Luck... | ```python
import sys
t = int(sys.stdin.readline())
while t>0:
n = int(sys.stdin.readline())
count = n/7
rem = n%7
count-=rem%4
if count<0:
print -1
else:
print count*7
t-=1
``` | vfc_65013 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n7\n4\n11\n1\n15",
"output": "7\n0\n7\n-1\n\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n7\n4\n11\n1\n28",
"output": "7\n0\n7\n-1\n28\n",
"type": "stdin_stdout"
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.