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 | p01424 Palindrome Generator | Solve the following coding problem using the programming language python:
A palidrome craftsperson starts to work in the early morning, with the clear air allowing him to polish up his palindromes.
On this morning, he is making his pieces to submit to the International Contest for Palindrome Craftspeople.
By the way... | vfc_35421 | {
"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 2\nab\nba\n1 1\n2 2",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\nab\nba\n1 1\n1 2",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": n... | |
code_contests | verifiable_code | p01579 Substring Expression | Solve the following coding problem using the programming language python:
Trees are sometimes represented in the form of strings. Here is one of the most popular ways to represent unlabeled trees:
* Leaves are represented by "()".
* Other nodes (i.e. internal nodes) are represented by "( S1 S2 ... Sn )", where Si is ... | vfc_35425 | {
"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": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "((())()())",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... | |
code_contests | verifiable_code | p01740 Rotation Game | Solve the following coding problem using the programming language python:
You have a board with height two and width W. The board is divided into 1x1 cells. Each row of the board is numbered 1 and 2 from top to bottom and each column is numbered 1 to W from left to right. We denote a cell at the i-th row in the j-th c... | vfc_35429 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n.oo\no..\n\no.o\no..",
"output": "1",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01880 Best Matched Pair | Solve the following coding problem using the programming language python:
Example
Input
2
1 2
Output
2
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split... | vfc_35433 | {
"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": "2\n1 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 2",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02017 Pray | Solve the following coding problem using the programming language python:
C: Prayer (Pray)
Some twins are famous for praying before the contest.
There are four integers $ H, W, X, Y $, and it seems unlucky if $ H \ times W $ and $ x + y $ are both odd numbers.
input
Four integers $ H, W, X, Y $ are given, separate... | ```python
a,b,c,d=map(int,input().split())
print("No" if ((a*b)%2)*((c+d)%2)==1 else "Yes")
``` | vfc_35437 | {
"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 5 1 4",
"output": "No",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 2 4",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 ... |
code_contests | verifiable_code | p02300 Convex Hull | Solve the following coding problem using the programming language python:
Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
Please note that you should ... | ```python
import math
EPS = 1e-10
class Vector2():
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, v):
return Vector2(self.x+v.x, self.y+v.y)
def __sub__(self, v):
return Vector2(self.x-v.x, self.y-v.y)
def __mul__(self, v):
return Vector2(... | vfc_35445 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0\n2 2\n0 2\n0 1",
"output": "4\n0 0\n2 2\n0 2\n0 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n2 1\n0 0\n1 2\n2 2\n4 2\n1 3\n3 3",
"output": "5\n0 0\n2 1\n4 2\n3 3\n1 3",
... |
code_contests | verifiable_code | attic | Solve the following coding problem using the programming language python:
Digory Kirke and Polly Plummer are two kids living next door to each other. The attics of the two houses are connected to each other through a passage. Digory's Uncle Andrew has been secretly doing strange things in the attic of his house, and h... | ```python
test=int(raw_input())
while test:
s=raw_input()
days=0
count=0
maximum=0
for i in range(len(s)):
if s[i] == '#':
if count>maximum:
days+=1
maximum=count
count=0
else:
count=0
else:
... | vfc_35453 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n####\n##.#..#\n##..#.#\n##.#....#",
"output": "0\n2\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n####\n#..#.##\n##..#.#\n##.#....#",
"output": "0\n1\n1\n2\n",
"t... |
code_contests | verifiable_code | cm1404 | Solve the following coding problem using the programming language python:
Problem description.
Liza wants to share her pizza among n friends, What are the minimum number of straight knife strokes required to cut the pizza into n pieces?
Input
The first line contains number of test cases T.
The next T lines contain... | ```python
from math import ceil
from math import sqrt
t=input()
for _ in xrange(t):
n=input()
if n==1:
print "0"
else:
ans=ceil((-1+sqrt(1+4*2*(n-1)))/2)
print int(ans)
``` | vfc_35457 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n5\n6",
"output": "2\n3\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | flow010 | Solve the following coding problem using the programming language python:
Write a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below.
Class ID
Ship Class
B or b
BattleShip
C or c
Cruiser
D or d
Destroyer
F or f
Frigate
I... | ```python
t=input()
for i in range(t):
dic={'b':'BattleShip','B':'BattleShip','c':'Cruiser','C':'Cruiser','d':'Destroyer','D':'Destroyer','f':'Frigate','F':'Frigate'}
s=raw_input()
print dic[s]
``` | vfc_35461 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \nB\nc\nD",
"output": "BattleShip\nCruiser\nDestroyer\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 \nC\nc\nD",
"output": "Cruiser\nCruiser\nDestroyer\n",
"type": "stdin_... |
code_contests | verifiable_code | lemouse | Solve the following coding problem using the programming language python:
It is well-known that the elephants are afraid of mouses. The Little Elephant from the Zoo of Lviv is not an exception.
The Little Elephant is on a board A of n rows and m columns (0-based numeration). At the beginning he is in cell with coordi... | ```python
#! /usr/bin/python
MAX_M = 100000
def xdiff(i, j, matrix, isYflow):
""" coming to i,j position in the matrix from x direction.
isYflow states the direction of second last move considering this as last,
0 represents from left, 1 from top and -1 for the case when both are possible.
Returns the additional... | vfc_35465 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 9\n001000001\n111111010\n100100100\n7 9\n010101110\n110110111\n010011111\n100100000\n000010100\n011011000\n000100101",
"output": "9\n10",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | pptest | Solve the following coding problem using the programming language python:
Polo, the Penguin, has a lot of tests tomorrow at the university.
He knows that there are N different questions that will be on the tests. For each question i (i = 1..N), he knows C[i] - the number of tests that will contain this question, P[i] ... | ```python
def knapsack(weights,values,maxw):
n=len(weights)
m=[]
tmp=[]
for i in xrange(0,maxw+1):
tmp.append(0)
m.append(tmp)
for i in xrange(1,n):
tmp=[]
for j in xrange(0,maxw+1):
if j<weights[i]:
tmp.append(m[i-1][j])
else:
tmp.append(max(m[i-1][j],m[i-1][j-weights[i]]+p[i])... | vfc_35469 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 7\n1 2 3\n2 3 5\n3 3 3",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 7\n1 2 0\n2 3 5\n3 3 3",
"output": "11\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | sumpair | Solve the following coding problem using the programming language python:
Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D.
Find out maximum possible sum of all good disjoint pairs that can be made from these numbers.
Sum of X pairs is the sum ... | ```python
'''
Created on 21-Jul-2015
@author: Venkatesh
'''
def read_int_list():
return [int(x) for x in raw_input().split()]
def read_int():
return int(raw_input())
def get_max_sum(nums, n, d):
nums.sort(reverse=True)
total, ind = 0, 0
while ind+1 < n:
diff = nums[ind] - nums[ind+1]
... | vfc_35473 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 3\n3 5 8\n4 3\n5 8 10 12\n5 3\n3 2 8 17 15",
"output": "8\n22\n37\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 3\n3 5 8\n4 3\n5 8 11 12\n5 3\n3 2 8 17 15",
"output": "8\... |
code_contests | verifiable_code | 100_I. Rotation | Solve the following coding problem using the programming language python:
Ehsan loves geometry! Especially he likes to rotate points!
Given a point in the plane, Ehsan likes to rotate it by k degrees (counter-clockwise), around the origin. What is the result of this rotation?
Input
A single integer k (0 ≤ k < 360) ... | vfc_35477 | {
"difficulty": "15",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "90\n1 1\n",
"output": "-1.00000000 1.00000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "180\n1 1390\n",
"output": "-1.00000000 -1390.00000000\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 1056_D. Decorate Apple Tree | Solve the following coding problem using the programming language python:
There is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enumerated from 1 to n, the... | ```python
n=int(input())
p=[0,0]+list(map(int,input().split()))#tomamos la entrada
d=[0]*(n+1)#aki vamos a contar la cantidad d colores q necesita cada union
for i in range(n,1,-1):#empezamos x las hojas hasta llegar a la raiz
if d[i]==0:#si no estas visitado eres una hoja => solo necesitas un color
d[i]=1
... | vfc_35485 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 3 3\n",
"output": "1 1 1 2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n",
"output": "1 1 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1078_E. Negative Time Summation | Solve the following coding problem using the programming language python:
Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!
More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the c... | ```python
def C(x, y):
return x + '10' + y + 't' + y
def CBF(x, y):
return x + '01' + y + 't' + y
Cr = C('r', 'l')
Cl = C('l', 'r')
Cu = C('u', 'd')
Cd = C('d', 'u')
CBFr = CBF('r', 'l')
CBFl = CBF('l', 'r')
CBFu = CBF('u', 'd')
CBFd = CBF('d', 'u')
def CE(x, y):
return x+x+'0'+x+'1'+y+y+'10... | vfc_35489 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n123456789 987654321\n555555555 555555555\n",
"output": "ds10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedsls... |
code_contests | verifiable_code | 1099_E. Nice table | Solve the following coding problem using the programming language python:
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that diff... | vfc_35493 | {
"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 5\nAGCAG\nAGCAG\nAGCAG\n",
"output": "AGCTC\nCTAGA\nAGCTC\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\nAG\nCT\n",
"output": "AG\nCT\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 111_D. Petya and Coloring | Solve the following coding problem using the programming language python:
Little Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size n × m (n rows, m columns) in k colors. Besides, the coloring should have the following property: for any vertical line that passes a... | ```python
n, m, k = [int(x) for x in input().split()]
mod = int(10**9 + 7)
if m == 1:
print(pow(k, n, mod))
exit()
ans = 0
fac = [1]
ifac = [1]
tav = [0]
for i in range(1, max(k + 1, n + 1)):
fac.append((fac[i - 1] * i) % mod)
for i in range(1, min(k + 1, n + 1)):
ifac.append((ifac[i - 1] * pow(i, mo... | vfc_35497 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1\n",
"output": " 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1147_A. Hide and Seek | Solve the following coding problem using the programming language python:
Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent.
Alice initially has a token on some cell on the line, and Bob tries to guess where it i... | ```python
from collections import Counter
nums, num_questions = map(int, input().split())
questions = list(map(int, input().split()))
exist = set()
things = dict(Counter(questions))
nums = nums * 3 - 2 - len(things)
for i in questions:
if i not in exist:
exist.add(i)
if things.get(i - 1):
... | vfc_35501 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n5 1 4\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100000 1\n42\n",
"output": "299997\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1168_B. Good Triple | Solve the following coding problem using the programming language python:
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such th... | ```python
def func(st,en):
for i in range(st,en+1):
for j in range(i+1,en+1 ):
if (j-i+1)%2==1:
if s[(i+j)//2]==s[i]==s[j]:
return False
#print(st, en)
return True
s=input().strip()
c=0
n=len(s)
for i in range(2,9):
for j in range(len(s)):
... | vfc_35505 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "010101\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1186_E. Vus the Cossack and a Field | Solve the following coding problem using the programming language python:
Vus the Cossack has a field with dimensions n × m, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way:
1. He takes the current field and finds a new inverted field. In other words, th... | ```python
from sys import stdin,stdout
n,m,q = map(int, stdin.readline().split())
mat = [[0]*m for i in range(n)]
for i in range(n):
row = stdin.readline().strip()
for j,c in enumerate(row):
mat[i][j] = 1 if c == '1' else -1
#print(mat)
def get(a,b):
if a < 0 or b < 0:
return 0
x = a... | vfc_35509 | {
"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 3 7\n100\n101\n4 12 5 17\n5 4 9 4\n1 4 13 18\n12 1 14 9\n3 10 7 18\n3 15 12 17\n8 6 8 12\n",
"output": "6\n3\n98\n13\n22\n15\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 5\n10\... |
code_contests | verifiable_code | 1205_D. Almost All | Solve the following coding problem using the programming language python:
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied:
For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of thi... | ```python
import math
n = int(input())
if n == 1:
print()
else:
edge = [list(map(int, input().split())) for i in range(1, n) ]
g = {}
for x, y in edge:
if x not in g:
g[x] = []
if y not in g:
g[y] = []
g[x].append(y)
g[y].appe... | vfc_35513 | {
"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\n2 3\n2 1\n",
"output": "2 3 1\n2 1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 4\n2 3\n2 1\n",
"output": "2 4 1\n2 3 2\n2 1 4\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1223_A. CME | Solve the following coding problem using the programming language python:
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+... | ```python
# import numpy as np
import array
def solution():
req = int(input())
for i in range(req):
count = int(input())
result = 0
if count==2:
print(2)
continue
while count % 2 != 0 :
result+=1
count+=1
print(result)
... | vfc_35517 | {
"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\n2\n5\n8\n11\n",
"output": "2\n1\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n579\n568\n595\n573\n523\n543\n509\n510\n599\n525\n570\n563\n516\n598\n501\n586\n588\n524\n546\... |
code_contests | verifiable_code | 1248_D2. The World Is Just a Programming Task (Hard Version) | Solve the following coding problem using the programming language python:
This is a harder version of the problem. In this version, n ≤ 300 000.
Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gift... | ```python
n = int(input())
s = input()
r = 0
l = n-1
root = []
buf = []
to_the_right = True
for count in range(n):
if to_the_right:
i = r
r += 1
else:
i = l
l -= 1
b = s[i]
if b == '(':
if len(buf) == 0 or buf[-1][0] != -1:
buf.append([-1,-1,[]])
... | vfc_35521 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\n)(()(()())()\n",
"output": "4\n5 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n()()())(()\n",
"output": "5\n8 7",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 1267_B. Balls of Buma | Solve the following coding problem using the programming language python:
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 18 16:25:32 2020
@author: MridulSachdeva
"""
s = input()
n = len(s)
condensed = []
temp = s[0]
count = 1
for i in range(1, n):
if s[i] == temp:
count += 1
else:
condensed.append((temp, count))
temp = s[i]
count = 1
co... | vfc_35525 | {
"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": "OOOWWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BBWBB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BB... |
code_contests | verifiable_code | 1288_D. Minimax Problem | Solve the following coding problem using the programming language python:
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}.
You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size... | vfc_35529 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 5\n5 0 3 1 2\n1 8 9 1 3\n1 2 3 4 5\n9 1 0 3 7\n2 3 0 6 3\n6 4 1 7 0\n",
"output": "1 5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1331_G. Lingua Romana | Solve the following coding problem using the programming language python:
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumul... | ```python
l = [0 for i in range(11)]
for i in range(11):
l[i] = int(input())
l.reverse()
for i in l:
a = (i ** 3) * 5 + (abs(i) ** 0.5)
if a > 400:
print('f(' + str(i) + ') = MAGNA NIMIS!')
continue
print('f(' + str(i) + ') =', format(a, '.2f'))
``` | vfc_35537 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0\n1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n10\n",
"output": "f(10) = MAGNA NIMIS!\nf(-9) = -3642.00\nf(-8) = -2557.17\nf(-7) = -1712.35\nf(-6) = -1077.55\nf(-5) = -622.76\nf(-4) = -318.00\nf(-3) = -133.27\nf(-2) = -38.59\nf(1) = 6... |
code_contests | verifiable_code | 1371_F. Raging Thunder | Solve the following coding problem using the programming language python:
You are a warrior fighting against the machine god Thor.
Thor challenge you to solve the following problem:
There are n conveyors arranged in a line numbered with integers from 1 to n from left to right. Each conveyor has a symbol "<" or ">". ... | vfc_35545 | {
"difficulty": "12",
"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 6\n><>><\n2 4\n3 5\n1 5\n1 3\n2 4\n1 5\n",
"output": "3\n3\n3\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n>\n1 1\n",
"output": "1\n",
"type":... | |
code_contests | verifiable_code | 1419_B. Stairs | Solve the following coding problem using the programming language python:
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.
A staircase is a squared figure that consists of square cells. ... | ```python
ty=[1]
p=2
while(True):
p=p*2
ty.append(p-1)
if(p>10**18):
break
t=int(input())
for j in range(0,t):
x=int(input())
s=0
c=0
for o in ty:
s=s+((o)*(o+1))//2
if(s<=x):
c=c+1
else:
break
print(c)
``` | vfc_35553 | {
"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\n1\n8\n6\n1000000000000000000\n",
"output": "1\n2\n1\n30\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1437_B. Reverse Binary Strings | Solve the following coding problem using the programming language python:
You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's.
String s has exactly n/2 zeroes and n/2 ones (n is even).
In one operation you can reverse any substring of s. A substring of a string... | ```python
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#New Imports
def solution():
n = int(input())
s = input()
val = s.count('10')
a1 = n//2 - val
val = s.count('01')
a2 = n//2 - val
print(min(a1,a2))
return
def main():
testcases = 1
testcases... | vfc_35557 | {
"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\n2\n10\n4\n0110\n8\n11101000\n",
"output": "0\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n10\n4\n0110\n8\n11100001\n",
"output": "0\n1\n3\n",
"type": "stdin_s... |
code_contests | verifiable_code | 1461_F. Mathematical Expression | Solve the following coding problem using the programming language python:
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, …, a_n without any mathematical symbols. The teacher explained ... | ```python
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
ops = input().strip()
if len(ops) == 1:
print(ops.join(map(str, a)))
elif '+' in ops and '*' in ops:
seqs = [[a[0]]]
output = []
# split into seqs of all 0's or non 0's
# every seq in seqs is a li... | vfc_35561 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 1 1 2\n+*\n",
"output": "\n2+1+1+2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 2 0\n+-*\n",
"output": "\n2*2-0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1487_A. Arena | Solve the following coding problem using the programming language python:
n heroes fight against each other in the Arena. Initially, the i-th hero has level a_i.
Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that wer... | ```python
tests = int(input())
for t in range(tests):
n = int(input())
heroes = list(map(int, input().split(' ')))
m = min(heroes)
print(sum([1 for x in heroes if x > m]))
``` | vfc_35565 | {
"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\n3\n3 2 2\n2\n5 5\n4\n1 3 3 7\n",
"output": "\n1\n0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n2 2 2 3\n2\n2 2\n",
"output": "1\n0\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1510_I. Is It Rated? | Solve the following coding problem using the programming language python:
The popular improv website Interpretation Impetus hosts regular improv contests and maintains a rating of the best performers. However, since improv can often go horribly wrong, the website is notorious for declaring improv contests unrated. It ... | vfc_35569 | {
"difficulty": "15",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n000\n\n1\n100\n\n1\n001\n\n0\n111\n\n1\n",
"output": "\n\n\n0\n\n\n0\n\n\n1\n\n\n1\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n000\n\n1\n100\n\n1\n001\n\n0\n111\n\n1\n",
... | |
code_contests | verifiable_code | 1538_C. Number of Pairs | Solve the following coding problem using the programming language python:
You are given an array a of n integers. Find the number of pairs (i, j) (1 ≤ i < j ≤ n) where the sum of a_i + a_j is greater than or equal to l and less than or equal to r (that is, l ≤ a_i + a_j ≤ r).
For example, if n = 3, a = [5, 1, 2], l =... | ```python
# Author: Javier Bórquez
import os
import sys
import bisect
def main():
fastReadInt = sys.stdin.buffer.readline
def fastReadStr(): return sys.stdin.buffer.readline().decode('utf-8').strip()
def fastWrite(ans): return sys.stdout.buffer.write(str(str(ans) + "\n").encode('utf-8'))
def fastWriteList(ans... | vfc_35573 | {
"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\n3 4 7\n5 1 2\n5 5 8\n5 1 2 4 3\n4 100 1000\n1 1 1 1\n5 9 13\n2 5 5 1 1\n",
"output": "\n2\n7\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100 120 130\n1 1 2 3 4 5 6 7 8 9 10... |
code_contests | verifiable_code | 164_C. Machine Programming | Solve the following coding problem using the programming language python:
One remarkable day company "X" received k machines. And they were not simple machines, they were mechanical programmers! This was the last unsuccessful step before switching to android programmers, but that's another story.
The company has now ... | vfc_35577 | {
"difficulty": "9",
"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 2\n1 5 4\n1 4 5\n1 3 2\n4 1 2\n5 6 1\n",
"output": "1 1 0 0 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n2 7 5\n1 3 3\n4 1 3\n",
"output": "0 1 1 ",
"type": "stdin_s... | |
code_contests | verifiable_code | 185_D. Visit of the Great | Solve the following coding problem using the programming language python:
The Great Mushroom King descended to the dwarves, but not everyone managed to see him. Only the few chosen ones could see the King.
We know that only LCM(k2l + 1, k2l + 1 + 1, ..., k2r + 1) dwarves can see the Great Mushroom King. Numbers k, l,... | vfc_35581 | {
"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": "2\n3 1 10 2\n5 0 4 3\n",
"output": "0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 1 9 2\n5 0 4 3\n",
"output": "0\n0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 207_D10. The Beaver's Problem - 3 | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
Y... | vfc_35585 | {
"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": "56000\nU.K. MONEY MARKET DEFICIT FORECAST AT 400 MLN STG\nLONDON, April 13 - The Bank of England said it forecast a\nshortage of around 400 mln stg in the money market today.\nAmong the main factors affecting liquidity, bills matur... | |
code_contests | verifiable_code | 231_E. Cactus | Solve the following coding problem using the programming language python:
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.
A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ ... | ```python
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
... | vfc_35589 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 11\n1 2\n2 3\n3 4\n1 4\n3 5\n5 6\n8 6\n8 7\n7 6\n7 9\n9 10\n6\n1 2\n3 5\n6 9\n9 2\n9 3\n9 10\n",
"output": "2\n2\n2\n4\n4\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n3\... |
code_contests | verifiable_code | 257_D. Sum | Solve the following coding problem using the programming language python:
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n).
Vasya wants to... | ```python
#!/usr/bin/python3
n = int(input())
a = list(map(int, input().split()))
s = a[-1]
ans = ['+']
for v in reversed(a[:-1]):
if s > 0:
s -= v
ans.append('-')
else:
s += v
ans.append('+')
if 0 <= s <= a[-1]:
print(''.join(reversed(ans)))
else:
s = -a[-1]
ans = [... | vfc_35593 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 3 5\n",
"output": "++-\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 5\n",
"output": "+--+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 280_D. k-Maximum Subsequence Sum | Solve the following coding problem using the programming language python:
Consider integer sequence a1, a2, ..., an. You should run queries of two types:
* The query format is "0 i val". In reply to this query you should make the following assignment: ai = val.
* The query format is "1 l r k". In reply to this q... | vfc_35597 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "15\n-4 8 -3 -10 10 4 -7 -7 0 -6 3 8 -10 7 2\n15\n1 3 9 2\n1 6 12 1\n0 6 5\n0 10 -7\n1 4 9 1\n1 7 9 1\n0 10 -3\n1 4 10 2\n1 3 13 2\n1 4 11 2\n0 15 -9\n0 13 -9\n0 11 -10\n1 5 14 2\n1 6 12 1\n",
"output": "14\n11\n15\n0\n15\n26\... | |
code_contests | verifiable_code | 303_C. Minimum Modular | Solve the following coding problem using the programming language python:
You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m > 0), so that for every pair of the remaining integers (ai, aj), the following unequality holds: <image>.
Input
The first ... | vfc_35601 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 0\n0 2 3 6 7 12 18\n",
"output": "13\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 32_D. Constellation | Solve the following coding problem using the programming language python:
A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars s... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
a = [tuple(map(lambda c: c == '*', input().rstrip())) for _ in range(n)]
cnt = [0] * 400
for i in range(1, n - 1):
for j in range(1, m - 1):
... | vfc_35605 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 1\n....*.\n...***\n....*.\n..*...\n.***..\n",
"output": "2 5\n1 5\n3 5\n2 4\n2 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7 2\n...*...\n.......\n...*...\n*.***.*\n...*...\n...... |
code_contests | verifiable_code | 375_C. Circling Round Treasures | Solve the following coding problem using the programming language python:
You have a map as a rectangle table. Each cell of the table is either an obstacle, or a treasure with a certain price, or a bomb, or an empty cell. Your initial position is also given to you.
You can go from one cell of the map to a side-adjace... | ```python
from collections import deque
def main():
n, m = map(int, raw_input().split())
b = [list(raw_input().strip()) for _ in xrange(n)]
def inboard(y, x):
return 0 <= y < n and 0 <= x < m
c = 0
for i in xrange(n):
for j in xrange(m):
if b[i][j] in '123456789':
... | vfc_35613 | {
"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": "7 7\n.......\n.1###2.\n.#...#.\n.#.B.#.\n.3...4.\n..##...\n......S\n100\n100\n100\n100\n",
"output": "364\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 8\n........\n........\n....1B..\... |
code_contests | verifiable_code | 420_A. Start Up | Solve the following coding problem using the programming language python:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should ... | ```python
'''input
XO
'''
s = input()
if all(s[x] == s[~x] for x in range(len(s)//2)):
if any(y not in "AHIMOTUVWXY" for y in s[:len(s)//2+1]):
print("NO")
else:
print("YES")
else:
print("NO")
``` | vfc_35621 | {
"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": "AHA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Z\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "XO\n",... |
code_contests | verifiable_code | 468_E. Permanent | Solve the following coding problem using the programming language python:
Little X has solved the #P-complete problem in polynomial time recently. So he gives this task to you.
There is a special n × n matrix A, you should calculate its permanent modulo 1000000007 (109 + 7). The special property of matrix A is almos... | vfc_35629 | {
"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": "10 10\n3 3 367056794\n6 2 124561273\n1 3 46718146\n6 9 415916869\n10 5 985968336\n3 1 526792265\n1 4 386357058\n10 4 349304187\n2 7 102032499\n3 6 502679075\n",
"output": "233333333",
"type": "stdin_stdout"
},
{... | |
code_contests | verifiable_code | 490_E. Restoring Increasing Sequence | Solve the following coding problem using the programming language python:
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Res... | ```python
def solve(s, t, i, l):
if i == l:
return False
if s[i] == "?":
if solve(s, t, i + 1, l):
s[i] = t[i]
return True
elif t[i] == "9":
return False
s[i] = nxt[t[i]]
for j in range(i, l):
if s[j] == "?":
... | vfc_35633 | {
"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\n?\n18\n1?\n",
"output": "YES\n1\n18\n19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n??\n?\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 514_E. Darth Vader and Tree | Solve the following coding problem using the programming language python:
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to di. The Sith Lord lo... | ```python
# fast io
from sys import stdin
_data = iter(stdin.read().split('\n'))
input = lambda: next(_data)
N = 101
MOD = 1000000007
def mul_vec_mat(v, a):
c = [0] * N
for i in range(N):
c[i] = sum(a[j][i] * v[j] % MOD for j in range(N)) % MOD
return c
def mul_vec_sparse_mat(v, a):
c = [0] *... | vfc_35637 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 3\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n2 2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 542_A. Place Your Ad Here | Solve the following coding problem using the programming language python:
Ivan Anatolyevich's agency is starting to become famous in the town.
They have already ordered and made n TV commercial videos. Each video is made in a special way: the colors and the soundtrack are adjusted to the time of the day and the view... | vfc_35641 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n0 0\n1 1 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n7 9\n1 4\n2 8 2\n0 4 1\n8 9 3\n",
"output": "4\n2 1\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 569_B. Inventory | Solve the following coding problem using the programming language python:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the tra... | ```python
n = int(input())
fix = list()
factors = set(range(1, n + 1))
for i in map(int, input().split()):
if i in factors:
factors.remove(i)
fix.append(i)
else:
fix.append(None)
print(' '.join(str(factors.pop()) if i is None else str(i) for i in fix))
``` | vfc_35645 | {
"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\n1 3 2\n",
"output": "1 3 2 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 58_E. Expression | Solve the following coding problem using the programming language python:
One day Vasya was solving arithmetical problems. He wrote down an expression a + b = c in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. Now Vasya tries to find excuses. He says t... | ```python
X = ''
s = raw_input().strip()
a,s=s.split('+')
b,c=s.split('=')
a,al = map(int,a),len(a)
b,bl = map(int,b),len(b)
c,cl = map(int,c),len(c)
a.reverse()
b.reverse()
c.reverse()
a=[0]+a
b=[0]+b
c=[0]+c
d = [[[((1000,0,0,0,0),0)]*(cl+1) for y in range(bl+1)] for x in range(al+1)]
e = [[[((1000,0,0,0,0),0)]*(cl+1... | vfc_35649 | {
"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+1=3\n",
"output": "12+1=13\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 611_G. New Year and Cake | Solve the following coding problem using the programming language python:
Limak is a little polar bear. According to some old traditions, his bear family prepared a New Year cake. And Limak likes cakes.
As you may know, a New Year cake is a strictly convex polygon with n vertices.
Parents won't allow Limak to eat mo... | vfc_35653 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n-10 0\n-6 6\n0 10\n6 6\n10 0\n6 -6\n0 -10\n-6 -6\n",
"output": "5216",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 4\n2 7\n5 7\n5 4\n3 -2\n",
"output": "90",
"type": "s... | |
code_contests | verifiable_code | 631_D. Messenger | Solve the following coding problem using the programming language python:
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search ... | ```python
def ziped(a):
p = []
for i in a:
x = int(i.split('-')[0])
y = i.split('-')[1]
if len(p) > 0 and p[-1][1] == y:
p[-1][0] += x
else:
p.append([x, y])
return p
def solve(a, b , c):
ans = 0
if len(b) == 1:
for token ... | vfc_35657 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 660_B. Seating On Bus | Solve the following coding problem using the programming language python:
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the ... | ```python
n,m = map(int,input().split())
for k in range(1,2*n +1):
num = 2 *n +k
if num <= m:
print(num, end=" ")
num = k
if num <= m:
print(num, end=" ")
``` | vfc_35661 | {
"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 7\n",
"output": "5 1 6 2 7 3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 36\n",
"output": "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 ... |
code_contests | verifiable_code | 72_A. Goshtasp, Vishtasp and Eidi | Solve the following coding problem using the programming language python:
Goshtasp was known to be a good programmer in his school. One day Vishtasp, Goshtasp's friend, asked him to solve this task:
Given a positive integer n, you should determine whether n is rich.
The positive integer x is rich, if there exists so... | vfc_35673 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11\n",
"output": "11=11\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 74_C. Chessboard Billiard | Solve the following coding problem using the programming language python:
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, f... | ```python
import math
n,m=map(int,input().split())
print(math.gcd(n-1,m-1)+1)
``` | vfc_35677 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 773_B. Dynamic Problem Scoring | Solve the following coding problem using the programming language python:
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem sco... | ```python
import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i]... | vfc_35681 | {
"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\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\n117 65 -1 -1 -1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n7... |
code_contests | verifiable_code | 798_A. Mike and palindrome | Solve the following coding problem using the programming language python:
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example... | ```python
import sys
import math
import itertools
import collections
def getdict(n):
d = {}
if type(n) is list or type(n) is str:
for i in n:
if i in d:
d[i] += 1
else:
d[i] = 1
else:
for i in range(n):
t = ii()
... | vfc_35685 | {
"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": "abbcca\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 818_C. Sofa Thief | Solve the following coding problem using the programming language python:
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This not... | ```python
import sys
from collections import defaultdict as dd
from collections import deque
pl=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if pl:
input=sys.stdin.readline
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip()... | vfc_35689 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 864_B. Polycarp and Letters | Solve the following coding problem using the programming language python:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
*... | ```python
import re
input()
print(max(map(lambda s: len(set(s)), re.split('[A-Z]', input()))))
``` | vfc_35697 | {
"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": "11\naaaaBaabAbA\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nABC\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 88_A. Chord | Solve the following coding problem using the programming language python:
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stan... | ```python
# Problem: 88A
# Time Created: August 10(Monday) 2020 || 11:37:58
#>-------------------------<#
import sys
input = sys.stdin.readline
#>-------------------------<#
from itertools import permutations
# Helper Functions. -> Don't cluster your code.
def check_chord(tup):
notes = ['C', 'C#', 'D', 'D#', 'E... | vfc_35701 | {
"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": "A B H\n",
"output": "strange\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "C E G\n",
"output": "major\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 912_D. Fishes | Solve the following coding problem using the programming language python:
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gi... | ```python
n, m, r, k = map(int, input().split())
def count(y, x):
minx = max(0, x-(r-1))
maxx = min(m-1-(r-1), x)
miny = max(0, y-(r-1))
maxy = min(n-1-(r-1), y)
res = (maxy-miny+1)*(maxx-minx+1)
return res
#X = [[0]*m for i in range(n)]
#for i in range(n):
#for j in range(m):
#X[i... | vfc_35705 | {
"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": "12 17 9 40\n",
"output": "32.8333333333",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 2 3\n",
"output": "2.0000000000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 934_D. A Determined Cleanup | Solve the following coding problem using the programming language python:
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p... | ```python
p, k = input().split()
p, k = int(p), int(k)
s = k - 1
ls = [0]
while s < p:
ls.append(0)
ls.append(0)
s = s * k * k + k - 1
n = len(ls)
for i in range(n):
if (i & 1) == 0:
ls[i] = k - 1
res = s - p
for i in range(n):
t = res % k
if i & 1:
ls[i] += t
else:
l... | vfc_35709 | {
"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": "46 2\n",
"output": "7\n 0 1 0 ... |
code_contests | verifiable_code | 960_F. Pathwalks | Solve the following coding problem using the programming language python:
You are given a directed graph with n nodes and m edges, with all edges having a certain weight.
There might be multiple edges and self loops, and the graph can also be disconnected.
You need to choose a path (possibly passing through same v... | vfc_35713 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n3 1 3\n1 2 1\n2 3 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | altf4-ctrlf4-and-the-game | Solve the following coding problem using the programming language python:
AltF4 and CtrlF4 again started playing games. This time they drew a N x N matrix and filled number in each of the cells randomly. The game is played in turns (AltF4 always starts first, as his name comes first alphabetically). In each turn, a p... | ```python
for mat_ in range(int(raw_input())):
mat = {}
N = int(raw_input())
row_weight = {}
col_weight = {}
for each_mat in range(N):
elems = (str(raw_input())).split()
elems = [int(i) for i in elems]
mat[each_mat+1] = elems
for index, elem in enumerate(elems):
try:
row_weight[each_mat+1] += elem
... | vfc_35721 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n4 1\n1 8\n\nSAMPLE",
"output": "8 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n4 1\n1 10\n\nSAMPLE",
"output": "10 4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | candle-problem | Solve the following coding problem using the programming language python:
Rajiv is given a problem in class.
" Suppose N burnt candles together make a new candle. then how many new candles are created if we start with M candles"
Please refer to similar MCQ Question for clarification.
SAMPLE INPUT
121
SAMPLE OUTPUT... | ```python
n = int(raw_input())
ans = n / 5
r = n % 5 + ans
while r >= 5:
ans += r / 5
r = r % 5 + r / 5
print ans
``` | vfc_35725 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "121\n\nSAMPLE",
"output": "30\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "121\n\nELPMAS",
"output": "30\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | defective-trophy-1 | Solve the following coding problem using the programming language python:
You are given N number of trophies. All trophies look similar. However, one of them is defective. All trophies except the defective one have same weight. The defective one has less weight compared to others. You are given a weighing balance. As ... | ```python
from math import ceil,log
def minCoins(coins):
if coins==0:
print 0
else:
print int(ceil(log(coins,3)))
n=int(raw_input())
for i in range(n):
coins=int(raw_input())
minCoins(coins)
``` | vfc_35729 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n4\n8\n16\n\nSAMPLE",
"output": "1\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0\n1",
"output": "0\n0\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | game-of-thornes | Solve the following coding problem using the programming language python:
Dothraki are planning an attack to usurp King Robert's throne. King Robert learns of this conspiracy from Raven and plans to lock the single door through which the enemy can enter his kingdom.
But, to lock the door he needs a key that is an ana... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
s = raw_input()
n = len(s)
d = {}
for c in s:
if c in d:
d[c] += 1
else:
d[c] = 1
nodd = 0
for key in d:
if d[key] % 2 == 1:
nodd += 1
if n%2 == 0 and nodd == 0:
p... | vfc_35733 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aaabbbb\n\nSAMPLE",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "wmtdtgddcldazqohcrpyjjebruxjxlstxmzqucvypaarrqyvhpurbyuuvteseyobmnuirrigsixjyweilabmzvhwpnovlexartiikrpcb... |
code_contests | verifiable_code | kth-sequence | Solve the following coding problem using the programming language python:
Today RK has a special task for you. RK gives you a positive integer N. First you have to find all the sequences of length N consisting of characters 'O' and 'Z' only such that no two 'Z' are adjacent in any sequence. After finding all such sequ... | ```python
from sys import stdin
fib = [1,2]
ma = 10**19
while True:
fib.append(fib[-1] + fib[-2])
if fib[-1] > ma:
break
t = int(stdin.readline())
for _ in xrange(t):
n,k = map(int,stdin.readline().split())
ans = ''
valid = 1
if n<len(fib) and fib[n] < k:
valid = 0
for i in xrange(n):
rem = n-1-i
#print... | vfc_35737 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 2\n\nSAMPLE",
"output": "OOZ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | monk-and-his-friends | Solve the following coding problem using the programming language python:
Monk is standing at the door of his classroom. There are currently N students in the class, i'th student got Ai candies.
There are still M more students to come. At every instant, a student enters the class and wishes to be seated with a student... | ```python
t = int(raw_input())
for _ in xrange(t):
n, m = map(int, raw_input().split())
students = map(int, raw_input().split())
seated = set(students[:n])
res = []
for student in students[n:]:
res.append("YES" if student in seated else "NO")
seated.add(student)
print "\n".join(res)
``` | vfc_35741 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 3\n3 2 9 11 2\n\nSAMPLE",
"output": "NO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n5 6\n1 5 2 1 2 3 3 5 2 1 5\n3 4\n3 1 2 2 3 4 3\n8 7\n5 2 5 5 3 4 5 5 2 2 4 5 4 3 1... |
code_contests | verifiable_code | paroothi-and-his-date | Solve the following coding problem using the programming language python:
Recently our Paroothi got a crush on a girl , as we all know he is not good with the girls so he asked Vikrant ( The stud ) for expert advise and he told him to take her to her favourite restaurant .
It is known that there are K restaurants in t... | ```python
A = [int(x) for x in raw_input().split(' ') if x!='']
a = [0]*A[1]
b = [int(x) for x in raw_input().split(' ') if x!='']
for i in range(0,A[0]):
a[b[i]-1] = a[b[i]-1]+1
max=0
k=0
for i in range(0,A[1]):
if max<a[i]:
max = a[i]
k=i
print k+1
``` | vfc_35745 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 6\n2 1 2 3 4 2 3 3\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | roy-and-coin-boxes-1 | Solve the following coding problem using the programming language python:
Roy has N coin boxes numbered from 1 to N.
Every day he selects two indices [L,R] and adds 1 coin to each coin box starting from L to R (both inclusive).
He does this for M number of days.
After M days, Roy has a query: How many coin boxes ha... | ```python
n=int(raw_input())
arr=[0]*1000002
b=[0]*1000002
m=int(raw_input())
for i in range(m):
l,r=map(int,raw_input().split())
arr[l]+=1
arr[r+1]-=1
for i in range(1,n+1):
arr[i] += arr[i - 1]
b[arr[i]]+=1
count=0
for i in range(1000000,0,-1):
b[i] += b[i + 1]
q=int(raw_input())
for i in range(q):
qu=int(raw... | vfc_35749 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000\n1000\n282 706\n388 521\n574 934\n410 922\n396 525\n4 550\n48 698\n595 953\n852 861\n3 677\n534 674\n408 417\n615 899\n830 873\n362 393\n989 991\n318 820\n316 708\n712 919\n181 745\n197 728\n765 782\n735 999\n444 697\n452 712\... |
code_contests | verifiable_code | string-problem-32 | Solve the following coding problem using the programming language python:
Arpit thought AB De-villiers could do anything no matter what it is, however his brother didn’t believe him . To make his brother believe him he contacted AB and gave him a problem in which he gave him a two strings where the second string was t... | ```python
def computeLPSArray(txt, M, lps):
lens = 0
lps[0] = 0
i = 1
while i < M:
if txt[i] == txt[lens]:
lens += 1
lps[i] = lens
i += 1
else:
if lens != 0:
lens = lps[lens - 1]
else:
lps[i] = 0
... | vfc_35753 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabababa\ntipra\nmanish\n\nSAMPLE",
"output": "Case 1: 5\nCase 2: -1\nCase 3: -1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\nabababa\ntipra\nmanish\nabcabcabcab\narpit\nmanisha\nma... |
code_contests | verifiable_code | utkarsh-and-jumps | Solve the following coding problem using the programming language python:
Utkarsh being a very talkative child, was scolded by his teacher multiple times. One day, the teacher became very angry and decided to give him a very rigorous punishment. He made him stand on the school field which is X axis.
Utkarsh initiall... | ```python
n,p = map(int,raw_input().split())
p = float(p)
dp = [0] * (n+1)
dp[0] = 1
dp[1] = 0
dp[2] = p/100
dp[3] = 1-p/100
for i in range(4,n+1):
dp[i] = (p/100) * dp[i-2] + (1-p/100) * dp[i-3]
print "%.6f"%dp[n]
``` | vfc_35757 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 20\n\nSAMPLE",
"output": "0.320000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999996 0",
"output": "1.000000\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | p02857 DISCO Presents Discovery Channel Code Contest 2020 Qual - Majority of Balls | Solve the following coding problem using the programming language python:
This is an interactive task.
We have 2N balls arranged in a row, numbered 1, 2, 3, ..., 2N from left to right, where N is an odd number. Among them, there are N red balls and N blue balls.
While blindfolded, you are challenged to guess the col... | vfc_35769 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p00016 Treasure Hunt | Solve the following coding problem using the programming language python:
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to... | ```python
import math
def calc(x, y, r, d, nd):
x = x + r * math.cos(math.radians(d))
y = y + r * math.sin(math.radians(d))
d -= nd
return x, y, d
x = y = 0
d = 90
while True:
r, nd = map(int, input().split(","))
if r == nd == 0: break
x, y, d = calc(x, y, r, d, nd)
print(int(x))
print(int(y))
``` | vfc_35801 | {
"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": "56,65\n97,54\n64,-4\n55,76\n42,-27\n43,80\n87,-86\n55,-6\n89,34\n95,5\n0,0",
"output": "171\n-302",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "56,65\n97,54\n64,-4\n55,76\n42,-27\n43,80\n8... |
code_contests | verifiable_code | p00469 Lining up the cards | Solve the following coding problem using the programming language python:
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers... | ```python
import itertools
while(True):
n = int(input())
k = int(input())
if (n,k) == (0,0):
break
num_lis = []
for _ in range(n):
num_lis.append(input())
word_list = []
for item in list(itertools.permutations(num_lis,k)):
word_list.append("".join(item))
print(len(set(word_list)))
``... | vfc_35813 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n1\n2\n12\n1\n6\n3\n72\n2\n12\n7\n2\n1\n0\n0",
"output": "7\n68",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2\n1\n3\n12\n1\n6\n3\n72\n2\n12\n7\n2\n1\n0\n0",
"output": "7\n6... |
code_contests | verifiable_code | p00661 Time Manipulation | Solve the following coding problem using the programming language python:
She is an apprentice wizard. She first learned the magic of manipulating time. And she decided to open a liquor store to earn a living. It has to do with the fact that all the inhabitants of the country where she lives love alcohol. Residents es... | ```python
# AOJ 1076 Time Manipulation
# Python3 2018.7.10 bal4u
while True:
n, m = map(int, input().split())
if n == 0: break
p = list(map(int, input().split()))
if 1 in p: n = 0
print(n/2)
``` | vfc_35817 | {
"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": "12 3\n2 3 6\n12 4\n1 2 3 6\n0 0",
"output": "6.0000000000\n0.0000000000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00804 e-market | Solve the following coding problem using the programming language python:
The city of Hakodate recently established a commodity exchange market. To participate in the market, each dealer transmits through the Internet an order consisting of his or her name, the type of the order (buy or sell), the name of the commodit... | vfc_35821 | {
"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\nPERLIS SELL A 300\nWILKES BUY A 200\nHAMMING SELL A 100\n4\nBACKUS SELL A 10\nFLOYD BUY A 20\nIVERSON SELL B 30\nBACKUS BUY B 40\n7\nWILKINSON SELL A 500\nMCCARTHY BUY C 300\nWILKINSON SELL C 200\nDIJKSTRA SELL B 100\nBACHMAN BU... | |
code_contests | verifiable_code | p00935 Decimal Sequences | Solve the following coding problem using the programming language python:
Example
Input
3
3 0 1
Output
2
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
j=''.join
u=input
n=int(u())
d=j(j(u().split())for i in[0]*(n//19+(n%19>0)))
i=0
while 1:
if d.find(str(i))<0:
print(i)
exit()
i+=1
``` | vfc_35825 | {
"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 0 1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 1",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n... |
code_contests | verifiable_code | p01068 Equivalent Vertices | Solve the following coding problem using the programming language python:
Background
The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu-kun, one of the kindergarten children, loves drawing as much as programming. So far, Yu has drawn many pictures with... | vfc_35829 | {
"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": "6 6\n0 1 5\n1 1 1\n0 1 5\n0 2 1\n0 5 1\n1 5 5\n0\n1\n2\n3\n4\n5",
"output": "3\n2\n3\n1\n3\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n0 0 1\n0 1 0\n0",
"output": "2",
... | |
code_contests | verifiable_code | p01202 Dance Dance Revolution | Solve the following coding problem using the programming language python:
Dance Dance Revolution is one of the most popular arcade games in Japan. The rule of this game is very simple. A series of four arrow symbols, up, down, left and right, flows downwards on the screen in time to music. The machine has four panels ... | ```python
import re
r=re.compile("UU|DD|RR|LL")
for i in range(input()):print "Yes" if r.search(raw_input()) is None else "No"
``` | vfc_35833 | {
"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\nUU\nRDUL\nULDURDULDURDULDURDULDURD",
"output": "No\nYes\nYes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nUU\nRDLU\nULDURDULDURDULDURDULDURD",
"output": "No\nYes\nYes\n",
... |
code_contests | verifiable_code | p01505 Billiards Sorting | Solve the following coding problem using the programming language python:
Rotation is one of several popular pocket billiards games. It uses 15 balls numbered from 1 to 15, and set them up as illustrated in the following figure at the beginning of a game. (Note: the ball order is modified from real-world Rotation rule... | vfc_35841 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n2 1\n4\n9\n2 4\n8 5 3\n7 1 6 10\n0",
"output": "Case 1: 1\nCase 2: 13",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n2 1\n4\n9\n2 4\n8 5 3\n7 1 6 10\n-1",
"output": "Case ... | |
code_contests | verifiable_code | p01676 Tree Reconstruction | Solve the following coding problem using the programming language python:
J - Tree Reconstruction
Problem Statement
You have a directed graph. Some non-negative value is assigned on each edge of the graph. You know that the value of the graph satisfies the flow conservation law That is, for every node v, the sum of ... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(M):
s, t = map(int, readline().split())
G[s-1].append(t-1)
used = [0]*N
cnt = 0
an... | vfc_35845 | {
"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": "9 13\n1 2\n1 3\n2 9\n3 4\n3 5\n3 6\n4 9\n5 7\n6 7\n6 8\n7 9\n8 9\n9 1",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 13\n1 2\n1 3\n2 9\n3 4\n3 5\n3 6\n4 9\n5 8\n6 7\n6 8\n7... |
code_contests | verifiable_code | p01820 Vector Field | Solve the following coding problem using the programming language python:
Example
Input
9
0 0 v
1 0 >
2 0
Output
9
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | vfc_35849 | {
"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": "9\n0 0 v\n1 0 >\n2 0",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n0 1 v\n1 0 >\n2 0",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": n... | |
code_contests | verifiable_code | p01953 Librarian's Work | Solve the following coding problem using the programming language python:
Japanese Animal Girl Library (JAG Library) is famous for a long bookshelf. It contains $N$ books numbered from $1$ to $N$ from left to right. The weight of the $i$-th book is $w_i$.
One day, naughty Fox Jiro shuffled the order of the books on t... | vfc_35853 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n2 3\n3 4\n1 2",
"output": "15",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02240 Connected Components | Solve the following coding problem using the programming language python:
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
Constraints
* $2 \leq n \leq 100,000$
* $0 \leq m \leq 100,000$
* $1 \leq q \leq 10,000... | ```python
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
class LinkedList:
def __init__(self, n):
self.n = n
self.ll = [[] for _ in range(self.n)]
def link(self, u, v, direction=False):
self.ll[u].append(v)
if not direction:
self.ll[v].append(u)
... | vfc_35861 | {
"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 9\n0 1\n0 2\n3 4\n5 7\n5 6\n6 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3",
"output": "yes\nyes\nno",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 ... |
code_contests | verifiable_code | p02386 Dice IV | Solve the following coding problem using the programming language python:
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned... | ```python
ptn=[
[1,2,3,4,5,6],
[2,6,3,4,1,5],
[3,6,5,2,1,4],
[4,6,2,5,1,3],
[5,6,4,3,1,2],
[6,2,4,3,5,1]
]
def diffDice(orgDice, newDice):
flg = False # diff
tmpDice = [0,0,0,0,0,0]
for i in range(6):
#newDiceをptn1で並べ替え
for idx, j in enumerate(ptn[i]):
tmpDice[idx] = newDice[j-1]
... | vfc_35865 | {
"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\n1 2 3 4 5 6\n6 5 4 3 2 1\n5 4 3 2 1 6",
"output": "Yes",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | clco05 | Solve the following coding problem using the programming language python:
After coming to college, Harry decided to have a get together with friends. So he contacted Chahak who is a renowned event organiser. She is given the task of managing this lavish party.
Harry is fond of eating and his friend Joseph is fond of c... | ```python
t = int (raw_input())
while(t>0):
n,d = map(int,raw_input().split())
a =[]
sum = 0
ans =0
mape = map(int,raw_input().split())
for i in mape:
sum += i
if(sum + (n-1)*10 >d):
ans = -1;
else:
ans = (d- sum)/5
print ans
t =t-1
``` | vfc_35873 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 30\n2 2 1\n3 20\n2 1 1",
"output": "5\n-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | fest | Solve the following coding problem using the programming language python:
Indian Institute of Technology, Banaras Hindu University is organizing an annual cultural festival. An organizing committee has been formed to get all the preprations done for the fest. The convener of the fest has decided to invite the American... | ```python
# your code goes here
mod=1000000007
def power(A,B):
res=1
while B>0:
if B&1:
res=(res*A)%mod
A=(A*A)%mod
B=B>>1
return res
t=input()
while t:
A,B=raw_input().split(" ")
A=int(A)
B=int(B)
print(power(A,B))
t-=1
``` | vfc_35877 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 2\n4 5\n7 4\n34534985349875439875439875349875 93475349759384754395743975349573495\n34543987529435983745230948023948 3498573497543987543985743989120393097595572309482304",
"output": "9\n1024\n2401\n735851262\n985546465",
... |
code_contests | verifiable_code | lebombs | Solve the following coding problem using the programming language python:
The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first and the last) has exactly two adjacent ... | ```python
t = int(raw_input())
for _ in xrange(t):
n = int(raw_input())
S = raw_input()
count = 0
for i in xrange(1, n - 1):
if S[i] == '0' and S[i - 1] == '0' and S[i + 1] == '0':
count += 1
if n != 1:
if S[0] == '0' and S[1] == '0':
count += 1
if S[n... | vfc_35881 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n010\n5\n10001\n7\n0000000",
"output": "0\n1\n7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | pntng | Solve the following coding problem using the programming language python:
You are given a transparent three-dimensional table, the height equals to H and the base is a two-dimensional table N∙M.
The layers of the 3D table are numbered from 1 to H. Each layer is a two-dimensional table, the rows are numbered from 1 to ... | ```python
#!/usr/bin/env python2.7
"""painting.py: solution to http://www.codechef.com/problems/PNTNG"""
import sys
dimensions = sys.stdin.readline().split(" ")
n, m, h = int(dimensions[0]), int(dimensions[1]), int(dimensions[2])
a = n*m
layers = []
maxsquares = 0
for i in xrange(0, h):
layer = sys.stdin.readli... | vfc_35885 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 3\n1 1\n1 2\n1 3",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 3\n1 1\n1 2\n1 3",
"output": "3\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | subarray | Solve the following coding problem using the programming language python:
You are given a character parenthesis array and an integer array.
You need to find the maximum sum sub-array in the integer array such that the corresponding sub-array in the character array has balanced parenthesis.
Formally, a balanced pare... | ```python
import sys
for __ in range(input()) :
n = input()
ch = raw_input()
ops = {')':'(','}':'{',']':'[','>':'<'}
cls = ['}',')','>',']']
lists = map(int,sys.stdin.readline().split())
dp , res , temp = [0]*(n+1) , 0 , 0
for j,i in enumerate(lists) :
dp[j] = dp[j-1]+i
par_st , max_pr , is_empty = [] , [-1... | vfc_35889 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n()()\n-1 -2 3 4\n4\n(()]\n-1 -2 3 4\n4\n[{]{\n1 2 3 4",
"output": "7\n1\n0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 100_B. Friendly Numbers | Solve the following coding problem using the programming language python:
Kiana thinks two integers are friends if and only if one of them divides the other one. For example, 12 and 4 are friends, also 6 and 6 are friends too, but 120 and 36 are not.
A group of non-zero integers is called friendly, if each pair of it... | vfc_35893 | {
"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,3,6,12\n",
"output": "FRIENDS\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1,2,9\n",
"output": "NOT FRIENDS\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1032_F. Vasya and Maximum Matching | Solve the following coding problem using the programming language python:
Vasya has got a tree consisting of n vertices. He wants to delete some (possibly zero) edges in this tree such that the maximum matching in the resulting graph is unique. He asks you to calculate the number of ways to choose a set of edges to re... | vfc_35897 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2\n1 3\n1 4\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... | |
code_contests | verifiable_code | 1055_D. Refactoring | Solve the following coding problem using the programming language python:
Alice has written a program and now tries to improve its readability. One of the ways to improve readability is to give sensible names to the variables, so now Alice wants to rename some variables in her program. In her IDE there is a command ca... | ```python
from __future__ import division
from fileinput import input
from itertools import izip
# // Pay attention!
# // the prefix under index i in the table above is
# // is the string from pattern[0] to pattern[i - 1]
# // inclusive, so the last character of the string under
# // index i is pattern[i - 1]
class... | vfc_35901 | {
"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\nbab\ncac\ncdc\nbdb\ncdc\ncdc\n",
"output": "YES\na\nd\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1077_E. Thematic Contests | Solve the following coding problem using the programming language python:
Polycarp has prepared n competitive programming problems. The topic of the i-th problem is a_i, and some problems' topics may coincide.
Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and... | ```python
# from collections import Counter as C
# n, k_ = map(int, input().split())
# l = [*map(int, input().split())]
# c = C(l)
# d = {}
# for k, v in c.items():
# d[v] = d.get(v, []) + [str(k)]
# ld = sorted([(k, v) for k, v in d.items()], reverse = True)
# res = []
# # print(ld)
# for e in ld:
# res += ... | vfc_35905 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n6 6 6 3 6 1000000000 3 3 6 6\n",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1337 1337 1337\n",
"output": "3",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 1098_D. Eels | Solve the following coding problem using the programming language python:
Vasya is a big fish lover, and his parents gave him an aquarium for the New Year. Vasya does not have a degree in ichthyology, so he thinks that filling a new aquarium with eels is a good idea. Unfortunately, eels are predators, so Vasya decided... | vfc_35909 | {
"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": "2\n+ 1\n- 1\n",
"output": "0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n+ 2\n+ 2\n+ 12\n- 2\n- 2\n+ 4\n+ 1\n+ 1\n- 12\n",
"output": "0\n1\n1\n0\n0\n0\n0\n3\n2\n",
"t... | |
code_contests | verifiable_code | 1119_E. Pavel and Triangles | Solve the following coding problem using the programming language python:
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these s... | ```python
n = int(input())
a = list(map(int, input().split()))
ans = 0
last = 0
for q in range(len(a)):
while last > 0 and a[q] >= 2:
ans += 1
a[q] -= 2
last -= 1
ans += a[q]//3
last += a[q] % 3
print(ans)
``` | vfc_35913 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 2 2 2\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 1167_B. Lost Numbers | Solve the following coding problem using the programming language python:
This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. I... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 15 18:26:08 2019
@author: Hamadeh
"""
class LLNode:
def __init__(self, data):
self.data = data
self.next = None
self.prev = None
# Class to create a Doubly Linked List
class LL:
# Constructor for empty Doubly Linked Li... | vfc_35921 | {
"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": "16\n64\n345\n672",
"output": "? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 6... |
code_contests | verifiable_code | 1204_C. Anna, Svyatoslav and Maps | Solve the following coding problem using the programming language python:
The main characters have been omitted to be short.
You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given by a sequence p_1, p_2, …, p_m of m vertexes; for each 1 ≤ i <... | ```python
from collections import deque
n = int(input())
graph = [list(map(lambda bit: bit == '1', list(input()))) for _ in range(n)]
m = int(input())
way = list(map(lambda i: int(i) - 1, input().split()))
#print(graph)
def dfs(start):
queue = deque([start])
d = [-1] * n
d[start] = 0
while len(queue) !... | vfc_35929 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n011\n101\n110\n7\n1 2 3 1 3 2 1\n",
"output": "7\n1 2 3 1 3 2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0110\n0001\n0001\n1000\n3\n1 2 4\n",
"output": "2\n1 4 \n",
... |
code_contests | verifiable_code | 1221_A. 2048 Game | Solve the following coding problem using the programming language python:
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you ch... | ```python
q=int(input())
for i in range(q):
n=int(input())
lst2=[]
lst1=list(map(int,input().split()))
for i in range(len(lst1)):
if lst1[i]<=2048:
lst2.append(lst1[i])
sum1=sum(lst2)
if sum1>=2048:
print("YES")
else:
print("NO")
``` | vfc_35933 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n",
"output": "YES\nYES\nNO\nNO\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.